# HG changeset patch
# User John Donoghue <john.donoghue@ieee.org>
# Date 1367182800 14400
# Node ID fa4a035e0cf433b0ad3742ac18fc698fd56f681b
# Parent  adc150db18099fdd02f4ad184faf3e3fe55a612b
Add octave_link uiputfile implementation

* libgui/src/dialog.cc, libgui/src/dialog.h
  (FileDialog::FileDialog): Change bool multiselect to QString multimode, add mode option of 'create' and set options accordingly.
  (QUIWidgetCreator::signal_filedialog): Change bool multiselect to QString multimode.
  (QUIWidgetCreator::create_filedialog): Change bool multiselect to QString multimode.

* libgui/src/main-window.cc, libgui/src/main-window.h
  (main_window::connect_uiwidget_links): update bool multiselect to QString multimode.
  (main_window::handle_create_filedialog): update bool multiselect to QString multimode.

* libgui/src/octave-qt-link.h
  (octave_qt_link::do_file_dialog): update bool multiselect to std::string multimode.

* libinterp/interpfcn/octave-link.h
  (octave_link::do_file_dialog): update bool multiselect to std::string multimode.
  (octave_link::file_dialog): update bool multiselect to std::string multimode.

* scripts/plot/uiputfile.m
  (uiputfile): update to call __octave_link_file_dialog__ if octave_link is present.

diff -r adc150db1809 -r fa4a035e0cf4 libgui/src/dialog.cc
--- a/libgui/src/dialog.cc	Sun Apr 28 13:41:37 2013 -0400
+++ b/libgui/src/dialog.cc	Sun Apr 28 17:00:00 2013 -0400
@@ -424,7 +424,7 @@
                         const QString& title,
                         const QString& filename,
                         const QString& dirname,
-                        bool multiselect)
+                        const QString& multimode)
   : QFileDialog()
 {
   // Create a NonModal message.
@@ -433,13 +433,26 @@
   setWindowTitle (title.isEmpty () ? " " : title);
   setDirectory (dirname);
 
-  if (multiselect)
-    setFileMode (QFileDialog::ExistingFiles);
-  else
-    setFileMode (QFileDialog::ExistingFile);
+  if (multimode == "on")         // uigetfile multiselect=on
+    {
+      setFileMode (QFileDialog::ExistingFiles);
+      setAcceptMode (QFileDialog::AcceptOpen);
+    }
+  else if(multimode == "create") // uiputfile
+    {
+      setFileMode (QFileDialog::AnyFile); 
+      setAcceptMode (QFileDialog::AcceptSave);
+      setOption (QFileDialog::DontConfirmOverwrite, false);
+      setConfirmOverwrite(true);
+    }
+  else                           // uigetfile multiselect=off
+    {
+      setFileMode (QFileDialog::ExistingFile);
+      setAcceptMode (QFileDialog::AcceptOpen);
+    }
 
   setNameFilters (filters);
-  setAcceptMode (QFileDialog::AcceptOpen);
+
   selectFile (filename);
   
   connect (this,
diff -r adc150db1809 -r fa4a035e0cf4 libgui/src/dialog.h
--- a/libgui/src/dialog.h	Sun Apr 28 13:41:37 2013 -0400
+++ b/libgui/src/dialog.h	Sun Apr 28 17:00:00 2013 -0400
@@ -106,9 +106,9 @@
 
   bool signal_filedialog (const QStringList& filters, const QString& title, 
                           const QString& filename, const QString& dirname, 
-                          bool multiselect)
+                          const QString &multimode)
   {
-    emit create_filedialog (filters, title, filename, dirname, multiselect);
+    emit create_filedialog (filters, title, filename, dirname, multimode);
     return true;
   }
 
@@ -135,7 +135,7 @@
 
   void create_filedialog (const QStringList& filters, const QString& title,
                           const QString& filename, const QString& dirname,
-                          bool multiselect);
+                          const QString& multimode);
 public slots:
 
   void dialog_button_clicked (QAbstractButton *button);
