diff --git a/data/com.github.dbhowell.peeq.gschema.xml b/data/com.github.dbhowell.peeq.gschema.xml
index 4e21e06..a694363 100644
--- a/data/com.github.dbhowell.peeq.gschema.xml
+++ b/data/com.github.dbhowell.peeq.gschema.xml
@@ -38,20 +38,25 @@
+
+ true
+ Use system font
+ Whether Peeq should use the default system font
+
'solarized-light'
Preferred Style Scheme
Set the preferred style scheme.
-
- 'Roboto Mono'
- Preferred mono spaced font
- Set the preferred mono spaced font for SQL queries and results.
+
+ 'Roboto Mono 10'
+ Preferred font
+ Set the preferred font for SQL queries and results.
-
+
'12pt'
- Preferred mono spaced font size
- Set the preferred mono spaced font size for SQL queries and results.
+ Preferred font size
+ Set the preferred font size for SQL queries and results.
diff --git a/src/Application.vala b/src/Application.vala
index 368bf2f..10ba443 100644
--- a/src/Application.vala
+++ b/src/Application.vala
@@ -18,6 +18,9 @@
*/
namespace Peeq {
+ public Services.Settings settings;
+ public string default_font;
+
public class Application : Gtk.Application {
private static string _app_cmd_name;
@@ -27,6 +30,9 @@ namespace Peeq {
public Application () {
Granite.Services.Logger.initialize ("Peeq");
+
+ settings = new Services.Settings ();
+ default_font = new GLib.Settings ("org.gnome.desktop.interface").get_string ("monospace-font-name");
}
public static Application _instance = null;
diff --git a/src/Dialogs/PreferencesDialog.vala b/src/Dialogs/PreferencesDialog.vala
new file mode 100644
index 0000000..2e90a2b
--- /dev/null
+++ b/src/Dialogs/PreferencesDialog.vala
@@ -0,0 +1,108 @@
+
+namespace Peeq.Dialogs {
+ public class Preferences : Gtk.Dialog {
+ private Gtk.Stack main_stack;
+ private Gtk.FontButton select_font;
+ private Gtk.Switch use_custom_font;
+
+ public Preferences (Gtk.Window? parent) {
+ Object (
+ border_width: 5,
+ deletable: false,
+ resizable: false,
+ title: _("Preferences"),
+ transient_for: parent
+ );
+ }
+
+ construct {
+ var indent_width = new Gtk.SpinButton.with_range (1, 24, 1);
+
+ var general_grid = new Gtk.Grid ();
+ general_grid.column_spacing = 12;
+ general_grid.row_spacing = 6;
+ general_grid.attach (new Granite.HeaderLabel (_("General")), 0, 0, 2, 1);
+
+ main_stack = new Gtk.Stack ();
+ main_stack.margin = 6;
+ main_stack.margin_bottom = 18;
+ main_stack.margin_top = 24;
+ //main_stack.add_titled (general_grid, "behavior", _("Behavior"));
+ main_stack.add_titled (get_editor_box (), "interface", _("Interface"));
+
+ var main_stackswitcher = new Gtk.StackSwitcher ();
+ main_stackswitcher.set_stack (main_stack);
+ main_stackswitcher.halign = Gtk.Align.CENTER;
+
+ var main_grid = new Gtk.Grid ();
+ main_grid.attach (main_stackswitcher, 0, 0, 1, 1);
+ main_grid.attach (main_stack, 0, 1, 1, 1);
+
+ get_content_area ().add (main_grid);
+
+ var close_button = new Gtk.Button.with_label (_("Close"));
+ close_button.clicked.connect (() => {
+ destroy ();
+ });
+
+ add_action_widget (close_button, 0);
+ }
+
+ private Gtk.Widget get_editor_box () {
+ var content = new Gtk.Grid ();
+ content.row_spacing = 6;
+ content.column_spacing = 12;
+
+ var editor_header = new Granite.HeaderLabel (_("Editor"));
+
+ var style_label = new SettingsLabel (_("Style:"));
+ var style_combo = new Gtk.ComboBoxText ();
+ style_combo.append ("classic", _("Classic"));
+ style_combo.append ("cobalt", _("Colbalt"));
+ style_combo.append ("kate", _("Kate"));
+ style_combo.append ("oblivion", _("Oblivion"));
+ style_combo.append ("solarized-dark", _("Solarized Dark"));
+ style_combo.append ("solarized-light", _("Solarized Light"));
+ style_combo.append ("tango", _("Tango"));
+ Peeq.settings.schema.bind ("style-scheme", style_combo, "active-id", SettingsBindFlags.DEFAULT);
+
+ var font_header = new Granite.HeaderLabel (_("Font"));
+
+ var use_custom_font_label = new SettingsLabel (_("Custom font:"));
+ use_custom_font = new Gtk.Switch ();
+ use_custom_font.halign = Gtk.Align.START;
+ Peeq.settings.schema.bind ("use-system-font", use_custom_font, "active", SettingsBindFlags.INVERT_BOOLEAN);
+
+ select_font = new Gtk.FontButton ();
+ select_font.hexpand = true;
+ Peeq.settings.schema.bind ("font", select_font, "font-name", SettingsBindFlags.DEFAULT);
+ Peeq.settings.schema.bind ("use-system-font", select_font, "sensitive", SettingsBindFlags.INVERT_BOOLEAN);
+
+ content.attach (editor_header, 0, 0, 3, 1);
+ content.attach (style_label, 0, 4, 1, 1);
+ content.attach (style_combo, 1, 4, 2, 1);
+ content.attach (font_header, 0, 7, 3, 1);
+ content.attach (use_custom_font_label , 0, 9, 1, 1);
+ content.attach (use_custom_font, 1, 9, 1, 1);
+ content.attach (select_font, 2, 9, 1, 1);
+
+ return content;
+ }
+
+ private class SettingsLabel : Gtk.Label {
+ public SettingsLabel (string text) {
+ label = text;
+ halign = Gtk.Align.END;
+ margin_start = 12;
+ }
+ }
+
+ private class SettingsSwitch : Gtk.Switch {
+ public SettingsSwitch (string setting) {
+ halign = Gtk.Align.START;
+ valign = Gtk.Align.CENTER;
+ Peeq.settings.schema.bind (setting, this, "active", SettingsBindFlags.DEFAULT);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/MainWindow.vala b/src/MainWindow.vala
index a2d1c93..30bcf04 100644
--- a/src/MainWindow.vala
+++ b/src/MainWindow.vala
@@ -29,6 +29,7 @@ namespace Peeq {
private Gtk.ScrolledWindow scrolled_window;
private Gee.ArrayList query_windows;
private Widgets.ListFooter footer;
+ private Gtk.Dialog? preferences_dialog = null;
public MainWindow (Peeq.Application peeq_app) {
Object (
@@ -111,6 +112,8 @@ namespace Peeq {
welcome.new_connection.connect (on_new_connection);
+ headerbar.preferences_clicked.connect (action_preferences);
+
Unix.signal_add (Posix.Signal.INT, quit_source_func, Priority.HIGH);
Unix.signal_add (Posix.Signal.TERM, quit_source_func, Priority.HIGH);
}
@@ -301,5 +304,18 @@ namespace Peeq {
save_settings ();
return false;
}
+
+ private void action_preferences () {
+ if (preferences_dialog == null) {
+ preferences_dialog = new Dialogs.Preferences (this);
+ preferences_dialog.show_all ();
+
+ preferences_dialog.destroy.connect (() => {
+ preferences_dialog = null;
+ });
+ }
+
+ preferences_dialog.present ();
+ }
}
}
diff --git a/src/Services/Settings.vala b/src/Services/Settings.vala
index 7897697..2892b9e 100644
--- a/src/Services/Settings.vala
+++ b/src/Services/Settings.vala
@@ -33,8 +33,9 @@ namespace Peeq {
public int window_x { get; set; }
public int window_y { get; set; }
public string style_scheme { get; set; }
- public string mono_space_font { get; set; }
- public string mono_space_font_size { get; set; }
+ public string font { get; set; }
+ public string font_size { get; set; }
+ public bool use_system_font { get; set; }
public Settings () {
base (Constants.PROJECT_NAME + ".settings");
diff --git a/src/Utils/StyleManager.vala b/src/Utils/StyleManager.vala
index bbf024a..a50f122 100644
--- a/src/Utils/StyleManager.vala
+++ b/src/Utils/StyleManager.vala
@@ -4,12 +4,34 @@ using Peeq.Services;
namespace Peeq.Utils {
public class StyleManager {
+ public static string get_current_font () {
+ if (!Peeq.settings.use_system_font) {
+ return Peeq.settings.font;
+ }
+
+ return Peeq.default_font;
+ }
+
+ public static string get_font_size () {
+ string font = get_current_font ();
+ string font_size = font.substring (font.last_index_of (" ") + 1);
+
+ return font_size;
+ }
+
+ public static string get_font_family () {
+ string font = get_current_font ();
+ string font_family = font.substring (0, font.last_index_of (" "));
+
+ return font_family;
+ }
+
public static Gtk.CssProvider get_mono_style () {
- var settings = new Services.Settings ();
var style = new Gtk.CssProvider ();
try {
- var data = @"* {font-family: $(settings.mono_space_font); font-size: $(settings.mono_space_font_size); }";
+ var data = @"* {font-family: \"$(get_font_family ())\"; font-size: $(get_font_size ())pt; }";
+ print(@"$(data)\n");
style.load_from_data (data, -1);
} catch (GLib.Error e) {
diff --git a/src/Utils/ValueCellRenderer.vala b/src/Utils/ValueCellRenderer.vala
index d2e4b46..5dfb3c3 100644
--- a/src/Utils/ValueCellRenderer.vala
+++ b/src/Utils/ValueCellRenderer.vala
@@ -3,12 +3,12 @@ using Pango;
namespace Peeq.Utils {
public class ValueCellRenderer : Gtk.CellRendererText {
- public ValueCellRenderer (string font) {
+ public ValueCellRenderer (string font, string size) {
this.font = font;
- this.editable = false;
+ this.size_points = int.parse(size);
+ this.editable = true;
this.ellipsize = EllipsizeMode.END;
this.ellipsize_set = true;
- this.size_points = 12;
}
}
}
\ No newline at end of file
diff --git a/src/Widgets/MainHeaderBar.vala b/src/Widgets/MainHeaderBar.vala
index a1d87a2..8490c34 100644
--- a/src/Widgets/MainHeaderBar.vala
+++ b/src/Widgets/MainHeaderBar.vala
@@ -19,8 +19,11 @@
namespace Peeq.Widgets {
public class MainHeaderBar : Gtk.HeaderBar {
+ public signal void preferences_clicked ();
+
Gtk.Spinner spinner;
-
+ Gtk.Button preferences;
+
public Gtk.AccelGroup accel_group;
public bool working {
@@ -44,6 +47,14 @@ namespace Peeq.Widgets {
spinner = new Gtk.Spinner ();
+ preferences = new Gtk.Button ();
+ preferences.image = new Gtk.Image.from_icon_name ("open-menu", Gtk.IconSize.LARGE_TOOLBAR);
+ preferences.tooltip_text = ("Menu");
+ preferences.clicked.connect (() => {
+ preferences_clicked ();
+ });
+
+ pack_end (preferences);
pack_end (spinner);
}
}
diff --git a/src/Widgets/RowsView.vala b/src/Widgets/RowsView.vala
index 9bae812..eb580de 100644
--- a/src/Widgets/RowsView.vala
+++ b/src/Widgets/RowsView.vala
@@ -39,8 +39,7 @@ namespace Peeq.Widgets {
}
void init_settings () {
- var settings = new Services.Settings ();
- default_font = settings.mono_space_font;
+
}
void init_layout () {
@@ -114,10 +113,8 @@ namespace Peeq.Widgets {
}
void set_columns (ArrayList fields) {
- Utils.ValueCellRenderer cell = new Utils.ValueCellRenderer (this.default_font);
- cell.editable_set = true;
- cell.editable = true;
-
+ Utils.ValueCellRenderer cell = new Utils.ValueCellRenderer (Utils.StyleManager.get_font_family (), Utils.StyleManager.get_font_size ());
+
for (int i=0; i < fields.size; i++) {
view.insert_column_with_attributes (-1, fields[i].name.replace ("_", "__"), cell, "text", i);
var c = view.get_column(i);
diff --git a/src/Widgets/SQLSourceView.vala b/src/Widgets/SQLSourceView.vala
index bbd9d62..d53f030 100644
--- a/src/Widgets/SQLSourceView.vala
+++ b/src/Widgets/SQLSourceView.vala
@@ -34,7 +34,7 @@ namespace Peeq.Widgets {
buffer = new Gtk.SourceBuffer (null);
buffer.language = manager.get_language ("sql");
- buffer.style_scheme = style_scheme_manager.get_scheme ("solarized-dark");
+ buffer.style_scheme = style_scheme_manager.get_scheme (Peeq.settings.style_scheme);
source_view = new Gtk.SourceView.with_buffer (buffer);
source_view.show_line_numbers = true;
diff --git a/src/meson.build b/src/meson.build
index c71b1f0..0a788e9 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -17,6 +17,7 @@ executable(
'MainWindow.vala',
'QueryWindow.vala',
'Dialogs/EditServer.vala',
+ 'Dialogs/PreferencesDialog.vala',
'Widgets/MainHeaderBar.vala',
'Widgets/ServerList.vala',
'Widgets/ServerListItem.vala',