]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiView.cpp
On Linux show in crash message box the backtrace
[lyx.git] / src / frontends / qt4 / GuiView.cpp
index f3cd9a58b52f22d8eae5eeb3f25c1d082cdb4558..a7cbbe49fed44c0026419e1a63c88d1aa6974ee4 100644 (file)
@@ -59,6 +59,7 @@
 #include "LyXVC.h"
 #include "Paragraph.h"
 #include "SpellChecker.h"
+#include "Session.h"
 #include "TexRow.h"
 #include "TextClass.h"
 #include "Text.h"
@@ -670,8 +671,6 @@ bool GuiView::restoreLayout()
                dialog->prepareView();
        if ((dialog = findOrBuild("progress", true)))
                dialog->prepareView();
-       if ((dialog = findOrBuild("findreplaceadv", true)))
-               dialog->prepareView();
 
        if (!restoreState(settings.value("layout").toByteArray(), 0))
                initToolbars();
@@ -1003,6 +1002,12 @@ void GuiView::updateWindowTitle(GuiWorkArea * wa)
                return;
        setWindowTitle(qt_("LyX: ") + wa->windowTitle());
        setWindowIconText(wa->windowIconText());
+#if (QT_VERSION >= 0x040400)
+       // Sets the path for the window: this is used by OSX to 
+       // allow a context click on the title bar showing a menu
+       // with the path up to the file
+       setWindowFilePath(toqstr(wa->bufferView().buffer().absFileName()));
+#endif
 }
 
 
@@ -1610,7 +1615,9 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 
        case LFUN_MASTER_BUFFER_UPDATE:
        case LFUN_MASTER_BUFFER_VIEW:
-               enable = doc_buffer && doc_buffer->parent() != 0
+               enable = doc_buffer
+                       && (doc_buffer->parent() != 0
+                           || doc_buffer->hasChildren())
                        && !d.processing_thread_watcher_.isRunning();
                break;
 
@@ -1731,7 +1738,8 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                else if (name == "print")
                        enable = doc_buffer->params().isExportable("dvi")
                                && lyxrc.print_command != "none";
