/********************* @Author : liuyuqi @Contact : liuyuqi.gov@msn.cn @Time : 2019/07/23 06:04:23 @Version : 1.0 @License : (C)Copyright 2019 liuyuqi. @Desc : None *********************/ "User Tweaks||4 : _getTweaks" Global $GT_FORCE_INI_USE = false; Global $GT_INI_FILE = "\.config\TheQwertysScripts.ini"; Global $GT_INI_SECTION = 'MAIN_MENU'; Global $GT_UPDATE_MENU_ON_BETAS = false; "- : _-" //--------------------------------------------------------------------- "_Initialize" Global $G_INITIALIZED; if (! $G_INITIALIZED) { Status 'Initializing script...',, 'progress'; Sub('_readOptions'); } $G_INITIALIZED = true; "Get Configuration||4 : _readOptions" Status 'Reading configuration...',, 'progress'; Sub('_getTweaks'); Global $GT_INI_FILE, $GT_FORCE_INI_USE, $GT_INI_SECTION; Global $GS_LAST_MODIFIED; Global $GS_MENU_TITLES, $GS_MENU_CMD_DATA_SPLITTER, $GS_MENU_CMD_LIST, $GS_XY_VERSION; if ($GT_FORCE_INI_USE) { $ScriptRetainPVs = false; } else { $ScriptRetainPVs = GetKey('ScriptRetainPVs', 'Settings'); } if ($ScriptRetainPVs && IsSet($P_THEQWERTY_MAIN_MENU_LAST_MODIFIED)) { Status 'Read configuration from permanent variables.',, 'progress'; $GS_LAST_MODIFIED = $P_THEQWERTY_MAIN_MENU_LAST_MODIFIED; // Options $GS_MENU_TITLES = $P_THEQWERTY_MAIN_MENU_MENU_TITLES; $GS_MENU_CMD_DATA_SPLITTER = $P_THEQWERTY_MAIN_MENU_MENU_CMD_DATA_SPLITTER; $GS_MENU_CMD_LIST = $P_THEQWERTY_MAIN_MENU_MENU_CMD_LIST; $GS_XY_VERSION = $P_THEQWERTY_MAIN_MENU_XY_VERSION; } else { if (1 == Exists($GT_INI_FILE)) { $iniOptions = GetKey('XY_Version', $GT_INI_SECTION, $GT_INI_FILE); if ($iniOptions) { Status 'Read configuration from INI file.',, 'progress'; $GS_LAST_MODIFIED = GetKey('LAST_MODIFIED', $GT_INI_SECTION, $GT_INI_FILE); // Options $GS_MENU_TITLES = GetKey('Menu_Titles', $GT_INI_SECTION, $GT_INI_FILE); $GS_MENU_CMD_DATA_SPLITTER = GetKey('Menu_Cmd_Data_Splitter', $GT_INI_SECTION, $GT_INI_FILE); $GS_MENU_CMD_LIST = GetKey('Menu_Cmd_List', $GT_INI_SECTION, $GT_INI_FILE); $GS_XY_VERSION = GetKey('XY_Version', $GT_INI_SECTION, $GT_INI_FILE); // Extra handling for INI files. $GS_MENU_CMD_LIST = Replace($GS_MENU_CMD_LIST, '¶', ""); $GS_MENU_CMD_LIST = Replace($GS_MENU_CMD_LIST, '&PILCROW;', '¶'); } Unset $iniOptions; } } Unset $ScriptRetainPVs; "Set Configuration||4 : _setOptions" Status 'Saving configuration...',, 'progress'; Sub('_getTweaks'); Global $GT_INI_FILE, $GT_FORCE_INI_USE, $GT_INI_SECTION; Global $GS_LAST_MODIFIED = Now('yyyy-mm-dd_hh.nn.ss'); Global $GS_MENU_TITLES, $GS_MENU_CMD_DATA_SPLITTER, $GS_MENU_CMD_LIST, $GS_XY_VERSION; if ($GT_FORCE_INI_USE) { $ScriptRetainPVs = false; } else { $ScriptRetainPVs = GetKey('ScriptRetainPVs', 'Settings'); } if ($ScriptRetainPVs) { Perm $P_THEQWERTY_MAIN_MENU_LAST_MODIFIED = $GS_LAST_MODIFIED; // Options Perm $P_THEQWERTY_MAIN_MENU_MENU_TITLES = $GS_MENU_TITLES; Perm $P_THEQWERTY_MAIN_MENU_MENU_CMD_DATA_SPLITTER = $GS_MENU_CMD_DATA_SPLITTER; Perm $P_THEQWERTY_MAIN_MENU_MENU_CMD_LIST = $GS_MENU_CMD_LIST; Perm $P_THEQWERTY_MAIN_MENU_XY_VERSION = $GS_XY_VERSION; Status 'Saved configuration to permanent variable.',, 'progress'; } else { if (1 != Exists($GT_INI_FILE)) { Status 'Creating INI file...',, 'progress'; New($GT_INI_FILE, 'file'); } // Extra handling for INI files. $cmdList = Replace($GS_MENU_CMD_LIST, '¶', '&PILCROW;'); $cmdList = Replace($cmdList, "", '¶'); SetKey $GS_LAST_MODIFIED, 'LAST_MODIFIED', $GT_INI_SECTION, $GT_INI_FILE; // Options SetKey $GS_MENU_TITLES, 'Menu_Titles', $GT_INI_SECTION, $GT_INI_FILE; SetKey $GS_MENU_CMD_DATA_SPLITTER, 'Menu_Cmd_Data_Splitter', $GT_INI_SECTION, $GT_INI_FILE; SetKey $cmdList, 'Menu_Cmd_List', $GT_INI_SECTION, $GT_INI_FILE, 1; SetKey $GS_XY_VERSION, 'XY_Version', $GT_INI_SECTION, $GT_INI_FILE; Status 'Saved configuration to INI file.',, 'progress'; Unset $cmdList; } Unset $ScriptRetainPVs; "- : _-" //--------------------------------------------------------------------- "Retrieve Commands||4 : _getCommands" Status 'Retrieving command list...',, 'progress'; Global $G_CMD_LIST; Msg <<<#INSTRUCTIONS To recreate the menu this script needs some help from you. You will only be asked to do this once per stable release of XYplorer. When the List of All Commands Dialog appears: 1) Right-click the list of commands. 2) Select 'Copy All Items'. 3) Close the List of All Commands dialog by clicking 'Cancel'. After this the text of your clipboard will be restored. #INSTRUCTIONS, 1; $cb = ""; CopyText ''; Status "In 'List of All Commands' dialog: Right-Click > 'Copy All Items' then Cancel.",, 'progress'; #705; //List of Functions $G_CMD_LIST = ""; CopyText $cb; Status 'Clipboard restored.',, 'progress'; Unset $cb; End $G_CMD_LIST == '', <<<#END_MSG It appears you didn't copy the items from the List of All Commands dialog. This script cannot continue without that information. #END_MSG; "Create Menu Data||4 : _genMenuData" Status 'Creating menu data....',, 'progress'; $ME = Self('Caption'); Unset $GS_MENU_TITLES, $GS_MENU_CMD_DATA_SPLITTER, $GS_MENU_CMD_LIST, $GS_XY_VERSION; Global $G_CMD_LIST = ''; Sub('_getCommands'); End $G_CMD_LIST == '', "Error [$ME]: Command list is empty."; $__CMD_DATA_SPLITTER__ = "__CMD_DATA_SPLITTER__"; $cmdList = ''; // List of menu items. $titleList = ''; // List of menu titles. $assigned = ''; // List of assigned accelerator keys. $cSub = ''; // Name of the currently being processed submenu. foreach ($line, $G_CMD_LIST, "") { if (! $line) { continue; } // Description $des = GetToken($line, 2, "", 't', 2); // Continue if we're within a submenu. if ($des Like "$cSub | *") { continue; } $cSub = ''; // Start a new submenu. if ($des LikeI '*- submenu -*') { $cSub = RegexReplace($des, ' \| - submenu -.*?$'); } // Command ID $cid = GetToken($line, 1, "", 't'); $cid = SubStr($cid, 1); // Caption (from Command ID) $caption = Get('MenuCaption', $cid, 1); // Menu Title (from Description) $title = GetToken($des, 1, ' | ', 't', 1); // Add to our list of menu titles. if (Replace("|$titleList|", '&') UnLike "*|$title|*") { $ampCount = GetToken(RegexMatches($title, '&', '|'), 'Count', '|'); if ($ampCount == 0 || $ampCount % 2 != 0) { $i = 0; $len = StrLen($title); // Locate a character we can make the accelerator. while ($i < $len) { $char = SubStr($title, $i, 1); $i++; // We will cheat and only add them to [a-z]. if (! RegexMatches($char, '[a-z]')) { continue; } // Avoid duplicates. if ($assigned UnLikeI "*$char*") { $assigned = $assigned . $char; $title = Replace($title, $char, "&$char", 0, 1, 1); break; } } Unset $i, $len, $char; } $titleList = $titleList . "|$title"; } // Build command list. $cmdList = $cmdList . GetToken($titleList, -1, '|') . " | $caption$__CMD_DATA_SPLITTER__$cid"; } Unset $assigned, $cSub, $line, $des, $cid, $caption, $title, $ampCount, $G_CMD_LIST; $titleList = SubStr($titleList, 1); // Remove leading pipe. Global $GS_MENU_TITLES = $titleList; End $GS_MENU_TITLES == '', "Error [$ME]: Failed to generate menu title list."; Global $GS_MENU_CMD_DATA_SPLITTER = $__CMD_DATA_SPLITTER__; End $GS_MENU_CMD_DATA_SPLITTER == '', "Error [$ME]: Failed to generate command / data splitter."; Global $GS_MENU_CMD_LIST = $cmdList; End $GS_MENU_CMD_LIST == '', "Error [$ME]: Failed to generate command list."; Global $GS_XY_VERSION = ""; End $GS_XY_VERSION == '', "Error [$ME]: Failed to retrieve XYplorer version."; Unset $__CMD_DATA_SPLITTER__, $cmdList, $titleList, $ME; "Refresh Menu Data||4 : _refreshMenuData" Status 'Checking freshness of menu data....',, 'progress'; Global $GS_MENU_TITLES, $GS_MENU_CMD_DATA_SPLITTER, $GS_MENU_CMD_LIST, $GS_XY_VERSION; $update = $GS_MENU_TITLES == ''; $update = $update || $GS_MENU_CMD_DATA_SPLITTER == ''; $update = $update || $GS_MENU_CMD_LIST == ''; $update = $update || $GS_XY_VERSION == ''; if (! $update) { Global $GT_UPDATE_MENU_ON_BETAS; if ($GT_UPDATE_MENU_ON_BETAS) { $idx = -1; // Use the full version. } else { $idx = 2; // Use the first two tokens. } $menuVer = GetToken($GS_XY_VERSION, $idx, '.', 't', 1); $xyVer = GetToken("", $idx, '.', 't', 1); $update = $menuVer < $xyVer; Unset $idx, $menuVer, $xyVer; } if ($update) { Sub '_updateMenuData'; } Unset $update; "Update Menu Data : _updateMenuData" Status 'Updating menu data...',, 'progress'; Sub '_genMenuData'; Sub '_setOptions'; "- : _-" //--------------------------------------------------------------------- "Show Menu||1 : showMenu" Status 'Preparing to show menu...',, 'progress'; $ME = Self('Caption'); Sub '_Initialize'; Sub '_refreshMenuData'; Global $GS_MENU_TITLES; End $GS_MENU_TITLES == '', "Error [$ME]: Missing menu title list."; Global $GS_MENU_CMD_DATA_SPLITTER; End $GS_MENU_CMD_DATA_SPLITTER == '', "Error [$ME]: Missing command / data splitter."; Global $GS_MENU_CMD_LIST; End $GS_MENU_CMD_LIST == '', "Error [$ME]: Missing command list."; Status 'Showing menu titles...',, 'progress'; $response = PopUpMenu($GS_MENU_TITLES . '|-|-|&>>>',,,,,, '|'); End ! $response; if ($response == '&>>>') { Status 'Displaying script menu...',, 'progress'; Load '*', 'showMenu;_updateMenuData;-;_createCallerScript;_createCTB;-;_toggleMenu'; } else { // Filter the command list based on user's title selection. $list = FormatList($GS_MENU_CMD_LIST, 'f', "", "$response | *"); $list = RegexReplace($list, "^$response\s*\|\s*"); // Show title's corresponding menu. Status 'Displaying menu...',,' progress'; $response = PopUpMenu($list,,,,,, "", $GS_MENU_CMD_DATA_SPLITTER); End ! $response; Status "Executing #$response: " . Get('MenuCaption', $response, 2),, 'ready'; Load "#$response;",, 's'; Unset $response, $list, $ME; } "Create Script to Show Menu : _createCallerScript" Status 'Generating calling script...',, 'progress'; $scriptFile = Self('File'); End ! $scriptFile, 'This requires the main script be saved to a file.'; Status 'Displaying calling script.',, 'ready'; Text <<<#SCRIPT Load '$scriptFile', 'showMenu', 'f'; #SCRIPT, , , 'Script to Show Menu'; Unset $scriptFile; "Create Custom Toolbar Button : _createCTB" Status 'Generating custom toolbar button...',, 'progress'; $scriptFile = Self('File'); End ! $scriptFile, 'This requires the main script be saved to a file.'; $unresolvedIconPath = '\'; Snippet <<<#SNIPPET Snip: CTB 1 XYplorer , Action NewUserButton Name Show Menu Icon $unresolvedIconPath ScriptL Load '$scriptFile', 'showMenu', 'f'; ScriptR "Update Menu Data" Load '$scriptFile', '_updateMenuData', 'f'; "Create Script to Show Menu" Load '$scriptFile', '_createCallerScript', 'f'; "Show/Hide Main Menu" Load '$scriptFile', '_toggleMenu', 'f'; FireClick 1 #SNIPPET; Status 'Custom Toolbar Button created.',, 'ready'; Unset $scriptFile, $unresolvedIconPath; "Show/Hide Main Menu : _toggleMenu" Status 'Toggling main menu display....',, 'progress'; #1061; //Miscellaneous | General Functions | Show/Hide Main Menu Status 'Toggled main menu display.',, 'ready';