summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaël Bonithon <gael@xfce.org>2022-03-14 18:49:18 +0100
committerGaël Bonithon <gael@xfce.org>2022-03-15 14:37:40 +0000
commit9a1210a1689bb61c5f147ece4b09292df8c76388 (patch)
tree443402a7a49163127180fcd96a1a681afb915c14
parent60b1b577ee1afe12990c6d5ab751dfdc72ac9adf (diff)
downloadlibxfce4ui-9a1210a1689bb61c5f147ece4b09292df8c76388.tar.gz
XfceShortcutsEditor: Add new vectorized constructor
This is useful when the number of sections is only known at runtime, thus avoiding the use of `xfce_shortcuts_editor_new()` in a loop.
-rw-r--r--libxfce4kbd-private/xfce-shortcuts-editor.c50
-rw-r--r--libxfce4kbd-private/xfce-shortcuts-editor.h15
2 files changed, 52 insertions, 13 deletions
diff --git a/libxfce4kbd-private/xfce-shortcuts-editor.c b/libxfce4kbd-private/xfce-shortcuts-editor.c
index ef418da..e37cbd0 100644
--- a/libxfce4kbd-private/xfce-shortcuts-editor.c
+++ b/libxfce4kbd-private/xfce-shortcuts-editor.c
@@ -58,13 +58,6 @@ typedef struct
gchar *other_path;
} ShortcutInfo;
-typedef struct
-{
- gchar *section_name;
- XfceGtkActionEntry *entries;
- size_t size;
-} Section;
-
static void xfce_shortcuts_editor_finalize (GObject *object);
@@ -97,8 +90,8 @@ struct _XfceShortcutsEditor
{
GtkVBox __parent__;
- Section *arrays;
- size_t arrays_count;
+ XfceShortcutsEditorSection *arrays;
+ size_t arrays_count;
};
@@ -172,6 +165,43 @@ xfce_shortcuts_editor_new (int argument_count, ...)
/**
+ * xfce_shortcuts_editor_new_array:
+ * @sections : an array of XfceShortcutsEditorSection triads (see
+ * xfce_shortcuts_editor_new_variadic for a description).
+ * @n_sections : #int, the size of the array.
+ *
+ * A vectorized version of xfce_shortcuts_editor_new.
+ *
+ * Since: 4.17.5
+ **/
+GtkWidget*
+xfce_shortcuts_editor_new_array (XfceShortcutsEditorSection *sections,
+ int n_sections)
+{
+ XfceShortcutsEditor *editor;
+
+ editor = g_object_new (XFCE_TYPE_SHORTCUTS_EDITOR, NULL);
+
+ editor->arrays_count = n_sections;
+ editor->arrays = g_new (XfceShortcutsEditorSection, n_sections);
+
+ for (int i = 0; i < n_sections; i++)
+ {
+ editor->arrays[i].section_name = g_strdup (sections[i].section_name);
+ editor->arrays[i].entries = sections[i].entries;
+ editor->arrays[i].size = sections[i].size;
+ }
+
+ xfce_shortcuts_editor_create_contents (editor);
+
+ gtk_widget_show (GTK_WIDGET (editor));
+
+ return GTK_WIDGET (editor);
+}
+
+
+
+/**
* xfce_shortcuts_editor_new_variadic:
* @argument_count : #int, the number of arguments, including this one.
* @argument_list : a #va_list containing the arguments
@@ -200,7 +230,7 @@ xfce_shortcuts_editor_new_variadic (int argument_count,
editor = g_object_new (XFCE_TYPE_SHORTCUTS_EDITOR, NULL);
editor->arrays_count = (argument_count - 1) / 3;
- editor->arrays = g_malloc (sizeof (Section) * editor->arrays_count);
+ editor->arrays = g_malloc (sizeof (XfceShortcutsEditorSection) * editor->arrays_count);
for (int i = 0; i * 3 + 1 < argument_count; i++)
{
diff --git a/libxfce4kbd-private/xfce-shortcuts-editor.h b/libxfce4kbd-private/xfce-shortcuts-editor.h
index f5308d0..c1b584c 100644
--- a/libxfce4kbd-private/xfce-shortcuts-editor.h
+++ b/libxfce4kbd-private/xfce-shortcuts-editor.h
@@ -36,12 +36,21 @@ typedef struct _XfceShortcutsEditor XfceShortcutsEditor;
#define XFCE_IS_SHORTCUTS_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_SHORTCUTS_EDITOR))
#define XFCE_SHORTCUTS_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_SHORTCUTS_EDITOR, XfceShortcutsEditorClass))
+typedef struct
+{
+ gchar *section_name;
+ XfceGtkActionEntry *entries;
+ size_t size;
+} XfceShortcutsEditorSection;
+
GType xfce_shortcuts_editor_get_type (void) G_GNUC_CONST;
-GtkWidget *xfce_shortcuts_editor_new (int argument_count,
+GtkWidget *xfce_shortcuts_editor_new (int argument_count,
...) G_GNUC_MALLOC;
-GtkWidget *xfce_shortcuts_editor_new_variadic (int argument_count,
- va_list argument_list) G_GNUC_MALLOC;
+GtkWidget *xfce_shortcuts_editor_new_array (XfceShortcutsEditorSection *sections,
+ int n_sections) G_GNUC_MALLOC;
+GtkWidget *xfce_shortcuts_editor_new_variadic (int argument_count,
+ va_list argument_list) G_GNUC_MALLOC;
G_END_DECLS