Nicolas Cannasse 7 years ago
parent
commit
abfb52ce09
3 changed files with 12 additions and 5 deletions
  1. 1 1
      hide/prefab/NoiseGen.hx
  2. 9 2
      hide/ui/View.hx
  3. 2 2
      hide/view/FileView.hx

+ 1 - 1
hide/prefab/NoiseGen.hx

@@ -170,7 +170,7 @@ class NoiseGen extends Prefab {
 			updateTexture(tex, DEFAULT_SEED);
 		});
 		e.find("[name=dl]").click(function(_) {
-			hide.ui.Ide.inst.chooseFileSave("noise.png", function(f) if( f != null ) {
+			ctx.ide.chooseFileSave("noise.png", function(f) if( f != null ) {
 				try {
 					var data = cast(ctx.getContext(this).local2d, h2d.Bitmap).tile.getTexture().capturePixels().toPNG();
 					sys.io.File.saveBytes(f, data);

+ 9 - 2
hide/ui/View.hx

@@ -30,10 +30,17 @@ class View<T> extends hide.comp.Component {
 		ide = Ide.inst;
 	}
 
-	function watch( filePath : String, onChange : Void -> Void, ?opts : { ?checkDelete : Bool, ?keepOnRebuild : Bool } ) {
+	public function watch( filePath : String, onChange : Void -> Void, ?opts : { ?checkDelete : Bool, ?keepOnRebuild : Bool } ) {
 		if( opts == null ) opts = {};
 		ide.fileWatcher.register(filePath, onChange, opts.checkDelete);
-		watches.push({ keep : opts.keepOnRebuild, path : filePath, callb : onChange });
+		var w = { keep : opts.keepOnRebuild, path : filePath, callb : onChange };
+		watches.push(w);
+		return w;
+	}
+
+	public function unwatch(w) {
+		if( watches.remove(w) )
+			ide.fileWatcher.unregister(w.path, w.callb);
 	}
 
 	function get_props() {

+ 2 - 2
hide/view/FileView.hx

@@ -2,8 +2,8 @@ package hide.view;
 
 class FileView extends hide.ui.View<{ path : String }> {
 
-	var extension(get,never) : String;
-	var modified(default, set) : Bool;
+	public var extension(get,never) : String;
+	public var modified(default, set) : Bool;
 	var skipNextChange : Bool;
 
 	public function new(state) {