Skip to content

Commit

Permalink
shelf
Browse files Browse the repository at this point in the history
  • Loading branch information
monsterkodi committed Jun 3, 2019
1 parent 305056c commit db439a8
Show file tree
Hide file tree
Showing 22 changed files with 493 additions and 401 deletions.
12 changes: 11 additions & 1 deletion coffee/browser/column.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class Column
openFileInNewWindow: ->

if item = @activeRow()?.item
if item.type == 'file' and item.textFile
if item.type == 'file' and item.textFile and item.file
post.emit 'openFiles', [item.file], newWindow: true
@

Expand Down Expand Up @@ -340,6 +340,12 @@ class Column

trash([pathToTrash]).catch (err) -> error "failed to trash #{pathToTrash} #{err}"

addToShelf: =>

if pathToShelf = @activePath()
post.emit 'addToShelf', pathToShelf
window.split.focus 'shelf'

duplicateFile: =>

unusedFilename = require 'unused-filename'
Expand Down Expand Up @@ -419,6 +425,10 @@ class Column
text: 'Move to Trash'
combo: 'ctrl+backspace'
cb: @moveToTrash
,
text: 'Add to Shelf'
combo: 'alt+shift+.'
cb: @addToShelf
,
text: 'Explorer'
combo: 'alt+e'
Expand Down
34 changes: 18 additions & 16 deletions coffee/browser/shelf.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ Scroller = require './scroller'
Column = require './column'
fuzzy = require 'fuzzy'
hub = require '../git/hub'

indexAndItemInItemsWithFunc = (item, items, withFunc) ->

for index in [0...items.length]
if withFunc items[index], item
return [index, items[index]]
return [-1,null]

class Shelf extends Column

Expand All @@ -31,7 +24,7 @@ class Shelf extends Column
@index = -1
@div.id = 'shelf'

@showHistory = window.stash.get 'shelf:history', false
@showHistory = window.stash.get 'shelf:history', true

post.on 'gitStatus', @loadGitStatus
post.on 'addToShelf', @addPath
Expand Down Expand Up @@ -71,12 +64,15 @@ class Shelf extends Column
onFile: (file) =>

return if empty file

[index, item] = indexAndItemInItemsWithFunc file, @items, (f,i) -> i.file == f
if item
@rows[index].setActive()
if @navigatingRows
delete @navigatingRows
return


for index in [0...@items.length]
if @items[index].file == file
@rows[index].setActive()
return

matches = []
for index,item of @items
if file?.startsWith item.file
Expand Down Expand Up @@ -257,14 +253,16 @@ class Shelf extends Column
@removeRow @row(@numRows()-1)

onNavigateHistoryChanged: (filePositions, currentIndex) =>

if @showHistory
@setHistoryItems filePositions

onNavigateIndexChanged: (currentIndex, currentItem) =>

if @showHistory
reverseIndex = @numRows() - currentIndex - 1
@row(reverseIndex)?.setActive()
if currentItem.file != @activeRow()?.item.file
@row(reverseIndex)?.setActive()

loadHistory: ->

Expand Down Expand Up @@ -335,8 +333,12 @@ class Shelf extends Column

kerror "no row at index #{index}/#{@numRows()-1}?", @numRows() if not @rows[index]?.activate?

if key == 'up' and index > @items.length then post.emit 'menuAction', 'Navigate Forward'
else if key == 'down' and index > @items.length + 1 then post.emit 'menuAction', 'Navigate Backward'
navigate = (action) =>
@navigatingRows = true
post.emit 'menuAction', action

if key == 'up' and index > @items.length then navigate 'Navigate Forward'
else if key == 'down' and index > @items.length + 1 then navigate 'Navigate Backward'
else @rows[index].activate()

openFileInNewWindow: ->
Expand Down
2 changes: 1 addition & 1 deletion coffee/commands/browse.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Browse extends Command
@browser.start()

if action != 'shelf'
if window.editor.currentFile?
if window.editor.currentFile? and slash.isFile window.editor.currentFile
@browser.navigateToFile window.editor.currentFile
else
post.emit 'filebrowser', 'loadItem', file:process.cwd(), type:'dir'
Expand Down
16 changes: 6 additions & 10 deletions coffee/editor/editor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class Editor extends Buffer

Editor.initActions() if not Editor.actions?

@indentString = _.padStart "", 4
@stickySelection = false
@syntax = new Syntax @config.syntaxName, @line, @lines
@do = new Do @
@indentString = _.padStart "", 4
@stickySelection = false
@syntax = new Syntax @config.syntaxName, @line, @lines
@do = new Do @

@setupFileType()

Expand All @@ -46,7 +46,7 @@ class Editor extends Buffer
@initActions: ->

@actions = []
for actionFile in filelist slash.join __dirname, 'actions'
for actionFile in filelist(slash.join __dirname, 'actions')
continue if slash.ext(actionFile) not in ['js', 'coffee']
actions = require actionFile
for key,value of actions
Expand All @@ -66,11 +66,7 @@ class Editor extends Buffer
for action in Editor.actions
if action.name == name
return action

# log "can't find action with name '#{name}'"
# for action in Editor.actions
# log action.name
return null
null

# 000000000 000 000 00000000 00000000
# 000 000 000 000 000 000
Expand Down
92 changes: 48 additions & 44 deletions coffee/editor/fileeditor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
###

{ post, stopEvent, setStyle, srcmap, popup, slash, empty, clamp, kpos, fs, kerror, _ } = require 'kxk'

Watcher = require '../tools/watcher'
TextEditor = require './texteditor'
Syntax = require './syntax'
Expand All @@ -17,7 +17,7 @@ class FileEditor extends TextEditor

