I sometimes try to open a file from a terminal and pass the wrong path. Asking the user to confirm the new file solves this problem, they can easily press escape to cancel the new document.
Occasionally I might use a glob that turns out to be wrong too, creating many unwanted new documents. So I made cancelling a new document ignore any remaining new filenames passed to Geany.
![image](https://user-images.githubusercontent.com/1107820/67089763-58e56200-f1a0-11e...)
You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany/pull/2369
-- Commit Summary --
* Ask whether to open new files from command-line * If new document cancelled, ignore remaining new filenames
-- File Changes --
M src/libmain.c (24)
-- Patch Links --
https://github.com/geany/geany/pull/2369.patch https://github.com/geany/geany/pull/2369.diff
Also, this pull doesn't add any new strings to translate.
Maybe you can just disable "Open new documents form the command-line" in configuration.
Or maybe Geany needs --new-document command line flag.
Maybe you can just disable "Open new documents form the command-line" in configuration.
:+1:
Maybe you can just disable "Open new documents form the command-line" in configuration.
I made that option ;-) I *want* to open new documents from the command-line, but I sometimes accidentally do it too.
Or maybe Geany needs --new-document command line flag.
I thought of that too, but it doesn't help when using a glob pattern that captures more files than you thought it would.
Maybe you can show that confirmation dialog only if is "Open new documents form the command-line" disabled?
PS: Geany don't save new files, so you can always restart Geany to remove unwanted opened files. :)
Maybe you can show that confirmation dialog only if is "Open new documents form the command-line" disabled?
Good idea.
PS: Geany don't save new files, so you can always restart Geany to remove unwanted opened files. :)
That's slow and loses a lot of information like Messages, Compiler tab contents, markers etc.
PS: Geany don't save new files, so you can always restart Geany to remove unwanted opened files. :)
Correct, Geany does not create new __files__ until the document is saved, so just close unwanted ones. There are 10 trillion* more ways to close documents being added in other PRs.
* rough estimate, YMMV
just close unwanted ones
That's a workaround that doesn't fix the problem. I think all that is necessary is to only open new documents from the command-line when there is a single filename passed. If more are needed, use `echo filename_list | xargs geany`.
Well I don't care which choice is made as I almost never open stuff from the command line, but basically the proposal is to remove the feature to open multiple new documents (not __FILES__) in case someone types a filename wrong and is too lazy to close the resulting document?
IMO, it's not a great idea to stick more blocking dialogs in the normal flow for normal users. Given that there's already a setting to fix the issue this PR is for, it seems like a really niche use case for users who want that setting enabled and also don't (sometimes).
IMO, it would be better to just create two aliases (or shortcuts, bat(ch) scripts, etc) which run Geany in either mode, depending on the preference. I do this for example to use Geany as my Git editor with different command-line options/config directories from regular IDE use.
Then it becomes just running the appropriate command, like:
```bash $ geany-no-new foo.c bar.h # or $ geany-new foo.c bar.h ```
it's not a great idea to stick more blocking dialogs in the normal flow for normal users
That's why I suggested only accepting one filename for a new file. But actually it could allow multiple new filenames so long as no existing filenames are also passed.
it would be better to just create two aliases (or shortcuts, bat(ch) scripts, etc) which run Geany in either mode, depending on the preference
That doesn't work - I want to create new files and open existing files *in an existing instance*.
Can this be closed?
* It's been 2 years, so unlikely to be merged. * I agree with... "it's not a great idea to stick more blocking dialogs in the normal flow for normal users." (But I'd phrase it: "Agh. Please stop adding more popups to Geany.") * Is it really any easier to deal with popups than to just close the documents? (Ctrl+W) * Pay more attention to what you're typing? * Use copy/paste. * Here's a bash script workaround:
```bash #!/usr/bin/env bash for f in "$@" ; do if [ -f "$f" ] ; then geany "$f" & else if [ ! "$ignore_rest" = true ] ; then if zenity --question \ --title "Question" \ --text "File not found: "$f"\n\nCreate new document?" then geany "$f" & else ignore_rest=true fi fi fi done ```
@xiota
Is it really any easier to deal with popups than to just close the documents? (Ctrl+W)
The best solution would be either: * require a switch to create new documents, and change the default to not open new documents from the CLI without it. * to only allow one new file from the command-line, and not show a dialog. Is creating multiple new documents from the CLI really needed?
Either would solve the problem.
Pay more attention to what you're typing? (Mistyped commands can do a lot of damage.)
`geany some_filename_glob` will only open files or open new documents. How can that do *a lot of damage*?
geany some_filename_glob will only open files or open new documents. How can that do a lot of damage?
I presume its a windows thing, on linux I would expect the glob will only pass actual filenames, so its only opening, not creating new?
Closed #2369.
@elextr I think the problem happened when I was pasting windows paths into MSYS and I had forgotten to quote or escape the backslashes. I'm now using Linux so it's not important for me ATM. Possibly it could detect if the first filename starts with a letter then a colon but no backslash and ignore the whole command in that case.
github-comments@lists.geany.org