Revision
79
Author
leonpegg
Date
2006-12-27 09:15:33 -0800 (Wed, 27 Dec 2006)

Log Message

Callicore ide file open dialog class

Added Paths

Diff

Added: desktop/trunk/programs/ide/lib/ide_fileopendialog.class.php (78 => 79)


--- desktop/trunk/programs/ide/lib/ide_fileopendialog.class.php	2006-12-20 15:47:33 UTC (rev 78)
+++ desktop/trunk/programs/ide/lib/ide_fileopendialog.class.php	2006-12-27 17:15:33 UTC (rev 79)
@@ -0,0 +1,45 @@
+<?php
+
+class CC_Ide_fileopendialog extends GtkFileChooserDialog{
+	
+	protected $filetypes = array();
+	
+	public function __construct($filetypes = array()){
+		parent::__construct("File Open", null,
+        	Gtk::FILE_CHOOSER_ACTION_OPEN,
+        	array(Gtk::STOCK_OK, Gtk::RESPONSE_OK), null);
+        $this->filetypes = $filetypes;
+        $hbox = new GtkHBox();
+    	$this->vbox->pack_start($hbox, 0, 0);
+    	$hbox->pack_start(new GtkLabel('File type:'), 0, 0);
+    	// create a combobox listing the available filter options
+    	$combobox = &GtkComboBoxEntry::new_text(); // note 1
+    	$combobox->append_text("All Files");
+    	$i = 0;
+    	foreach ($filetypes as $name => $filter){
+    		$combobox->append_text($name);
+    		if ($i == 0) {
+    			$combobox->get_child()->set_text($name);
+    			$filefilter = new GtkFileFilter(); // note 4
+    			$filefilter->add_pattern($this->filetypes[$name]);
+    			$this->set_filter($filefilter); // note 6
+    		}
+    	}
+    	$combobox->connect('changed', array($this,'on_change_filter')); // note 2
+      	$hbox->pack_start($combobox, 0, 0);
+      	$this->show_all();
+	}
+	
+	function on_change_filter($combobox) {
+    	$model = $combobox->get_model(); // get the model
+    	$selected_value = $model->get_value(
+    	    $combobox->get_active_iter(), 0);// note 3
+    	//echo "selected_value = $selected_value\n";
+    	$filter = new GtkFileFilter(); // note 4
+    	$filter->add_pattern($this->filetypes[$selected_value]);
+    	$this->set_filter($filter); // note 6
+	}
+	
+}
+
+?>
\ No newline at end of file