[latexila] Most used symbols: get command and tooltip
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] Most used symbols: get command and tooltip
- Date: Fri, 4 May 2012 17:03:42 +0000 (UTC)
commit cf0b17ad936f75be4e9aaf9909eafe2c60213ec6
Author: SÃbastien Wilmet <swilmet src gnome org>
Date: Fri May 4 19:00:21 2012 +0200
Most used symbols: get command and tooltip
In the previous implememtation, these information were stored directly
in the XML file. But it's better to take these information from the
other symbols categories, since the information can be modified (if the
latex command is wrong, ...).
src/most_used_symbols.vala | 9 ++++-
src/symbols.vala | 72 +++++++++++++++++++++++++++++++++++++++----
2 files changed, 72 insertions(+), 9 deletions(-)
---
diff --git a/src/most_used_symbols.vala b/src/most_used_symbols.vala
index 23fd9a8..916bfa8 100644
--- a/src/most_used_symbols.vala
+++ b/src/most_used_symbols.vala
@@ -136,12 +136,17 @@ public class MostUsedSymbols : GLib.Object
if (pixbuf == null)
return;
+ string command;
+ string tooltip;
+ if (! Symbols.get_default ().get_symbol_info (id, out command, out tooltip))
+ return;
+
TreeIter iter;
_store.append (out iter);
_store.set (iter,
SymbolColumn.PIXBUF, pixbuf,
- SymbolColumn.COMMAND, "",
- SymbolColumn.TOOLTIP, "",
+ SymbolColumn.COMMAND, command,
+ SymbolColumn.TOOLTIP, tooltip,
SymbolColumn.ID, id,
SYMBOL_COLUMN_NUM, nb_times_used
);
diff --git a/src/symbols.vala b/src/symbols.vala
index a103662..af723a9 100644
--- a/src/symbols.vala
+++ b/src/symbols.vala
@@ -68,6 +68,9 @@ public class Symbols : GLib.Object
private static Symbols _instance = null;
private ListStore _categories_store;
+ // category id -> NormalSymbols
+ private Gee.Map<string, NormalSymbols?> _normal_symbols_map;
+
// singleton
private Symbols ()
{
@@ -78,17 +81,24 @@ public class Symbols : GLib.Object
typeof (TreeModel)
);
+ _normal_symbols_map = new Gee.HashMap<string, NormalSymbols?> ();
+
foreach (CategoryInfo info in _normal_categories)
add_normal_category (info);
-
- add_most_used_category ();
}
public static Symbols get_default ()
{
if (_instance == null)
+ {
_instance = new Symbols ();
+ // This class must be instanciated before the construction of the
+ // MostUsedSymbols class, because MostUsedSymbols calls
+ // get_symbol_info().
+ _instance.add_most_used_category ();
+ }
+
return _instance;
}
@@ -97,10 +107,36 @@ public class Symbols : GLib.Object
return _categories_store as TreeModel;
}
+ public bool get_symbol_info (string id, out string command, out string tooltip)
+ {
+ command = null;
+ tooltip = null;
+
+ string[] id_components = id.split ("/");
+ return_val_if_fail (id_components.length == 2, false);
+
+ string category_id = id_components[0];
+ string icon_file = id_components[1];
+
+ return_val_if_fail (_normal_symbols_map.has_key (category_id), false);
+
+ NormalSymbols normal_symbols = _normal_symbols_map[category_id];
+
+ string package = null;
+ bool ok = normal_symbols.get_symbol_info (icon_file, out command, out package);
+
+ return_val_if_fail (ok, false);
+
+ tooltip = get_tooltip (command, package);
+ return true;
+ }
+
private void add_normal_category (CategoryInfo info)
{
ListStore store = new NormalSymbols (info.id);
+ _normal_symbols_map[info.id] = store as NormalSymbols;
+
TreeIter iter;
_categories_store.append (out iter);
_categories_store.set (iter,
@@ -156,7 +192,6 @@ private class NormalSymbols : ListStore
{
private struct SymbolInfo
{
- string icon_file;
string latex_command;
string? package_required;
}
@@ -164,11 +199,16 @@ private class NormalSymbols : ListStore
private string _category_id;
private string _resource_path;
+ // icon file -> symbol info
+ private Gee.Map<string, SymbolInfo?> _data;
+
public NormalSymbols (string category_id)
{
_category_id = category_id;
_resource_path = @"/org/gnome/latexila/symbols/$category_id/";
+ _data = new Gee.HashMap<string, SymbolInfo?> ();
+
Type[] column_types = {
typeof (Gdk.Pixbuf),
typeof (string), // command
@@ -181,6 +221,21 @@ private class NormalSymbols : ListStore
load_symbols ();
}
+ public bool get_symbol_info (string icon_file, out string command, out string package)
+ {
+ command = null;
+ package = null;
+
+ if (! _data.has_key (icon_file))
+ return false;
+
+ SymbolInfo info = _data[icon_file];
+ command = info.latex_command;
+ package = info.package_required;
+
+ return true;
+ }
+
private void load_symbols ()
{
unowned string? contents =
@@ -201,12 +256,14 @@ private class NormalSymbols : ListStore
}
}
- private void add_symbol (SymbolInfo symbol)
+ private void add_symbol (string icon_file, SymbolInfo symbol)
{
+ _data[icon_file] = symbol;
+
string tooltip = Symbols.get_tooltip (symbol.latex_command,
symbol.package_required);
- string id = "%s/%s".printf (_category_id, symbol.icon_file);
+ string id = "%s/%s".printf (_category_id, icon_file);
Gdk.Pixbuf? pixbuf = Symbols.get_pixbuf (id);
if (pixbuf == null)
@@ -233,13 +290,14 @@ private class NormalSymbols : ListStore
case "symbol":
SymbolInfo symbol = SymbolInfo ();
symbol.package_required = null;
+ string icon_file = null;
for (int i = 0 ; i < attr_names.length ; i++)
{
switch (attr_names[i])
{
case "file":
- symbol.icon_file = attr_values[i];
+ icon_file = attr_values[i];
break;
case "command":
@@ -256,7 +314,7 @@ private class NormalSymbols : ListStore
}
}
- add_symbol (symbol);
+ add_symbol (icon_file, symbol);
break;
default:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]