window: dedazzle

This can move to AdwApplicationWindow at some point.
This commit is contained in:
Christian Hergert
2021-09-28 13:21:37 -07:00
parent f2aca5a812
commit a383f4d78a
3 changed files with 33 additions and 20 deletions

View File

@ -25,20 +25,22 @@
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <sysprof-ui.h> #include <sysprof-ui.h>
#include "egg-binding-group.h"
#include "sysprof-window.h" #include "sysprof-window.h"
struct _SysprofWindow struct _SysprofWindow
{ {
DzlApplicationWindow parent_instance; GtkApplicationWindow parent_instance;
DzlBindingGroup *bindings; EggBindingGroup *bindings;
SysprofNotebook *notebook; SysprofNotebook *notebook;
GtkButton *open_button; GtkButton *open_button;
GtkMenuButton *menu_button; GtkMenuButton *menu_button;
}; };
G_DEFINE_TYPE (SysprofWindow, sysprof_window, DZL_TYPE_APPLICATION_WINDOW) G_DEFINE_TYPE (SysprofWindow, sysprof_window, GTK_TYPE_APPLICATION_WINDOW)
/** /**
* sysprof_window_new: * sysprof_window_new:
@ -63,9 +65,11 @@ sysprof_window_notify_can_replay_cb (SysprofWindow *self,
g_assert (SYSPROF_IS_WINDOW (self)); g_assert (SYSPROF_IS_WINDOW (self));
g_assert (SYSPROF_IS_NOTEBOOK (notebook)); g_assert (SYSPROF_IS_NOTEBOOK (notebook));
#if 0
dzl_gtk_widget_action_set (GTK_WIDGET (self), "win", "replay-capture", dzl_gtk_widget_action_set (GTK_WIDGET (self), "win", "replay-capture",
"enabled", sysprof_notebook_get_can_replay (notebook), "enabled", sysprof_notebook_get_can_replay (notebook),
NULL); NULL);
#endif
} }
static void static void
@ -76,9 +80,11 @@ sysprof_window_notify_can_save_cb (SysprofWindow *self,
g_assert (SYSPROF_IS_WINDOW (self)); g_assert (SYSPROF_IS_WINDOW (self));
g_assert (SYSPROF_IS_NOTEBOOK (notebook)); g_assert (SYSPROF_IS_NOTEBOOK (notebook));
#if 0
dzl_gtk_widget_action_set (GTK_WIDGET (self), "win", "save-capture", dzl_gtk_widget_action_set (GTK_WIDGET (self), "win", "save-capture",
"enabled", sysprof_notebook_get_can_save (notebook), "enabled", sysprof_notebook_get_can_save (notebook),
NULL); NULL);
#endif
} }
static void static void
@ -175,7 +181,7 @@ sysprof_window_finalize (GObject *object)
{ {
SysprofWindow *self = (SysprofWindow *)object; SysprofWindow *self = (SysprofWindow *)object;
dzl_binding_group_set_source (self->bindings, NULL); egg_binding_group_set_source (self->bindings, NULL);
g_clear_object (&self->bindings); g_clear_object (&self->bindings);
G_OBJECT_CLASS (sysprof_window_parent_class)->finalize (object); G_OBJECT_CLASS (sysprof_window_parent_class)->finalize (object);
@ -194,6 +200,17 @@ sysprof_window_class_init (SysprofWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, SysprofWindow, open_button); gtk_widget_class_bind_template_child (widget_class, SysprofWindow, open_button);
gtk_widget_class_bind_template_child (widget_class, SysprofWindow, notebook); gtk_widget_class_bind_template_child (widget_class, SysprofWindow, notebook);
#if 0
/* Switch to GtkShortcutController class bindings */
DzlShortcutController *controller;
controller = dzl_shortcut_controller_find (GTK_WIDGET (self));
dzl_shortcut_controller_add_command_action (controller,
"org.gnome.sysprof3.stop-recording",
"Escape",
DZL_SHORTCUT_PHASE_BUBBLE,
"win.stop-recording");
#endif
g_type_ensure (SYSPROF_TYPE_NOTEBOOK); g_type_ensure (SYSPROF_TYPE_NOTEBOOK);
g_type_ensure (SYSPROF_TYPE_DISPLAY); g_type_ensure (SYSPROF_TYPE_DISPLAY);
} }
@ -201,7 +218,6 @@ sysprof_window_class_init (SysprofWindowClass *klass)
static void static void
sysprof_window_init (SysprofWindow *self) sysprof_window_init (SysprofWindow *self)
{ {
DzlShortcutController *controller;
static GActionEntry actions[] = { static GActionEntry actions[] = {
{ "close-tab", close_tab_cb }, { "close-tab", close_tab_cb },
{ "new-tab", new_tab_cb }, { "new-tab", new_tab_cb },
@ -210,9 +226,13 @@ sysprof_window_init (SysprofWindow *self)
{ "save-capture", save_capture_cb }, { "save-capture", save_capture_cb },
{ "stop-recording", stop_recording_cb }, { "stop-recording", stop_recording_cb },
}; };
GMenu *menu;
gtk_widget_init_template (GTK_WIDGET (self)); gtk_widget_init_template (GTK_WIDGET (self));
menu = gtk_application_get_menu_by_id (GTK_APPLICATION (g_application_get_default ()), "win-menu");
gtk_menu_button_set_menu_model (self->menu_button, G_MENU_MODEL (menu));
g_action_map_add_action_entries (G_ACTION_MAP (self), g_action_map_add_action_entries (G_ACTION_MAP (self),
actions, actions,
G_N_ELEMENTS (actions), G_N_ELEMENTS (actions),
@ -230,24 +250,20 @@ sysprof_window_init (SysprofWindow *self)
self, self,
G_CONNECT_SWAPPED); G_CONNECT_SWAPPED);
self->bindings = dzl_binding_group_new (); self->bindings = egg_binding_group_new ();
dzl_binding_group_bind (self->bindings, "title", self, "title", G_BINDING_SYNC_CREATE); egg_binding_group_bind (self->bindings, "title", self, "title", G_BINDING_SYNC_CREATE);
g_object_bind_property (self->notebook, "current", self->bindings, "source", g_object_bind_property (self->notebook, "current", self->bindings, "source",
G_BINDING_SYNC_CREATE); G_BINDING_SYNC_CREATE);
controller = dzl_shortcut_controller_find (GTK_WIDGET (self)); #if 0
dzl_shortcut_controller_add_command_action (controller, /* Switch to using gtk_widget_action_set_enabled() */
"org.gnome.sysprof3.stop-recording",
"Escape",
DZL_SHORTCUT_PHASE_BUBBLE,
"win.stop-recording");
dzl_gtk_widget_action_set (GTK_WIDGET (self), "win", "save-capture", dzl_gtk_widget_action_set (GTK_WIDGET (self), "win", "save-capture",
"enabled", FALSE, "enabled", FALSE,
NULL); NULL);
dzl_gtk_widget_action_set (GTK_WIDGET (self), "win", "replay-capture", dzl_gtk_widget_action_set (GTK_WIDGET (self), "win", "replay-capture",
"enabled", FALSE, "enabled", FALSE,
NULL); NULL);
#endif
} }
void void

