From 66ba9bb2804535b1482e85d9310d26a2119b635d Mon Sep 17 00:00:00 2001 From: Vincent de Lachaux Date: Tue, 19 Sep 2023 11:56:40 +0200 Subject: [PATCH] restore menu class --- Project/Sources/Classes/menu.4dm | 877 +++++++++++++++++-------------- 1 file changed, 468 insertions(+), 409 deletions(-) diff --git a/Project/Sources/Classes/menu.4dm b/Project/Sources/Classes/menu.4dm index 5409408..5062109 100644 --- a/Project/Sources/Classes/menu.4dm +++ b/Project/Sources/Classes/menu.4dm @@ -1,4 +1,8 @@ -Class constructor($options) +property data; submenus : Collection +property choice; ref : Text +property autoRelease; released; localize; metacharacters; selected : Boolean + +Class constructor($def) var $c : Collection @@ -6,38 +10,39 @@ Class constructor($options) This:C1470.ref:=Null:C1517 This:C1470.autoRelease:=True:C214 + This:C1470.released:=False:C215 This:C1470.localize:=True:C214 This:C1470.metacharacters:=False:C215 This:C1470.selected:=False:C215 This:C1470.choice:="" - This:C1470.submenus:=New collection:C1472 - This:C1470.data:=New collection:C1472 + This:C1470.submenus:=[] + This:C1470.data:=[] If (Count parameters:C259>=1) Case of //______________________________________________________ - : (Value type:C1509($options)=Is text:K8:3) + : (Value type:C1509($def)=Is text:K8:3) Case of //______________________________________________________ - : ($options="menuBar") // Load the current menu bar + : ($def="menuBar") // Load the current menu bar This:C1470.ref:=Get menu bar reference:C979 //______________________________________________________ - : (Match regex:C1019("(?m-si)\\|MR\\|\\d{12}"; $options; 1)) // Menu reference + : (Match regex:C1019("(?m-si)\\|MR\\|\\d{12}"; $def; 1)) // Menu reference - This:C1470.ref:=$options + This:C1470.ref:=$def //______________________________________________________ Else This:C1470.ref:=Create menu:C408 - $c:=Split string:C1554(String:C10($options); ";") + $c:=Split string:C1554(String:C10($def); ";") Case of @@ -45,28 +50,28 @@ Class constructor($options) : ($c.length>1) This:C1470.autoRelease:=($c.indexOf("keep-reference")=-1) - This:C1470.metacharacters:=($c.indexOf("display-metacharacters")#-1) + This:C1470.metacharacters:=($c.includes("display-metacharacters")) This:C1470.localize:=($c.indexOf("no-localization")=-1) //----------------- - : ($options="no-localization") + : ($def="no-localization") This:C1470.localize:=False:C215 //----------------- - : ($options="keep-reference") + : ($def="keep-reference") This:C1470.autoRelease:=False:C215 //----------------- - : ($options="display-metacharacters") + : ($def="display-metacharacters") This:C1470.metacharacters:=True:C214 //----------------- - Else // Menu bar name + Else // Menu bar name - This:C1470.ref:=Create menu:C408($options) + This:C1470.ref:=Create menu:C408($def) //----------------- End case @@ -74,16 +79,16 @@ Class constructor($options) //______________________________________________________ End case //______________________________________________________ - : (Value type:C1509($options)=Is real:K8:4)\ - | (Value type:C1509($options)=Is longint:K8:6) // Menu bar number + : (Value type:C1509($def)=Is real:K8:4)\ + | (Value type:C1509($def)=Is longint:K8:6) // Menu bar number - This:C1470.ref:=Create menu:C408($options) + This:C1470.ref:=Create menu:C408($def) //______________________________________________________ - : (Value type:C1509($options)=Is collection:K8:32) // Create from collection + : (Value type:C1509($def)=Is collection:K8:32) // Create from collection This:C1470.ref:=Create menu:C408 - This:C1470.append($options) + This:C1470.append($def) //______________________________________________________ Else @@ -99,22 +104,28 @@ Class constructor($options) End if - // === === === === === === === === === === === === === === === === === === === === === === === === - // Removes the menu from memory -Function release() + // MARK:-[Definition] + // === === === === === === === === === === === === === === === === === === === === === === === === === === + // Adds/insert an item + // If afterItem < 0, it is considered as the offset from the item count of the menu +Function append($item; $param; $mark; $afterItem : Integer) : cs:C1710.menu - If (This:C1470._isMenu()) + var $t : Text + var $o : Object + + If (Value type:C1509($mark)=Is longint:K8:6)\ + | (Value type:C1509($mark)=Is real:K8:4) - RELEASE MENU:C978(This:C1470.ref) + $afterItem:=$mark + $mark:=False:C215 + + Else + + $afterItem:=Count parameters:C259>=4 ? $afterItem : MAXLONG:K35:2 End if - // === === === === === === === === === === === === === === === === === === === === === === === === - // Adds a new item to the menu -Function append($item; $param; $mark : Boolean) : cs:C1710.menu - - var $t : Text - var $o : Object + $afterItem:=$afterItem<0 ? This:C1470.itemCount()+$afterItem-1 : $afterItem Case of @@ -145,12 +156,14 @@ Function append($item; $param; $mark : Boolean) : cs:C1710.menu // 🤬 The "Get localized string" command does not like it at all. //______________________________________________________ - : (Not:C34(This:C1470.localize)) - - // Don't try to localize + : (Not:C34(This:C1470.localize)) // Don't try to localize - // TODO: TO TEST : Replace the hyphen by the unicode 2013 - //$item:=Replace string($item; "-"; "–") + If ($item#"-@") && ($item#"(-@") + + // Replace the hyphen by the unicode 2013 (better UI) + $item:=Replace string:C233($item; "-"; "–") + + End if //______________________________________________________ Else @@ -160,11 +173,9 @@ Function append($item; $param; $mark : Boolean) : cs:C1710.menu //______________________________________________________ End case - - $t:=$t || $item - If (Count parameters:C259>=2) + If ($param#Null:C1517) If (Value type:C1509($param)=Is object:K8:27) // Submenu @@ -175,12 +186,27 @@ Function append($item; $param; $mark : Boolean) : cs:C1710.menu If (This:C1470.metacharacters) - APPEND MENU ITEM:C411(This:C1470.ref; $t; $param.ref) + If ($afterItem#MAXLONG:K35:2) + + INSERT MENU ITEM:C412(This:C1470.ref; $afterItem; $t; $param.ref) + + Else + + APPEND MENU ITEM:C411(This:C1470.ref; $t; $param.ref) + + End if Else - APPEND MENU ITEM:C411(This:C1470.ref; $t; $param.ref; *) - + If ($afterItem#MAXLONG:K35:2) + + INSERT MENU ITEM:C412(This:C1470.ref; $afterItem; $t; $param.ref; *) + + Else + + APPEND MENU ITEM:C411(This:C1470.ref; $t; $param.ref; *) + + End if End if // Keep the sub-menu structure @@ -197,6 +223,7 @@ Function append($item; $param; $mark : Boolean) : cs:C1710.menu If ($param.autoRelease) RELEASE MENU:C978($param.ref) + $param.released:=True:C214 End if @@ -206,12 +233,27 @@ Function append($item; $param; $mark : Boolean) : cs:C1710.menu If (This:C1470.metacharacters) - APPEND MENU ITEM:C411(This:C1470.ref; $t) + If ($afterItem#MAXLONG:K35:2) + + INSERT MENU ITEM:C412(This:C1470.ref; $afterItem; $t) + + Else + + APPEND MENU ITEM:C411(This:C1470.ref; $t) + + End if Else - APPEND MENU ITEM:C411(This:C1470.ref; $t; *) - + If ($afterItem#MAXLONG:K35:2) + + INSERT MENU ITEM:C412(This:C1470.ref; $afterItem; $t; *) + + Else + + APPEND MENU ITEM:C411(This:C1470.ref; $t; *) + + End if End if If (Count parameters:C259>1) @@ -288,7 +330,7 @@ Function append($item; $param; $mark : Boolean) : cs:C1710.menu If ($o.shortcut#Null:C1517) - This:C1470.shortcut($o.shortcut) + This:C1470.shortcut($o.shortcut; Num:C11($o.modifier)) End if End for each @@ -303,37 +345,30 @@ Function append($item; $param; $mark : Boolean) : cs:C1710.menu return This:C1470 - // === === === === === === === === === === === === === === === === === === === === === === === === + // === === === === === === === === === === === === === === === === === === === === === === === === === === Function add($ref : Text; $text : Text; $param : Variant; $mark : Boolean) - // TODO: wip - - // === === === === === === === === === === === === === === === === === === === === === === === === - // Adds a line to the menu -Function line() : cs:C1710.menu - - APPEND MENU ITEM:C411(This:C1470.ref; "-(") - - return This:C1470 + // TODO: wip - But I don't remember what the purpose was :-( - // === === === === === === === === === === === === === === === === === === === === === === === === - // Defines the project method associated with a menu item -Function method($method : Text; $index : Integer) : cs:C1710.menu + // === === === === === === === === === === === === === === === === === === === === === === === === === === + // Adds/insert a line + // If afterItem < 0, it is considered as the offset from the item count of the menu +Function line($afterItem : Integer) : cs:C1710.menu - If (Count parameters:C259>1) + If (Count parameters:C259>=1) - SET MENU ITEM METHOD:C982(This:C1470.ref; $index; $method) + $afterItem:=$afterItem<0 ? This:C1470.itemCount()+$afterItem-1 : $afterItem + INSERT MENU ITEM:C412(This:C1470.ref; $afterItem; "-(") Else - // Last added item - SET MENU ITEM METHOD:C982(This:C1470.ref; -1; $method) + APPEND MENU ITEM:C411(This:C1470.ref; "-(") End if return This:C1470 - // === === === === === === === === === === === === === === === === === === === === === === === === + // === === === === === === === === === === === === === === === === === === === === === === === === === === // Delete an item or the last added item Function delete($index : Integer) : cs:C1710.menu @@ -349,120 +384,137 @@ Function delete($index : Integer) : cs:C1710.menu return This:C1470 - // === === === === === === === === === === === === === === === === === === === === === === === === - // Defines the activated status of a menu item -Function enable($enabled : Boolean; $index : Integer) : cs:C1710.menu + // === === === === === === === === === === === === === === === === === === === === === === === === === === + // Removes the menu from memory +Function release() + + If (This:C1470._isMenu()) + + RELEASE MENU:C978(This:C1470.ref) + This:C1470.released:=True:C214 + + End if + + // MARK:-[Properties] + + // === === === === === === === === === === === === === === === === === === === === === === === === === === + // Modifies the icon associated with a menu item +Function icon($proxy : Text; $index : Integer) : cs:C1710.menu + + $index:=Count parameters:C259>=2 ? $index : -1 + SET MENU ITEM ICON:C984(This:C1470.ref; $index; This:C1470._proxy($proxy)) + + return This:C1470 + + // === === === === === === === === === === === === === === === === === === === === === === === === === === + // Sets the check mark of a menu item +Function mark($checked : Boolean; $index : Integer) : cs:C1710.menu Case of //______________________________________________________ : (Count parameters:C259=0) - ENABLE MENU ITEM:C149(This:C1470.ref; -1) + SET MENU ITEM MARK:C208(This:C1470.ref; -1; Char:C90(18)) //______________________________________________________ : (Count parameters:C259=1) - If ($enabled) - - ENABLE MENU ITEM:C149(This:C1470.ref; -1) - - Else - - DISABLE MENU ITEM:C150(This:C1470.ref; -1) - - End if + SET MENU ITEM MARK:C208(This:C1470.ref; -1; Char:C90(18)*Num:C11($checked)) //______________________________________________________ Else - If ($enabled) - - ENABLE MENU ITEM:C149(This:C1470.ref; $index) - - Else - - DISABLE MENU ITEM:C150(This:C1470.ref; $index) - - End if + SET MENU ITEM MARK:C208(This:C1470.ref; $index; Char:C90(18)*Num:C11($checked)) //______________________________________________________ End case return This:C1470 - // === === === === === === === === === === === === === === === === === === === === === === === === -Function indent($index : Integer; $number : Integer) : cs:C1710.menu + // === === === === === === === === === === === === === === === === === === === === === === === === === === + // Associates a custom parameter to a menu item +Function parameter($param : Text; $index : Integer) : cs:C1710.menu If (Count parameters:C259=0) - // Special tag for indent on windows - SET MENU ITEM PROPERTY:C973(This:C1470.ref; -1; "_4D_PictureForIndent"; 1) + SET MENU ITEM PARAMETER:C1004(This:C1470.ref; -1; $param) Else - If (Count parameters:C259=1) - - SET MENU ITEM PROPERTY:C973(This:C1470.ref; $index; "_4D_PictureForIndent"; 1) - - Else - - SET MENU ITEM PROPERTY:C973(This:C1470.ref; $index; "_4D_PictureForIndent"; $number) - - End if + SET MENU ITEM PARAMETER:C1004(This:C1470.ref; $index; $param) + End if return This:C1470 - // === === === === === === === === === === === === === === === === === === === === === === === === - // Disable a menu item -Function disable($index : Integer) : cs:C1710.menu + // === === === === === === === === === === === === === === === === === === === === === === === === === === + // Associate a standard action with a menu item +Function action($action : Variant; $index : Integer) : cs:C1710.menu - If (Count parameters:C259=0) + If (Count parameters:C259=1) - DISABLE MENU ITEM:C150(This:C1470.ref; -1) + SET MENU ITEM PROPERTY:C973(This:C1470.ref; -1; Associated standard action name:K28:8; $action) Else - DISABLE MENU ITEM:C150(This:C1470.ref; $index) + SET MENU ITEM PROPERTY:C973(This:C1470.ref; $index; Associated standard action name:K28:8; $action) End if return This:C1470 - // === === === === === === === === === === === === === === === === === === === === === === === === - // Associate a standard action with a menu item -Function action($action : Variant; $index : Integer) : cs:C1710.menu + // === === === === === === === === === === === === === === === === === === === === === === === === === === + // Defines the project method associated with a menu item +Function method($method : Text; $index : Integer) : cs:C1710.menu - If (Count parameters:C259=1) + If (Count parameters:C259>1) - SET MENU ITEM PROPERTY:C973(This:C1470.ref; -1; Associated standard action name:K28:8; $action) + SET MENU ITEM METHOD:C982(This:C1470.ref; $index; $method) Else - SET MENU ITEM PROPERTY:C973(This:C1470.ref; $index; Associated standard action name:K28:8; $action) + // Last added item + SET MENU ITEM METHOD:C982(This:C1470.ref; -1; $method) End if return This:C1470 - // === === === === === === === === === === === === === === === === === === === === === === === === - // Associates a custom parameter to a menu item -Function parameter($param : Text; $index : Integer) : cs:C1710.menu + // === === === === === === === === === === === === === === === === === === === === === === === === === === + // Replaces the shortcut key associated with the menu item +Function shortcut($key; $modifier : Integer; $index : Integer) : cs:C1710.menu - If (Count parameters:C259=0) + $index:=($index=0) ? -1 : $index + + If (Count parameters:C259>=2) - SET MENU ITEM PARAMETER:C1004(This:C1470.ref; -1; $param) + If (Value type:C1509($key)=Is object:K8:27) + + SET MENU ITEM SHORTCUT:C423(This:C1470.ref; $index; String:C10($key.key); Num:C11($key.modifier)) + + Else + + SET MENU ITEM SHORTCUT:C423(This:C1470.ref; $index; String:C10($key); $modifier) + + End if Else - SET MENU ITEM PARAMETER:C1004(This:C1470.ref; $index; $param) - + If (Value type:C1509($key)=Is object:K8:27) + + SET MENU ITEM SHORTCUT:C423(This:C1470.ref; -1; String:C10($key.key); Num:C11($key.modifier)) + + Else + + SET MENU ITEM SHORTCUT:C423(This:C1470.ref; -1; String:C10($key); 0) + + End if End if return This:C1470 - // === === === === === === === === === === === === === === === === === === === === === === === === + // === === === === === === === === === === === === === === === === === === === === === === === === === === // Associates a property to a menu item /* ⚠️ ONE CAN SET A PROPERTY FOR ALL MENU TYPE (MENU BAR OR POPUP) @@ -482,13 +534,93 @@ Function property($property : Text; $value : Variant; $index : Integer) : cs:C17 return This:C1470 - // === === === === === === === === === === === === === === === === === === === === === === === === - // Returns a property of a menu item -Function getProperty($property : Text; $index : Integer)->$value + // === === === === === === === === === === === === === === === === === === === === === === === === === === + // Changes the font style of the menu item +Function setStyle($tyle : Integer; $index : Integer) : cs:C1710.menu - GET MENU ITEM PROPERTY:C972(This:C1470.ref; $index; $property; $value) + If (Count parameters:C259>1) + + SET MENU ITEM STYLE:C425(This:C1470.ref; $index; $tyle) + + Else + + SET MENU ITEM STYLE:C425(This:C1470.ref; -1; $tyle) + + End if + + return This:C1470 + + // === === === === === === === === === === === === === === === === === === === === === === === === === === +Function indent($index : Integer; $number : Integer) : cs:C1710.menu + + $number:=$number>0 ? $number : 1 + $index:=Count parameters:C259>=1 ? $index : -1 + + // Special tag for indent on windows + SET MENU ITEM PROPERTY:C973(This:C1470.ref; $index; "_4D_PictureForIndent"; $number) + + return This:C1470 + + // === === === === === === === === === === === === === === === === === === === === === === === === === === + // Defines the activated status of a menu item +Function enable($enabled : Boolean; $index : Integer) : cs:C1710.menu + + Case of + + //______________________________________________________ + : (Count parameters:C259=0) // Enable last added + + ENABLE MENU ITEM:C149(This:C1470.ref; -1) + + //______________________________________________________ + : (Count parameters:C259=1) // Enable/disable Last added + + If ($enabled) + + ENABLE MENU ITEM:C149(This:C1470.ref; -1) + + Else + + DISABLE MENU ITEM:C150(This:C1470.ref; -1) + + End if + + //______________________________________________________ + Else // Enable/disable item + + If ($enabled) + + ENABLE MENU ITEM:C149(This:C1470.ref; $index) + + Else + + DISABLE MENU ITEM:C150(This:C1470.ref; $index) + + End if + + //______________________________________________________ + End case + + return This:C1470 + + // === === === === === === === === === === === === === === === === === === === === === === === === === === + // Disable a menu item +Function disable($index : Integer) : cs:C1710.menu + + If (Count parameters:C259=0) + + DISABLE MENU ITEM:C150(This:C1470.ref; -1) + + Else + + DISABLE MENU ITEM:C150(This:C1470.ref; $index) + + End if + + return This:C1470 - // === === === === === === === === === === === === === === === === === === === === === === === === + // MARK:-[DATA] + // === === === === === === === === === === === === === === === === === === === === === === === === === === // Associates data to a menu item Function setData($name : Text; $value : Variant; $index : Integer) : cs:C1710.menu @@ -515,14 +647,15 @@ Function setData($name : Text; $value : Variant; $index : Integer) : cs:C1710.me //_____________________________ End case - $o:=This:C1470.data.query("ref = :1 & name = :2"; $ref; $name).pop() + $o:=This:C1470.data.query("ref = :1 & name = :2"; $ref; $name).first() If ($o=Null:C1517) - This:C1470.data.push(New object:C1471(\ - "ref"; $ref; \ - "name"; $name; \ - "value"; $value)) + This:C1470.data.push({\ + ref: $ref; \ + name: $name; \ + value: $value\ + }) Else @@ -533,158 +666,187 @@ Function setData($name : Text; $value : Variant; $index : Integer) : cs:C1710.me return This:C1470 - // === === === === === === === === === === === === === === === === === === === === === === === === + // === === === === === === === === === === === === === === === === === === === === === === === === === === // Retrieve data associated to selected menu item -Function getData($name : Text; $ref : Text)->$value +Function getData($name : Text; $ref : Text) : Variant var $o : Object - If (Asserted:C1132(This:C1470.selected)) + $o:=Count parameters:C259>=2\ + ? This:C1470.data.query("name = :1 & ref = :2"; $name; $ref).first()\ + : This:C1470.data.query("name = :1"; $name).first() + + If ($o#Null:C1517) - If (Count parameters:C259>=2) - - $o:=This:C1470.data.query("name = :1 & ref = :2"; $name; $ref).pop() - - Else - - $o:=This:C1470.data.query("name = :1"; $name).pop() - - End if + return $o.value - If ($o#Null:C1517) - - $value:=$o.value - - End if End if - // === === === === === === === === === === === === === === === === === === === === === === === === - // Sets the check mark of a menu item -Function mark($checked : Boolean; $index : Integer) : cs:C1710.menu + // MARK:-[Informations] + // === === === === === === === === === === === === === === === === === === === === === === === === === === + // Returns the number of menu items present in the menu +Function itemCount() : Integer - Case of - - //______________________________________________________ - : (Count parameters:C259=0) - - SET MENU ITEM MARK:C208(This:C1470.ref; -1; Char:C90(18)) - - //______________________________________________________ - : (Count parameters:C259=1) - - SET MENU ITEM MARK:C208(This:C1470.ref; -1; Char:C90(18)*Num:C11($checked)) - - //______________________________________________________ - Else - - SET MENU ITEM MARK:C208(This:C1470.ref; $index; Char:C90(18)*Num:C11($checked)) - - //______________________________________________________ - End case + return Count menu items:C405(This:C1470.ref) - return This:C1470 + // === === === === === === === === === === === === === === === === === === === === === === === === === === + // Returns a menu item from its title or index +Function item($item; $ref : Text) : Object - // === === === === === === === === === === === === === === === === === === === === === === === === - // Replaces the shortcut key associated with the menu item -Function shortcut($key; $modifier : Integer; $index : Integer) : cs:C1710.menu + var $menuItem : Object + var $indx : Integer + var $value - $index:=($index=0) ? -1 : $index + ARRAY TEXT:C222($titles; 0) + ARRAY TEXT:C222($references; 0) If (Count parameters:C259>=2) - If (Value type:C1509($key)=Is object:K8:27) - - SET MENU ITEM SHORTCUT:C423(This:C1470.ref; $index; String:C10($key.key); Num:C11($key.modifier)) - - Else - - SET MENU ITEM SHORTCUT:C423(This:C1470.ref; $index; String:C10($key); $modifier) - - End if + GET MENU ITEMS:C977($ref; $titles; $references) Else - If (Value type:C1509($key)=Is object:K8:27) - - SET MENU ITEM SHORTCUT:C423(This:C1470.ref; -1; String:C10($key.key); Num:C11($key.modifier)) - - Else - - SET MENU ITEM SHORTCUT:C423(This:C1470.ref; -1; String:C10($key); 0) - - End if + GET MENU ITEMS:C977(This:C1470.ref; $titles; $references) + End if - return This:C1470 - - // === === === === === === === === === === === === === === === === === === === === === === === === - // Modifies the icon associated with a menu item -Function icon($icon : Text; $index : Integer) : cs:C1710.menu - - var $path : Text - Case of + //______________________________________________________ - : ($icon="path:@") + : (Value type:C1509($item)=Is text:K8:3) // -> withTitle - $path:=$icon + $indx:=Find in array:C230($titles; $item) //______________________________________________________ - : ($icon="/RESOURCES/@") + : (Value type:C1509($item)=Is longint:K8:6)\ + | (Value type:C1509($item)=Is real:K8:4) // -> at - $path:="path:"+$icon + $indx:=$item //______________________________________________________ Else - $path:="path:/RESOURCES/"+$icon + ASSERT:C1129(False:C215; Current method name:C684+": invalid type") //______________________________________________________ End case - If (Count parameters:C259>1) + If (Asserted:C1132($indx>0; "Item \""+String:C10($item)+"\" not found")) - SET MENU ITEM ICON:C984(This:C1470.ref; $index; $path) + $menuItem:=New object:C1471(\ + "title"; Get menu item:C422(This:C1470.ref; $indx); \ + "key"; Get menu item key:C424(This:C1470.ref; $indx); \ + "mark"; Get menu item mark:C428(This:C1470.ref; $indx); \ + "method"; Get menu item method:C981(This:C1470.ref; $indx); \ + "modifiers"; Get menu item modifiers:C980(This:C1470.ref; $indx); \ + "parameter"; Get menu item parameter:C1003(This:C1470.ref; $indx); \ + "style"; Get menu item style:C426(This:C1470.ref; $indx); \ + "withSubMenu"; Length:C16($references{$indx})>0; \ + "subMenuReference"; $references{$indx}; \ + "isSeparator"; This:C1470.isSeparatorItem($indx)\ + ) - Else + $menuItem.data:=This:C1470.data.query("ref = :1"; $menuItem.parameter) + + GET MENU ITEM PROPERTY:C972(This:C1470.ref; $indx; Associated standard action:K56:1; $value) + $menuItem.standardAction:=$value - SET MENU ITEM ICON:C984(This:C1470.ref; -1; $path) + GET MENU ITEM PROPERTY:C972(This:C1470.ref; $indx; Access privileges:K56:3; $value) + $menuItem.accessPrivileges:=$value End if - return This:C1470 + return $menuItem - // === === === === === === === === === === === === === === === === === === === === === === === === - // Changes the font style of the menu item -Function setStyle($tyle : Integer; $index : Integer) : cs:C1710.menu + // === === === === === === === === === === === === === === === === === === === === === === === === === === + // Returns a collection of the first level menu items +Function items() : Collection - If (Count parameters:C259>1) - - SET MENU ITEM STYLE:C425(This:C1470.ref; $index; $tyle) - - Else + var $i : Integer + var $items : Collection + + $items:=[] + + For ($i; 1; This:C1470.itemCount(); 1) - SET MENU ITEM STYLE:C425(This:C1470.ref; -1; $tyle) + $items.push(This:C1470.item($i)) - End if + End for - return This:C1470 + return $items - // === === === === === === === === === === === === === === === === === === === === === === === === - // Replaces the current menu bar with the current menu -Function setBar() + // === === === === === === === === === === === === === === === === === === === === === === === === === === +Function isSeparatorItem($item : Integer) : Boolean - This:C1470._cleanup() + var $value - SET MENU BAR:C67(This:C1470.ref) + Case of + + //________________________________________ + : (Get menu item:C422(This:C1470.ref; $item)="(-@") + + return True:C214 + + //________________________________________ + : (Get menu item:C422(This:C1470.ref; $item)="-@") + + return True:C214 + + //________________________________________ + Else + + GET MENU ITEM PROPERTY:C972(This:C1470.ref; $item; "4D_separator"; $value) + return $value#0 + + //________________________________________ + End case - If (This:C1470.autoRelease) + // === === === === === === === === === === === === === === === === === === === === === === === === === === +Function itemSubMenuRef($withTitle : Text) : Text + + var $indx : Integer + + ARRAY TEXT:C222($titles; 0x0000) + ARRAY TEXT:C222($references; 0x0000) + GET MENU ITEMS:C977(This:C1470.ref; $titles; $references) + + $indx:=Find in array:C230($titles; $withTitle) + + If ($indx#-1) - This:C1470.release() + return $references{$indx} End if - // === === === === === === === === === === === === === === === === === === === === === === === === + // === === === === === === === === === === === === === === === === === === === === === === === === === === + // Returns a property of a menu item +Function getProperty($property : Text; $index : Integer) : Variant + + var $value : Text + + GET MENU ITEM PROPERTY:C972(This:C1470.ref; $index; $property; $value) + + Case of + + //______________________________________________________ + : (Match regex:C1019("(?m-is)^(?:[tT]rue|[fF]alse)$"; $value; 1; *)) + + return $value="true" + + : (Match regex:C1019("(?m-si)^(?:\\+|-)?\\d*\\.*\\d+$"; $value; 1; *)) + + return Num:C11($value) + + //______________________________________________________ + Else + + return $value + + //______________________________________________________ + End case + + // MARK:-[Tools] + // === === === === === === === === === === === === === === === === === === === === === === === === === === // Display the current menu as a pop-up menu Function popup($where : Variant; $x : Variant; $y : Integer) : cs:C1710.menu @@ -753,39 +915,12 @@ Function popup($where : Variant; $x : Variant; $y : Integer) : cs:C1710.menu return This:C1470 - // === === === === === === === === === === === === === === === === === === === === === === === === - // Returns the number of menu items present in the menu -Function itemCount()->$number : Integer - - $number:=Count menu items:C405(This:C1470.ref) - - // === === === === === === === === === === === === === === === === === === === === === === === === -Function menuSelected()->$selected : Object - - var $menuSelected : Integer - var $menuRef : Text - - $menuSelected:=Menu selected:C152($menuRef) - - $selected:=New object:C1471(\ - "ref"; $menuRef; \ - "menu"; $menuSelected\65536; \ - "item"; $menuSelected%65536) - - // === === === === === === === === === === === === === === === === === === === === === === === === - // Default File menu -Function file() : cs:C1710.menu - - This:C1470.append(":xliff:CommonMenuItemQuit").action(ak quit:K76:61).shortcut("Q") - - return This:C1470 - - // === === === === === === === === === === === === === === === === === === === === === === === === + // === === === === === === === === === === === === === === === === === === === === === === === === === === // Standard Edit menu Function edit() : cs:C1710.menu This:C1470.append(":xliff:CommonMenuItemUndo").action(ak undo:K76:51).shortcut("Z") - This:C1470.append(":xliff:CommonMenuRedo").action(ak redo:K76:52).shortcut("Z"; 512) + This:C1470.append(":xliff:CommonMenuRedo").action(ak redo:K76:52).shortcut("Z"; Shift key mask:K16:3) This:C1470.line() This:C1470.append(":xliff:CommonMenuItemCut").action(ak cut:K76:53).shortcut("X") This:C1470.append(":xliff:CommonMenuItemCopy").action(ak copy:K76:54).shortcut("C") @@ -797,24 +932,32 @@ Function edit() : cs:C1710.menu return This:C1470 - // === === === === === === === === === === === === === === === === === === === === === === === === + // === === === === === === === === === === === === === === === === === === === === === === === === === === + // Default File menu +Function file() : cs:C1710.menu + + This:C1470.append(":xliff:CommonMenuItemQuit").action(ak quit:K76:61).shortcut("Q") + + return This:C1470 + + // === === === === === === === === === === === === === === === === === === === === === === === === === === // Fonts menu with or without styles -Function fonts($withStyle : Boolean) : cs:C1710.menu +Function fonts($withStyle; $callback : Text) : cs:C1710.menu var $menuStyles : Text - var $styled : Boolean var $i; $j : Integer - If (Count parameters:C259>0) + If (Value type:C1509($withStyle)=Is text:K8:3) - $styled:=$withStyle + $callback:=$withStyle + $withStyle:=False:C215 End if ARRAY TEXT:C222($fontsFamilly; 0x0000) FONT LIST:C460($fontsFamilly) - If ($styled) + If ($withStyle) For ($i; 1; Size of array:C274($fontsFamilly); 1) @@ -833,6 +976,7 @@ Function fonts($withStyle : Boolean) : cs:C1710.menu APPEND MENU ITEM:C411($menuStyles; $styles{$j}) // Localized name SET MENU ITEM PARAMETER:C1004($menuStyles; -1; $names{$j}) // System name + SET MENU ITEM METHOD:C982($menuStyles; -1; $callback) End for @@ -843,6 +987,7 @@ Function fonts($withStyle : Boolean) : cs:C1710.menu APPEND MENU ITEM:C411(This:C1470.ref; $fontsFamilly{$i}) SET MENU ITEM PARAMETER:C1004(This:C1470.ref; -1; $names{1}) + SET MENU ITEM METHOD:C982(This:C1470.ref; -1; $callback) End if @@ -864,9 +1009,9 @@ Function fonts($withStyle : Boolean) : cs:C1710.menu return This:C1470 - // === === === === === === === === === === === === === === === === === === === === === === === === + // === === === === === === === === === === === === === === === === === === === === === === === === === === // Windows menu -Function windows() : cs:C1710.menu +Function windows($callback : Text) : cs:C1710.menu var $name : Text var $current; $frontmostWindow; $i : Integer @@ -876,20 +1021,22 @@ Function windows() : cs:C1710.menu ARRAY LONGINT:C221($windows; 0x0000) WINDOW LIST:C442($windows) - $c:=New collection:C1472 + $c:=[] For ($i; 1; Size of array:C274($windows); 1) - $c.push(New object:C1471(\ - "ref"; $windows{$i}; \ - "name"; Get window title:C450($windows{$i}); \ - "process"; Window process:C446($windows{$i}))) + $c.push({\ + ref: $windows{$i}; \ + name: Get window title:C450($windows{$i}); \ + process: Window process:C446($windows{$i})\ + }) End for - $c:=$c.orderBy(New collection:C1472(\ - New object:C1471("propertyPath"; "process"; "descending"; True:C214); \ - New object:C1471("propertyPath"; "name"))) + $c:=$c.orderBy([\ + {propertyPath: "process"; descending: True:C214}; \ + {propertyPath: "name"}\ + ]) If ($c.length>0) @@ -911,144 +1058,19 @@ Function windows() : cs:C1710.menu This:C1470.append($o.name; $o.ref; $frontmostWindow=$o.ref) + If ($callback#"") + + This:C1470.method($callback) + + End if + End for each End if return This:C1470 - // === === === === === === === === === === === === === === === === === === === === === === === === - // Create a default minimal menu bar -Function defaultMinimalMenuBar() : cs:C1710.menu - - This:C1470.append(":xliff:CommonMenuFile"; cs:C1710.menu.new().file()) - This:C1470.append(":xliff:CommonMenuEdit"; cs:C1710.menu.new().edit()) - - return This:C1470 - - // === === === === === === === === === === === === === === === === === === === === === === === === - // Returns a menu item from its title or index -Function item($item; $ref : Text)->$menuItem : Object - - var $indx : Integer - var $value - - ARRAY TEXT:C222($titles; 0) - ARRAY TEXT:C222($references; 0) - - If (Count parameters:C259>=2) - - GET MENU ITEMS:C977($ref; $titles; $references) - - Else - - GET MENU ITEMS:C977(This:C1470.ref; $titles; $references) - - End if - - Case of - - //______________________________________________________ - : (Value type:C1509($item)=Is text:K8:3) // -> withTitle - - $indx:=Find in array:C230($titles; $item) - - //______________________________________________________ - : (Value type:C1509($item)=Is longint:K8:6)\ - | (Value type:C1509($item)=Is real:K8:4) // -> at - - $indx:=$item - - //______________________________________________________ - Else - - ASSERT:C1129(False:C215; Current method name:C684+": invalid type") - - //______________________________________________________ - End case - - If (Asserted:C1132($indx>0; "Item \""+String:C10($item)+"\" not found")) - - $menuItem:=New object:C1471(\ - "title"; Get menu item:C422(This:C1470.ref; $indx); \ - "key"; Get menu item key:C424(This:C1470.ref; $indx); \ - "mark"; Get menu item mark:C428(This:C1470.ref; $indx); \ - "method"; Get menu item method:C981(This:C1470.ref; $indx); \ - "modifiers"; Get menu item modifiers:C980(This:C1470.ref; $indx); \ - "parameter"; Get menu item parameter:C1003(This:C1470.ref; $indx); \ - "style"; Get menu item style:C426(This:C1470.ref; $indx); \ - "withSubMenu"; Length:C16($references{$indx})>0; \ - "subMenuReference"; $references{$indx}; \ - "isSeparator"; This:C1470.isSeparatorItem($indx)\ - ) - - $menuItem.data:=This:C1470.data.query("ref = :1"; $menuItem.parameter) - - GET MENU ITEM PROPERTY:C972(This:C1470.ref; $indx; Associated standard action:K56:1; $value) - $menuItem.standardAction:=$value - - GET MENU ITEM PROPERTY:C972(This:C1470.ref; $indx; Access privileges:K56:3; $value) - $menuItem.accessPrivileges:=$value - - End if - - // === === === === === === === === === === === === === === === === === === === === === === === === - // Returns a collection of the first level menu items -Function items()->$items : Collection - - var $i : Integer - - $items:=New collection:C1472 - - For ($i; 1; This:C1470.itemCount(); 1) - - $items.push(This:C1470.item($i)) - - End for - - // === === === === === === === === === === === === === === === === === === === === === === === === -Function itemSubMenuRef($withTitle : Text)->$reference : Text - - var $indx : Integer - - ARRAY TEXT:C222($titles; 0x0000) - ARRAY TEXT:C222($references; 0x0000) - GET MENU ITEMS:C977(This:C1470.ref; $titles; $references) - - $indx:=Find in array:C230($titles; $withTitle) - - If ($indx#-1) - - $reference:=$references{$indx} - - End if - - // === === === === === === === === === === === === === === === === === === === === === === === === -Function isSeparatorItem($item : Integer)->$isSeparator : Boolean - - var $value - - Case of - - //________________________________________ - : (Get menu item:C422(This:C1470.ref; $item)="(-@") - - $isSeparator:=True:C214 - - //________________________________________ - : (Get menu item:C422(This:C1470.ref; $item)="-@") - - $isSeparator:=True:C214 - - //________________________________________ - Else - - GET MENU ITEM PROPERTY:C972(This:C1470.ref; $item; "4D_separator"; $value) - $isSeparator:=($value#0) - - //________________________________________ - End case - - // === === === === === === === === === === === === === === === === === === === === === === === === + // MARK:- + // === === === === === === === === === === === === === === === === === === === === === === === === === === // Remove duplicates (lines or items) Function _cleanup() @@ -1110,11 +1132,48 @@ Function _cleanup() End if End for - // === === === === === === === === === === === === === === === === === === === === === === === === -Function _isMenu()->$isMenu : Boolean + // === === === === === === === === === === === === === === === === === === === === === === === === === === +Function _isMenu() : Boolean If (Asserted:C1132(This:C1470.ref#Null:C1517; Current method name:C684+": The menu reference is null")) - $isMenu:=True:C214 + return True:C214 - End if \ No newline at end of file + End if + + // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** +Function _proxy($proxy : Text) : Text + + Case of + + //______________________________________________________ + : (Position:C15("path:"; $proxy)=1)\ + || (Position:C15("file:"; $proxy)=1)\ + || (Position:C15("var:"; $proxy)=1)\ + || (Position:C15("!"; $proxy)=1) + + return $proxy + + //______________________________________________________ + : (Position:C15("#"; $proxy)=1) // Shortcut for Resources folder + + return "path:/RESOURCES/"+Delete string:C232($proxy; 1; 1) + + //______________________________________________________ + : ($proxy="|@") + + return "path:/.PRODUCT_RESOURCES/"+Delete string:C232($proxy; 1; 1) + + //______________________________________________________ + : (Position:C15("/"; $proxy)=1) + + return "path:"+$proxy + + //______________________________________________________ + Else + + return "path:/RESOURCES/"+$proxy + + //______________________________________________________ + End case + \ No newline at end of file