From 48f6118a9682766a58051282ea6e5fe9751c229f Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Tue, 2 Jun 2015 20:52:05 +0800 Subject: [PATCH] src/Builder4/Editor.bjs src/Builder4/Editor.vala --- src/Builder4/Editor.bjs | 2 +- src/Builder4/Editor.vala | 33 ++++++++++----------------------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/Builder4/Editor.bjs b/src/Builder4/Editor.bjs index 9aea7f278..3b5460a33 100644 --- a/src/Builder4/Editor.bjs +++ b/src/Builder4/Editor.bjs @@ -9,7 +9,6 @@ "items" : [ { "# Xcls_MainWindow window" : "null", - "| Gee.ArrayList search" : "(string txt) {\n\n\tvar s = new Gtk.SourceSearchSettings();\n\t\n\tvar sctx = new Gtk.SourceSearchContext(this.buffer.el,s);\n\tsctx.set_highlight(true);\n\ts.set_search_text(txt);\n\twhile (sctx.get_occurence_position(st, en)> -1) {\n\n\n\tvar ret = new Gee.ArrayList();\n\n\tvar str = this.buffer.toString();\n\n\tvar lines = str.split(\"\\n\");\n\tfor (var i = 0 ; i < lines.length; i++) {\n\tif (lines[i].contains(txt)) {\n\t\tret.add(i);\n\t}\n \n\t}\n\treturn ret;\n}\n", "| bool saveContents" : " () {\n \n \n if (_this.file == null) {\n return true;\n }\n \n \n \n \n \n var str = _this.buffer.toString();\n \n _this.buffer.checkSyntax();\n \n \n \n // LeftPanel.model.changed( str , false);\n _this.dirty = false;\n _this.save_button.el.sensitive = false;\n \n // find the text for the node..\n if (_this.file.xtype != \"PlainFile\") {\n if (ptype == \"listener\") {\n this.node.listeners.set(key,str);\n \n } else {\n this.node.props.set(key,str);\n }\n } else {\n _this.file.setSource( str );\n }\n \n // call the signal..\n this.save();\n \n return true;\n\n} ", "# string activeEditor" : "\"\"", "| void scroll_to_line" : "(int line) {\n\n\tGLib.Timeout.add(500, () => {\n \n\t\tvar buf = this.view.el.get_buffer();\n\n\t\tvar sbuf = (Gtk.SourceBuffer) buf;\n\n\n\t\tGtk.TextIter iter; \n\t\tsbuf.get_iter_at_line(out iter, line);\n\t\tthis.view.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);\n\t\treturn false;\n\t}); \n}\n", @@ -17,6 +16,7 @@ "# int pos_root_y" : "", "# string ptype" : "\"\"", "bool hexpand" : true, + "| int search" : "(string txt) {\n\n\tvar s = new Gtk.SourceSearchSettings();\n\t\n\tthis.sourcecontext = new Gtk.SourceSearchContext(this.buffer.el,s);\n\tsctx.set_highlight(true);\n\ts.set_search_text(txt);\n\treturn this.sourcecontext.get_occurences_count();\n\n}\n", "# string key" : "\"\"", "* pack" : "add", "xtype" : "Box", diff --git a/src/Builder4/Editor.vala b/src/Builder4/Editor.vala index eeadbcd67..9ff8682db 100644 --- a/src/Builder4/Editor.vala +++ b/src/Builder4/Editor.vala @@ -61,29 +61,6 @@ public class Editor : Object } // user defined functions - public Gee.ArrayList search (string txt) { - - var s = new Gtk.SourceSearchSettings(); - - var sctx = new Gtk.SourceSearchContext(this.buffer.el,s); - sctx.set_highlight(true); - s.set_search_text(txt); - while (sctx.get_occurence_position(st, en)> -1) { - - - var ret = new Gee.ArrayList(); - - var str = this.buffer.toString(); - - var lines = str.split("\n"); - for (var i = 0 ; i < lines.length; i++) { - if (lines[i].contains(txt)) { - ret.add(i); - } - - } - return ret; - } public bool saveContents () { @@ -138,6 +115,16 @@ public class Editor : Object return false; }); } + public int search (string txt) { + + var s = new Gtk.SourceSearchSettings(); + + this.sourcecontext = new Gtk.SourceSearchContext(this.buffer.el,s); + sctx.set_highlight(true); + s.set_search_text(txt); + return this.sourcecontext.get_occurences_count(); + + } public void show (JsRender.JsRender file, JsRender.Node? node, string ptype, string key) { this.file = file; -- 2.39.2