forked from AuroraMiddleware/gtk
Getting started: Coding style updates
Make the new examples use GTK+ coding style.
This commit is contained in:
parent
e6c5faed73
commit
99203f09f2
@ -348,14 +348,14 @@
|
||||
static void
|
||||
example_app_window_init (ExampleAppWindow *win)
|
||||
{
|
||||
gtk_widget_init_template (GTK_WIDGET (win));
|
||||
gtk_widget_init_template (GTK_WIDGET (win));
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_window_class_init (ExampleAppWindowClass *class)
|
||||
{
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/window.ui");
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/window.ui");
|
||||
}
|
||||
|
||||
...
|
||||
@ -409,8 +409,9 @@ example_app_window_class_init (ExampleAppWindowClass *class)
|
||||
<programlisting><![CDATA[
|
||||
...
|
||||
|
||||
struct ExampleAppWindowPrivate {
|
||||
GtkWidget *stack;
|
||||
struct _ExampleAppWindowPrivate
|
||||
{
|
||||
GtkWidget *stack;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW);
|
||||
@ -420,9 +421,9 @@ G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLIC
|
||||
static void
|
||||
example_app_window_class_init (ExampleAppWindowClass *class)
|
||||
{
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/window.ui");
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, stack);
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/window.ui");
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, stack);
|
||||
}
|
||||
|
||||
...
|
||||
@ -442,32 +443,34 @@ void
|
||||
example_app_window_open (ExampleAppWindow *win,
|
||||
GFile *file)
|
||||
{
|
||||
ExampleAppWindowPrivate *priv = example_app_window_get_instance_private (win);
|
||||
gchar *basename;
|
||||
GtkWidget *scrolled, *view;
|
||||
gchar *contents;
|
||||
gsize length;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
gchar *basename;
|
||||
GtkWidget *scrolled, *view;
|
||||
gchar *contents;
|
||||
gsize length;
|
||||
|
||||
basename = g_file_get_basename (file);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
basename = g_file_get_basename (file);
|
||||
|
||||
scrolled = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_widget_show (scrolled);
|
||||
gtk_widget_set_hexpand (scrolled, TRUE);
|
||||
gtk_widget_set_vexpand (scrolled, TRUE);
|
||||
view = gtk_text_view_new ();
|
||||
gtk_widget_show (view);
|
||||
gtk_container_add (GTK_CONTAINER (scrolled), view);
|
||||
gtk_stack_add_titled (GTK_STACK (priv->stack), scrolled, basename, basename);
|
||||
scrolled = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_widget_show (scrolled);
|
||||
gtk_widget_set_hexpand (scrolled, TRUE);
|
||||
gtk_widget_set_vexpand (scrolled, TRUE);
|
||||
view = gtk_text_view_new ();
|
||||
gtk_widget_show (view);
|
||||
gtk_container_add (GTK_CONTAINER (scrolled), view);
|
||||
gtk_stack_add_titled (GTK_STACK (priv->stack), scrolled, basename, basename);
|
||||
|
||||
if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL)) {
|
||||
GtkTextBuffer *buffer;
|
||||
if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL))
|
||||
{
|
||||
GtkTextBuffer *buffer;
|
||||
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
gtk_text_buffer_set_text (buffer, contents, length);
|
||||
g_free (contents);
|
||||
}
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
gtk_text_buffer_set_text (buffer, contents, length);
|
||||
g_free (contents);
|
||||
}
|
||||
|
||||
g_free (basename);
|
||||
g_free (basename);
|
||||
}
|
||||
|
||||
...
|
||||
@ -533,34 +536,35 @@ quit_activated (GSimpleAction *action,
|
||||
g_application_quit (G_APPLICATION (app));
|
||||
}
|
||||
|
||||
static GActionEntry app_entries[] = {
|
||||
{ "preferences", preferences_activated, NULL, NULL, NULL },
|
||||
{ "quit", quit_activated, NULL, NULL, NULL }
|
||||
static GActionEntry app_entries[] =
|
||||
{
|
||||
{ "preferences", preferences_activated, NULL, NULL, NULL },
|
||||
{ "quit", quit_activated, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static void
|
||||
example_app_startup (GApplication *app)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu);
|
||||
g_object_unref (builder);
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu);
|
||||
g_object_unref (builder);
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_class_init (ExampleAppClass *class)
|
||||
{
|
||||
G_APPLICATION_CLASS (class)->startup = example_app_startup;
|
||||
...
|
||||
G_APPLICATION_CLASS (class)->startup = example_app_startup;
|
||||
...
|
||||
}
|
||||
|
||||
...
|
||||
@ -618,15 +622,15 @@ example_app_class_init (ExampleAppClass *class)
|
||||
static void
|
||||
example_app_window_init (ExampleAppWindow *win)
|
||||
{
|
||||
ExampleAppWindowPrivate *priv;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
gtk_widget_init_template (GTK_WIDGET (win));
|
||||
priv->settings = g_settings_new ("org.gtk.exampleapp");
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
gtk_widget_init_template (GTK_WIDGET (win));
|
||||
priv->settings = g_settings_new ("org.gtk.exampleapp");
|
||||
|
||||
g_settings_bind (priv->settings, "transition",
|
||||
priv->stack, "transition-type",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
g_settings_bind (priv->settings, "transition",
|
||||
priv->stack, "transition-type",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
}
|
||||
|
||||
...
|
||||
@ -670,12 +674,12 @@ preferences_activated (GSimpleAction *action,
|
||||
GVariant *parameter,
|
||||
gpointer app)
|
||||
{
|
||||
ExampleAppPrefs *prefs;
|
||||
GtkWindow *win;
|
||||
ExampleAppPrefs *prefs;
|
||||
GtkWindow *win;
|
||||
|
||||
win = gtk_application_get_active_window (GTK_APPLICATION (app));
|
||||
prefs = example_app_prefs_new (EXAMPLE_APP_WINDOW (win));
|
||||
gtk_window_present (GTK_WINDOW (prefs));
|
||||
win = gtk_application_get_active_window (GTK_APPLICATION (app));
|
||||
prefs = example_app_prefs_new (EXAMPLE_APP_WINDOW (win));
|
||||
gtk_window_present (GTK_WINDOW (prefs));
|
||||
}
|
||||
|
||||
...
|
||||
@ -723,32 +727,33 @@ static void
|
||||
search_text_changed (GtkEntry *entry,
|
||||
ExampleAppWindow *win)
|
||||
{
|
||||
ExampleAppWindowPrivate *priv;
|
||||
const gchar *text;
|
||||
GtkWidget *tab;
|
||||
GtkWidget *view;
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextIter start, match_start, match_end;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
const gchar *text;
|
||||
GtkWidget *tab;
|
||||
GtkWidget *view;
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextIter start, match_start, match_end;
|
||||
|
||||
text = gtk_entry_get_text (entry);
|
||||
text = gtk_entry_get_text (entry);
|
||||
|
||||
if (text[0] == '\0')
|
||||
return;
|
||||
if (text[0] == '\0')
|
||||
return;
|
||||
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
|
||||
tab = gtk_stack_get_visible_child (GTK_STACK (priv->stack));
|
||||
view = gtk_bin_get_child (GTK_BIN (tab));
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
tab = gtk_stack_get_visible_child (GTK_STACK (priv->stack));
|
||||
view = gtk_bin_get_child (GTK_BIN (tab));
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
|
||||
/* Very simple-minded search implementation */
|
||||
gtk_text_buffer_get_start_iter (buffer, &start);
|
||||
if (gtk_text_iter_forward_search (&start, text, GTK_TEXT_SEARCH_CASE_INSENSITIVE,
|
||||
&match_start, &match_end, NULL)) {
|
||||
gtk_text_buffer_select_range (buffer, &match_start, &match_end);
|
||||
gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (view), &match_start,
|
||||
0.0, FALSE, 0.0, 0.0);
|
||||
}
|
||||
/* Very simple-minded search implementation */
|
||||
gtk_text_buffer_get_start_iter (buffer, &start);
|
||||
if (gtk_text_iter_forward_search (&start, text, GTK_TEXT_SEARCH_CASE_INSENSITIVE,
|
||||
&match_start, &match_end, NULL))
|
||||
{
|
||||
gtk_text_buffer_select_range (buffer, &match_start, &match_end);
|
||||
gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (view), &match_start,
|
||||
0.0, FALSE, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -757,8 +762,8 @@ example_app_window_init (ExampleAppWindow *win)
|
||||
|
||||
...
|
||||
|
||||
priv->text_changed_handler = g_signal_connect (priv->searchentry, "changed",
|
||||
G_CALLBACK (search_text_changed), win);
|
||||
priv->text_changed_handler = g_signal_connect (priv->searchentry, "changed",
|
||||
G_CALLBACK (search_text_changed), win);
|
||||
|
||||
...
|
||||
|
||||
@ -814,14 +819,14 @@ example_app_window_init (ExampleAppWindow *win)
|
||||
|
||||
...
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/gears-menu.ui");
|
||||
menu = G_MENU_MODEL (gtk_builder_get_object (builder, "menu"));
|
||||
gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (priv->gears), menu);
|
||||
g_object_unref (builder);
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/gears-menu.ui");
|
||||
menu = G_MENU_MODEL (gtk_builder_get_object (builder, "menu"));
|
||||
gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (priv->gears), menu);
|
||||
g_object_unref (builder);
|
||||
|
||||
action = g_settings_create_action (priv->settings, "show-words");
|
||||
g_action_map_add_action (G_ACTION_MAP (win), action);
|
||||
g_object_unref (action);
|
||||
action = g_settings_create_action (priv->settings, "show-words");
|
||||
g_action_map_add_action (G_ACTION_MAP (win), action);
|
||||
g_object_unref (action);
|
||||
}
|
||||
|
||||
...
|
||||
|
@ -3,12 +3,14 @@
|
||||
#include "exampleapp.h"
|
||||
#include "exampleappwin.h"
|
||||
|
||||
struct ExampleApp {
|
||||
GtkApplication parent;
|
||||
struct _ExampleApp
|
||||
{
|
||||
GtkApplication parent;
|
||||
};
|
||||
|
||||
struct ExampleAppClass {
|
||||
GtkApplicationClass parent_class;
|
||||
struct _ExampleAppClass
|
||||
{
|
||||
GtkApplicationClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(ExampleApp, example_app, GTK_TYPE_APPLICATION);
|
||||
@ -21,10 +23,10 @@ example_app_init (ExampleApp *app)
|
||||
static void
|
||||
example_app_activate (GApplication *app)
|
||||
{
|
||||
ExampleAppWindow *win;
|
||||
ExampleAppWindow *win;
|
||||
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -33,34 +35,34 @@ example_app_open (GApplication *app,
|
||||
gint n_files,
|
||||
const gchar *hint)
|
||||
{
|
||||
GList *windows;
|
||||
ExampleAppWindow *win;
|
||||
int i;
|
||||
GList *windows;
|
||||
ExampleAppWindow *win;
|
||||
int i;
|
||||
|
||||
windows = gtk_application_get_windows (GTK_APPLICATION (app));
|
||||
if (windows)
|
||||
win = EXAMPLE_APP_WINDOW (windows->data);
|
||||
else
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
windows = gtk_application_get_windows (GTK_APPLICATION (app));
|
||||
if (windows)
|
||||
win = EXAMPLE_APP_WINDOW (windows->data);
|
||||
else
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
|
||||
for (i = 0; i < n_files; i++)
|
||||
example_app_window_open (win, files[i]);
|
||||
for (i = 0; i < n_files; i++)
|
||||
example_app_window_open (win, files[i]);
|
||||
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_class_init (ExampleAppClass *class)
|
||||
{
|
||||
G_APPLICATION_CLASS (class)->activate = example_app_activate;
|
||||
G_APPLICATION_CLASS (class)->open = example_app_open;
|
||||
G_APPLICATION_CLASS (class)->activate = example_app_activate;
|
||||
G_APPLICATION_CLASS (class)->open = example_app_open;
|
||||
}
|
||||
|
||||
ExampleApp *
|
||||
example_app_new (void)
|
||||
{
|
||||
return g_object_new (EXAMPLE_APP_TYPE,
|
||||
"application-id", "org.gtk.exampleapp",
|
||||
"flags", G_APPLICATION_HANDLES_OPEN,
|
||||
NULL);
|
||||
return g_object_new (EXAMPLE_APP_TYPE,
|
||||
"application-id", "org.gtk.exampleapp",
|
||||
"flags", G_APPLICATION_HANDLES_OPEN,
|
||||
NULL);
|
||||
}
|
||||
|
@ -8,8 +8,8 @@
|
||||
#define EXAMPLE_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_TYPE, ExampleApp))
|
||||
|
||||
|
||||
typedef struct ExampleApp ExampleApp;
|
||||
typedef struct ExampleAppClass ExampleAppClass;
|
||||
typedef struct _ExampleApp ExampleApp;
|
||||
typedef struct _ExampleAppClass ExampleAppClass;
|
||||
|
||||
|
||||
GType example_app_get_type (void);
|
||||
|
@ -2,12 +2,14 @@
|
||||
#include "exampleappwin.h"
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
struct ExampleAppWindow {
|
||||
GtkApplicationWindow parent;
|
||||
struct _ExampleAppWindow
|
||||
{
|
||||
GtkApplicationWindow parent;
|
||||
};
|
||||
|
||||
struct ExampleAppWindowClass {
|
||||
GtkApplicationWindowClass parent_class;
|
||||
struct _ExampleAppWindowClass
|
||||
{
|
||||
GtkApplicationWindowClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW);
|
||||
@ -25,7 +27,7 @@ example_app_window_class_init (ExampleAppWindowClass *class)
|
||||
ExampleAppWindow *
|
||||
example_app_window_new (ExampleApp *app)
|
||||
{
|
||||
return g_object_new (EXAMPLE_APP_WINDOW_TYPE, "application", app, NULL);
|
||||
return g_object_new (EXAMPLE_APP_WINDOW_TYPE, "application", app, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -9,8 +9,8 @@
|
||||
#define EXAMPLE_APP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_WINDOW_TYPE, ExampleAppWindow))
|
||||
|
||||
|
||||
typedef struct ExampleAppWindow ExampleAppWindow;
|
||||
typedef struct ExampleAppWindowClass ExampleAppWindowClass;
|
||||
typedef struct _ExampleAppWindow ExampleAppWindow;
|
||||
typedef struct _ExampleAppWindowClass ExampleAppWindowClass;
|
||||
|
||||
|
||||
GType example_app_window_get_type (void);
|
||||
|
@ -4,5 +4,5 @@
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
return g_application_run (G_APPLICATION (example_app_new ()), argc, argv);
|
||||
return g_application_run (G_APPLICATION (example_app_new ()), argc, argv);
|
||||
}
|
||||
|
@ -3,12 +3,14 @@
|
||||
#include "exampleapp.h"
|
||||
#include "exampleappwin.h"
|
||||
|
||||
struct ExampleApp {
|
||||
GtkApplication parent;
|
||||
struct _ExampleApp
|
||||
{
|
||||
GtkApplication parent;
|
||||
};
|
||||
|
||||
struct ExampleAppClass {
|
||||
GtkApplicationClass parent_class;
|
||||
struct _ExampleAppClass
|
||||
{
|
||||
GtkApplicationClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(ExampleApp, example_app, GTK_TYPE_APPLICATION);
|
||||
@ -21,10 +23,10 @@ example_app_init (ExampleApp *app)
|
||||
static void
|
||||
example_app_activate (GApplication *app)
|
||||
{
|
||||
ExampleAppWindow *win;
|
||||
ExampleAppWindow *win;
|
||||
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -33,34 +35,34 @@ example_app_open (GApplication *app,
|
||||
gint n_files,
|
||||
const gchar *hint)
|
||||
{
|
||||
GList *windows;
|
||||
ExampleAppWindow *win;
|
||||
int i;
|
||||
GList *windows;
|
||||
ExampleAppWindow *win;
|
||||
int i;
|
||||
|
||||
windows = gtk_application_get_windows (GTK_APPLICATION (app));
|
||||
if (windows)
|
||||
win = EXAMPLE_APP_WINDOW (windows->data);
|
||||
else
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
windows = gtk_application_get_windows (GTK_APPLICATION (app));
|
||||
if (windows)
|
||||
win = EXAMPLE_APP_WINDOW (windows->data);
|
||||
else
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
|
||||
for (i = 0; i < n_files; i++)
|
||||
example_app_window_open (win, files[i]);
|
||||
for (i = 0; i < n_files; i++)
|
||||
example_app_window_open (win, files[i]);
|
||||
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_class_init (ExampleAppClass *class)
|
||||
{
|
||||
G_APPLICATION_CLASS (class)->activate = example_app_activate;
|
||||
G_APPLICATION_CLASS (class)->open = example_app_open;
|
||||
G_APPLICATION_CLASS (class)->activate = example_app_activate;
|
||||
G_APPLICATION_CLASS (class)->open = example_app_open;
|
||||
}
|
||||
|
||||
ExampleApp *
|
||||
example_app_new (void)
|
||||
{
|
||||
return g_object_new (EXAMPLE_APP_TYPE,
|
||||
"application-id", "org.gtk.exampleapp",
|
||||
"flags", G_APPLICATION_HANDLES_OPEN,
|
||||
NULL);
|
||||
return g_object_new (EXAMPLE_APP_TYPE,
|
||||
"application-id", "org.gtk.exampleapp",
|
||||
"flags", G_APPLICATION_HANDLES_OPEN,
|
||||
NULL);
|
||||
}
|
||||
|
@ -8,8 +8,8 @@
|
||||
#define EXAMPLE_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_TYPE, ExampleApp))
|
||||
|
||||
|
||||
typedef struct ExampleApp ExampleApp;
|
||||
typedef struct ExampleAppClass ExampleAppClass;
|
||||
typedef struct _ExampleApp ExampleApp;
|
||||
typedef struct _ExampleAppClass ExampleAppClass;
|
||||
|
||||
|
||||
GType example_app_get_type (void);
|
||||
|
@ -2,12 +2,14 @@
|
||||
#include "exampleappwin.h"
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
struct ExampleAppWindow {
|
||||
GtkApplicationWindow parent;
|
||||
struct _ExampleAppWindow
|
||||
{
|
||||
GtkApplicationWindow parent;
|
||||
};
|
||||
|
||||
struct ExampleAppWindowClass {
|
||||
GtkApplicationWindowClass parent_class;
|
||||
struct _ExampleAppWindowClass
|
||||
{
|
||||
GtkApplicationWindowClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW);
|
||||
@ -15,20 +17,20 @@ G_DEFINE_TYPE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW)
|
||||
static void
|
||||
example_app_window_init (ExampleAppWindow *win)
|
||||
{
|
||||
gtk_widget_init_template (GTK_WIDGET (win));
|
||||
gtk_widget_init_template (GTK_WIDGET (win));
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_window_class_init (ExampleAppWindowClass *class)
|
||||
{
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/window.ui");
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/window.ui");
|
||||
}
|
||||
|
||||
ExampleAppWindow *
|
||||
example_app_window_new (ExampleApp *app)
|
||||
{
|
||||
return g_object_new (EXAMPLE_APP_WINDOW_TYPE, "application", app, NULL);
|
||||
return g_object_new (EXAMPLE_APP_WINDOW_TYPE, "application", app, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -9,8 +9,8 @@
|
||||
#define EXAMPLE_APP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_WINDOW_TYPE, ExampleAppWindow))
|
||||
|
||||
|
||||
typedef struct ExampleAppWindow ExampleAppWindow;
|
||||
typedef struct ExampleAppWindowClass ExampleAppWindowClass;
|
||||
typedef struct _ExampleAppWindow ExampleAppWindow;
|
||||
typedef struct _ExampleAppWindowClass ExampleAppWindowClass;
|
||||
|
||||
|
||||
GType example_app_window_get_type (void);
|
||||
|
@ -4,5 +4,5 @@
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
return g_application_run (G_APPLICATION (example_app_new ()), argc, argv);
|
||||
return g_application_run (G_APPLICATION (example_app_new ()), argc, argv);
|
||||
}
|
||||
|
@ -3,12 +3,14 @@
|
||||
#include "exampleapp.h"
|
||||
#include "exampleappwin.h"
|
||||
|
||||
struct ExampleApp {
|
||||
GtkApplication parent;
|
||||
struct _ExampleApp
|
||||
{
|
||||
GtkApplication parent;
|
||||
};
|
||||
|
||||
struct ExampleAppClass {
|
||||
GtkApplicationClass parent_class;
|
||||
struct _ExampleAppClass
|
||||
{
|
||||
GtkApplicationClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(ExampleApp, example_app, GTK_TYPE_APPLICATION);
|
||||
@ -21,10 +23,10 @@ example_app_init (ExampleApp *app)
|
||||
static void
|
||||
example_app_activate (GApplication *app)
|
||||
{
|
||||
ExampleAppWindow *win;
|
||||
ExampleAppWindow *win;
|
||||
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -33,34 +35,34 @@ example_app_open (GApplication *app,
|
||||
gint n_files,
|
||||
const gchar *hint)
|
||||
{
|
||||
GList *windows;
|
||||
ExampleAppWindow *win;
|
||||
int i;
|
||||
GList *windows;
|
||||
ExampleAppWindow *win;
|
||||
int i;
|
||||
|
||||
windows = gtk_application_get_windows (GTK_APPLICATION (app));
|
||||
if (windows)
|
||||
win = EXAMPLE_APP_WINDOW (windows->data);
|
||||
else
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
windows = gtk_application_get_windows (GTK_APPLICATION (app));
|
||||
if (windows)
|
||||
win = EXAMPLE_APP_WINDOW (windows->data);
|
||||
else
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
|
||||
for (i = 0; i < n_files; i++)
|
||||
example_app_window_open (win, files[i]);
|
||||
for (i = 0; i < n_files; i++)
|
||||
example_app_window_open (win, files[i]);
|
||||
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_class_init (ExampleAppClass *class)
|
||||
{
|
||||
G_APPLICATION_CLASS (class)->activate = example_app_activate;
|
||||
G_APPLICATION_CLASS (class)->open = example_app_open;
|
||||
G_APPLICATION_CLASS (class)->activate = example_app_activate;
|
||||
G_APPLICATION_CLASS (class)->open = example_app_open;
|
||||
}
|
||||
|
||||
ExampleApp *
|
||||
example_app_new (void)
|
||||
{
|
||||
return g_object_new (EXAMPLE_APP_TYPE,
|
||||
"application-id", "org.gtk.exampleapp",
|
||||
"flags", G_APPLICATION_HANDLES_OPEN,
|
||||
NULL);
|
||||
return g_object_new (EXAMPLE_APP_TYPE,
|
||||
"application-id", "org.gtk.exampleapp",
|
||||
"flags", G_APPLICATION_HANDLES_OPEN,
|
||||
NULL);
|
||||
}
|
||||
|
@ -8,8 +8,8 @@
|
||||
#define EXAMPLE_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_TYPE, ExampleApp))
|
||||
|
||||
|
||||
typedef struct ExampleApp ExampleApp;
|
||||
typedef struct ExampleAppClass ExampleAppClass;
|
||||
typedef struct _ExampleApp ExampleApp;
|
||||
typedef struct _ExampleAppClass ExampleAppClass;
|
||||
|
||||
|
||||
GType example_app_get_type (void);
|
||||
|
@ -2,18 +2,21 @@
|
||||
#include "exampleappwin.h"
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
struct ExampleAppWindow {
|
||||
GtkApplicationWindow parent;
|
||||
struct _ExampleAppWindow
|
||||
{
|
||||
GtkApplicationWindow parent;
|
||||
};
|
||||
|
||||
struct ExampleAppWindowClass {
|
||||
GtkApplicationWindowClass parent_class;
|
||||
struct _ExampleAppWindowClass
|
||||
{
|
||||
GtkApplicationWindowClass parent_class;
|
||||
};
|
||||
|
||||
typedef struct ExampleAppWindowPrivate ExampleAppWindowPrivate;
|
||||
typedef struct _ExampleAppWindowPrivate ExampleAppWindowPrivate;
|
||||
|
||||
struct ExampleAppWindowPrivate {
|
||||
GtkWidget *stack;
|
||||
struct _ExampleAppWindowPrivate
|
||||
{
|
||||
GtkWidget *stack;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW);
|
||||
@ -21,53 +24,55 @@ G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLIC
|
||||
static void
|
||||
example_app_window_init (ExampleAppWindow *win)
|
||||
{
|
||||
gtk_widget_init_template (GTK_WIDGET (win));
|
||||
gtk_widget_init_template (GTK_WIDGET (win));
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_window_class_init (ExampleAppWindowClass *class)
|
||||
{
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/window.ui");
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, stack);
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/window.ui");
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, stack);
|
||||
}
|
||||
|
||||
ExampleAppWindow *
|
||||
example_app_window_new (ExampleApp *app)
|
||||
{
|
||||
return g_object_new (EXAMPLE_APP_WINDOW_TYPE, "application", app, NULL);
|
||||
return g_object_new (EXAMPLE_APP_WINDOW_TYPE, "application", app, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
example_app_window_open (ExampleAppWindow *win,
|
||||
GFile *file)
|
||||
{
|
||||
ExampleAppWindowPrivate *priv = example_app_window_get_instance_private (win);
|
||||
gchar *basename;
|
||||
GtkWidget *scrolled, *view;
|
||||
gchar *contents;
|
||||
gsize length;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
gchar *basename;
|
||||
GtkWidget *scrolled, *view;
|
||||
gchar *contents;
|
||||
gsize length;
|
||||
|
||||
basename = g_file_get_basename (file);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
basename = g_file_get_basename (file);
|
||||
|
||||
scrolled = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_widget_show (scrolled);
|
||||
gtk_widget_set_hexpand (scrolled, TRUE);
|
||||
gtk_widget_set_vexpand (scrolled, TRUE);
|
||||
view = gtk_text_view_new ();
|
||||
gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_widget_show (view);
|
||||
gtk_container_add (GTK_CONTAINER (scrolled), view);
|
||||
gtk_stack_add_titled (GTK_STACK (priv->stack), scrolled, basename, basename);
|
||||
scrolled = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_widget_show (scrolled);
|
||||
gtk_widget_set_hexpand (scrolled, TRUE);
|
||||
gtk_widget_set_vexpand (scrolled, TRUE);
|
||||
view = gtk_text_view_new ();
|
||||
gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_widget_show (view);
|
||||
gtk_container_add (GTK_CONTAINER (scrolled), view);
|
||||
gtk_stack_add_titled (GTK_STACK (priv->stack), scrolled, basename, basename);
|
||||
|
||||
if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL)) {
|
||||
GtkTextBuffer *buffer;
|
||||
if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL))
|
||||
{
|
||||
GtkTextBuffer *buffer;
|
||||
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
gtk_text_buffer_set_text (buffer, contents, length);
|
||||
g_free (contents);
|
||||
}
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
gtk_text_buffer_set_text (buffer, contents, length);
|
||||
g_free (contents);
|
||||
}
|
||||
|
||||
g_free (basename);
|
||||
g_free (basename);
|
||||
}
|
||||
|
@ -9,8 +9,8 @@
|
||||
#define EXAMPLE_APP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_WINDOW_TYPE, ExampleAppWindow))
|
||||
|
||||
|
||||
typedef struct ExampleAppWindow ExampleAppWindow;
|
||||
typedef struct ExampleAppWindowClass ExampleAppWindowClass;
|
||||
typedef struct _ExampleAppWindow ExampleAppWindow;
|
||||
typedef struct _ExampleAppWindowClass ExampleAppWindowClass;
|
||||
|
||||
|
||||
GType example_app_window_get_type (void);
|
||||
|
@ -4,5 +4,5 @@
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
return g_application_run (G_APPLICATION (example_app_new ()), argc, argv);
|
||||
return g_application_run (G_APPLICATION (example_app_new ()), argc, argv);
|
||||
}
|
||||
|
@ -3,12 +3,14 @@
|
||||
#include "exampleapp.h"
|
||||
#include "exampleappwin.h"
|
||||
|
||||
struct ExampleApp {
|
||||
GtkApplication parent;
|
||||
struct _ExampleApp
|
||||
{
|
||||
GtkApplication parent;
|
||||
};
|
||||
|
||||
struct ExampleAppClass {
|
||||
GtkApplicationClass parent_class;
|
||||
struct _ExampleAppClass
|
||||
{
|
||||
GtkApplicationClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(ExampleApp, example_app, GTK_TYPE_APPLICATION);
|
||||
@ -33,36 +35,37 @@ quit_activated (GSimpleAction *action,
|
||||
g_application_quit (G_APPLICATION (app));
|
||||
}
|
||||
|
||||
static GActionEntry app_entries[] = {
|
||||
{ "preferences", preferences_activated, NULL, NULL, NULL },
|
||||
{ "quit", quit_activated, NULL, NULL, NULL }
|
||||
static GActionEntry app_entries[] =
|
||||
{
|
||||
{ "preferences", preferences_activated, NULL, NULL, NULL },
|
||||
{ "quit", quit_activated, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
example_app_startup (GApplication *app)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu);
|
||||
g_object_unref (builder);
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu);
|
||||
g_object_unref (builder);
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_activate (GApplication *app)
|
||||
{
|
||||
ExampleAppWindow *win;
|
||||
ExampleAppWindow *win;
|
||||
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -71,35 +74,35 @@ example_app_open (GApplication *app,
|
||||
gint n_files,
|
||||
const gchar *hint)
|
||||
{
|
||||
GList *windows;
|
||||
ExampleAppWindow *win;
|
||||
int i;
|
||||
GList *windows;
|
||||
ExampleAppWindow *win;
|
||||
int i;
|
||||
|
||||
windows = gtk_application_get_windows (GTK_APPLICATION (app));
|
||||
if (windows)
|
||||
win = EXAMPLE_APP_WINDOW (windows->data);
|
||||
else
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
windows = gtk_application_get_windows (GTK_APPLICATION (app));
|
||||
if (windows)
|
||||
win = EXAMPLE_APP_WINDOW (windows->data);
|
||||
else
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
|
||||
for (i = 0; i < n_files; i++)
|
||||
example_app_window_open (win, files[i]);
|
||||
for (i = 0; i < n_files; i++)
|
||||
example_app_window_open (win, files[i]);
|
||||
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_class_init (ExampleAppClass *class)
|
||||
{
|
||||
G_APPLICATION_CLASS (class)->startup = example_app_startup;
|
||||
G_APPLICATION_CLASS (class)->activate = example_app_activate;
|
||||
G_APPLICATION_CLASS (class)->open = example_app_open;
|
||||
G_APPLICATION_CLASS (class)->startup = example_app_startup;
|
||||
G_APPLICATION_CLASS (class)->activate = example_app_activate;
|
||||
G_APPLICATION_CLASS (class)->open = example_app_open;
|
||||
}
|
||||
|
||||
ExampleApp *
|
||||
example_app_new (void)
|
||||
{
|
||||
return g_object_new (EXAMPLE_APP_TYPE,
|
||||
"application-id", "org.gtk.exampleapp",
|
||||
"flags", G_APPLICATION_HANDLES_OPEN,
|
||||
NULL);
|
||||
return g_object_new (EXAMPLE_APP_TYPE,
|
||||
"application-id", "org.gtk.exampleapp",
|
||||
"flags", G_APPLICATION_HANDLES_OPEN,
|
||||
NULL);
|
||||
}
|
||||
|
@ -8,8 +8,8 @@
|
||||
#define EXAMPLE_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_TYPE, ExampleApp))
|
||||
|
||||
|
||||
typedef struct ExampleApp ExampleApp;
|
||||
typedef struct ExampleAppClass ExampleAppClass;
|
||||
typedef struct _ExampleApp ExampleApp;
|
||||
typedef struct _ExampleAppClass ExampleAppClass;
|
||||
|
||||
|
||||
GType example_app_get_type (void);
|
||||
|
@ -2,18 +2,21 @@
|
||||
#include "exampleappwin.h"
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
struct ExampleAppWindow {
|
||||
GtkApplicationWindow parent;
|
||||
struct _ExampleAppWindow
|
||||
{
|
||||
GtkApplicationWindow parent;
|
||||
};
|
||||
|
||||
struct ExampleAppWindowClass {
|
||||
GtkApplicationWindowClass parent_class;
|
||||
struct _ExampleAppWindowClass
|
||||
{
|
||||
GtkApplicationWindowClass parent_class;
|
||||
};
|
||||
|
||||
typedef struct ExampleAppWindowPrivate ExampleAppWindowPrivate;
|
||||
typedef struct _ExampleAppWindowPrivate ExampleAppWindowPrivate;
|
||||
|
||||
struct ExampleAppWindowPrivate {
|
||||
GtkWidget *stack;
|
||||
struct _ExampleAppWindowPrivate
|
||||
{
|
||||
GtkWidget *stack;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW);
|
||||
@ -21,53 +24,55 @@ G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLIC
|
||||
static void
|
||||
example_app_window_init (ExampleAppWindow *win)
|
||||
{
|
||||
gtk_widget_init_template (GTK_WIDGET (win));
|
||||
gtk_widget_init_template (GTK_WIDGET (win));
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_window_class_init (ExampleAppWindowClass *class)
|
||||
{
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/window.ui");
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, stack);
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/window.ui");
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, stack);
|
||||
}
|
||||
|
||||
ExampleAppWindow *
|
||||
example_app_window_new (ExampleApp *app)
|
||||
{
|
||||
return g_object_new (EXAMPLE_APP_WINDOW_TYPE, "application", app, NULL);
|
||||
return g_object_new (EXAMPLE_APP_WINDOW_TYPE, "application", app, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
example_app_window_open (ExampleAppWindow *win,
|
||||
GFile *file)
|
||||
{
|
||||
ExampleAppWindowPrivate *priv = example_app_window_get_instance_private (win);
|
||||
gchar *basename;
|
||||
GtkWidget *scrolled, *view;
|
||||
gchar *contents;
|
||||
gsize length;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
gchar *basename;
|
||||
GtkWidget *scrolled, *view;
|
||||
gchar *contents;
|
||||
gsize length;
|
||||
|
||||
basename = g_file_get_basename (file);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
basename = g_file_get_basename (file);
|
||||
|
||||
scrolled = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_widget_show (scrolled);
|
||||
gtk_widget_set_hexpand (scrolled, TRUE);
|
||||
gtk_widget_set_vexpand (scrolled, TRUE);
|
||||
view = gtk_text_view_new ();
|
||||
gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_widget_show (view);
|
||||
gtk_container_add (GTK_CONTAINER (scrolled), view);
|
||||
gtk_stack_add_titled (GTK_STACK (priv->stack), scrolled, basename, basename);
|
||||
scrolled = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_widget_show (scrolled);
|
||||
gtk_widget_set_hexpand (scrolled, TRUE);
|
||||
gtk_widget_set_vexpand (scrolled, TRUE);
|
||||
view = gtk_text_view_new ();
|
||||
gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_widget_show (view);
|
||||
gtk_container_add (GTK_CONTAINER (scrolled), view);
|
||||
gtk_stack_add_titled (GTK_STACK (priv->stack), scrolled, basename, basename);
|
||||
|
||||
if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL)) {
|
||||
GtkTextBuffer *buffer;
|
||||
if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL))
|
||||
{
|
||||
GtkTextBuffer *buffer;
|
||||
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
gtk_text_buffer_set_text (buffer, contents, length);
|
||||
g_free (contents);
|
||||
}
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
gtk_text_buffer_set_text (buffer, contents, length);
|
||||
g_free (contents);
|
||||
}
|
||||
|
||||
g_free (basename);
|
||||
g_free (basename);
|
||||
}
|
||||
|
@ -9,8 +9,8 @@
|
||||
#define EXAMPLE_APP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_WINDOW_TYPE, ExampleAppWindow))
|
||||
|
||||
|
||||
typedef struct ExampleAppWindow ExampleAppWindow;
|
||||
typedef struct ExampleAppWindowClass ExampleAppWindowClass;
|
||||
typedef struct _ExampleAppWindow ExampleAppWindow;
|
||||
typedef struct _ExampleAppWindowClass ExampleAppWindowClass;
|
||||
|
||||
|
||||
GType example_app_window_get_type (void);
|
||||
|
@ -4,5 +4,5 @@
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
return g_application_run (G_APPLICATION (example_app_new ()), argc, argv);
|
||||
return g_application_run (G_APPLICATION (example_app_new ()), argc, argv);
|
||||
}
|
||||
|
@ -3,12 +3,14 @@
|
||||
#include "exampleapp.h"
|
||||
#include "exampleappwin.h"
|
||||
|
||||
struct ExampleApp {
|
||||
GtkApplication parent;
|
||||
struct _ExampleApp
|
||||
{
|
||||
GtkApplication parent;
|
||||
};
|
||||
|
||||
struct ExampleAppClass {
|
||||
GtkApplicationClass parent_class;
|
||||
struct _ExampleAppClass
|
||||
{
|
||||
GtkApplicationClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(ExampleApp, example_app, GTK_TYPE_APPLICATION);
|
||||
@ -33,36 +35,37 @@ quit_activated (GSimpleAction *action,
|
||||
g_application_quit (G_APPLICATION (app));
|
||||
}
|
||||
|
||||
static GActionEntry app_entries[] = {
|
||||
{ "preferences", preferences_activated, NULL, NULL, NULL },
|
||||
{ "quit", quit_activated, NULL, NULL, NULL }
|
||||
static GActionEntry app_entries[] =
|
||||
{
|
||||
{ "preferences", preferences_activated, NULL, NULL, NULL },
|
||||
{ "quit", quit_activated, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
example_app_startup (GApplication *app)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu);
|
||||
g_object_unref (builder);
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu);
|
||||
g_object_unref (builder);
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_activate (GApplication *app)
|
||||
{
|
||||
ExampleAppWindow *win;
|
||||
ExampleAppWindow *win;
|
||||
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -71,35 +74,35 @@ example_app_open (GApplication *app,
|
||||
gint n_files,
|
||||
const gchar *hint)
|
||||
{
|
||||
GList *windows;
|
||||
ExampleAppWindow *win;
|
||||
int i;
|
||||
GList *windows;
|
||||
ExampleAppWindow *win;
|
||||
int i;
|
||||
|
||||
windows = gtk_application_get_windows (GTK_APPLICATION (app));
|
||||
if (windows)
|
||||
win = EXAMPLE_APP_WINDOW (windows->data);
|
||||
else
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
windows = gtk_application_get_windows (GTK_APPLICATION (app));
|
||||
if (windows)
|
||||
win = EXAMPLE_APP_WINDOW (windows->data);
|
||||
else
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
|
||||
for (i = 0; i < n_files; i++)
|
||||
example_app_window_open (win, files[i]);
|
||||
for (i = 0; i < n_files; i++)
|
||||
example_app_window_open (win, files[i]);
|
||||
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_class_init (ExampleAppClass *class)
|
||||
{
|
||||
G_APPLICATION_CLASS (class)->startup = example_app_startup;
|
||||
G_APPLICATION_CLASS (class)->activate = example_app_activate;
|
||||
G_APPLICATION_CLASS (class)->open = example_app_open;
|
||||
G_APPLICATION_CLASS (class)->startup = example_app_startup;
|
||||
G_APPLICATION_CLASS (class)->activate = example_app_activate;
|
||||
G_APPLICATION_CLASS (class)->open = example_app_open;
|
||||
}
|
||||
|
||||
ExampleApp *
|
||||
example_app_new (void)
|
||||
{
|
||||
return g_object_new (EXAMPLE_APP_TYPE,
|
||||
"application-id", "org.gtk.exampleapp",
|
||||
"flags", G_APPLICATION_HANDLES_OPEN,
|
||||
NULL);
|
||||
return g_object_new (EXAMPLE_APP_TYPE,
|
||||
"application-id", "org.gtk.exampleapp",
|
||||
"flags", G_APPLICATION_HANDLES_OPEN,
|
||||
NULL);
|
||||
}
|
||||
|
@ -8,8 +8,8 @@
|
||||
#define EXAMPLE_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_TYPE, ExampleApp))
|
||||
|
||||
|
||||
typedef struct ExampleApp ExampleApp;
|
||||
typedef struct ExampleAppClass ExampleAppClass;
|
||||
typedef struct _ExampleApp ExampleApp;
|
||||
typedef struct _ExampleAppClass ExampleAppClass;
|
||||
|
||||
|
||||
GType example_app_get_type (void);
|
||||
|
@ -2,19 +2,22 @@
|
||||
#include "exampleappwin.h"
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
struct ExampleAppWindow {
|
||||
GtkApplicationWindow parent;
|
||||
struct _ExampleAppWindow
|
||||
{
|
||||
GtkApplicationWindow parent;
|
||||
};
|
||||
|
||||
struct ExampleAppWindowClass {
|
||||
GtkApplicationWindowClass parent_class;
|
||||
struct _ExampleAppWindowClass
|
||||
{
|
||||
GtkApplicationWindowClass parent_class;
|
||||
};
|
||||
|
||||
typedef struct ExampleAppWindowPrivate ExampleAppWindowPrivate;
|
||||
typedef struct _ExampleAppWindowPrivate ExampleAppWindowPrivate;
|
||||
|
||||
struct ExampleAppWindowPrivate {
|
||||
GSettings *settings;
|
||||
GtkWidget *stack;
|
||||
struct _ExampleAppWindowPrivate
|
||||
{
|
||||
GSettings *settings;
|
||||
GtkWidget *stack;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW);
|
||||
@ -22,87 +25,88 @@ G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLIC
|
||||
static void
|
||||
example_app_window_init (ExampleAppWindow *win)
|
||||
{
|
||||
ExampleAppWindowPrivate *priv;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
gtk_widget_init_template (GTK_WIDGET (win));
|
||||
priv->settings = g_settings_new ("org.gtk.exampleapp");
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
gtk_widget_init_template (GTK_WIDGET (win));
|
||||
priv->settings = g_settings_new ("org.gtk.exampleapp");
|
||||
|
||||
g_settings_bind (priv->settings, "transition",
|
||||
priv->stack, "transition-type",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
g_settings_bind (priv->settings, "transition",
|
||||
priv->stack, "transition-type",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_window_dispose (GObject *object)
|
||||
{
|
||||
ExampleAppWindow *win;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
ExampleAppWindow *win;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
|
||||
win = EXAMPLE_APP_WINDOW (object);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
win = EXAMPLE_APP_WINDOW (object);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
|
||||
g_clear_object (&priv->settings);
|
||||
g_clear_object (&priv->settings);
|
||||
|
||||
G_OBJECT_CLASS (example_app_window_parent_class)->dispose (object);
|
||||
G_OBJECT_CLASS (example_app_window_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_window_class_init (ExampleAppWindowClass *class)
|
||||
{
|
||||
G_OBJECT_CLASS (class)->dispose = example_app_window_dispose;
|
||||
G_OBJECT_CLASS (class)->dispose = example_app_window_dispose;
|
||||
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/window.ui");
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, stack);
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/window.ui");
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, stack);
|
||||
}
|
||||
|
||||
ExampleAppWindow *
|
||||
example_app_window_new (ExampleApp *app)
|
||||
{
|
||||
return g_object_new (EXAMPLE_APP_WINDOW_TYPE, "application", app, NULL);
|
||||
return g_object_new (EXAMPLE_APP_WINDOW_TYPE, "application", app, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
example_app_window_open (ExampleAppWindow *win,
|
||||
GFile *file)
|
||||
{
|
||||
ExampleAppWindowPrivate *priv;
|
||||
gchar *basename;
|
||||
GtkWidget *scrolled, *view;
|
||||
gchar *contents;
|
||||
gsize length;
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextTag *tag;
|
||||
GtkTextIter start_iter, end_iter;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
gchar *basename;
|
||||
GtkWidget *scrolled, *view;
|
||||
gchar *contents;
|
||||
gsize length;
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextTag *tag;
|
||||
GtkTextIter start_iter, end_iter;
|
||||
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
basename = g_file_get_basename (file);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
basename = g_file_get_basename (file);
|
||||
|
||||
scrolled = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_widget_show (scrolled);
|
||||
gtk_widget_set_hexpand (scrolled, TRUE);
|
||||
gtk_widget_set_vexpand (scrolled, TRUE);
|
||||
view = gtk_text_view_new ();
|
||||
gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_widget_show (view);
|
||||
gtk_container_add (GTK_CONTAINER (scrolled), view);
|
||||
gtk_stack_add_titled (GTK_STACK (priv->stack), scrolled, basename, basename);
|
||||
scrolled = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_widget_show (scrolled);
|
||||
gtk_widget_set_hexpand (scrolled, TRUE);
|
||||
gtk_widget_set_vexpand (scrolled, TRUE);
|
||||
view = gtk_text_view_new ();
|
||||
gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_widget_show (view);
|
||||
gtk_container_add (GTK_CONTAINER (scrolled), view);
|
||||
gtk_stack_add_titled (GTK_STACK (priv->stack), scrolled, basename, basename);
|
||||
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
|
||||
if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL)) {
|
||||
gtk_text_buffer_set_text (buffer, contents, length);
|
||||
g_free (contents);
|
||||
}
|
||||
if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL))
|
||||
{
|
||||
gtk_text_buffer_set_text (buffer, contents, length);
|
||||
g_free (contents);
|
||||
}
|
||||
|
||||
tag = gtk_text_buffer_create_tag (buffer, NULL, NULL);
|
||||
g_settings_bind (priv->settings, "font", tag, "font", G_SETTINGS_BIND_DEFAULT);
|
||||
tag = gtk_text_buffer_create_tag (buffer, NULL, NULL);
|
||||
g_settings_bind (priv->settings, "font", tag, "font", G_SETTINGS_BIND_DEFAULT);
|
||||
|
||||
gtk_text_buffer_get_start_iter (buffer, &start_iter);
|
||||
gtk_text_buffer_get_end_iter (buffer, &end_iter);
|
||||
gtk_text_buffer_apply_tag (buffer, tag, &start_iter, &end_iter);
|
||||
gtk_text_buffer_get_start_iter (buffer, &start_iter);
|
||||
gtk_text_buffer_get_end_iter (buffer, &end_iter);
|
||||
gtk_text_buffer_apply_tag (buffer, tag, &start_iter, &end_iter);
|
||||
|
||||
g_free (basename);
|
||||
g_free (basename);
|
||||
}
|
||||
|
@ -9,8 +9,8 @@
|
||||
#define EXAMPLE_APP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_WINDOW_TYPE, ExampleAppWindow))
|
||||
|
||||
|
||||
typedef struct ExampleAppWindow ExampleAppWindow;
|
||||
typedef struct ExampleAppWindowClass ExampleAppWindowClass;
|
||||
typedef struct _ExampleAppWindow ExampleAppWindow;
|
||||
typedef struct _ExampleAppWindowClass ExampleAppWindowClass;
|
||||
|
||||
|
||||
GType example_app_window_get_type (void);
|
||||
|
@ -4,12 +4,12 @@
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
/* Since this example is running uninstalled,
|
||||
* we have to help it find its schema. This
|
||||
* is *not* necessary in properly installed
|
||||
* application.
|
||||
*/
|
||||
g_setenv ("GSETTINGS_SCHEMA_DIR", ".", FALSE);
|
||||
/* Since this example is running uninstalled,
|
||||
* we have to help it find its schema. This
|
||||
* is *not* necessary in properly installed
|
||||
* application.
|
||||
*/
|
||||
g_setenv ("GSETTINGS_SCHEMA_DIR", ".", FALSE);
|
||||
|
||||
return g_application_run (G_APPLICATION (example_app_new ()), argc, argv);
|
||||
return g_application_run (G_APPLICATION (example_app_new ()), argc, argv);
|
||||
}
|
||||
|
@ -4,12 +4,14 @@
|
||||
#include "exampleappwin.h"
|
||||
#include "exampleappprefs.h"
|
||||
|
||||
struct ExampleApp {
|
||||
GtkApplication parent;
|
||||
struct _ExampleApp
|
||||
{
|
||||
GtkApplication parent;
|
||||
};
|
||||
|
||||
struct ExampleAppClass {
|
||||
GtkApplicationClass parent_class;
|
||||
struct _ExampleAppClass
|
||||
{
|
||||
GtkApplicationClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(ExampleApp, example_app, GTK_TYPE_APPLICATION);
|
||||
@ -24,12 +26,12 @@ preferences_activated (GSimpleAction *action,
|
||||
GVariant *parameter,
|
||||
gpointer app)
|
||||
{
|
||||
ExampleAppPrefs *prefs;
|
||||
GtkWindow *win;
|
||||
ExampleAppPrefs *prefs;
|
||||
GtkWindow *win;
|
||||
|
||||
win = gtk_application_get_active_window (GTK_APPLICATION (app));
|
||||
prefs = example_app_prefs_new (EXAMPLE_APP_WINDOW (win));
|
||||
gtk_window_present (GTK_WINDOW (prefs));
|
||||
win = gtk_application_get_active_window (GTK_APPLICATION (app));
|
||||
prefs = example_app_prefs_new (EXAMPLE_APP_WINDOW (win));
|
||||
gtk_window_present (GTK_WINDOW (prefs));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -40,36 +42,37 @@ quit_activated (GSimpleAction *action,
|
||||
g_application_quit (G_APPLICATION (app));
|
||||
}
|
||||
|
||||
static GActionEntry app_entries[] = {
|
||||
{ "preferences", preferences_activated, NULL, NULL, NULL },
|
||||
{ "quit", quit_activated, NULL, NULL, NULL }
|
||||
static GActionEntry app_entries[] =
|
||||
{
|
||||
{ "preferences", preferences_activated, NULL, NULL, NULL },
|
||||
{ "quit", quit_activated, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static void
|
||||
example_app_startup (GApplication *app)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu);
|
||||
g_object_unref (builder);
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu);
|
||||
g_object_unref (builder);
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_activate (GApplication *app)
|
||||
{
|
||||
ExampleAppWindow *win;
|
||||
ExampleAppWindow *win;
|
||||
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -78,35 +81,35 @@ example_app_open (GApplication *app,
|
||||
gint n_files,
|
||||
const gchar *hint)
|
||||
{
|
||||
GList *windows;
|
||||
ExampleAppWindow *win;
|
||||
int i;
|
||||
GList *windows;
|
||||
ExampleAppWindow *win;
|
||||
int i;
|
||||
|
||||
windows = gtk_application_get_windows (GTK_APPLICATION (app));
|
||||
if (windows)
|
||||
win = EXAMPLE_APP_WINDOW (windows->data);
|
||||
else
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
windows = gtk_application_get_windows (GTK_APPLICATION (app));
|
||||
if (windows)
|
||||
win = EXAMPLE_APP_WINDOW (windows->data);
|
||||
else
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
|
||||
for (i = 0; i < n_files; i++)
|
||||
example_app_window_open (win, files[i]);
|
||||
for (i = 0; i < n_files; i++)
|
||||
example_app_window_open (win, files[i]);
|
||||
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_class_init (ExampleAppClass *class)
|
||||
{
|
||||
G_APPLICATION_CLASS (class)->startup = example_app_startup;
|
||||
G_APPLICATION_CLASS (class)->activate = example_app_activate;
|
||||
G_APPLICATION_CLASS (class)->open = example_app_open;
|
||||
G_APPLICATION_CLASS (class)->startup = example_app_startup;
|
||||
G_APPLICATION_CLASS (class)->activate = example_app_activate;
|
||||
G_APPLICATION_CLASS (class)->open = example_app_open;
|
||||
}
|
||||
|
||||
ExampleApp *
|
||||
example_app_new (void)
|
||||
{
|
||||
return g_object_new (EXAMPLE_APP_TYPE,
|
||||
"application-id", "org.gtk.exampleapp",
|
||||
"flags", G_APPLICATION_HANDLES_OPEN,
|
||||
NULL);
|
||||
return g_object_new (EXAMPLE_APP_TYPE,
|
||||
"application-id", "org.gtk.exampleapp",
|
||||
"flags", G_APPLICATION_HANDLES_OPEN,
|
||||
NULL);
|
||||
}
|
||||
|
@ -8,8 +8,8 @@
|
||||
#define EXAMPLE_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_TYPE, ExampleApp))
|
||||
|
||||
|
||||
typedef struct ExampleApp ExampleApp;
|
||||
typedef struct ExampleAppClass ExampleAppClass;
|
||||
typedef struct _ExampleApp ExampleApp;
|
||||
typedef struct _ExampleAppClass ExampleAppClass;
|
||||
|
||||
|
||||
GType example_app_get_type (void);
|
||||
|
@ -4,20 +4,24 @@
|
||||
#include "exampleappwin.h"
|
||||
#include "exampleappprefs.h"
|
||||
|
||||
struct ExampleAppPrefs {
|
||||
GtkDialog parent;
|
||||
struct _ExampleAppPrefs
|
||||
{
|
||||
GtkDialog parent;
|
||||
};
|
||||
|
||||
struct ExampleAppPrefsClass {
|
||||
GtkDialogClass parent_class;
|
||||
struct _ExampleAppPrefsClass
|
||||
{
|
||||
GtkDialogClass parent_class;
|
||||
};
|
||||
|
||||
typedef struct ExampleAppPrefsPrivate ExampleAppPrefsPrivate;
|
||||
struct ExampleAppPrefsPrivate {
|
||||
GSettings *settings;
|
||||
GtkWidget *font;
|
||||
GtkWidget *transition;
|
||||
GtkWidget *close;
|
||||
typedef struct _ExampleAppPrefsPrivate ExampleAppPrefsPrivate;
|
||||
|
||||
struct _ExampleAppPrefsPrivate
|
||||
{
|
||||
GSettings *settings;
|
||||
GtkWidget *font;
|
||||
GtkWidget *transition;
|
||||
GtkWidget *close;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppPrefs, example_app_prefs, GTK_TYPE_DIALOG)
|
||||
@ -25,47 +29,47 @@ G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppPrefs, example_app_prefs, GTK_TYPE_DIALOG)
|
||||
static void
|
||||
example_app_prefs_init (ExampleAppPrefs *prefs)
|
||||
{
|
||||
ExampleAppPrefsPrivate *priv;
|
||||
ExampleAppPrefsPrivate *priv;
|
||||
|
||||
priv = example_app_prefs_get_instance_private (prefs);
|
||||
gtk_widget_init_template (GTK_WIDGET (prefs));
|
||||
priv->settings = g_settings_new ("org.gtk.exampleapp");
|
||||
priv = example_app_prefs_get_instance_private (prefs);
|
||||
gtk_widget_init_template (GTK_WIDGET (prefs));
|
||||
priv->settings = g_settings_new ("org.gtk.exampleapp");
|
||||
|
||||
g_settings_bind (priv->settings, "font",
|
||||
priv->font, "font",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
g_settings_bind (priv->settings, "transition",
|
||||
priv->transition, "active-id",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
g_signal_connect_swapped (priv->close, "clicked",
|
||||
G_CALLBACK (gtk_widget_destroy), prefs);
|
||||
g_settings_bind (priv->settings, "font",
|
||||
priv->font, "font",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
g_settings_bind (priv->settings, "transition",
|
||||
priv->transition, "active-id",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
g_signal_connect_swapped (priv->close, "clicked",
|
||||
G_CALLBACK (gtk_widget_destroy), prefs);
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_prefs_dispose (GObject *object)
|
||||
{
|
||||
ExampleAppPrefsPrivate *priv;
|
||||
ExampleAppPrefsPrivate *priv;
|
||||
|
||||
priv = example_app_prefs_get_instance_private (EXAMPLE_APP_PREFS (object));
|
||||
g_clear_object (&priv->settings);
|
||||
priv = example_app_prefs_get_instance_private (EXAMPLE_APP_PREFS (object));
|
||||
g_clear_object (&priv->settings);
|
||||
|
||||
G_OBJECT_CLASS (example_app_prefs_parent_class)->dispose (object);
|
||||
G_OBJECT_CLASS (example_app_prefs_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_prefs_class_init (ExampleAppPrefsClass *class)
|
||||
{
|
||||
G_OBJECT_CLASS (class)->dispose = example_app_prefs_dispose;
|
||||
G_OBJECT_CLASS (class)->dispose = example_app_prefs_dispose;
|
||||
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/prefs.ui");
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppPrefsPrivate, font);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppPrefsPrivate, transition);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppPrefsPrivate, close);
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/prefs.ui");
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppPrefsPrivate, font);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppPrefsPrivate, transition);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppPrefsPrivate, close);
|
||||
}
|
||||
|
||||
ExampleAppPrefs *
|
||||
example_app_prefs_new (ExampleAppWindow *win)
|
||||
{
|
||||
return g_object_new (EXAMPLE_APP_PREFS_TYPE, "transient-for", win, NULL);
|
||||
return g_object_new (EXAMPLE_APP_PREFS_TYPE, "transient-for", win, NULL);
|
||||
}
|
||||
|
@ -9,8 +9,8 @@
|
||||
#define EXAMPLE_APP_PREFS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_PREFS_TYPE, ExampleAppPrefs))
|
||||
|
||||
|
||||
typedef struct ExampleAppPrefs ExampleAppPrefs;
|
||||
typedef struct ExampleAppPrefsClass ExampleAppPrefsClass;
|
||||
typedef struct _ExampleAppPrefs ExampleAppPrefs;
|
||||
typedef struct _ExampleAppPrefsClass ExampleAppPrefsClass;
|
||||
|
||||
|
||||
GType example_app_prefs_get_type (void);
|
||||
|
@ -2,24 +2,27 @@
|
||||
#include "exampleappwin.h"
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
struct ExampleAppWindow {
|
||||
GtkApplicationWindow parent;
|
||||
struct _ExampleAppWindow
|
||||
{
|
||||
GtkApplicationWindow parent;
|
||||
};
|
||||
|
||||
struct ExampleAppWindowClass {
|
||||
GtkApplicationWindowClass parent_class;
|
||||
struct _ExampleAppWindowClass
|
||||
{
|
||||
GtkApplicationWindowClass parent_class;
|
||||
};
|
||||
|
||||
typedef struct ExampleAppWindowPrivate ExampleAppWindowPrivate;
|
||||
typedef struct _ExampleAppWindowPrivate ExampleAppWindowPrivate;
|
||||
|
||||
struct ExampleAppWindowPrivate {
|
||||
GSettings *settings;
|
||||
GtkWidget *stack;
|
||||
GtkWidget *search;
|
||||
GtkWidget *searchbar;
|
||||
GtkWidget *searchentry;
|
||||
gulong text_changed_handler;
|
||||
gulong tab_changed_handler;
|
||||
struct _ExampleAppWindowPrivate
|
||||
{
|
||||
GSettings *settings;
|
||||
GtkWidget *stack;
|
||||
GtkWidget *search;
|
||||
GtkWidget *searchbar;
|
||||
GtkWidget *searchentry;
|
||||
gulong text_changed_handler;
|
||||
gulong tab_changed_handler;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW);
|
||||
@ -28,32 +31,33 @@ static void
|
||||
search_text_changed (GtkEntry *entry,
|
||||
ExampleAppWindow *win)
|
||||
{
|
||||
ExampleAppWindowPrivate *priv;
|
||||
const gchar *text;
|
||||
GtkWidget *tab;
|
||||
GtkWidget *view;
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextIter start, match_start, match_end;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
const gchar *text;
|
||||
GtkWidget *tab;
|
||||
GtkWidget *view;
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextIter start, match_start, match_end;
|
||||
|
||||
text = gtk_entry_get_text (entry);
|
||||
text = gtk_entry_get_text (entry);
|
||||
|
||||
if (text[0] == '\0')
|
||||
return;
|
||||
if (text[0] == '\0')
|
||||
return;
|
||||
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
|
||||
tab = gtk_stack_get_visible_child (GTK_STACK (priv->stack));
|
||||
view = gtk_bin_get_child (GTK_BIN (tab));
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
tab = gtk_stack_get_visible_child (GTK_STACK (priv->stack));
|
||||
view = gtk_bin_get_child (GTK_BIN (tab));
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
|
||||
/* Very simple-minded search implementation */
|
||||
gtk_text_buffer_get_start_iter (buffer, &start);
|
||||
if (gtk_text_iter_forward_search (&start, text, GTK_TEXT_SEARCH_CASE_INSENSITIVE,
|
||||
&match_start, &match_end, NULL)) {
|
||||
gtk_text_buffer_select_range (buffer, &match_start, &match_end);
|
||||
gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (view), &match_start,
|
||||
0.0, FALSE, 0.0, 0.0);
|
||||
}
|
||||
/* Very simple-minded search implementation */
|
||||
gtk_text_buffer_get_start_iter (buffer, &start);
|
||||
if (gtk_text_iter_forward_search (&start, text, GTK_TEXT_SEARCH_CASE_INSENSITIVE,
|
||||
&match_start, &match_end, NULL))
|
||||
{
|
||||
gtk_text_buffer_select_range (buffer, &match_start, &match_end);
|
||||
gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (view), &match_start,
|
||||
0.0, FALSE, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -61,120 +65,125 @@ visible_child_changed (GObject *stack,
|
||||
GParamSpec *pspec,
|
||||
ExampleAppWindow *win)
|
||||
{
|
||||
ExampleAppWindowPrivate *priv;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->searchbar), FALSE);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->searchbar), FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_window_init (ExampleAppWindow *win)
|
||||
{
|
||||
ExampleAppWindowPrivate *priv;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
gtk_widget_init_template (GTK_WIDGET (win));
|
||||
priv->settings = g_settings_new ("org.gtk.exampleapp");
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
gtk_widget_init_template (GTK_WIDGET (win));
|
||||
priv->settings = g_settings_new ("org.gtk.exampleapp");
|
||||
|
||||
g_settings_bind (priv->settings, "transition",
|
||||
priv->stack, "transition-type",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
g_settings_bind (priv->settings, "transition",
|
||||
priv->stack, "transition-type",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
|
||||
g_object_bind_property (priv->search, "active",
|
||||
priv->searchbar, "search-mode-enabled",
|
||||
G_BINDING_BIDIRECTIONAL);
|
||||
g_object_bind_property (priv->search, "active",
|
||||
priv->searchbar, "search-mode-enabled",
|
||||
G_BINDING_BIDIRECTIONAL);
|
||||
|
||||
priv->text_changed_handler = g_signal_connect (priv->searchentry, "changed",
|
||||
G_CALLBACK (search_text_changed), win);
|
||||
priv->tab_changed_handler = g_signal_connect (priv->stack, "notify::visible-child",
|
||||
G_CALLBACK (visible_child_changed), win);
|
||||
priv->text_changed_handler = g_signal_connect (priv->searchentry, "changed",
|
||||
G_CALLBACK (search_text_changed), win);
|
||||
priv->tab_changed_handler = g_signal_connect (priv->stack, "notify::visible-child",
|
||||
G_CALLBACK (visible_child_changed), win);
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_window_dispose (GObject *object)
|
||||
{
|
||||
ExampleAppWindow *win;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
ExampleAppWindow *win;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
|
||||
win = EXAMPLE_APP_WINDOW (object);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
win = EXAMPLE_APP_WINDOW (object);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
|
||||
if (priv->text_changed_handler != 0) {
|
||||
g_signal_handler_disconnect (priv->searchentry, priv->text_changed_handler);
|
||||
priv->text_changed_handler = 0;
|
||||
}
|
||||
if (priv->text_changed_handler != 0)
|
||||
{
|
||||
g_signal_handler_disconnect (priv->searchentry, priv->text_changed_handler);
|
||||
priv->text_changed_handler = 0;
|
||||
}
|
||||
|
||||
if (priv->tab_changed_handler != 0) {
|
||||
g_signal_handler_disconnect (priv->stack, priv->tab_changed_handler);
|
||||
priv->tab_changed_handler = 0;
|
||||
}
|
||||
if (priv->tab_changed_handler != 0)
|
||||
{
|
||||
g_signal_handler_disconnect (priv->stack, priv->tab_changed_handler);
|
||||
priv->tab_changed_handler = 0;
|
||||
}
|
||||
|
||||
g_clear_object (&priv->settings);
|
||||
g_clear_object (&priv->settings);
|
||||
|
||||
G_OBJECT_CLASS (example_app_window_parent_class)->dispose (object);
|
||||
G_OBJECT_CLASS (example_app_window_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_window_class_init (ExampleAppWindowClass *class)
|
||||
{
|
||||
G_OBJECT_CLASS (class)->dispose = example_app_window_dispose;
|
||||
G_OBJECT_CLASS (class)->dispose = example_app_window_dispose;
|
||||
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/window.ui");
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, stack);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, search);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, searchbar);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, searchentry);
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/window.ui");
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, stack);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, search);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, searchbar);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, searchentry);
|
||||
}
|
||||
|
||||
ExampleAppWindow *
|
||||
example_app_window_new (ExampleApp *app)
|
||||
{
|
||||
return g_object_new (EXAMPLE_APP_WINDOW_TYPE, "application", app, NULL);
|
||||
return g_object_new (EXAMPLE_APP_WINDOW_TYPE, "application", app, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
example_app_window_open (ExampleAppWindow *win,
|
||||
GFile *file)
|
||||
{
|
||||
ExampleAppWindowPrivate *priv;
|
||||
gchar *basename;
|
||||
GtkWidget *scrolled, *view;
|
||||
gchar *contents;
|
||||
gsize length;
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextTag *tag;
|
||||
GtkTextIter start_iter, end_iter;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
gchar *basename;
|
||||
GtkWidget *scrolled, *view;
|
||||
gchar *contents;
|
||||
gsize length;
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextTag *tag;
|
||||
GtkTextIter start_iter, end_iter;
|
||||
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
basename = g_file_get_basename (file);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
basename = g_file_get_basename (file);
|
||||
|
||||
scrolled = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_widget_show (scrolled);
|
||||
gtk_widget_set_hexpand (scrolled, TRUE);
|
||||
gtk_widget_set_vexpand (scrolled, TRUE);
|
||||
view = gtk_text_view_new ();
|
||||
gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_widget_show (view);
|
||||
gtk_container_add (GTK_CONTAINER (scrolled), view);
|
||||
gtk_stack_add_titled (GTK_STACK (priv->stack), scrolled, basename, basename);
|
||||
scrolled = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_widget_show (scrolled);
|
||||
gtk_widget_set_hexpand (scrolled, TRUE);
|
||||
gtk_widget_set_vexpand (scrolled, TRUE);
|
||||
view = gtk_text_view_new ();
|
||||
gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_widget_show (view);
|
||||
gtk_container_add (GTK_CONTAINER (scrolled), view);
|
||||
gtk_stack_add_titled (GTK_STACK (priv->stack), scrolled, basename, basename);
|
||||
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
|
||||
if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL)) {
|
||||
gtk_text_buffer_set_text (buffer, contents, length);
|
||||
g_free (contents);
|
||||
}
|
||||
if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL))
|
||||
{
|
||||
gtk_text_buffer_set_text (buffer, contents, length);
|
||||
g_free (contents);
|
||||
}
|
||||
|
||||
tag = gtk_text_buffer_create_tag (buffer, NULL, NULL);
|
||||
g_settings_bind (priv->settings, "font", tag, "font", G_SETTINGS_BIND_DEFAULT);
|
||||
tag = gtk_text_buffer_create_tag (buffer, NULL, NULL);
|
||||
g_settings_bind (priv->settings, "font",
|
||||
tag, "font",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
|
||||
gtk_text_buffer_get_start_iter (buffer, &start_iter);
|
||||
gtk_text_buffer_get_end_iter (buffer, &end_iter);
|
||||
gtk_text_buffer_apply_tag (buffer, tag, &start_iter, &end_iter);
|
||||
gtk_text_buffer_get_start_iter (buffer, &start_iter);
|
||||
gtk_text_buffer_get_end_iter (buffer, &end_iter);
|
||||
gtk_text_buffer_apply_tag (buffer, tag, &start_iter, &end_iter);
|
||||
|
||||
g_free (basename);
|
||||
g_free (basename);
|
||||
|
||||
gtk_widget_set_sensitive (priv->search, TRUE);
|
||||
gtk_widget_set_sensitive (priv->search, TRUE);
|
||||
}
|
||||
|
@ -9,8 +9,8 @@
|
||||
#define EXAMPLE_APP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_WINDOW_TYPE, ExampleAppWindow))
|
||||
|
||||
|
||||
typedef struct ExampleAppWindow ExampleAppWindow;
|
||||
typedef struct ExampleAppWindowClass ExampleAppWindowClass;
|
||||
typedef struct _ExampleAppWindow ExampleAppWindow;
|
||||
typedef struct _ExampleAppWindowClass ExampleAppWindowClass;
|
||||
|
||||
|
||||
GType example_app_window_get_type (void);
|
||||
|
@ -4,12 +4,12 @@
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
/* Since this example is running uninstalled,
|
||||
* we have to help it find its schema. This
|
||||
* is *not* necessary in properly installed
|
||||
* application.
|
||||
*/
|
||||
g_setenv ("GSETTINGS_SCHEMA_DIR", ".", FALSE);
|
||||
/* Since this example is running uninstalled,
|
||||
* we have to help it find its schema. This
|
||||
* is *not* necessary in properly installed
|
||||
* application.
|
||||
*/
|
||||
g_setenv ("GSETTINGS_SCHEMA_DIR", ".", FALSE);
|
||||
|
||||
return g_application_run (G_APPLICATION (example_app_new ()), argc, argv);
|
||||
return g_application_run (G_APPLICATION (example_app_new ()), argc, argv);
|
||||
}
|
||||
|
@ -4,12 +4,14 @@
|
||||
#include "exampleappwin.h"
|
||||
#include "exampleappprefs.h"
|
||||
|
||||
struct ExampleApp {
|
||||
GtkApplication parent;
|
||||
struct _ExampleApp
|
||||
{
|
||||
GtkApplication parent;
|
||||
};
|
||||
|
||||
struct ExampleAppClass {
|
||||
GtkApplicationClass parent_class;
|
||||
struct _ExampleAppClass
|
||||
{
|
||||
GtkApplicationClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(ExampleApp, example_app, GTK_TYPE_APPLICATION);
|
||||
@ -24,12 +26,12 @@ preferences_activated (GSimpleAction *action,
|
||||
GVariant *parameter,
|
||||
gpointer app)
|
||||
{
|
||||
ExampleAppPrefs *prefs;
|
||||
GtkWindow *win;
|
||||
ExampleAppPrefs *prefs;
|
||||
GtkWindow *win;
|
||||
|
||||
win = gtk_application_get_active_window (GTK_APPLICATION (app));
|
||||
prefs = example_app_prefs_new (EXAMPLE_APP_WINDOW (win));
|
||||
gtk_window_present (GTK_WINDOW (prefs));
|
||||
win = gtk_application_get_active_window (GTK_APPLICATION (app));
|
||||
prefs = example_app_prefs_new (EXAMPLE_APP_WINDOW (win));
|
||||
gtk_window_present (GTK_WINDOW (prefs));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -40,36 +42,37 @@ quit_activated (GSimpleAction *action,
|
||||
g_application_quit (G_APPLICATION (app));
|
||||
}
|
||||
|
||||
static GActionEntry app_entries[] = {
|
||||
{ "preferences", preferences_activated, NULL, NULL, NULL },
|
||||
{ "quit", quit_activated, NULL, NULL, NULL }
|
||||
static GActionEntry app_entries[] =
|
||||
{
|
||||
{ "preferences", preferences_activated, NULL, NULL, NULL },
|
||||
{ "quit", quit_activated, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static void
|
||||
example_app_startup (GApplication *app)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *app_menu;
|
||||
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
|
||||
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
||||
app_entries, G_N_ELEMENTS (app_entries),
|
||||
app);
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu);
|
||||
g_object_unref (builder);
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
|
||||
app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
|
||||
gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu);
|
||||
g_object_unref (builder);
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_activate (GApplication *app)
|
||||
{
|
||||
ExampleAppWindow *win;
|
||||
ExampleAppWindow *win;
|
||||
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -78,35 +81,35 @@ example_app_open (GApplication *app,
|
||||
gint n_files,
|
||||
const gchar *hint)
|
||||
{
|
||||
GList *windows;
|
||||
ExampleAppWindow *win;
|
||||
int i;
|
||||
GList *windows;
|
||||
ExampleAppWindow *win;
|
||||
int i;
|
||||
|
||||
windows = gtk_application_get_windows (GTK_APPLICATION (app));
|
||||
if (windows)
|
||||
win = EXAMPLE_APP_WINDOW (windows->data);
|
||||
else
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
windows = gtk_application_get_windows (GTK_APPLICATION (app));
|
||||
if (windows)
|
||||
win = EXAMPLE_APP_WINDOW (windows->data);
|
||||
else
|
||||
win = example_app_window_new (EXAMPLE_APP (app));
|
||||
|
||||
for (i = 0; i < n_files; i++)
|
||||
example_app_window_open (win, files[i]);
|
||||
for (i = 0; i < n_files; i++)
|
||||
example_app_window_open (win, files[i]);
|
||||
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_class_init (ExampleAppClass *class)
|
||||
{
|
||||
G_APPLICATION_CLASS (class)->startup = example_app_startup;
|
||||
G_APPLICATION_CLASS (class)->activate = example_app_activate;
|
||||
G_APPLICATION_CLASS (class)->open = example_app_open;
|
||||
G_APPLICATION_CLASS (class)->startup = example_app_startup;
|
||||
G_APPLICATION_CLASS (class)->activate = example_app_activate;
|
||||
G_APPLICATION_CLASS (class)->open = example_app_open;
|
||||
}
|
||||
|
||||
ExampleApp *
|
||||
example_app_new (void)
|
||||
{
|
||||
return g_object_new (EXAMPLE_APP_TYPE,
|
||||
"application-id", "org.gtk.exampleapp",
|
||||
"flags", G_APPLICATION_HANDLES_OPEN,
|
||||
NULL);
|
||||
return g_object_new (EXAMPLE_APP_TYPE,
|
||||
"application-id", "org.gtk.exampleapp",
|
||||
"flags", G_APPLICATION_HANDLES_OPEN,
|
||||
NULL);
|
||||
}
|
||||
|
@ -8,8 +8,8 @@
|
||||
#define EXAMPLE_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_TYPE, ExampleApp))
|
||||
|
||||
|
||||
typedef struct ExampleApp ExampleApp;
|
||||
typedef struct ExampleAppClass ExampleAppClass;
|
||||
typedef struct _ExampleApp ExampleApp;
|
||||
typedef struct _ExampleAppClass ExampleAppClass;
|
||||
|
||||
|
||||
GType example_app_get_type (void);
|
||||
|
@ -4,20 +4,24 @@
|
||||
#include "exampleappwin.h"
|
||||
#include "exampleappprefs.h"
|
||||
|
||||
struct ExampleAppPrefs {
|
||||
GtkDialog parent;
|
||||
struct _ExampleAppPrefs
|
||||
{
|
||||
GtkDialog parent;
|
||||
};
|
||||
|
||||
struct ExampleAppPrefsClass {
|
||||
GtkDialogClass parent_class;
|
||||
struct _ExampleAppPrefsClass
|
||||
{
|
||||
GtkDialogClass parent_class;
|
||||
};
|
||||
|
||||
typedef struct ExampleAppPrefsPrivate ExampleAppPrefsPrivate;
|
||||
struct ExampleAppPrefsPrivate {
|
||||
GSettings *settings;
|
||||
GtkWidget *font;
|
||||
GtkWidget *transition;
|
||||
GtkWidget *close;
|
||||
typedef struct _ExampleAppPrefsPrivate ExampleAppPrefsPrivate;
|
||||
|
||||
struct _ExampleAppPrefsPrivate
|
||||
{
|
||||
GSettings *settings;
|
||||
GtkWidget *font;
|
||||
GtkWidget *transition;
|
||||
GtkWidget *close;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppPrefs, example_app_prefs, GTK_TYPE_DIALOG)
|
||||
@ -25,47 +29,47 @@ G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppPrefs, example_app_prefs, GTK_TYPE_DIALOG)
|
||||
static void
|
||||
example_app_prefs_init (ExampleAppPrefs *prefs)
|
||||
{
|
||||
ExampleAppPrefsPrivate *priv;
|
||||
ExampleAppPrefsPrivate *priv;
|
||||
|
||||
priv = example_app_prefs_get_instance_private (prefs);
|
||||
gtk_widget_init_template (GTK_WIDGET (prefs));
|
||||
priv->settings = g_settings_new ("org.gtk.exampleapp");
|
||||
priv = example_app_prefs_get_instance_private (prefs);
|
||||
gtk_widget_init_template (GTK_WIDGET (prefs));
|
||||
priv->settings = g_settings_new ("org.gtk.exampleapp");
|
||||
|
||||
g_settings_bind (priv->settings, "font",
|
||||
priv->font, "font",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
g_settings_bind (priv->settings, "transition",
|
||||
priv->transition, "active-id",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
g_signal_connect_swapped (priv->close, "clicked",
|
||||
G_CALLBACK (gtk_widget_destroy), prefs);
|
||||
g_settings_bind (priv->settings, "font",
|
||||
priv->font, "font",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
g_settings_bind (priv->settings, "transition",
|
||||
priv->transition, "active-id",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
g_signal_connect_swapped (priv->close, "clicked",
|
||||
G_CALLBACK (gtk_widget_destroy), prefs);
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_prefs_dispose (GObject *object)
|
||||
{
|
||||
ExampleAppPrefsPrivate *priv;
|
||||
ExampleAppPrefsPrivate *priv;
|
||||
|
||||
priv = example_app_prefs_get_instance_private (EXAMPLE_APP_PREFS (object));
|
||||
g_clear_object (&priv->settings);
|
||||
priv = example_app_prefs_get_instance_private (EXAMPLE_APP_PREFS (object));
|
||||
g_clear_object (&priv->settings);
|
||||
|
||||
G_OBJECT_CLASS (example_app_prefs_parent_class)->dispose (object);
|
||||
G_OBJECT_CLASS (example_app_prefs_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_prefs_class_init (ExampleAppPrefsClass *class)
|
||||
{
|
||||
G_OBJECT_CLASS (class)->dispose = example_app_prefs_dispose;
|
||||
G_OBJECT_CLASS (class)->dispose = example_app_prefs_dispose;
|
||||
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/prefs.ui");
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppPrefsPrivate, font);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppPrefsPrivate, transition);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppPrefsPrivate, close);
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/prefs.ui");
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppPrefsPrivate, font);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppPrefsPrivate, transition);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppPrefsPrivate, close);
|
||||
}
|
||||
|
||||
ExampleAppPrefs *
|
||||
example_app_prefs_new (ExampleAppWindow *win)
|
||||
{
|
||||
return g_object_new (EXAMPLE_APP_PREFS_TYPE, "transient-for", win, NULL);
|
||||
return g_object_new (EXAMPLE_APP_PREFS_TYPE, "transient-for", win, NULL);
|
||||
}
|
||||
|
@ -9,8 +9,8 @@
|
||||
#define EXAMPLE_APP_PREFS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_PREFS_TYPE, ExampleAppPrefs))
|
||||
|
||||
|
||||
typedef struct ExampleAppPrefs ExampleAppPrefs;
|
||||
typedef struct ExampleAppPrefsClass ExampleAppPrefsClass;
|
||||
typedef struct _ExampleAppPrefs ExampleAppPrefs;
|
||||
typedef struct _ExampleAppPrefsClass ExampleAppPrefsClass;
|
||||
|
||||
|
||||
GType example_app_prefs_get_type (void);
|
||||
|
@ -2,28 +2,31 @@
|
||||
#include "exampleappwin.h"
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
struct ExampleAppWindow {
|
||||
GtkApplicationWindow parent;
|
||||
struct _ExampleAppWindow
|
||||
{
|
||||
GtkApplicationWindow parent;
|
||||
};
|
||||
|
||||
struct ExampleAppWindowClass {
|
||||
GtkApplicationWindowClass parent_class;
|
||||
struct _ExampleAppWindowClass
|
||||
{
|
||||
GtkApplicationWindowClass parent_class;
|
||||
};
|
||||
|
||||
typedef struct ExampleAppWindowPrivate ExampleAppWindowPrivate;
|
||||
typedef struct _ExampleAppWindowPrivate ExampleAppWindowPrivate;
|
||||
|
||||
struct ExampleAppWindowPrivate {
|
||||
GSettings *settings;
|
||||
GtkWidget *stack;
|
||||
GtkWidget *search;
|
||||
GtkWidget *searchbar;
|
||||
GtkWidget *searchentry;
|
||||
GtkWidget *gears;
|
||||
GtkWidget *sidebar;
|
||||
GtkWidget *words;
|
||||
gulong text_changed_handler;
|
||||
gulong tab_changed_handler;
|
||||
gulong words_changed_handler;
|
||||
struct _ExampleAppWindowPrivate
|
||||
{
|
||||
GSettings *settings;
|
||||
GtkWidget *stack;
|
||||
GtkWidget *search;
|
||||
GtkWidget *searchbar;
|
||||
GtkWidget *searchentry;
|
||||
GtkWidget *gears;
|
||||
GtkWidget *sidebar;
|
||||
GtkWidget *words;
|
||||
gulong text_changed_handler;
|
||||
gulong tab_changed_handler;
|
||||
gulong words_changed_handler;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW);
|
||||
@ -32,99 +35,102 @@ static void
|
||||
search_text_changed (GtkEntry *entry,
|
||||
ExampleAppWindow *win)
|
||||
{
|
||||
ExampleAppWindowPrivate *priv;
|
||||
const gchar *text;
|
||||
GtkWidget *tab;
|
||||
GtkWidget *view;
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextIter start, match_start, match_end;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
const gchar *text;
|
||||
GtkWidget *tab;
|
||||
GtkWidget *view;
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextIter start, match_start, match_end;
|
||||
|
||||
text = gtk_entry_get_text (entry);
|
||||
text = gtk_entry_get_text (entry);
|
||||
|
||||
if (text[0] == '\0')
|
||||
return;
|
||||
if (text[0] == '\0')
|
||||
return;
|
||||
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
|
||||
tab = gtk_stack_get_visible_child (GTK_STACK (priv->stack));
|
||||
view = gtk_bin_get_child (GTK_BIN (tab));
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
tab = gtk_stack_get_visible_child (GTK_STACK (priv->stack));
|
||||
view = gtk_bin_get_child (GTK_BIN (tab));
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
|
||||
/* Very simple-minded search implementation */
|
||||
gtk_text_buffer_get_start_iter (buffer, &start);
|
||||
if (gtk_text_iter_forward_search (&start, text, GTK_TEXT_SEARCH_CASE_INSENSITIVE,
|
||||
&match_start, &match_end, NULL)) {
|
||||
gtk_text_buffer_select_range (buffer, &match_start, &match_end);
|
||||
gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (view), &match_start,
|
||||
0.0, FALSE, 0.0, 0.0);
|
||||
}
|
||||
/* Very simple-minded search implementation */
|
||||
gtk_text_buffer_get_start_iter (buffer, &start);
|
||||
if (gtk_text_iter_forward_search (&start, text, GTK_TEXT_SEARCH_CASE_INSENSITIVE,
|
||||
&match_start, &match_end, NULL))
|
||||
{
|
||||
gtk_text_buffer_select_range (buffer, &match_start, &match_end);
|
||||
gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (view), &match_start,
|
||||
0.0, FALSE, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
find_word (GtkButton *button,
|
||||
ExampleAppWindow *win)
|
||||
{
|
||||
ExampleAppWindowPrivate *priv;
|
||||
const gchar *word;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
const gchar *word;
|
||||
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
|
||||
word = gtk_button_get_label (button);
|
||||
gtk_entry_set_text (GTK_ENTRY (priv->searchentry), word);
|
||||
word = gtk_button_get_label (button);
|
||||
gtk_entry_set_text (GTK_ENTRY (priv->searchentry), word);
|
||||
}
|
||||
|
||||
static void
|
||||
update_words (ExampleAppWindow *win)
|
||||
{
|
||||
ExampleAppWindowPrivate *priv;
|
||||
GHashTable *strings;
|
||||
GHashTableIter iter;
|
||||
GtkWidget *tab, *view, *row;
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextIter start, end;
|
||||
GList *children, *l;
|
||||
gchar *word, *key;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
GHashTable *strings;
|
||||
GHashTableIter iter;
|
||||
GtkWidget *tab, *view, *row;
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextIter start, end;
|
||||
GList *children, *l;
|
||||
gchar *word, *key;
|
||||
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
|
||||
tab = gtk_stack_get_visible_child (GTK_STACK (priv->stack));
|
||||
view = gtk_bin_get_child (GTK_BIN (tab));
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
tab = gtk_stack_get_visible_child (GTK_STACK (priv->stack));
|
||||
view = gtk_bin_get_child (GTK_BIN (tab));
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
|
||||
strings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||
strings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||
|
||||
gtk_text_buffer_get_start_iter (buffer, &start);
|
||||
while (!gtk_text_iter_is_end (&start)) {
|
||||
while (!gtk_text_iter_starts_word (&start)) {
|
||||
if (!gtk_text_iter_forward_char (&start))
|
||||
goto done;
|
||||
}
|
||||
end = start;
|
||||
if (!gtk_text_iter_forward_word_end (&end))
|
||||
goto done;
|
||||
word = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
|
||||
g_hash_table_add (strings, g_utf8_strdown (word, -1));
|
||||
g_free (word);
|
||||
start = end;
|
||||
gtk_text_buffer_get_start_iter (buffer, &start);
|
||||
while (!gtk_text_iter_is_end (&start))
|
||||
{
|
||||
while (!gtk_text_iter_starts_word (&start))
|
||||
{
|
||||
if (!gtk_text_iter_forward_char (&start))
|
||||
goto done;
|
||||
}
|
||||
end = start;
|
||||
if (!gtk_text_iter_forward_word_end (&end))
|
||||
goto done;
|
||||
word = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
|
||||
g_hash_table_add (strings, g_utf8_strdown (word, -1));
|
||||
g_free (word);
|
||||
start = end;
|
||||
}
|
||||
|
||||
done:
|
||||
children = gtk_container_get_children (GTK_CONTAINER (priv->words));
|
||||
for (l = children; l; l = l->next) {
|
||||
gtk_container_remove (GTK_CONTAINER (priv->words), GTK_WIDGET (l->data));
|
||||
}
|
||||
g_list_free (children);
|
||||
children = gtk_container_get_children (GTK_CONTAINER (priv->words));
|
||||
for (l = children; l; l = l->next)
|
||||
gtk_container_remove (GTK_CONTAINER (priv->words), GTK_WIDGET (l->data));
|
||||
g_list_free (children);
|
||||
|
||||
g_hash_table_iter_init (&iter, strings);
|
||||
while (g_hash_table_iter_next (&iter, (gpointer *)&key, NULL)) {
|
||||
row = gtk_button_new_with_label (key);
|
||||
g_signal_connect (row, "clicked",
|
||||
G_CALLBACK (find_word), win);
|
||||
gtk_widget_show (row);
|
||||
gtk_container_add (GTK_CONTAINER (priv->words), row);
|
||||
}
|
||||
g_hash_table_iter_init (&iter, strings);
|
||||
while (g_hash_table_iter_next (&iter, (gpointer *)&key, NULL))
|
||||
{
|
||||
row = gtk_button_new_with_label (key);
|
||||
g_signal_connect (row, "clicked",
|
||||
G_CALLBACK (find_word), win);
|
||||
gtk_widget_show (row);
|
||||
gtk_container_add (GTK_CONTAINER (priv->words), row);
|
||||
}
|
||||
|
||||
g_hash_table_unref (strings);
|
||||
g_hash_table_unref (strings);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -132,11 +138,11 @@ visible_child_changed (GObject *stack,
|
||||
GParamSpec *pspec,
|
||||
ExampleAppWindow *win)
|
||||
{
|
||||
ExampleAppWindowPrivate *priv;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->searchbar), FALSE);
|
||||
update_words (win);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->searchbar), FALSE);
|
||||
update_words (win);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -144,145 +150,151 @@ words_changed (GObject *sidebar,
|
||||
GParamSpec *pspec,
|
||||
ExampleAppWindow *win)
|
||||
{
|
||||
update_words (win);
|
||||
update_words (win);
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_window_init (ExampleAppWindow *win)
|
||||
{
|
||||
ExampleAppWindowPrivate *priv;
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *menu;
|
||||
GAction *action;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
GtkBuilder *builder;
|
||||
GMenuModel *menu;
|
||||
GAction *action;
|
||||
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
gtk_widget_init_template (GTK_WIDGET (win));
|
||||
priv->settings = g_settings_new ("org.gtk.exampleapp");
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
gtk_widget_init_template (GTK_WIDGET (win));
|
||||
priv->settings = g_settings_new ("org.gtk.exampleapp");
|
||||
|
||||
g_settings_bind (priv->settings, "transition",
|
||||
priv->stack, "transition-type",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
g_settings_bind (priv->settings, "transition",
|
||||
priv->stack, "transition-type",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
|
||||
g_settings_bind (priv->settings, "show-words",
|
||||
priv->sidebar, "reveal-child",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
g_settings_bind (priv->settings, "show-words",
|
||||
priv->sidebar, "reveal-child",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
|
||||
g_object_bind_property (priv->search, "active",
|
||||
priv->searchbar, "search-mode-enabled",
|
||||
G_BINDING_BIDIRECTIONAL);
|
||||
g_object_bind_property (priv->search, "active",
|
||||
priv->searchbar, "search-mode-enabled",
|
||||
G_BINDING_BIDIRECTIONAL);
|
||||
|
||||
priv->text_changed_handler = g_signal_connect (priv->searchentry, "changed",
|
||||
G_CALLBACK (search_text_changed), win);
|
||||
priv->tab_changed_handler = g_signal_connect (priv->stack, "notify::visible-child",
|
||||
G_CALLBACK (visible_child_changed), win);
|
||||
priv->words_changed_handler = g_signal_connect (priv->sidebar, "notify::reveal-child",
|
||||
G_CALLBACK (words_changed), win);
|
||||
priv->text_changed_handler = g_signal_connect (priv->searchentry, "changed",
|
||||
G_CALLBACK (search_text_changed), win);
|
||||
priv->tab_changed_handler = g_signal_connect (priv->stack, "notify::visible-child",
|
||||
G_CALLBACK (visible_child_changed), win);
|
||||
priv->words_changed_handler = g_signal_connect (priv->sidebar, "notify::reveal-child",
|
||||
G_CALLBACK (words_changed), win);
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/gears-menu.ui");
|
||||
menu = G_MENU_MODEL (gtk_builder_get_object (builder, "menu"));
|
||||
gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (priv->gears), menu);
|
||||
g_object_unref (builder);
|
||||
builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/gears-menu.ui");
|
||||
menu = G_MENU_MODEL (gtk_builder_get_object (builder, "menu"));
|
||||
gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (priv->gears), menu);
|
||||
g_object_unref (builder);
|
||||
|
||||
action = g_settings_create_action (priv->settings, "show-words");
|
||||
g_action_map_add_action (G_ACTION_MAP (win), action);
|
||||
g_object_unref (action);
|
||||
action = g_settings_create_action (priv->settings, "show-words");
|
||||
g_action_map_add_action (G_ACTION_MAP (win), action);
|
||||
g_object_unref (action);
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_window_dispose (GObject *object)
|
||||
{
|
||||
ExampleAppWindow *win;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
ExampleAppWindow *win;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
|
||||
win = EXAMPLE_APP_WINDOW (object);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
win = EXAMPLE_APP_WINDOW (object);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
|
||||
if (priv->text_changed_handler != 0) {
|
||||
g_signal_handler_disconnect (priv->searchentry, priv->text_changed_handler);
|
||||
priv->text_changed_handler = 0;
|
||||
}
|
||||
if (priv->text_changed_handler != 0)
|
||||
{
|
||||
g_signal_handler_disconnect (priv->searchentry, priv->text_changed_handler);
|
||||
priv->text_changed_handler = 0;
|
||||
}
|
||||
|
||||
if (priv->tab_changed_handler != 0) {
|
||||
g_signal_handler_disconnect (priv->stack, priv->tab_changed_handler);
|
||||
priv->tab_changed_handler = 0;
|
||||
}
|
||||
if (priv->tab_changed_handler != 0)
|
||||
{
|
||||
g_signal_handler_disconnect (priv->stack, priv->tab_changed_handler);
|
||||
priv->tab_changed_handler = 0;
|
||||
}
|
||||
|
||||
if (priv->words_changed_handler != 0) {
|
||||
g_signal_handler_disconnect (priv->sidebar, priv->words_changed_handler);
|
||||
priv->words_changed_handler = 0;
|
||||
}
|
||||
if (priv->words_changed_handler != 0)
|
||||
{
|
||||
g_signal_handler_disconnect (priv->sidebar, priv->words_changed_handler);
|
||||
priv->words_changed_handler = 0;
|
||||
}
|
||||
|
||||
g_clear_object (&priv->settings);
|
||||
g_clear_object (&priv->settings);
|
||||
|
||||
G_OBJECT_CLASS (example_app_window_parent_class)->dispose (object);
|
||||
G_OBJECT_CLASS (example_app_window_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
example_app_window_class_init (ExampleAppWindowClass *class)
|
||||
{
|
||||
G_OBJECT_CLASS (class)->dispose = example_app_window_dispose;
|
||||
G_OBJECT_CLASS (class)->dispose = example_app_window_dispose;
|
||||
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/window.ui");
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, stack);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, search);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, searchbar);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, searchentry);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, gears);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, words);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, sidebar);
|
||||
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
|
||||
"/org/gtk/exampleapp/window.ui");
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, stack);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, search);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, searchbar);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, searchentry);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, gears);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, words);
|
||||
gtk_widget_class_bind_child (GTK_WIDGET_CLASS (class), ExampleAppWindowPrivate, sidebar);
|
||||
}
|
||||
|
||||
ExampleAppWindow *
|
||||
example_app_window_new (ExampleApp *app)
|
||||
{
|
||||
return g_object_new (EXAMPLE_APP_WINDOW_TYPE, "application", app, NULL);
|
||||
return g_object_new (EXAMPLE_APP_WINDOW_TYPE, "application", app, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
example_app_window_open (ExampleAppWindow *win,
|
||||
GFile *file)
|
||||
{
|
||||
ExampleAppWindowPrivate *priv;
|
||||
gchar *basename;
|
||||
GtkWidget *scrolled, *view;
|
||||
gchar *contents;
|
||||
gsize length;
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextTag *tag;
|
||||
GtkTextIter start_iter, end_iter;
|
||||
ExampleAppWindowPrivate *priv;
|
||||
gchar *basename;
|
||||
GtkWidget *scrolled, *view;
|
||||
gchar *contents;
|
||||
gsize length;
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextTag *tag;
|
||||
GtkTextIter start_iter, end_iter;
|
||||
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
basename = g_file_get_basename (file);
|
||||
priv = example_app_window_get_instance_private (win);
|
||||
basename = g_file_get_basename (file);
|
||||
|
||||
scrolled = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_widget_show (scrolled);
|
||||
gtk_widget_set_hexpand (scrolled, TRUE);
|
||||
gtk_widget_set_vexpand (scrolled, TRUE);
|
||||
view = gtk_text_view_new ();
|
||||
gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_widget_show (view);
|
||||
gtk_container_add (GTK_CONTAINER (scrolled), view);
|
||||
gtk_stack_add_titled (GTK_STACK (priv->stack), scrolled, basename, basename);
|
||||
scrolled = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_widget_show (scrolled);
|
||||
gtk_widget_set_hexpand (scrolled, TRUE);
|
||||
gtk_widget_set_vexpand (scrolled, TRUE);
|
||||
view = gtk_text_view_new ();
|
||||
gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
|
||||
gtk_widget_show (view);
|
||||
gtk_container_add (GTK_CONTAINER (scrolled), view);
|
||||
gtk_stack_add_titled (GTK_STACK (priv->stack), scrolled, basename, basename);
|
||||
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
||||
|
||||
if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL)) {
|
||||
gtk_text_buffer_set_text (buffer, contents, length);
|
||||
g_free (contents);
|
||||
}
|
||||
if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL))
|
||||
{
|
||||
gtk_text_buffer_set_text (buffer, contents, length);
|
||||
g_free (contents);
|
||||
}
|
||||
|
||||
tag = gtk_text_buffer_create_tag (buffer, NULL, NULL);
|
||||
g_settings_bind (priv->settings, "font", tag, "font", G_SETTINGS_BIND_DEFAULT);
|
||||
tag = gtk_text_buffer_create_tag (buffer, NULL, NULL);
|
||||
g_settings_bind (priv->settings, "font",
|
||||
tag, "font",
|
||||
G_SETTINGS_BIND_DEFAULT);
|
||||
|
||||
gtk_text_buffer_get_start_iter (buffer, &start_iter);
|
||||
gtk_text_buffer_get_end_iter (buffer, &end_iter);
|
||||
gtk_text_buffer_apply_tag (buffer, tag, &start_iter, &end_iter);
|
||||
gtk_text_buffer_get_start_iter (buffer, &start_iter);
|
||||
gtk_text_buffer_get_end_iter (buffer, &end_iter);
|
||||
gtk_text_buffer_apply_tag (buffer, tag, &start_iter, &end_iter);
|
||||
|
||||
g_free (basename);
|
||||
g_free (basename);
|
||||
|
||||
gtk_widget_set_sensitive (priv->search, TRUE);
|
||||
gtk_widget_set_sensitive (priv->search, TRUE);
|
||||
|
||||
update_words (win);
|
||||
update_words (win);
|
||||
}
|
||||
|
@ -9,8 +9,8 @@
|
||||
#define EXAMPLE_APP_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_APP_WINDOW_TYPE, ExampleAppWindow))
|
||||
|
||||
|
||||
typedef struct ExampleAppWindow ExampleAppWindow;
|
||||
typedef struct ExampleAppWindowClass ExampleAppWindowClass;
|
||||
typedef struct _ExampleAppWindow ExampleAppWindow;
|
||||
typedef struct _ExampleAppWindowClass ExampleAppWindowClass;
|
||||
|
||||
|
||||
GType example_app_window_get_type (void);
|
||||
|
@ -4,12 +4,12 @@
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
/* Since this example is running uninstalled,
|
||||
* we have to help it find its schema. This
|
||||
* is *not* necessary in properly installed
|
||||
* application.
|
||||
*/
|
||||
g_setenv ("GSETTINGS_SCHEMA_DIR", ".", FALSE);
|
||||
/* Since this example is running uninstalled,
|
||||
* we have to help it find its schema. This
|
||||
* is *not* necessary in properly installed
|
||||
* application.
|
||||
*/
|
||||
g_setenv ("GSETTINGS_SCHEMA_DIR", ".", FALSE);
|
||||
|
||||
return g_application_run (G_APPLICATION (example_app_new ()), argc, argv);
|
||||
return g_application_run (G_APPLICATION (example_app_new ()), argc, argv);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user