I believe that a document-based GNOME application should do these things, even I start two instances from the panel’s Applications menu rather than starting the second instance from the application’s File menu. (For now, let’s ignore single-instance tabbed applications such as gedit.)
- File/Quit should close both instances.
- It should list the open instances in a Documents menu.
- It should warn me if I open a file that is already open in another instance, offering to just bring it to the front.
Firefox does this. Gnumeric and Abiword don’t, though it works for a second instance that I open via File/New. They probably start extra File/New instances in the same process and keep track of them via static data.
They could solve the problem by enforcing a single-instance via libunique, so the one process knows about all “instances”. Yesterday I easily added libunique support in my experimental gtkmm document/view framework, Bakery, because I want to fix this problem in Glom.
Many processes, single-instance?
However, having all application instances in one process gets annoying fast. Applications do hang or crash sometimes and it’s nice if that does not affect every open instance of the application. People probably don’t notice this because they rarely use File/New or File/Open. They probably do notice that File/Quit and the Documents menu don’t work as they’d expect.
So I guess we need some RPC to allow each application instance’s process to talk to all the others, maybe using a D-Bus interface. But that would quickly get complex and buggy and would provide multiple opportunities for code duplication and inconsistent behavior. I guess some shared API is needed. Has anyone else thought about this or even solved the problem already? Is there even one application that does it properly already?
Maybe it would be simplest for application instances to register themselves with a desktop-wide D-Bus service which could also be asked for a list of open documents.
What do other platforms do?
Back when I used Apple MacOS (versions 5 through 8) this was normal and worked, probably partly because the Finder maintained a list of open documents and didn’t even try to open second instances of already-open documents. The MacOS toolbox API was incredibly primitive back then so I guess that applications solved this individually. But it was a simpler time.
I wonder if MacOS X has actual API to help applications solve this problem.