mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
fix AF-2068, AF-2069, AF-1175, AF-2061, AF-2079, AF-2034, AF-2080, AF-1960, AF-2081 1. replace `dnd-kit` with `@atlaskit/pragmatic-drag-and-drop` 2. allow creating split views by drag & drop the following a. WorkbenchLinks (route links), like journals, trash, all docs b. doc refs c. tags/collection 3. style adjustments to split view 4. remove split view's feature flag and make it GA for electron https://github.com/user-attachments/assets/6a3e4a25-faa2-4215-8eb0-983f44db6e8c
117 lines
2.8 KiB
TypeScript
117 lines
2.8 KiB
TypeScript
import { Menu } from 'electron';
|
|
|
|
import { logger } from '../logger';
|
|
import {
|
|
addTab,
|
|
closeTab,
|
|
reloadView,
|
|
type TabAction,
|
|
WebContentViewsManager,
|
|
} from './tab-views';
|
|
|
|
export const showTabContextMenu = async (
|
|
tabId: string,
|
|
viewIndex: number
|
|
): Promise<TabAction | null> => {
|
|
const workbenches = WebContentViewsManager.instance.tabViewsMeta.workbenches;
|
|
const tabMeta = workbenches.find(w => w.id === tabId);
|
|
if (!tabMeta) {
|
|
return null;
|
|
}
|
|
|
|
const { resolve, promise } = Promise.withResolvers<TabAction | null>();
|
|
|
|
const template: Parameters<typeof Menu.buildFromTemplate>[0] = [
|
|
tabMeta.pinned
|
|
? {
|
|
label: 'Unpin tab',
|
|
click: () => {
|
|
WebContentViewsManager.instance.pinTab(tabId, false);
|
|
},
|
|
}
|
|
: {
|
|
label: 'Pin tab',
|
|
click: () => {
|
|
WebContentViewsManager.instance.pinTab(tabId, true);
|
|
},
|
|
},
|
|
{
|
|
label: 'Refresh tab',
|
|
click: () => {
|
|
reloadView().catch(err => logger.error(err));
|
|
},
|
|
},
|
|
{
|
|
label: 'Duplicate tab',
|
|
click: () => {
|
|
addTab({
|
|
basename: tabMeta.basename,
|
|
view: tabMeta.views,
|
|
show: false,
|
|
}).catch(err => logger.error(err));
|
|
},
|
|
},
|
|
|
|
{ type: 'separator' },
|
|
|
|
tabMeta.views.length > 1
|
|
? {
|
|
label: 'Separate tabs',
|
|
click: () => {
|
|
WebContentViewsManager.instance.separateView(tabId, viewIndex);
|
|
},
|
|
}
|
|
: {
|
|
label: 'Open in split view',
|
|
click: () => {
|
|
WebContentViewsManager.instance.openInSplitView({ tabId });
|
|
},
|
|
},
|
|
|
|
...(workbenches.length > 1
|
|
? ([
|
|
{ type: 'separator' },
|
|
{
|
|
label: 'Close tab',
|
|
click: () => {
|
|
closeTab(tabId).catch(err => logger.error(err));
|
|
},
|
|
},
|
|
{
|
|
label: 'Close other tabs',
|
|
click: () => {
|
|
const tabsToRetain =
|
|
WebContentViewsManager.instance.tabViewsMeta.workbenches.filter(
|
|
w => w.id === tabId || w.pinned
|
|
);
|
|
|
|
WebContentViewsManager.instance.patchTabViewsMeta({
|
|
workbenches: tabsToRetain,
|
|
activeWorkbenchId: tabId,
|
|
});
|
|
},
|
|
},
|
|
] as const)
|
|
: []),
|
|
];
|
|
const menu = Menu.buildFromTemplate(template);
|
|
menu.popup();
|
|
let unsub: (() => void) | undefined;
|
|
const subscription = WebContentViewsManager.instance.tabAction$.subscribe(
|
|
action => {
|
|
resolve(action);
|
|
unsub?.();
|
|
}
|
|
);
|
|
menu.on('menu-will-close', () => {
|
|
setTimeout(() => {
|
|
resolve(null);
|
|
unsub?.();
|
|
});
|
|
});
|
|
unsub = () => {
|
|
subscription.unsubscribe();
|
|
};
|
|
return promise;
|
|
};
|