Revision
125
Author
leonpegg
Date
2007-01-15 05:10:13 -0800 (Mon, 15 Jan 2007)

Log Message

added save and save as functions

Modified Paths

Diff

Modified: trunk/programs/ide/docs/roadmap.txt (124 => 125)


--- trunk/programs/ide/docs/roadmap.txt	2007-01-12 19:17:13 UTC (rev 124)
+++ trunk/programs/ide/docs/roadmap.txt	2007-01-15 13:10:13 UTC (rev 125)
@@ -3,8 +3,8 @@
 Basic Source Editor
   New 100%
   Open 100%
-  Save
-  Save As
+  Save 100%
+  Save As 100%
   Save All
   Copy 100%
   Cut 100%

Modified: trunk/programs/ide/lib/ide.class.php (124 => 125)


--- trunk/programs/ide/lib/ide.class.php	2007-01-12 19:17:13 UTC (rev 124)
+++ trunk/programs/ide/lib/ide.class.php	2007-01-15 13:10:13 UTC (rev 125)
@@ -16,6 +16,7 @@
 			'file:new',
 			'file:open',
 			'file:save',
+			'file:saveas',
 			'file:quit',
 		),
 		'_Edit' => array(
@@ -50,6 +51,7 @@
 		'file:new',
 		'file:open',
 		'file:save',
+		'file:saveas',
 		'file:quit',
 		'edit:copy',
 		'edit:cut',
@@ -71,6 +73,7 @@
 		'file:new',
 		'file:open',
 		'file:save',
+		'file:saveas',
 		'separator',
 		'edit:copy',
 		'edit:cut',
@@ -96,17 +99,12 @@
 		$vpaned2->pack2($hpaned1);
 		$hpaned1->pack2($hpaned2);
 		$this->pane_top = new CC_Ide_notebook();
-		//$this->pane_top->append_page(new GtkLabel('Top'));
 		$this->pane_bottom = new CC_Ide_notebook();
-		//$this->pane_bottom->append_page(new GtkLabel('bottom'));
 		$this->pane_left = new CC_Ide_notebook();
-		//$this->pane_left->append_page(new GtkLabel('Left'));
 		$this->pane_right = new CC_Ide_notebook();
-		//$this->pane_right->append_page(new GtkLabel('Right'));
 		$hpaned1->pack1($this->pane_left);
 		$vpaned1->pack2($this->pane_bottom);
 		$vpaned2->pack1($this->pane_top);
-		//$hpaned1->pack2(new GtkLabel('hpaned1 pack2'));
 		$hpaned2->pack1($this->editor);
 		$hpaned2->pack2($this->pane_right);
  		$this->vbox->pack_start($vpaned1);
@@ -203,13 +201,24 @@
 					'label' => '_Save',
 					'short-label' => '_Save',
 					'tooltip' => 'Save File',
-					//'callback' => array($this, 'on_save'),
+					'callback' => array($this, 'on_save'),
 					'image' => 'gtk-save',
 				)
 		);
 		$actions->add_action('file',
 				array(
 					'type' => 'action',
+					'name' => 'saveas',
+					'label' => '_Save As',
+					'short-label' => '_Save As',
+					'tooltip' => 'Save File As',
+					'callback' => array($this, 'on_save_as'),
+					'image' => 'gtk-save-as',
+				)
+		);
+		$actions->add_action('file',
+				array(
+					'type' => 'action',
 					'name' => 'new',
 					'label' => '_New',
 					'short-label' => '_New',
@@ -354,6 +363,34 @@
 		$preferences->show_all(true);
 	}
 	
+	public function on_save(){
+		$sourceView = $this->editor->get_current_page();
+		if ($sourceView !== null) {
+			$filename = $sourceView->get_data('filename');
+			if ($filename !== null) {
+				echo $filename."\n";
+				$this->editor->save_document($filename,$this->editor->get_current_page_id());
+			}else{
+				$this->on_save_as();
+			}
+		}
+	}
+	
+	public function on_save_as(){
+		$sourceView = $this->editor->get_current_page();
+		if ($sourceView !== null) {
+			$dialog = new GtkFileChooserDialog("File Save", null, Gtk::FILE_CHOOSER_ACTION_SAVE, // note 2
+        										array(Gtk::STOCK_OK, Gtk::RESPONSE_OK), null);
+        	$dialog->show_all();
+        	if ($dialog->run() == Gtk::RESPONSE_OK) {
+        	    $filename = $dialog->get_filename(); // get the input filename
+        	    $sourceView->set_data('filename',$filename);
+        	    $this->editor->save_document($filename,$this->editor->get_current_page_id());
+        	}
+        	$dialog->destroy();
+		}
+	}
+	
 }
 
 ?>
