mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
PY-76662 Jupyter(fix): Add ability to force save document changes even if document is not changed
We need to do it because in jupyter a lot of infor especially outputs are not in document but in metadata (cherry picked from commit 0fe7ce59b7e9d64f5a03080c1f4ce9a0dc7c121f) (cherry picked from commit 2007b95711b213a014d7be2b349989b04ca7ed24) IJ-CR-147319 GitOrigin-RevId: 6945f3b7f07e6147281423c2e8bd1c3d0899526a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8beae300b4
commit
4c88de60ff
@@ -79,6 +79,7 @@ public class FileDocumentManagerImpl extends FileDocumentManagerBase implements
|
||||
private static final Logger LOG = Logger.getInstance(FileDocumentManagerImpl.class);
|
||||
|
||||
public static final Key<Object> NOT_RELOADABLE_DOCUMENT_KEY = new Key<>("NOT_RELOADABLE_DOCUMENT_KEY");
|
||||
private static final Key<Boolean> FORCE_SAVE_DOCUMENT_KEY = new Key<>("FORCE_SAVE_DOCUMENT_KEY");
|
||||
|
||||
private static final Key<String> LINE_SEPARATOR_KEY = Key.create("LINE_SEPARATOR_KEY");
|
||||
private static final Key<Boolean> MUST_RECOMPUTE_FILE_TYPE = Key.create("Must recompute file type");
|
||||
@@ -100,7 +101,7 @@ public class FileDocumentManagerImpl extends FileDocumentManagerBase implements
|
||||
@Override
|
||||
public void documentChanged(@NotNull DocumentEvent e) {
|
||||
Document document = e.getDocument();
|
||||
markDocumentUnsaved(document);
|
||||
markDocumentUnsaved(document, false);
|
||||
Runnable currentCommand = CommandProcessor.getInstance().getCurrentCommand();
|
||||
Project project = currentCommand == null ? null : CommandProcessor.getInstance().getCurrentCommandProject();
|
||||
VirtualFile virtualFile = getFile(document);
|
||||
@@ -209,9 +210,12 @@ public class FileDocumentManagerImpl extends FileDocumentManagerBase implements
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public void markDocumentUnsaved(Document document) {
|
||||
public void markDocumentUnsaved(Document document, boolean force) {
|
||||
if (!ApplicationManager.getApplication().hasWriteAction(ExternalChangeAction.ExternalDocumentChange.class)) {
|
||||
myUnsavedDocuments.add(document);
|
||||
if (force) {
|
||||
document.putUserData(FORCE_SAVE_DOCUMENT_KEY, Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,6 +243,7 @@ public class FileDocumentManagerImpl extends FileDocumentManagerBase implements
|
||||
VirtualFile file = getFile(document);
|
||||
if (file == null) continue;
|
||||
unbindFileFromDocument(file, document);
|
||||
document.putUserData(FORCE_SAVE_DOCUMENT_KEY, null);
|
||||
}
|
||||
myUnsavedDocuments.clear();
|
||||
myMultiCaster.unsavedDocumentsDropped();
|
||||
@@ -440,6 +445,8 @@ public class FileDocumentManagerImpl extends FileDocumentManagerBase implements
|
||||
LoadTextUtil.write(project, file, this, text, document.getModificationStamp());
|
||||
|
||||
myUnsavedDocuments.remove(document);
|
||||
document.putUserData(FORCE_SAVE_DOCUMENT_KEY, null);
|
||||
|
||||
LOG.assertTrue(!myUnsavedDocuments.contains(document));
|
||||
myTrailingSpacesStripper.clearLineModificationFlags(document);
|
||||
});
|
||||
@@ -458,11 +465,17 @@ public class FileDocumentManagerImpl extends FileDocumentManagerBase implements
|
||||
|
||||
private void removeFromUnsaved(@NotNull Document document) {
|
||||
myUnsavedDocuments.remove(document);
|
||||
document.putUserData(FORCE_SAVE_DOCUMENT_KEY, null);
|
||||
|
||||
myMultiCaster.unsavedDocumentDropped(document);
|
||||
LOG.assertTrue(!myUnsavedDocuments.contains(document));
|
||||
}
|
||||
|
||||
private static boolean isSaveNeeded(@NotNull Document document, @NotNull VirtualFile file) throws IOException {
|
||||
if (document.getUserData(FORCE_SAVE_DOCUMENT_KEY)== Boolean.TRUE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (file.getFileType().isBinary() || document.getTextLength() > 1000 * 1000) { // don't compare if the file is too big
|
||||
return true;
|
||||
}
|
||||
@@ -757,7 +770,9 @@ public class FileDocumentManagerImpl extends FileDocumentManagerBase implements
|
||||
myMultiCaster.fileWithNoDocumentChanged(file);
|
||||
myMultiCaster.afterDocumentUnbound(file, document);
|
||||
}
|
||||
|
||||
myUnsavedDocuments.remove(document);
|
||||
document.putUserData(FORCE_SAVE_DOCUMENT_KEY, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user