-
Notifications
You must be signed in to change notification settings - Fork 609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"persistent temp files" feature for saveactions plugin (sqashed PR) #3911
"persistent temp files" feature for saveactions plugin (sqashed PR) #3911
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch - looks good to me in general except for some of the notes below. I personally think that having such a feature in Geany (i.e. multi-tab Scrilbble backed by Scintilla with all the Geany features) would be nice, but depends what others think.
I didn't go through all the things in detail and this is just a rough quick review.
Includes one small extension to API (new function in main.h) - if i understood correctly, this does not require incrementing any versions
Yes, it does, but it can be done one everything is ironed-out.
thanks for your comments, will look at it |
064011a
to
e8f7761
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See some more review comments.
Maybe one more idea - wouldn't it be better to introduce this feature just as a special mode of "Instant save"? Because I think that's what this feature really is - it just picks the file names automatically, prevents some accidental tab closing but it's instant save otherwise. It would also prevent possible confusion why the Enable button in preferences gets disabled.
What I meant by this is that the whole "persistent temp files" tab in config could go away and the "Instant save" tab would be reused for this feature too. Te rationale about this is:
- It reduces confusion because these features are mutually exclusive and enabling one disables the other and users don't see clearly why this happens.
- I'm slightly worried that users won't get the "persistent temp files" naming and what this feature is good for (as usual, nobody will read the documentation). So what I would suggest is to have a checkbox with something like "Scribble mode" inside the "Instant save" tab enabling this feature. Users probably already know the Scribble tab in Geany's message window and kind of know what to expect. Also, the generated filenames could start with scribble_ making it consistent with existing Geany features.
If it's implemented this way, the code below would just go away, only the save interval would have to be added into "Instant save" (grayed out when "Scribble mode" not enabled) and the text explaining the persistence of the directory where the temp files are stored should be changed a little.
Now before implementing anything, I'd suggest waiting for others what they think about it - this would make sense to me but others may have a different opinion.
* @return always FALSE = Just a one shot execution | ||
* | ||
*/ | ||
static gboolean open_document_once_idle(gpointer p_locale_file_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit unfortunate this is necessary - maybe Geany could add some signal allowing plugins to disallow document closing.
"Does it save the Geany Scribble window then?" [user who didn't read the docs question] Whilst I didn't get the "persistent temp files" either and I still don't know what the use-case is beyond persisting unnamed buffers and I don't understand what the reason for saving unnamed buffers is, if its unnamed how do I know whats in it to switch to it when they are all named "Untitled"? So I can't suggest anything better than the descriptive "save unnamed buffers". |
They will get some file name (see the screencast, I personally would suggest names
That's not the whole thing the patch does though - it really is some "scribble mode" with additional features:
Now to why people (#905), including me, want to have this feature - the Scribble panel is extremely limited and the basic editor features don't work there (see #3558). Having a full-blown Scintilla editor used for Scribble with all editing options and syntax highlighting in a big window would be really nice. And this PR is quite a nice way how to implement it in a pretty much invisible and care-free way for users. |
I know the scribble window is very limited, thats why I'm confused by you wanting to call this "scribble". PS, I said I do not understand the use-case for this, I didn't say not to do it, just because I don't understand why you would want it doesn't mean not to do it. (if that was the case Geany wouldn't have a C filetype 😜 ) |
Well, it doesn't really have to be called this way, I'd just call it based on what it's supposed to do instead of how it's implemented (i.e. "persistent temp files"). Could be for instance "persistent notepad" and the individual tabs would be |
Ok, at least "notepad" is a term thats not used so far AFAICT so it won't get confused with something else. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, I've just added a few more comments.
There are two things that should still be resolved:
- The naming of this feature and its placement in preferences
- 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:
- One may need to "transfer" some piece of code from one project to another and opening it separately adds extra complexity.
- 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:
plugin_init()
- even though the session isn't loading now, the plugin load should open the notebooks upon load.- "project-open" signal handler - project session files will be loaded afterwards
- "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?
One more thing. The plugin should pre-fill Also, when this empty directory gets confirmed, the plugin shows a dialog with error, but this invalid value is stored into the config file anyway (I know this is how the Instantsave feature has it implemented now and you just copied it from there, but it shouldn't be possible to confirm the save action preferences with the invalid value and the preferences dialog shouldn't be closed in this case). Finally, when you confirm the empty directory entry, the plugin crashes in
This should be fixed too. |
not sure how any of these is possible - target_dir value in config file may stay empty while in-memory variable is filled with default value anyway. |
ah found it, the issue appears not when you delete config file but when you dont have directory itself existing on disc, will try to do something with it |
so i reworked settings behavior for this feature, now everything should be fine:
also, i fulfilled old TODO of instantsave code i reused and added one of utils function to plugins API (checking if file is writable) Overall, now everything seems working fine to me. |
added re-opening for all temp files as described here - #3911 (review) |
@LiquidCake Thanks for the updates! I definitely like that the temp files are preserved across project opens/closes and it seems to work very well for me. Some more observations when playing with the feature:
|
Added workaround to prevent temp files hijacking active tab on session change. And about these:
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.
To me such UX seems to allow user too many options to chose from, and also whole idea of allowing user to "keep" temp file on disk while not having it open in editor seems contradicting the essence of feature - user should see 'temp' tab as if it was an 'untitled' tab that just doesnt disappear after we close program. If user wants to save file and close tab - they should explicitly do it with save-as.
done
removed |
What is this and where is the commit?
You could just avoid using
Fair enough, makes sense.
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 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. |
At any session change, including initial startup - we first load session and then call |
i could try, but this would anyway be used only when we try to close temp file tab and chose save-as. But when user just tries to save-as temp file using menu - it will still be opening on temp folder |
lol you're right, changed logic to this one |
Ah, right, I overlooked it - I thought it only removed the API call.
OK, I didn't think of this possibility - I guess it doesn't make sense to spend time on this then.
Better ;-) |
so i think this feature is complete, if we are considering merging it - we should settle on config UI (either keep as is or change to point #1 from #3911 (review)) otherwise it is usable with manual geany build, helps me a lot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so i think this feature is complete, if we are considering merging it -
Agree, I think it's mostly ready.
I just had a look at the code once more and found some minor issues but nothing big.
we should settle on config UI (either keep as is or change to point #1 from #3911 (review))
And probably rename everything to "persistent notepad" or something like that.
I've been thinking about it and maybe "persistent untitled documents" would be best so there's no new terminology. I still think it would be best to merge the configuration with "instant save" but depends on what others (@b4n @eht16) think.
Note that we seem to be in the middle of the "Geany summer vacation" period and even normally it takes quite some time to get things merged (so please be patient) but from me at least this PR has full support - it's very useful and it also fixes the issue with the most thumbs up reactions.
One more problem - when you launch Geany from the command-line by
where In any case, I believe this could be mitigated if inside One more request - could you rebase this PR on top of current Geany master (or merge master into this branch)? I'd like to give this feature some more testing but in parallel test the recently merged #3849 together with the LSP plugin. |
merged master, fixed unconditional reopening of files. This is indeed beneficial, though the core issue with keeping right tab active after opening non-existent file from console is related to fact that we cannot manually activate tab that does not yet have underlying file saved to disk (we can activate it only by re-opening file from disc right now). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and works well (apart from the two nitpicky style comments).
the core issue with keeping right tab active after opening non-existent file from console is related to fact that we cannot manually activate tab that does not yet have underlying file saved to disk
Right, that's the reason.
One more thing though - when playing with it, I didn't quite like the behavior of "close all" documents which also closes the temp files - I think these should stay open as they are not normal files (I typically use "close all" when the number of open files gets out of my control but closing temp files kind of kills this feature because one would have to open them manually and spend time on something that should happen automatically).
I believe this could be achieved by reopening all temp files when the number of open tabs drops to 0. I think one could schedule an idle function inside persistent_temp_files_document_close_cb()
(in the geany_is_closing_all_documents()
case) and inside this idle function do something like
static gboolean persistent_temp_files_document_close_idle(gpointer data)
{
if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(geany->main_widgets->notebook)) == 0)
load_all_temp_files_into_editor();
}
I think at the point this idle function is called, Geany will have all the documents closed.
(One slight problem is that when closing 100 files, the idle function will be scheduled 100 times and when there are no temp files, load_all_temp_files_into_editor();
will be also called 100 times and try to find some temp files but I think even this will be very quick and not worth taking care of.)
By the way I did run into a strange issue during Geany quitting when this feature is used in combination with the LSP plugin. Not a problem of this PR, I'll try to address it with #4069. |
c1c3673
to
4c1191a
Compare
…persistent-untitled-documents' feature, re-organized 'instantsave' feature config
@techee i've reset branch and re-applied changes as 2 commits, i guess this is what we want |
I've just diffed it against the previous version and apart from a fixed whitespace, there's no other difference in saveactions.c 👍 I'll wait until the next weekend and unless anybody has some more comments, I would merge it afterwards 🎉 If you feel bored, it would be good to address #4033 - possibly as a separate PR so possible review comments don't block this PR. I think you don't have to go into too much detail and just describe the general functionality of this feature in Line 5362 in 4264d0c
|
Created PR for doc update #4077 |
I created 3 PRs with fixes to existing bugs i found during development. Autosave cannot be disabled Configured file type is not set to GeanyDocument File templates are not supported Last 2 are related to Instantsave and thus transferred to Pers. docs that were built looking on what Instantsave actually does atm |
I think this patch should be added to this PR - it's pretty straightforward and fixes a problem introduced here.
Does not affect this PR (it works for untitled documents) and was probably present before - I think you can open it once this PR is merged.
Alright, maybe I miss something but I think you can determine a non-file-backed documents just by checking if In addition, I don't think you could change the "document-new" signal without affecting existing plugins. Also, plugins would have to be modified to use In any case, it can wait until this PR is merged. |
all 3 problems are in master branch, you can tell from how config window looks on videos, and PR for Autosave is directed to master (of my fork).
right, it does not affect PUD unless templates start working, then it would in a minor way. But we could just merge changes from that PR into current one or create new one afterwards or just forget about it - as you prefer
Here is how i see it: Then, we have this commit - now filename is pre-generated for template-created document and is set to document struct. So from this point on, Instantsave is not working with such new files. And this is how it works now in my PR, once we let Instantsave pass beyond If we dont fix this - we should at least remove mentions of supporting templates from geany.txt, in my PR #4077 i kept mentions and furthermore moved it to common part that describes both IS and PUD since their code in that place is common.
This is not cool, yes, alternatives would be worse - add field to GeanyDocument or just change template-spawned file name to something definitive like "untitled-tpl" and check for this kind of name here
Noone is oblidged to use it as old document_new_file() func still exists. If this doesnt brake ABI things should work for any plugin without re-compiling even. But here im not sure i wont insist on doing anything as i dont personally need any of these to work and dont have that much spare time to keep working on it, but if we want/can complete this work and cut all tails - would be nice. |
I don't care much, you can post it afterwards too.
I'm slightly lost in what you are proposing here - as I said, I think it can wait until this PR is merged.
I'm not questioning the fact that it doesn't work - I just don't think your implementation is the right one. You can't change the "document-new" signal - you break API towards plugins this way. Also, as I said, plugins would have to be modified to use As I said, instead, the plugin itself should try to do it right by itself without any extra API.
This is an option too, depends which way you decide to go.
Again, I'd point you to |
Then i'll just create another PR after this one is merged
I proposed to add those changes right to this PR, but doesnt matter, i'll create another PR after this one is merged
ok got it about Which leads us to the last open question - since templates are not working - what to do with geany.txt from another PR - should i remove mentions of templates from |
To me it doesn't sound too difficult so I'll try to do it myself once this PR is merged. But of course on the way I can realize it's not so easy as I imagine and may decide it's not worth it.
Since this is a separate PR, I'd say let's wait if I manage to implement it in which case we can keep it; otherwise we can drop it.
In the light of the above, I think it would actually be best if you added both of the fixes to this PR so I can start the work on the finished result. I think you can keep these as separate commits (no rebasing needed). |
done |
@LiquidCake I just tried this in Maybe I'm overlooking something but IMO it's as simple as that. Could you have a look at it and give it a try? |
looks good to me |
Good to hear. Would it be OK if I push the change to this PR so we don't have to open another one?
And other from the plugins - e.g. the VC plugin shows git history in a non-saved tab. But you can start editing this document and then you probably want it to be persistent with this feature (on the other hand, when you don't edit it, you just want to close it without any warning which is why I added the modification check). |
…similar We don't want to convert non-empty documents to instant save or persistent untitled documents immediately since these may just be temporary files with some information that the user wants to close after their creation. Instead, these converted to files only after they are modified for the first time.
sure
i see, then original (broken) logic from instantsave was not really enough but we didnt know because it was blocked |
@LiquidCake The day has come, merging. 🎉 Thanks for all the work and your patience, really appreciated! |
nice, thanks for you support |
Extension of saveactions plugin that allows Geany to store/load data for new, unnamed tabs when Geany window is closed/reopened.
This is a convenience feature inspired by Notepad++ and discussed here #905
Includes one small extension to API (new function in main.h) - if i understood correctly, this does not require incrementing any versions
persistent_temp_files.mp4