Use a fisheyelistview
authorEnrico Zini <enrico@enricozini.org>
Sun, 13 Dec 2009 23:47:39 +0000 (23:47 +0000)
committerEnrico Zini <enrico@enricozini.org>
Sun, 13 Dec 2009 23:47:39 +0000 (23:47 +0000)
zapolygen/zapolygen.vala

index e9ee164d5cab04fe5ea72a5e6fa972a00ed9ee64..260792824668c56cfd2e1a0da048e6d5cf790d5b 100644 (file)
@@ -20,6 +20,7 @@
 
 using GLib;
 
+/*
 protected class PolygenPage : Object
 {
        public string name { get; construct; }
@@ -63,6 +64,7 @@ protected class PolygenPage : Object
                selected(name, (string)grm_name, (string)grm_type);
        }
 }
+*/
 
 protected class PolygenRun : Gtk.VBox
 {
@@ -144,12 +146,15 @@ protected class PolygenRun : Gtk.VBox
 
 public class Polygen : Gtk.Window
 {
-       protected Gee.ArrayList<PolygenPage> pages;
+       //protected Gee.ArrayList<PolygenPage> pages;
        protected Gtk.Notebook notebook;
        protected PolygenRun result;
+       protected Gtk.ListStore grammars;
+       protected FisheyeListView grammarlist;
 
        private void add_grammar(string page, string name, string type, string title)
        {
+/*
                PolygenPage pg = null;
                foreach (PolygenPage p in pages)
                {
@@ -171,8 +176,15 @@ public class Polygen : Gtk.Window
                pg.model.set(iter, 0, name);
                pg.model.set(iter, 1, title);
                pg.model.set(iter, 2, type);
+       */
+               Gtk.TreeIter iter;
+               grammars.append (out iter);
+               grammars.set(iter, 0, "%s/%s - %s".printf(page, name, title));
+               grammars.set(iter, 1, "%s/%s".printf(page, name));
+               grammars.set(iter, 2, type);
        }
 
+       /*
        protected void on_selected(string page, string name, string type)
        {
                result.grm_name = page + "/" + name;
@@ -180,16 +192,19 @@ public class Polygen : Gtk.Window
                result.update();
                notebook.set_current_page(notebook.get_n_pages()-1);
        }
+       */
 
        public Polygen(string label, IOChannel data) throws ConvertError, IOChannelError, RegexError
        {
                title = label;
                destroy += Gtk.main_quit;
 
+               grammars = new Gtk.ListStore(3, typeof(string), typeof(string), typeof(string));
+
                var vbox = new Gtk.VBox(false, 0);
                add(vbox);
 
-               pages = new Gee.ArrayList<PolygenPage>();
+               //pages = new Gee.ArrayList<PolygenPage>();
 
                while (true)
                {
@@ -203,11 +218,18 @@ public class Polygen : Gtk.Window
                        add_grammar(np[0], np[1], vals[1], vals[2].strip());
                }
 
+               grammarlist = new FisheyeListView();
+               grammarlist.set_model(grammars);
+               grammarlist.row_activated += on_row_activated;
+
                notebook = new Gtk.Notebook();
+               notebook.append_page(grammarlist, new Gtk.Label("Grammars"));
+               /*
                foreach (PolygenPage p in pages)
                {
                        notebook.append_page(p.scroll, new Gtk.Label(p.name));
                }
+               */
                result = new PolygenRun();
                notebook.append_page(result, new Gtk.Label("Result"));
 
@@ -218,6 +240,22 @@ public class Polygen : Gtk.Window
                //select.clicked += on_click;
        }
 
+       public void on_row_activated(Gtk.TreePath path)
+       {
+               Gtk.TreeIter iter;
+               grammars.get_iter(out iter, path);
+               string grm;
+               string type;
+               grammars.get(iter, 1, out grm, 2, out type, -1);
+               stdout.printf("Clicked on %s %s\n", type, grm);
+
+               result.grm_name = grm;
+               result.grm_type = type;
+               result.update();
+               notebook.set_current_page(notebook.get_n_pages()-1);
+       }
+
+       /*
        private void on_click(Gtk.Button b)
        {
                stderr.printf("ZA\n");
@@ -229,6 +267,7 @@ public class Polygen : Gtk.Window
                        page.select();
                }
        }
+                       */
 }
 
 string homedir;