seed r222 - in trunk: examples/ide tests



Author: hortont
Date: Sun Nov  9 09:59:57 2008
New Revision: 222
URL: http://svn.gnome.org/viewvc/seed?rev=222&view=rev

Log:
Fixed test maker w/ stderr; fleshing out IDE; begun work on IDEMessageArea.


Added:
   trunk/examples/ide/ide-messagearea.js
Modified:
   trunk/examples/ide/ide-actions.js
   trunk/examples/ide/ide-sourceview.js
   trunk/examples/ide/ide-tab.js
   trunk/examples/ide/ide-tabview.js
   trunk/examples/ide/ide-toolbar.js
   trunk/examples/ide/main.js
   trunk/tests/make-test.py

Modified: trunk/examples/ide/ide-actions.js
==============================================================================
--- trunk/examples/ide/ide-actions.js	(original)
+++ trunk/examples/ide/ide-actions.js	Sun Nov  9 09:59:57 2008
@@ -13,12 +13,10 @@
     file_chooser.add_button("Open", Gtk.ResponseType.accept);
     file_chooser.set_action(Gtk.FileChooserAction.open);
     
-    var current_tab = tab_view.get_nth_page(tab_view.page);
-    
     if(file_chooser.run() == Gtk.ResponseType.accept)
     {
-        if(current_tab.source_view.filename == "")
-            current_tab.source_view.load_file(file_chooser.get_filename(), current_tab);
+        if(current_tab().source_view.filename == "" && !current_tab().source_view.edited)
+            current_tab().source_view.load(file_chooser.get_filename());
         else
             tab_view.create_tab(file_chooser.get_filename());
     }
@@ -28,67 +26,32 @@
 
 function save_file()
 {
-    var current_tab = tab_view.get_nth_page(tab_view.page);
-    
-    if(current_tab.source_view.filename == "")
-    {
-        var file_chooser = new Gtk.FileChooserDialog();
-        var file_filter = new Gtk.FileFilter();
-        file_filter.add_mime_type("text/javascript");
-        file_chooser.set_filter(file_filter);
-        file_chooser.add_button("Cancel", Gtk.ResponseType.cancel);
-        file_chooser.add_button("Save", Gtk.ResponseType.accept);
-        file_chooser.set_action(Gtk.FileChooserAction.save);
-
-        if(file_chooser.run() == Gtk.ResponseType.accept)
-        {
-            current_tab.source_view.update_filename(file_chooser.get_filename(), current_tab);
-            update_window(file_chooser.get_filename());
-        }
-
-        file_chooser.destroy();
-    }
-    
-    if(current_tab.source_view.filename != "")
-        Gio.simple_write(current_tab.source_view.filename, current_tab.source_view.get_buffer().text);
+    current_tab().source_view.save();
 }
 
 function undo()
 {
-    var current_tab = tab_view.get_nth_page(tab_view.page);
-    current_tab.source_view.get_buffer().undo();
-    toolbar.update_undo_state(current_tab.source_view);
+    current_tab().source_view.get_buffer().undo();
+    current_tab().source_view.update_undo_state();
 }
 
 function redo()
 {
-    var current_tab = tab_view.get_nth_page(tab_view.page);
-    current_tab.source_view.get_buffer().redo();
-    toolbar.update_undo_state(current_tab.source_view);
+    current_tab().source_view.get_buffer().redo();
+    current_tab().source_view.update_undo_state();
 }
 
 function execute()
 {
-    var current_tab = tab_view.get_nth_page(tab_view.page);
-    
-    if(current_tab.source_view.filename == "")
-        save_file();
-    
-    try
-    {
-    	Gio.simple_write(current_tab.source_view.filename, current_tab.source_view.get_buffer().text);
-    }
-    catch(e)
-    {
-    	Seed.print(e.name + " " + e.message); // TODO: popup
-    }
+    if(current_tab().source_view.save())
+    	return;
     
-    current_tab.terminal.reset(true, true);
-    current_tab.terminal.fork_command("/bin/dash");
+    current_tab().terminal.reset(true, true);
+    current_tab().terminal.fork_command("/bin/dash");
     
-    var command = "clear ; env seed \"" + current_tab.source_view.filename + "\" ; sleep 1d\n";
+    var command = "clear ; /usr/bin/env seed \"" + current_tab().source_view.filename + "\" ; sleep 1d\n";
     
-    current_tab.terminal.feed_child(command, command.length);
+    current_tab().terminal.feed_child(command, command.length);
 }
 
 function close_tab()

