Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2126cd2
Confirm pending item when tab is clicked
kuychaco Dec 24, 2015
6173652
Create preview tab if item is pending
kuychaco Dec 24, 2015
66323ef
Check existence before function invocation
kuychaco Dec 24, 2015
4db8908
Update specs for pending tab functionality
kuychaco Dec 24, 2015
2142a5c
Remove Use Preview Tab setting
kuychaco Dec 24, 2015
07abe60
Fix bug - activate item on tab click
kuychaco Dec 25, 2015
f4318f0
Rename onDidConfirmPendingState for clarity
kuychaco Dec 25, 2015
0eb16e2
Use 'waits' before cleanup due to async nature
kuychaco Dec 28, 2015
be7f102
Fix bug: invoke isPending only if exists
kuychaco Dec 31, 2015
6ce80d5
Fix tests
kuychaco Dec 31, 2015
19325f6
Remove test
kuychaco Jan 5, 2016
929a790
Make tests backwards compatible
kuychaco Jan 6, 2016
205b3d4
:non-potable_water: Remove listener with same function that was added
kuychaco Jan 8, 2016
8910c47
Make keep-preview-tab command confirm pending state and fix test
kuychaco Jan 8, 2016
8df7626
Remove unneccessary spec handled in tree-view
kuychaco Jan 8, 2016
55547e6
Replace 'preview' with 'pending'
kuychaco Jan 10, 2016
873f884
Clean out old previewTabs code
kuychaco Jan 10, 2016
3cd0385
In spec, explicitly wait for pane to be activated
maxbrunsfeld Jan 13, 2016
9cd8a49
Guard against activating destroyed panes when a tab is clicked
maxbrunsfeld Jan 13, 2016
ad38a61
:white_check_mark: Keep pending pane upon losing focus
kuychaco Jan 14, 2016
1a3f53f
Fix tests for pending state
kuychaco Jan 14, 2016
23484f7
:art: Use double quotes for describe and it statements
kuychaco Jan 14, 2016
66a1f74
Remove code for ensuring only one pending tab
kuychaco Jan 15, 2016
0ad1fa1
Make tab permanent on double click
kuychaco Jan 15, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions lib/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,29 @@ module.exports =
type: 'integer'
default: 120
description: 'Threshold for switching to the next/previous tab when the `Tab Scrolling` config setting is enabled. Higher numbers mean that a longer scroll is needed to jump to the next/previous tab.'
usePreviewTabs:
type: 'boolean'
default: false
description: 'Tabs will only stay open if they\'re double-clicked or their contents is modified.'
enableVcsColoring:
title: "Enable VCS Coloring"
type: 'boolean'
default: false
description: 'Color file names in tabs based on VCS status, similar to how file names are colored in the tree view.'

activate: (state) ->
state = [] unless Array.isArray(state)
@tabBarViews = []

TabBarView = require './tab-bar-view'
_ = require 'underscore-plus'

@paneSubscription = atom.workspace.observePanes (pane) =>
tabBarView = new TabBarView
tabBarView.initialize(pane, state.shift())
tabBarView.initialize(pane)

paneElement = atom.views.getView(pane)
paneElement.insertBefore(tabBarView, paneElement.firstChild)

@tabBarViews.push(tabBarView)
pane.onDidDestroy => _.remove(@tabBarViews, tabBarView)

state = [] # Reset state so it only affects the initial panes observed

deactivate: ->
@paneSubscription.dispose()
tabBarView.remove() for tabBarView in @tabBarViews
return

serialize: ->
@tabBarViews.map (tabBarView) ->
previewTabURI: tabBarView.getPreviewTabURI()
62 changes: 13 additions & 49 deletions lib/tab-bar-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class TabBarView extends HTMLElement
@classList.add("inset-panel")
@setAttribute("tabindex", -1)

initialize: (@pane, state={}) ->
initialize: (@pane) ->
@subscriptions = new CompositeDisposable

@subscriptions.add atom.commands.add atom.views.getView(@pane),
'tabs:keep-preview-tab': => @clearPreviewTabs()
'tabs:keep-pending-tab': => @terminatePendingStates()
'tabs:close-tab': => @closeTab(@getActiveTab())
'tabs:close-other-tabs': => @closeOtherTabs(@getActiveTab())
'tabs:close-tabs-to-right': => @closeTabsToRight(@getActiveTab())
Expand Down Expand Up @@ -53,7 +53,6 @@ class TabBarView extends HTMLElement

@paneContainer = @pane.getContainer()
@addTabForItem(item) for item in @pane.getItems()
@setInitialPreviewTab(state.previewTabURI)

@subscriptions.add @pane.onDidDestroy =>
@unsubscribe()
Expand All @@ -68,71 +67,33 @@ class TabBarView extends HTMLElement
@removeTabForItem(item)

@subscriptions.add @pane.onDidChangeActiveItem (item) =>
@destroyPreviousPreviewTab()
@updateActiveTab()

@subscriptions.add atom.config.observe 'tabs.tabScrolling', => @updateTabScrolling()
@subscriptions.add atom.config.observe 'tabs.tabScrollingThreshold', => @updateTabScrollingThreshold()
@subscriptions.add atom.config.observe 'tabs.alwaysShowTabBar', => @updateTabBarVisibility()

@handleTreeViewEvents()

@updateActiveTab()

@addEventListener "mousedown", @onMouseDown
@addEventListener "dblclick", @onDoubleClick
@addEventListener "click", @onClick

ipcRenderer.on('tab:dropped', @onDropOnOtherWindow.bind(this))
@onDropOnOtherWindow = @onDropOnOtherWindow.bind(this)
ipcRenderer.on('tab:dropped', @onDropOnOtherWindow)

