add to favorites moved from toolbar into tab context menu

This commit is contained in:
Jan Prochazka 2021-04-30 18:03:34 +02:00
parent 38aae142ea
commit 7b6ca27b66

View File

@ -87,9 +87,9 @@
registerCommand({ registerCommand({
id: 'tabs.addToFavorites', id: 'tabs.addToFavorites',
category: 'Tabs', category: 'Tabs',
name: 'Favorites', name: 'Add current tab to favorites',
icon: 'icon favorite', // icon: 'icon favorite',
toolbar: true, // toolbar: true,
testEnabled: () => testEnabled: () =>
getActiveTab()?.tabComponent && getActiveTab()?.tabComponent &&
tabs[getActiveTab()?.tabComponent] && tabs[getActiveTab()?.tabComponent] &&
@ -146,9 +146,10 @@
} }
}; };
const getContextMenu = (tabid, props) => () => { const getContextMenu = tab => () => {
const { tabid, props, tabComponent } = tab;
const { conid, database } = props || {}; const { conid, database } = props || {};
const res = [ return [
{ {
text: 'Close', text: 'Close',
onClick: () => closeTab(tabid), onClick: () => closeTab(tabid),
@ -161,20 +162,29 @@
text: 'Close others', text: 'Close others',
onClick: () => closeOthers(tabid), onClick: () => closeOthers(tabid),
}, },
tabComponent &&
tabs[tabComponent] &&
tabs[tabComponent].allowAddToFavorites &&
tabs[tabComponent].allowAddToFavorites(props) && [
{ divider: true },
{
text: 'Add to favorites',
onClick: () => showModal(FavoriteModal, { savingTab: tab }),
},
],
conid &&
database && [
{ divider: true },
{
text: `Close with same DB - ${database}`,
onClick: () => closeWithSameDb(tabid),
},
{
text: `Close with other DB than ${database}`,
onClick: () => closeWithOtherDb(tabid),
},
],
]; ];
if (conid && database) {
res.push(
{
text: `Close with same DB - ${database}`,
onClick: () => closeWithSameDb(tabid),
},
{
text: `Close with other DB than ${database}`,
onClick: () => closeWithOtherDb(tabid),
}
);
}
return res;
}; };
const handleSetDb = async props => { const handleSetDb = async props => {
@ -216,7 +226,7 @@
class:selected={tab.selected} class:selected={tab.selected}
on:click={e => handleTabClick(e, tab.tabid)} on:click={e => handleTabClick(e, tab.tabid)}
on:mouseup={e => handleMouseUp(e, tab.tabid)} on:mouseup={e => handleMouseUp(e, tab.tabid)}
use:contextMenu={getContextMenu(tab.tabid, tab.props)} use:contextMenu={getContextMenu(tab)}
> >
<FontIcon icon={tab.busy ? 'icon loading' : tab.icon} /> <FontIcon icon={tab.busy ? 'icon loading' : tab.icon} />
<span class="file-name"> <span class="file-name">