30 #include <SimoxUtility/algorithm/string/string_tools.h>
32 #include <boost/property_tree/xml_parser.hpp>
34 #define EDITORFILEOPENER_CONFIGFILE "ArmarXGui/EditorFileOpenerConfig.xml"
35 #define FILE_VARIABLE "$file"
36 #define LINE_VARIABLE "$line"
37 #define DEFAULT_EDITOR "qtcreator"
43 setTag(
"EditorFileOpener");
44 using namespace boost::property_tree;
49 if (configFile.empty())
62 xml_parser::read_xml(configFile, pt);
64 catch (xml_parser::xml_parser_error& e)
68 << configFile <<
"'. Required parameters may be unset.\nReason at "
69 << e.filename() <<
":" << e.line() <<
":\n" << e.message() <<
flush;
73 for (ptree::value_type
const&
v : pt.get_child(
"editors"))
75 if (
v.first ==
"editor")
77 std::string editorName =
v.second.get<std::string>(
"name");
78 std::string openCommandLine =
v.second.get<std::string>(
"opencommandline");
79 editors[editorName] = openCommandLine;
86 std::string openCommandLine = editors[editorName];
88 if (openCommandLine.empty())
90 ARMARX_WARNING <<
"Cannot find editor named '" << editorName <<
"'";
94 std::string::size_type lenFile = std::string(
FILE_VARIABLE).size();
95 std::string::size_type posFile = openCommandLine.find(
FILE_VARIABLE);
97 if (posFile != std::string::npos)
99 openCommandLine.replace(posFile, lenFile, filepath);
102 std::string::size_type lenLine = std::string(
LINE_VARIABLE).size();
103 std::string::size_type posLine = openCommandLine.find(
LINE_VARIABLE);
104 std::stringstream lineStr;
105 lineStr << lineNumber;
107 if (posLine != std::string::npos)
109 openCommandLine.replace(posLine, lenLine, lineStr.str());
112 simox::alg::trim(openCommandLine);
114 if (*openCommandLine.rbegin() !=
'&')
116 openCommandLine +=
" &";
121 if (std::system(openCommandLine.c_str())) {}
126 const char* envEditor = std::getenv(
"ARMARX_EDITOR");
128 const std::string editorName = [&]() -> std::string
130 if (envEditor ==
nullptr)
135 const std::string editor = std::string(envEditor);
136 if (editors.count(editor) > 0)
141 ARMARX_WARNING <<
"The editor '" << editor <<
"' is not registered. "
147 openFile(editorName, filepath, lineNumber);