From a31bcc3b30e4bc8fe9a8b5bef236d34cc309b317 Mon Sep 17 00:00:00 2001 From: Dominique Lasserre Date: Wed, 7 Aug 2013 01:11:37 +0200 Subject: [PATCH] Use gtk templates. --- CMakeLists.txt | 19 +- src/SettingsWindow.vala | 101 ++----- src/resources/finalterm.gresource.xml | 6 + src/resources/ui/SettingsWindow.ui | 361 ++++++++++++++++++++++++++ 4 files changed, 411 insertions(+), 76 deletions(-) create mode 100644 src/resources/finalterm.gresource.xml create mode 100644 src/resources/ui/SettingsWindow.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index 343525b..4aa7b51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,7 @@ link_directories(${DEPS_LIBRARY_DIRS}) find_package(Vala REQUIRED) include(ValaVersion) -ensure_vala_version("0.16.0" MINIMUM) +ensure_vala_version("0.21" MINIMUM) include(ValaPrecompile) vala_precompile(VALA_C @@ -85,6 +85,8 @@ OPTIONS -g --vapidir=${CMAKE_CURRENT_SOURCE_DIR}/vapi/ ${VALAFLAGS} + --target-glib=2.38 + --gresources=${CMAKE_CURRENT_SOURCE_DIR}/src/resources/finalterm.gresource.xml ) add_subdirectory (po) @@ -92,7 +94,20 @@ add_subdirectory (po) include(GSettings) add_schema ("data/org.gnome.finalterm.gschema.xml") -add_executable(finalterm ${VALA_C}) +find_program(GLIB_COMPILE_RESOURCES glib-compile-resources) +execute_process(OUTPUT_VARIABLE gresources_deps + COMMAND ${GLIB_COMPILE_RESOURCES} --generate-dependencies --sourcedir=${CMAKE_CURRENT_SOURCE_DIR}/src/resources ${CMAKE_CURRENT_SOURCE_DIR}/src/resources/finalterm.gresource.xml + OUTPUT_STRIP_TRAILING_WHITESPACE +) +string(REPLACE "\n" ";" gresources_deps ${gresources_deps}) +add_custom_command(OUTPUT finalterm-resource.c + COMMAND ${GLIB_COMPILE_RESOURCES} --target=finalterm-resource.c --sourcedir=${CMAKE_CURRENT_SOURCE_DIR}/src/resources --generate-source ${CMAKE_CURRENT_SOURCE_DIR}/src/resources/finalterm.gresource.xml + DEPENDS ${gresources_deps} + COMMENT "Compile gresources." + VERBATIM +) + +add_executable(finalterm ${VALA_C} finalterm-resource.c) target_link_libraries(finalterm m util) install(TARGETS finalterm RUNTIME DESTINATION bin) diff --git a/src/SettingsWindow.vala b/src/SettingsWindow.vala index cc2202a..bbe4f05 100644 --- a/src/SettingsWindow.vala +++ b/src/SettingsWindow.vala @@ -1,5 +1,6 @@ /* * Copyright © 2013 Tom Beckmann + * 2013 Dominique Lasserre * * Nemo vir est qui mundum non reddat meliorem. * @@ -20,18 +21,34 @@ * along with Final Term. If not, see . */ +[GtkTemplate (ui = "/org/gnome/finalterm/ui/SettingsWindow.ui")] public class SettingsWindow : Gtk.Dialog { - public SettingsWindow() { - title = _("Preferences"); + [GtkChild (name = "rows")] + private Gtk.SpinButton rows; + + [GtkChild (name = "columns")] + private Gtk.SpinButton columns; + + [GtkChild (name = "terminal_font")] + private Gtk.FontButton terminal_font; + + [GtkChild (name = "label_font")] + private Gtk.FontButton label_font; + + [GtkChild (name = "dark_look")] + private Gtk.Switch dark_look; + + [GtkChild (name = "color_scheme")] + private Gtk.ComboBoxText color_scheme; - add_buttons(Gtk.Stock.CLOSE, Gtk.ResponseType.CANCEL); + [GtkChild (name = "theme")] + private Gtk.ComboBoxText theme; - var dimensions_columns = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 6); - var dimensions_rows = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 6); - var rows = new Gtk.SpinButton.with_range(10, 200, 1); - var columns = new Gtk.SpinButton.with_range(10, 300, 1); + [GtkChild (name = "opacity")] + private Gtk.Scale opacityval; + public SettingsWindow() { rows.value = Settings.get_default().terminal_lines; rows.value_changed.connect(() => { Settings.get_default().terminal_lines = (int)rows.value; @@ -42,14 +59,6 @@ public class SettingsWindow : Gtk.Dialog { Settings.get_default().terminal_columns = (int)columns.value; }); - dimensions_columns.pack_start(columns, false); - dimensions_columns.pack_start(new Gtk.Label(_("columns")), false); - dimensions_rows.pack_start(rows, false); - dimensions_rows.pack_start(new Gtk.Label(_("rows")), false); - - var terminal_font = new Gtk.FontButton(); - terminal_font.use_font = true; - // Restrict selection to monospaced fonts terminal_font.set_filter_func((family, face) => { return family.is_monospace(); }); @@ -58,21 +67,16 @@ public class SettingsWindow : Gtk.Dialog { Settings.get_default().terminal_font_name = terminal_font.font_name; }); - var label_font = new Gtk.FontButton(); - label_font.use_font = true; label_font.font_name = Settings.get_default().label_font_name; label_font.font_set.connect(() => { Settings.get_default().label_font_name = label_font.font_name; }); - var dark_look = new Gtk.Switch(); dark_look.active = Settings.get_default().dark; - dark_look.halign = Gtk.Align.START; dark_look.notify["active"].connect(() => { Settings.get_default().dark = dark_look.active; }); - var color_scheme = new Gtk.ComboBoxText(); foreach (var color_scheme_name in FinalTerm.color_schemes.keys) { color_scheme.append(color_scheme_name, color_scheme_name); } @@ -81,7 +85,6 @@ public class SettingsWindow : Gtk.Dialog { Settings.get_default().color_scheme_name = color_scheme.active_id; }); - var theme = new Gtk.ComboBoxText(); foreach (var theme_name in FinalTerm.themes.keys) { theme.append(theme_name, theme_name); } @@ -90,59 +93,9 @@ public class SettingsWindow : Gtk.Dialog { Settings.get_default().theme_name = theme.active_id; }); - var opacity = new Gtk.Scale.with_range(Gtk.Orientation.HORIZONTAL, 0, 100, 1); - opacity.set_value(Settings.get_default().opacity * 100.0); - opacity.value_changed.connect(() => { - Settings.get_default().opacity = opacity.get_value() / 100.0; + opacityval.set_value(Settings.get_default().opacity * 100.0); + opacityval.value_changed.connect(() => { + Settings.get_default().opacity = opacityval.get_value() / 100.0; }); - - var grid = new Gtk.Grid(); - grid.column_homogeneous = true; - grid.column_spacing = 12; - grid.row_spacing = 6; - grid.margin = 12; - - grid.attach(create_header(_("General")), 0, 0, 1, 1); - - grid.attach(create_label(_("Default dimensions:")), 0, 1, 1, 1); - grid.attach(dimensions_columns, 1, 1, 1, 1); - grid.attach(dimensions_rows, 1, 2, 1, 1); - - grid.attach(create_header(_("Appearance")), 0, 3, 1, 1); - - grid.attach(create_label(_("Terminal font:")), 0, 4, 1, 1); - grid.attach(terminal_font, 1, 4, 1, 1); - - grid.attach(create_label(_("Label font:")), 0, 5, 1, 1); - grid.attach(label_font, 1, 5, 1, 1); - - grid.attach(create_label(_("Dark look:")), 0, 6, 1, 1); - grid.attach(dark_look, 1, 6, 1, 1); - - grid.attach(create_label(_("Color scheme:")), 0, 7, 1, 1); - grid.attach(color_scheme, 1, 7, 1, 1); - - grid.attach(create_label(_("Theme:")), 0, 8, 1, 1); - grid.attach(theme, 1, 8, 1, 1); - - // TODO: This looks ugly (alignment) - grid.attach(create_label(_("Opacity:")), 0, 9, 1, 1); - grid.attach(opacity, 1, 9, 1, 1); - - get_content_area().add(grid); - } - - private Gtk.Label create_header(string title) { - var label = new Gtk.Label("" + title + ""); - label.use_markup = true; - label.halign = Gtk.Align.START; - return label; } - - private Gtk.Label create_label(string text) { - var label = new Gtk.Label(text); - label.halign = Gtk.Align.END; - return label; - } - } diff --git a/src/resources/finalterm.gresource.xml b/src/resources/finalterm.gresource.xml new file mode 100644 index 0000000..b38340f --- /dev/null +++ b/src/resources/finalterm.gresource.xml @@ -0,0 +1,6 @@ + + + + ui/SettingsWindow.ui + + diff --git a/src/resources/ui/SettingsWindow.ui b/src/resources/ui/SettingsWindow.ui new file mode 100644 index 0000000..1d4642e --- /dev/null +++ b/src/resources/ui/SettingsWindow.ui @@ -0,0 +1,361 @@ + + + + + 10 + 300 + 10 + 1 + 10 + + + 10 + 200 + 10 + 1 + 10 + + + 100 + 90 + 1 + 10 + + +