Author: tommaso
Date: Thu Oct  6 15:47:42 2011
New Revision: 39805
URL: http://www.lyx.org/trac/changeset/39805

Log:
Added Export As... dialog, exploiting the new destination path that can
be specified when exporting.
This fixes #3402.

Modified:
   lyx-devel/trunk/lib/ui/stdmenus.inc
   lyx-devel/trunk/src/FuncCode.h
   lyx-devel/trunk/src/LyXAction.cpp
   lyx-devel/trunk/src/frontends/qt4/FileDialog.cpp
   lyx-devel/trunk/src/frontends/qt4/FileDialog.h
   lyx-devel/trunk/src/frontends/qt4/GuiView.cpp
   lyx-devel/trunk/src/frontends/qt4/GuiView.h

Modified: lyx-devel/trunk/lib/ui/stdmenus.inc
==============================================================================
--- lyx-devel/trunk/lib/ui/stdmenus.inc Thu Oct  6 15:34:32 2011        (r39804)
+++ lyx-devel/trunk/lib/ui/stdmenus.inc Thu Oct  6 15:47:42 2011        (r39805)
@@ -87,6 +87,7 @@
        End
 
        Menu "file_export"
+               Item "Export As...|A" "buffer-export-as"
                ExportFormats
                Item "More Formats & Options...|O" "buffer-export custom"
        End

Modified: lyx-devel/trunk/src/FuncCode.h
==============================================================================
--- lyx-devel/trunk/src/FuncCode.h      Thu Oct  6 15:34:32 2011        (r39804)
+++ lyx-devel/trunk/src/FuncCode.h      Thu Oct  6 15:47:42 2011        (r39805)
@@ -450,6 +450,7 @@
        LFUN_SCRIPT_INSERT,             // gb, 20101123
        // 350
 
+       LFUN_BUFFER_EXPORT_AS,          // tommaso 20111006
        LFUN_LASTACTION                 // end of the table
 };
 

