Merge branch 'dboles/issue6001-ShortcutsWindow-programmatic' into 'main'
Add API to programmatically build ShortcutsWindow Closes #6001 See merge request GNOME/gtk!6249
This commit is contained in:
@@ -40,6 +40,14 @@
|
||||
* depending on the application context.
|
||||
*
|
||||
* This widget is only meant to be used with [class@Gtk.ShortcutsWindow].
|
||||
*
|
||||
* The recommended way to construct a `GtkShortcutsGroup` is with
|
||||
* [class@Gtk.Builder], by using the `<child>` tag to populate a
|
||||
* `GtkShortcutsGroup` with one or more [class@Gtk.ShortcutsShortcut]
|
||||
* instances.
|
||||
*
|
||||
* If you need to add a shortcut programmatically, use
|
||||
* [method@Gtk.ShortcutsGroup.add_shortcut].
|
||||
*/
|
||||
|
||||
struct _GtkShortcutsGroup
|
||||
@@ -152,9 +160,8 @@ gtk_shortcuts_group_buildable_add_child (GtkBuildable *buildable,
|
||||
{
|
||||
if (GTK_IS_SHORTCUTS_SHORTCUT (child))
|
||||
{
|
||||
gtk_box_append (GTK_BOX (buildable), GTK_WIDGET (child));
|
||||
gtk_shortcuts_group_apply_accel_size_group (GTK_SHORTCUTS_GROUP (buildable), GTK_WIDGET (child));
|
||||
gtk_shortcuts_group_apply_title_size_group (GTK_SHORTCUTS_GROUP (buildable), GTK_WIDGET (child));
|
||||
gtk_shortcuts_group_add_shortcut (GTK_SHORTCUTS_GROUP (buildable),
|
||||
GTK_SHORTCUTS_SHORTCUT (child));
|
||||
}
|
||||
else
|
||||
parent_buildable_iface->add_child (buildable, builder, child, type);
|
||||
@@ -361,3 +368,30 @@ gtk_shortcuts_group_init (GtkShortcutsGroup *self)
|
||||
GTK_ACCESSIBLE_RELATION_LABELLED_BY, self->title, NULL,
|
||||
-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_shortcuts_group_add_shortcut:
|
||||
* @self: a `GtkShortcutsGroup`
|
||||
* @shortcut: the `GtkShortcutsShortcut` to add
|
||||
*
|
||||
* Adds a shortcut to the shortcuts group.
|
||||
*
|
||||
* This is the programmatic equivalent to using [class@Gtk.Builder] and a
|
||||
* `<child>` tag to add the child. Adding children with other API is not
|
||||
* appropriate as `GtkShortcutsGroup` manages its children internally.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gtk_shortcuts_group_add_shortcut (GtkShortcutsGroup *self,
|
||||
GtkShortcutsShortcut *shortcut)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_SHORTCUTS_GROUP (self));
|
||||
g_return_if_fail (GTK_IS_SHORTCUTS_SHORTCUT (shortcut));
|
||||
g_return_if_fail (gtk_widget_get_parent (GTK_WIDGET (shortcut)) == NULL);
|
||||
|
||||
GtkWidget *widget = GTK_WIDGET (shortcut);
|
||||
gtk_box_append (GTK_BOX (self), widget);
|
||||
gtk_shortcuts_group_apply_accel_size_group (self, widget);
|
||||
gtk_shortcuts_group_apply_title_size_group (self, widget);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#endif
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gtk/gtkshortcutsshortcut.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@@ -30,12 +31,15 @@ G_BEGIN_DECLS
|
||||
#define GTK_SHORTCUTS_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SHORTCUTS_GROUP, GtkShortcutsGroup))
|
||||
#define GTK_IS_SHORTCUTS_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SHORTCUTS_GROUP))
|
||||
|
||||
|
||||
typedef struct _GtkShortcutsGroup GtkShortcutsGroup;
|
||||
typedef struct _GtkShortcutsGroupClass GtkShortcutsGroupClass;
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GType gtk_shortcuts_group_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gtk_shortcuts_group_add_shortcut (GtkShortcutsGroup *self,
|
||||
GtkShortcutsShortcut *shortcut);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
@@ -53,6 +53,15 @@
|
||||
* and columns.
|
||||
*
|
||||
* This widget is only meant to be used with [class@Gtk.ShortcutsWindow].
|
||||
*
|
||||
* The recommended way to construct a `GtkShortcutsSection` is with
|
||||
* [class@Gtk.Builder], by using the `<child>` tag to populate a
|
||||
* `GtkShortcutsSection` with one or more [class@Gtk.ShortcutsGroup]
|
||||
* instances, which in turn contain one or more [class@Gtk.ShortcutsShortcut]
|
||||
* objects.
|
||||
*
|
||||
* If you need to add a group programmatically, use
|
||||
* [method@Gtk.ShortcutsSection.add_group].
|
||||
*/
|
||||
|
||||
struct _GtkShortcutsSection
|
||||
@@ -109,8 +118,6 @@ static void gtk_shortcuts_section_set_view_name (GtkShortcutsSection *self,
|
||||
const char *view_name);
|
||||
static void gtk_shortcuts_section_set_max_height (GtkShortcutsSection *self,
|
||||
guint max_height);
|
||||
static void gtk_shortcuts_section_add_group (GtkShortcutsSection *self,
|
||||
GtkShortcutsGroup *group);
|
||||
|
||||
static void gtk_shortcuts_section_show_all (GtkShortcutsSection *self);
|
||||
static void gtk_shortcuts_section_filter_groups (GtkShortcutsSection *self);
|
||||
@@ -454,10 +461,29 @@ gtk_shortcuts_section_set_max_height (GtkShortcutsSection *self,
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MAX_HEIGHT]);
|
||||
}
|
||||
|
||||
static void
|
||||
/**
|
||||
* gtk_shortcuts_section_add_group:
|
||||
* @self: a `GtkShortcutsSection`
|
||||
* @group: the `GtkShortcutsGroup` to add
|
||||
*
|
||||
* Adds a group to the shortcuts section.
|
||||
*
|
||||
* This is the programmatic equivalent to using [class@Gtk.Builder] and a
|
||||
* `<child>` tag to add the child.
|
||||
*
|
||||
* Adding children with the `GtkBox` API is not appropriate, as
|
||||
* `GtkShortcutsSection` manages its children internally.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gtk_shortcuts_section_add_group (GtkShortcutsSection *self,
|
||||
GtkShortcutsGroup *group)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_SHORTCUTS_SECTION (self));
|
||||
g_return_if_fail (GTK_IS_SHORTCUTS_GROUP (group));
|
||||
g_return_if_fail (gtk_widget_get_parent (GTK_WIDGET (group)) == NULL);
|
||||
|
||||
GtkWidget *page, *column;
|
||||
|
||||
page = gtk_widget_get_last_child (GTK_WIDGET (self->stack));
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#endif
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gtk/gtkshortcutsgroup.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@@ -30,12 +31,15 @@ G_BEGIN_DECLS
|
||||
#define GTK_SHORTCUTS_SECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SHORTCUTS_SECTION, GtkShortcutsSection))
|
||||
#define GTK_IS_SHORTCUTS_SECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SHORTCUTS_SECTION))
|
||||
|
||||
|
||||
typedef struct _GtkShortcutsSection GtkShortcutsSection;
|
||||
typedef struct _GtkShortcutsSectionClass GtkShortcutsSectionClass;
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GType gtk_shortcuts_section_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gtk_shortcuts_section_add_group (GtkShortcutsSection *self,
|
||||
GtkShortcutsGroup *group);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
@@ -56,9 +56,14 @@
|
||||
* showing information that is not relevant in the current application context.
|
||||
*
|
||||
* The recommended way to construct a `GtkShortcutsWindow` is with
|
||||
* [class@Gtk.Builder], by populating a `GtkShortcutsWindow` with one or
|
||||
* more `GtkShortcutsSection` objects, which contain `GtkShortcutsGroups`
|
||||
* that in turn contain objects of class `GtkShortcutsShortcut`.
|
||||
* [class@Gtk.Builder], by using the `<child>` tag to populate a
|
||||
* `GtkShortcutsWindow` with one or more [class@Gtk.ShortcutsSection] objects,
|
||||
* which contain one or more [class@Gtk.ShortcutsGroup] instances, which, in turn,
|
||||
* contain [class@Gtk.ShortcutsShortcut] instances.
|
||||
*
|
||||
* If you need to add a section programmatically, use [method@Gtk.ShortcutsWindow.add_section]
|
||||
* instead of [method@Gtk.Window.set_child], as the shortcuts window manages
|
||||
* its children directly.
|
||||
*
|
||||
* # A simple example:
|
||||
*
|
||||
@@ -333,10 +338,29 @@ section_notify_cb (GObject *section,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
/**
|
||||
* gtk_shortcuts_window_add_section:
|
||||
* @self: a `GtkShortcutsWindow`
|
||||
* @section: the `GtkShortcutsSection` to add
|
||||
*
|
||||
* Adds a section to the shortcuts window.
|
||||
*
|
||||
* This is the programmatic equivalent to using [class@Gtk.Builder] and a
|
||||
* `<child>` tag to add the child.
|
||||
*
|
||||
* Using [method@Gtk.Window.set_child] is not appropriate as the shortcuts
|
||||
* window manages its children internally.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gtk_shortcuts_window_add_section (GtkShortcutsWindow *self,
|
||||
GtkShortcutsSection *section)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_SHORTCUTS_WINDOW (self));
|
||||
g_return_if_fail (GTK_IS_SHORTCUTS_SECTION (section));
|
||||
g_return_if_fail (gtk_widget_get_parent (GTK_WIDGET (section)) == NULL);
|
||||
|
||||
GtkListBoxRow *row;
|
||||
char *title;
|
||||
char *name;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#endif
|
||||
|
||||
#include <gtk/gtkwindow.h>
|
||||
#include <gtk/gtkshortcutssection.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@@ -30,12 +31,15 @@ G_BEGIN_DECLS
|
||||
#define GTK_SHORTCUTS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SHORTCUTS_WINDOW, GtkShortcutsWindow))
|
||||
#define GTK_IS_SHORTCUTS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SHORTCUTS_WINDOW))
|
||||
|
||||
|
||||
typedef struct _GtkShortcutsWindow GtkShortcutsWindow;
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GType gtk_shortcuts_window_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gtk_shortcuts_window_add_section (GtkShortcutsWindow *self,
|
||||
GtkShortcutsSection *section);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkShortcutsWindow, g_object_unref)
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
Reference in New Issue
Block a user