nomadicME
nomadicME

Reputation: 1409

How to open a text file from CLI using a running instance of a GTK text editor written in C?

I have a text editor written in C using gtk+-3.x and gtksourceview3. I would like to expand the functionality to include the ability to open a text file from the command line and add the text in this file to a new buffer in the previously opened editor.

So the question is, how do I access this text? I can add it to a buffer,scrollwin... that isn't the problem. Thanks.

Upvotes: 0

Views: 128

Answers (1)

Jussi Kukkonen
Jussi Kukkonen

Reputation: 14587

I'm assuming your problem is what's mentioned in the title: getting an already running instance of a GTK app to do something from the command line.

GtkApplication and it's base class GApplication will give you the tools you need: It allows you to define actions that the new instance can invoke on the original instance (using D-Bus but that's an implementation detail). For your use case take a look at the already defined "open" action in GApplication (see example).

If you are using a an old version of GTK+ that doesn't have GtkApplication, you can use libunique instead -- the API is roughly the same.

Upvotes: 1

Related Questions