unsubscribe: ->
ipcRenderer.removeListener('tab:dropped', @onDropOnOtherWindow.bind(this))
ipcRenderer.removeListener('tab:dropped', @onDropOnOtherWindow)
@subscriptions.dispose()

handleTreeViewEvents: ->
treeViewSelector = '.tree-view .entry.file'
clearPreviewTabForFile = ({target}) =>
return unless @pane.isFocused()
return unless matches(target, treeViewSelector)

target = target.querySelector('[data-path]') unless target.dataset.path

if itemPath = target.dataset.path
@tabForItem(@pane.itemForURI(itemPath))?.clearPreview()

document.body.addEventListener('dblclick', clearPreviewTabForFile)
@subscriptions.add dispose: ->
document.body.removeEventListener('dblclick', clearPreviewTabForFile)

setInitialPreviewTab: (previewTabURI) ->
for tab in @getTabs() when tab.isPreviewTab
tab.clearPreview() if tab.item.getURI() isnt previewTabURI
return

getPreviewTabURI: ->
for tab in @getTabs() when tab.isPreviewTab
return tab.item.getURI()
terminatePendingStates: ->
tab.terminatePendingState?() for tab in @getTabs()
return

clearPreviewTabs: ->
tab.clearPreview() for tab in @getTabs()
return

storePreviewTabToDestroy: ->
for tab in @getTabs() when tab.isPreviewTab
@previewTabToDestroy = tab
return

destroyPreviousPreviewTab: ->
if @previewTabToDestroy?.isPreviewTab
@pane.destroyItem(@previewTabToDestroy.item)
@previewTabToDestroy = null

addTabForItem: (item, index) ->
tabView = new TabView()
tabView.initialize(item)
tabView.clearPreview() if @isItemMovingBetweenPanes
@storePreviewTabToDestroy() if tabView.isPreviewTab
tabView.terminatePendingState() if @isItemMovingBetweenPanes
@insertTabAtIndex(tabView, index)

moveItemTabToIndex: (item, index) ->
Expand Down Expand Up @@ -374,13 +335,16 @@ class TabBarView extends HTMLElement
event.preventDefault()
else if event.which is 1 and not event.target.classList.contains('close-icon')
@pane.activateItem(tab.item)
setImmediate => @pane.activate()
setImmediate => @pane.activate() unless @pane.isDestroyed()
else if event.which is 2
@pane.destroyItem(tab.item)
event.preventDefault()

onDoubleClick: (event) ->
if event.target is this
if tab = closest(event.target, '.tab')
tab.item.terminatePendingState?()

else if event.target is this
atom.commands.dispatch(this, 'application:new-file')
event.preventDefault()

Expand Down
26 changes: 17 additions & 9 deletions lib/tab-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TabView extends HTMLElement
initialize: (@item) ->
if typeof @item.getPath is 'function'
@path = @item.getPath()
@isPreviewTab = atom.config.get('tabs.usePreviewTabs')
@isPendingTab = @item.isPending?()

@classList.add('tab', 'sortable')

Expand All @@ -27,17 +27,23 @@ class TabView extends HTMLElement
@updateModifiedStatus()
@setupTooltip()

if @isPreviewTab
if @isPendingTab
@itemTitle.classList.add('temp')
@classList.add('preview-tab')
@addEventListener 'dblclick', => @clearPreview()
@classList.add('pending-tab')

handleEvents: ->
titleChangedHandler = =>
@updateDataAttributes()
@updateTitle()
@updateTooltip()

if typeof @item.onDidTerminatePendingState is 'function'
onDidTerminatePendingStateDisposable = @item.onDidTerminatePendingState => @clearPending()
if Disposable.isDisposable(onDidTerminatePendingStateDisposable)
@subscriptions.add(onDidTerminatePendingStateDisposable)
else
console.warn "::onDidTerminatePendingState does not return a valid Disposable!", @item

if typeof @item.onDidChangeTitle is 'function'
onDidChangeTitleDisposable = @item.onDidChangeTitle(titleChangedHandler)
if Disposable.isDisposable(onDidChangeTitleDisposable)
Expand Down Expand Up @@ -83,7 +89,7 @@ class TabView extends HTMLElement

if typeof @item.onDidSave is 'function'
onDidSaveDisposable = @item.onDidSave (event) =>
@clearPreview()
@terminatePendingState()
if event.path isnt @path
@path = event.path
@setupVcsStatus() if atom.config.get 'tabs.enableVcsColoring'
Expand Down Expand Up @@ -183,10 +189,13 @@ class TabView extends HTMLElement
getTabs: ->
@parentElement?.querySelectorAll('.tab') ? []

clearPreview: ->
@isPreviewTab = false
terminatePendingState: ->
@item.terminatePendingState?()

clearPending: ->
@isPendingTab = false
@itemTitle.classList.remove('temp')
@classList.remove('preview-tab')
@classList.remove('pending-tab')

updateIconVisibility: ->
if atom.config.get 'tabs.showIcons'
Expand All @@ -196,7 +205,6 @@ class TabView extends HTMLElement

updateModifiedStatus: ->
if @item.isModified?()
@clearPreview()
@classList.add('modified') unless @isModified
@isModified = true
else
Expand Down
4 changes: 2 additions & 2 deletions menus/tabs.cson
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ menu: [
{label: 'Split Left', command: 'tabs:split-left'}
{label: 'Split Right', command: 'tabs:split-right'}
]
'.tab.preview-tab': [
{label: 'Keep Preview Tab', command: 'tabs:keep-preview-tab'}
'.tab.pending-tab': [
{label: 'Keep Pending Tab', command: 'tabs:keep-pending-tab'}
]
'.tab-bar': [
{label: 'Reopen Closed Tab', command: 'pane:reopen-closed-item'}
Expand Down
Loading