@@ -253,7 +253,7 @@
 
   explicit FileDialog (const QStringList& filters,
                        const QString& title, const QString& filename, 
-                       const QString& dirname, bool multiselect);
+                       const QString& dirname, const QString& multimode);
 
 signals:
 
diff -r adc150db1809 -r fa4a035e0cf4 libgui/src/main-window.cc
--- a/libgui/src/main-window.cc	Sun Apr 28 13:41:37 2013 -0400
+++ b/libgui/src/main-window.cc	Sun Apr 28 17:00:00 2013 -0400
@@ -654,11 +654,11 @@
 
   connect (&uiwidget_creator,
            SIGNAL (create_filedialog (const QStringList &,const QString&,
-                                      const QString&, const QString&, bool)),
+                                      const QString&, const QString&, const QString&)),
            this,
            SLOT (handle_create_filedialog (const QStringList &, const QString&,
                                            const QString&, const QString&,
-                                           bool)));
+                                           const QString&)));
 }
 
 // Create a message dialog with specified string, buttons and decorative
@@ -720,10 +720,10 @@
                                        const QString& title, 
                                        const QString& filename, 
                                        const QString& dirname,
-                                       bool multiselect)
+                                       const QString& multimode)
 {
   FileDialog *file_dialog = new FileDialog (filters, title, filename,
-                                            dirname, multiselect);
+                                            dirname, multimode);
 
   file_dialog->setAttribute (Qt::WA_DeleteOnClose);
   file_dialog->show ();
diff -r adc150db1809 -r fa4a035e0cf4 libgui/src/main-window.h
--- a/libgui/src/main-window.h	Sun Apr 28 13:41:37 2013 -0400
+++ b/libgui/src/main-window.h	Sun Apr 28 17:00:00 2013 -0400
@@ -160,7 +160,7 @@
   void handle_create_filedialog (const QStringList &filters, 
                                  const QString& title, const QString& filename, 
                                  const QString &dirname,
-                                 bool multiselect);
+                                 const QString& multimode);
 
   // find files dialog 
   void find_files(const QString &startdir=QDir::currentPath());
diff -r adc150db1809 -r fa4a035e0cf4 libgui/src/octave-qt-link.cc
--- a/libgui/src/octave-qt-link.cc	Sun Apr 28 13:41:37 2013 -0400
+++ b/libgui/src/octave-qt-link.cc	Sun Apr 28 17:00:00 2013 -0400
@@ -226,7 +226,7 @@
                                 const std::string& title,
                                 const std::string& filename,
                                 const std::string& dirname,
-                                bool multiselect)
+                                const std::string& multimode)
 {
   std::list<std::string> retval;
 
@@ -234,7 +234,7 @@
                                       QString::fromStdString (title),
                                       QString::fromStdString (filename),
                                       QString::fromStdString (dirname),
-                                      multiselect);
+                                      QString::fromStdString (multimode));
 
   // Wait while the user is responding to dialog.
   uiwidget_creator.wait ();
diff -r adc150db1809 -r fa4a035e0cf4 libgui/src/octave-qt-link.h
--- a/libgui/src/octave-qt-link.h	Sun Apr 28 13:41:37 2013 -0400
+++ b/libgui/src/octave-qt-link.h	Sun Apr 28 17:00:00 2013 -0400
@@ -87,7 +87,7 @@
   std::list<std::string>
   do_file_dialog (const filter_list& filter, const std::string& title, 
                   const std::string &filename, const std::string &pathname,
-                  bool multiselect);
+                  const std::string& multimode);
 
   int
   do_debug_cd_or_addpath_error (const std::string& file,
diff -r adc150db1809 -r fa4a035e0cf4 libinterp/interpfcn/octave-link.cc
--- a/libinterp/interpfcn/octave-link.cc	Sun Apr 28 13:41:37 2013 -0400
+++ b/libinterp/interpfcn/octave-link.cc	Sun Apr 28 17:00:00 2013 -0400
@@ -208,7 +208,7 @@
       std::string title = args (1).string_value ();
       std::string filename = args (2).string_value ();
       Matrix pos = args (3).matrix_value ();
-      std::string multi_on = args (4).string_value (); // on, off
+      std::string multi_on = args (4).string_value (); // on, off, create
       std::string pathname = args (5).string_value ();
 
       octave_idx_type nel = flist.numel ();
@@ -225,7 +225,7 @@
 
           std::list<std::string> items_lst
             = octave_link::file_dialog (filter_lst, title, filename, pathname,
-                                        multi_on == "on" ? true : false);
+                                        multi_on);
 
           nel = items_lst.size ();
 
