Desktop: Resolves #1900: Allow selecting what views should be available from the Layout button (#2028)

* Added options for selecting layout

* Toggle through the layouts based on config

* Used redux state for getting layout settings

* Removed duplicated strings for layout options

* Moved option for selecting layouts to "View" menu
pull/2049/head
Subodh Dahal 2019-10-31 09:42:17 +01:00 committed by Laurent Cozic
parent 316746605e
commit f450ef09cc
2 changed files with 59 additions and 11 deletions

View File

@ -122,19 +122,31 @@ class Application extends BaseApplication {
case 'NOTE_VISIBLE_PANES_TOGGLE':
{
let panes = state.noteVisiblePanes.slice();
if (panes.length === 2) {
panes = ['editor'];
} else if (panes.indexOf('editor') >= 0) {
panes = ['viewer'];
} else if (panes.indexOf('viewer') >= 0) {
panes = ['editor', 'viewer'];
const getNextLayout = (currentLayout) => {
currentLayout = panes.length === 2 ? 'both' : currentLayout[0];
let paneOptions;
if (state.settings.layout === Setting.LAYOUT_EDITOR_VIEWER) {
paneOptions = ['editor', 'viewer'];
} else if (state.settings.layout === Setting.LAYOUT_EDITOR_SPLIT) {
paneOptions = ['editor', 'both'];
} else if (state.settings.layout === Setting.LAYOUT_VIEWER_SPLIT) {
paneOptions = ['viewer', 'both'];
} else {
panes = ['editor', 'viewer'];
paneOptions = ['editor', 'viewer', 'both'];
}
const currentLayoutIndex = paneOptions.indexOf(currentLayout);
const nextLayoutIndex = currentLayoutIndex === paneOptions.length - 1 ? 0 : currentLayoutIndex + 1;
let nextLayout = paneOptions[nextLayoutIndex];
return nextLayout === 'both' ? ['editor', 'viewer'] : [nextLayout];
};
newState = Object.assign({}, state);
newState.noteVisiblePanes = panes;
let panes = state.noteVisiblePanes.slice();
newState.noteVisiblePanes = getNextLayout(panes);
}
break;
@ -726,6 +738,17 @@ class Application extends BaseApplication {
],
};
const layoutOptions = Object.entries(Setting.enumOptions('layout')).map(([layoutKey, layout]) => ({
label: layout,
screens: ['Main'],
type: 'checkbox',
checked: Setting.value('layout') == layoutKey,
click: () => {
Setting.setValue('layout', layoutKey);
this.refreshMenu();
},
}));
const rootMenus = {
edit: {
id: 'edit',
@ -879,6 +902,13 @@ class Application extends BaseApplication {
name: 'toggleSidebar',
});
},
}, {
type: 'separator',
screens: ['Main'],
}, {
label: _('Layouts'),
screens: ['Main'],
submenu: layoutOptions,
}, {
label: _('Toggle note list'),
screens: ['Main'],

View File

@ -233,6 +233,19 @@ class Setting extends BaseModel {
return output;
},
},
layout: {
value: Setting.LAYOUT_ALL,
type: Setting.TYPE_INT,
public: false,
appTypes: ['desktop'],
isEnum: true,
options: () => ({
[Setting.LAYOUT_ALL]: _('%s / %s / %s', _('Editor'), _('Viewer'), _('Split View')),
[Setting.LAYOUT_EDITOR_VIEWER]: _('%s / %s', _('Editor'), _('Viewer')),
[Setting.LAYOUT_EDITOR_SPLIT]: _('%s / %s', _('Editor'), _('Split View')),
[Setting.LAYOUT_VIEWER_SPLIT]: _('%s / %s', _('Viewer'), _('Split View')),
}),
},
uncompletedTodosOnTop: { value: true, type: Setting.TYPE_BOOL, section: 'note', public: true, appTypes: ['cli'], label: () => _('Uncompleted to-dos on top') },
showCompletedTodos: { value: true, type: Setting.TYPE_BOOL, section: 'note', public: true, appTypes: ['cli'], label: () => _('Show completed to-dos') },
'notes.sortOrder.field': {
@ -923,6 +936,11 @@ Setting.FONT_COURIER_NEW = 2;
Setting.FONT_AVENIR = 3;
Setting.FONT_MONOSPACE = 4;
Setting.LAYOUT_ALL = 0;
Setting.LAYOUT_EDITOR_VIEWER = 1;
Setting.LAYOUT_EDITOR_SPLIT = 2;
Setting.LAYOUT_VIEWER_SPLIT = 3;
Setting.DATE_FORMAT_1 = 'DD/MM/YYYY';
Setting.DATE_FORMAT_2 = 'DD/MM/YY';
Setting.DATE_FORMAT_3 = 'MM/DD/YYYY';