constructor: (viewElem) ->

super viewElem,
super viewElem,
features: [
'Diffbar'
'Scrollbar'
Expand All @@ -35,7 +35,7 @@ class FileEditor extends TextEditor
@watch = null

@view.addEventListener "contextmenu", @onContextMenu

post.on 'commandline', @onCommandline
post.on 'jumpTo', @jumpTo
post.on 'jumpToFile', @jumpToFile
Expand Down Expand Up @@ -65,8 +65,8 @@ class FileEditor extends TextEditor
# 000 000 000 000
# 000 000 0000000 00000000

clear: ->
clear: ->

@dirty = false
@setSalterMode false
@stopWatcher()
Expand All @@ -83,7 +83,7 @@ class FileEditor extends TextEditor
@currentFile = file

@setupFileType()

fileExists = @currentFile? and slash.fileExists @currentFile

if restoreState
Expand All @@ -95,13 +95,13 @@ class FileEditor extends TextEditor

if fileExists
@watch = new Watcher @currentFile

post.emit 'file', @currentFile # browser & shelf

@emit 'file', @currentFile # diffbar, pigments, ...

post.emit 'dirty', @dirty

restoreFromTabState: (tabsState) ->

return kerror "no tabsState.file?" if not tabsState.file?
Expand All @@ -112,25 +112,25 @@ class FileEditor extends TextEditor
@watch?.stop()
@watch = null

# 000000000 000 000 00000000 00000000
# 000 000 000 000 000 000
# 000 00000 00000000 0000000
# 000 000 000 000
# 000 000 000 00000000
# 000000000 000 000 00000000 00000000
# 000 000 000 000 000 000
# 000 00000 00000000 0000000
# 000 000 000 000
# 000 000 000 00000000

shebangFileType: ->

fileType = Syntax.shebang @line(0) if @numLines()
if fileType == 'txt'
if fileType == 'txt'
if @currentFile?
ext = slash.ext @currentFile
if ext in Syntax.syntaxNames
return ext
else if fileType
return fileType

super()

# 0000000 0000000 00 00 00 00 0000000 000 000 0000000 000 000 000 000 00000000
# 000 000 000 000 000 000 000 000 000 0000 000 000 000 000 000 0000 000 000
# 000 000 000 000000000 000000000 000000000 000 0 000 000 000 000 000 000 0 000 0000000
Expand Down Expand Up @@ -185,18 +185,18 @@ class FileEditor extends TextEditor
if filePositions[@currentFile]?

s = filePositions[@currentFile]

cursors = s.cursors ? [[0,0]]
cursors = cursors.map (c) => [c[0], clamp(0,@numLines()-1,c[1])]

@setCursors cursors
@setSelections s.selections ? []
@setHighlights s.highlights ? []
@setMain s.main ? 0
@setState @state

@syntax.fillDiss @mainCursor()[1]

@scroll.to s.scroll if s.scroll
@scroll.cursorIntoView()

Expand All @@ -221,16 +221,20 @@ class FileEditor extends TextEditor
# 0000000 0000000 000 000 000

jumpToFile: (opt) =>


window.tabs.activeTab true

# log 'jumpToFile', require('kxk').noon.stringify opt

if opt.newTab

file = opt.file
file += ':' + opt.line if opt.line
file += ':' + opt.col if opt.col
post.emit 'newTabWithFile', file

else

[file, fpos] = slash.splitFilePos opt.file
opt.pos = fpos
opt.pos[0] = opt.col if opt.col
Expand Down Expand Up @@ -389,23 +393,23 @@ class FileEditor extends TextEditor
else
@updateLayers()

# 00000000 0000000 00000000 000 000 00000000
# 000 000 000 000 000 000 000 000 000 000
# 00000000 000 000 00000000 000 000 00000000
# 000 000 000 000 000 000 000
# 000 0000000 000 0000000 000
# 00000000 0000000 00000000 000 000 00000000
# 000 000 000 000 000 000 000 000 000 000
# 00000000 000 000 00000000 000 000 00000000
# 000 000 000 000 000 000 000
# 000 0000000 000 0000000 000

onContextMenu: (event) => stopEvent event, @showContextMenu kpos event

showContextMenu: (absPos) =>

if not absPos?
absPos = kpos @view.getBoundingClientRect().left, @view.getBoundingClientRect().top

opt = items: [
text: 'Browse'
combo: 'command+.'
accel: 'ctrl+.'
combo: 'command+.'
accel: 'ctrl+.'
cb: -> window.commandline.startCommand 'browse'
,
text: 'Back'
Expand All @@ -415,19 +419,19 @@ class FileEditor extends TextEditor
text: ''
,
text: 'Maximize'
combo: 'command+shift+y'
accel: 'ctrl+shift+y'
combo: 'command+shift+y'
accel: 'ctrl+shift+y'
cb: -> window.split.maximizeEditor()
,
text: ''
,
text: ''
]

opt.items = opt.items.concat window.titlebar.menuTemplate()

opt.x = absPos.x
opt.y = absPos.y
popup.menu opt

# 0000000 000 000 0000000 000 000
# 000 000 000 000 000 000
# 000 000 000 000 0000000
Expand All @@ -450,7 +454,7 @@ class FileEditor extends TextEditor
# 000 000 00000000 000

handleModKeyComboCharEvent: (mod, key, combo, char, event) ->

return if 'unhandled' != super mod, key, combo, char, event
switch combo
when 'alt+ctrl+enter' then return window.commandline.commands.coffee.executeText @textOfSelectionForClipboard()
Expand Down
Loading

0 comments on commit db439a8

Please sign in to comment.