[gtk+] gtk-demo: Show data files as well
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] gtk-demo: Show data files as well
- Date: Fri, 18 May 2012 04:49:56 +0000 (UTC)
commit 91d01434bc77b454d1f59ab72d8dbed97c7269f1
Author: Matthias Clasen <mclasen redhat com>
Date: Fri May 18 00:48:57 2012 -0400
gtk-demo: Show data files as well
Several demos use .ui files and the like. The demos are much
more useful if these files can be inspected in the ui as well.
demos/gtk-demo/Makefile.am | 2 +-
demos/gtk-demo/application.c | 2 +-
demos/gtk-demo/builder.c | 2 +-
demos/gtk-demo/main.c | 69 ++++++++++++++++++++++++++++++++++++++----
4 files changed, 66 insertions(+), 9 deletions(-)
---
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am
index db62767..dacedd2 100644
--- a/demos/gtk-demo/Makefile.am
+++ b/demos/gtk-demo/Makefile.am
@@ -122,7 +122,7 @@ IMAGEFILES= alphatest.png \
gnu-keys.png \
gtk-logo-rgb.gif
-democode_DATA = $(demos) $(IMAGEFILES) demo.ui
+democode_DATA = $(demos) $(IMAGEFILES) demo.ui menus.ui application.ui
DISTCLEANFILES = demos.h
diff --git a/demos/gtk-demo/application.c b/demos/gtk-demo/application.c
index af4e4e4..6f6c054 100644
--- a/demos/gtk-demo/application.c
+++ b/demos/gtk-demo/application.c
@@ -1,4 +1,4 @@
-/* Application class
+/* Application class :: menus.ui application.ui
*
* Demonstrates a simple application.
*
diff --git a/demos/gtk-demo/builder.c b/demos/gtk-demo/builder.c
index 615c753..abb3ad8 100644
--- a/demos/gtk-demo/builder.c
+++ b/demos/gtk-demo/builder.c
@@ -1,4 +1,4 @@
-/* Builder
+/* Builder :: demo.ui
*
* Demonstrates an interface loaded from a XML description.
*/
diff --git a/demos/gtk-demo/main.c b/demos/gtk-demo/main.c
index 9ae6c41..df2a6c6 100644
--- a/demos/gtk-demo/main.c
+++ b/demos/gtk-demo/main.c
@@ -14,6 +14,7 @@ static GtkTextBuffer *source_buffer;
static gchar *current_file = NULL;
+static GtkWidget *notebook;
enum {
TITLE_COLUMN,
@@ -514,6 +515,47 @@ fontify (void)
}
}
+static GtkWidget *create_text (GtkTextBuffer **buffer, gboolean is_source);
+
+static void
+add_data_tab (const gchar *filename)
+{
+ GtkTextBuffer *buffer = NULL;
+ gchar *full_filename;
+ GError *err = NULL;
+ gchar *text;
+ GtkWidget *widget, *label;
+
+ full_filename = demo_find_file (filename, &err);
+ if (!full_filename ||
+ !g_file_get_contents (full_filename, &text, NULL, &err))
+ {
+ g_warning ("%s", err->message);
+ g_error_free (err);
+ return;
+ }
+
+ widget = create_text (&buffer, FALSE);
+ gtk_widget_show_all (widget);
+ label = gtk_label_new (filename);
+ gtk_widget_show (label);
+ gtk_notebook_append_page (GTK_NOTEBOOK (notebook), widget, label);
+
+ gtk_text_buffer_set_text (buffer, text, -1);
+
+ g_free (full_filename);
+ g_free (text);
+}
+
+static void
+remove_data_tabs (void)
+{
+ gint i;
+
+ for (i = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) - 1; i > 1; i--)
+ gtk_notebook_remove_page (GTK_NOTEBOOK (notebook), i);
+}
+
void
load_file (const gchar *filename)
{
@@ -524,15 +566,24 @@ load_file (const gchar *filename)
GString *buffer = g_string_new (NULL);
int state = 0;
gboolean in_para = 0;
+ gchar **names;
+ gint i;
+
+ remove_data_tabs ();
+
+ names = g_strsplit (filename, " ", -1);
+
+ for (i = 1; names[i]; i++)
+ add_data_tab (names[i]);
- if (current_file && !strcmp (current_file, filename))
+ if (current_file && !strcmp (current_file, names[0]))
{
g_string_free (buffer, TRUE);
return;
}
g_free (current_file);
- current_file = g_strdup (filename);
+ current_file = g_strdup (names[0]);
gtk_text_buffer_get_bounds (info_buffer, &start, &end);
gtk_text_buffer_delete (info_buffer, &start, &end);
@@ -540,7 +591,7 @@ load_file (const gchar *filename)
gtk_text_buffer_get_bounds (source_buffer, &start, &end);
gtk_text_buffer_delete (source_buffer, &start, &end);
- full_filename = demo_find_file (filename, &err);
+ full_filename = demo_find_file (names[0], &err);
if (!full_filename)
{
g_warning ("%s", err->message);
@@ -572,14 +623,17 @@ load_file (const gchar *filename)
while (*p == '/' || *p == '*' || g_ascii_isspace (*p))
p++;
r = p;
- while (*r != '/' && strlen (r))
+ while (*r != '/' && *r != ':' && *r != '\0')
r++;
- if (strlen (r) > 0)
+ if (*r == '/')
p = r + 1;
+ if (r[0] == ':' && r[1] == ':')
+ *r = '\0';
q = p + strlen (p);
while (q > p && g_ascii_isspace (*(q - 1)))
q--;
+
if (q > p)
{
int len_chars = g_utf8_pointer_to_offset (p, q);
@@ -595,6 +649,8 @@ load_file (const gchar *filename)
start = end;
+ while (*p != '\n') p++;
+
state++;
}
break;
@@ -662,6 +718,8 @@ load_file (const gchar *filename)
fontify ();
g_string_free (buffer, TRUE);
+
+ g_strfreev (names);
}
void
@@ -928,7 +986,6 @@ int
main (int argc, char **argv)
{
GtkWidget *window;
- GtkWidget *notebook;
GtkWidget *hbox;
GtkWidget *tree;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]