return ++this._version; // increased on every call? - bit of a kludge until we do real versioning
}
private set {
+
this._version = value;
+ this.updateUndo();
}
}
+
public string permname;
public string language;
public string content_type;
public Gee.HashMap<string,string> transStrings; // map of md5 -> string.
public Gee.HashMap<string,string> namedStrings;
+
+ public Gee.HashMap<int,string> undo_json;
+
//public Gee.HashMap<string, GLib.ListStore> errorsByType;
private Gee.ArrayList<Lsp.Diagnostic> errors;
public int error_counter {
get; private set; default = 0;
}
- public signal void changed (Node? node, string source);
-
+ //public signal void changed (Node? node, string source); (not used?)
+ public signal void navigation_tree_updated( Gee.ArrayList<Lsp.DocumentSymbol> syms);
public signal void compile_notice(string type, string file, int line, string message);
if (!GLib.FileUtils.test(this.path, GLib.FileTest.EXISTS)) {
return null;
}
- this._icon = File.new_for_path(this.path).query_info("standard::icon",GLib.FileQueryInfoFlags.NONE).get_icon();
+ try {
+ this._icon = File.new_for_path(this.path).query_info("standard::icon",GLib.FileQueryInfoFlags.NONE).get_icon();
+ } catch(GLib.Error e) {
+ return null;
+ }
return this._icon;
}
}
+
/**
* UI componenets
*
this.childfiles = new GLib.ListStore(typeof(JsRender));
//this.errorsByType = new Gee.HashMap<string, GLib.ListStore>();
this.errors = new Gee.ArrayList<Lsp.Diagnostic>((a,b) => { return a.equals(b); });
-
+ this.undo_json = new Gee.HashMap<int,string>();
}
print("Save failed");
}
}
-
-
-
-
-
-
-
+
+ bool in_undo = false;
+ public void updateUndo()
+ {
+ if (this.in_undo) {
+ return;
+ }
+ if (this.xtype == "PlainFile") {
+ // handled by gtk sourceview buffer...
+ return;
+ }
+ //GLib.debug("UNDO store %d", this.version);
+ this.undo_json.set(this.version, this.tree.toJsonString());
+ if (this.undo_json.has_key(this.version+1)) {
+ var n = this.version +1;
+ while (this.undo_json.has_key(n)) {
+ this.undo_json.unset(n++);
+ }
+
+ }
+
+ }
+
+ public bool undoStep(int step = -1) // undo back/next
+ {
+
+ if (!this.undo_json.has_key(this.version + step)) {
+ //GLib.debug("UNDO step %d failed - no version available", this.version + step);
+ return false;
+ }
+ var new_version = this.version + step;
+ var pa = new Json.Parser();
+ //GLib.debug("UNDO RESTORE : %d", this.version + step);
+ try {
+ pa.load_from_data(this.undo_json.get(new_version));
+ } catch (GLib.Error e) {
+ return false;
+ }
+ var node = pa.get_root();
+ this.in_undo = true;
+ this.loadTree(node.get_object(),2);
+ this.tree.updated_count = new_version;
+ this.in_undo = false;
+ return true;
+ }
public string jsonHasOrEmpty(Json.Object obj, string key) {
return obj.has_member(key) ?
private void addError(Lsp.Diagnostic diag)
{
- GLib.debug("ADD Error %s", diag.to_string());
+ //GLib.debug("ADD Error %s", diag.to_string());
this.errors.add(diag);
this.project.addError(this, diag);
public void removeError(Lsp.Diagnostic diag)
{
- GLib.debug("REMOVE Error %s", diag.to_string());
+ //GLib.debug("REMOVE Error %s", diag.to_string());
this.errors.remove(diag);
this.project.removeError(this, diag);
this.error_counter++;
return ret;
+ }
+
+ public void loadTree(Json.Object obj, int bjs_version = 2)
+ {
+ if (this.xtype == "PlainFile" ){
+ return;
+ }
+ Node.uid_count = 0;
+ this.tree = new Node();
+ this.tree.loadFromJson(obj,bjs_version);
+ this.tree.file = this;
+ //this.tree.version_changed.connect(() => {
+ // this.updateUndo();
+ //});
+
}
+
public abstract string language_id();
public abstract void save();
public abstract void saveHTML(string html);
public abstract string toGlade();
public abstract string targetName();
public abstract void loadItems() throws GLib.Error;
+
}
+
+
}