3 #include "PUIFileDialog.hxx"
5 #include <boost/foreach.hpp>
7 #include <simgear/debug/logstream.hxx>
8 #include <simgear/props/props_io.hxx>
10 #include <Main/globals.hxx>
11 #include <Main/fg_props.hxx>
12 #include <GUI/new_gui.hxx>
14 class PUIFileDialog::PathListener : public SGPropertyChangeListener
17 PathListener(PUIFileDialog* dlg) :
21 virtual void valueChanged(SGPropertyNode* node)
23 _dialog->pathChanged(SGPath(node->getStringValue()));
27 PUIFileDialog* _dialog;
30 PUIFileDialog::PUIFileDialog(const std::string& aTitle, Usage use) :
31 FGFileDialog(aTitle, use),
34 SG_LOG(SG_GENERAL, SG_INFO, "created PUIFileDialog");
37 PUIFileDialog::~PUIFileDialog()
40 SGPropertyNode_ptr path = _dialogRoot->getNode("path");
41 path->removeChangeListener(_listener);
45 void PUIFileDialog::exec()
47 NewGUI* gui = static_cast<NewGUI*>(globals->get_subsystem("gui"));
48 std::string name("native-file-0");
49 _dialogRoot = fgGetNode("/sim/gui/dialogs/" + name, true);
51 SGPropertyNode_ptr dlg = _dialogRoot->getChild("dialog", 0, true);
52 SGPath dlgXML = globals->resolve_resource_path("gui/dialogs/file-select.xml");
53 readProperties(dlgXML.str(), dlg);
55 dlg->setStringValue("name", name);
58 _dialogRoot->setStringValue("title", _title);
59 _dialogRoot->setStringValue("button", _buttonText);
60 _dialogRoot->setStringValue("directory", _initialPath.str());
61 _dialogRoot->setStringValue("selection", _placeholder);
63 // convert patterns vector into pattern nodes
64 _dialogRoot->removeChildren("pattern");
66 BOOST_FOREACH(std::string pat, _filterPatterns) {
67 _dialogRoot->getNode("pattern", index++, true)->setStringValue(pat);
70 _dialogRoot->setBoolValue("show-files", _usage != USE_CHOOSE_DIR);
71 _dialogRoot->setBoolValue("dotfiles", _showHidden);
74 _listener = new PathListener(this);
76 SGPropertyNode_ptr path = _dialogRoot->getNode("path", 0, true);
77 path->addChangeListener(_listener);
79 gui->showDialog(name);
82 void PUIFileDialog::pathChanged(const SGPath& aPath)
84 _callback->onFileDialogDone(this, aPath);