Browse Source

Move Recents to top of New... contextmenu option (#175)

Leonardo Jeanteur 4 years ago
parent
commit
f782582f99
3 changed files with 22 additions and 18 deletions
  1. 12 18
      hide/comp/SceneEditor.hx
  2. 5 0
      hide/view/FXEditor.hx
  3. 5 0
      hide/view/Prefab.hx

+ 12 - 18
hide/comp/SceneEditor.hx

@@ -2180,6 +2180,18 @@ class SceneEditor {
 		return edit;
 	}
 
+	function getNewRecentContextMenu(current, ?onMake: PrefabElement->Void=null) : Array<hide.comp.ContextMenu.ContextMenuItem> {
+		var parent = current == null ? sceneData : current;
+		var grecent = [];
+		var recents : Array<String> = ide.currentConfig.get("sceneeditor.newrecents", []);
+		for( g in recents) {
+			var pmodel = hrt.prefab.Library.getRegistered().get(g);
+			if (checkAllowParent({cl : g, inf : pmodel.inf}, parent))
+				grecent.push(getNewTypeMenuItem(g, parent, onMake));
+		}
+		return grecent;
+	}
+
 	// Override
 	function getNewContextMenu(current: PrefabElement, ?onMake: PrefabElement->Void=null, ?groupByType=true ) : Array<hide.comp.ContextMenu.ContextMenuItem> {
 		var newItems = new Array<hide.comp.ContextMenu.ContextMenuItem>();
@@ -2187,25 +2199,9 @@ class SceneEditor {
 		allRegs.remove("reference");
 		allRegs.remove("unknown");
 		var parent = current == null ? sceneData : current;
-		var allowChildren = null;
-		{
-			var cur = parent;
-			while( allowChildren == null && cur != null ) {
-				allowChildren = cur.getHideProps().allowChildren;
-				cur = cur.parent;
-			}
-		}
 
-		var grecent = [];
 		var groups = [];
 		var gother = [];
-		var recents : Array<String> = ide.currentConfig.get("sceneeditor.newrecents", []);
-		for( g in recents) {
-			var pmodel = hrt.prefab.Library.getRegistered().get(g);
-			if (checkAllowParent({cl : g, inf : pmodel.inf}, parent)) 
-				grecent.push(getNewTypeMenuItem(g, parent, onMake));
-
-		}
 
 		for( g in (view.config.get("sceneeditor.newgroups") : Array<String>) ) {
 			var parts = g.split("|");
@@ -2254,8 +2250,6 @@ class SceneEditor {
 			newItems.push({ label : "Other", menu : gother });
 		}
 
-		newItems.unshift({label : "Recents", menu : grecent});
-
 		return newItems;
 	}
 

+ 5 - 0
hide/view/FXEditor.hx

@@ -76,6 +76,7 @@ private class FXSceneEditor extends hide.comp.SceneEditor {
 			return ret;
 		}
 		var allTypes = super.getNewContextMenu(current, onMake, false);
+		var recents = getNewRecentContextMenu(current, onMake);
 
 		var menu = [];
 		if (parent.is2D) {
@@ -140,6 +141,10 @@ private class FXSceneEditor extends hide.comp.SceneEditor {
 			label: "Other",
 			menu: allTypes
 		});
+		menu.unshift({
+			label : "Recents",
+			menu : recents,
+		});
 		return menu;
 	}
 

+ 5 - 0
hide/view/Prefab.hx

@@ -184,6 +184,7 @@ private class PrefabSceneEditor extends hide.comp.SceneEditor {
 
 	override function getNewContextMenu(current: PrefabElement, ?onMake: PrefabElement->Void=null, ?groupByType = true ) {
 		var newItems = super.getNewContextMenu(current, onMake, groupByType);
+		var recents = getNewRecentContextMenu(current, onMake);
 
 		function setup(p : PrefabElement) {
 			autoName(p);
@@ -252,6 +253,10 @@ private class PrefabSceneEditor extends hide.comp.SceneEditor {
 			});
 		};
 		addNewInstances();
+		newItems.unshift({
+			label : "Recents",
+			menu : recents,
+		});
 		return newItems;
 	}