sysprof: Implement new-window action

GNOME Shell uses the "new-window" action to open new main windows for an
application. Implementing it allows the application launcher to detect that
action, and provide a "New Window" menu entry for the user.
This commit is contained in:
Balló György
2025-03-31 03:00:38 +02:00
parent 8fa1dd2c1d
commit e925428d33
3 changed files with 33 additions and 25 deletions

View File

@ -130,6 +130,36 @@ sysprof_application_class_init (SysprofApplicationClass *klass)
gtk_app_class->window_added = sysprof_application_window_added;
}
static void
sysprof_new_window (GSimpleAction *action,
GVariant *variant,
gpointer user_data)
{
const GList *windows;
GApplication *app = user_data;
GtkWindow *window;
GtkWidget *greeter;
g_assert (G_IS_APPLICATION (app));
g_assert (G_IS_SIMPLE_ACTION (action));
g_assert (variant == NULL);
windows = gtk_application_get_windows (GTK_APPLICATION (app));
for (const GList *iter = windows; iter != NULL; iter = iter->next)
{
if (SYSPROF_IS_GREETER (iter->data))
{
gtk_window_present (iter->data);
return;
}
}
greeter = sysprof_greeter_new ();
gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (greeter));
gtk_window_present (GTK_WINDOW (greeter));
}
static void
sysprof_quit (GSimpleAction *action,
GVariant *variant,
@ -240,6 +270,7 @@ static void
sysprof_application_init (SysprofApplication *self)
{
static const GActionEntry actions[] = {
{ "new-window", sysprof_new_window },
{ "about", sysprof_about },
{ "show-help-overlay", sysprof_show_help_overlay },
{ "help", sysprof_help },

View File

@ -113,8 +113,6 @@ sysprof_window_update_action_state (SysprofWindow *self)
if (self->session == NULL)
{
gtk_widget_action_set_enabled (GTK_WIDGET (self), "win.open-capture", FALSE);
gtk_widget_action_set_enabled (GTK_WIDGET (self), "win.record-capture", FALSE);
gtk_widget_action_set_enabled (GTK_WIDGET (self), "session.zoom-one", FALSE);
gtk_widget_action_set_enabled (GTK_WIDGET (self), "session.zoom-out", FALSE);
gtk_widget_action_set_enabled (GTK_WIDGET (self), "session.zoom-in", FALSE);
@ -124,8 +122,6 @@ sysprof_window_update_action_state (SysprofWindow *self)
}
else
{
gtk_widget_action_set_enabled (GTK_WIDGET (self), "win.open-capture", TRUE);
gtk_widget_action_set_enabled (GTK_WIDGET (self), "win.record-capture", TRUE);
gtk_widget_action_set_enabled (GTK_WIDGET (self), "win.save-capture", TRUE);
gtk_widget_action_set_enabled (GTK_WIDGET (self), "session.zoom-in", TRUE);
@ -228,24 +224,6 @@ sysprof_window_open_capture_action (GtkWidget *widget,
sysprof_window_open_file (GTK_WINDOW (widget), template);
}
static void
sysprof_window_record_capture_action (GtkWidget *widget,
const char *action_name,
GVariant *param)
{
SysprofWindow *self = (SysprofWindow *)widget;
SysprofGreeter *greeter;
g_assert (SYSPROF_IS_WINDOW (self));
greeter = g_object_new (SYSPROF_TYPE_GREETER,
"transient-for", self,
NULL);
gtk_application_add_window (GTK_APPLICATION (SYSPROF_APPLICATION_DEFAULT),
GTK_WINDOW (greeter));
gtk_window_present (GTK_WINDOW (greeter));
}
static void
sysprof_window_set_document (SysprofWindow *self,
SysprofDocument *document)
@ -628,7 +606,6 @@ sysprof_window_class_init (SysprofWindowClass *klass)
gtk_widget_class_bind_template_callback (widget_class, n_filters_to_button_visibility);
gtk_widget_class_install_action (widget_class, "win.open-capture", NULL, sysprof_window_open_capture_action);
gtk_widget_class_install_action (widget_class, "win.record-capture", NULL, sysprof_window_record_capture_action);
gtk_widget_class_install_action (widget_class, "session.zoom-one", NULL, sysprof_window_session_zoom_one);
gtk_widget_class_install_action (widget_class, "session.zoom-out", NULL, sysprof_window_session_zoom_out);
gtk_widget_class_install_action (widget_class, "session.zoom-in", NULL, sysprof_window_session_zoom_in);

View File

@ -29,7 +29,7 @@
<child>
<object class="GtkShortcut">
<property name="trigger">&lt;ctrl&gt;n</property>
<property name="action">action(win.record-capture)</property>
<property name="action">action(app.new-window)</property>
</object>
</child>
<child>
@ -458,7 +458,7 @@
<section>
<item>
<attribute name="label" translatable="yes">_Record Again…</attribute>
<attribute name="action">win.record-capture</attribute>
<attribute name="action">app.new-window</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Open Recording…</attribute>