@techee requested changes on this pull request.
Looks pretty good, I've just added a few more comments.
There are two things that should still be resolved:
1. The naming of this feature and its placement in preferences
2. How it should behave on project opens/closes.
For (1) my current suggestion is (if others dislike Scribble) "Persistent
notebooks" and the corresponding preferences would be merged "Instant save" and
this feature under the "Untitled Document Actions". It would look something
like this:
```
Untitled Document Behavior
() Default
() Instant Save
Directory to save files in
[entry ]
Current description
() Persistent Notebook
Directory to save persistent notebook files in
[entry ]
Save interval
[entry ]
Default filetype [Combo]
```
and things will get greyed-out depending on the selection.
Now to (2), i.e. behavior on project opens/closes. I've been playing with it a
little and I find it kind of stupid that persistent files don't survive project
opens:
1. One may need to "transfer" some piece of code from one project to another
and opening it separately adds extra complexity.
2. There might be more and more "stale" temp files stored as some projects get
deleted and unused and these would become inaccessible from the normal UI.
One option could possibly be a new menu item "Open all persistent notebooks"
which would open all temp files stored in the target directory but I think even
better if these are opened automatically. (And I know, I was the one who
suggested it should just rely on Geany's session handling and now I think I was
wrong, sorry.)
Ideally this feature should do nothing if all the persistent files are already
stored in the session and preserve the active document stored in the session.
Only when some persistent files are missing in the current session, those
should be opened.
Implementing would be a bit fiddly as Geany doesn't report when it opened a
project or the default session but I think doable.
There could be a variable, let's call it `session_opening` indicating whether a
session (default or project) is being opened. It would be set to TRUE in these
situations:
1. `plugin_init()` - even though the session isn't loading now, the plugin load
should open the notebooks upon load.
2. "project-open" signal handler - project session files will be loaded
afterwards
3. "project-close" signal handler - project is being closed, defult session
will be loaded afterwards
Then the plugin should connect to the "document-activate" signal. When session
is being opened, it's only fired for the tab that becomes active once all the
session files are loaded so you can be sure it's called only once. In its
handler you can check if `session_opening == TRUE` (and reset it back to
FALSE). If TRUE, it means it was session loading and not normal tab switching.
Then you can go through the contents of the temp file directory, check if there
are open documents for all the files, and if not, open them.
In any case, before spending any more time on this, better to finally ask
someone wise ;-). @b4n What do you think about this feature and the possible
ways it could be implemented?
> @@ -304,6 +314,274 @@ static void instantsave_document_new_cb(GObject *obj,
> GeanyDocument *doc, gpoint
}
+static gboolean is_temp_saved_file(const gchar *file_path_utf8)
Since you already pass the whole path in most cases (I think there's just one
case where the directory will have to be added), this function could also check
whether the directory corresponds to the configured target directory. Better to
be on the save side since closing temp saved files may lead to their deletion.
> + ret = gtk_dialog_run(GTK_DIALOG(dialog));
+
+ gtk_widget_destroy(dialog);
+
+ return ret;
+}
+
+
+static void show_unsaved_dialog_for_persistent_temp_files_tab_closing(
+ GeanyDocument *doc, const gchar *short_filename)
+{
+ gchar *msg, *old_file_path, *locale_file_path;
+ const gchar *msg2;
+ gint response;
+
+ msg = g_strdup_printf(_("The file '%s' is not saved."), short_filename);
Possibly to be updated later when we agree on some "correct" naming of this
feature. But I'd not refer to file here - could be something like "Notebook is
not saved".
> + {
+ /* we have to store old filename inside document data
to be able to somehow
+ pass it to document-save callback that is called
directly after this one */
+ plugin_set_document_data_full(geany_plugin, doc,
"file-name-before-save-as",
+ g_strdup(old_file_path_utf8), g_free);
+ }
+ }
+}
+
+
+static void persistent_temp_files_document_save_cb(GObject *obj, GeanyDocument
*doc, gpointer user_data)
+{
+ gchar *new_file_path_utf8, *old_file_path_utf8;
+
+ new_file_path_utf8 = DOC_FILENAME(doc);
+ old_file_path_utf8 = plugin_get_document_data(geany_plugin, doc,
"file-name-before-save-as");
Call `plugin_set_document_data(..., "file-name-before-save-as", NULL)` so the
previous `old_file_path_utf8` isn't attached to the document (could cause
problems when ordinary "save" would think it's "save as").
> +
+
+static void show_unsaved_dialog_for_persistent_temp_files_tab_closing(
+ GeanyDocument *doc, const gchar *short_filename)
+{
+ gchar *msg, *old_file_path, *locale_file_path;
+ const gchar *msg2;
+ gint response;
+
+ msg = g_strdup_printf(_("The file '%s' is not saved."), short_filename);
+ msg2 = _("Do you want to save it before closing?");
+
+ response =
run_unsaved_dialog_for_persistent_temp_files_tab_closing(msg, msg2);
+ g_free(msg);
+
+ locale_file_path = g_strdup(doc->real_path);
The `g_strdup()` and maybe even the whole `locale_file_path` could be removed
here and `doc->real_path` could be used instead everywhere.
--
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/3911#pullrequestreview-2136554129
You are receiving this because you are subscribed to this thread.
Message ID: <geany/geany/pull/3911/review/[email protected]>