Added workaround to prevent temp files hijacking active tab on session change.
What is this and where is the commit?
when closing a temp file and choosing "Save", I'd suggest using some other default directory than the one where temp files are stored so users aren't tempted to store the files there (and be surprised by the consequences if they choose a `gtemp_x` file name)
I would also like this but we wont be able to do it on plugin level, directory is defined and set to save-as window in core code and also very early.
You could just avoid using `dialogs_show_save_as()` and implement it manually similarly to e.g. `target_directory_button_clicked_cb()` but for saving files in this case (note the changes related to #3861 - if you copy the code of `target_directory_button_clicked_cb()` and modify it, you can reuse `file_chooser_run()` and `file_chooser_destroy()`).
- since all temp files are opened on session load, there could be one more option in the dialog asking what to do when closing a temp file - "Close". This would just close the temp file but keep it saved on the disk. I can imagine it could be useful when someone is not interested to see the temp file for some project but still wants to keep it for other projects. I'd also maybe rename "Don't save" to "Delete" so it's clear the contents of the tab is lost.
To me such UX seems to allow user too many options ...
Fair enough, makes sense.
- it would be worth considering whether `create_new_temp_file_name()` shouldn't rather iterate over integers and test whether `gtemp_i` exists - this way, when e.g. `gtemp_5` is open and all other temp files closed, `gtemp_1-4` file names could be reused again for new tabs
Instead of using GDir, storing the result into a hash table, and then iterating over integers, wouldn't it be easier to do something like ```C gint i;
for (i = 1; i < 1000; i++) { gchar *name = g_strdup_printf("%s%c%s%d", persistent_temp_files_target_dir, G_DIR_SEPARATOR, PERSISTENT_TEMP_FILE_NAME_PREFIX, i); gboolean file_exists = g_file_test(dirpath_locale, G_FILE_TEST_EXISTS); g_free(name;) if (!file_exists) break; }
return g_strdup_printf("%s%d", PERSISTENT_TEMP_FILE_NAME_PREFIX, i); ```
Untested, possibly missing some details.