forked from AuroraMiddleware/gtk
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.
This commit is contained in:
parent
fc86f2af1d
commit
91d01434bc
@ -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
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Application class
|
||||
/* Application class :: menus.ui application.ui
|
||||
*
|
||||
* Demonstrates a simple application.
|
||||
*
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Builder
|
||||
/* Builder :: demo.ui
|
||||
*
|
||||
* Demonstrates an interface loaded from a XML description.
|
||||
*/
|
||||
|
@ -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;
|
||||
|
||||
if (current_file && !strcmp (current_file, filename))
|
||||
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, 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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user