After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 143646 - gedit opens same file multiple times
gedit opens same file multiple times
Status: RESOLVED FIXED
Product: gedit
Classification: Applications
Component: general
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: Paolo Maggi
Gedit maintainers
: 162162 167867 301510 350348 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2004-06-03 14:04 UTC by Stephen Kennedy
Modified: 2006-08-08 10:16 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
this patch should prevent opening of same file more than once. (1.93 KB, patch)
2004-08-17 15:40 UTC, udayan kumar
none Details | Review
screenie (81.39 KB, image/png)
2005-11-18 11:09 UTC, Paolo Borelli
  Details
First version of a patch implementing my suggestion on comment #13 (3.58 KB, patch)
2006-05-21 16:21 UTC, Paolo Maggi
none Details | Review
Patch v.2 (3.99 KB, patch)
2006-05-21 19:01 UTC, Paolo Maggi
committed Details | Review

Description Stephen Kennedy 2004-06-03 14:04:26 UTC
To reproduce:

1. open a file in gedit.
2. open the file again.

Result:

Two tabs each with a copy of the file

Expected result:

The second "open" switches to the existing buffer.


This should also work for drag and drop so that
1. dropping an already open file switches to that tab
2. dropping multiple files only opens tabs for new files
Comment 1 udayan kumar 2004-08-17 15:40:07 UTC
Created attachment 30664 [details] [review]
this patch should prevent opening of same file more than once.
Comment 2 Paolo Borelli 2004-12-24 21:12:02 UTC
*** Bug 162162 has been marked as a duplicate of this bug. ***
Comment 3 Paolo Borelli 2004-12-24 21:26:27 UTC
(silly me, I wrote the comments on the bug I was marking as duplicate, pasting
them here for reference)

I am not sure that forcing a "spatial behavior" on gedit (just one
view per file) is the right thing to do: for instance opening the same file
twice to compare the modified one from the original is a totally legit thing to
do (and I do it from time to time).

Beside every other text editor on earth allows you to open the same text file
more than once, so I do not consider it a very surprising behavior.


So I guess that this requires more thinking and discussions, a couple of things
that come to my mind:

1 - would a popup dialog sayng "this file is already open, do you want to open
another copy" be annoyng?

2 - note that the risk of losing some work if two different copys are edited
would be milded by the use of file monitoring and/or by checking the mtime
before saving (two issues which are already reported in other bugreports)
Comment 4 Massimo Cora' 2004-12-27 21:30:56 UTC
I think it would be a good thing to let the user decide what to do. There could
be an addon on preferences... I see there's yet a patch, so it won't take much
time to implement it.
Answering at your points:
1. in my opinion it won't be annoying coz this lets the user know that he's
risking to loose some data. As currently gedit is, everything happens silently.

2. If I've N opened files, with N big, I would prefer to have just one tab for a
file, not 2/3/4...: the tab bar is limited by the screen resolution so it'll
take more time to quickly switch from a file to another, there could be some
confusions etc..

Anyway if you don't like the spatial way, you should at least offer it [as for
instance nautilus does]. Under windows I always use Ultraedit that for default
lets just one view per file...
Comment 5 Stephen Kennedy 2005-01-04 12:20:29 UTC
I think we can get the best of both worlds easily enough.
When we are about to open a file which is already open, we show
a dialog with the choices:

The file "%s" is already opened for editing.
"Switch to opened file"
"Open Read-Only"
"Edit anyway"
"Dont open"

Also this dialog has a radiobutton
"Always prompt"
"Always switch to unmodified files"
"Always switch"

I think that covers all possible use cases. I'd suggest that most
of the ui is in an "Advanced" expander, with the default dialog being
a warning plus "open", "don't open" buttons.

Comment 6 Bert Vermeulen 2005-01-19 13:11:23 UTC
An extra popup dialog to get in your face + another config option is hardly the
best of both worlds. Both should be kept to a minimum, to avoid forcing the user
to think about the internal workings of the application.

However, multiple views of the same file is potentially interesting, so I would
suggest the following:

- open file should just read and open a new file, in a new tab, just as the user
expects, and the way it is now. There is no need for special behavior.

- right mouse button click on the tab, with a menu option there "Open new view",
or
- have the "New" menu item in the "File" menu bar become a submenu, and put
  "Document", "View", and so on in there.

I would recommend the first approach, since it's totally non-intrusive.

Comment 7 Stephen Kennedy 2005-01-19 13:53:38 UTC
Bert - keeping the current behaviour is bad because it's far too easy to cause
data loss. Scenario: open file, make edits. open in other tab, make edits. Now
theres no way to save both edits. Indeed, currently you don't even get warned!

