Skip to content

Commit

Permalink
feature: add shortcut 'Ctrl + W': close current tab / window
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksey-hoffman committed Sep 11, 2021
1 parent f783b62 commit 9e08e4e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,23 @@ export default {
shortcut: 'Ctrl + T',
description: 'New tab in current workspace'
},
closeCurrentTab: {
isGlobal: false,
isReadOnly: false,
conditions: {
dirItemIsSelected: true,
dialogIsOpened: false
},
routes: ['navigator'],
icon: 'mdi-tab-remove',
iconSize: '20px',
action: {
name: 'CLOSE_CURRENT_TAB',
options: 'selected'
},
shortcut: 'Ctrl + W',
description: 'Close current tab / window'
},
scrollTop: {
isGlobal: false,
isReadOnly: false,
Expand Down
35 changes: 32 additions & 3 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2755,15 +2755,44 @@ export default new Vuex.Store({
tabs = []
dispatch('SET_TABS', tabs)
},
CLOSE_TAB ({ state, commit, dispatch, getters }, tab) {
let tabs = [...getters.selectedWorkspace.tabs]
CLOSE_CURRENT_TAB (store) {
let tabs = [...store.getters.selectedWorkspace.tabs]
const currentDirTab = tabs.find(item => item.path === store.state.navigatorView.currentDir.path)
if (currentDirTab) {
store.dispatch('CLOSE_TAB', currentDirTab)
}
if (tabs.length === 0) {
eventHub.$emit('notification', {
action: 'update-by-type',
type: 'current-workspace-has-no-tabs',
timeout: 3000,
type: '',
closeButton: true,
title: 'Current workspace has no tabs'
})
}
},
CLOSE_TAB (store, tab) {
if (!tab?.path) {return}
let tabs = [...store.getters.selectedWorkspace.tabs]
const tabIndex = tabs.findIndex(item => item.path === tab.path)
const tabExists = tabIndex !== -1
// Remove tab
if (tabExists) {
tabs.splice(tabIndex, 1)
store.dispatch('SET_TABS', tabs)
new Notification({
name: 'tabRemoved',
format: {
tabPath: tab.path
}
})
// Switch tab
const currentDirTabIndex = tabs.findIndex(item => item.path === store.state.navigatorView.currentDir.path)
if (currentDirTabIndex === -1 && tabs.length > 0) {
store.dispatch('SWITCH_TAB', tabs.length)
}
}
dispatch('SET_TABS', tabs)
},
ADD_TAB ({ state, commit, dispatch, getters }) {
let item = state.navigatorView.selectedDirItems.getLast()
Expand Down
8 changes: 8 additions & 0 deletions src/utils/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ class Notification {
title: 'Rename undone',
message: ''
},
tabRemoved: {
action: 'update-by-type',
type: 'tab-removed',
timeout: 3000,
closeButton: true,
title: 'Removed tab from current workspace',
message: `{{tabPath}}`
},
}

this.data = this.notifications[params.name]
Expand Down

0 comments on commit 9e08e4e

Please sign in to comment.