]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/FileDialog.cxx
Support for multiple data dirs.
[flightgear.git] / src / GUI / FileDialog.cxx
index 8b59ae0c79a1b985b1546d77bef303990cf5b16a..33f10838b907f8b06daa32d2201b2b859da0855e 100644 (file)
@@ -39,9 +39,8 @@
     #include "CocoaFileDialog.hxx"
 #endif
 
-FGFileDialog::FGFileDialog(const std::string& aTitle, Usage use) :
+FGFileDialog::FGFileDialog(Usage use) :
     _usage(use),
-    _title(aTitle),
     _showHidden(false)
 {
     
@@ -52,6 +51,11 @@ FGFileDialog::~FGFileDialog()
     // ensure this is concrete so callback gets cleaned up.
 }
 
+void FGFileDialog::setTitle(const std::string& aText)
+{
+    _title = aText;
+}
+
 void FGFileDialog::setButton(const std::string& aText)
 {
     _buttonText = aText;
@@ -82,12 +86,6 @@ void FGFileDialog::setShowHidden(bool show)
     _showHidden = show;
 }
 
-naRef FGFileDialog::openFromNasal(const nasal::CallContext& ctx)
-{
-    exec();
-    return naNil();
-}
-
 class NasalCallback : public FGFileDialog::Callback
 {
 public:
@@ -123,32 +121,30 @@ private:
     int _gcKeys[2];
 };
 
-naRef FGFileDialog::setCallbackFromNasal(const nasal::CallContext& ctx)
+void FGFileDialog::setCallbackFromNasal(const nasal::CallContext& ctx)
 {
     // wrap up the naFunc in our callback type
     naRef func = ctx.requireArg<naRef>(0);
     naRef object = ctx.getArg<naRef>(1, naNil());
     
     setCallback(new NasalCallback(func, object));
-    return naNil();
 }
 
 typedef boost::shared_ptr<FGFileDialog> FileDialogPtr;
 typedef nasal::Ghost<FileDialogPtr> NasalFileDialog;
 
 /**
- * Create new Canvas and get ghost for it.
+ * Create new FGFileDialog and get ghost for it.
  */
 static naRef f_createFileDialog(naContext c, naRef me, int argc, naRef* args)
 {
     nasal::CallContext ctx(c, argc, args);
-    std::string title = ctx.requireArg<std::string>(0);
-    FGFileDialog::Usage usage = (FGFileDialog::Usage) ctx.requireArg<int>(1);
-    
+    FGFileDialog::Usage usage = (FGFileDialog::Usage) ctx.requireArg<int>(0);
+  
 #ifdef SG_MAC
-    FileDialogPtr fd(new CocoaFileDialog(title, usage));
+    FileDialogPtr fd(new CocoaFileDialog(usage));
 #else
-    FileDialogPtr fd(new PUIFileDialog(title, usage));
+    FileDialogPtr fd(new PUIFileDialog(usage));
 #endif
     
     return NasalFileDialog::create(c, fd);
@@ -156,23 +152,21 @@ static naRef f_createFileDialog(naContext c, naRef me, int argc, naRef* args)
 
 void postinitNasalGUI(naRef globals, naContext c)
 {
-    NasalFileDialog::init("gui.FileSelector")
+    NasalFileDialog::init("gui._FileDialog")
+    .member("title", &FGFileDialog::getTitle,  &FGFileDialog::setTitle)
     .member("button", &FGFileDialog::getButton,  &FGFileDialog::setButton)
     .member("directory", &FGFileDialog::getDirectory, &FGFileDialog::setDirectory)
-    .member("show-hidden", &FGFileDialog::showHidden, &FGFileDialog::setShowHidden)
+    .member("show_hidden", &FGFileDialog::showHidden, &FGFileDialog::setShowHidden)
     .member("placeholder", &FGFileDialog::getPlaceholder, &FGFileDialog::setPlaceholderName)
     .member("pattern", &FGFileDialog::filterPatterns, &FGFileDialog::setFilterPatterns)
-    .method<&FGFileDialog::openFromNasal>("open")
-    .method<&FGFileDialog::setCallbackFromNasal>("setCallback");
-    
-    naRef guiModule = naHash_cget(globals, (char*) "gui");
-    if (naIsNil(guiModule)) {
-        SG_LOG(SG_GENERAL, SG_WARN, "postinitNasalGUI: gui.nas not loaded");
-        return;
-    }
-    
-    nasal::Hash globals_module(globals, c),
-        gui_module = globals_module.get<nasal::Hash>("gui");
+    .method("open", &FGFileDialog::exec)
+    .method("close", &FGFileDialog::close)
+    .method("setCallback", &FGFileDialog::setCallbackFromNasal);
+
+    nasal::Hash guiModule = nasal::Hash(globals, c).get<nasal::Hash>("gui");
     
-    gui_module.set("_newFileDialog", f_createFileDialog);
+    guiModule.set("FILE_DIALOG_OPEN_FILE", (int) FGFileDialog::USE_OPEN_FILE);
+    guiModule.set("FILE_DIALOG_SAVE_FILE", (int) FGFileDialog::USE_SAVE_FILE);
+    guiModule.set("FILE_DIALOG_CHOOSE_DIR", (int) FGFileDialog::USE_CHOOSE_DIR);
+    guiModule.set("_createFileDialog", f_createFileDialog);
 }