Added support for invoked an editor defined by P3D_EDITOR or EDITOR env vars when user press 'U' in Present3D.

This feature makes it easier to editor an presentation that is already running in Present3D, once the edits are done
pressing 'u' in Present3D then loads the file again.
This commit is contained in:
Robert Osfield
2016-03-11 19:41:22 +00:00
parent cb2af961db
commit 9d68e13567
2 changed files with 28 additions and 0 deletions

View File

@@ -2956,6 +2956,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(const std::string&
local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName));
local_opt->setFindFileCallback(new MyFindFileCallback);
local_opt->setPluginStringData("filename",file);
local_opt->setPluginStringData("fullpath",fileName);
osgDB::XmlNode::Input input;
input.open(fileName);
@@ -2980,6 +2981,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(std::istream& fin,
osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(osgDB::XmlNode::Input& input, osgDB::ReaderWriter::Options* options) const
{
std::string fileName = options ? options->getPluginStringData("filename") : std::string();
std::string fullpath = options ? options->getPluginStringData("fullpath") : std::string();
std::string extension = osgDB::getFileExtension(fileName);
std::string fileNameSansExtension = osgDB::getNameLessExtension(fileName);
std::string nestedExtension = osgDB::getFileExtension(fileNameSansExtension);
@@ -3085,6 +3087,9 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(osgDB::XmlNode::Inp
if (presentation_node.valid())
{
presentation_node->setUserValue("filename",fileName);
presentation_node->setUserValue("fullpath",fullpath);
if (!options || options->getPluginStringData("P3D_EVENTHANDLER")!="none")
{
// if (!readOnlyHoldingPage && !readOnlyMainPresentation)

View File

@@ -907,6 +907,10 @@ void SlideEventHandler::set(osg::Node* model)
FindNamedSwitchVisitor findPresentation("Presentation");
model->accept(findPresentation);
std::string fullpath;
model->getUserValue("fullpath", fullpath);
if (!fullpath.empty()) setUserValue("fullpath", fullpath);
if (findPresentation._switch)
{
OSG_INFO<<"Presentation '"<<model->getName()<<"'"<<std::endl;
@@ -1192,6 +1196,25 @@ bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction
return true;
}
else if (ea.getKey()=='U')
{
char* editor = getenv("P3D_EDITOR");
if (!editor) editor = getenv("EDITOR");
std::string filename;
if (editor && getUserValue("fullpath", filename) && !filename.empty())
{
std::stringstream command;
command<<editor<<" "<<filename<<" &"<<std::endl;
int result = system(command.str().c_str());
OSG_INFO<<"system("<<command.str()<<") result "<<result<<std::endl;
}
return true;
}
return false;
}
case(osgGA::GUIEventAdapter::KEYUP):