From 1e9a0036e746cea90314152ae40fb70a30f4d440 Mon Sep 17 00:00:00 2001 From: Siddhant Sehgal <35633575+coderrsid@users.noreply.github.com> Date: Sat, 4 Apr 2020 22:33:09 +0530 Subject: [PATCH] Desktop: Resolves #2296: Right-click to move note to notebook (#2566) * Assign Notebook functionality added * Made the changes acc. to laurent22 * Changes done till 9/03/20 * Removed NoteContentPropertiesDialog.js * Render notebooks in tree hierarchy * Update PromptDialog.jsx Co-authored-by: Laurent Cozic --- ElectronClient/gui/MainScreen.jsx | 29 +++++++++++++++++++++++ ElectronClient/gui/PromptDialog.jsx | 3 ++- ElectronClient/gui/utils/NoteListUtils.js | 13 ++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/ElectronClient/gui/MainScreen.jsx b/ElectronClient/gui/MainScreen.jsx index 8d1c6c389b..980214a539 100644 --- a/ElectronClient/gui/MainScreen.jsx +++ b/ElectronClient/gui/MainScreen.jsx @@ -208,6 +208,35 @@ class MainScreenComponent extends React.Component { }, }, }); + } else if (command.name === 'moveToFolder') { + const startFolders = []; + const maxDepth = 15; + + const addOptions = (folders, depth) => { + for (let i = 0; i < folders.length; i++) { + const folder = folders[i]; + startFolders.push({ key: folder.id, value: folder.id, label: folder.title, indentDepth: depth }); + if (folder.children) addOptions(folder.children, (depth + 1) < maxDepth ? depth + 1 : maxDepth); + } + }; + addOptions(await Folder.allAsTree(), 0); + + this.setState({ + promptOptions: { + label: _('Move to notebook:'), + inputType: 'dropdown', + value: '', + autocomplete: startFolders, + onClose: async answer => { + if (answer != null) { + for (let i = 0; i < command.noteIds.length; i++) { + await Note.moveToFolder(command.noteIds[i], answer.value); + } + } + this.setState({ promptOptions: null }); + }, + }, + }); } else if (command.name === 'renameFolder') { const folder = await Folder.load(command.id); diff --git a/ElectronClient/gui/PromptDialog.jsx b/ElectronClient/gui/PromptDialog.jsx index 4393a113bf..c49a13b8f2 100644 --- a/ElectronClient/gui/PromptDialog.jsx +++ b/ElectronClient/gui/PromptDialog.jsx @@ -117,10 +117,11 @@ class PromptDialog extends React.Component { fontFamily: theme.fontFamily, backgroundColor: theme.backgroundColor, }), - option: provided => + option: (provided, state) => Object.assign(provided, { color: theme.color, fontFamily: theme.fontFamily, + paddingLeft: `${10 + (state.data.indentDepth || 0) * 20}px`, }), multiValueLabel: provided => Object.assign(provided, { diff --git a/ElectronClient/gui/utils/NoteListUtils.js b/ElectronClient/gui/utils/NoteListUtils.js index cf4b3daeef..9784a973ea 100644 --- a/ElectronClient/gui/utils/NoteListUtils.js +++ b/ElectronClient/gui/utils/NoteListUtils.js @@ -35,6 +35,19 @@ class NoteListUtils { }) ); + menu.append( + new MenuItem({ + label: _('Move to notebook'), + click: () => { + props.dispatch({ + type: 'WINDOW_COMMAND', + name: 'moveToFolder', + noteIds: noteIds, + }); + }, + }) + ); + menu.append( new MenuItem({ label: _('Duplicate'),