]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiView.cpp
Do not show master's errors if compiling child
[lyx.git] / src / frontends / qt4 / GuiView.cpp
index 7b7189743ecd1de84b5588b48a03cd2c79781c31..45c26c325c4829e504ed103fdbc60da1b1449e3f 100644 (file)
@@ -263,7 +263,7 @@ typedef map<string, GuiToolbar *> ToolbarMap;
 
 typedef shared_ptr<Dialog> DialogPtr;
 
-} // namespace anon
+} // namespace
 
 
 class GuiView::GuiViewPrivate
@@ -508,7 +508,7 @@ QSet<Buffer const *> GuiView::GuiViewPrivate::busyBuffers;
 
 GuiView::GuiView(int id)
        : d(*new GuiViewPrivate(this)), id_(id), closing_(false), busy_(0),
-         command_execute_(false), minibuffer_focus_(false)
+         command_execute_(false), minibuffer_focus_(false), devel_mode_(false)
 {
        connect(this, SIGNAL(bufferViewChanged()),
                this, SLOT(onBufferViewChanged()));
@@ -577,9 +577,25 @@ GuiView::GuiView(int id)
                busylabel, SLOT(hide()));
 
        QFontMetrics const fm(statusBar()->fontMetrics());
-       int const roheight = max(int(d.normalIconSize), fm.height());
-       QSize const rosize(roheight, roheight);
-       QPixmap readonly = QIcon(getPixmap("images/", "emblem-readonly", "svgz,png")).pixmap(rosize);
+       int const iconheight = max(int(d.normalIconSize), fm.height());
+       QSize const iconsize(iconheight, iconheight);
+
+       QPixmap shellescape = QIcon(getPixmap("images/", "emblem-shellescape", "svgz,png")).pixmap(iconsize);
+       shell_escape_ = new QLabel(statusBar());
+       shell_escape_->setPixmap(shellescape);
+       shell_escape_->setScaledContents(true);
+       shell_escape_->setAlignment(Qt::AlignCenter);
+       shell_escape_->setContextMenuPolicy(Qt::CustomContextMenu);
+       shell_escape_->setToolTip(qt_("WARNING: LaTeX is allowed to execute "
+                                     "external commands for this document. "
+                                     "Right click to change."));
+       SEMenu * menu = new SEMenu(this);
+       connect(shell_escape_, SIGNAL(customContextMenuRequested(QPoint)),
+               menu, SLOT(showMenu(QPoint)));
+       shell_escape_->hide();
+       statusBar()->addPermanentWidget(shell_escape_);
+
+       QPixmap readonly = QIcon(getPixmap("images/", "emblem-readonly", "svgz,png")).pixmap(iconsize);
        read_only_ = new QLabel(statusBar());
        read_only_->setPixmap(readonly);
        read_only_->setScaledContents(true);
@@ -638,6 +654,17 @@ GuiView::~GuiView()
 }
 
 
+void GuiView::disableShellEscape()
+{
+       BufferView * bv = documentBufferView();
+       if (!bv)
+               return;
+       theSession().shellescapeFiles().remove(bv->buffer().absFileName());
+       bv->buffer().params().shell_escape = false;
+       bv->processUpdateFlags(Update::Force);
+}
+
+
 QVector<GuiWorkArea*> GuiView::GuiViewPrivate::guiWorkAreas()
 {
        QVector<GuiWorkArea*> areas;
@@ -698,7 +725,10 @@ void GuiView::processingThreadFinished()
                errors("Export");
                return;
        }
-       errors(d.last_export_format);
+       if (status != Buffer::ExportSuccess && status != Buffer::PreviewSuccess &&
+           status != Buffer::ExportCancel) {
+               errors(d.last_export_format);
+       }
 }
 
 