Added: trunk/examples/ide/ide-messagearea.js
==============================================================================
--- (empty file)
+++ trunk/examples/ide/ide-messagearea.js	Sun Nov  9 09:59:57 2008
@@ -0,0 +1,87 @@
+#!/usr/bin/env seed
+
+Seed.import_namespace("Gtk");
+
+Gtk.init(null, null);
+
+function style_set()
+{
+	var win = new Gtk.Window({type: Gtk.WindowType.popup});
+	win.set_name("gtk-tooltip");
+	win.ensure_style();
+	this.set_style(win.get_style());
+	
+	this.queue_draw();
+}
+
+function draw_box(widget, event)
+{
+	var x = Gtk.allocation_get_x(widget.get_allocation());
+	var y = Gtk.allocation_get_y(widget.get_allocation());
+	var width = Gtk.allocation_get_width(widget.get_allocation());
+	var height = Gtk.allocation_get_height(widget.get_allocation());
+
+	Gtk.paint_flat_box(widget.style,
+					   widget.window,
+					   Gtk.StateType.normal,
+					   Gtk.ShadowType.out,
+					   null,
+					   widget,
+					   "tooltip",
+					   x + 1, y + 1,
+					   width - 2, height - 2);
+}
+
+IDEMessageAreaType = {
+    parent: Gtk.HBox,
+    name: "IDEMessageArea",
+    class_init: function(klass, prototype)
+    {
+    },
+    instance_init: function(klass)
+    {
+    	this.signal.expose_event.connect(draw_box, this);
+    	
+		this.app_paintable = true;
+		this.border_width = 8;
+
+		this.inner_box = new Gtk.HBox();
+		this.pack_start(this.inner_box, true, true);
+		this.inner_box.signal.style_set.connect(style_set, this);
+		
+		this.icon = new Gtk.Image({stock: Gtk.STOCK_DIALOG_ERROR,
+								   icon_size: Gtk.IconSize.dialog});
+		this.text = new Gtk.Label();
+		this.detail = new Gtk.Label();
+		
+		this.text.use_markup = true;
+		this.detail.use_markup = true;
+		
+		this.icon.set_alignment(0.5, 0.5);
+		this.text.set_alignment(0, 0.5);
+		this.detail.set_alignment(0, 0.5);
+		
+		this.text_vbox = new Gtk.VBox({border_width: 3});
+		this.text_vbox.pack_start(this.text, true, true, 4);
+		this.text_vbox.pack_start(this.detail, true, true, 4);
+		
+		this.close = Gtk.Button.new_from_stock(Gtk.STOCK_CLOSE);
+		this.button_vbox = new Gtk.VBox({border_width: 3});
+		this.button_vbox.pack_start(this.close, true, false);
+		
+		this.inner_box.pack_start(this.icon);
+		this.inner_box.pack_start(this.text_vbox, true, true);
+		this.inner_box.pack_start(this.button_vbox);
+    }};
+
+IDEMessageArea = new GType(IDEMessageAreaType);
+
+var window = new Gtk.Window();
+window.resize(600, 80);
+var ma = new IDEMessageArea();
+ma.text.label = "<b>Could not save the file <i>/home/hortont/tim.js</i>.</b>";
+ma.detail.label = "<small>You do not have the permissions necessary to save the file.\nPlease check that you typed the location correctly and try again.</small>";
+window.add(ma);
+window.show_all();
+
+Gtk.main();

Modified: trunk/examples/ide/ide-sourceview.js
==============================================================================
--- trunk/examples/ide/ide-sourceview.js	(original)
+++ trunk/examples/ide/ide-sourceview.js	Sun Nov  9 09:59:57 2008
@@ -15,9 +15,9 @@
                 tab.header.label.label = "Untitled";
         }
         
-        prototype.load_file = function(new_filename, tab)
+        prototype.load = function(new_filename)
         {
-            this.update_filename(new_filename, tab);
+            this.update_filename(new_filename, this.tab);
             
             if(this.filename == "")
                 return;
@@ -29,11 +29,55 @@
                 buf.begin_not_undoable_action();
                 buf.text = Gio.simple_read(this.filename);
                 buf.end_not_undoable_action();
+                
+                this.update_edited(false);
+                
+                return 0;
             }
             catch(e)
             {
-                Seed.print(e.name + " " + e.message);
+                Seed.print(e.name + " " + e.message); //TODO: popup
             }
+            
+            return -1;
+        }
+        
+        prototype.save = function()
+        {
+        	if(this.filename == "")
+			{
+				var file_chooser = new Gtk.FileChooserDialog();
+				var file_filter = new Gtk.FileFilter();
+				file_filter.add_mime_type("text/javascript");
+				file_chooser.set_filter(file_filter);
+				file_chooser.add_button("Cancel", Gtk.ResponseType.cancel);
+				file_chooser.add_button("Save", Gtk.ResponseType.accept);
+				file_chooser.set_action(Gtk.FileChooserAction.save);
+
+				if(file_chooser.run() == Gtk.ResponseType.accept)
+				{
+					this.update_filename(file_chooser.get_filename(), current_tab());
+					update_window(file_chooser.get_filename());
+				}
+
+				file_chooser.destroy();
+			}
+	
+			if(this.filename != "")
+			{
+				try
+				{
+					Gio.simple_write(this.filename, this.get_buffer().text);
+					this.update_edited(false);
+					return 0;
+				}
+				catch(e)
+				{
+					Seed.print("had a problem writing!!"); // TODO: popup
+				}
+			}
+			
+			return -1;
         }
         
         prototype.exception_clear = function ()