Modified: lyx-devel/trunk/src/LyXAction.cpp
==============================================================================
--- lyx-devel/trunk/src/LyXAction.cpp   Thu Oct  6 15:34:32 2011        (r39804)
+++ lyx-devel/trunk/src/LyXAction.cpp   Thu Oct  6 15:47:42 2011        (r39805)
@@ -2978,6 +2978,14 @@
  */
                { LFUN_BUFFER_EXPORT_CUSTOM, "buffer-export-custom", ReadOnly, 
Buffer },
 /*!
+ * \var lyx::FuncCode lyx::LFUN_BUFFER_EXPORT_AS
+ * \li Action: Pops up a dialog for exporting the current buffer.
+ * \li Syntax: buffer-export
+ * \li Origin: tommaso, 6 Oct 2011
+ * \endvar
+ */
+               { LFUN_BUFFER_EXPORT_AS, "buffer-export-as", ReadOnly, Buffer },
+/*!
  * \var lyx::FuncCode lyx::LFUN_BUFFER_PRINT
  * \li Action: Prints the current document.
  * \li Notion: Many settings can be given via the preferences dialog.

Modified: lyx-devel/trunk/src/frontends/qt4/FileDialog.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/FileDialog.cpp    Thu Oct  6 15:34:32 
2011        (r39804)
+++ lyx-devel/trunk/src/frontends/qt4/FileDialog.cpp    Thu Oct  6 15:47:42 
2011        (r39805)
@@ -81,7 +81,8 @@
 
 
 FileDialog::Result FileDialog::save(QString const & path,
-       QStringList const & filters, QString const & suggested)
+       QStringList const & filters, QString const & suggested,
+       QString & selectedFilter)
 {
        LYXERR(Debug::GUI, "Select with path \"" << path
                           << "\", mask \"" << filters.join(";;")
@@ -95,7 +96,7 @@
        QString const name = 
                QFileDialog::getSaveFileName(qApp->focusWidget(),
             title_, startsWith, filters.join(";;"),
-                        0, QFileDialog::DontConfirmOverwrite);
+                        selectedFilter, QFileDialog::DontConfirmOverwrite);
        if (name.isNull())
                result.first = FileDialog::Later;
        else
@@ -118,12 +119,21 @@
                result.second = internalPath(dlg.selectedFiles()[0]);
        else
                result.first = FileDialog::Later;
+       selectedFilter = dlg.selectedNameFilter();
        dlg.hide();
 #endif
        return result;
 }
 
 
+FileDialog::Result FileDialog::save(QString const & path,
+       QStringList const & filters, QString const & suggested)
+{
+       QString selectedFilter = 0;
+       return save(path, filters, suggested, selectedFilter);
+}
+
+
 FileDialog::Result FileDialog::open(QString const & path,
        QStringList const & filters, QString const & suggested)
 {

Modified: lyx-devel/trunk/src/frontends/qt4/FileDialog.h
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/FileDialog.h      Thu Oct  6 15:34:32 
2011        (r39804)
+++ lyx-devel/trunk/src/frontends/qt4/FileDialog.h      Thu Oct  6 15:47:42 
2011        (r39805)
@@ -70,6 +70,10 @@
        Result save(QString const & path, QStringList const & filters,
                          QString const & suggested = QString());
 
+       /// Also retrieve the selected filter.
+       Result save(QString const & path, QStringList const & filters,
+                   QString const & suggested, QString & selectedFilter);
+
 private:
        class Private;
        friend class Private;

Modified: lyx-devel/trunk/src/frontends/qt4/GuiView.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiView.cpp       Thu Oct  6 15:34:32 
2011        (r39804)
+++ lyx-devel/trunk/src/frontends/qt4/GuiView.cpp       Thu Oct  6 15:47:42 
2011        (r39805)
@@ -1657,6 +1657,7 @@
        }
 
        case LFUN_BUFFER_WRITE_AS:
+       case LFUN_BUFFER_EXPORT_AS:
                enable = doc_buffer;
                break;
 
@@ -2313,6 +2314,64 @@
 }
 
 
+bool GuiView::exportBufferAs(Buffer & b)
+{
+       FileName fname = b.fileName();
+       FileName const oldname = fname;
+
+       FileDialog dlg(qt_("Choose a filename to export the document as"));
+       dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
+
+       QStringList types;
+       types << "Any supported format (*.*)";
+       Formats::const_iterator it = formats.begin();
+       for (; it != formats.end(); ++it)
+               if (it->documentFormat())
+                       types << toqstr(it->name() + " (*." + it->extension() + 
")");
+       QString filter;
+       FileDialog::Result result =
+               dlg.save(toqstr(fname.onlyPath().absFileName()),
+                        types,
+                        toqstr(fname.onlyFileName()),
+                        filter);
+       if (result.first != FileDialog::Chosen)
+               return false;
+
+       string s = fromqstr(filter);
+       size_t pos = s.find(" (");
+       LASSERT(pos != string::npos, /**/);
+       string fmt_name = s.substr(0, pos);
+       fname.set(fromqstr(result.second));
+       if (fmt_name == "Any supported format")
+               fmt_name = formats.getFormatFromExtension(fname.extension());
+       LYXERR(Debug::FILES, "fmt_name=" << fmt_name << ", fname=" << 
fname.absFileName());
+
+       if (fname.empty())
+               return false;
+
+       // fname is now the new Buffer location.
+       if (FileName(fname).exists()) {
+               docstring const file = makeDisplayPath(fname.absFileName(), 30);
+               docstring text = bformat(_("The document %1$s already "
+                                          "exists.\n\nDo you want to "
+                                          "overwrite that document?"),
+                                        file);
+               int const ret = Alert::prompt(_("Overwrite document?"),
+                       text, 0, 2, _("&Overwrite"), _("&Rename"), 
_("&Cancel"));
+               switch (ret) {
+               case 0: break;
+               case 1: return exportBufferAs(b);
+               case 2: return false;
+               }
+       }
+
+       FuncRequest cmd(LFUN_BUFFER_EXPORT, fmt_name + " " + 
fname.absFileName());
+       DispatchResult dr;
+       dispatch(cmd, dr);
+       return dr.dispatched();
+}
+
+
 bool GuiView::saveBuffer(Buffer & b) {
        return saveBuffer(b, FileName());
 }
@@ -3158,6 +3217,11 @@
                        break;
                }
 
+               case LFUN_BUFFER_EXPORT_AS:
+                       LASSERT(doc_buffer, break);
+                       exportBufferAs(*doc_buffer);
+                       break;
+
                case LFUN_BUFFER_UPDATE: {
                        d.asyncBufferProcessing(argument,
                                                doc_buffer,

Modified: lyx-devel/trunk/src/frontends/qt4/GuiView.h
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiView.h Thu Oct  6 15:34:32 2011        
(r39804)
+++ lyx-devel/trunk/src/frontends/qt4/GuiView.h Thu Oct  6 15:47:42 2011        
(r39805)
@@ -353,6 +353,8 @@
        ///
        void insertPlaintextFile(docstring const & fname,
                bool asParagraph);
+       ///
+       bool exportBufferAs(Buffer & b);
 
        /// Save a buffer as a new file. 
        /**

Reply via email to