From 5fb4860e088fd8f9708eea438a396ca7c4e7e2b1 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 13 Dec 2011 12:07:50 +0100 Subject: [PATCH] Configurable Safe Write option --- .../src/com/intellij/ide/GeneralSettings.java | 26 +++++++++++++--- .../ide/GeneralSettingsConfigurable.java | 30 +++++++------------ .../intellij/ide/GeneralSettingsPanel.form | 16 ++++++++-- .../vfs/impl/local/LocalFileSystemBase.java | 6 ++-- 4 files changed, 50 insertions(+), 28 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ide/GeneralSettings.java b/platform/platform-api/src/com/intellij/ide/GeneralSettings.java index 52415124e3e7..3fb9b07e514e 100644 --- a/platform/platform-api/src/com/intellij/ide/GeneralSettings.java +++ b/platform/platform-api/src/com/intellij/ide/GeneralSettings.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,6 +46,7 @@ public class GeneralSettings implements NamedJDOMExternalizable, ExportableAppli private boolean mySaveOnFrameDeactivation = true; private boolean myAutoSaveIfInactive = false; // If true the IDEA automatically saves files if it is inactive for some seconds private int myInactiveTimeout; // Number of seconds of inactivity after which IDEA automatically saves all files + private boolean myUseSafeWrite = true; private final PropertyChangeSupport myPropertyChangeSupport; private boolean myUseDefaultBrowser = true; private boolean myConfirmExtractFiles = true; @@ -53,6 +54,7 @@ public class GeneralSettings implements NamedJDOMExternalizable, ExportableAppli private boolean mySearchInBackground; private boolean myConfirmExit = true; private int myConfirmOpenNewProject = OPEN_PROJECT_ASK; + @NonNls private static final String ELEMENT_OPTION = "option"; @NonNls private static final String ATTRIBUTE_NAME = "name"; @NonNls private static final String ATTRIBUTE_VALUE = "value"; @@ -64,6 +66,8 @@ public class GeneralSettings implements NamedJDOMExternalizable, ExportableAppli @NonNls private static final String OPTION_AUTO_SYNC_FILES = "autoSyncFiles"; @NonNls private static final String OPTION_AUTO_SAVE_FILES = "autoSaveFiles"; @NonNls private static final String OPTION_AUTO_SAVE_IF_INACTIVE = "autoSaveIfInactive"; + @NonNls private static final String OPTION_USE_SAFE_WRITE = "useSafeWrite"; + @Deprecated @NonNls private static final String OPTION_CHARSET = "charset"; @Deprecated @@ -77,6 +81,7 @@ public class GeneralSettings implements NamedJDOMExternalizable, ExportableAppli @NonNls private static final String OPTION_CONFIRM_OPEN_NEW_PROJECT = "confirmOpenNewProject2"; @NonNls private static final String OPTION_CYCLIC_BUFFER_SIZE = "cyclicBufferSize"; @NonNls private static final String OPTION_LAST_PROJECT_LOCATION = "lastProjectLocation"; + @Deprecated private Charset myCharset; @Deprecated @@ -207,6 +212,14 @@ public class GeneralSettings implements NamedJDOMExternalizable, ExportableAppli ); } + public boolean isUseSafeWrite() { + return myUseSafeWrite; + } + + public void setUseSafeWrite(final boolean useSafeWrite) { + myUseSafeWrite = useSafeWrite; + } + //todo use DefaultExternalizer public void readExternal(Element parentNode) { List children = parentNode.getChildren(ELEMENT_OPTION); @@ -280,6 +293,10 @@ public class GeneralSettings implements NamedJDOMExternalizable, ExportableAppli catch (Exception ignored) { } } + if (OPTION_USE_SAFE_WRITE.equals(name) && value != null) { + myUseSafeWrite = Boolean.valueOf(value).booleanValue(); + } + if (OPTION_CHARSET.equals(name)) { //for migration myCharset = CharsetToolkit.forName(value); @@ -384,8 +401,6 @@ public class GeneralSettings implements NamedJDOMExternalizable, ExportableAppli optionElement.setAttribute(ATTRIBUTE_VALUE, Boolean.toString(mySaveOnFrameDeactivation)); parentNode.addContent(optionElement); - // AutoSave if inactive - optionElement = new Element(ELEMENT_OPTION); optionElement.setAttribute(ATTRIBUTE_NAME,OPTION_AUTO_SAVE_IF_INACTIVE); optionElement.setAttribute(ATTRIBUTE_VALUE,(myAutoSaveIfInactive?Boolean.TRUE:Boolean.FALSE).toString()); @@ -396,7 +411,10 @@ public class GeneralSettings implements NamedJDOMExternalizable, ExportableAppli optionElement.setAttribute(ATTRIBUTE_VALUE,Integer.toString(myInactiveTimeout)); parentNode.addContent(optionElement); - // + optionElement = new Element(ELEMENT_OPTION); + optionElement.setAttribute(ATTRIBUTE_NAME, OPTION_USE_SAFE_WRITE); + optionElement.setAttribute(ATTRIBUTE_VALUE, (myUseSafeWrite ? Boolean.TRUE : Boolean.FALSE).toString()); + parentNode.addContent(optionElement); optionElement = new Element(ELEMENT_OPTION); optionElement.setAttribute(ATTRIBUTE_NAME, OPTION_USE_DEFAULT_BROWSER); diff --git a/platform/platform-impl/src/com/intellij/ide/GeneralSettingsConfigurable.java b/platform/platform-impl/src/com/intellij/ide/GeneralSettingsConfigurable.java index c748cdeb847b..9c1caa26569d 100644 --- a/platform/platform-impl/src/com/intellij/ide/GeneralSettingsConfigurable.java +++ b/platform/platform-impl/src/com/intellij/ide/GeneralSettingsConfigurable.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,7 +59,6 @@ public class GeneralSettingsConfigurable extends CompositeConfigurable 0 && settings.getInactiveTimeout() != inactiveTimeout; + isModified |= settings.isUseSafeWrite() != myComponent.myChkUseSafeWrite.isSelected(); + return isModified; } public JComponent createComponent() { -// optionGroup.add(getDiffOptions().getPanel()); if (myComponent == null) { myComponent = new MyComponent(); } @@ -137,10 +133,10 @@ public class GeneralSettingsConfigurable extends CompositeConfigurable - + @@ -87,7 +87,7 @@ - + @@ -137,9 +137,21 @@ + + + + + + + + + + + + diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java index 2c4cdf30af9d..dfba3883a4d6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemBase.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.vfs.impl.local; +import com.intellij.ide.GeneralSettings; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; @@ -48,7 +49,6 @@ import java.util.Locale; public abstract class LocalFileSystemBase extends LocalFileSystem { protected static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vfs.impl.local.LocalFileSystemImpl"); - private final boolean myPreventSafeWrite = Boolean.parseBoolean(System.getProperty("idea.no.safe.write")); private final List myHandlers = new ArrayList(); @Override @@ -497,8 +497,8 @@ public abstract class LocalFileSystemBase extends LocalFileSystem { }; } - private boolean shallUseSafeStream(final Object requestor, final VirtualFile file) { - return !myPreventSafeWrite && requestor instanceof SafeWriteRequestor && !file.isSymLink(); + private static boolean shallUseSafeStream(final Object requestor, final VirtualFile file) { + return GeneralSettings.getInstance().isUseSafeWrite() && requestor instanceof SafeWriteRequestor && !file.isSymLink(); } @Override