context menu on tab and "close all except for this tab"

This commit is contained in:
zadam 2019-05-07 21:34:01 +02:00
parent aef0e552a0
commit 4ea27e604f
3 changed files with 30 additions and 0 deletions

View file

@ -277,6 +277,14 @@
this.setupDraggabilly()
}
removeAllTabsExceptForThis(remainingTabEl) {
for (const tabEl of this.tabEls) {
if (remainingTabEl !== tabEl) {
this.removeTab(tabEl);
}
}
}
updateTab(tabEl, tabProperties) {
tabEl.querySelector('.chrome-tab-title').textContent = tabProperties.title

View file

@ -2,6 +2,10 @@ const $contextMenuContainer = $("#context-menu-container");
let dateContextMenuOpenedMs = 0;
/**
* @param event - originating click event (used to get coordinates to display menu at position)
* @param {object} contextMenu - needs to have getContextMenuItems() and selectContextMenuItem(e, cmd)
*/
async function initContextMenu(event, contextMenu) {
event.stopPropagation();

View file

@ -8,6 +8,7 @@ import NoteFull from "../entities/note_full.js";
import bundleService from "./bundle.js";
import utils from "./utils.js";
import importDialog from "../dialogs/import.js";
import contextMenuService from "./context_menu.js";
const chromeTabsEl = document.querySelector('.chrome-tabs');
const chromeTabs = new ChromeTabs();
@ -263,6 +264,23 @@ chromeTabsEl.addEventListener('tabRemove', ({ detail }) => {
console.log(`Removed tab ${tabId}`);
});
$(chromeTabsEl).on('contextmenu', '.chrome-tab', e => {
const tab = $(e.target).closest(".chrome-tab");
contextMenuService.initContextMenu(e, {
getContextMenuItems: () => {
return [
{title: "Close all tabs except for this", cmd: "removeAllTabsExceptForThis", uiIcon: "empty"}
];
},
selectContextMenuItem: (e, cmd) => {
if (cmd === 'removeAllTabsExceptForThis') {
chromeTabs.removeAllTabsExceptForThis(tab[0]);
}
}
});
});
if (utils.isElectron()) {
utils.bindShortcut('ctrl+w', () => {
if (noteContexts.length === 1) {