@@ -714,7 +744,8 @@ void GuiView::autoSaveThreadFinished()
 void GuiView::saveLayout() const
 {
        QSettings settings;
-       settings.setValue("zoom", lyxrc.currentZoom);
+       settings.setValue("zoom_ratio", zoom_ratio_);
+       settings.setValue("devel_mode", devel_mode_);
        settings.beginGroup("views");
        settings.beginGroup(QString::number(id_));
 #if defined(Q_WS_X11) || defined(QPA_XCB)
@@ -730,22 +761,29 @@ void GuiView::saveLayout() const
 
 void GuiView::saveUISettings() const
 {
+       QSettings settings;
+
        // Save the toolbar private states
        ToolbarMap::iterator end = d.toolbars_.end();
        for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
-               it->second->saveSession();
+               it->second->saveSession(settings);
        // Now take care of all other dialogs
        map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
        for (; it!= d.dialogs_.end(); ++it)
-               it->second->saveSession();
+               it->second->saveSession(settings);
 }
 
 
 bool GuiView::restoreLayout()
 {
        QSettings settings;
-       lyxrc.currentZoom = settings.value("zoom", lyxrc.zoom).toInt();
-       lyx::dispatch(FuncRequest(LFUN_BUFFER_ZOOM, convert<docstring>(lyxrc.currentZoom)));
+       zoom_ratio_ = settings.value("zoom_ratio", 1.0).toDouble();
+       // Actual zoom value: default zoom + fractional offset
+       int zoom = lyxrc.defaultZoom * zoom_ratio_;
+       if (zoom < static_cast<int>(zoom_min_))
+               zoom = zoom_min_;
+       lyxrc.currentZoom = zoom;
+       devel_mode_ = settings.value("devel_mode", devel_mode_).toBool();
        settings.beginGroup("views");
        settings.beginGroup(QString::number(id_));
        QString const icon_key = "icon_size";
@@ -1158,6 +1196,11 @@ void GuiView::updateWindowTitle(GuiWorkArea * wa)
        // Tell Qt whether the current document is changed
        setWindowModified(!buf.isClean());
 
+       if (buf.params().shell_escape)
+               shell_escape_->show();
+       else
+               shell_escape_->hide();
+
        if (buf.hasReadonlyFlag())
                read_only_->show();
        else
@@ -1254,7 +1297,7 @@ void GuiView::showMessage()
        if (msg.isEmpty()) {
                BufferView const * bv = currentBufferView();
                if (bv)
-                       msg = toqstr(bv->cursor().currentState());
+                       msg = toqstr(bv->cursor().currentState(devel_mode_));
                else
                        msg = qt_("Welcome to LyX!");
        }
@@ -1873,8 +1916,22 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                enable = doc_buffer && doc_buffer->notifiesExternalModification();
                break;
 
-       case LFUN_BUFFER_WRITE_AS:
+       case LFUN_BUFFER_EXPORT: {
+               if (!doc_buffer || d.processing_thread_watcher_.isRunning()) {
+                       enable = false;
+                       break;
+               }
+               return doc_buffer->getStatus(cmd, flag);
+               break;
+       }
+
        case LFUN_BUFFER_EXPORT_AS:
+               if (!doc_buffer || d.processing_thread_watcher_.isRunning()) {
+                       enable = false;
+                       break;
+               }
+               // fall through
+       case LFUN_BUFFER_WRITE_AS:
                enable = doc_buffer != 0;
                break;
 
@@ -1887,6 +1944,23 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                enable = theBufferList().last() != theBufferList().first();
                break;
 
+       case LFUN_BUFFER_CHKTEX: {
+               // hide if we have no checktex command
+               if (lyxrc.chktex_command.empty()) {
+                       flag.setUnknown(true);
+                       enable = false;
+                       break;
+               }
+               if (!doc_buffer || !doc_buffer->params().isLatex()
+                   || d.processing_thread_watcher_.isRunning()) {
+                       // grey out, don't hide
+                       enable = false;
+                       break;
+               }
+               enable = true;
+               break;
+       }
+
        case LFUN_VIEW_SPLIT:
                if (cmd.getArg(0) == "vertical")
                        enable = doc_buffer && (d.splitter_->count() == 1 ||
@@ -1900,6 +1974,10 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                enable = d.tabWorkAreaCount() > 1;
                break;
 
+       case LFUN_DEVEL_MODE_TOGGLE:
+               flag.setOnOff(devel_mode_);
+               break;
+
        case LFUN_TOOLBAR_TOGGLE: {
                string const name = cmd.getArg(0);
                if (GuiToolbar * t = toolbar(name))
@@ -1951,7 +2029,8 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 
        case LFUN_DIALOG_TOGGLE:
                flag.setOnOff(isDialogVisible(cmd.getArg(0)));
-               // fall through to set "enable"
+               // to set "enable"
+               // fall through
        case LFUN_DIALOG_SHOW: {
                string const name = cmd.getArg(0);
                if (!doc_buffer)
@@ -3130,6 +3209,7 @@ static bool ensureBufferClean(Buffer * buffer)
 
 bool GuiView::reloadBuffer(Buffer & buf)
 {
+       currentBufferView()->cursor().reset();
        Buffer::ReadStatus status = buf.reload();
        return status == Buffer::ReadSuccess;
 }
@@ -3440,8 +3520,7 @@ bool GuiView::goToFileRow(string const & argument)
 
 void GuiView::toolBarPopup(const QPoint & /*pos*/)
 {
-       QMenu * menu = new QMenu;
-       menu = guiApp->menus().menu(toqstr("context-toolbars"), * this);
+       QMenu * menu = guiApp->menus().menu(toqstr("context-toolbars"), * this);
        menu->exec(QCursor::pos());
 }
 
@@ -3741,6 +3820,11 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        gotoNextOrPreviousBuffer(PREVBUFFER, true);
                        break;
 
+               case LFUN_BUFFER_CHKTEX:
+                       LASSERT(doc_buffer, break);
+                       doc_buffer->runChktex();
+                       break;
+
                case LFUN_COMMAND_EXECUTE: {
                        command_execute_ = true;
                        minibuffer_focus_ = true;
@@ -3862,6 +3946,14 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        closeBufferAll();
                        break;
 
+               case LFUN_DEVEL_MODE_TOGGLE:
+                       devel_mode_ = !devel_mode_;
+                       if (devel_mode_)
+                               dr.setMessage(_("Developer mode is now enabled."));
+                       else
+                               dr.setMessage(_("Developer mode is now disabled."));
+                       break;
+
                case LFUN_TOOLBAR_TOGGLE: {
                        string const name = cmd.getArg(0);
                        if (GuiToolbar * t = toolbar(name))
@@ -4069,30 +4161,31 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                case LFUN_BUFFER_ZOOM_IN:
                case LFUN_BUFFER_ZOOM_OUT:
                case LFUN_BUFFER_ZOOM: {
-                       // use a signed temp to avoid overflow
-                       int zoom = lyxrc.currentZoom;
                        if (cmd.argument().empty()) {
                                if (cmd.action() == LFUN_BUFFER_ZOOM)
-                                       zoom = lyxrc.zoom;
+                                       zoom_ratio_ = 1.0;
                                else if (cmd.action() == LFUN_BUFFER_ZOOM_IN)
-                                       zoom += 20;
+                                       zoom_ratio_ += 0.1;
                                else
-                                       zoom -= 20;
+                                       zoom_ratio_ -= 0.1;
                        } else {
                                if (cmd.action() == LFUN_BUFFER_ZOOM)
-                                       zoom = convert<int>(cmd.argument());
+                                       zoom_ratio_ = convert<int>(cmd.argument()) / double(lyxrc.defaultZoom);
                                else if (cmd.action() == LFUN_BUFFER_ZOOM_IN)
-                                       zoom += convert<int>(cmd.argument());
+                                       zoom_ratio_ += convert<int>(cmd.argument()) / 100.0;
                                else
-                                       zoom -= convert<int>(cmd.argument());
+                                       zoom_ratio_ -= convert<int>(cmd.argument()) / 100.0;
                        }
 
+                       // Actual zoom value: default zoom + fractional extra value
+                       int zoom = lyxrc.defaultZoom * zoom_ratio_;
                        if (zoom < static_cast<int>(zoom_min_))
                                zoom = zoom_min_;
 
                        lyxrc.currentZoom = zoom;
 
-                       dr.setMessage(bformat(_("Zoom level is now %1$d%"), lyxrc.currentZoom));
+                       dr.setMessage(bformat(_("Zoom level is now %1$d% (default value: %2$d%)"),
+                                             lyxrc.currentZoom, lyxrc.defaultZoom));
 
                        // The global QPixmapCache is used in GuiPainter to cache text
                        // painting so we must reset it.
@@ -4359,7 +4452,7 @@ bool isValidName(string const & name)
                                cmpCStr(name.c_str())) != end_dialognames;
 }
 
-} // namespace anon
+} // namespace
 
 
 void GuiView::resetDialogs()
@@ -4639,6 +4732,14 @@ Dialog * GuiView::build(string const & name)
 }
 
 
+SEMenu::SEMenu(QWidget * parent)
+{
+       QAction * action = addAction(qt_("Disable Shell Escape"));
+       connect(action, SIGNAL(triggered()),
+               parent, SLOT(disableShellEscape()));
+}
+
+
 } // namespace frontend
 } // namespace lyx