[dconf] editor: Use GtkApplication
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf] editor: Use GtkApplication
- Date: Tue, 1 May 2012 23:44:39 +0000 (UTC)
commit 4be0e3f533c869a6368cac14eafecc7430a48e62
Author: Robert Ancell <robert ancell canonical com>
Date: Tue May 1 16:19:59 2012 +1200
editor: Use GtkApplication
editor/Makefile.am | 6 ++--
editor/dconf-editor.ui | 6 -----
editor/dconf-editor.vala | 47 ++++++++++++++++++++++++---------------------
3 files changed, 28 insertions(+), 31 deletions(-)
---
diff --git a/editor/Makefile.am b/editor/Makefile.am
index e52d833..55575fb 100644
--- a/editor/Makefile.am
+++ b/editor/Makefile.am
@@ -1,9 +1,9 @@
bin_PROGRAMS = dconf-editor
-AM_CFLAGS = $(gtk_CFLAGS) $(gmodule_CFLAGS) $(libxml_CFLAGS) -I$(top_srcdir)/common -I$(top_srcdir)/client -DPKGDATADIR=\"@datadir@/dconf-editor\"
-AM_VALAFLAGS = --vapidir ../client --pkg gtk+-3.0 --pkg gmodule-2.0 --pkg libxml-2.0 --pkg dconf
+AM_CFLAGS = $(gtk_CFLAGS) $(libxml_CFLAGS) -I$(top_srcdir)/common -I$(top_srcdir)/client -DPKGDATADIR=\"@datadir@/dconf-editor\"
+AM_VALAFLAGS = --vapidir ../client --pkg gtk+-3.0 --pkg libxml-2.0 --pkg dconf
CFLAGS += -Wno-error -Wno-unused-but-set-variable -Wno-unused-variable
-dconf_editor_LDADD = ../client/libdconf.so.0 $(gtk_LIBS) $(gmodule_LIBS) $(gee_LIBS) $(libxml_LIBS)
+dconf_editor_LDADD = ../client/libdconf.so.0 $(gtk_LIBS) $(gee_LIBS) $(libxml_LIBS)
dconf_editor_SOURCES = config.vapi dconf-editor.vala dconf-model.vala dconf-schema.vala dconf-view.vala
desktopdir = $(datadir)/applications
diff --git a/editor/dconf-editor.ui b/editor/dconf-editor.ui
index 72f040d..41406a7 100644
--- a/editor/dconf-editor.ui
+++ b/editor/dconf-editor.ui
@@ -4,16 +4,10 @@
<object class="GtkAction" id="set_default_action">
<property name="label" translatable="yes">Set to Default</property>
<property name="sensitive">False</property>
- <signal name="activate" handler="set_default_cb" swapped="no"/>
</object>
<object class="GtkWindow" id="main_window">
<property name="can_focus">False</property>
<property name="border_width">6</property>
- <property name="title" translatable="yes">Configuration Editor</property>
- <property name="default_width">600</property>
- <property name="default_height">300</property>
- <signal name="window-state-event" handler="main_window_window_state_event_cb" swapped="no"/>
- <signal name="configure-event" handler="main_window_configure_event_cb" swapped="no"/>
<child>
<object class="GtkHPaned" id="hpaned1">
<property name="visible">True</property>
diff --git a/editor/dconf-editor.vala b/editor/dconf-editor.vala
index 9daf3c0..c49cd5e 100644
--- a/editor/dconf-editor.vala
+++ b/editor/dconf-editor.vala
@@ -1,10 +1,10 @@
-class ConfigurationEditor
+class ConfigurationEditor : Gtk.Application
{
private SettingsModel model;
private Settings settings;
private Gtk.Builder ui;
- private Gtk.Window window;
+ private Gtk.ApplicationWindow window;
private Gtk.TreeView dir_tree_view;
private Gtk.TreeView key_tree_view;
private Gtk.Grid key_info_grid;
@@ -19,6 +19,13 @@ class ConfigurationEditor
public ConfigurationEditor()
{
+ Object(application_id: "ca.desrt.dconf-editor", flags: ApplicationFlags.FLAGS_NONE);
+ }
+
+ protected override void startup()
+ {
+ base.startup();
+
settings = new Settings ("ca.desrt.dconf-editor.Settings");
model = new SettingsModel();
@@ -26,15 +33,19 @@ class ConfigurationEditor
ui = new Gtk.Builder();
try
{
- ui.add_from_file(Path.build_filename(Config.PKGDATADIR, "dconf-editor.ui"));
+ string[] objects = { "set_default_action", "hpaned1" };
+ ui.add_objects_from_file(Path.build_filename(Config.PKGDATADIR, "dconf-editor.ui"), objects);
}
catch (Error e)
{
critical("Failed to load UI: %s", e.message);
}
- ui.connect_signals(this);
- window = (Gtk.Window)ui.get_object("main_window");
- window.destroy.connect(Gtk.main_quit);
+ window = new Gtk.ApplicationWindow(this);
+ window.set_default_size(600, 300);
+ window.title = _("Configuration Editor");
+ window.window_state_event.connect(main_window_window_state_event_cb);
+ window.configure_event.connect(main_window_configure_event_cb);
+ window.add((Gtk.HPaned)ui.get_object("hpaned1"));
window.set_default_size (settings.get_int ("width"), settings.get_int ("height"));
if (settings.get_boolean ("maximized"))
@@ -60,6 +71,7 @@ class ConfigurationEditor
type_label = (Gtk.Label)ui.get_object("type_label");
default_label = (Gtk.Label)ui.get_object("default_label");
set_default_action = (Gtk.Action)ui.get_object("set_default_action");
+ set_default_action.activate.connect(set_default_cb);
/* Always select something */
Gtk.TreeIter iter;
@@ -67,9 +79,9 @@ class ConfigurationEditor
dir_tree_view.get_selection().select_iter(iter);
}
- public void show()
+ protected override void activate()
{
- window.show();
+ window.present();
}
private void dir_selected_cb()
@@ -175,16 +187,14 @@ class ConfigurationEditor
set_default_action.sensitive = selected_key != null && !selected_key.is_default;
}
- [CCode (cname = "G_MODULE_EXPORT set_default_cb", instance_pos = -1)]
- public void set_default_cb (Gtk.Action action)
+ private void set_default_cb (Gtk.Action action)
{
if (selected_key == null)
return;
selected_key.set_to_default();
}
- [CCode (cname = "G_MODULE_EXPORT main_window_configure_event_cb", instance_pos = -1)]
- public bool main_window_configure_event_cb (Gtk.Widget widget, Gdk.EventConfigure event)
+ private bool main_window_configure_event_cb (Gtk.Widget widget, Gdk.EventConfigure event)
{
if (!settings.get_boolean ("maximized"))
{
@@ -195,8 +205,7 @@ class ConfigurationEditor
return false;
}
- [CCode (cname = "G_MODULE_EXPORT main_window_window_state_event_cb", instance_pos = -1)]
- public bool main_window_window_state_event_cb (Gtk.Widget widget, Gdk.EventWindowState event)
+ private bool main_window_window_state_event_cb (Gtk.Widget widget, Gdk.EventWindowState event)
{
if ((event.changed_mask & Gdk.WindowState.MAXIMIZED) != 0)
{
@@ -209,13 +218,7 @@ class ConfigurationEditor
public static int main(string[] args)
{
- Gtk.init(ref args);
-
- var editor = new ConfigurationEditor();
- editor.show ();
-
- Gtk.main();
-
- return 0;
+ var app = new ConfigurationEditor();
+ return app.run(args);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]