liuyuqi-dellpc 4 years ago
commit
c4a5c86209
8 changed files with 384 additions and 0 deletions
  1. 285 0
      MainMenu.xys.txt
  2. 22 0
      README.md
  3. 8 0
      html-preview.xys
  4. 11 0
      open-vscode.xys
  5. 10 0
      test/change-file-date.xys
  6. 16 0
      test/go-to-dir.xys
  7. 21 0
      test/hello.xys
  8. 11 0
      test/open-spanel.xys

+ 285 - 0
MainMenu.xys.txt

@@ -0,0 +1,285 @@
+/*********************
+ @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 = "<xyscripts>\.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, '¶', "<crlf>");
+        $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, "<crlf>", '¶');
+    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 = "<clipboard>";
+  CopyText '';
+  Status "In 'List of All Commands' dialog: Right-Click > 'Copy All Items' then Cancel.",, 'progress';
+  #705; //List of Functions
+  $G_CMD_LIST = "<clipboard>";
+  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, "<crlf>") {
+    if (! $line) { continue; }
+    // Description
+    $des = GetToken($line, 2, "<tab>", '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, "<tab>", '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<crlf>";
+  }
+  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 = "<xyver>";
+  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("<xyver>",     $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', "<crlf>", "$response | *");
+    $list = RegexReplace($list, "^$response\s*\|\s*");
+    // Show title's corresponding menu.
+    Status 'Displaying menu...',,' progress';
+    $response = PopUpMenu($list,,,,,, "<crlf>", $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 = '<xypath>\<xyexe>';
+  Snippet <<<#SNIPPET
+Snip: CTB 1
+  XYplorer <xyver>, <date>
+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';

+ 22 - 0
README.md

@@ -0,0 +1,22 @@
+## XYplorer-Script
+
+xyplorer 脚本后缀 .xys 或者 .xyi
+
+## Usage
+
+1、地址栏输入:
+
+```
+::msg "Hello world!"
+```
+
+2、脚本--运行脚本---确定
+
+```
+msg "Hello world!"
+```
+
+## screenshot
+
+![](https://cdn.yoqi.me/blog/wp-content/uploads/2019/07/3.gif)
+

+ 8 - 0
html-preview.xys

@@ -0,0 +1,8 @@
+/*********************
+ @Author  :   liuyuqi
+ @Contact :   liuyuqi.gov@msn.cn
+ @Time    :   2019/07/23 05:47:21
+ @Version :   1.0
+ @License :   (C)Copyright 2019 liuyuqi.
+ @Desc    :   html 预览
+*********************/

+ 11 - 0
open-vscode.xys

@@ -0,0 +1,11 @@
+/*********************
+ @Author  :   liuyuqi
+ @Contact :   liuyuqi.gov@msn.cn
+ @Time    :   2019/07/23 05:54:37
+ @Version :   1.0
+ @License :   (C)Copyright 2019 liuyuqi.
+ @Desc    :   None
+*********************/
+
+openwith D:\Program-Files\VSCode-win32-x64-1.30.1\Code.exe
+

+ 10 - 0
test/change-file-date.xys

@@ -0,0 +1,10 @@
+/*********************
+ @Author  :   liuyuqi
+ @Contact :   liuyuqi.gov@msn.cn
+ @Time    :   2019/07/23 05:43:34
+ @Version :   1.0
+ @License :   (C)Copyright 2019 liuyuqi.
+ @Desc    :   None
+*********************/
+
+rename "b", "*-<datem yyyymmdd>"

+ 16 - 0
test/go-to-dir.xys

@@ -0,0 +1,16 @@
+/*********************
+ @Author  :   liuyuqi
+ @Contact :   liuyuqi.gov@msn.cn
+ @Time    :   2019/07/23 05:45:26
+ @Version :   1.0
+ @License :   (C)Copyright 2019 liuyuqi.
+ @Desc    :   None
+*********************/
+
+
+"Go to C:\ : croot"
+  goto "C:\"
+"Go to System Folder : system"
+  goto "%winsysdir%"
+"Go to XYplorer Folder : xy"
+  goto "<xypath>"

+ 21 - 0
test/hello.xys

@@ -0,0 +1,21 @@
+/*********************
+ @Author  :   liuyuqi
+ @Contact :   liuyuqi.gov@msn.cn
+ @Time    :   2019/07/23 05:33:20
+ @Version :   1.0
+ @License :   (C)Copyright 2019 liuyuqi.
+ @Desc    :   None
+*********************/
+
+msg "Hello world!"
+
+msg "%temp%"
+
+msg "XYplorer.exe runs from <xypath>"
+
+msg "Press OK to copy the time!"; copytext "<date hh:nn:ss>"
+
+$a = "<curpath>"; msg $a
+
+$a = "Year " . "<date yyyy>"; msg $a
+

+ 11 - 0
test/open-spanel.xys

@@ -0,0 +1,11 @@
+/*********************
+ @Author  :   liuyuqi
+ @Contact :   liuyuqi.gov@msn.cn
+ @Time    :   2019/07/23 05:41:56
+ @Version :   1.0
+ @License :   (C)Copyright 2019 liuyuqi.
+ @Desc    :   None
+*********************/
+
+#1026
+