[latexila] GSettings: use ranges when appropriate
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] GSettings: use ranges when appropriate
- Date: Wed, 10 Aug 2011 15:51:43 +0000 (UTC)
commit c1bb06dff6582dbfde66b200c7d34cf9ceeadde9
Author: SÃbastien Wilmet <swilmet src gnome org>
Date: Wed Aug 10 17:47:31 2011 +0200
GSettings: use ranges when appropriate
The documentation says that Settings.get_range () should not be used in
normal application. But it avoids the duplication of range values in the
Gtk.Adjustment applied to the SpinButtons.
Another mean would have been to use constants in config.h. But this
method is less generic.
TODO | 8 +----
data/org.gnome.latexila.gschema.xml | 6 +++-
src/app_settings.vala | 1 -
src/completion.vala | 1 -
src/main.vala | 2 +-
src/most_used_symbols.vala | 13 ++++++--
src/preferences_dialog.vala | 55 +++++++++++++++++++++++++++-------
src/ui/preferences_dialog.ui | 27 -----------------
8 files changed, 59 insertions(+), 54 deletions(-)
---
diff --git a/TODO b/TODO
index 66b6c47..7c05077 100644
--- a/TODO
+++ b/TODO
@@ -3,12 +3,6 @@ TODO
See also the Roadmap:
http://projects.gnome.org/latexila/#roadmap
-LaTeXila 2.2
-============
-
-Translations: integration with GNOME Damned Lies
-
-
LaTeXila â 2.4
==============
@@ -28,7 +22,7 @@ LaTeXila â 2.4
- Update on the fly the structure when the document is modified. An item can be inserted,
deleted or modified. The simplest way I think is to re-run the parsing only on the modified
lines (with a lower and upper bounds) every 2 seconds for example. This way, we simply
- delete all items between the two bounds, and the parsing will re-add them correcly.
+ delete all items between the two bounds, and the parsing will re-add them correctly.
(-) Edit toolbar: create a custom MenuToolButton:
Now the icon does nothing when we click on it, we must always click first on the arrow and then select the item.
diff --git a/data/org.gnome.latexila.gschema.xml b/data/org.gnome.latexila.gschema.xml
index 7564a81..43e539a 100644
--- a/data/org.gnome.latexila.gschema.xml
+++ b/data/org.gnome.latexila.gschema.xml
@@ -38,6 +38,7 @@
<description>Whether LaTeXila should automatically save modified files after a time interval. You can set the time interval with the "Autosave Interval" option.</description>
</key>
<key name="auto-save-interval" type="u">
+ <range min="1" max="100" />
<default>10</default>
<summary>Autosave Interval</summary>
<description>Number of minutes after which LaTeXila will automatically save modified files. This will only take effect if the "Autosave" option is turned on.</description>
@@ -48,6 +49,7 @@
<description>Whether LaTeXila should reopen the files that was opened the last time.</description>
</key>
<key name="tabs-size" type="u">
+ <range min="1" max="24" />
<default>2</default>
<summary>Tab Size</summary>
<description>Specifies the number of spaces that should be displayed instead of Tab characters.</description>
@@ -77,7 +79,8 @@
<summary>Highlight Matching Brackets</summary>
<description>Whether LaTeXila should highlight matching brackets.</description>
</key>
- <key name="nb-most-used-symbols" type="i">
+ <key name="nb-most-used-symbols" type="u">
+ <range min="1" max="50" />
<default>15</default>
<summary>Number of most used symbols</summary>
</key>
@@ -130,6 +133,7 @@
<description>Automatically show commands proposals</description>
</key>
<key name="interactive-completion-num" type="u">
+ <range min="0" max="8" />
<default>2</default>
<summary>Interactive completion min chars</summary>
<description>Minimum number of characters after '\' for interactive completion</description>
diff --git a/src/app_settings.vala b/src/app_settings.vala
index ead4af3..db2035f 100644
--- a/src/app_settings.vala
+++ b/src/app_settings.vala
@@ -94,7 +94,6 @@ public class AppSettings : GLib.Settings
{
uint val;
setting.get (key, "u", out val);
- val = val.clamp (1, 24);
foreach (DocumentView view in Application.get_default ().get_views ())
view.tab_width = val;
diff --git a/src/completion.vala b/src/completion.vala
index 4b3b0d2..b0c5980 100644
--- a/src/completion.vala
+++ b/src/completion.vala
@@ -168,7 +168,6 @@ public class CompletionProvider : GLib.Object, SourceCompletionProvider
uint min_nb_chars;
settings.get ("interactive-completion-num", "u", out min_nb_chars);
- min_nb_chars = min_nb_chars.clamp (0, 8);
return cmd != null && cmd.length > min_nb_chars;
}
diff --git a/src/main.vala b/src/main.vala
index cda4f6b..ffb7eba 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -50,7 +50,7 @@ int main (string[] args)
Config.SCHEMA_DIR != "/usr/share")
{
Environment.set_variable ("XDG_DATA_DIRS",
- "/usr/local/share:/usr/share:" + Config.SCHEMA_DIR, true);
+ Config.SCHEMA_DIR + ":/usr/local/share:/usr/share", true);
}
/* internationalisation */
diff --git a/src/most_used_symbols.vala b/src/most_used_symbols.vala
index ec237c8..54fa706 100644
--- a/src/most_used_symbols.vala
+++ b/src/most_used_symbols.vala
@@ -71,8 +71,12 @@ public class MostUsedSymbols : GLib.Object
public Iterator<MostUsedSymbol?> iterator ()
{
- int max = settings.get_int ("nb-most-used-symbols");
- var slice = most_used_symbols.slice (0, int.min (max, most_used_symbols.size));
+ uint max;
+ settings.get ("nb-most-used-symbols", "u", out max);
+
+ int slice_max = int.min ((int) max, most_used_symbols.size);
+ var slice = most_used_symbols.slice (0, slice_max);
+
return (Iterator<MostUsedSymbol?>) slice.iterator ();
}
@@ -85,7 +89,8 @@ public class MostUsedSymbols : GLib.Object
public void add_symbol (string id, string command, string? package)
{
modified = true;
- int max = settings.get_int ("nb-most-used-symbols");
+ uint max;
+ settings.get ("nb-most-used-symbols", "u", out max);
int i = 0;
foreach (MostUsedSymbol mus in most_used_symbols)
@@ -99,7 +104,7 @@ public class MostUsedSymbols : GLib.Object
{
if (i >= max)
{
- Symbols.remove_most_used_symbol (max - 1);
+ Symbols.remove_most_used_symbol ((int) max - 1);
Symbols.insert_most_used_symbol (new_i, mus);
}
else
diff --git a/src/preferences_dialog.vala b/src/preferences_dialog.vala
index dc1f290..be667c2 100644
--- a/src/preferences_dialog.vala
+++ b/src/preferences_dialog.vala
@@ -149,7 +149,9 @@ public class PreferencesDialog : Dialog
settings.bind ("display-line-numbers", display_line_nb_checkbutton, "active",
SettingsBindFlags.DEFAULT);
- var tab_width_spinbutton = builder.get_object ("tab_width_spinbutton");
+ var tab_width_spinbutton =
+ builder.get_object ("tab_width_spinbutton") as SpinButton;
+ set_spin_button_range (tab_width_spinbutton, settings, "tabs-size");
settings.bind ("tabs-size", tab_width_spinbutton, "value",
SettingsBindFlags.DEFAULT);
@@ -157,7 +159,7 @@ public class PreferencesDialog : Dialog
settings.bind ("insert-spaces", insert_spaces_checkbutton, "active",
SettingsBindFlags.DEFAULT);
- Widget forget_no_tabs = (Widget) builder.get_object ("forget_no_tabs");
+ Widget forget_no_tabs = builder.get_object ("forget_no_tabs") as Widget;
settings.bind ("forget-no-tabs", forget_no_tabs, "active",
SettingsBindFlags.DEFAULT);
set_sensitivity (settings, "insert-spaces", forget_no_tabs);
@@ -180,12 +182,14 @@ public class PreferencesDialog : Dialog
settings.bind ("auto-save", autosave_checkbutton, "active",
SettingsBindFlags.DEFAULT);
- var autosave_spinbutton = (Widget) builder.get_object ("autosave_spinbutton");
+ var autosave_spinbutton =
+ builder.get_object ("autosave_spinbutton") as SpinButton;
+ set_spin_button_range (autosave_spinbutton, settings, "auto-save-interval");
settings.bind ("auto-save-interval", autosave_spinbutton, "value",
SettingsBindFlags.DEFAULT);
set_sensitivity (settings, "auto-save", autosave_spinbutton);
- Label autosave_label = (Label) builder.get_object ("autosave_label");
+ Label autosave_label = builder.get_object ("autosave_label") as Label;
set_plural (autosave_label, settings, "auto-save-interval",
(n) => ngettext ("minute", "minutes", n));
@@ -200,7 +204,7 @@ public class PreferencesDialog : Dialog
new GLib.Settings ("org.gnome.latexila.preferences.editor");
var default_font_checkbutton =
- (Button) builder.get_object ("default_font_checkbutton");
+ builder.get_object ("default_font_checkbutton") as Button;
settings.bind ("use-default-font", default_font_checkbutton, "active",
SettingsBindFlags.DEFAULT);
set_system_font_label (default_font_checkbutton);
@@ -215,10 +219,10 @@ public class PreferencesDialog : Dialog
settings.bind ("editor-font", font_button, "font-name",
SettingsBindFlags.DEFAULT);
- var font_hbox = (Widget) builder.get_object ("font_hbox");
+ var font_hbox = builder.get_object ("font_hbox") as Widget;
set_sensitivity (settings, "use-default-font", font_hbox, false);
- TreeView schemes_treeview = (TreeView) builder.get_object ("schemes_treeview");
+ TreeView schemes_treeview = builder.get_object ("schemes_treeview") as TreeView;
string current_scheme_id = settings.get_string ("scheme");
init_schemes_treeview (schemes_treeview, current_scheme_id);
@@ -273,7 +277,9 @@ public class PreferencesDialog : Dialog
SettingsBindFlags.DEFAULT);
var interactive_comp_spinbutton =
- builder.get_object ("interactive_comp_spinbutton") as Widget;
+ builder.get_object ("interactive_comp_spinbutton") as SpinButton;
+ set_spin_button_range (interactive_comp_spinbutton, settings,
+ "interactive-completion-num");
settings.bind ("interactive-completion-num", interactive_comp_spinbutton, "value",
SettingsBindFlags.DEFAULT);
set_sensitivity (settings, "interactive-completion",
@@ -413,7 +419,9 @@ public class PreferencesDialog : Dialog
GLib.Settings fb_settings =
new GLib.Settings ("org.gnome.latexila.preferences.file-browser");
- var nb_most_used_symbols = builder.get_object ("nb_most_used_symbols");
+ var nb_most_used_symbols =
+ builder.get_object ("nb_most_used_symbols") as SpinButton;
+ set_spin_button_range (nb_most_used_symbols, settings, "nb-most-used-symbols");
settings.bind ("nb-most-used-symbols", nb_most_used_symbols, "value",
SettingsBindFlags.DEFAULT);
@@ -423,7 +431,7 @@ public class PreferencesDialog : Dialog
SettingsBindFlags.DEFAULT);
Widget auto_clean_up_checkbutton =
- (Widget) builder.get_object ("auto_clean_up_checkbutton");
+ builder.get_object ("auto_clean_up_checkbutton") as Widget;
latex_settings.bind ("automatic-clean", auto_clean_up_checkbutton, "active",
SettingsBindFlags.DEFAULT);
set_sensitivity (latex_settings, "no-confirm-clean", auto_clean_up_checkbutton);
@@ -437,7 +445,7 @@ public class PreferencesDialog : Dialog
SettingsBindFlags.DEFAULT);
Widget vbox_file_browser_show_all =
- (Widget) builder.get_object ("vbox_file_browser_show_all");
+ builder.get_object ("vbox_file_browser_show_all") as Widget;
set_sensitivity (fb_settings, "show-all-files", vbox_file_browser_show_all);
var file_browser_except = builder.get_object ("file_browser_except");
@@ -449,7 +457,7 @@ public class PreferencesDialog : Dialog
SettingsBindFlags.DEFAULT);
Widget file_browser_entry =
- (Widget) builder.get_object ("file_browser_entry");
+ builder.get_object ("file_browser_entry") as Widget;
fb_settings.bind ("file-extensions", file_browser_entry, "text",
SettingsBindFlags.DEFAULT);
set_sensitivity (fb_settings, "show-all-files", file_browser_entry, false);
@@ -491,6 +499,29 @@ public class PreferencesDialog : Dialog
});
}
+ private void set_spin_button_range (SpinButton spin_button, GLib.Settings settings,
+ string key)
+ {
+ Variant range = settings.get_range (key);
+
+ string range_type;
+ Variant range_contents;
+ range.get ("(sv)", out range_type, out range_contents);
+
+ return_if_fail (range_type == "range");
+
+ uint min;
+ uint max;
+ range_contents.get ("(uu)", out min, out max);
+
+ uint cur_value;
+ settings.get (key, "u", out cur_value);
+
+ Adjustment adjustment = new Adjustment ((double) cur_value, (double) min,
+ (double) max, 1.0, 0, 0);
+ spin_button.set_adjustment (adjustment);
+ }
+
private enum StyleSchemes
{
ID,
diff --git a/src/ui/preferences_dialog.ui b/src/ui/preferences_dialog.ui
index 4e66641..5a266dd 100644
--- a/src/ui/preferences_dialog.ui
+++ b/src/ui/preferences_dialog.ui
@@ -2,29 +2,6 @@
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
- <object class="GtkAdjustment" id="adjustment1">
- <property name="lower">1</property>
- <property name="upper">24</property>
- <property name="value">2</property>
- <property name="step_increment">1</property>
- </object>
- <object class="GtkAdjustment" id="adjustment2">
- <property name="lower">1</property>
- <property name="upper">100</property>
- <property name="value">10</property>
- <property name="step_increment">1</property>
- </object>
- <object class="GtkAdjustment" id="adjustment3">
- <property name="lower">1</property>
- <property name="upper">50</property>
- <property name="value">15</property>
- <property name="step_increment">1</property>
- </object>
- <object class="GtkAdjustment" id="adjustment4">
- <property name="upper">8</property>
- <property name="value">2</property>
- <property name="step_increment">1</property>
- </object>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -80,7 +57,6 @@
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
- <property name="adjustment">adjustment1</property>
</object>
<packing>
<property name="expand">False</property>
@@ -206,7 +182,6 @@
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
- <property name="adjustment">adjustment2</property>
</object>
<packing>
<property name="expand">False</property>
@@ -483,7 +458,6 @@
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
- <property name="adjustment">adjustment4</property>
</object>
<packing>
<property name="expand">False</property>
@@ -820,7 +794,6 @@
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
- <property name="adjustment">adjustment3</property>
</object>
<packing>
<property name="expand">False</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]