2020-11-13 19:09:28 +02:00
|
|
|
// This extends the generic stateToWhenClauseContext (potentially shared by
|
|
|
|
// all apps) with additional properties specific to the desktop app. So in
|
|
|
|
// general, any desktop component should import this file, and not the lib
|
|
|
|
// one.
|
|
|
|
|
2021-09-04 19:11:29 +02:00
|
|
|
import { AppState } from '../../app.reducer';
|
2021-05-13 18:57:37 +02:00
|
|
|
import libStateToWhenClauseContext, { WhenClauseContextOptions } from '@joplin/lib/services/commands/stateToWhenClauseContext';
|
2020-11-13 19:09:28 +02:00
|
|
|
import layoutItemProp from '../../gui/ResizableLayout/utils/layoutItemProp';
|
2024-11-08 17:32:05 +02:00
|
|
|
import { defaultWindowId, stateUtils } from '@joplin/lib/reducer';
|
2020-11-13 19:09:28 +02:00
|
|
|
|
2021-05-13 18:57:37 +02:00
|
|
|
export default function stateToWhenClauseContext(state: AppState, options: WhenClauseContextOptions = null) {
|
2024-11-08 17:32:05 +02:00
|
|
|
const windowId = options?.windowId ?? defaultWindowId;
|
|
|
|
const isMainWindow = windowId === defaultWindowId;
|
|
|
|
const windowState = stateUtils.windowStateById(state, windowId);
|
|
|
|
|
2020-11-13 19:09:28 +02:00
|
|
|
return {
|
2021-05-13 18:57:37 +02:00
|
|
|
...libStateToWhenClauseContext(state, options),
|
2020-11-13 19:09:28 +02:00
|
|
|
|
|
|
|
// UI elements
|
2024-11-08 17:32:05 +02:00
|
|
|
markdownEditorVisible: !!windowState.editorCodeView && !state.settings['isSafeMode'],
|
|
|
|
richTextEditorVisible: !windowState.editorCodeView && !state.settings['isSafeMode'],
|
2023-10-22 13:00:19 +02:00
|
|
|
|
2024-11-08 17:32:05 +02:00
|
|
|
markdownEditorPaneVisible: windowState.editorCodeView && windowState.noteVisiblePanes.includes('editor'),
|
|
|
|
markdownViewerPaneVisible: windowState.editorCodeView && windowState.noteVisiblePanes.includes('viewer'),
|
2020-11-13 19:09:28 +02:00
|
|
|
modalDialogVisible: !!Object.keys(state.visibleDialogs).length,
|
2021-12-31 10:20:29 +02:00
|
|
|
gotoAnythingVisible: !!state.visibleDialogs['gotoAnything'],
|
2024-11-08 17:32:05 +02:00
|
|
|
sidebarVisible: isMainWindow && !!state.mainLayout && layoutItemProp(state.mainLayout, 'sideBar', 'visible'),
|
|
|
|
noteListHasNotes: !!windowState.notes.length,
|
2021-01-12 14:28:55 +02:00
|
|
|
|
|
|
|
// Deprecated
|
|
|
|
sideBarVisible: !!state.mainLayout && layoutItemProp(state.mainLayout, 'sideBar', 'visible'),
|
2020-11-13 19:09:28 +02:00
|
|
|
};
|
|
|
|
}
|