From 0397df2f4d78ad36eb8af90dfcb06e367621627d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 5 Aug 2013 11:32:04 -0700 Subject: [PATCH] Rename package main to just Bookmarks This allows the view that displays the bookmarks for browsing to be called just BookmarksView. --- .../bookmarks/lib/bookmarks-list-view.coffee | 77 --------- .../bookmarks/lib/bookmarks-view.coffee | 155 +++++++----------- src/packages/bookmarks/lib/bookmarks.coffee | 108 ++++++++++++ src/packages/bookmarks/package.cson | 2 +- 4 files changed, 171 insertions(+), 171 deletions(-) delete mode 100644 src/packages/bookmarks/lib/bookmarks-list-view.coffee create mode 100644 src/packages/bookmarks/lib/bookmarks.coffee diff --git a/src/packages/bookmarks/lib/bookmarks-list-view.coffee b/src/packages/bookmarks/lib/bookmarks-list-view.coffee deleted file mode 100644 index e280801c5..000000000 --- a/src/packages/bookmarks/lib/bookmarks-list-view.coffee +++ /dev/null @@ -1,77 +0,0 @@ -path = require 'path' - -{$$} = require 'space-pen' - -SelectList = require 'select-list' - -module.exports = -class BookmarksView extends SelectList - @viewClass: -> "#{super} bookmarks-view overlay from-top" - - filterKey: 'bookmarkFilterText' - - initialize: -> - super - - toggle: -> - if @hasParent() - @cancel() - else - @populateBookmarks() - @attach() - - getFilterText: (bookmark) -> - segments = [] - bookmarkRow = bookmark.getStartPosition().row - segments.push(bookmarkRow) - if bufferPath = bookmark.buffer.getPath() - segments.push(bufferPath) - if lineText = @getLineText(bookmark) - segments.push(lineText) - segments.join(' ') - - getLineText: (bookmark) -> - bookmark.buffer.lineForRow(bookmark.getStartPosition().row)?.trim() - - populateBookmarks: -> - markers = [] - attributes = class: 'bookmark' - for buffer in project.getBuffers() - for marker in buffer.findMarkers(attributes) - marker.bookmarkFilterText = @getFilterText(marker) - markers.push(marker) - @setArray(markers) - - itemForElement: (bookmark) -> - bookmarkRow = bookmark.getStartPosition().row - if filePath = bookmark.buffer.getPath() - bookmarkLocation = "#{path.basename(filePath)}:#{bookmarkRow + 1}" - else - bookmarkLocation = "untitled:#{bookmarkRow + 1}" - lineText = @getLineText(bookmark) - - $$ -> - if lineText - @li class: 'bookmark two-lines', => - @div bookmarkLocation, class: 'primary-line' - @div lineText, class: 'secondary-line line-text' - else - @li class: 'bookmark', => - @div bookmarkLocation, class: 'primary-line' - - getEmptyMessage: (itemCount) -> - if itemCount is 0 - 'No bookmarks found' - else - super - - confirmed : (bookmark) -> - for editor in rootView.getEditors() - if editor.getBuffer() is bookmark.buffer - editor.activeEditSession.setSelectedBufferRange(bookmark.getRange(), autoscroll: true) - - attach: -> - super - - rootView.append(this) - @miniEditor.focus() diff --git a/src/packages/bookmarks/lib/bookmarks-view.coffee b/src/packages/bookmarks/lib/bookmarks-view.coffee index 9b6d42fee..e280801c5 100644 --- a/src/packages/bookmarks/lib/bookmarks-view.coffee +++ b/src/packages/bookmarks/lib/bookmarks-view.coffee @@ -1,108 +1,77 @@ -_ = require 'underscore' -shell = require 'shell' +path = require 'path' + +{$$} = require 'space-pen' + +SelectList = require 'select-list' module.exports = -class BookmarksView - @activate: -> - bookmarksList = null +class BookmarksView extends SelectList + @viewClass: -> "#{super} bookmarks-view overlay from-top" - rootView.command 'bookmarks:view-all', -> - unless bookmarksList? - BookmarksListView = require './bookmarks-list-view' - bookmarksList = new BookmarksListView() - bookmarksList.toggle() + filterKey: 'bookmarkFilterText' - rootView.eachEditor (editor) => - new BookmarksView(editor) if editor.attached and editor.getPane()? + initialize: -> + super - editor: null - - constructor: (@editor) -> - @gutter = @editor.gutter - @editor.on 'editor:display-updated', @renderBookmarkMarkers - - @editor.command 'bookmarks:toggle-bookmark', @toggleBookmark - @editor.command 'bookmarks:jump-to-next-bookmark', @jumpToNextBookmark - @editor.command 'bookmarks:jump-to-previous-bookmark', @jumpToPreviousBookmark - - toggleBookmark: => - cursors = @editor.getCursors() - for cursor in cursors - position = cursor.getBufferPosition() - bookmarks = @findBookmarkMarkers(startBufferRow: position.row) - - if bookmarks and bookmarks.length - bookmark.destroy() for bookmark in bookmarks - else - newmark = @createBookmarkMarker(position.row) - - @renderBookmarkMarkers() - - jumpToNextBookmark: => - @jumpToBookmark('getNextBookmark') - - jumpToPreviousBookmark: => - @jumpToBookmark('getPreviousBookmark') - - renderBookmarkMarkers: => - return unless @gutter.isVisible() - - @gutter.find(".line-number.bookmarked").removeClass('bookmarked') - - markers = @findBookmarkMarkers() - for marker in markers - row = marker.getBufferRange().start.row - @gutter.find(".line-number[lineNumber=#{row}]").addClass('bookmarked') - - ### Internal ### - - jumpToBookmark: (getBookmarkFunction) => - cursor = @editor.getCursor() - position = cursor.getBufferPosition() - bookmarkMarker = @[getBookmarkFunction](position.row) - - if bookmarkMarker - @editor.activeEditSession.setSelectedBufferRange(bookmarkMarker.getBufferRange(), autoscroll: true) + toggle: -> + if @hasParent() + @cancel() else - shell.beep() + @populateBookmarks() + @attach() - getPreviousBookmark: (bufferRow) -> - markers = @findBookmarkMarkers() - return null unless markers.length - return markers[0] if markers.length == 1 + getFilterText: (bookmark) -> + segments = [] + bookmarkRow = bookmark.getStartPosition().row + segments.push(bookmarkRow) + if bufferPath = bookmark.buffer.getPath() + segments.push(bufferPath) + if lineText = @getLineText(bookmark) + segments.push(lineText) + segments.join(' ') - bookmarkIndex = _.sortedIndex markers, bufferRow, (marker) -> - if marker.getBufferRange then marker.getBufferRange().start.row else marker + getLineText: (bookmark) -> + bookmark.buffer.lineForRow(bookmark.getStartPosition().row)?.trim() - bookmarkIndex-- - bookmarkIndex = markers.length - 1 if bookmarkIndex < 0 + populateBookmarks: -> + markers = [] + attributes = class: 'bookmark' + for buffer in project.getBuffers() + for marker in buffer.findMarkers(attributes) + marker.bookmarkFilterText = @getFilterText(marker) + markers.push(marker) + @setArray(markers) - markers[bookmarkIndex] + itemForElement: (bookmark) -> + bookmarkRow = bookmark.getStartPosition().row + if filePath = bookmark.buffer.getPath() + bookmarkLocation = "#{path.basename(filePath)}:#{bookmarkRow + 1}" + else + bookmarkLocation = "untitled:#{bookmarkRow + 1}" + lineText = @getLineText(bookmark) - getNextBookmark: (bufferRow) -> - markers = @findBookmarkMarkers() - return null unless markers.length - return markers[0] if markers.length == 1 + $$ -> + if lineText + @li class: 'bookmark two-lines', => + @div bookmarkLocation, class: 'primary-line' + @div lineText, class: 'secondary-line line-text' + else + @li class: 'bookmark', => + @div bookmarkLocation, class: 'primary-line' - bookmarkIndex = _.sortedIndex markers, bufferRow, (marker) -> - if marker.getBufferRange then marker.getBufferRange().start.row else marker + getEmptyMessage: (itemCount) -> + if itemCount is 0 + 'No bookmarks found' + else + super - bookmarkIndex++ if markers[bookmarkIndex] and markers[bookmarkIndex].getBufferRange().start.row == bufferRow - bookmarkIndex = 0 if bookmarkIndex >= markers.length + confirmed : (bookmark) -> + for editor in rootView.getEditors() + if editor.getBuffer() is bookmark.buffer + editor.activeEditSession.setSelectedBufferRange(bookmark.getRange(), autoscroll: true) - markers[bookmarkIndex] + attach: -> + super - createBookmarkMarker: (bufferRow) -> - range = [[bufferRow, 0], [bufferRow, 0]] - - # TODO: use the 'surround' strategy when collaboration is merged in - @displayBuffer().markBufferRange(range, @bookmarkMarkerAttributes(invalidationStrategy: 'never')) - - findBookmarkMarkers: (attributes={}) -> - @displayBuffer().findMarkers(@bookmarkMarkerAttributes(attributes)) - - bookmarkMarkerAttributes: (attributes={}) -> - _.extend(attributes, class: 'bookmark', displayBufferId: @displayBuffer().id) - - displayBuffer: -> - @editor.activeEditSession.displayBuffer + rootView.append(this) + @miniEditor.focus() diff --git a/src/packages/bookmarks/lib/bookmarks.coffee b/src/packages/bookmarks/lib/bookmarks.coffee new file mode 100644 index 000000000..d43486af8 --- /dev/null +++ b/src/packages/bookmarks/lib/bookmarks.coffee @@ -0,0 +1,108 @@ +_ = require 'underscore' +shell = require 'shell' + +module.exports = +class Bookmarks + @activate: -> + bookmarksList = null + + rootView.command 'bookmarks:view-all', -> + unless bookmarksList? + BookmarksListView = require './bookmarks-view' + bookmarksList = new BookmarksListView() + bookmarksList.toggle() + + rootView.eachEditor (editor) -> + new Bookmarks(editor) if editor.attached and editor.getPane()? + + editor: null + + constructor: (@editor) -> + @gutter = @editor.gutter + @editor.on 'editor:display-updated', @renderBookmarkMarkers + + @editor.command 'bookmarks:toggle-bookmark', @toggleBookmark + @editor.command 'bookmarks:jump-to-next-bookmark', @jumpToNextBookmark + @editor.command 'bookmarks:jump-to-previous-bookmark', @jumpToPreviousBookmark + + toggleBookmark: => + cursors = @editor.getCursors() + for cursor in cursors + position = cursor.getBufferPosition() + bookmarks = @findBookmarkMarkers(startBufferRow: position.row) + + if bookmarks and bookmarks.length + bookmark.destroy() for bookmark in bookmarks + else + newmark = @createBookmarkMarker(position.row) + + @renderBookmarkMarkers() + + jumpToNextBookmark: => + @jumpToBookmark('getNextBookmark') + + jumpToPreviousBookmark: => + @jumpToBookmark('getPreviousBookmark') + + renderBookmarkMarkers: => + return unless @gutter.isVisible() + + @gutter.find(".line-number.bookmarked").removeClass('bookmarked') + + markers = @findBookmarkMarkers() + for marker in markers + row = marker.getBufferRange().start.row + @gutter.find(".line-number[lineNumber=#{row}]").addClass('bookmarked') + + ### Internal ### + + jumpToBookmark: (getBookmarkFunction) => + cursor = @editor.getCursor() + position = cursor.getBufferPosition() + bookmarkMarker = @[getBookmarkFunction](position.row) + + if bookmarkMarker + @editor.activeEditSession.setSelectedBufferRange(bookmarkMarker.getBufferRange(), autoscroll: true) + else + shell.beep() + + getPreviousBookmark: (bufferRow) -> + markers = @findBookmarkMarkers() + return null unless markers.length + return markers[0] if markers.length == 1 + + bookmarkIndex = _.sortedIndex markers, bufferRow, (marker) -> + if marker.getBufferRange then marker.getBufferRange().start.row else marker + + bookmarkIndex-- + bookmarkIndex = markers.length - 1 if bookmarkIndex < 0 + + markers[bookmarkIndex] + + getNextBookmark: (bufferRow) -> + markers = @findBookmarkMarkers() + return null unless markers.length + return markers[0] if markers.length == 1 + + bookmarkIndex = _.sortedIndex markers, bufferRow, (marker) -> + if marker.getBufferRange then marker.getBufferRange().start.row else marker + + bookmarkIndex++ if markers[bookmarkIndex] and markers[bookmarkIndex].getBufferRange().start.row == bufferRow + bookmarkIndex = 0 if bookmarkIndex >= markers.length + + markers[bookmarkIndex] + + createBookmarkMarker: (bufferRow) -> + range = [[bufferRow, 0], [bufferRow, 0]] + + # TODO: use the 'surround' strategy when collaboration is merged in + @displayBuffer().markBufferRange(range, @bookmarkMarkerAttributes(invalidationStrategy: 'never')) + + findBookmarkMarkers: (attributes={}) -> + @displayBuffer().findMarkers(@bookmarkMarkerAttributes(attributes)) + + bookmarkMarkerAttributes: (attributes={}) -> + _.extend(attributes, class: 'bookmark', displayBufferId: @displayBuffer().id) + + displayBuffer: -> + @editor.activeEditSession.displayBuffer diff --git a/src/packages/bookmarks/package.cson b/src/packages/bookmarks/package.cson index b5f2b67c1..936fa10fe 100644 --- a/src/packages/bookmarks/package.cson +++ b/src/packages/bookmarks/package.cson @@ -1,2 +1,2 @@ -'main': './lib/bookmarks-view' +'main': './lib/bookmarks' 'description': 'Can mark lines, then jump back to them'