diff --git a/.eslintignore b/.eslintignore index e65399b3918..1814f389c88 100644 --- a/.eslintignore +++ b/.eslintignore @@ -283,9 +283,9 @@ packages/app-desktop/gui/MainScreen/commands/openNote.js.map packages/app-desktop/gui/MainScreen/commands/openTag.d.ts packages/app-desktop/gui/MainScreen/commands/openTag.js packages/app-desktop/gui/MainScreen/commands/openTag.js.map -packages/app-desktop/gui/MainScreen/commands/perNotebookSortOrder.d.ts -packages/app-desktop/gui/MainScreen/commands/perNotebookSortOrder.js -packages/app-desktop/gui/MainScreen/commands/perNotebookSortOrder.js.map +packages/app-desktop/gui/MainScreen/commands/perFolderSortOrder.d.ts +packages/app-desktop/gui/MainScreen/commands/perFolderSortOrder.js +packages/app-desktop/gui/MainScreen/commands/perFolderSortOrder.js.map packages/app-desktop/gui/MainScreen/commands/print.d.ts packages/app-desktop/gui/MainScreen/commands/print.js packages/app-desktop/gui/MainScreen/commands/print.js.map diff --git a/.gitignore b/.gitignore index 90d28945e10..db0d072ae19 100644 --- a/.gitignore +++ b/.gitignore @@ -268,9 +268,9 @@ packages/app-desktop/gui/MainScreen/commands/openNote.js.map packages/app-desktop/gui/MainScreen/commands/openTag.d.ts packages/app-desktop/gui/MainScreen/commands/openTag.js packages/app-desktop/gui/MainScreen/commands/openTag.js.map -packages/app-desktop/gui/MainScreen/commands/perNotebookSortOrder.d.ts -packages/app-desktop/gui/MainScreen/commands/perNotebookSortOrder.js -packages/app-desktop/gui/MainScreen/commands/perNotebookSortOrder.js.map +packages/app-desktop/gui/MainScreen/commands/perFolderSortOrder.d.ts +packages/app-desktop/gui/MainScreen/commands/perFolderSortOrder.js +packages/app-desktop/gui/MainScreen/commands/perFolderSortOrder.js.map packages/app-desktop/gui/MainScreen/commands/print.d.ts packages/app-desktop/gui/MainScreen/commands/print.js packages/app-desktop/gui/MainScreen/commands/print.js.map diff --git a/packages/app-desktop/gui/MainScreen/commands/index.ts b/packages/app-desktop/gui/MainScreen/commands/index.ts index c35bc6e367d..77fc5a43e42 100644 --- a/packages/app-desktop/gui/MainScreen/commands/index.ts +++ b/packages/app-desktop/gui/MainScreen/commands/index.ts @@ -14,7 +14,7 @@ import * as notesSortOrderToggleReverse from './notesSortOrderToggleReverse'; import * as openFolder from './openFolder'; import * as openNote from './openNote'; import * as openTag from './openTag'; -import * as perNotebookSortOrder from './perNotebookSortOrder'; +import * as perFolderSortOrder from './perFolderSortOrder'; import * as print from './print'; import * as renameFolder from './renameFolder'; import * as renameTag from './renameTag'; @@ -49,7 +49,7 @@ const index:any[] = [ openFolder, openNote, openTag, - perNotebookSortOrder, + perFolderSortOrder, print, renameFolder, renameTag, diff --git a/packages/app-desktop/gui/MainScreen/commands/perNotebookSortOrder.ts b/packages/app-desktop/gui/MainScreen/commands/perFolderSortOrder.ts similarity index 63% rename from packages/app-desktop/gui/MainScreen/commands/perNotebookSortOrder.ts rename to packages/app-desktop/gui/MainScreen/commands/perFolderSortOrder.ts index 919b03f36b1..15393c3790f 100644 --- a/packages/app-desktop/gui/MainScreen/commands/perNotebookSortOrder.ts +++ b/packages/app-desktop/gui/MainScreen/commands/perFolderSortOrder.ts @@ -9,10 +9,10 @@ import { import { _ } from '@joplin/lib/locale'; -export const PER_NOTEBOOK_SORT_ORDER = 'perNotebookSortOrder'; -export const SETTING_PER_NOTEBOOK_SORT_ORDER_ENABLED = 'notes.perNotebookSortOrderEnabled'; +export const PER_FOLDER_SORT_ORDER = 'perFolderSortOrder'; +export const SETTING_PER_FOLDER_SORT_ORDER_ENABLED = 'notes.perFolderSortOrderEnabled'; -let previousNotebookId: string = null; +let previousFolderId: string = null; let ownSortOrders: { [key: string]: any } = null; const sharedSortOrder: { [key: string]: any } = { field: 'user_updated_time', @@ -23,33 +23,33 @@ const sharedSortOrder: { [key: string]: any } = { order: false, }; -export function selectedNotebookHasOwnSortOrder() { - return hasOwnSortOrder(getSelectedNotebookId()); +export function selectedFolderHasOwnSortOrder() { + return hasOwnSortOrder(getSelectedFolderId()); } -export function hasOwnSortOrder(notebookId: string) { - return notebookId && ownSortOrders && ownSortOrders.hasOwnProperty(notebookId + SUFFIX_FIELD); +export function hasOwnSortOrder(folderId: string) { + return folderId && ownSortOrders && ownSortOrders.hasOwnProperty(folderId + SUFFIX_FIELD); } export const declaration: CommandDeclaration = { - name: PER_NOTEBOOK_SORT_ORDER, + name: PER_FOLDER_SORT_ORDER, label: () => _('Toggle own sort order'), }; export const runtime = (): CommandRuntime => { loadOwnSortOrders(); loadSharedSortOrder(); - eventManager.appStateOn('notesParentType', onNotebookSelectionMayChange); - eventManager.appStateOn('selectedFolderId', onNotebookSelectionMayChange); + eventManager.appStateOn('notesParentType', onFolderSelectionMayChange); + eventManager.appStateOn('selectedFolderId', onFolderSelectionMayChange); return { enabledCondition: 'oneFolderSelected', - execute: async (context: CommandContext, notebookId?: string, own?: boolean) => { - let targetId = notebookId; - const selectedId = getSelectedNotebookId(context.state); + execute: async (context: CommandContext, folderId?: string, own?: boolean) => { + let targetId = folderId; + const selectedId = getSelectedFolderId(context.state); if (!targetId) { - targetId = selectedId; // default: selected notebook + targetId = selectedId; // default: selected folder if (!targetId) return; } const targetOwn = hasOwnSortOrder(targetId); @@ -81,40 +81,40 @@ export const runtime = (): CommandRuntime => { }; }; -function onNotebookSelectionMayChange() { - const selectedId = getSelectedNotebookId(); - if (previousNotebookId === null) previousNotebookId = selectedId; - if (previousNotebookId === selectedId) return; +function onFolderSelectionMayChange() { + const selectedId = getSelectedFolderId(); + if (previousFolderId === null) previousFolderId = selectedId; + if (previousFolderId === selectedId) return; const field = getCurrentField(); const reverse = getCurrentReverse(); - const previousNotebookHasOwnSortOrder = hasOwnSortOrder(previousNotebookId); - if (previousNotebookHasOwnSortOrder) { - setOwnSortOrder(previousNotebookId, field, reverse); + const previousFolderHasOwnSortOrder = hasOwnSortOrder(previousFolderId); + if (previousFolderHasOwnSortOrder) { + setOwnSortOrder(previousFolderId, field, reverse); } else { setSharedSortOrder(field, reverse); } - previousNotebookId = selectedId; + previousFolderId = selectedId; let next; if (hasOwnSortOrder(selectedId)) { next = getOwnSortOrder(selectedId); - } else if (previousNotebookHasOwnSortOrder) { + } else if (previousFolderHasOwnSortOrder) { next = sharedSortOrder; } else { return; } - if (perNotebookSortOrderEnabled()) { + if (perFolderSortOrderEnabled()) { if (next.field != field || next.reverse != reverse) { void CommandService.instance().execute(NOTES_SORT_ORDER_SWITCH, next.field, next.reverse); } } } -const OWN_SORT_ORDERS = 'notes.perNotebookSortOrders'; +const OWN_SORT_ORDERS = 'notes.perFolderSortOrders'; const SHARED_SORT_ORDER = 'notes.sharedSortOrder'; const SUFFIX_FIELD = '$field'; const SUFFIX_REVERSE = '$reverse'; -function getSelectedNotebookId(state?: State): string { +function getSelectedFolderId(state?: State): string { const s = state ? state : app().store().getState(); if (s.notesParentType === 'Folder') { return s.selectedFolderId; @@ -135,25 +135,25 @@ function perFieldReversalEnabled(): boolean { return Setting.value(SETTING_PER_FIELD_REVERSAL_ENABLED); } -function perNotebookSortOrderEnabled(): boolean { - return Setting.value(SETTING_PER_NOTEBOOK_SORT_ORDER_ENABLED); +function perFolderSortOrderEnabled(): boolean { + return Setting.value(SETTING_PER_FOLDER_SORT_ORDER_ENABLED); } -function getOwnSortOrder(notebookId: string) { - const field = ownSortOrders[notebookId + SUFFIX_FIELD] as string; - const reverse = ownSortOrders[notebookId + SUFFIX_REVERSE] as boolean; +function getOwnSortOrder(folderId: string) { + const field = ownSortOrders[folderId + SUFFIX_FIELD] as string; + const reverse = ownSortOrders[folderId + SUFFIX_REVERSE] as boolean; return { field, reverse }; } -function setOwnSortOrder(notebookId: string, field: string, reverse: boolean) { - const old = getOwnSortOrder(notebookId); +function setOwnSortOrder(folderId: string, field: string, reverse: boolean) { + const old = getOwnSortOrder(folderId); let dirty = false; if (old.field !== field) { - ownSortOrders[notebookId + SUFFIX_FIELD] = field; + ownSortOrders[folderId + SUFFIX_FIELD] = field; dirty = true; } if (old.reverse !== reverse) { - ownSortOrders[notebookId + SUFFIX_REVERSE] = reverse; + ownSortOrders[folderId + SUFFIX_REVERSE] = reverse; dirty = true; } if (dirty) { @@ -161,14 +161,14 @@ function setOwnSortOrder(notebookId: string, field: string, reverse: boolean) { } } -function deleteOwnSortOrder(notebookId: string) { +function deleteOwnSortOrder(folderId: string) { let dirty = false; - if (ownSortOrders.hasOwnProperty(notebookId + SUFFIX_FIELD)) { - delete ownSortOrders[notebookId + SUFFIX_FIELD]; + if (ownSortOrders.hasOwnProperty(folderId + SUFFIX_FIELD)) { + delete ownSortOrders[folderId + SUFFIX_FIELD]; dirty = true; } - if (ownSortOrders.hasOwnProperty(notebookId + SUFFIX_REVERSE)) { - delete ownSortOrders[notebookId + SUFFIX_REVERSE]; + if (ownSortOrders.hasOwnProperty(folderId + SUFFIX_REVERSE)) { + delete ownSortOrders[folderId + SUFFIX_REVERSE]; dirty = true; } if (dirty) { diff --git a/packages/app-desktop/gui/Sidebar/Sidebar.tsx b/packages/app-desktop/gui/Sidebar/Sidebar.tsx index 54fbf4395c8..c2c0e488325 100644 --- a/packages/app-desktop/gui/Sidebar/Sidebar.tsx +++ b/packages/app-desktop/gui/Sidebar/Sidebar.tsx @@ -20,7 +20,7 @@ import Logger from '@joplin/lib/Logger'; import { FolderEntity } from '@joplin/lib/services/database/types'; import stateToWhenClauseContext from '../../services/commands/stateToWhenClauseContext'; import { store } from '@joplin/lib/reducer'; -import { hasOwnSortOrder } from '../MainScreen/commands/perNotebookSortOrder'; +import { hasOwnSortOrder } from '../MainScreen/commands/perFolderSortOrder'; const { connect } = require('react-redux'); const shared = require('@joplin/lib/components/shared/side-menu-shared.js'); const { themeStyle } = require('@joplin/lib/theme'); @@ -325,9 +325,9 @@ class SidebarComponent extends React.Component { submenu: exportMenu, }) ); - if (Setting.value('notes.perNotebookSortOrderEnabled')) { + if (Setting.value('notes.perFolderSortOrderEnabled')) { menu.append(new MenuItem({ - ...menuUtils.commandToStatefulMenuItem('perNotebookSortOrder', itemId), + ...menuUtils.commandToStatefulMenuItem('perFolderSortOrder', itemId), type: 'checkbox', checked: hasOwnSortOrder(itemId), })); diff --git a/packages/app-desktop/gui/menuCommandNames.ts b/packages/app-desktop/gui/menuCommandNames.ts index afe0847aba7..918aa7ced78 100644 --- a/packages/app-desktop/gui/menuCommandNames.ts +++ b/packages/app-desktop/gui/menuCommandNames.ts @@ -18,7 +18,7 @@ export default function() { 'notesSortOrderSwitch', 'notesSortOrderToggleReverse', 'openProfileDirectory', - 'perNotebookSortOrder', + 'perFolderSortOrder', 'print', 'setTags', 'showLocalSearch', diff --git a/packages/lib/models/Setting.ts b/packages/lib/models/Setting.ts index 41d6c6dc481..396ccca7791 100644 --- a/packages/lib/models/Setting.ts +++ b/packages/lib/models/Setting.ts @@ -800,7 +800,7 @@ class Setting extends BaseModel { public: false, appTypes: [AppType.Cli, AppType.Desktop], }, - 'notes.perNotebookSortOrderEnabled': { + 'notes.perFolderSortOrderEnabled': { value: true, type: SettingItemType.Bool, storage: SettingStorage.File, @@ -809,7 +809,7 @@ class Setting extends BaseModel { label: () => _('Enable per-notebook sort order'), appTypes: [AppType.Cli, AppType.Desktop], }, - 'notes.perNotebookSortOrders': { + 'notes.perFolderSortOrders': { value: {}, type: SettingItemType.Object, storage: SettingStorage.File,