Padre now has working single-instance support

Alias on 2009-05-07T03:54:47

Now that Padre is running fast enough to well and truly keep up with my typing, I'm making another attempt to switch over and make Padre my primary editor.

As a result, I've been forced into implementing one of my shop-stopper features.

"Single Instance" support is a fairly common feature in major applications which keeps only one instance of the application running, and causes new invocations to communicate with the primary instance and open any files in the existing one, instead of spawning a new instance.

It seems simple, but implementing it involves implementing a Wx::Socket-based server inside of Padre (so that it can run in the main thread), writing a protocol for two Padre instances to talk to each other and communicate commands, and then writing a client for it into the startup sequence of Padre that talks to the server, all in a way that doesn't block for long periods of time.

To enable single-instance mode, set the flag main_singleinstance: 1 in your config.yml (by hand in the short term).

Once enabled, it should become much simpler to integrate Padre into other applications as an "external editor" so that double clicking in your version control gui or anything else that supports editor integration does the expected thing and just loads the specified file in the current Padre instance.

With single instance support out of the way, now I only need to get recursive find and replace working, and there should be no reasons left to go back to Ultraedit any more.

Single instance support should appear on the CPAN in Padre 0.35.


Great Job.

azawawi on 2009-05-07T06:34:48

It is good to see ticket:117 finished :) I think we need to focus/activate the single instance Padre if another is launched.

Re:Great Job.

Alias on 2009-05-07T06:51:11

It does that too.

An example of the command stream from the child to the server is

open C:\project\Makefile.PL
open C:\project\lib\Foo.pm
focus

The last command is sent even if there's no files to open, and triggers the single instance into bringing itself to the foreground.

How about using wxSingleInstanceChecker?

azawawi on 2009-05-07T06:43:52

Have you tried wxSingleInstanceChecker btw?

http://docs.wxwidgets.org/2.8/wx_wxsingleinstancechecker.html#wxsinglein stancechecker

Re:How about using wxSingleInstanceChecker?

Alias on 2009-05-07T06:53:05

That's not really what I was looking for...

I'd just prefer to go straight to hitting a localhost port.

Yeah I just switched too!

patspam on 2009-05-07T12:47:22

I finally made the switch from Eclipse + EPIC to Padre this week.

So far the positives are outweighing the itches which makes me happy. Really amazing how far Padre has come since YAPC::EU 2008. You guys rock.

a suggestion

mattp on 2009-05-07T13:56:48

Though I don't use padre myself, reading your post mention 'recursive find and replace' made me think .. would it be possible to integrate ack with padre in a simple plugin? http://search.cpan.org/user/petdance/ack/ more horsepower available than anything you'd write yourself, since most of the work is already done. I'm not exactly sure what feature set you're looking for but ack might fit the bill.

Re:a suggestion

tsee on 2009-05-07T14:06:58

It's already there.

I think the ack support could do with some spit and polish, but it's been part of the editor for a long time. It *should* be a plugin, though.

I'm a little dubious

Alias on 2009-05-07T23:51:23

Although I appreciate ack, I'm not entirely sure if deep integration is worth it.

It mainly hinges on how well we can deal with callbacks from Ack back into Padre, and whether the search parameter set up is clean enough.

It's a pity that libunique can't help you

potyl on 2009-05-10T19:58:45

I've just published the bindings for libunique to CPAN this week (Gtk2::Unique). Libunique doest exactly what you need but it works only with Gtk2 and through D-Bus (although it can default to use sockets if D-Bus is not present). This dependencies make it almost Linux/Unix exclusive. It's a pity that you can't reuse it for your project as it would have saved you a lot of troubles.

Perhaps you could do something similar to what libunique does and provide a framework and a separate module for other wx applications? I'm sure that a lot of people would appreciate it.