From 5a2a0f1069f535eebe32071fbcca26577e4dc5bc Mon Sep 17 00:00:00 2001 From: tiddlygit-test Date: Wed, 5 May 2021 19:19:05 +0800 Subject: [PATCH] feat: add show/hide sidebar to context menu --- localization/locales/en/translation.json | 3 ++- localization/locales/zh_CN/translation.json | 1 + src/pages/Main/SortableWorkspaceSelector.tsx | 2 +- src/preload/common/remote.ts | 2 +- src/services/menu/index.ts | 10 ++++++++++ src/services/workspaces/index.ts | 5 +++-- 6 files changed, 18 insertions(+), 5 deletions(-) diff --git a/localization/locales/en/translation.json b/localization/locales/en/translation.json index 8d2f1438..ac7ca27e 100644 --- a/localization/locales/en/translation.json +++ b/localization/locales/en/translation.json @@ -285,6 +285,7 @@ "History": "History", "Language": "Language", "Window": "Window", - "Workspaces": "Workspaces" + "Workspaces": "Workspaces", + "Back": "Back" } } diff --git a/localization/locales/zh_CN/translation.json b/localization/locales/zh_CN/translation.json index 00e6cd56..690fd77b 100644 --- a/localization/locales/zh_CN/translation.json +++ b/localization/locales/zh_CN/translation.json @@ -227,6 +227,7 @@ "DarkTheme": "黑暗主题", "LightTheme": "亮色主题", "ShowSideBar": "显示侧边栏", + "HideSideBar": "隐藏侧边栏", "SystemDefalutTheme": "系统默认主题色", "Theme": "主题色", "Reset": "你确定吗?所有首选项都将恢复为其原始默认值。浏览数据不会受到影响。此操作无法撤消。", diff --git a/src/pages/Main/SortableWorkspaceSelector.tsx b/src/pages/Main/SortableWorkspaceSelector.tsx index 09e4594c..99878a61 100644 --- a/src/pages/Main/SortableWorkspaceSelector.tsx +++ b/src/pages/Main/SortableWorkspaceSelector.tsx @@ -66,7 +66,7 @@ export function SortableWorkspaceSelector({ index, workspace, showSidebarShortcu }); } - void window.remote.popContextMenu(template, { x: event.clientX, y: event.clientY, editFlags: { canCopy: false } }); + void window.remote.buildContextMenuAndPopup(template, { x: event.clientX, y: event.clientY, editFlags: { canCopy: false } }); }}> void> => { + buildContextMenuAndPopup: async (menus: MenuItemConstructorOptions[], parameters: IOnContextMenuInfo): Promise<() => void> => { const [ipcSafeMenus, unregister] = rendererMenuItemProxy(menus); await service.menu.buildContextMenuAndPopup(ipcSafeMenus, parameters, windowName); return unregister; diff --git a/src/services/menu/index.ts b/src/services/menu/index.ts index 162317fe..067bd46e 100644 --- a/src/services/menu/index.ts +++ b/src/services/menu/index.ts @@ -9,6 +9,7 @@ import { lazyInject } from '@services/container'; import serviceIdentifier from '@services/serviceIdentifier'; import { IWindowService } from '@services/windows/interface'; import { IViewService } from '@services/view/interface'; +import { IPreferenceService } from '@services/preferences/interface'; import i18next from '@services/libs/i18n'; import ContextMenuBuilder from './contextMenuBuilder'; import { IpcSafeMenuItem, mainMenuItemProxy } from './rendererMenuItemProxy'; @@ -18,6 +19,7 @@ import { InsertMenuAfterSubMenuIndexError } from './error'; export class MenuService implements IMenuService { @lazyInject(serviceIdentifier.Window) private readonly windowService!: IWindowService; @lazyInject(serviceIdentifier.View) private readonly viewService!: IViewService; + @lazyInject(serviceIdentifier.Preference) private readonly preferenceService!: IPreferenceService; private _menuTemplate?: DeferredMenuItemConstructorOptions[]; private get menuTemplate(): DeferredMenuItemConstructorOptions[] { @@ -303,6 +305,14 @@ export class MenuService implements IMenuService { }, }), ); + menu.append( + new MenuItem({ + label: (await this.preferenceService.get('sidebar')) ? i18next.t('Preference.HideSideBar') : i18next.t('Preference.ShowSideBar'), + click: async () => { + await this.preferenceService.set('sidebar', !(await this.preferenceService.get('sidebar'))); + }, + }), + ); menu.append(new MenuItem({ type: 'separator' })); menu.append( new MenuItem({ diff --git a/src/services/workspaces/index.ts b/src/services/workspaces/index.ts index 836e8bf5..1af048b0 100644 --- a/src/services/workspaces/index.ts +++ b/src/services/workspaces/index.ts @@ -19,11 +19,11 @@ import type { IWindowService } from '@services/windows/interface'; import type { IMenuService } from '@services/menu/interface'; import { WindowNames } from '@services/windows/WindowProperties'; import { IAuthenticationService } from '@services/auth/interface'; +import { IWikiGitWorkspaceService } from '@services/wikiGitWorkspace/interface'; import { SupportedStorageServices } from '@services/types'; import { lazyInject } from '@services/container'; import { IWorkspaceService, IWorkspace, IWorkspaceMetaData, INewWorkspaceConfig } from './interface'; import i18n from '@services/libs/i18n'; -import { workspace } from '@/preload/common/services'; @injectable() export class Workspace implements IWorkspaceService { @@ -37,6 +37,7 @@ export class Workspace implements IWorkspaceService { @lazyInject(serviceIdentifier.Window) private readonly windowService!: IWindowService; @lazyInject(serviceIdentifier.View) private readonly viewService!: IViewService; @lazyInject(serviceIdentifier.WorkspaceView) private readonly workspaceViewService!: IWorkspaceViewService; + @lazyInject(serviceIdentifier.WikiGitWorkspace) private readonly wikiGitWorkspaceService!: IWikiGitWorkspaceService; @lazyInject(serviceIdentifier.MenuService) private readonly menuService!: IMenuService; @lazyInject(serviceIdentifier.Authentication) private readonly authenticationService!: IAuthenticationService; @@ -91,7 +92,7 @@ export class Workspace implements IWorkspaceService { click: async () => { const currentActiveWorkspace = await this.getActiveWorkspace(); if (currentActiveWorkspace === undefined) return; - await this.workspaceViewService.removeWorkspaceView(currentActiveWorkspace.id); + await this.wikiGitWorkspaceService.removeWorkspace(currentActiveWorkspace.id); }, enabled: async () => (await this.countWorkspaces()) > 0, },