浏览代码

Use more native display of available keyboard shortcuts

Note that at the moment, if buttons have shortcuts with modifiers, they
will be displayed with dashes (eg. Ctrl-A), while in the scenetree
context menus they will be displayed with a plus (eg. Ctrl+D)
Leonardo Jeanteur 4 年之前
父节点
当前提交
5806a7cd26
共有 5 个文件被更改,包括 29 次插入12 次删除
  1. 8 0
      hide/comp/ContextMenu.hx
  2. 7 7
      hide/comp/SceneEditor.hx
  3. 11 0
      hide/ui/Keys.hx
  4. 2 4
      hide/view/l3d/Level3D.hx
  5. 1 1
      libs/nw/MenuItem.hx

+ 8 - 0
hide/comp/ContextMenu.hx

@@ -7,6 +7,10 @@ typedef ContextMenuItem = {
 	@:optional var enabled : Bool;
 	@:optional var checked : Bool;
 	@:optional var isSeparator : Bool;
+	@:optional var keys : {
+		@:optional var key : String;
+		@:optional var modifiers : String;
+	};
 }
 
 class ContextMenu {
@@ -34,6 +38,10 @@ class ContextMenu {
 
 	function makeMenuItem(i:ContextMenuItem) {
 		var mconf : nw.MenuItem.MenuItemOptions = { label : i.label, type : i.checked != null ? Checkbox : i.isSeparator ? Separator : Normal };
+		if( i.keys != null ) {
+			mconf.key = i.keys.key;
+			mconf.modifiers = i.keys.modifiers;
+		}
 		if( i.menu != null ) mconf.submenu = makeMenu(i.menu);
 		var m = new nw.MenuItem(mconf);
 		if( i.checked != null ) m.checked = i.checked;

+ 7 - 7
hide/comp/SceneEditor.hx

@@ -483,9 +483,9 @@ class SceneEditor {
 				{ label : "New...", menu : newItems },
 			];
 			var actionItems : Array<hide.comp.ContextMenu.ContextMenuItem> = [
-				{ label : "Rename" + ((view.config.get("key.rename") != null)? "	" + view.config.get("key.rename") : ""), enabled : current != null, click : function() tree.editNode(current) },
-				{ label : "Delete" + ((view.config.get("key.delete") != null)? "	" + view.config.get("key.delete") : ""), enabled : current != null, click : function() deleteElements(curEdit.rootElements) },
-				{ label : "Duplicate" + ((view.config.get("key.duplicate") != null)? "	" + view.config.get("key.duplicate") : ""), enabled : current != null, click : duplicate.bind(false) },
+				{ label : "Rename", enabled : current != null, click : function() tree.editNode(current), keys : hide.ui.Keys.getKeys("rename", view.config) },
+				{ label : "Delete", enabled : current != null, click : function() deleteElements(curEdit.rootElements), keys : hide.ui.Keys.getKeys("delete", view.config) },
+				{ label : "Duplicate", enabled : current != null, click : duplicate.bind(false), keys : hide.ui.Keys.getKeys("duplicate", view.config) },
 			];
 
 			var isObj = current != null && (current.to(Object3D) != null || current.to(Object2D) != null);
@@ -499,18 +499,18 @@ class SceneEditor {
 			if( isObj ) {
 				var visible = !isHidden(current);
 				menuItems = menuItems.concat([
-					{ label : "Show in editor" + ((view.config.get("key.sceneeditor.hide") != null)? "	" + view.config.get("key.sceneeditor.hide") : ""), checked : visible, click : function() setVisible(curEdit.elements, !visible) },
+					{ label : "Show in editor" , checked : visible, click : function() setVisible(curEdit.elements, !visible), keys : hide.ui.Keys.getKeys("sceneeditor.hide", view.config) },
 					{ label : "Locked", checked : current.locked, click : function() {
 						current.locked = !current.locked;
 						setLock(curEdit.elements, current.locked);
 					} },
-					{ label : "Select all" + ((view.config.get("key.selectAll") != null)? "	" + view.config.get("key.selectAll") : ""), click : selectAll },
+					{ label : "Select all", click : selectAll, keys : hide.ui.Keys.getKeys("selectAll", view.config) },
 					{ label : "Select children", enabled : current != null, click : function() selectElements(current.flatten()) },
 				]);
 				if( !isRef )
 					actionItems = actionItems.concat([
-						{ label : "Isolate" + ((view.config.get("key.sceneeditor.isolate") != null)? "	" + view.config.get("key.sceneeditor.isolate") : ""), click : function() isolate(curEdit.elements) },
-						{ label : "Group" + ((view.config.get("key.group") != null)? "	" + view.config.get("key.group") : ""), enabled : curEdit != null && canGroupSelection(), click : groupSelection }
+						{ label : "Isolate", click : function() isolate(curEdit.elements), keys : hide.ui.Keys.getKeys("sceneeditor.isolate", view.config) },
+						{ label : "Group", enabled : curEdit != null && canGroupSelection(), click : groupSelection, keys : hide.ui.Keys.getKeys("group", view.config) },
 					]);
 			}
 

+ 11 - 0
hide/ui/Keys.hx

@@ -77,6 +77,17 @@ class Keys {
 		keys.set(name, callb);
 	}
 
+	public static function getKeys( eventName : String, config : Config ) {
+		var keyCode : String = config.get("key." + eventName);
+		if( keyCode == null )
+			return null;
+		var splitKeys = keyCode.split('-');
+		return {
+			key: splitKeys[splitKeys.length - 1],
+			modifiers: [for( i in 0...(splitKeys.length - 1)) splitKeys[i]].join("+"),
+		};
+	}
+
 	public static function get( e : Element ) : Keys {
 		return Reflect.field(e[0], "__keys");
 	}

+ 2 - 4
hide/view/l3d/Level3D.hx

@@ -463,16 +463,14 @@ class Level3D extends FileView {
 		for (toolName in toolsNames) {
 			var tool = config.get("sceneeditor." + toolName);
 			if (tool != null) {
+				var shortcut = (config.get("key.sceneeditor." + toolName) != null)? " (" + config.get("key.sceneeditor." + toolName) + ")" : "";
 				switch(tool.type) {
 					case "Button":
-						var shortcut = (config.get("key.sceneeditor." + toolName) != null)? "	" + config.get("key.sceneeditor." + toolName) : "";
-						var button = tools.addButton(tool.icon, tool.title +  shortcut, toolButtonFunctions[toolName]);
+						var button = tools.addButton(tool.icon, tool.title + shortcut, toolButtonFunctions[toolName]);
 						if (tool.iconTransform != null) {
 							button.find(".icon").css({transform: tool.iconTransform});
 						}
-
 					case "Toggle":
-						var shortcut = (config.get("key.sceneeditor." + toolName) != null)? "	" + config.get("key.sceneeditor." + toolName) : "";
 						var toggle = tools.addToggle(tool.icon, tool.title + shortcut, toolToggleFunctions[toolName]);
 						if (tool.iconTransform != null) {
 							toggle.element.find(".icon").css({transform: tool.iconTransform});

+ 1 - 1
libs/nw/MenuItem.hx

@@ -6,7 +6,7 @@ package nw;
 	var Separator = "separator";
 }
 
-typedef MenuItemOptions = { label : String, ?icon : String, ?type : MenuItemType, ?submenu : Menu };
+typedef MenuItemOptions = { label : String, ?icon : String, ?type : MenuItemType, ?submenu : Menu, ?key : String, ?modifiers : String };
 
 extern class MenuItem {