From f7fb0b953fa4b86788876e67efdc9b5e028d1b14 Mon Sep 17 00:00:00 2001 From: Katsiaryna Tsytsenia Date: Thu, 29 Aug 2024 12:45:31 +0200 Subject: [PATCH] IJMP-1583 Returned file sync fix during indexing in 223 --- .../dataops/content/synchronizer/SyncAction.kt | 9 +++++++++ .../formainframe/editor/ChangeContentServiceImpl.kt | 12 ++++++++---- .../formainframe/editor/FileEditorEventsListener.kt | 11 +++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/eu/ibagroup/formainframe/dataops/content/synchronizer/SyncAction.kt b/src/main/kotlin/eu/ibagroup/formainframe/dataops/content/synchronizer/SyncAction.kt index 09d0554bf..1e92fd9c0 100644 --- a/src/main/kotlin/eu/ibagroup/formainframe/dataops/content/synchronizer/SyncAction.kt +++ b/src/main/kotlin/eu/ibagroup/formainframe/dataops/content/synchronizer/SyncAction.kt @@ -96,6 +96,15 @@ class SyncAction : DumbAwareAction() { } val editor = getEditor(e) ?: return + val isDumbMode = ActionUtil.isDumbMode(e.project) + if (!isDumbMode && file.isWritable) { + editor.document.setReadOnly(false) + editor.isViewer = false + } else { + e.presentation.isEnabledAndVisible = false + return + } + val contentSynchronizer = service().getContentSynchronizer(file) val syncProvider = DocumentedSyncProvider(file) val currentContent = runReadAction { syncProvider.retrieveCurrentContent() } diff --git a/src/main/kotlin/eu/ibagroup/formainframe/editor/ChangeContentServiceImpl.kt b/src/main/kotlin/eu/ibagroup/formainframe/editor/ChangeContentServiceImpl.kt index afd62a156..28db19f94 100644 --- a/src/main/kotlin/eu/ibagroup/formainframe/editor/ChangeContentServiceImpl.kt +++ b/src/main/kotlin/eu/ibagroup/formainframe/editor/ChangeContentServiceImpl.kt @@ -48,15 +48,19 @@ class ChangeContentServiceImpl : ChangeContentService { override fun afterActionPerformed(action: AnAction, event: AnActionEvent, result: AnActionResult) { if (action is EditorPasteAction || (action is PasteAction && event.place == "EditorPopup")) { val editor = event.getData(CommonDataKeys.EDITOR) ?: return - - processMfContent(editor) + val isFileWritable = requestDocumentWriting(editor) + if (isFileWritable) { + processMfContent(editor) + } } } override fun afterEditorTyping(c: Char, dataContext: DataContext) { val editor = dataContext.getData(CommonDataKeys.EDITOR) ?: return - - processMfContent(editor) + val isFileWritable = requestDocumentWriting(editor) + if (isFileWritable) { + processMfContent(editor) + } } } ) diff --git a/src/main/kotlin/eu/ibagroup/formainframe/editor/FileEditorEventsListener.kt b/src/main/kotlin/eu/ibagroup/formainframe/editor/FileEditorEventsListener.kt index 22b4d0b40..adde1051f 100644 --- a/src/main/kotlin/eu/ibagroup/formainframe/editor/FileEditorEventsListener.kt +++ b/src/main/kotlin/eu/ibagroup/formainframe/editor/FileEditorEventsListener.kt @@ -41,9 +41,16 @@ class FileEditorEventsListener : FileEditorManagerListener { override fun fileOpened(source: FileEditorManager, file: VirtualFile) { if (file is MFVirtualFile) { val editor = source.selectedTextEditor as? EditorEx - editor?.addFocusListener(focusListener) + if (editor != null) { + editor.addFocusListener(focusListener) + val isDumbMode = ActionUtil.isDumbMode(editor.project) + if (isDumbMode) { + editor.document.setReadOnly(true) + editor.isViewer = true + } + super.fileOpened(source, file) + } } - super.fileOpened(source, file) } }