From f617325006e7b7f22340b0a49f60a82e3d0392b4 Mon Sep 17 00:00:00 2001 From: Don HO Date: Mon, 21 Dec 2020 17:54:10 +0100 Subject: [PATCH] Enhance ghost typing command line argument feature Enhance ghost typing command line argument feature by changing its format: With it's new format -qX="string contains white space" (where X is 't', 'n' or 'f'), the white spaces can be contained between double quote, so no need to use %20 anymore for substituting white spacees. --- PowerEditor/src/Notepad_plus_Window.h | 10 +++++----- PowerEditor/src/winmain.cpp | 18 ++++++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/PowerEditor/src/Notepad_plus_Window.h b/PowerEditor/src/Notepad_plus_Window.h index c846d67d..d02cb7bb 100644 --- a/PowerEditor/src/Notepad_plus_Window.h +++ b/PowerEditor/src/Notepad_plus_Window.h @@ -31,12 +31,12 @@ const TCHAR COMMAND_ARG_HELP[] = TEXT("Usage :\r\ \r\ -notepad++ [--help] [-multiInst] [-noPlugin] [-lLanguage] [-LlangCode] [-nLineNumber] [-cColumnNumber] [-pPosition] [-xLeftPos] [-yTopPos] [-nosession] [-notabbar] [-ro] [-systemtray] [-loadingTime] [-alwaysOnTop] [-openSession] [-r] [-qnEasterEggName | -qtText | -qfCntentFileName] [-qSpeed1|2|3] [-quickPrint] [-settingsDir=\"d:\\your settings dir\\\"] [-openFoldersAsWorkspace] [filePath]\r\ +notepad++ [--help] [-multiInst] [-noPlugin] [-lLanguage] [-LlangCode] [-nLineNumber] [-cColumnNumber] [-pPosition] [-xLeftPos] [-yTopPos] [-nosession] [-notabbar] [-ro] [-systemtray] [-loadingTime] [-alwaysOnTop] [-openSession] [-r] [-qn=\"Easter egg name\" | -qt=\"a text to display.\" | -qf=\"D:\\my quote.txt\"] [-qSpeed1|2|3] [-quickPrint] [-settingsDir=\"d:\\your settings dir\\\"] [-openFoldersAsWorkspace] [filePath]\r\ \r\ --help : This help message\r\ -multiInst : Launch another Notepad++ instance\r\ -noPlugin : Launch Notepad++ without loading any plugin\r\ --l : Open file or display ghost typing with syntax highlighting of choice\r\ +-l : Open file or Ghost type with syntax highlighting of choice\r\ -L : Apply indicated localization, langCode is browser language code\r\ -n : Scroll to indicated line on filePath\r\ -c : Scroll to indicated column on filePath\r\ @@ -52,9 +52,9 @@ notepad++ [--help] [-multiInst] [-noPlugin] [-lLanguage] [-LlangCode] [-nLineNum -openSession : Open a session. filePath must be a session file\r\ -r : Open files recursively. This argument will be ignored\r\ if filePath contain no wildcard character\r\ --qn : Launch ghost typing to display easter egg via its name\r\ --qt : Launch ghost typing to display a text via the given text\r\ --qf : Launch ghost typing to display a file content via the file path\r\ +-qn=\"Easter egg name\": Ghost type easter egg via its name\r\ +-qt=\"text to display.\": Ghost type the given text\r\ +-qf=\"D:\\my quote.txt\": Ghost type a file content via the file path\r\ -qSpeed : Ghost typing speed. Value from 1 to 3 for slow, fast and fastest\r\ -quickPrint : Print the file given as argument then quit Notepad++\r\ -settingsDir=\"d:\\your settings dir\\\": Override the default settings dir\r\ diff --git a/PowerEditor/src/winmain.cpp b/PowerEditor/src/winmain.cpp index 5cbdfde7..dca76747 100644 --- a/PowerEditor/src/winmain.cpp +++ b/PowerEditor/src/winmain.cpp @@ -262,15 +262,14 @@ int getNumberFromParam(char paramName, ParamVector & params, bool & isParamePres generic_string getEasterEggNameFromParam(ParamVector & params, unsigned char & type) { generic_string EasterEggName; - if (!getParamValFromString(TEXT("-qn"), params, EasterEggName)) // get internal easter egg + if (!getParamValFromString(TEXT("-qn="), params, EasterEggName)) // get internal easter egg { - if (!getParamValFromString(TEXT("-qt"), params, EasterEggName)) // get user quote from cmdline argument + if (!getParamValFromString(TEXT("-qt="), params, EasterEggName)) // get user quote from cmdline argument { - if (!getParamValFromString(TEXT("-qf"), params, EasterEggName)) // get user quote from a content of file + if (!getParamValFromString(TEXT("-qf="), params, EasterEggName)) // get user quote from a content of file return TEXT(""); else { - EasterEggName = relativeFilePathToFullFilePath(EasterEggName.c_str()); type = 2; // quote content in file } } @@ -280,15 +279,14 @@ generic_string getEasterEggNameFromParam(ParamVector & params, unsigned char & t else type = 0; // easter egg - generic_string percentTwentyStr = TEXT("%20"); - generic_string spaceStr = TEXT(" "); - size_t start_pos = 0; - while ((start_pos = EasterEggName.find(percentTwentyStr, start_pos)) != std::string::npos) + if (EasterEggName.c_str()[0] == '"' && EasterEggName.c_str()[EasterEggName.length() - 1] == '"') { - EasterEggName.replace(start_pos, percentTwentyStr.length(), spaceStr); - start_pos += spaceStr.length(); // Handles case where 'to' is a substring of 'from' + EasterEggName = EasterEggName.substr(1, EasterEggName.length() - 2); } + if (type == 2) + EasterEggName = relativeFilePathToFullFilePath(EasterEggName.c_str()); + return EasterEggName; }