[gnome-text-editor] app: allow starting a standalone instance of the application
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] app: allow starting a standalone instance of the application
- Date: Fri, 27 May 2022 23:54:24 +0000 (UTC)
commit 90bb94c9510e8c9ae9bc0478babc73608984a83b
Author: Christian Hergert <chergert redhat com>
Date: Fri May 27 16:45:43 2022 -0700
app: allow starting a standalone instance of the application
Basically the same as Builder, except that we have to also ignore the
session when doing so to avoid overwritting session data/etc.
Fixes #386
src/editor-application-private.h | 3 ++-
src/editor-application.c | 25 +++++++++++++++++++------
src/main.c | 25 ++++++++++++++++++++++++-
3 files changed, 45 insertions(+), 8 deletions(-)
---
diff --git a/src/editor-application-private.h b/src/editor-application-private.h
index 0a4cbed..eacf484 100644
--- a/src/editor-application-private.h
+++ b/src/editor-application-private.h
@@ -32,9 +32,10 @@ struct _EditorApplication
GtkCssProvider *recoloring;
GDBusProxy *portal;
char *system_font_name;
+ guint standalone : 1;
};
-EditorApplication *_editor_application_new (void);
+EditorApplication *_editor_application_new (gboolean standalone);
void _editor_application_actions_init (EditorApplication *self);
PangoFontDescription *_editor_application_get_system_font (EditorApplication *self);
diff --git a/src/editor-application.c b/src/editor-application.c
index 5d0131a..88e7633 100644
--- a/src/editor-application.c
+++ b/src/editor-application.c
@@ -523,9 +523,12 @@ editor_application_handle_local_options (GApplication *app,
g_assert (options != NULL);
/* This should only happen in the application launching, not the remote
- * instance as we don't want to affect something already running.
+ * instance as we don't want to affect something already running. Running
+ * standalone implies --ignore-session so that we don't stomp on any
+ * other session data.
*/
- if (g_variant_dict_lookup (options, "ignore-session", "b", &ignore_session))
+ if (self->standalone ||
+ g_variant_dict_lookup (options, "ignore-session", "b", &ignore_session))
_editor_session_set_restore_pages (self->session, FALSE);
return G_APPLICATION_CLASS (editor_application_parent_class)->handle_local_options (app, options);
@@ -542,8 +545,6 @@ editor_application_constructed (GObject *object)
g_application_set_application_id (G_APPLICATION (self), APP_ID);
g_application_set_resource_base_path (G_APPLICATION (self), "/org/gnome/TextEditor");
- g_application_set_flags (G_APPLICATION (self),
- G_APPLICATION_HANDLES_OPEN | G_APPLICATION_HANDLES_COMMAND_LINE);
}
static void
@@ -658,6 +659,7 @@ editor_application_class_init (EditorApplicationClass *klass)
static const GOptionEntry entries[] = {
{ "ignore-session", 'i', 0, G_OPTION_ARG_NONE, NULL, N_("Do not restore session at startup") },
{ "new-window", 'n', 0, G_OPTION_ARG_NONE, NULL, N_("Open provided files in a new window") },
+ { "standalone", 's', 0, G_OPTION_ARG_NONE, NULL, N_("Run a new instance of Text Editor (implies
--ignore-session)") },
{ 0 }
};
@@ -682,9 +684,20 @@ editor_application_init (EditorApplication *self)
}
EditorApplication *
-_editor_application_new (void)
+_editor_application_new (gboolean standalone)
{
- return g_object_new (EDITOR_TYPE_APPLICATION, NULL);
+ GApplicationFlags flags = G_APPLICATION_HANDLES_COMMAND_LINE | G_APPLICATION_HANDLES_OPEN;
+ EditorApplication *self;
+
+ if (standalone)
+ flags |= G_APPLICATION_NON_UNIQUE;
+
+ self = g_object_new (EDITOR_TYPE_APPLICATION,
+ "flags", flags,
+ NULL);
+ self->standalone = !!standalone;
+
+ return self;
}
/**
diff --git a/src/main.c b/src/main.c
index 434e78b..c0ad6fc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,21 +24,44 @@
#include "editor-application-private.h"
+static gboolean
+check_standalone (int *argc,
+ char ***argv)
+{
+ g_autoptr(GOptionContext) context = NULL;
+ gboolean standalone = FALSE;
+ GOptionEntry entries[] = {
+ { "standalone", 's', 0, G_OPTION_ARG_NONE, &standalone },
+ { NULL }
+ };
+
+ context = g_option_context_new (NULL);
+ g_option_context_set_ignore_unknown_options (context, TRUE);
+ g_option_context_set_help_enabled (context, FALSE);
+ g_option_context_add_main_entries (context, entries, NULL);
+ g_option_context_parse (context, argc, argv, NULL);
+
+ return standalone;
+}
+
int
main (int argc,
char *argv[])
{
g_autoptr(EditorApplication) app = NULL;
+ gboolean standalone;
int ret;
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
+ standalone = check_standalone (&argc, &argv);
+
gtk_init ();
gtk_source_init ();
- app = _editor_application_new ();
+ app = _editor_application_new (standalone);
ret = g_application_run (G_APPLICATION (app), argc, argv);
gtk_source_finalize ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]