[gnome-software: 1/13] update-dialog: Make it a HdyWindow
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 1/13] update-dialog: Make it a HdyWindow
- Date: Tue, 10 Aug 2021 07:25:59 +0000 (UTC)
commit 4fd8c54db2f039533ab7f1f45dce3a47ca173f2d
Author: Adrien Plazas <kekun plazas laposte net>
Date: Tue Aug 3 13:46:46 2021 +0200
update-dialog: Make it a HdyWindow
We don't need it to be a GtkDialog as we don't use it as a dialog, so
let's instead make it a HdyWindow to have nice rounded corners, to
simplify the code a bit, and to avoid having to work around oddities of
GtkDialog.
src/gs-update-dialog.c | 20 ++++++++++++--------
src/gs-update-dialog.h | 3 ++-
src/gs-update-dialog.ui | 32 +++++++++++++++++++-------------
src/gs-updates-section.c | 4 ----
4 files changed, 33 insertions(+), 26 deletions(-)
---
diff --git a/src/gs-update-dialog.c b/src/gs-update-dialog.c
index 05e81bb0f..e2a86f052 100644
--- a/src/gs-update-dialog.c
+++ b/src/gs-update-dialog.c
@@ -32,7 +32,7 @@ typedef enum {
struct _GsUpdateDialog
{
- GtkDialog parent_instance;
+ HdyWindow parent_instance;
GQueue *back_entry_stack;
GCancellable *cancellable;
@@ -55,7 +55,7 @@ struct _GsUpdateDialog
GtkWidget *permissions_section_content;
};
-G_DEFINE_TYPE (GsUpdateDialog, gs_update_dialog, GTK_TYPE_DIALOG)
+G_DEFINE_TYPE (GsUpdateDialog, gs_update_dialog, HDY_TYPE_WINDOW)
static void
save_back_entry (GsUpdateDialog *dialog)
@@ -745,15 +745,21 @@ key_press_event (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
GdkModifierType state;
gboolean is_rtl;
- if (!gtk_widget_is_visible (dialog->button_back) || !gtk_widget_is_sensitive (dialog->button_back))
- return GDK_EVENT_PROPAGATE;
-
state = event->state;
keymap = gdk_keymap_get_for_display (gtk_widget_get_display (widget));
gdk_keymap_add_virtual_modifiers (keymap, &state);
state = state & gtk_accelerator_get_default_mod_mask ();
is_rtl = gtk_widget_get_direction (dialog->button_back) == GTK_TEXT_DIR_RTL;
+ if (event->keyval == GDK_KEY_Escape) {
+ gtk_window_close (GTK_WINDOW (dialog));
+
+ return GDK_EVENT_STOP;
+ }
+
+ if (!gtk_widget_is_visible (dialog->button_back) || !gtk_widget_is_sensitive (dialog->button_back))
+ return GDK_EVENT_PROPAGATE;
+
if ((!is_rtl && state == GDK_MOD1_MASK && event->keyval == GDK_KEY_Left) ||
(is_rtl && state == GDK_MOD1_MASK && event->keyval == GDK_KEY_Right) ||
event->keyval == GDK_KEY_Back) {
@@ -864,9 +870,7 @@ gs_update_dialog_new (GsPluginLoader *plugin_loader)
{
GsUpdateDialog *dialog;
- dialog = g_object_new (GS_TYPE_UPDATE_DIALOG,
- "use-header-bar", TRUE,
- NULL);
+ dialog = g_object_new (GS_TYPE_UPDATE_DIALOG, NULL);
set_plugin_loader (dialog, plugin_loader);
return GTK_WIDGET (dialog);
diff --git a/src/gs-update-dialog.h b/src/gs-update-dialog.h
index 0008baa35..0a06c2f62 100644
--- a/src/gs-update-dialog.h
+++ b/src/gs-update-dialog.h
@@ -10,6 +10,7 @@
#pragma once
#include <gtk/gtk.h>
+#include <handy.h>
#include "gnome-software-private.h"
@@ -17,7 +18,7 @@ G_BEGIN_DECLS
#define GS_TYPE_UPDATE_DIALOG (gs_update_dialog_get_type ())
-G_DECLARE_FINAL_TYPE (GsUpdateDialog, gs_update_dialog, GS, UPDATE_DIALOG, GtkDialog)
+G_DECLARE_FINAL_TYPE (GsUpdateDialog, gs_update_dialog, GS, UPDATE_DIALOG, HdyWindow)
GtkWidget *gs_update_dialog_new (GsPluginLoader *plugin_loader);
void gs_update_dialog_show_installed_updates (GsUpdateDialog *dialog);
diff --git a/src/gs-update-dialog.ui b/src/gs-update-dialog.ui
index bda300240..6e712adb9 100644
--- a/src/gs-update-dialog.ui
+++ b/src/gs-update-dialog.ui
@@ -1,15 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.10"/>
- <template class="GsUpdateDialog" parent="GtkDialog">
+ <template class="GsUpdateDialog" parent="HdyWindow">
<property name="modal">True</property>
- <property name="default_width">600</property>
- <property name="default_height">600</property>
+ <property name="window_position">center</property>
<property name="destroy_with_parent">True</property>
+ <property name="icon_name">dialog-information</property>
+ <property name="skip_taskbar_hint">True</property>
+ <property name="title" translatable="yes">Software Repositories</property>
<property name="type_hint">dialog</property>
- <property name="use_header_bar">1</property>
- <child internal-child="headerbar">
- <object class="GtkHeaderBar">
+ <property name="default-width">640</property>
+ <property name="default-height">576</property>
+
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="HdyHeaderBar">
+ <property name="show_close_button">True</property>
+ <property name="visible">True</property>
+ <property name="title" bind-source="GsUpdateDialog" bind-property="title"
bind-flags="sync-create"/>
<child>
<object class="GtkButton" id="button_back">
<property name="visible">True</property>
@@ -35,13 +46,8 @@
<property name="pack-type">start</property>
</packing>
</child>
- </object>
- </child>
- <child internal-child="vbox">
- <object class="GtkBox" id="dialog-vbox1">
- <property name="border_width">0</property>
- <property name="orientation">vertical</property>
- <property name="spacing">2</property>
+ </object>
+ </child>
<child>
<object class="GtkStack" id="stack">
<property name="visible">True</property>
diff --git a/src/gs-updates-section.c b/src/gs-updates-section.c
index f93663c34..84e107434 100644
--- a/src/gs-updates-section.c
+++ b/src/gs-updates-section.c
@@ -490,10 +490,6 @@ _app_row_activated_cb (GsUpdatesSection *self, GtkListBoxRow *row)
dialog = gs_update_dialog_new (self->plugin_loader);
gs_update_dialog_show_update_details (GS_UPDATE_DIALOG (dialog), app);
gs_shell_modal_dialog_present (gs_page_get_shell (self->page), GTK_WINDOW (dialog));
-
- /* just destroy */
- g_signal_connect_swapped (dialog, "response",
- G_CALLBACK (gtk_widget_destroy), dialog);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]