From: <ez...@us...> - 2017-07-14 14:41:04
|
Revision: 24725 http://sourceforge.net/p/jedit/svn/24725 Author: ezust Date: 2017-07-14 14:41:01 +0000 (Fri, 14 Jul 2017) Log Message: ----------- More from Patch 596. Final touches and cleanup. Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/Buffer.java jEdit/trunk/org/gjt/sp/jedit/MiscUtilities.java jEdit/trunk/org/gjt/sp/jedit/PerspectiveManager.java jEdit/trunk/org/gjt/sp/jedit/View.java jEdit/trunk/org/gjt/sp/jedit/bufferio/BufferAutosaveRequest.java jEdit/trunk/org/gjt/sp/jedit/bufferset/BufferSetManager.java jEdit/trunk/org/gjt/sp/jedit/jEdit.java jEdit/trunk/org/gjt/sp/jedit/options/SaveBackupOptionPane.java jEdit/trunk/org/jedit/localization/jedit_en.props Modified: jEdit/trunk/org/gjt/sp/jedit/Buffer.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/Buffer.java 2017-07-02 17:28:41 UTC (rev 24724) +++ jEdit/trunk/org/gjt/sp/jedit/Buffer.java 2017-07-14 14:41:01 UTC (rev 24725) @@ -349,11 +349,33 @@ */ public void autosave() { - if(autosaveFile == null || !getFlag(AUTOSAVE_DIRTY) + autosave(false); + } //}}} + + //{{{ autosave() method + /** + * Autosaves this buffer. + * + * @param force save even if AUTOSAVE_DIRTY not set + * @since jEdit 5.5pre1 + */ + public void autosave(boolean force) + { + + if(autosaveFile == null || (!getFlag(AUTOSAVE_DIRTY) && !force) || !isDirty() || isPerformingIO() || !autosaveFile.getParentFile().exists()) return; + // re-set autosave file path, based on the path at the settings + File autosaveFileOriginal = autosaveFile; + setAutosaveFile(); + + // if autosave path settings changed, delete the old file + if(autosaveFile != null && !autosaveFileOriginal.toString().equals(autosaveFile.toString())) { + autosaveFileOriginal.delete(); + } + setFlag(AUTOSAVE_DIRTY,false); ThreadUtilities.runInBackground(new BufferAutosaveRequest( @@ -900,6 +922,7 @@ /** * * @param untitled untitled value to set + * @since jEdit 5.5pre1 */ protected void setUntitled(boolean untitled) { @@ -1903,9 +1926,6 @@ setFileReadOnly(true); name = vfs.getFileName(path); - // reloading an untitled, so retain the path - boolean reloadingUntitled = name.startsWith("#") && name.endsWith("#"); - // clean up buffer name // #filename# is for autosave, e.g. reloading autosaved file, remove #'s from the buffer's name if ( name.startsWith("#") && name.endsWith("#")) @@ -1925,13 +1945,8 @@ if(autosaveFile != null) autosaveFile.delete(); - if ( reloadingUntitled ) { - autosaveFile = file; - } else { - File autosaveDir = MiscUtilities.prepareAutosaveDirectory(symlinkPath, isUntitled()); - autosaveFile = new File(autosaveDir,'#' + name + '#'); + setAutosaveFile(); } - } else { // I wonder if the lack of this broke anything in the @@ -1942,6 +1957,16 @@ } } //}}} + //{{{ setAutosaveFile() method + /** + * Set the autosave file, based on the autosettings dir. + * @since jEdit 5.5pre1 + */ + private void setAutosaveFile() + { + File autosaveDir = MiscUtilities.prepareBackupDirectory(symlinkPath); + autosaveFile = new File(autosaveDir,'#' + name + '#'); + } //}}} //{{{ recoverAutosave() method private boolean recoverAutosave(final View view) Modified: jEdit/trunk/org/gjt/sp/jedit/MiscUtilities.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/MiscUtilities.java 2017-07-02 17:28:41 UTC (rev 24724) +++ jEdit/trunk/org/gjt/sp/jedit/MiscUtilities.java 2017-07-14 14:41:01 UTC (rev 24725) @@ -672,35 +672,21 @@ } }// }}} - //{{{ prepareAutosaveDirectory method + //{{{ getBackupDirectory method /** - * Prepares the directory to autosave the specified file. - * If the backup directory is specified, it is used. Otherwise, - * the current directory is used, but only for local files. - * The directory is created if does not exist. - * @param path VFS path to the Buffer - * @param untitled do we need the path for untitled buffer - * @return Autosave directory, or null if no backup directory is specified and it is a non-local file. - * @since 5.0pre1 + * Get backup.directory property, or null. + * @return backup.directory property, or null + * @since jEdit 5.5pre1 */ - public static File prepareAutosaveDirectory(String path, boolean untitled) + public static String getBackupDirectory() { - return prepareBackupDirectory(path, untitled); - }// }}} - - //{{{ prepareAutosaveDirectory method - /** - * Prepares the directory to autosave the specified file. - * If the backup directory is specified, it is used. Otherwise, - * the current directory is used, but only for local files. - * The directory is created if does not exist. - * @param path VFS path to the Buffer - * @return Autosave directory, or null if no backup directory is specified and it is a non-local file. - * @since 5.0pre1 - */ - public static File prepareAutosaveDirectory(String path) + String backupDirectory = jEdit.getProperty("backup.directory"); + if(backupDirectory == null || backupDirectory.length() == 0) { - return prepareBackupDirectory(path); + return null; + } else { + return MiscUtilities.expandVariables(backupDirectory); + } }// }}} //{{{ prepareBackupDirectory method @@ -717,24 +703,6 @@ */ public static File prepareBackupDirectory(String path) { - return prepareBackupDirectory(path, false); - } - - //{{{ prepareBackupDirectory method - /** - * Prepares the directory to backup the specified file. - * A jEdit property is used to determine the directory. - * If there is no dedicated backup directory specified by props, - * then the current directory is used, but only for local files. - * The directory is created if it does not exist. - * @param path path to the buffer - * @param untitled do we need the path for untitled buffer - * @return Backup directory. <code>null</code> is returned for - * non-local files if no backup directory is specified in properties. - * @since 5.0pre1 - */ - public static File prepareBackupDirectory(String path, boolean untitled) - { boolean isLocal = VFSManager.getVFSForPath(path) instanceof FileVFS; File file; if (isLocal) @@ -746,8 +714,8 @@ dir=dir.getParentFile(); // Check for backup.directory - String backupDirectory = jEdit.getProperty("backup.directory"); - if(backupDirectory == null || backupDirectory.length() == 0) + String backupDirectory = getBackupDirectory(); + if(backupDirectory == null) { if (!isLocal) return null; @@ -754,13 +722,6 @@ } else { - backupDirectory = MiscUtilities.expandVariables(backupDirectory); - - boolean autosaveUntitled = jEdit.getBooleanProperty("autosaveUntitled"); - if ( untitled && autosaveUntitled ) { - return new File(backupDirectory); - } - if (path.startsWith(backupDirectory)) return dir; // Perhaps here we would want to guard with Modified: jEdit/trunk/org/gjt/sp/jedit/PerspectiveManager.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/PerspectiveManager.java 2017-07-02 17:28:41 UTC (rev 24724) +++ jEdit/trunk/org/gjt/sp/jedit/PerspectiveManager.java 2017-07-14 14:41:01 UTC (rev 24725) @@ -166,9 +166,7 @@ out.write("\">"); // for untitled, we only have the autosave file - out.write(XMLUtilities.charsToEntities( - buffer.isUntitled()?buffer.getAutosaveFile().getPath():buffer.getPath(), - false)); + out.write(XMLUtilities.charsToEntities(buffer.getPath(), false)); out.write("</BUFFER>"); out.write(lineSep); Modified: jEdit/trunk/org/gjt/sp/jedit/View.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/View.java 2017-07-02 17:28:41 UTC (rev 24724) +++ jEdit/trunk/org/gjt/sp/jedit/View.java 2017-07-14 14:41:01 UTC (rev 24725) @@ -1683,8 +1683,7 @@ EditPane editPane = (EditPane) component; splitConfig.append('"'); Buffer editPaneBuffer = editPane.getBuffer(); - splitConfig.append(StandardUtilities.charsToEscapes( - editPaneBuffer.isUntitled()?editPaneBuffer.getAutosaveFile().getPath():editPaneBuffer.getPath())); + splitConfig.append(StandardUtilities.charsToEscapes(editPaneBuffer.getPath())); splitConfig.append("\" buffer"); BufferSet bufferSet = editPane.getBufferSet(); Buffer[] buffers = bufferSet.getAllBuffers(); @@ -1693,8 +1692,7 @@ if (!buffer.isNewFile() || (buffer.isUntitled() && autosaveUntitled)) { splitConfig.append(" \""); - splitConfig.append(StandardUtilities.charsToEscapes( - buffer.isUntitled()?buffer.getAutosaveFile().getPath():buffer.getPath() )); + splitConfig.append(StandardUtilities.charsToEscapes(buffer.getPath() )); splitConfig.append("\" buff"); } } Modified: jEdit/trunk/org/gjt/sp/jedit/bufferio/BufferAutosaveRequest.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/bufferio/BufferAutosaveRequest.java 2017-07-02 17:28:41 UTC (rev 24724) +++ jEdit/trunk/org/gjt/sp/jedit/bufferio/BufferAutosaveRequest.java 2017-07-14 14:41:01 UTC (rev 24725) @@ -71,9 +71,14 @@ buffer.readLock(); if(buffer.isDirty()) out = vfs._createOutputStream(session,path,view); - if(out != null) + if(out != null) { + Log.log(Log.DEBUG,MiscUtilities.class, + "Saving autosave of file \"" + + buffer.getPath() + "\" to \"" + + path + '"'); write(buffer,out); } + } catch (FileNotFoundException e) { Log.log(Log.WARNING,this,"Unable to save " + e.getMessage()); Modified: jEdit/trunk/org/gjt/sp/jedit/bufferset/BufferSetManager.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/bufferset/BufferSetManager.java 2017-07-02 17:28:41 UTC (rev 24724) +++ jEdit/trunk/org/gjt/sp/jedit/bufferset/BufferSetManager.java 2017-07-14 14:41:01 UTC (rev 24725) @@ -349,12 +349,13 @@ } if (parent == null) { - // autosave files will be in a separated dir - String settingsDirectory = jEdit.getSettingsDirectory(); - parent = MiscUtilities.prepareAutosaveDirectory(settingsDirectory, true).getPath(); + parent = MiscUtilities.getBackupDirectory(); } - VFS vfs = VFSManager.getVFSForPath(parent); - if ((vfs.getCapabilities() & VFS.WRITE_CAP) == 0) + VFS vfs = null; + if (parent != null) { + vfs = VFSManager.getVFSForPath(parent); + } + if (vfs != null && (vfs.getCapabilities() & VFS.WRITE_CAP) == 0) { // cannot write on that VFS, creating untitled buffer in home directory parent = System.getProperty("user.home"); Modified: jEdit/trunk/org/gjt/sp/jedit/jEdit.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/jEdit.java 2017-07-02 17:28:41 UTC (rev 24724) +++ jEdit/trunk/org/gjt/sp/jedit/jEdit.java 2017-07-14 14:41:01 UTC (rev 24725) @@ -1772,7 +1772,7 @@ * * @return the buffer, or null if jEdit was unable to load it * - * @since jEdit 3.2pre10 + * @since jEdit 5.5pre1 */ public static Buffer openTemporary(View view, String parent, String path, boolean newFile, boolean untitled) @@ -1827,12 +1827,7 @@ path = path.substring(5); } - if ( untitled ) { - path = MiscUtilities.constructPath( - MiscUtilities.prepareAutosaveDirectory(settingsDirectory, untitled).getPath(),path); - } else { path = MiscUtilities.constructPath(parent,path); - } if(props == null) props = new Hashtable<String, Object>(); @@ -1918,7 +1913,6 @@ /** * Creates a new `untitled' file. - * Default directory is <settings_dir>/autosave * * @param editPane The editPane to create the file in * @@ -1933,8 +1927,8 @@ { path = editPane.getBuffer().getDirectory(); } else { - File autosaveDir = MiscUtilities.prepareAutosaveDirectory(System.getProperty("user.home"), true); - path = autosaveDir.getPath(); + File backupDir = MiscUtilities.prepareBackupDirectory(System.getProperty("user.home")); + path = backupDir.getPath(); } VFS vfs = VFSManager.getVFSForPath(path); // don't want 'New File' to create a read only buffer Modified: jEdit/trunk/org/gjt/sp/jedit/options/SaveBackupOptionPane.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/options/SaveBackupOptionPane.java 2017-07-02 17:28:41 UTC (rev 24724) +++ jEdit/trunk/org/gjt/sp/jedit/options/SaveBackupOptionPane.java 2017-07-14 14:41:01 UTC (rev 24725) @@ -154,6 +154,7 @@ jEdit.setBooleanProperty("confirmSaveAll",confirmSaveAll.isSelected()); jEdit.setProperty("autosave", this.autosave.getText()); jEdit.setProperty("backups",backups.getText()); + String backupDirectoryOriginal = jEdit.getProperty("backup.directory"); jEdit.setProperty("backup.directory",backupDirectory.getText()); jEdit.setProperty("backup.prefix",backupPrefix.getText()); jEdit.setProperty("backup.suffix",backupSuffix.getText()); @@ -176,6 +177,20 @@ } } } + + // if backup dir changed, we should issue to perform an autosave for all dirty and all untitled buffers + // to have the autosaves at the new location + if (!backupDirectoryOriginal.equals(backupDirectory.getText())) { + Buffer[] buffers = jEdit.getBuffers(); + for (Buffer buffer : buffers) { + // save dirty + if ( buffer.isDirty() ) { + buffer.autosave(true); + } + + } + } + } //}}} //{{{ Private members Modified: jEdit/trunk/org/jedit/localization/jedit_en.props =================================================================== --- jEdit/trunk/org/jedit/localization/jedit_en.props 2017-07-02 17:28:41 UTC (rev 24724) +++ jEdit/trunk/org/jedit/localization/jedit_en.props 2017-07-14 14:41:01 UTC (rev 24725) @@ -1688,7 +1688,7 @@ options.save-back.backups=Max number of backups: options.save-back.backups.tooltip=to disable, set to 0 options.save-back.backupDirectory=Backup, Autosave directory: -options.save-back.backupDirectory.tooltip=if blank, use buffer directory +options.save-back.backupDirectory.tooltip=If blank, use buffer directory. $VARIABLE/prefixes allowed. options.save-back.backupPrefix=Backup filename prefix: options.save-back.backupSuffix=Backup filename suffix: options.save-back.backupEverySave=Backup on every save This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |