* @brief Open given file to external editor specified in options. * @param [in] file Full path to file to open. * * Opens file to defined (in Options/system), Notepad by default, * external editor. Path is decorated with quotation marks if needed * (contains spaces). Also '$file' in editor path is replaced by * filename to open. * @param [in] file Full path to file to open. * @param [in] n
| 1129 | * @param [in] nLineNumber Line number to go to. |
| 1130 | */ |
| 1131 | void CMergeApp::OpenFileToExternalEditor(const String& file, int nLineNumber/* = 1*/) |
| 1132 | { |
| 1133 | String sCmd = env::ExpandEnvironmentVariables(GetOptionsMgr()->GetString(OPT_EXT_EDITOR_CMD)); |
| 1134 | String sFile(file); |
| 1135 | strutils::replace(sCmd, _T("$linenum"), strutils::to_str(nLineNumber)); |
| 1136 | |
| 1137 | size_t nIndex = sCmd.find(_T("$file")); |
| 1138 | if (nIndex != String::npos) |
| 1139 | { |
| 1140 | sFile.insert(0, _T("\"")); |
| 1141 | strutils::replace(sCmd, _T("$file"), sFile); |
| 1142 | nIndex = sCmd.find(' ', nIndex + sFile.length()); |
| 1143 | if (nIndex != String::npos) |
| 1144 | sCmd.insert(nIndex, _T("\"")); |
| 1145 | else |
| 1146 | sCmd += '"'; |
| 1147 | } |
| 1148 | else |
| 1149 | { |
| 1150 | sCmd += _T(" \""); |
| 1151 | sCmd += sFile; |
| 1152 | sCmd += _T("\""); |
| 1153 | } |
| 1154 | |
| 1155 | bool retVal = false; |
| 1156 | STARTUPINFO stInfo = { sizeof STARTUPINFO }; |
| 1157 | PROCESS_INFORMATION processInfo; |
| 1158 | |
| 1159 | retVal = !!CreateProcess(nullptr, (tchar_t*)sCmd.c_str(), |
| 1160 | nullptr, nullptr, FALSE, CREATE_DEFAULT_ERROR_MODE, nullptr, nullptr, |
| 1161 | &stInfo, &processInfo); |
| 1162 | |
| 1163 | if (!retVal) |
| 1164 | { |
| 1165 | // Error invoking external editor |
| 1166 | String msg = strutils::format_string1(_("Failed to execute external editor: %1"), sCmd); |
| 1167 | AfxMessageBox(msg.c_str(), MB_ICONSTOP); |
| 1168 | } |
| 1169 | else |
| 1170 | { |
| 1171 | CloseHandle(processInfo.hThread); |
| 1172 | CloseHandle(processInfo.hProcess); |
| 1173 | } |
| 1174 | } |
| 1175 | |
| 1176 | /** @brief Returns pointer to global file filter */ |
| 1177 | FileFilterHelper* CMergeApp::GetGlobalFileFilter() |
nothing calls this directly
no test coverage detected