-               else if (name == "character" || name == "symbols") {
+               else if (name == "character" || name == "symbols"
+                       || name == "mathdelimiter" || name == "mathmatrix") {
                        if (!buf || buf->isReadonly())
                                enable = false;
                        else {
@@ -1777,7 +1785,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                        enable = false;
                break;
 
-       case LFUN_COMPLETION_COMPLETE:
+       case LFUN_COMPLETE:
                if (!d.current_work_area_
                        || !d.current_work_area_->completer().inlinePossible(
                        currentBufferView()->cursor()))
@@ -1944,16 +1952,12 @@ void GuiView::openDocument(string const & fname)
        string filename;
 
        if (fname.empty()) {
-               FileDialog dlg(qt_("Select document to open"), LFUN_FILE_OPEN);
+               FileDialog dlg(qt_("Select document to open"));
                dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
                dlg.setButton2(qt_("Examples|#E#e"),
                                toqstr(addPath(package().system_support().absFileName(), "examples")));
 
-               QStringList filter(qt_("LyX Documents (*.lyx)"));
-               filter << qt_("LyX-1.3.x Documents (*.lyx13)")
-                       << qt_("LyX-1.4.x Documents (*.lyx14)")
-                       << qt_("LyX-1.5.x Documents (*.lyx15)")
-                       << qt_("LyX-1.6.x Documents (*.lyx16)");
+               QStringList const filter(qt_("LyX Documents (*.lyx)"));
                FileDialog::Result result =
                        dlg.open(toqstr(initpath), filter);
 
@@ -2087,7 +2091,7 @@ void GuiView::importDocument(string const & argument)
                docstring const text = bformat(_("Select %1$s file to import"),
                        formats.prettyName(format));
 
-               FileDialog dlg(toqstr(text), LFUN_BUFFER_IMPORT);
+               FileDialog dlg(toqstr(text));
                dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
                dlg.setButton2(qt_("Examples|#E#e"),
                        toqstr(addPath(package().system_support().absFileName(), "examples")));
@@ -2117,6 +2121,18 @@ void GuiView::importDocument(string const & argument)
        // get absolute path of file
        FileName const fullname(support::makeAbsPath(filename));
 
+       // Can happen if the user entered a path into the dialog
+       // (see bug #7437)
+       if (fullname.onlyFileName().empty()) {
+               docstring msg = bformat(_("The file name '%1$s' is invalid!\n"
+                                         "Aborting import."),
+                                       from_utf8(fullname.absFileName()));
+               frontend::Alert::error(_("File name error"), msg);
+               message(_("Canceled."));
+               return;
+       }
+
+
        FileName const lyxfile(support::changeExtension(fullname.absFileName(), ".lyx"));
 
        // Check if the document already is open
@@ -2209,7 +2225,7 @@ void GuiView::insertLyXFile(docstring const & fname)
                        initpath = trypath;
 
                // FIXME UNICODE
-               FileDialog dlg(qt_("Select LyX document to insert"), LFUN_FILE_INSERT);
+               FileDialog dlg(qt_("Select LyX document to insert"));
                dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
                dlg.setButton2(qt_("Examples|#E#e"),
                        toqstr(addPath(package().system_support().absFileName(),
@@ -2251,8 +2267,7 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname, RenameKind kin
 
                // No argument? Ask user through dialog.
                // FIXME UNICODE
-               FileDialog dlg(qt_("Choose a filename to save document as"),
-                                  LFUN_BUFFER_WRITE_AS);
+               FileDialog dlg(qt_("Choose a filename to save document as"));
                dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
                dlg.setButton2(qt_("Templates|#T#t"), toqstr(lyxrc.template_path));
 
@@ -2361,7 +2376,7 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname, RenameKind kin
 
        bool const saved = saveBuffer(b, fname);
        if (saved)
-               b.reload(false);
+               b.reload();
        return saved;
 }
 
@@ -2369,12 +2384,13 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname, RenameKind kin
 struct PrettyNameComparator
 {
        bool operator()(Format const *first, Format const *second) const {
-               return compare_ascii_no_case(first->prettyname(), second->prettyname()) <= 0;
+               return compare_no_case(translateIfPossible(from_ascii(first->prettyname())),
+                                      translateIfPossible(from_ascii(second->prettyname()))) <= 0;
        }
 };
 
 
-bool GuiView::exportBufferAs(Buffer & b)
+bool GuiView::exportBufferAs(Buffer & b, docstring const & iformat)
 {
        FileName fname = b.fileName();
 
@@ -2382,37 +2398,50 @@ bool GuiView::exportBufferAs(Buffer & b)
        dlg.setButton1(qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
 
        QStringList types;
-       types << "Any supported format (*.*)";
+       QString const anyformat = qt_("Guess from extension (*.*)");
+       types << anyformat;
        Formats::const_iterator it = formats.begin();
        vector<Format const *> export_formats;
        for (; it != formats.end(); ++it)
-               if (it->documentFormat() && it->inExportMenu())
+               if (it->documentFormat())
                        export_formats.push_back(&(*it));
        PrettyNameComparator cmp;
        sort(export_formats.begin(), export_formats.end(), cmp);
        vector<Format const *>::const_iterator fit = export_formats.begin();
-       for (; fit != export_formats.end(); ++fit)
-               types << toqstr((*fit)->prettyname() + " (*." + (*fit)->extension() + ")");
+       map<QString, string> fmap;
        QString filter;
+       string ext;
+       for (; fit != export_formats.end(); ++fit) {
+               docstring const loc_prettyname =
+                       translateIfPossible(from_utf8((*fit)->prettyname()));
+               QString const loc_filter = toqstr(bformat(from_ascii("%1$s (*.%2$s)"),
+                                                    loc_prettyname,
+                                                    from_ascii((*fit)->extension())));
+               types << loc_filter;
+               fmap[loc_filter] = (*fit)->name();
+               if (from_ascii((*fit)->name()) == iformat) {
+                       filter = loc_filter;
+                       ext = (*fit)->extension();
+               }
+       }
+       string ofname = fname.onlyFileName();
+       if (!ext.empty())
+               ofname = support::changeExtension(ofname, ext);
        FileDialog::Result result =
                dlg.save(toqstr(fname.onlyPath().absFileName()),
                         types,
-                        toqstr(fname.onlyFileName()),
+                        toqstr(ofname),
                         &filter);
        if (result.first != FileDialog::Chosen)
                return false;
 
-       string s = fromqstr(filter);
-       size_t pos = s.find(" (*.");
-       LATTEST(pos != string::npos);
-       string fmt_prettyname = s.substr(0, pos);
        string fmt_name;
        fname.set(fromqstr(result.second));
-       if (fmt_prettyname == "Any supported format")
+       if (filter == anyformat)
                fmt_name = formats.getFormatFromExtension(fname.extension());
        else
-               fmt_name = formats.getFormatFromPrettyName(fmt_prettyname);
-       LYXERR(Debug::FILES, "fmt_prettyname=" << fmt_prettyname
+               fmt_name = fmap[filter];
+       LYXERR(Debug::FILES, "filter=" << fromqstr(filter)
               << ", fmt_name=" << fmt_name << ", fname=" << fname.absFileName());
 
        if (fmt_name.empty() || fname.empty())
@@ -2429,7 +2458,7 @@ bool GuiView::exportBufferAs(Buffer & b)
                        text, 0, 2, _("&Overwrite"), _("&Rename"), _("&Cancel"));
                switch (ret) {
                case 0: break;
-               case 1: return exportBufferAs(b);
+               case 1: return exportBufferAs(b, from_ascii(fmt_name));
                case 2: return false;
                }
        }
@@ -2874,7 +2903,7 @@ void GuiView::dispatchVC(FuncRequest const & cmd, DispatchResult & dr)
                if (!buffer->lyxvc().inUse()) {
                        if (buffer->lyxvc().registrer()) {
                                reloadBuffer(*buffer);
-                               dr.suppressMessageUpdate();
+                               dr.clearMessageUpdate();
                        }
                }
                break;
@@ -2954,7 +2983,7 @@ void GuiView::dispatchVC(FuncRequest const & cmd, DispatchResult & dr)
                LASSERT(buffer, return);
                if (buffer->lyxvc().revert()) {
                        reloadBuffer(*buffer);
-                       dr.suppressMessageUpdate();
+                       dr.clearMessageUpdate();
                }
                break;
 
@@ -2962,7 +2991,7 @@ void GuiView::dispatchVC(FuncRequest const & cmd, DispatchResult & dr)
                LASSERT(buffer, return);
                buffer->lyxvc().undoLast();
                reloadBuffer(*buffer);
-               dr.suppressMessageUpdate();
+               dr.clearMessageUpdate();
                break;
 
        case LFUN_VC_REPO_UPDATE:
@@ -3298,11 +3327,19 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                case LFUN_BUFFER_EXPORT: {
                        if (!doc_buffer)
                                break;
+                       FileName target_dir = doc_buffer->fileName().onlyPath();
+                       string const dest = cmd.getArg(1);
+                       if (!dest.empty() && FileName::isAbsolute(dest))
+                               target_dir = FileName(support::onlyPath(dest));
                        // GCC only sees strfwd.h when building merged
                        if (::lyx::operator==(cmd.argument(), "custom")) {
                                dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"), dr);
                                break;
                        }
+                       if (!target_dir.isDirWritable()) {
+                               exportBufferAs(*doc_buffer, cmd.argument());
+                               break;
+                       }
                        /* TODO/Review: Is it a problem to also export the children?
                                        See the update_unincluded flag */
                        d.asyncBufferProcessing(argument,
@@ -3315,10 +3352,14 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        break;
                }
 
-               case LFUN_BUFFER_EXPORT_AS:
+               case LFUN_BUFFER_EXPORT_AS: {
                        LASSERT(doc_buffer, break);
-                       exportBufferAs(*doc_buffer);
+                       docstring f = cmd.argument();
+                       if (f.empty())
+                               f = from_ascii(doc_buffer->params().getDefaultOutputFormat());
+                       exportBufferAs(*doc_buffer, f);
                        break;
+               }
 
                case LFUN_BUFFER_UPDATE: {
                        d.asyncBufferProcessing(argument,
@@ -3431,7 +3472,6 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 
                case LFUN_FILE_INSERT_PLAINTEXT:
                case LFUN_FILE_INSERT_PLAINTEXT_PARA: {
-                       bool const as_paragraph = (cmd.action() == LFUN_FILE_INSERT_PLAINTEXT_PARA);
                        string const fname = to_utf8(cmd.argument());
                        if (!fname.empty() && !FileName::isAbsolute(fname)) {
                                dr.setMessage(_("Absolute filename expected."));
@@ -3440,8 +3480,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        
                        FileName filename(fname);
                        if (fname.empty()) {
-                               FileDialog dlg(qt_("Select file to insert"), (as_paragraph ?
-                                       LFUN_FILE_INSERT_PLAINTEXT_PARA : LFUN_FILE_INSERT_PLAINTEXT));
+                               FileDialog dlg(qt_("Select file to insert"));
 
                                FileDialog::Result result = dlg.open(toqstr(bv->buffer().filePath()),
                                        QStringList(qt_("All Files (*)")));
@@ -3666,7 +3705,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        break;
 
 
-               case LFUN_COMPLETION_COMPLETE:
+               case LFUN_COMPLETE:
                        if (d.current_work_area_)
                                d.current_work_area_->completer().tab();
                        break;
@@ -3794,8 +3833,6 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
        if (isFullScreen()) {
                if (menuBar()->isVisible() && lyxrc.full_screen_menubar)
                        menuBar()->hide();
-               if (statusBar()->isVisible())
-                       statusBar()->hide();
        }
 }
 
@@ -3854,7 +3891,8 @@ void GuiView::toggleFullScreen()
                setContentsMargins(-2, -2, -2, -2);
                saveLayout();
                setWindowState(windowState() ^ Qt::WindowFullScreen);
-               statusBar()->hide();
+               if (lyxrc.full_screen_statusbar)
+                       statusBar()->hide();
                if (lyxrc.full_screen_menubar)
                        menuBar()->hide();
                if (lyxrc.full_screen_toolbars) {