The solution is to make sure the second set of edits don't happen in the first
place. You could share the textbuffer between the views, but IMHO it's more
intuitive to share the views too.

Re: views. Multiple views can be useful, but only as a split pane within a tab
so two or more areas are visible at once. I cannot imagine a good use case for
multiple view in separate tabs.
Comment 8 Paolo Maggi 2005-02-19 10:27:06 UTC
See also bug #167867
Comment 9 Paolo Maggi 2005-02-27 16:16:38 UTC
*** Bug 167867 has been marked as a duplicate of this bug. ***
Comment 10 Paolo Borelli 2005-04-21 21:16:38 UTC
*** Bug 301510 has been marked as a duplicate of this bug. ***
Comment 11 Nikos Kouremenos 2005-04-21 21:27:54 UTC
Paolo, ok sorry I didn't see the dup. this really annoys many people cause they
cannot trust gedit to hack/work seriously. plz fix it asap :)
Comment 12 Pierre Ossman 2005-05-29 20:38:18 UTC
How tightly integrated is the view with the document data? Would it be possible
to have several views into the same document? I.e. if I change the text in one
view the changes will be reflected in all others.

This seems to be what comment 7 is getting at but I don't agree that split pane
is necessary. Since you can pull off tabs you can have the views side by side
with the current system. And in many cases it's just useful to be able to keep
several views at different points in the document.
Comment 13 Paolo Borelli 2005-05-30 07:29:34 UTC
Making two views reflect the changes is possible, but it just complicates things
without real gain, since one of the reason to keep the same doc open two times
is to be able to compare two diverging versions of the doc.

At the moment the solution we plan is to warn the user user when he opens the
file the second time and give him the choice to 1) just read it making the view
Read Only or 2) Edit anyway
Comment 14 Murray Cumming 2005-11-18 11:01:56 UTC
I also like the idea of a dialog to ask the user, but it shouldn't be as
complicated as the one above. How about just

"
File already open.
The file is already open. Would you like to open it in a second read-only tab?

[Cancel] [Show existing tab] [Open in new tab]
"

That should cover most cases. Even if it doesn't cover everything, it would be a
big improvement over what we have now.
Comment 15 Paolo Borelli 2005-11-18 11:09:13 UTC
Created attachment 54909 [details]
screenie

it currently look like this in new_mdi
Comment 16 Pierre Ossman 2005-11-18 11:54:19 UTC
What does 'Dont edit' mean? Close or read-only? Perhaps this text should be
something more obvious.

And why the firefox-esqe placement of the error? Is GNOME going in this
direction? Otherwise it seems like a big UI discrepance for little gain.

</nitpick>

I think it's great that you're working on this function so this is meant as
constructive critisism, not whining. :)
Comment 17 Paolo Borelli 2005-11-18 12:27:16 UTC
Wording improvements and suggestions are always welcome... 'Don't Edit' means
read-only, we decided to not close the document since chances are that the user
opened it on purpose, beside closing is just as easy by normally closing the tab.

The firefoxesque error messages are an UI decisions we adopted for every error
that affects just one document so that it doesn't block all the other tabs like
a dialog would do. As far as I know, epiphany also uses per tab error pages.
Comment 18 Massimo Cora' 2005-11-18 14:08:28 UTC
Seems great to me. Good also is the choice of not using a dialog block to notify
the user. Perhaps the "don't edit" would be more understandable by "let it read
only" or just "read only".
Comment 19 John Pye 2005-11-29 03:09:23 UTC
The multiple-open-copies of a document thing is particularly annoying when using
external tools in cooperation with Gedit. My preference here would be

(a) when a file is being opened from the shell on an existing Gedit instance, it
*doesn't* open a new copy of the file, it just raises the existing open file.

(b) when a file is being opened from the File..Open dialog inside Gedit, the
user should be prompted "Open another copy?", along with "always yes", "always
no", "yes" and "no", plus settings in the preferences to govern this.

Comment 20 Steve Frécinaux 2006-04-06 11:28:06 UTC
Someone suggested to reuse the buffer from the already opened version of the document, so that both are keeped in sync.
Comment 21 Paolo Maggi 2006-04-06 14:09:55 UTC
GtkTextView/GtkSourceView support for multiple views of the same document is broken by design. There is no way we can implement this in a sane way without rewriting GtkTextView.
Comment 22 Nikos Kouremenos 2006-04-06 14:37:28 UTC
Steve, it's a nice though! I really like this (I love it in OOoWriter)