\ No newline at end of file

Modified: trunk/programs/ide/lib/ide_editor.class.php (124 => 125)


--- trunk/programs/ide/lib/ide_editor.class.php	2007-01-12 19:17:13 UTC (rev 124)
+++ trunk/programs/ide/lib/ide_editor.class.php	2007-01-15 13:10:13 UTC (rev 125)
@@ -1,11 +1,11 @@
 <?php
 
 class CC_Ide_editor extends CC_Ide_notebook {
-	
+
 	public function __construct(){
 		parent::__construct();
 	}
-	
+
 	public function new_document(){
 		static $count = 0;
 		$count++;
@@ -23,7 +23,7 @@
 		$this->show_all();
 		$this->set_current_page($id);
 	}
-	
+
 	public function open_document($filename){
 		if (file_exists($filename)) {
 			$sourceView = new CC_Ide_source();
@@ -42,56 +42,56 @@
 			$this->set_current_page($id);
 		}
 	}
-	
+
 	public function save_document($filename, $id){
-		$scroll = $this->$this->get_nth_page($id);
+		$scroll = $this->get_nth_page($id);
 		if ($scroll !== null) {
 			$sourceView = $scroll->get_child();
 			$document = $sourceView->get_text();
 			file_put_contents($filename,$document);
 		}
 	}
-	
+
 	public function get_current_page(){
 		$scroll = parent::get_current_page();
 		return $scroll->get_child();
 	}
-	
+
 	public function on_copy(){
 		$sourceView = $this->get_current_page();
 		if ($sourceView !== null){
 			$sourceView->copy();
 		}
 	}
-	
+
 	public function on_cut(){
 		$sourceView = $this->get_current_page();
 		if ($sourceView !== null){
 			$sourceView->cut();
 		}
 	}
-	
+
 	public function on_paste(){
 		$sourceView = $this->get_current_page();
 		if ($sourceView !== null){
 			$sourceView->paste();
 		}
 	}
-	
+
 	public function on_undo(){
 		$sourceView = $this->get_current_page();
 		if ($sourceView !== null){
 			$sourceView->undo();
 		}
 	}
-	
+
 	public function on_redo(){
 		$sourceView = $this->get_current_page();
 		if ($sourceView !== null){
 			$sourceView->redo();
 		}
 	}
-	
+
 }
 
 ?>
\ No newline at end of file

Modified: trunk/programs/ide/lib/ide_fileopendialog.class.php (124 => 125)


--- trunk/programs/ide/lib/ide_fileopendialog.class.php	2007-01-12 19:17:13 UTC (rev 124)
+++ trunk/programs/ide/lib/ide_fileopendialog.class.php	2007-01-15 13:10:13 UTC (rev 125)
@@ -12,7 +12,7 @@
         $hbox = new GtkHBox();
     	$this->vbox->pack_start($hbox, 0, 0);
     	$hbox->pack_start(new GtkLabel('File type:'), 0, 0);
-    	$combobox = &GtkComboBoxEntry::new_text();
+    	$combobox = GtkComboBoxEntry::new_text();
     	$combobox->append_text("All Files");
     	$i = 0;
     	foreach ($filetypes as $name => $filter){