]> git.lyx.org Git - lyx.git/blobdiff - src/LyXFunc.cpp
Fixed some lines that were too long. It compiled afterwards.
[lyx.git] / src / LyXFunc.cpp
index f0748f309139d8276cbc937464817e10191dc63d..19fd449c9d02918220d11c0d1da49175406915d7 100644 (file)
@@ -219,7 +219,7 @@ void LyXFunc::initKeySequences(KeyMap * kb)
 
 void LyXFunc::setLyXView(LyXView * lv)
 {
-       if (lyx_view_ && lyx_view_ != lv)
+       if (!quitting && lyx_view_ && lyx_view_ != lv)
                // save current selection to the selection buffer to allow
                // middle-button paste in another window
                cap::saveSelection(lyx_view_->view()->cursor());
@@ -496,7 +496,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                enable = buf->lyxvc().inUse();
                break;
        case LFUN_BUFFER_RELOAD:
-               enable = !buf->isUnnamed() && !buf->isClean();
+               enable = !buf->isUnnamed() && fs::exists(buf->fileName())
+                       && (!buf->isClean() || buf->isExternallyModified(Buffer::timestamp_method));
                break;
 
        case LFUN_INSET_SETTINGS: {
@@ -612,6 +613,29 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                break;
        }
 
+
+       case LFUN_BUFFER_WRITE_ALL: {
+       // We enable the command only if there are some modified buffers
+               Buffer * first = theBufferList().first();
+               bool modified = false;
+               if (first) {
+                       Buffer * b = first;
+               
+               // We cannot use a for loop as the buffer list is a cycle.
+                       do {
+                               if (!b->isClean()) {
+                                       modified = true;
+                                       break;
+                               }
+                               b = theBufferList().next(b);
+                       } while (b != first); 
+               }
+       
+               enable = modified;
+
+               break;
+       }
+
        case LFUN_BOOKMARK_GOTO: {
                const unsigned int num = convert<unsigned int>(to_utf8(cmd.argument()));
                enable = LyX::ref().session().bookmarks().isValid(num);
@@ -907,6 +931,30 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        updateFlags = Update::None;
                        break;
 
+               case LFUN_BUFFER_WRITE_ALL: {
+                       Buffer * first = theBufferList().first();
+                       if (first) {
+                               Buffer * b = first;
+                               lyx_view_->message(_("Saving all documents..."));
+               
+                               // We cannot use a for loop as the buffer list cycles.
+                               do {
+                                       if (!b->isClean()) {
+                                               if (!b->isUnnamed()) {
+                                                       menuWrite(b);
+                                                       lyxerr[Debug::ACTION] << "Saved " << b->fileName() << endl;
+                                               } else
+                                                       writeAs(b);
+                                       }
+                                       b = theBufferList().next(b);
+                               } while (b != first); 
+                               lyx_view_->message(_("All documents saved."));
+                       } 
+       
+                       updateFlags = Update::None;
+                       break;
+               }
+
                case LFUN_BUFFER_RELOAD: {
                        BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
                        docstring const file = makeDisplayPath(view()->buffer()->fileName(), 20);
@@ -1190,16 +1238,19 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                case LFUN_BUFFER_SWITCH:
                        BOOST_ASSERT(lyx_view_);
                        lyx_view_->setBuffer(theBufferList().getBuffer(argument));
+                       updateFlags = Update::Force;
                        break;
 
                case LFUN_BUFFER_NEXT:
                        BOOST_ASSERT(lyx_view_);
                        lyx_view_->setBuffer(theBufferList().next(view()->buffer()));
+                       updateFlags = Update::Force;
                        break;
 
                case LFUN_BUFFER_PREVIOUS:
                        BOOST_ASSERT(lyx_view_);
                        lyx_view_->setBuffer(theBufferList().previous(view()->buffer()));
+                       updateFlags = Update::Force;
                        break;
 
                case LFUN_FILE_NEW:
@@ -1374,7 +1425,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                }
 
                case LFUN_DIALOG_HIDE:
-                       Dialogs::hide(argument, 0);
+                       LyX::cref().hideDialogs(argument, 0);
                        break;
 
                case LFUN_DIALOG_TOGGLE: {
@@ -1547,9 +1598,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        theApp()->updateColor(lcolor.getFromLyXName(lyx_name));
 
                        if (graphicsbg_changed) {
-#ifdef WITH_WARNINGS
-#warning FIXME!! The graphics cache no longer has a changeDisplay method.
-#endif
+                               // FIXME: The graphics cache no longer has a changeDisplay method.
 #if 0
                                graphics::GCache::get().changeDisplay(true);
 #endif
@@ -1784,18 +1833,22 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        string const name = cmd.getArg(0);
                        bool const allowauto = cmd.getArg(1) == "allowauto";
                        lyx_view_->toggleToolbarState(name, allowauto);
-                       ToolbarInfo::Flags const flags = 
-                               lyx_view_->getToolbarState(name);
+                       ToolbarInfo * tbi = lyx_view_->getToolbarInfo(name);
+                       if (!tbi) {
+                               setMessage(bformat(_("Unknown toolbar \"%1$s\""),
+                                                  from_utf8(name)));
+                               break;
+                       }
                        docstring state;
-                       if (flags & ToolbarInfo::ON)
+                       if (tbi->flags & ToolbarInfo::ON)
                                state = _("on");
-                       else if (flags & ToolbarInfo::OFF)
+                       else if (tbi->flags & ToolbarInfo::OFF)
                                state = _("off");
-                       else if (flags & ToolbarInfo::AUTO)
+                       else if (tbi->flags & ToolbarInfo::AUTO)
                                state = _("auto");
 
                        setMessage(bformat(_("Toolbar \"%1$s\" state set to %2$s"), 
-                                                  from_ascii(name), state));
+                                          _(tbi->gui_name), state));
                        break;
                }
 
@@ -1837,7 +1890,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        }
                }
        }
-       if (!quitting) {
+       if (!quitting && lyx_view_) {
                lyx_view_->updateMenubar();
                lyx_view_->updateToolbars();
                // Some messages may already be translated, so we cannot use _()