Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GLib.Settings instead of Granite.Service.Settings #808

Merged
merged 5 commits into from
May 19, 2020
Merged
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
10 changes: 5 additions & 5 deletions plugins/pastebin/pastebin_dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,14 @@ namespace Scratch.Dialogs {
string paste_name = this.doc.get_basename ();
name_entry.text = paste_name;

expiry_combo.set_active_id (Scratch.services.expiry_time);
private_check.set_active (Scratch.services.set_private);
expiry_combo.set_active_id (Scratch.service_settings.get_string ("expiry-time"));
private_check.set_active (Scratch.service_settings.get_boolean ("set-private"));
}

private void write_settings () {
Scratch.services.paste_format_code = format_combo.get_active_id ();
Scratch.services.expiry_time = expiry_combo.get_active_id ();
Scratch.services.set_private = private_check.get_active ();
Scratch.service_settings.set_string ("paste-format-code", format_combo.active_id);
Scratch.service_settings.set_string ("expiry-time", expiry_combo.active_id);
Scratch.service_settings.set_boolean ("set-private", private_check.active);
}

private void send_button_clicked () {
Expand Down
6 changes: 3 additions & 3 deletions plugins/preserve-indent/preserve-indent.vala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class Scratch.Plugins.PreserveIndent : Peas.ExtensionBase, Peas.Activatab

pos = line_begin;
int indent = 0;
int tabwidth = Scratch.settings.indent_width;
int tabwidth = Scratch.settings.get_int ("indent-width");

unichar ch = pos.get_char ();
while (pos.get_offset () < iter.get_offset () && ch != '\n') {
Expand Down Expand Up @@ -171,7 +171,7 @@ public class Scratch.Plugins.PreserveIndent : Peas.ExtensionBase, Peas.Activatab
if (view.insert_spaces_instead_of_tabs) {
indent_str = string.nfill (nchars, ' ');
} else {
int tabwidth = Scratch.settings.indent_width;
int tabwidth = Scratch.settings.get_int ("indent-width");
int tabs = nchars / tabwidth;
int spaces = nchars % tabwidth;

Expand Down Expand Up @@ -203,7 +203,7 @@ public class Scratch.Plugins.PreserveIndent : Peas.ExtensionBase, Peas.Activatab
}

Gtk.TextBuffer buffer = view.buffer;
int tabwidth = Scratch.settings.indent_width;
int tabwidth = Scratch.settings.get_int ("indent-width");
Gtk.TextIter del_begin, del_end, itr;

for (var line = first_line; line <= last_line; ++line) {
Expand Down
35 changes: 0 additions & 35 deletions plugins/spell/Settings.vala

This file was deleted.

1 change: 0 additions & 1 deletion plugins/spell/meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module_name = 'spell'

module_files = [
'Settings.vala',
'spell.vala'
]

Expand Down
13 changes: 6 additions & 7 deletions plugins/spell/spell.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Scratch.Plugins.Spell: Peas.ExtensionBase, Peas.Activatable {

Scratch.Services.Interface plugins;

Scratch.Plugins.SpellSettings.Settings settings;
private GLib.Settings settings;

MainWindow window = null;

Expand All @@ -35,11 +35,10 @@ public class Scratch.Plugins.Spell: Peas.ExtensionBase, Peas.Activatable {
}

public void activate () {

this.settings = new Scratch.Plugins.SpellSettings.Settings ();
settings = new GLib.Settings (Constants.PROJECT_NAME + ".plugins.spell");

// Restore the last dictionary used.
this.lang_dict = settings.language;
lang_dict = settings.get_string ("language");

settings.changed.connect (settings_changed);

Expand Down Expand Up @@ -136,8 +135,8 @@ public class Scratch.Plugins.Spell: Peas.ExtensionBase, Peas.Activatable {
public void settings_changed () {
if (spell != null) {
try {
spell.set_language (settings.language);
this.lang_dict = settings.language;
spell.set_language (settings.get_string ("language"));
lang_dict = settings.get_string ("language");
} catch (Error e) {
warning (e.message);
}
Expand All @@ -146,7 +145,7 @@ public class Scratch.Plugins.Spell: Peas.ExtensionBase, Peas.Activatable {

public void save_settings () {
// Save the last dictionary used.
settings.language = this.lang_dict;
settings.set_string ("language", lang_dict);
}

public void deactivate () {
Expand Down
35 changes: 0 additions & 35 deletions plugins/terminal/Settings.vala

This file was deleted.

1 change: 0 additions & 1 deletion plugins/terminal/meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module_name = 'terminal'

module_files = [
'Settings.vala',
'terminal.vala'
]

Expand Down
8 changes: 4 additions & 4 deletions plugins/terminal/terminal.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Scratch.Plugins.Terminal : Peas.ExtensionBase, Peas.Activatable {

MainWindow window = null;

Scratch.Plugins.TerminalViewer.Settings settings;
private GLib.Settings settings;

Gtk.Notebook? bottombar = null;
Scratch.Widgets.HeaderBar? toolbar = null;
Expand Down Expand Up @@ -94,7 +94,7 @@ public class Scratch.Plugins.Terminal : Peas.ExtensionBase, Peas.Activatable {
}

void save_last_working_directory () {
settings.last_opened_path = get_shell_location ();
settings.set_string ("last-opened-path", get_shell_location ());
}

bool on_window_key_press_event (Gdk.EventKey event) {
Expand Down Expand Up @@ -203,7 +203,7 @@ public class Scratch.Plugins.Terminal : Peas.ExtensionBase, Peas.Activatable {
}

void on_hook_notebook () {
this.settings = new Scratch.Plugins.TerminalViewer.Settings ();
this.settings = new GLib.Settings (Constants.PROJECT_NAME + ".plugins.terminal");
this.terminal = new Vte.Terminal ();
this.terminal.scrollback_lines = -1;

Expand Down Expand Up @@ -258,7 +258,7 @@ public class Scratch.Plugins.Terminal : Peas.ExtensionBase, Peas.Activatable {
});

try {
string last_opened_path = settings.last_opened_path == "" ? "~/" : settings.last_opened_path;
string last_opened_path = settings.get_string ("last-opened-path") == "" ? "~/" : settings.get_string ("last-opened-path");
terminal.spawn_sync (Vte.PtyFlags.DEFAULT, last_opened_path, { Vte.get_user_shell () }, null, GLib.SpawnFlags.SEARCH_PATH, null, out child_pid);
} catch (GLib.Error e) {
warning (e.message);
Expand Down
10 changes: 5 additions & 5 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

namespace Scratch {
public GLib.Settings saved_state;
public Settings settings;
public ServicesSettings services;
public GLib.Settings settings;
public GLib.Settings service_settings;
public GLib.Settings privacy_settings;

public class Application : Gtk.Application {
Expand Down Expand Up @@ -55,9 +55,9 @@ namespace Scratch {

// Init settings
default_font = new GLib.Settings ("org.gnome.desktop.interface").get_string ("monospace-font-name");
saved_state = new GLib.Settings ("io.elementary.code.saved-state");
settings = new Settings ();
services = new ServicesSettings ();
saved_state = new GLib.Settings (Constants.PROJECT_NAME + ".saved-state");
settings = new GLib.Settings (Constants.PROJECT_NAME + ".settings");
service_settings = new GLib.Settings (Constants.PROJECT_NAME + ".services");
privacy_settings = new GLib.Settings ("org.gnome.desktop.privacy");

// Init data home folder for unsaved text files
Expand Down
16 changes: 8 additions & 8 deletions src/Dialogs/PreferencesDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace Scratch.Dialogs {
smart_cut_copy_info.tooltip_text = _("Cutting or copying without an active selection will cut or copy the entire current line");

var indent_width = new Gtk.SpinButton.with_range (1, 24, 1);
Scratch.settings.schema.bind ("indent-width", indent_width, "value", SettingsBindFlags.DEFAULT);
Scratch.settings.bind ("indent-width", indent_width, "value", SettingsBindFlags.DEFAULT);

var general_grid = new Gtk.Grid ();
general_grid.column_spacing = 12;
Expand Down Expand Up @@ -121,7 +121,7 @@ namespace Scratch.Dialogs {
var draw_spaces_combo = new Gtk.ComboBoxText ();
draw_spaces_combo.append ("For Selection", _("For selected text"));
draw_spaces_combo.append ("Always", _("Always"));
Scratch.settings.schema.bind ("draw-spaces", draw_spaces_combo, "active-id", SettingsBindFlags.DEFAULT);
Scratch.settings.bind ("draw-spaces", draw_spaces_combo, "active-id", SettingsBindFlags.DEFAULT);

var show_mini_map_label = new SettingsLabel (_("Show Mini Map:"));
show_mini_map = new SettingsSwitch ("show-mini-map");
Expand All @@ -131,21 +131,21 @@ namespace Scratch.Dialogs {

var right_margin_position = new Gtk.SpinButton.with_range (1, 250, 1);
right_margin_position.hexpand = true;
Scratch.settings.schema.bind ("right-margin-position", right_margin_position, "value", SettingsBindFlags.DEFAULT);
Scratch.settings.schema.bind ("show-right-margin", right_margin_position, "sensitive", SettingsBindFlags.DEFAULT);
Scratch.settings.bind ("right-margin-position", right_margin_position, "value", SettingsBindFlags.DEFAULT);
Scratch.settings.bind ("show-right-margin", right_margin_position, "sensitive", 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;
use_custom_font.valign = Gtk.Align.CENTER;
Scratch.settings.schema.bind ("use-system-font", use_custom_font, "active", SettingsBindFlags.INVERT_BOOLEAN);
Scratch.settings.bind ("use-system-font", use_custom_font, "active", SettingsBindFlags.INVERT_BOOLEAN);

select_font = new Gtk.FontButton ();
select_font.hexpand = true;
Scratch.settings.schema.bind ("font", select_font, "font-name", SettingsBindFlags.DEFAULT);
Scratch.settings.schema.bind ("use-system-font", select_font, "sensitive", SettingsBindFlags.INVERT_BOOLEAN);
Scratch.settings.bind ("font", select_font, "font-name", SettingsBindFlags.DEFAULT);
Scratch.settings.bind ("use-system-font", select_font, "sensitive", SettingsBindFlags.INVERT_BOOLEAN);

content.attach (editor_header, 0, 0, 3, 1);
content.attach (highlight_matching_brackets_label, 0, 2, 1, 1);
Expand Down Expand Up @@ -179,7 +179,7 @@ namespace Scratch.Dialogs {
public SettingsSwitch (string setting) {
halign = Gtk.Align.START;
valign = Gtk.Align.CENTER;
Scratch.settings.schema.bind (setting, this, "active", SettingsBindFlags.DEFAULT);
Scratch.settings.bind (setting, this, "active", SettingsBindFlags.DEFAULT);
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ namespace Scratch {
default_height = rect.height;

var gtk_settings = Gtk.Settings.get_default ();
gtk_settings.gtk_application_prefer_dark_theme = Scratch.settings.prefer_dark_style;
gtk_settings.gtk_application_prefer_dark_theme = Scratch.settings.get_boolean ("prefer-dark-style");

var window_state = Scratch.saved_state.get_enum ("window-state");
switch (window_state) {
Expand Down Expand Up @@ -300,7 +300,7 @@ namespace Scratch {
search_bar.highlight_none ();
});

Scratch.settings.schema.bind ("cyclic-search", search_bar.tool_cycle_search, "active", SettingsBindFlags.DEFAULT);
Scratch.settings.bind ("cyclic-search", search_bar.tool_cycle_search, "active", SettingsBindFlags.DEFAULT);

// SlitView
split_view = new Scratch.Widgets.SplitView (this);
Expand Down Expand Up @@ -418,10 +418,10 @@ namespace Scratch {

public void restore_opened_documents () {
if (privacy_settings.get_boolean ("remember-recent-files")) {
var uris_view1 = settings.opened_files_view1;
var uris_view2 = settings.opened_files_view2;
unowned string focused_document1 = settings.focused_document_view1;
unowned string focused_document2 = settings.focused_document_view2;
var uris_view1 = Scratch.settings.get_strv ("opened-files-view1");
var uris_view2 = Scratch.settings.get_strv ("opened-files-view2");
var focused_document1 = Scratch.settings.get_string ("focused-document-view1");
var focused_document2 = Scratch.settings.get_string ("focused-document-view2");

if (uris_view1.length > 0) {
var view = add_view ();
Expand Down Expand Up @@ -671,7 +671,7 @@ namespace Scratch {
}

public void set_default_zoom () {
Scratch.settings.font = get_current_font () + " " + get_default_font_size ().to_string ();
Scratch.settings.set_string ("font", get_current_font () + " " + get_default_font_size ().to_string ());
}

// Ctrl + scroll
Expand All @@ -687,8 +687,8 @@ namespace Scratch {
private void zooming (Gdk.ScrollDirection direction) {
string font = get_current_font ();
int font_size = (int) get_current_font_size ();
if (Scratch.settings.use_system_font) {
Scratch.settings.use_system_font = false;
if (Scratch.settings.get_boolean ("use-system-font")) {
Scratch.settings.set_boolean ("use-system-font", false);
font = get_default_font ();
font_size = (int) get_default_font_size ();
}
Expand All @@ -706,17 +706,17 @@ namespace Scratch {
}

string new_font = font + " " + font_size.to_string ();
Scratch.settings.font = new_font;
Scratch.settings.set_string ("font", new_font);
}

public string get_current_font () {
string font = Scratch.settings.font;
string font = Scratch.settings.get_string ("font");
string font_family = font.substring (0, font.last_index_of (" "));
return font_family;
}

public double get_current_font_size () {
string font = Scratch.settings.font;
string font = Scratch.settings.get_string ("font");
string font_size = font.substring (font.last_index_of (" ") + 1);
return double.parse (font_size);
}
Expand Down
Loading