简体   繁体   English

如何使用正在运行的用C编写的GTK文本编辑器实例从CLI打开文本文件?

[英]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. 我有一个使用gtk + -3.x和gtksourceview3用C语言编写的文本编辑器。 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. 我可以将它添加到缓冲区,scrollwin ...这不是问题。 Thanks. 谢谢。

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. 我假设您的问题是标题中提到的问题:让一个已经运行的GTK应用程序实例从命令行执行某些操作。

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). GtkApplication及其基类GApplication将为您提供所需的工具:它允许您定义新实例可以在原始实例上调用的操作(使用D-Bus,但这是实现细节)。 For your use case take a look at the already defined "open" action in GApplication (see example ). 对于您的用例,请看一下GApplication中已经定义的“打开”操作(请参阅示例 )。

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. 如果您使用的旧版本的GTK +没有GtkApplication,则可以使用libunique - API大致相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM