OSDN Git Service

- Allow environment variables to be included in the path of the external editor
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Fri, 21 May 2021 14:19:41 +0000 (23:19 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Fri, 21 May 2021 14:19:41 +0000 (23:19 +0900)
- Set the initial value of the path of the external editor to% windir%\NOTEPAD.EXE

Src/Environment.cpp
Src/Environment.h
Src/Merge.cpp
Src/OptionsInit.cpp

index fcbfeab..327f6d7 100644 (file)
@@ -182,6 +182,19 @@ static bool launchProgram(const String& sCmd, WORD wShowWindow)
        return true;
 }
 
+String ExpandEnvironmentVariables(const String& text)
+{
+       TCHAR buf[512];
+       buf[0] = 0;
+       const unsigned size = sizeof(buf) / sizeof(buf[0]);
+       const unsigned expandedSize = ::ExpandEnvironmentStrings(text.c_str(), buf, size);
+       if (expandedSize <= size)
+               return buf;
+       std::vector<TCHAR> newbuf(expandedSize);
+       ::ExpandEnvironmentStrings(text.c_str(), newbuf.data(), expandedSize);
+       return newbuf.data();
+}
+
 /**
  * @brief Load registry keys from .reg file if existing .reg file
  */
index c8d4371..527f08c 100644 (file)
@@ -24,6 +24,8 @@ String GetSystemTempPath();
 
 String GetPerInstanceString(const String& name);
 
+String ExpandEnvironmentVariables(const String& text);
+
 bool LoadRegistryFromFile(const String& sRegFilePath);
 bool SaveRegistryToFile(const String& sRegFilePath, const String& sRegDir);
 
index e05fa33..5aa61d6 100644 (file)
@@ -803,7 +803,7 @@ void CMergeApp::OnHelp()
  */
 void CMergeApp::OpenFileToExternalEditor(const String& file, int nLineNumber/* = 1*/)
 {
-       String sCmd = GetOptionsMgr()->GetString(OPT_EXT_EDITOR_CMD);
+       String sCmd = env::ExpandEnvironmentVariables(GetOptionsMgr()->GetString(OPT_EXT_EDITOR_CMD));
        String sFile(file);
        strutils::replace(sCmd, _T("$linenum"), strutils::to_str(nLineNumber));
 
index d908f92..5c28f66 100644 (file)
@@ -114,7 +114,7 @@ void Init(COptionsMgr *pOptions)
        pOptions->InitOption(OPT_TAB_SIZE, (int)4);
        pOptions->InitOption(OPT_TAB_TYPE, (int)0);     // 0 means tabs inserted
 
-       pOptions->InitOption(OPT_EXT_EDITOR_CMD, paths::ConcatPath(env::GetWindowsDirectory(), _T("NOTEPAD.EXE")));
+       pOptions->InitOption(OPT_EXT_EDITOR_CMD, _T("%windir%\\NOTEPAD.EXE"));
        pOptions->InitOption(OPT_USE_RECYCLE_BIN, true);
        pOptions->InitOption(OPT_SINGLE_INSTANCE, 0);
        pOptions->InitOption(OPT_MERGE_MODE, false);