diff -r adc150db1809 -r fa4a035e0cf4 libinterp/interpfcn/octave-link.h
--- a/libinterp/interpfcn/octave-link.h	Sun Apr 28 13:41:37 2013 -0400
+++ b/libinterp/interpfcn/octave-link.h	Sun Apr 28 17:00:00 2013 -0400
@@ -184,10 +184,10 @@
   static std::list<std::string>
   file_dialog (const filter_list& filter, const std::string& title,
                const std::string& filename, const std::string& dirname,
-               bool multiselect)
+               const std::string& multimode)
   {
     return enabled ()
-      ? instance->do_file_dialog (filter, title, filename, dirname, multiselect)
+      ? instance->do_file_dialog (filter, title, filename, dirname, multimode)
       : std::list<std::string> ();
   }
 
@@ -386,7 +386,7 @@
   virtual std::list<std::string>
   do_file_dialog (const filter_list& filter, const std::string& title,
                   const std::string& filename, const std::string& dirname,
-                  bool multiselect) = 0;
+                  const std::string& multimode) = 0;
 
   virtual int
   do_debug_cd_or_addpath_error (const std::string& file,
diff -r adc150db1809 -r fa4a035e0cf4 scripts/plot/uiputfile.m
--- a/scripts/plot/uiputfile.m	Sun Apr 28 13:41:37 2013 -0400
+++ b/scripts/plot/uiputfile.m	Sun Apr 28 17:00:00 2013 -0400
@@ -56,16 +56,18 @@
 
 function [retfile, retpath, retindex] = uiputfile (varargin)
 
-  defaulttoolkit = get (0, "defaultfigure__graphics_toolkit__");
-  funcname = ["__uiputfile_", defaulttoolkit, "__"];
-  functype = exist (funcname);
-  if (! __is_function__ (funcname))
-    funcname = "__uiputfile_fltk__";
+  if (! __octave_link_enabled__ ())
+    defaulttoolkit = get (0, "defaultfigure__graphics_toolkit__");
+    funcname = ["__uiputfile_", defaulttoolkit, "__"];
+    functype = exist (funcname);
     if (! __is_function__ (funcname))
-      error ("uiputfile: fltk graphics toolkit required");
-    elseif (! strcmp (defaulttoolkit, "gnuplot"))
-      warning ("uiputfile: no implementation for toolkit '%s', using 'fltk' instead",
+      funcname = "__uiputfile_fltk__";
+      if (! __is_function__ (funcname))
+        error ("uiputfile: fltk graphics toolkit required");
+      elseif (! strcmp (defaulttoolkit, "gnuplot"))
+        warning ("uiputfile: no implementation for toolkit '%s', using 'fltk' instead",
                defaulttoolkit);
+      endif
     endif
   endif
 
@@ -117,7 +119,11 @@
     endif
   endif
 
-  [retfile, retpath, retindex] = feval (funcname, outargs{:});
+  if (__octave_link_enabled__ ())
+    [retfile, retpath, retindex] = __octave_link_file_dialog__ (outargs{:});
+  else
+    [retfile, retpath, retindex] = feval (funcname, outargs{:});
+  endif
 
 endfunction
 
