diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2014-11-01 22:18:59 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2014-11-01 22:18:59 +0100 |
commit | 06d0bac8006889749fbf03efd5200ae68818b576 (patch) | |
tree | 177d88ce165e2129cb845e0271ab1217880bb89a /src | |
parent | 2123df90ffb5ae07c6439609123fad14cb75d9ef (diff) | |
download | sciteco-06d0bac8006889749fbf03efd5200ae68818b576.tar.gz |
fixed reversing EW (save as)
when the file name changes, there will no longer be a use-less
save point file. instead the new file is deleted upon rubout.
* save points are properly created if a file already exists
with the same name, even though it was not known to SciTECO before
the save. (e.g. you do save-as to a file that already exists).
* more effects of the save command can now be rubbed out correctly
Diffstat (limited to 'src')
-rw-r--r-- | src/ring.cpp | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/src/ring.cpp b/src/ring.cpp index c5df8e3..939a75c 100644 --- a/src/ring.cpp +++ b/src/ring.cpp @@ -391,25 +391,39 @@ Ring::save(const gchar *filename) if (!current) return false; - if (!filename) - filename = current->filename; - if (!filename) + if (!filename && !current->filename) return false; + /* + * Undirtify + * NOTE: info update is performed by current->set_filename() + */ + interface.undo_info_update(current); + undo.push_var(current->dirty) = false; + + /* + * FIXME: necessary also if the filename was not specified but the file + * is (was) new, in order to canonicalize the filename. + * May be circumvented by cananonicalizing without requiring the file + * name to exist (like readlink -f) + * NOTE: undo_info_update is already called above + */ + undo.push_str(current->filename); + current->set_filename(filename ? : current->filename); + if (undo.enabled) { - if (current->filename && - g_file_test(current->filename, G_FILE_TEST_IS_REGULAR)) { + if (g_file_test(current->filename, G_FILE_TEST_IS_REGULAR)) { #ifdef G_OS_UNIX g_stat(current->filename, &file_stat); #endif attributes = make_savepoint(current); } else { - undo.push(new UndoTokenRemoveFile(filename)); + undo.push(new UndoTokenRemoveFile(current->filename)); } } /* leaves mode intact if file exists */ - file = g_fopen(filename, "w"); + file = g_fopen(current->filename, "w"); if (!file) return false; @@ -437,7 +451,7 @@ Ring::save(const gchar *filename) /* if file existed but has been renamed, restore attributes */ if (attributes != INVALID_FILE_ATTRIBUTES) - set_file_attributes(filename, attributes); + set_file_attributes(current->filename, attributes); #ifdef G_OS_UNIX /* * only a good try to inherit owner since process user must have @@ -452,21 +466,6 @@ Ring::save(const gchar *filename) fclose(file); - interface.undo_info_update(current); - undo.push_var(current->dirty); - current->dirty = false; - - /* - * FIXME: necessary also if the filename was not specified but the file - * is (was) new, in order to canonicalize the filename. - * May be circumvented by cananonicalizing without requiring the file - * name to exist (like readlink -f) - */ - //if (filename) { - undo.push_str(current->filename); - current->set_filename(filename); - //} - return true; } |