Skip to content
This repository has been archived by the owner on Nov 11, 2018. It is now read-only.

Use gtk templates. #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -85,14 +85,29 @@ 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)

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)
Expand Down
101 changes: 27 additions & 74 deletions src/SettingsWindow.vala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright © 2013 Tom Beckmann <[email protected]>
* 2013 Dominique Lasserre <[email protected]>
*
* Nemo vir est qui mundum non reddat meliorem.
*
Expand All @@ -20,18 +21,34 @@
* along with Final Term. If not, see <http://www.gnu.org/licenses/>.
*/

[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;
Expand All @@ -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();
});
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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("<span weight='bold'>" + title + "</span>");
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;
}

}
6 changes: 6 additions & 0 deletions src/resources/finalterm.gresource.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/finalterm">
<file compressed="true" preprocess="xml-stripblanks">ui/SettingsWindow.ui</file>
</gresource>
</gresources>
Loading