View File

@ -20,15 +20,13 @@
#pragma once #pragma once
#include <dazzle.h>
#include "sysprof-application.h" #include "sysprof-application.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define SYSPROF_TYPE_WINDOW (sysprof_window_get_type()) #define SYSPROF_TYPE_WINDOW (sysprof_window_get_type())
G_DECLARE_FINAL_TYPE (SysprofWindow, sysprof_window, SYSPROF, WINDOW, DzlApplicationWindow) G_DECLARE_FINAL_TYPE (SysprofWindow, sysprof_window, SYSPROF, WINDOW, GtkApplicationWindow)
GtkWidget *sysprof_window_new (SysprofApplication *application); GtkWidget *sysprof_window_new (SysprofApplication *application);
void sysprof_window_new_tab (SysprofWindow *self); void sysprof_window_new_tab (SysprofWindow *self);

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<interface> <interface>
<template class="SysprofWindow" parent="DzlApplicationWindow"> <template class="SysprofWindow" parent="GtkApplicationWindow">
<property name="default-height">750</property> <property name="default-height">750</property>
<property name="icon-name">org.gnome.Sysprof-symbolic</property> <property name="icon-name">org.gnome.Sysprof-symbolic</property>
<property name="show-menubar">false</property> <property name="show-menubar">false</property>
@ -10,10 +10,9 @@
<property name="visible">true</property> <property name="visible">true</property>
<property name="title" translatable="yes">Sysprof</property> <property name="title" translatable="yes">Sysprof</property>
<child> <child>
<object class="DzlMenuButton" id="menu_button"> <object class="GtkMenuButton" id="menu_button">
<property name="icon-name">open-menu-symbolic</property> <property name="icon-name">open-menu-symbolic</property>
<property name="show-accels">true</property> <property name="show-accels">true</property>
<property name="menu-id">win-menu</property>
<property name="visible">true</property> <property name="visible">true</property>
<style> <style>
<class name="image-button"/> <class name="image-button"/>