我使用 Gtkmm 编写了一个小型应用程序,我想为用户提供文档。为此,我想从我的应用程序菜单中启动Gnome 帮助系统(例如,可以查看gedit)。
首先,我写了一个最小的 Mallardindex.page
文件:
<page xmlns="http://projectmallard.org/1.0/"
type="guide"
id="index">
<title>Example help</title>
</page>
yelp help/C/index.page
我可以通过从项目的根目录调用命令来查看:
然后,我编写了一些最小的 C++ 应用程序(Gtkmm 3.22)来调用帮助系统:
#include <iostream>
#include <gtkmm.h>
constexpr char HELP_URI[] = "help:myapp";
int main(int argc, char* argv[])
{
auto app = Gtk::Application::create(argc, argv, "bob.morane.question");
Gtk::Window window;
// 1. Add the help menu item:
Gtk::MenuItem helpItem;
helpItem.set_label("Help");
Gtk::Menu helpMenu;
Gtk::MenuItem openHelpItem;
openHelpItem.set_label("Open help...");
Gtk::MenuBar menuBar;
menuBar.append(helpItem);
helpItem.set_submenu(helpMenu);
helpMenu.append(openHelpItem);
window.add(menuBar);
// 2. Link the help menu item to Mallard documentation:
openHelpItem.signal_activate().connect([&window](){
const guint32 timestamp = gtk_get_current_event_time();
GError* error = nullptr;
// This is the call that triggers gnome help system:
const bool status = gtk_show_uri_on_window (window.gobj(),
HELP_URI,
timestamp,
&error);
if(!status)
{
std::cout << "Unable to show help : " + std::string{error->message} << std::endl;
return;
}
});
window.show_all();
return app->run(window);
}
我使用一个非常简单的 Makefile 构建:
all: main.cpp
g++ -std=c++17 main.cpp -o myapp `pkg-config gtkmm-3.0 --cflags --libs`
当我单击Open help...
菜单项时,我得到以下信息:
如果我将程序的第一行更改为: constexpr char HELP_URI[] = "help:gedit";
,则 gedit 帮助会很好地弹出。现在使用诸如 Meson(如 gedit)或 Autotools(如Gnome 文档所建议的)之类的构建系统对我来说太过分了。我希望能够显示我的帮助文件而不需要处理那些(即我想继续使用我的 Makefile)。
*问题:如何在不需要使用 Meson 或 Autotools 的情况下显示我自己的帮助文件?