Quellcode durchsuchen

Settings: wip project settings

lviguier vor 9 Monaten
Ursprung
Commit
6401551de4
5 geänderte Dateien mit 192 neuen und 61 gelöschten Zeilen
  1. 2 1
      bin/app.html
  2. 5 2
      hide/Ide.hx
  3. 108 0
      hide/view/settings/ProjectSettings.hx
  4. 50 58
      hide/view/settings/Settings.hx
  5. 27 0
      hide/view/settings/UserSettings.hx

+ 2 - 1
bin/app.html

@@ -109,7 +109,8 @@
 		<div class="content">
 		</div>
 		<separator></separator>
-		<menu label="Show" class="showSettings"></menu>
+		<menu label="User settings" class="user-settings"></menu>
+		<menu label="Project settings" class="project-settings"></menu>
 	</menu>
 </xml>
 <script src="hide.js"></script>

+ 5 - 2
hide/Ide.hx

@@ -1326,8 +1326,11 @@ class Ide extends hide.tools.IdeData {
 		});
 
 		var settings = menu.find(".settings");
-		settings.find('.showSettings').click(function(_) {
-			open("hide.view.Settings", {});
+		settings.find('.user-settings').click(function(_) {
+			open("hide.view.settings.UserSettings", {});
+		});
+		settings.find('.project-settings').click(function(_) {
+			open("hide.view.settings.ProjectSettings", {});
 		});
 
 		window.menu = new hide.ui.Menu(menu).root;

+ 108 - 0
hide/view/settings/ProjectSettings.hx

@@ -0,0 +1,108 @@
+package hide.view.settings;
+
+typedef LocalSettings = {
+	var file : String;
+	var content : Dynamic;
+	var children : Array<LocalSettings>;
+}
+
+class ProjectSettings extends Settings {
+	public static var SETTINGS_FILE = "props.json";
+
+	var settings : Array<LocalSettings>;
+
+	public function new( ?state ) {
+		super(state);
+
+		var localSettings = getPropsFiles(ide.projectDir);
+
+		var general = new hide.view.settings.Settings.Categorie("General");
+		categories.push(general);
+
+		for (f in Reflect.fields(localSettings[0].content)) {
+			var cat = general;
+			if (f.split('.').length > 1) {
+				var catName = sublimeName(f.split('.')[0]);
+				cat = getCategorie(catName);
+				if (cat == null) {
+					cat = new hide.view.settings.Settings.Categorie(catName);
+					categories.push(cat);
+				}
+			}
+
+			var settingName = sublimeName(f.split('.')[f.split('.').length - 1]);
+			var type = Type.typeof(Reflect.field(localSettings[0].content, f));
+			var settingElement = switch (type) {
+				case TClass(String):
+					new Element('<input/>');
+				case TBool:
+					new Element('<input type="checkbox"/>');
+				case TInt, TFloat:
+					new Element('<input type="number"/>');
+				default:
+					new Element('<p>EDITION NOT SUPPORTED</p>');
+			}
+
+			cat.add(settingName, settingElement, null);
+		}
+
+		categories.sort(function(p1, p2) return (p1.name > p2.name) ? 1 : -1);
+	}
+
+	override function getTitle() {
+		return "Project Settings";
+	}
+
+	function getPropsFiles(path: String) : Array<LocalSettings> {
+		var res : Array<LocalSettings> = [];
+
+		var settingsPath = '${path}/${ProjectSettings.SETTINGS_FILE}';
+
+		var localSettings : LocalSettings = null;
+		if (sys.FileSystem.exists(settingsPath)) {
+			var content = sys.io.File.getContent(settingsPath);
+			var obj = try haxe.Json.parse(content) catch( e : Dynamic ) throw "Failed to parse " + settingsPath + "("+e+")";
+			localSettings = { file: settingsPath, content: obj, children: null };
+		}
+
+		for (f in sys.FileSystem.readDirectory(path)) {
+			if (!sys.FileSystem.isDirectory('${path}/${f}'))
+				continue;
+
+			var children = getPropsFiles('${path}/${f}');
+			if (children == null)
+				continue;
+
+			res = res.concat(children);
+		}
+
+		if (localSettings == null)
+			return res;
+
+		localSettings.children = res;
+		return [localSettings];
+	}
+
+	function sublimeName(string : String) {
+		var res = "";
+		for (cIdx in 0...string.length) {
+			var c = string.charAt(cIdx);
+
+			if (cIdx == 0) {
+				res += c.toUpperCase();
+				continue;
+			}
+
+			if (c == c.toUpperCase()) {
+				res += " " + c;
+				continue;
+			}
+
+			res += c;
+		}
+
+		return res;
+	}
+
+	static var _ = hide.ui.View.register(ProjectSettings);
+}

+ 50 - 58
hide/view/Settings.hx → hide/view/settings/Settings.hx

@@ -1,4 +1,41 @@
-package hide.view;
+package hide.view.settings;
+
+class Categorie {
+	public var name : String;
+	public var element : Element;
+
+	public function new(name: String) {
+		this.name = name;
+		this.element = new Element('
+		<div>
+			<h1>${name}</h1>
+		</div>');
+	}
+
+	public function add(settingsName: String, editElement: Element, value: Dynamic, ?onChange : Dynamic -> Void) {
+		var el = new Element('<dl><dt>${settingsName}</dt><dd class="edit"></dd></dl>');
+		el.find('.edit').append(editElement);
+
+		if (editElement.is('input[type="checkbox"]'))
+			editElement.prop('checked', value);
+		else
+			editElement.val(value);
+
+		this.element.append(el);
+
+		if (onChange != null)
+			editElement.on('change', function(v) {
+				var v : Dynamic = null;
+				if (editElement.is('input[type="checkbox"]'))
+					v = editElement.prop('checked');
+				else
+					v = Std.parseFloat(editElement.val());
+
+				onChange(v);
+				Ide.inst.config.global.save();
+			} );
+	}
+}
 
 class Settings extends hide.ui.View<{}> {
 	public var categories : Array<Categorie>;
@@ -7,20 +44,6 @@ class Settings extends hide.ui.View<{}> {
 		super(state);
 
 		categories = [];
-
-		var general = new Categorie("General");
-		general.add("Auto-save prefabs before closing", new Element('<input type="checkbox"/>'), Ide.inst.ideConfig.autoSavePrefab, (v) -> Ide.inst.ideConfig.autoSavePrefab = v);
-		categories.push(general);
-
-		var search = new Categorie("Search");
-		search.add("Typing debounce threshold (ms)", new Element('<input type="number"/>'), Ide.inst.ideConfig.typingDebounceThreshold, (v) -> Ide.inst.ideConfig.typingDebounceThreshold = v);
-		search.add("Close search on file opening", new Element('<input type="checkbox"/>'), Ide.inst.ideConfig.closeSearchOnFileOpen, (v) -> Ide.inst.ideConfig.closeSearchOnFileOpen = v);
-		categories.push(search);
-
-		var performance = new Categorie("Performance");
-		performance.add("Track gpu alloc", new Element('<input type="checkbox"/>'), Ide.inst.ideConfig.trackGpuAlloc, (v) -> Ide.inst.ideConfig.trackGpuAlloc = v);
-		performance.add("Culling distance factor", new Element('<input type="number"/>'), Ide.inst.ideConfig.cullingDistanceFactor, (v) -> Ide.inst.ideConfig.cullingDistanceFactor = v);
-		categories.push(performance);
 	}
 
 	override function onDisplay() {
@@ -40,12 +63,9 @@ class Settings extends hide.ui.View<{}> {
 			cEl.on('click', function(e){ selectCategorie(c); });
 		}
 
-		// By default open general settings
-		selectCategorie(categories[0]);
-	}
-
-	override function getTitle() {
-		return "Settings";
+		// By default open first categorie
+        if (categories.length > 0)
+		    selectCategorie(categories[0]);
 	}
 
 	function selectCategorie(c : Categorie) {
@@ -55,42 +75,14 @@ class Settings extends hide.ui.View<{}> {
 		content.append(c.element);
 	}
 
-	static var _ = hide.ui.View.register(Settings);
-}
-
-class Categorie {
-	public var name : String;
-	public var element : Element;
-
-	public function new(name: String) {
-		this.name = name;
-		this.element = new Element('
-		<div>
-			<h1>${name}</h1>
-		</div>');
-	}
-
-	public function add(settingsName: String, editElement: Element, value: Dynamic, ?onChange : Dynamic -> Void) {
-		var el = new Element('<dl><dt>${settingsName}</dt><dd class="edit"></dd></dl>');
-		el.find('.edit').append(editElement);
-
-		if (editElement.is('input[type="checkbox"]'))
-			editElement.prop('checked', value);
-		else
-			editElement.val(value);
-
-		this.element.append(el);
-
-		if (onChange != null)
-			editElement.on('change', function(v) {
-				var v : Dynamic = null;
-				if (editElement.is('input[type="checkbox"]'))
-					v = editElement.prop('checked');
-				else
-					v = Std.parseFloat(editElement.val());
 
-				onChange(v);
-				Ide.inst.config.global.save();
-			} );
+	settings.register("oeoeoe", [Array<zae])
+	function getCategorie(name : String) {
+		var res = null;
+		for (c in categories) {
+			if (c.name == name)
+				return c;
+		}
+		return res;
 	}
-}
+}

+ 27 - 0
hide/view/settings/UserSettings.hx

@@ -0,0 +1,27 @@
+package hide.view.settings;
+
+class UserSettings extends Settings {
+	public function new( ?state ) {
+		super(state);
+
+		var general = new hide.view.settings.Settings.Categorie("General");
+		general.add("Auto-save prefabs before closing", new Element('<input type="checkbox"/>'), Ide.inst.ideConfig.autoSavePrefab, (v) -> Ide.inst.ideConfig.autoSavePrefab = v);
+		categories.push(general);
+
+		var search = new hide.view.settings.Settings.Categorie("Search");
+		search.add("Typing debounce threshold (ms)", new Element('<input type="number"/>'), Ide.inst.ideConfig.typingDebounceThreshold, (v) -> Ide.inst.ideConfig.typingDebounceThreshold = v);
+		search.add("Close search on file opening", new Element('<input type="checkbox"/>'), Ide.inst.ideConfig.closeSearchOnFileOpen, (v) -> Ide.inst.ideConfig.closeSearchOnFileOpen = v);
+		categories.push(search);
+
+		var performance = new hide.view.settings.Settings.Categorie("Performance");
+		performance.add("Track gpu alloc", new Element('<input type="checkbox"/>'), Ide.inst.ideConfig.trackGpuAlloc, (v) -> Ide.inst.ideConfig.trackGpuAlloc = v);
+		performance.add("Culling distance factor", new Element('<input type="number"/>'), Ide.inst.ideConfig.cullingDistanceFactor, (v) -> Ide.inst.ideConfig.cullingDistanceFactor = v);
+		categories.push(performance);
+	}
+
+	override function getTitle() {
+		return "User Settings";
+	}
+
+	static var _ = hide.ui.View.register(UserSettings);
+}