aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h.in3
-rw-r--r--share/gui/window-main.ui1
-rw-r--r--src/ld-window-main.c77
3 files changed, 81 insertions, 0 deletions
diff --git a/config.h.in b/config.h.in
index a7b11ad..e7c7e5d 100644
--- a/config.h.in
+++ b/config.h.in
@@ -16,11 +16,14 @@
#ifdef OPTION_NOINSTALL
/* For developers. */
+ #define PROJECT_DOC_DIR "${CMAKE_SOURCE_DIR}/docs/"
#define PROJECT_SHARE_DIR "${CMAKE_SOURCE_DIR}/share/"
#define PROJECT_GSETTINGS_DIR "${CMAKE_BINARY_DIR}"
#elif defined (_WIN32)
+ #define PROJECT_DOC_DIR "share/doc/${PROJECT_NAME}/"
#define PROJECT_SHARE_DIR "share/${PROJECT_NAME}/"
#else
+ #define PROJECT_DOC_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/${PROJECT_NAME}/"
#define PROJECT_SHARE_DIR "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/"
#endif
diff --git a/share/gui/window-main.ui b/share/gui/window-main.ui
index 8974cdc..1d90531 100644
--- a/share/gui/window-main.ui
+++ b/share/gui/window-main.ui
@@ -36,6 +36,7 @@
<menuitem action="NormalSize" />
</menu>
<menu name="HelpMenu" action="HelpMenu">
+ <menuitem action="UserGuide" />
<menuitem action="About" />
</menu>
</menubar>
diff --git a/src/ld-window-main.c b/src/ld-window-main.c
index 855bf48..4977508 100644
--- a/src/ld-window-main.c
+++ b/src/ld-window-main.c
@@ -100,6 +100,7 @@ static void on_action_open (GtkAction *action, LdWindowMain *self);
static void on_action_save (GtkAction *action, LdWindowMain *self);
static void on_action_save_as (GtkAction *action, LdWindowMain *self);
static void on_action_quit (GtkAction *action, LdWindowMain *self);
+static void on_action_user_guide (GtkAction *action, LdWindowMain *self);
static void on_action_about (GtkAction *action, LdWindowMain *self);
static void on_action_undo (GtkAction *action, LdWindowMain *self);
@@ -176,6 +177,9 @@ static GtkActionEntry wm_action_entries[] =
G_CALLBACK (on_action_normal_size)},
{"HelpMenu", NULL, N_("_Help"), NULL, NULL, NULL},
+ {"UserGuide", GTK_STOCK_HELP, N_("_User Guide"), NULL,
+ N_("Open the manual"),
+ G_CALLBACK (on_action_user_guide)},
{"About", GTK_STOCK_ABOUT, N_("_About"), NULL,
N_("Show a dialog about this application"),
G_CALLBACK (on_action_about)}
@@ -973,6 +977,79 @@ on_action_quit (GtkAction *action, LdWindowMain *self)
gtk_widget_destroy (GTK_WIDGET (self));
}
+static GFile *
+user_guide_path (const gchar *language)
+{
+ gchar *filename, *path;
+ GFile *file;
+
+ filename = g_strdup_printf ("user-guide-%s.html", language);
+ path = g_build_filename (PROJECT_DOC_DIR, "user-guide", filename, NULL);
+ g_free (filename);
+ file = g_file_new_for_path (path);
+ g_free (path);
+ return file;
+}
+
+static gboolean
+open_file (GFile *file, GdkScreen *screen, GError **error)
+{
+ GdkDisplay *display;
+ GAppInfo *app_info;
+ GdkAppLaunchContext *context;
+ GList link;
+ gboolean success;
+
+ /* GLib 2.36.1 prevents us from using gtk_show_uri() on Windows XP. */
+ if (!(app_info = g_file_query_default_handler (file, NULL, error)))
+ return FALSE;
+
+ link.next = link.prev = NULL;
+ link.data = file;
+
+ display = gdk_screen_get_display (screen);
+ context = gdk_display_get_app_launch_context (display);
+ gdk_app_launch_context_set_screen (context, screen);
+ success = g_app_info_launch (app_info,
+ &link, G_APP_LAUNCH_CONTEXT (context), error);
+ g_object_unref (context);
+ return success;
+}
+
+static void
+on_action_user_guide (GtkAction *action, LdWindowMain *self)
+{
+ const gchar *const *iter;
+ GFile *file;
+ GError *error = NULL;
+
+ /* Look for a usable language variant, or fall back to the lingua franca. */
+ for (iter = g_get_language_names (); *iter; iter++)
+ {
+ if (g_file_query_exists ((file = user_guide_path (*iter)), NULL))
+ break;
+ g_object_unref (file);
+ }
+ if (!*iter)
+ file = user_guide_path ("en");
+
+ if (!open_file (file, gtk_window_get_screen (GTK_WINDOW (self)), &error))
+ {
+ GtkWidget *message_dialog;
+
+ message_dialog = gtk_message_dialog_new (GTK_WINDOW (self),
+ GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
+ _("Failed to open the user guide"));
+ gtk_message_dialog_format_secondary_text
+ (GTK_MESSAGE_DIALOG (message_dialog), "%s", error->message);
+ g_error_free (error);
+
+ gtk_dialog_run (GTK_DIALOG (message_dialog));
+ gtk_widget_destroy (message_dialog);
+ }
+ g_object_unref (file);
+}
+
static void
on_action_about (GtkAction *action, LdWindowMain *self)
{