mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-29 15:16:05 +00:00
Changed: NeL helpers to launch an external editor
--HG-- branch : develop
This commit is contained in:
parent
5658cad02e
commit
5dfa19518a
1 changed files with 26 additions and 31 deletions
|
@ -34,19 +34,23 @@ bool EditExternalText (const std::string &editor, std::string &text, const std::
|
|||
{
|
||||
bool status = false;
|
||||
// Create a temporary file
|
||||
char dir[512];
|
||||
if (getcwd (dir, 512))
|
||||
std::string dir = CPath::getCurrentPath();
|
||||
|
||||
if (!dir.empty())
|
||||
{
|
||||
// Build a temporary filename
|
||||
string tempFilename;
|
||||
uint i = 0;
|
||||
|
||||
do
|
||||
tempFilename = string(dir)+"/~tmp"+toString (i++)+"."+ext;
|
||||
{
|
||||
tempFilename = string(dir) + "/~tmp" + toString(i++) + "." + ext;
|
||||
}
|
||||
while (NLMISC::CFile::isExists(tempFilename));
|
||||
|
||||
// Fill the temp file
|
||||
bool saved = false;
|
||||
FILE *file = fopen (tempFilename.c_str(), "w");
|
||||
FILE *file = nlfopen (tempFilename, "w");
|
||||
if (file)
|
||||
{
|
||||
saved = fputs (text.c_str(), file) != EOF;
|
||||
|
@ -54,25 +58,16 @@ bool EditExternalText (const std::string &editor, std::string &text, const std::
|
|||
}
|
||||
|
||||
// Hide the file
|
||||
SetFileAttributes (tempFilename.c_str(), FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
|
||||
SetFileAttributes (utf8ToTStr(tempFilename), FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
|
||||
|
||||
// Open the temp file with a text editor
|
||||
if (saved)
|
||||
{
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
memset(&si, 0, sizeof(si));
|
||||
memset(&pi, 0, sizeof(pi));
|
||||
si.cb = sizeof(si);
|
||||
char cmdLine[1024];
|
||||
strncpy (cmdLine, ("\""+editor+"\" \""+tempFilename+"\"").c_str(), sizeof(cmdLine)-1);
|
||||
if (CreateProcess(editor.c_str (), cmdLine, NULL, NULL, FALSE, 0, NULL, dir, &si, &pi))
|
||||
{
|
||||
if (WaitForSingleObject (pi.hProcess, INFINITE) == WAIT_OBJECT_0)
|
||||
if (launchProgramAndWaitForResult(editor, tempFilename))
|
||||
{
|
||||
// Open the file..
|
||||
std::string tempText;
|
||||
FILE *file = fopen (tempFilename.c_str(), "r");
|
||||
FILE *file = nlfopen (tempFilename.c_str(), "r");
|
||||
if (file)
|
||||
{
|
||||
// Read the new file
|
||||
|
@ -83,6 +78,7 @@ bool EditExternalText (const std::string &editor, std::string &text, const std::
|
|||
buffer[red] = 0;
|
||||
tempText += buffer;
|
||||
}
|
||||
|
||||
fclose (file);
|
||||
|
||||
// Return the text
|
||||
|
@ -91,7 +87,6 @@ bool EditExternalText (const std::string &editor, std::string &text, const std::
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the file
|
||||
NLMISC::CFile::deleteFile (tempFilename);
|
||||
|
|
Loading…
Reference in a new issue