Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve Stash GUI example.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5252 ea778897-0a13-0410-b9d1-a72fbfd435f5
  • Loading branch information...
commit 6bb2011f14491681ed8f3e524f28bb1e24946116 1 parent cb44ff6
@ntrel ntrel authored
View
7 ChangeLog
@@ -1,3 +1,10 @@
+2010-09-22 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
+
+ * src/stash.c, doc/Makefile.am, doc/stash-example.c,
+ doc/stash-gui-example.c:
+ Improve Stash GUI example.
+
+
2010-09-21 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/interface.c, geany.glade:
View
2  doc/Makefile.am
@@ -3,7 +3,7 @@ DOCDIR = $(DESTDIR)$(docdir)
IMAGE_FILES = images/*.png
EXTRA_DIST = geany.html geany.css geany.txt geany.1 \
plugins.dox pluginsymbols.c pluginsignals.c \
- stash-example.c \
+ stash-example.c stash-gui-example.c \
$(srcdir)/$(IMAGE_FILES)
pdf: geany.txt
View
2  doc/stash-example.c
@@ -4,7 +4,7 @@ gchar *potter_name;
const gchar filename[] = "/path/data.conf";
/* setup the group */
-group = stash_group_new("cups");
+group = stash_group_new("cup");
stash_group_add_boolean(group, &china_enabled, "china", TRUE);
stash_group_add_string(group, &potter_name, "potter_name", "Miss Clay");
View
36 doc/stash-gui-example.c
@@ -0,0 +1,36 @@
+gboolean want_handle;
+StashGroup *group = ...;
+
+/* Add the stash setting first so we can load it from disk if we want.
+ * Effectively, stash_group_add_boolean() is called for you.
+ * We need to use either a widget pointer or a widget name, and as we
+ * haven't created the widget yet we'll use a name - check_handle. */
+stash_group_add_toggle_button(group, &want_handle, "handle", TRUE, "check_handle");
+
+/* here we could load the setting from disk */
+
+...
+/* Later we create a dialog holding the toggle button widget.
+ * (Note: a check button is a subclass of a toggle button). */
+GtkWidget *dialog = ...;
+GtkWidget *check_button = gtk_check_button_new_with_label(_("Handle"));
+
+/* pack the widget into the dialog */
+gtk_container_add(GTK_CONTAINER(dialog->vbox), check_button);
+
+/* Now we set a name to lookup the widget from the dialog.
+ * We must remember to pass 'dialog' as an argument to Stash later. */
+ui_hookup_widget(dialog, check_button, "check_handle");
+
+...
+/* At some point we want to display the dialog.
+ * First we apply the want_handle boolean variable to the widget */
+stash_group_display(group, dialog);
+
+/* now display the dialog */
+gtk_widget_show_all(dialog);
+
+/* let the user manipulate widgets */
+...
+/* Now synchronize the want_handle variable */
+stash_group_update(group, dialog);
View
31 src/stash.c
@@ -50,30 +50,21 @@
* property. Macros could be added for common widget properties such as @c GtkExpander:"expanded".
*
* @section settings-example Settings Example
+ * Here we have some settings for how to make a cup - whether it should be made of china
+ * and who's going to make it. (Yes, it's a stupid example).
* @include stash-example.c
* @note You might want to handle the warning/error conditions differently from above.
*
* @section prefs-example GUI Prefs Example
- * For prefs, it's the same as the above example but you add widget prefs instead of e.g.
- * boolean settings.
+ * For prefs, it's the same as the above example but you tell Stash to add widget prefs instead of
+ * just data settings.
*
* This example uses lookup strings for widgets as they are more flexible than widget pointers.
- * @code
-gboolean want_handle;
-GtkWidget *parent;
-GtkWidget *my_check_button;
-
-stash_group_add_toggle_button(group, &want_handle, "handle", TRUE, "check_handle");
-...
-gtk_container_add(GTK_CONTAINER(parent), my_check_button);
-ui_hookup_widget(parent, my_check_button, "check_handle");
-...
-stash_group_display(group, parent);
-* @endcode
-* Now let the user manipulate widgets. To synchronize the Stash settings afterwards, call:
-* @code
-stash_group_update(group, parent);
- * @endcode
+ * Code to load and save the settings is omitted - see the first example instead.
+ *
+ * Here we show a dialog with a toggle button for whether the cup should have a handle.
+ * @include stash-gui-example.c
+ * @note This example should also work for other widget containers besides dialogs, e.g. popup menus.
*/
/* Implementation Note
@@ -86,9 +77,9 @@ stash_group_update(group, parent);
*
* Usually the prefs code isn't what user code will spend most of its time doing, so this
* should be efficient enough. But, if desired we could add a stash_group_set_size() function
- * to reduce reallocation.
+ * to reduce reallocation (or perhaps use a different container).
*
- * TODO: Maybe using GSlice chunks with an extra 'next' pointer would be more (memory) efficient.
+ * Note: Maybe using GSlice chunks with an extra 'next' pointer would be more efficient.
*/
Please sign in to comment.
Something went wrong with that request. Please try again.