protected class PolygenPage : Object
{
- public string name { get; construct; }
- public Gtk.ListStore model;
- public Gtk.TreeView list;
- public Gtk.ScrolledWindow scroll;
- public signal void selected(string page, string name, string type);
+ public string name { get; construct; }
+ public Gtk.ListStore model;
+ public Gtk.TreeView list;
+ public Gtk.ScrolledWindow scroll;
+ public signal void selected(string page, string name, string type);
- public PolygenPage(string name)
- {
- Object(name: name);
- model = new Gtk.ListStore(3, typeof(string), typeof(string), typeof(string));
- list = new Gtk.TreeView.with_model(model);
- list.insert_column_with_attributes (-1, "Name", new Gtk.CellRendererText(), "text", 0);
- list.insert_column_with_attributes (-1, "Title", new Gtk.CellRendererText(), "text", 1);
- scroll = new Gtk.ScrolledWindow (null, null);
- scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
- scroll.add(list);
+ public PolygenPage(string name)
+ {
+ Object(name: name);
+ model = new Gtk.ListStore(3, typeof(string), typeof(string), typeof(string));
+ list = new Gtk.TreeView.with_model(model);
+ list.insert_column_with_attributes (-1, "Name", new Gtk.CellRendererText(), "text", 0);
+ list.insert_column_with_attributes (-1, "Title", new Gtk.CellRendererText(), "text", 1);
+ scroll = new Gtk.ScrolledWindow (null, null);
+ scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
+ scroll.add(list);
- list.row_activated += on_row_activated;
- }
+ 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);
+ 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);
- }
+ // Activate it
+ list.row_activated(path, col);
+ }
- private void on_row_activated(Gtk.TreeView tv, Gtk.TreePath path, Gtk.TreeViewColumn column)
- {
- Gtk.TreeIter iter;
- if (!model.get_iter(out iter, path)) return;
- Value grm_name, grm_type;
- model.get_value(iter, 0, out grm_name);
- model.get_value(iter, 2, out grm_type);
- selected(name, (string)grm_name, (string)grm_type);
- }
+ private void on_row_activated(Gtk.TreeView tv, Gtk.TreePath path, Gtk.TreeViewColumn column)
+ {
+ Gtk.TreeIter iter;
+ if (!model.get_iter(out iter, path)) return;
+ Value grm_name, grm_type;
+ model.get_value(iter, 0, out grm_name);
+ model.get_value(iter, 2, out grm_type);
+ selected(name, (string)grm_name, (string)grm_type);
+ }
}
protected class PolygenRun : Gtk.VBox
{
- public Gtk.ScrolledWindow scroll;
- protected Gtk.TextBuffer text_buffer;
- protected Gtk.TextView text;
- protected Regex unhtml;
- protected Regex seplines;
+ public Gtk.ScrolledWindow scroll;
+ protected Gtk.TextBuffer text_buffer;
+ protected Gtk.TextView text;
+ protected Regex unhtml;
+ protected Regex seplines;
- public string grm_name { get; set; }
- public string grm_type { get; set; }
+ public string grm_name { get; set; }
+ public string grm_type { get; set; }
- public PolygenRun() throws RegexError
- {
- grm_name = "";
- grm_type = "";
- unhtml = new Regex("[ ]*<[^>]+>[ ]*", 0, 0);
- seplines = new Regex("\n");
- text_buffer = new Gtk.TextBuffer(null);
- text = new Gtk.TextView.with_buffer(text_buffer);
- text.wrap_mode = Gtk.WrapMode.WORD;
- text.cursor_visible = false;
- text.editable = false;
- text.add_events(Gdk.EventMask.BUTTON_PRESS_MASK);
- text.button_press_event += on_button_press;
- scroll = new Gtk.ScrolledWindow (null, null);
- scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
- scroll.add(text);
+ public PolygenRun() throws RegexError
+ {
+ grm_name = "";
+ grm_type = "";
+ unhtml = new Regex("[ ]*<[^>]+>[ ]*", 0, 0);
+ seplines = new Regex("\n");
+ text_buffer = new Gtk.TextBuffer(null);
+ text = new Gtk.TextView.with_buffer(text_buffer);
+ text.wrap_mode = Gtk.WrapMode.WORD;
+ text.cursor_visible = false;
+ text.editable = false;
+ text.add_events(Gdk.EventMask.BUTTON_PRESS_MASK);
+ text.button_press_event += on_button_press;
+ scroll = new Gtk.ScrolledWindow (null, null);
+ scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
+ scroll.add(text);
pack_start(scroll, true, true, 0);
- }
+ }
+
+ public bool on_button_press(Gdk.EventButton event)
+ {
+ update();
+ return true;
+ }
- public bool on_button_press(Gdk.EventButton event)
- {
- update();
- return true;
- }
+ public void update()
+ {
+ if (grm_name == "") return;
+ string[] args = new string[5];
+ args[0] = "/usr/bin/polygen";
+ args[1] = "/usr/share/polygen/" + grm_name + ".grm";
+ if (grm_type == "line/text" || grm_type == "line/html")
+ {
+ args[2] = "-X";
+ args[3] = "10";
+ args[4] = null;
+ }
+ else
+ args[2] = null;
+ int pipe_out;
+ string result;
+ try {
+ Process.spawn_async_with_pipes(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);
- public void update()
- {
- if (grm_name == "") return;
- string[] args = new string[5];
- args[0] = "/usr/bin/polygen";
- args[1] = "/usr/share/polygen/" + grm_name + ".grm";
- if (grm_type == "line/text" || grm_type == "line/html")
- {
- args[2] = "-X";
- args[3] = "10";
- args[4] = null;
- }
- else
- args[2] = null;
- int pipe_out;
- string result;
- try {
- Process.spawn_async_with_pipes(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);
- Gtk.TextMark mark = text_buffer.create_mark(null, iter, true);
- text.scroll_mark_onscreen(mark);
- }
+ } catch (Error e) {
+ result = "Error: " + e.message;
+ }
+ text_buffer.text = result;
+ Gtk.TextIter iter;
+ text_buffer.get_iter_at_offset(out iter, 0);
+ Gtk.TextMark mark = text_buffer.create_mark(null, iter, true);
+ text.scroll_mark_onscreen(mark);
+ }
}
public class Polygen : Gtk.Window
{
- protected Gee.ArrayList<PolygenPage> pages;
- protected Gtk.Notebook notebook;
- protected PolygenRun result;
+ protected Gee.ArrayList<PolygenPage> pages;
+ protected Gtk.Notebook notebook;
+ protected PolygenRun result;
- private void add_grammar(string page, string name, string type, string title)
- {
- PolygenPage pg = null;
- foreach (PolygenPage p in pages)
- {
- if (p.name == page)
- {
- pg = p;
- break;
- }
- }
- if (pg == null)
- {
- pg = new PolygenPage(page);
- pg.selected += on_selected;
- pages.add(pg);
- }
+ private void add_grammar(string page, string name, string type, string title)
+ {
+ PolygenPage pg = null;
+ foreach (PolygenPage p in pages)
+ {
+ if (p.name == page)
+ {
+ pg = p;
+ break;
+ }
+ }
+ if (pg == null)
+ {
+ pg = new PolygenPage(page);
+ pg.selected += on_selected;
+ pages.add(pg);
+ }
- Gtk.TreeIter iter;
- pg.model.append (out iter);
- pg.model.set(iter, 0, name);
- pg.model.set(iter, 1, title);
- pg.model.set(iter, 2, type);
- }
+ Gtk.TreeIter iter;
+ pg.model.append (out iter);
+ pg.model.set(iter, 0, name);
+ pg.model.set(iter, 1, title);
+ pg.model.set(iter, 2, type);
+ }
- protected void on_selected(string page, string name, string type)
- {
- result.grm_name = page + "/" + name;
- result.grm_type = type;
- result.update();
- notebook.set_current_page(notebook.get_n_pages()-1);
- }
+ protected void on_selected(string page, string name, string type)
+ {
+ result.grm_name = page + "/" + name;
+ result.grm_type = type;
+ result.update();
+ notebook.set_current_page(notebook.get_n_pages()-1);
+ }
public Polygen(string label, IOChannel data) throws ConvertError, IOChannelError, RegexError
{
var vbox = new Gtk.VBox(false, 0);
add(vbox);
- pages = new Gee.ArrayList<PolygenPage>();
+ pages = new Gee.ArrayList<PolygenPage>();
- while (true)
- {
- string line;
- var res = data.read_line(out line, null, null);
- if (res != IOStatus.NORMAL) break;
- string[] vals = line.split(" ", 3);
- if (vals == null) break;
- string[] np = vals[0].split("/", 2);
- if (np == null) break;
- add_grammar(np[0], np[1], vals[1], vals[2].strip());
- }
+ while (true)
+ {
+ string line;
+ var res = data.read_line(out line, null, null);
+ if (res != IOStatus.NORMAL) break;
+ string[] vals = line.split(" ", 3);
+ if (vals == null) break;
+ string[] np = vals[0].split("/", 2);
+ if (np == null) break;
+ add_grammar(np[0], np[1], vals[1], vals[2].strip());
+ }
- notebook = new Gtk.Notebook();
- 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"));
+ notebook = new Gtk.Notebook();
+ 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"));
vbox.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;
+ //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();
- }
- }
+ 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;
public void init()
{
homedir = GLib.Environment.get_home_dir() + "/.zavai";
- try {
- var data = new IOChannel.file(homedir + "/polygen-info", "r");
- polygen = new Polygen("Polygen", data);
- data.shutdown(false);
+ try {
+ var data = new IOChannel.file(homedir + "/polygen-info", "r");
+ polygen = new Polygen("Polygen", data);
+ data.shutdown(false);
- //zavai.registry.register_applet("ui.polygen", polygen);
- //zavai.registry.getmenu("menu.misc").add_applet("ui.polygen");
- } catch (Error e) {
- polygen = null;
- //zavai.log.error("Skipping polygen plugin: " + e.message);
- }
+ //zavai.registry.register_applet("ui.polygen", polygen);
+ //zavai.registry.getmenu("menu.misc").add_applet("ui.polygen");
+ } catch (Error e) {
+ polygen = null;
+ //zavai.log.error("Skipping polygen plugin: " + e.message);
+ }
}
}