SF.net SVN: geany:[5252] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Wed Sep 22 16:33:38 UTC 2010


Revision: 5252
          http://geany.svn.sourceforge.net/geany/?rev=5252&view=rev
Author:   ntrel
Date:     2010-09-22 16:33:38 +0000 (Wed, 22 Sep 2010)

Log Message:
-----------
Improve Stash GUI example.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/doc/Makefile.am
    trunk/doc/stash-example.c
    trunk/src/stash.c

Added Paths:
-----------
    trunk/doc/stash-gui-example.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2010-09-22 15:25:37 UTC (rev 5251)
+++ trunk/ChangeLog	2010-09-22 16:33:38 UTC (rev 5252)
@@ -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:

Modified: trunk/doc/Makefile.am
===================================================================
--- trunk/doc/Makefile.am	2010-09-22 15:25:37 UTC (rev 5251)
+++ trunk/doc/Makefile.am	2010-09-22 16:33:38 UTC (rev 5252)
@@ -3,7 +3,7 @@
 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

Modified: trunk/doc/stash-example.c
===================================================================
--- trunk/doc/stash-example.c	2010-09-22 15:25:37 UTC (rev 5251)
+++ trunk/doc/stash-example.c	2010-09-22 16:33:38 UTC (rev 5252)
@@ -4,7 +4,7 @@
 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");
 

Added: trunk/doc/stash-gui-example.c
===================================================================
--- trunk/doc/stash-gui-example.c	                        (rev 0)
+++ trunk/doc/stash-gui-example.c	2010-09-22 16:33:38 UTC (rev 5252)
@@ -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);


Property changes on: trunk/doc/stash-gui-example.c
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native

Modified: trunk/src/stash.c
===================================================================
--- trunk/src/stash.c	2010-09-22 15:25:37 UTC (rev 5251)
+++ trunk/src/stash.c	2010-09-22 16:33:38 UTC (rev 5252)
@@ -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 @@
  *
  * 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.
  */
 
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list