Exemplo n.º 1
0
		function __construct(){
			$this->glade = new GladeXML("glades/win_main.glade");
			$this->glade->signal_autoconnect_instance($this);
			
			$this->window = $this->glade->get_widget("window");
			$this->window->show_all();
			
			$this->tv_files = $this->glade->get_widget("tv_files");
			$this->tv_files->get_selection()->connect("changed", array($this, "on_tvFiles_changed"));
			treeview_addColumn($this->tv_files, array("Filename"));
			
			$this->DirChoose();
		}
Exemplo n.º 2
0
	/**
	 * Add a column (or more columns if you give it an array instead of a string) to a GtkTreeView(). Saves code.
	 * @param GtkTreeView $treeview The treeview which the function should add columns to.
	 * @param mixed $arrcolumn As a string, this would be the title of the one column added. As an array, this should be all the titles which should be added to the treeview as strings in the array.
	*/
	function treeview_addColumn(GtkTreeView $treeview, $arrcolumn){
		if (is_array($arrcolumn) && !$arrcolumn["type"] && !$arrcolumn["title"]){
			//Adding a liststore to the treeview.
			$eval = "\$ls = new GtkListStore(";
			$first = true;
			foreach($arrcolumn AS $column){
				if ($first == true){
					$first = false;
				}else{
					$eval .= ", ";
				}
				
				if (!is_array($column)){
					$type = "text";
				}else{
					$type = $column["type"];
				}
				
				if ($type == "text"){
					$eval .= "_TYPE_STRING";
				}elseif($type == "active"){
					$eval .= "_TYPE_BOOLEAN";
				}elseif($type == "int"){
					$eval .= "_TYPE_LONG";
				}else{
					throw new Exception("Invalid type: " . $type);
				}
				
				$count++;
			}
			$eval .= ");";
			eval($eval);
			
			$treeview->set_model($ls);
			$treeview->set_enable_search(true);
			
			//Add columns to the treeview.
			foreach($arrcolumn AS $value){
				treeview_addColumn($treeview, $value);
			}
		}else{
			$number = count($treeview->get_columns());
			
			if (is_array($arrcolumn)){
				$type = $arrcolumn["type"];
				$title = $arrcolumn["title"];
			}else{
				$title = $arrcolumn;
				$type = "text";
			}
			
			if ($type == "text" || $type == "int"){
				$render = new GtkCellRendererText();
				$type = "text";
			}elseif($type == "active"){
				$render = new GtkCellRendererToggle();
				$render->set_property("activatable", true);
			}else{
				throw new Exception("Invalid type: " . $type);
			}
			
			if (is_array($arrcolumn["connect"])){
				foreach($arrcolumn["connect"] AS $key => $value){
					$render->connect_after($key, $value);
				}
			}
			
			$column = new GtkTreeViewColumn($title, $render, $type, $number);
			$column->set_reorderable(true);
			$column->set_resizable(true);
			$column->set_clickable(true);
			$column->set_sort_column_id($number);
			$treeview->append_column($column);
			
			if (is_array($arrcolumn)){
				if ($arrcolumn["hidden"] == true){
					$column->set_visible(false);
				}
				
				if ($arrcolumn["searchcol"] == true){
					$treeview->set_search_column($number);
				}
				
				if ($arrcolumn["sortcol"] == true){
					if ($arrcolumn["sort"] == "desc"){
						$treeview->get_model()->set_sort_column_id($number, Gtk::SORT_DESCENDING);
					}else{
						$treeview->get_model()->set_sort_column_id($number, Gtk::SORT_ASCENDING);
					}
				}
			}
		}
	}