Added dbus config
[gregoa/zavai.git] / src / app_polygen.vala
index b3a997a976394adff725870562dc9036f9db770f..719ba886e880084df6300ccd5c15a72a5fd2f56b 100644 (file)
@@ -46,6 +46,17 @@ protected class PolygenPage : Object
         list.row_activated += on_row_activated;
     }
 
+    public void select()
+    {
+        // Get currently selected/focused
+        Gtk.TreePath path;
+        Gtk.TreeViewColumn col;
+        list.get_cursor(out path, out col);
+
+        // Activate it
+        list.row_activated(path, col);
+    }
+
     private void on_row_activated(Gtk.TreeView tv, Gtk.TreePath path, Gtk.TreeViewColumn column)
     {
         Gtk.TreeIter iter;
@@ -108,21 +119,25 @@ protected class PolygenRun : Gtk.VBox
         else
             args[2] = null;
         int pipe_out;
-        Process.spawn_async_with_pipes(config.homedir, args, null, 0, null, null, null, out pipe_out, null);
-        IOChannel ch = new IOChannel.unix_new(pipe_out);
         string result;
-        size_t res_len;
-        ch.read_to_end(out result, out res_len);
-        ch.shutdown(false);
+        try {
+            Process.spawn_async_with_pipes(config.homedir, args, null, 0, null, null, null, out pipe_out, null);
+            IOChannel ch = new IOChannel.unix_new(pipe_out);
+            size_t res_len;
+            ch.read_to_end(out result, out res_len);
+            ch.shutdown(false);
+
+            if (grm_type == "line/html" || grm_type == "block/html")
+            {
+                result = unhtml.replace(result, (long)res_len, 0, " ", 0);
+            } else if (grm_type == "line/text") {
+                result = seplines.replace(result, (long)res_len, 0, "\n\n", 0);
+            }
+            
 
-        if (grm_type == "line/html" || grm_type == "block/html")
-        {
-            result = unhtml.replace(result, (long)res_len, 0, " ", 0);
-        } else if (grm_type == "line/text") {
-            result = seplines.replace(result, (long)res_len, 0, "\n\n", 0);
+        } catch (Error e) {
+            result = "Error: " + e.message;
         }
-        
-
         text_buffer.text = result;
         Gtk.TextIter iter;
         text_buffer.get_iter_at_offset(out iter, 0);
@@ -196,7 +211,23 @@ public class Polygen : Applet
         notebook.append_page(result, new Gtk.Label("Result"));
 
                pack_start(notebook, true, true, 0);
+
+        Gtk.Button select = new Gtk.Button.with_label("Select");
+        button_box.pack_start(select, true, true, 0);
+        select.clicked += on_click;
        }
+
+    private void on_click(Gtk.Button b)
+    {
+        stderr.printf("ZA\n");
+        if (notebook.page >= pages.size)
+            result.update(); // If we are in the result page, just update
+        else
+        {
+            PolygenPage page = pages[notebook.page];
+            page.select();
+        }
+    }
 }
 
 Polygen polygen;
@@ -209,30 +240,11 @@ public void init()
         data.shutdown(false);
 
         zavai.registry.register_applet("ui.polygen", polygen);
-        zavai.registry.getmenu("menu.main").add_applet("ui.polygen");
-    } catch (FileError e) {
+        zavai.registry.getmenu("menu.misc").add_applet("ui.polygen");
+    } catch (Error e) {
         polygen = null;
         zavai.log.error("Skipping polygen plugin: " + e.message);
     }
-
-    /*
-       window_list = new WindowList("Current apps");
-       zavai.registry.register_applet("wm.list", window_list);
-       zavai.registry.getmenu("menu.main").add_applet("wm.list");
-
-       try {
-               launcher = new Launcher("Run program");
-       } catch (Error e) {
-               zavai.log.error("Not running launcher: " + e.message);
-               launcher = null;
-       }
-
-       if (launcher != null)
-       {
-               zavai.registry.register_applet("wm.launcher", launcher);
-               zavai.registry.getmenu("menu.main").add_applet("wm.launcher");
-       }
-    */
 }
 
 }