[gtk/print-editor: 2/3] print-editor: Allow opening files
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/print-editor: 2/3] print-editor: Allow opening files
- Date: Sun, 28 Jun 2020 14:52:42 +0000 (UTC)
commit 6774f3663643dd052641f1bd90ce64b13a31c92e
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jun 28 10:26:19 2020 -0400
print-editor: Allow opening files
Since it calls itself an editor, it should really
support opening files on the commandline.
demos/print-editor/print-editor.c | 37 ++++++++++++++++---------------------
1 file changed, 16 insertions(+), 21 deletions(-)
---
diff --git a/demos/print-editor/print-editor.c b/demos/print-editor/print-editor.c
index 158ea873b1..f8fa0b4ef1 100644
--- a/demos/print-editor/print-editor.c
+++ b/demos/print-editor/print-editor.c
@@ -752,25 +752,6 @@ mark_set_callback (GtkTextBuffer *text_buffer,
update_statusbar ();
}
-static gint
-command_line (GApplication *application,
- GApplicationCommandLine *command_line)
-{
- int argc;
- char **argv;
-
- argv = g_application_command_line_get_arguments (command_line, &argc);
-
- if (argc == 2)
- {
- GFile *file = g_file_new_for_commandline_arg (argv[1]);
- load_file (file);
- g_object_unref (file);
- }
-
- return 0;
-}
-
static void
startup (GApplication *app)
{
@@ -845,6 +826,20 @@ activate (GApplication *app)
gtk_widget_show (main_window);
}
+static void
+open (GApplication *application,
+ GFile **files,
+ int n_files,
+ const char *hint)
+{
+ if (n_files > 1)
+ g_warning ("Can only open a single file");
+
+ activate (application);
+
+ load_file (files[0]);
+}
+
int
main (int argc, char **argv)
{
@@ -868,7 +863,7 @@ main (int argc, char **argv)
g_clear_error (&error);
}
- app = gtk_application_new ("org.gtk.PrintEditor", 0);
+ app = gtk_application_new ("org.gtk.PrintEditor4", G_APPLICATION_HANDLES_OPEN);
g_action_map_add_action_entries (G_ACTION_MAP (app),
app_entries, G_N_ELEMENTS (app_entries),
@@ -876,7 +871,7 @@ main (int argc, char **argv)
g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
- g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
+ g_signal_connect (app, "open", G_CALLBACK (open), NULL);
g_application_run (G_APPLICATION (app), argc, argv);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]