@@ -57,10 +101,11 @@
         
         prototype.text_changed = function(sbuf)
         {
-            toolbar.update_undo_state(this);
+            this.update_undo_state();
+            this.update_edited(true);
             
             var text = sbuf.text.replace(new RegExp("#!.*"), "");
-    
+
             try
             {
                 Seed.check_syntax(text);
@@ -73,10 +118,32 @@
             
             this.exception_clear();
         }
+        
+        prototype.update_undo_state = function ()
+        {
+            actions.get_action("undo").sensitive = this.get_buffer().can_undo;
+            actions.get_action("redo").sensitive = this.get_buffer().can_redo;
+        }
+        
+        prototype.update_edited = function (edit)
+        {
+	        var current_label = this.tab.header.label;
+	
+	        if(edit)
+	        {
+		        if(!this.edited)
+			        current_label.label = "*" + current_label.label;
+	        }
+	        else if(this.edited && current_label.label[0] == "*")
+		        current_label.label = current_label.label.substr(1);
+		    
+		    this.edited = edit;
+        }
     },
     instance_init: function(klass)
     {
         this.filename = "";
+        this.edited = false;
         
         this.set_show_line_numbers(true);
         this.set_show_right_margin(true);

Modified: trunk/examples/ide/ide-tab.js
==============================================================================
--- trunk/examples/ide/ide-tab.js	(original)
+++ trunk/examples/ide/ide-tab.js	Sun Nov  9 09:59:57 2008
@@ -20,6 +20,7 @@
     instance_init: function(klass)
     {
         this.source_view = new IDESourceView();
+        this.source_view.tab = this;
         this.terminal = new Vte.Terminal();
         this.pane = new Gtk.VPaned();
         

Modified: trunk/examples/ide/ide-tabview.js
==============================================================================
--- trunk/examples/ide/ide-tabview.js	(original)
+++ trunk/examples/ide/ide-tabview.js	Sun Nov  9 09:59:57 2008
@@ -9,7 +9,7 @@
             
             tab.header = new IDETabHeader();
             tab.header.set_tab(tab);
-            tab.source_view.load_file(filename, tab);
+            tab.source_view.load(filename);
             
             this.append_page(tab, tab.header);
             this.set_tab_reorderable(tab, true);
@@ -22,6 +22,10 @@
         
         prototype.close_tab = function (button)
         {
+            if(this.source_view.edited)
+                Seed.print("oh noes!!");
+            // TODO: warn first!! return if they don't want to...
+            
             tab_view.remove_page(tab_view.page_num(this));
             
             if(tab_view.get_n_pages() == 0)
@@ -32,7 +36,7 @@
         {
             var my_page = notebook.get_nth_page(n);
             update_window(my_page.source_view.filename);
-            toolbar.update_undo_state(my_page.source_view);
+            my_page.source_view.update_undo_state(my_page.source_view);
         }
     },
     instance_init: function(klass)

Modified: trunk/examples/ide/ide-toolbar.js
==============================================================================
--- trunk/examples/ide/ide-toolbar.js	(original)
+++ trunk/examples/ide/ide-toolbar.js	Sun Nov  9 09:59:57 2008
@@ -3,11 +3,7 @@
     name: "IDEToolbar",
     class_init: function(klass, prototype)
     {
-        prototype.update_undo_state = function (source_view)
-        {
-            toolbar.undo_button.sensitive = source_view.get_buffer().can_undo;
-            toolbar.redo_button.sensitive = source_view.get_buffer().can_redo;
-        }
+
     },
     instance_init: function(klass)
     {

Modified: trunk/examples/ide/main.js
==============================================================================
--- trunk/examples/ide/main.js	(original)
+++ trunk/examples/ide/main.js	Sun Nov  9 09:59:57 2008
@@ -18,7 +18,7 @@
 Seed.include("ide-tabview.js");
 Seed.include("ide-toolbar.js");
 
-// TODO: put this in a subclass of the window
+// TODO: put this in a subclass of the window and give it a tab (read it out of the header)
 function update_window(new_filename)
 {
     var shortfilename = new_filename.split("/").slice(-1);
@@ -29,6 +29,11 @@
         window.title = "Seed IDE";
 }
 
+function current_tab()
+{
+	return tab_view.get_nth_page(tab_view.page);
+}
+
 var window = new Gtk.Window();
 window.resize(700, 700);
 window.signal.hide.connect(Gtk.main_quit);

Modified: trunk/tests/make-test.py
==============================================================================
--- trunk/tests/make-test.py	(original)
+++ trunk/tests/make-test.py	Sun Nov  9 09:59:57 2008
@@ -42,7 +42,7 @@
 outf.write("// Returns: 0\n")
 outf.write("// STDIN:" + test_in + "\n")
 outf.write("// STDOUT:" + sanitize("".join(out.readlines()).rstrip()) + "\n")
-outf.write("// STDERR:" + sanitize("".join(out.readlines()).rstrip()) + "\n")
+outf.write("// STDERR:" + sanitize("".join(err.readlines()).rstrip()) + "\n")
 
 if(test_in != ""):
 	outf.write("".join(test_code[2:]))



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]