elementaryart team mailing list archive
-
elementaryart team
-
Mailing list archive
-
Message #01916
[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/91721
This adds two methods to ContractView.vala
One adds custom items even if they're not contracts, the others blacklist unwanted contracts by name.
--
https://code.launchpad.net/~voluntatefaber/granite/contractorview-custom-items/+merge/91721
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-06 21:25:22 +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-06 21:25:22 +0000
@@ -27,9 +27,25 @@
**/
public bool contractor_available;
+ public delegate void DelegateType ();
+
+ /**
+ * A general item that can be inserted in the tree, even if it isn't a contract
+ * @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 that contains all the methods which should be called when the item is activated
+ * (must return void and mustn't have any parameter)
+ **/
+ public struct Item {string name; string text; string icon_name; int icon_size; int position; DelegateType method;}
+ private Gee.HashMap<int, Item?> outsiders;
+
/**
* the index of the currently selected contract
**/
+
public int selected {
get {
TreePath path;
@@ -53,7 +69,8 @@
* @param icon_size the size of the icon in pixel
* @param show_contract_name show the name of the contract in the list
**/
- public ContractorView (string filename, string mime, int icon_size = 32, bool show_contract_name = true) {
+ public ContractorView (string filename, string mime, int icon_size = 32, bool show_contract_name = true, Item[] items = {}, string[] name_blacklist = {}) {
+
/* Setup the ListStore */
var list = new ListStore (2, typeof (Gdk.Pixbuf), typeof (string));
this.model = list;
@@ -69,10 +86,10 @@
var cell1 = new CellRendererPixbuf ();
cell1.set_padding (5, 8);
this.insert_column_with_attributes (-1, "", cell1, "pixbuf", 0);
+
var cell2 = new CellRendererText ();
cell2.set_padding (2, 8);
this.insert_column_with_attributes (-1, "", cell2, "markup", 1);
-
this.contracts = Granite.Services.Contractor.get_contract (filename, mime);
if (this.contracts == null || this.contracts.length == 0) {
warning ("You should install contractor (or no contracts found for this mime).\n");
@@ -96,16 +113,34 @@
else {
contractor_available = true;
- for (var i=0; i<this.contracts.length; i++){
+ int correction = 0;
+ outsiders = new Gee.HashMap<int, Item?> ();
+ for (var i=0; i<(this.contracts.length+items.length); i++){
+ bool is_item = false;
+ Item? item = null;
+ foreach (Item cur_item in items) {
+ if (cur_item.position == i) {
+ is_item = true;
+ item = cur_item;
+ outsiders[i] = cur_item;
+ correction++;
+ break;
+ }
+ }
+
+ if ((!is_item) && this.contracts[i-correction].lookup ("Name") in name_blacklist) {
+ continue;
+ }
+
TreeIter it;
list.append (out it);
- string text = this.contracts[i].lookup ("Description");
+ string text = is_item ? item.text : this.contracts[i-correction].lookup ("Description");
+
if (show_contract_name)
- text = "<b>"+this.contracts[i].lookup ("Name")+"</b>\n"+text;
+ text = "<b>"+ (is_item ? item.name : this.contracts[i-correction].lookup ("Name") )+"</b>\n"+text;
try{
- list.set (it,
- 0, IconTheme.get_default ().load_icon (this.contracts[i].lookup ("IconName"),
- icon_size, 0), 1, text);
+ string icon_name = is_item ? item.icon_name : this.contracts[i-correction].lookup ("IconName");
+ list.set (it, 0, IconTheme.get_default ().load_icon (icon_name, icon_size, 0), 1, text);
}
catch (Error e) {
error (e.message);
@@ -116,12 +151,16 @@
}
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 {
+ Process.spawn_command_line_async (
+ this.contracts[this.selected].lookup ("Exec"));
+ }
+ catch (Error e) {
+ error (e.message);
+ }
}
}
}