mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Configurable Safe Write option
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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<Searchabl
|
||||
else if (settings.getConfirmOpenNewProject() == GeneralSettings.OPEN_PROJECT_ASK) {
|
||||
settings.setConfirmOpenNewProject(GeneralSettings.OPEN_PROJECT_NEW_WINDOW);
|
||||
}
|
||||
// AutoSave in inactive
|
||||
settings.setAutoSaveIfInactive(myComponent.myChkAutoSaveIfInactive.isSelected());
|
||||
try {
|
||||
int newInactiveTimeout = Integer.parseInt(myComponent.myTfInactiveTimeout.getText());
|
||||
@@ -67,10 +66,8 @@ public class GeneralSettingsConfigurable extends CompositeConfigurable<Searchabl
|
||||
settings.setInactiveTimeout(newInactiveTimeout);
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException ignored) {
|
||||
}
|
||||
|
||||
|
||||
catch (NumberFormatException ignored) { }
|
||||
settings.setUseSafeWrite(myComponent.myChkUseSafeWrite.isSelected());
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
@@ -92,16 +89,15 @@ public class GeneralSettingsConfigurable extends CompositeConfigurable<Searchabl
|
||||
try {
|
||||
inactiveTimeout = Integer.parseInt(myComponent.myTfInactiveTimeout.getText());
|
||||
}
|
||||
catch (NumberFormatException ignored) {
|
||||
}
|
||||
|
||||
catch (NumberFormatException ignored) { }
|
||||
isModified |= inactiveTimeout > 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<Searchabl
|
||||
myComponent.myChkReopenLastProject.setSelected(settings.isReopenLastProject());
|
||||
myComponent.myChkSyncOnFrameActivation.setSelected(settings.isSyncOnFrameActivation());
|
||||
myComponent.myChkSaveOnFrameDeactivation.setSelected(settings.isSaveOnFrameDeactivation());
|
||||
|
||||
myComponent.myChkAutoSaveIfInactive.setSelected(settings.isAutoSaveIfInactive());
|
||||
myComponent.myTfInactiveTimeout.setText(Integer.toString(settings.getInactiveTimeout()));
|
||||
myComponent.myTfInactiveTimeout.setEditable(settings.isAutoSaveIfInactive());
|
||||
myComponent.myChkUseSafeWrite.setSelected(settings.isUseSafeWrite());
|
||||
myComponent.myConfirmExit.setSelected(settings.isConfirmExit());
|
||||
myComponent.myConfirmFrameToOpenCheckBox.setSelected(settings.getConfirmOpenNewProject() == GeneralSettings.OPEN_PROJECT_ASK);
|
||||
}
|
||||
@@ -155,23 +151,19 @@ public class GeneralSettingsConfigurable extends CompositeConfigurable<Searchabl
|
||||
return "preferences.general";
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class MyComponent {
|
||||
JPanel myPanel;
|
||||
|
||||
private JPanel myPanel;
|
||||
private JCheckBox myChkReopenLastProject;
|
||||
private JCheckBox myChkSyncOnFrameActivation;
|
||||
private JCheckBox myChkSaveOnFrameDeactivation;
|
||||
private JCheckBox myChkAutoSaveIfInactive;
|
||||
private JTextField myTfInactiveTimeout;
|
||||
public JCheckBox myConfirmExit;
|
||||
private JCheckBox myChkUseSafeWrite;
|
||||
private JCheckBox myConfirmExit;
|
||||
private JPanel myPluginOptionsPanel;
|
||||
private JCheckBox myConfirmFrameToOpenCheckBox;
|
||||
|
||||
|
||||
public MyComponent() {
|
||||
}
|
||||
public MyComponent() { }
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="ca628" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="ca628" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
@@ -87,7 +87,7 @@
|
||||
</hspacer>
|
||||
<vspacer id="da5bb">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="e5195" class="javax.swing.JCheckBox" binding="myChkSaveOnFrameDeactivation">
|
||||
@@ -137,9 +137,21 @@
|
||||
<columns value="10"/>
|
||||
<margin top="0" left="2" bottom="0" right="4"/>
|
||||
</properties>
|
||||
<clientProperties>
|
||||
<caretAspectRatio class="java.lang.Float" value="0.04"/>
|
||||
</clientProperties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="6f8cf" class="javax.swing.JCheckBox" binding="myChkUseSafeWrite">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<selected value="true"/>
|
||||
<text value="Use "safe write""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<hspacer id="e616c">
|
||||
|
||||
+3
-3
@@ -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<LocalFileOperationsHandler> myHandlers = new ArrayList<LocalFileOperationsHandler>();
|
||||
|
||||
@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
|
||||
|
||||
Reference in New Issue
Block a user