feat: when hide sidebar, show wiki operations directly inside context menu

This commit is contained in:
lin onetwo 2022-11-23 11:42:03 +08:00
parent ce611eafd0
commit d7ba2eeca9
6 changed files with 42 additions and 27 deletions

View file

@ -3,6 +3,7 @@
"WorkspaceSelector": {
"Add": "Add",
"OpenWorkspaceTagTiddler": "Open {{tagName}}",
"DefaultTiddlers": "Default Tiddlers",
"OpenWorkspaceMenuName": "Open Workspace",
"EditWorkspace": "Edit Workspace",
"RemoveWorkspace": "Remove Workspace",
@ -373,6 +374,7 @@
"Language": "Language",
"Window": "Window",
"Workspaces": "Workspaces",
"CurrentWorkspace": "Current Workspace",
"Back": "Back",
"Find": "Find",
"FindNext": "Find Next",

View file

@ -4,6 +4,7 @@
"WorkspaceSelector": {
"Add": "添加",
"OpenWorkspaceTagTiddler": "打开 {{tagName}}",
"DefaultTiddlers": "默认条目",
"OpenWorkspaceMenuName": "打开工作区",
"EditWorkspace": "编辑工作区",
"EditCurrentWorkspace": "编辑当前工作区",
@ -87,7 +88,8 @@
"SelectNextWorkspace": "选择下一个工作区",
"Language": "语言/Lang",
"History": "历史",
"Workspaces": "工作区",
"Workspaces": "工作区列表",
"CurrentWorkspace": "当前工作区",
"Window": "窗口",
"Help": "帮助",
"ActualSize": "正常大小",

View file

@ -21,7 +21,6 @@ declare module 'i18next' {
// init i18n is async, but our usage is basically await the electron app to start, so this is basically ok
// eslint-disable-next-line import/no-named-as-default-member
export const i18n = i18next.use(Backend);
export const t = (key: string): string => i18n.t(key) ?? key;
export async function initRendererI18NHandler(): Promise<void> {
await i18n.init({

View file

@ -364,9 +364,10 @@ export class MenuService implements IMenuService {
workspace: this.workspaceService,
workspaceView: this.workspaceViewService,
};
// workspace menus
menu.append(new MenuItem({ type: 'separator' }));
// show workspace menu to manipulate workspaces if sidebar is not open
if (!sidebar) {
menu.append(new MenuItem({ type: 'separator' }));
menu.append(
new MenuItem({
label: i18n.t('ContextMenu.OpenCommandPalette'),
@ -376,6 +377,12 @@ export class MenuService implements IMenuService {
},
}),
);
if (activeWorkspace !== undefined) {
const currentWorkspaceContextMenuTemplate = await getWorkspaceMenuTemplate(activeWorkspace, i18n.t.bind(i18n), services);
currentWorkspaceContextMenuTemplate.forEach((menuItem) => {
menu.append(new MenuItem(menuItem));
});
}
menu.append(
new MenuItem({
label: i18n.t('Menu.Workspaces'),
@ -400,7 +407,9 @@ export class MenuService implements IMenuService {
new MenuItem({
label: i18n.t('WorkspaceSelector.OpenWorkspaceMenuName'),
submenu: workspaces.map((workspace) => ({
label: i18n.t('WorkspaceSelector.OpenWorkspaceTagTiddler', { tagName: workspace.tagName ?? workspace.name }),
label: i18n.t('WorkspaceSelector.OpenWorkspaceTagTiddler', {
tagName: workspace.tagName ?? (workspace.isSubWiki ? workspace.name : i18n.t('WorkspaceSelector.DefaultTiddlers')),
}),
click: async () => {
await openWorkspaceTagTiddler(workspace, services);
},
@ -417,7 +426,28 @@ export class MenuService implements IMenuService {
}),
);
}
menu.append(
new MenuItem({
label: i18n.t('ContextMenu.RestartService'),
click: async () => {
const workspace = await this.workspaceService.getActiveWorkspace();
if (workspace !== undefined) {
await this.workspaceViewService.restartWorkspaceViewService(workspace.id);
await this.workspaceViewService.realignActiveWorkspace(workspace.id);
}
},
}),
);
menu.append(
new MenuItem({
label: i18n.t('ContextMenu.Reload'),
click: () => {
webContents.reload();
},
}),
);
}
menu.append(new MenuItem({ type: 'separator' }));
menu.append(
new MenuItem({
label: i18n.t('ContextMenu.Back'),
@ -436,26 +466,6 @@ export class MenuService implements IMenuService {
},
}),
);
menu.append(
new MenuItem({
label: i18n.t('ContextMenu.Reload'),
click: () => {
webContents.reload();
},
}),
);
menu.append(
new MenuItem({
label: i18n.t('ContextMenu.RestartService'),
click: async () => {
const workspace = await this.workspaceService.getActiveWorkspace();
if (workspace !== undefined) {
await this.workspaceViewService.restartWorkspaceViewService(workspace.id);
await this.workspaceViewService.realignActiveWorkspace(workspace.id);
}
},
}),
);
menu.append(
new MenuItem({
label: sidebar ? i18n.t('Preference.HideSideBar') : i18n.t('Preference.ShowSideBar'),

View file

@ -61,11 +61,13 @@ export async function getWorkspaceMenuTemplate(
t: TFunction,
service: IWorkspaceMenuRequiredServices,
): Promise<MenuItemConstructorOptions[]> {
const { active, id, hibernated, tagName, isSubWiki, wikiFolderLocation, gitUrl, storageService, homeUrl } = workspace;
const { active, id, hibernated, tagName, isSubWiki, wikiFolderLocation, gitUrl, storageService, homeUrl, name } = workspace;
/* eslint-disable @typescript-eslint/no-misused-promises */
const template: MenuItemConstructorOptions[] = [
{
label: t('WorkspaceSelector.OpenWorkspaceTagTiddler', { tagName }),
label: t('WorkspaceSelector.OpenWorkspaceTagTiddler', {
tagName: tagName ?? (isSubWiki ? name : `${name} ${t('WorkspaceSelector.DefaultTiddlers')}`),
}),
click: async () => {
await openWorkspaceTagTiddler(workspace, service);
},

@ -1 +1 @@
Subproject commit 85123f78f7903814db817e78b1d490b784f21b05
Subproject commit 5043b4ee3ed6cce3231c0316367efbb46e1033ce