elementaryart team mailing list archive
-
elementaryart team
-
Mailing list archive
-
Message #01917
[Merge] lp:~voluntatefaber/granite/contractorview-custom-items into lp:granite
Andrea Basso has proposed merging lp:~voluntatefaber/granite/contractorview-custom-items into lp:granite.
Requested reviews:
elementary Pantheon team (elementary-pantheon)
For more details, see:
https://code.launchpad.net/~voluntatefaber/granite/contractorview-custom-items/+merge/91916
This branch adds two methods to ContractorView.vala that make possible adding new non-contracts items to the list or blacklisting some contracts.
--
https://code.launchpad.net/~voluntatefaber/granite/contractorview-custom-items/+merge/91916
Your team elementaryart (old) is subscribed to branch lp:granite.
=== modified file 'lib/CMakeLists.txt'
--- lib/CMakeLists.txt 2012-01-15 22:14:08 +0000
+++ lib/CMakeLists.txt 2012-02-07 20:26:44 +0000
@@ -24,7 +24,7 @@
find_package(GObjectIntrospection 0.9.12)
include(GObjectIntrospectionMacros)
set(PKG_DEPS gtk+-3.0 gio-unix-2.0)
-pkg_check_modules(DEPS REQUIRED gtk+-3.0 gio-unix-2.0 gthread-2.0)
+pkg_check_modules(DEPS REQUIRED gtk+-3.0 gio-unix-2.0 gthread-2.0 gee-1.0)
# Link all
set(CFLAGS ${DEPS_CFLAGS} ${DEPS_CFLAGS_OTHER})
@@ -75,6 +75,7 @@
PACKAGES
${PKG_DEPS}
posix
+ gee-1.0
OPTIONS
--thread
GENERATE_VAPI
=== modified file 'lib/Widgets/ContractorView.vala'
--- lib/Widgets/ContractorView.vala 2012-01-06 21:05:18 +0000
+++ lib/Widgets/ContractorView.vala 2012-02-07 20:26:44 +0000
@@ -27,6 +27,13 @@
**/
public bool contractor_available;
+ public delegate void DelegateType ();
+ private Gee.HashMap<int, DelegateWrapper?> outsiders;
+ private int[] blacklisted_pos;
+ private ListStore list;
+
+ private struct DelegateWrapper {DelegateType method;}
+
/**
* the index of the currently selected contract
**/
@@ -55,7 +62,8 @@
**/
public ContractorView (string filename, string mime, int icon_size = 32, bool show_contract_name = true) {
/* Setup the ListStore */
- var list = new ListStore (2, typeof (Gdk.Pixbuf), typeof (string));
+ list = new ListStore (2, typeof (Gdk.Pixbuf), typeof (string));
+ outsiders = new Gee.HashMap<int, DelegateWrapper?> ();
this.model = list;
/* GUI */
@@ -115,13 +123,82 @@
}
}
+ /**
+ * A method to add items to the tree
+ * @param name the name
+ * @param text the description
+ * @param icon_name the name of the icon to show
+ * @param icon_size the size of the icon in pixel
+ * @param position the posion the item will be inserted at (first position is 0)
+ * @param method a general method containing all the methods that should be called when the item is activated
+ * (must return void and mustn't have any parameter)
+ **/
+ public void add_item (string name, string desc, string icon_name, int icon_size, int position, DelegateType method) {
+ TreeIter it;
+ list.insert (out it, position);
+
+ string text = "<b>" + name + "</b>\n" + desc;
+
+ try{
+ list.set (it, 0, IconTheme.get_default ().load_icon (icon_name, icon_size, 0), 1, text);
+ } catch (Error e) {
+ error (e.message);
+ }
+
+ DelegateWrapper wr = {method};
+ outsiders[position] = wr;
+
+ this.selected = 0;
+ }
+
+ public void name_blacklist (string[] names) {
+ TreeIter it;
+ TreeIter it2;
+ Value value;
+ bool check;
+ int cur_pos = 0;
+ list.get_iter_first (out it);
+ list.get_iter_first (out it2);
+
+ while (true) {
+ list.get_value (it, 1, out value);
+ check = list.iter_next (ref it2);
+ string text = value.get_string ();
+
+ if (text[3:text.index_of ("</b>")] in names) {
+ list.remove (it);
+ blacklisted_pos += cur_pos;
+ }
+ if (!check)
+ break;
+
+ it = it2;
+ cur_pos++;
+ }
+ }
+
+
public void run_selected () {
- try {
- Process.spawn_command_line_async (
- this.contracts[this.selected].lookup ("Exec"));
- }
- catch (Error e) {
- error (e.message);
+ if (this.selected in outsiders.keys ) {
+ outsiders[this.selected].method ();
+ } else {
+ try {
+ int corr = 0;
+ foreach (int i in outsiders.keys) { //adjust in case of items added
+ if (i > this.selected)
+ break;
+ corr++;
+ }
+ foreach (int i in blacklisted_pos) { //adjust in case of items removed
+ if (i > this.selected)
+ break;
+ corr--;
+ }
+ Process.spawn_command_line_async (
+ this.contracts[this.selected-corr].lookup ("Exec"));
+ } catch (Error e) {
+ error (e.message);
+ }
}
}
}
Follow ups