Paolo, are you sure about textview? gtk-demo text widget --> multiple views seems to does it
Comment 23 Paolo Maggi 2006-04-07 17:26:44 UTC
pbor and I discussed this topic on IRC.

We propose the following solution:

- if the file is already open in the same window, then the tab is raised and the file is not open twice
- otherwise, we open the file and show the warning message.

For historical reasons I put here the IRC log (in italian):

paolo riguardo al discorso dei documenti aperti due volte
paolo stavo pensando ad un possibile "compromesso"
paolo ossia se il file si trova nella stessa window
paolo allora seleziona la tab
paolo altrimenti, se è in una altra finestra mostra il warning
paolo come or
paolo a
pbor o nello stesso workspace
paolo beh... quella mi sembra una finezza in più
pbor pero a quel punto bisognerebbe aggoungere un menu item per aprire un'altra copia del doc corrente...
paolo perchè?
pbor e aggiungere una command line option per forzare l'apertura invece del raise
paolo semplicemente non è possibile farlo
pbor ma a volte io voglio farlo
paolo apri un altra finestra e non rompi :)
pbor hehe
pbor ok
pbor almeno concedimi la command line option
pbor :)
paolo piuttosto possiamo aggiungere una voce di menu "New Window"
pbor potremmo mostrare il warning quando fai File->open
pbor e invece fare il raise se semplicemente fai il double click
pbor o magari no
pbor sarebbe un po incasinato
paolo infatti
pbor ok, per me va bene il raise di default

Comment 24 Pierre Ossman 2006-04-07 17:52:21 UTC
Just make sure that virtual desktops are handled in a sane manner. :)
Comment 25 Paolo Maggi 2006-05-21 16:21:11 UTC
Created attachment 65947 [details] [review]
First version of a patch implementing my suggestion on comment #13

I have prepared a first version of a patch implementing my suggestion on comment #13. I have put it here for you testing pleasure and for comments.

I still need to:
- sanitize the list of files to open in order to remove duplicates (see the FIXME in the code)
- rephrase the warning message we already have since it is  broken (see bug #324491) and since it is now shown only if a duplicated document exists in another window. Suggestions are welcome.
Comment 26 Paolo Maggi 2006-05-21 16:22:41 UTC
It was comment #23, not #13
Comment 27 Paolo Maggi 2006-05-21 19:01:42 UTC
Created attachment 65961 [details] [review]
Patch v.2

As patch v.1, but removes duplicates from "uris" list.

The code still has a potential problem I don't think it is worth worrying about:
you should be able to open the same file twice in the same window if you open
a remote file and you are fast enough to open it in two different requests before
the URI of the file is set. I don't think  it can happen in practice and in any
case you will get the warning message we already have now.

hmmmm... re-reading the code, probably this potential problem does not exist. I leave the comment to remember to check this case again.
Comment 28 Paolo Borelli 2006-05-29 10:19:52 UTC
patch looks ok, the FIXME can now be removed.
Comment 29 Paolo Maggi 2006-05-29 14:07:43 UTC
We also need to modify the warning message in case the duplicated file is in a different window.
Any suggestion?
Comment 30 jessevdk@gmail.com 2006-08-06 07:16:59 UTC
What about:

Primary: This file (%s) is already opened in another gedit window.
Secondary: gedit opened the file in a non-editable way. Do you want to edit it anyway?

This patch should really go in. I think it may annoy some people who actually want to open another instance of the file in the same window (because there is no way of doing that now). How about adding a yellow message to the already opened file giving the choice to open it in a new tab? (Sorry if this already came up in the discussion)
Comment 31 Paolo Borelli 2006-08-06 09:26:06 UTC
The problem with that is when windows are on different workspaces: switching workspace automatically is very confusing, moving the window to the current work space is even worse and annoying since chances are that it was on a workspace with other related windows opened (terminals, nautilus, epiphany etc)
Comment 32 Paolo Borelli 2006-08-06 11:14:27 UTC
Ok, since Paolo Maggi is away and time is running out for 2.16, we bit the bullet and committed the above patch after review/test and updated the message area message.
Comment 33 jessevdk@gmail.com 2006-08-08 07:01:07 UTC
*** Bug 350348 has been marked as a duplicate of this bug. ***
Comment 34 Paolo Maggi 2006-08-08 10:09:36 UTC
How have you changed the message?
Comment 35 Paolo Borelli 2006-08-08 10:16:18 UTC
see comment #30:

Primary: This file (%s) is already opened in another gedit window.
Secondary: gedit opened the file in a non-editable way. Do you want to edit it
anyway?