#238 menu command - close tabs x current DB

This commit is contained in:
Jan Prochazka
2022-03-03 11:28:16 +01:00
parent fac78afa31
commit be90241091
2 changed files with 41 additions and 3 deletions

View File

@@ -22,8 +22,10 @@ module.exports = [
{
label: 'Window',
submenu: [
{ command: 'tabs.closeTab', hideDisabled: true },
{ command: 'tabs.closeAll', hideDisabled: true },
{ command: 'tabs.closeTab', hideDisabled: false },
{ command: 'tabs.closeAll', hideDisabled: false },
{ command: 'tabs.closeTabsWithCurrentDb', hideDisabled: false },
{ command: 'tabs.closeTabsButCurrentDb', hideDisabled: false },
{ divider: true },
{ command: 'app.zoomIn', hideDisabled: true },
{ command: 'app.zoomOut', hideDisabled: true },

View File

@@ -53,6 +53,18 @@
}))
);
};
const closeTabsWithCurrentDb = () => {
const db = getCurrentDatabase();
closeMultipleTabs(tab => {
return db?.connection?._id == tab?.props?.conid && db?.name == tab?.props?.database;
});
};
const closeTabsButCurrentDb = () => {
const db = getCurrentDatabase();
closeMultipleTabs(tab => {
return db?.connection?._id != tab?.props?.conid || db?.name != tab?.props?.database;
});
};
const closeCurrentTab = () => {
closeTab(getActiveTabId());
};
@@ -117,6 +129,22 @@
onClick: closeCurrentTab,
});
registerCommand({
id: 'tabs.closeTabsWithCurrentDb',
category: 'Tabs',
name: 'Close tabs with current DB',
testEnabled: () => getOpenedTabs().filter(x => !x.closedTime).length >= 1 && !!getCurrentDatabase(),
onClick: closeTabsWithCurrentDb,
});
registerCommand({
id: 'tabs.closeTabsButCurrentDb',
category: 'Tabs',
name: 'Close tabs but current DB',
testEnabled: () => getOpenedTabs().filter(x => !x.closedTime).length >= 1 && !!getCurrentDatabase(),
onClick: closeTabsButCurrentDb,
});
registerCommand({
id: 'tabs.addToFavorites',
category: 'Tabs',
@@ -143,7 +171,15 @@
import { showModal } from '../modals/modalTools';
import newQuery from '../query/newQuery';
import { currentDatabase, getActiveTab, getOpenedTabs, openedTabs, activeTabId, getActiveTabId } from '../stores';
import {
currentDatabase,
getActiveTab,
getOpenedTabs,
openedTabs,
activeTabId,
getActiveTabId,
getCurrentDatabase,
} from '../stores';
import tabs from '../tabs';
import { setSelectedTab } from '../utility/common';
import contextMenu from '../utility/contextMenu';