From d1bb0ae352424a4bdf8dad641dd7c0a5943d2066 Mon Sep 17 00:00:00 2001 From: Benjamin Thiemann Date: Mon, 26 Feb 2024 14:48:22 +0100 Subject: [PATCH] components: Add actions for open read-only mode Signed-off-by: Benjamin Thiemann --- src/components/Editor.vue | 25 ++++++++++++++++++----- src/components/Editor/Wrapper.provider.js | 12 +++++++++++ src/components/Editor/Wrapper.vue | 10 ++++++++- src/components/Menu/BaseActionEntry.js | 11 ++++++++-- src/components/Menu/MenuBar.vue | 8 ++++++-- src/components/Menu/ReadonlyBar.vue | 10 +++++++-- 6 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/components/Editor.vue b/src/components/Editor.vue index 66d565bf4a1..83a40e92f00 100644 --- a/src/components/Editor.vue +++ b/src/components/Editor.vue @@ -40,12 +40,13 @@ :content-loaded="contentLoaded" :show-author-annotations="showAuthorAnnotations" :show-outline-outside="showOutlineOutside" + @read-only-toggled="readOnlyToggled" @outline-toggled="outlineToggled"> -
+
- + { this.emit('sync-service:idle') @@ -734,6 +741,14 @@ export default { this.emit('outline-toggled', visible) }, + readOnlyToggled() { + if (this.editMode) { + this.$syncService.save() + } + this.editMode = !this.editMode + this.$editor.setEditable(this.editMode) + }, + onKeyDown(event) { if (event.key === 'Escape') { event.preventDefault() diff --git a/src/components/Editor/Wrapper.provider.js b/src/components/Editor/Wrapper.provider.js index b8b1c29f389..19bcceedd8e 100644 --- a/src/components/Editor/Wrapper.provider.js +++ b/src/components/Editor/Wrapper.provider.js @@ -1,5 +1,6 @@ export const OUTLINE_STATE = Symbol('wrapper:outline-state') export const OUTLINE_ACTIONS = Symbol('wrapper:outline-actions') +export const READ_ONLY_ACTIONS = Symbol('wrapper:read-only-actions') export const useOutlineStateMixin = { inject: { @@ -23,3 +24,14 @@ export const useOutlineActions = { }, }, } + +export const useReadOnlyActions = { + inject: { + $readOnlyActions: { + from: READ_ONLY_ACTIONS, + default: { + toggle: () => {}, + }, + }, + }, +} diff --git a/src/components/Editor/Wrapper.vue b/src/components/Editor/Wrapper.vue index 7e717f1a670..3c590a89031 100644 --- a/src/components/Editor/Wrapper.vue +++ b/src/components/Editor/Wrapper.vue @@ -35,7 +35,7 @@