]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
hopefully fix tex2lyx linking.
[lyx.git] / src / lyxfunc.C
index deb7d0a239374747461df04f54f7e3ced30f608a..7de71684d5d8267f2de39d929e5b4b88325e2ce3 100644 (file)
@@ -229,8 +229,8 @@ void LyXFunc::handleKeyFunc(kb_action action)
        if (keyseq->length())
                c = 0;
 
-       lyx_view_->view()->getIntl().getTransManager()
-               .deadkey(c, get_accent(action).accent, view()->getLyXText());
+       lyx_view_->view()->getIntl().getTransManager().deadkey(
+               c, get_accent(action).accent, view()->getLyXText(), view()->cursor());
        // Need to clear, in case the minibuffer calls these
        // actions
        keyseq->clear();
@@ -352,6 +352,18 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                flag.message(from_utf8(N_("Exiting")));
                flag.enabled(true);
                return flag;
+       } else if (cmd.action == LFUN_BOOKMARK_GOTO) {
+               // bookmarks can be valid even if there is no opened buffer
+               flag.enabled(LyX::ref().session().bookmarks().isValid(convert<unsigned int>(to_utf8(cmd.argument()))));
+               return flag;
+       } else if (cmd.action == LFUN_BOOKMARK_CLEAR) {
+               flag.enabled(LyX::ref().session().bookmarks().size() > 0);
+               return flag;
+       } else if (cmd.action == LFUN_TOOLBAR_TOGGLE_STATE) {
+               ToolbarBackend::Flags flags = lyx_view_->getToolbarState(to_utf8(cmd.argument()));
+               if (!(flags & ToolbarBackend::AUTO))
+                       flag.setOnOff(flags & ToolbarBackend::ON);
+               return flag;
        }
 
        LCursor & cur = view()->cursor();
@@ -365,7 +377,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
           http://bugzilla.lyx.org/show_bug.cgi?id=1941#c4
        */
        Buffer * buf;
-       if (cmd.origin == FuncRequest::UI && !lyx_view_->hasFocus())
+       if (cmd.origin == FuncRequest::MENU && !lyx_view_->hasFocus())
                buf = 0;
        else
                buf = lyx_view_->buffer();
@@ -565,6 +577,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                break;
        }
 
+
        // this one is difficult to get right. As a half-baked
        // solution, we consider only the first action of the sequence
        case LFUN_COMMAND_SEQUENCE: {
@@ -1022,14 +1035,22 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
 
                case LFUN_LYX_QUIT:
+                       if (argument != "force") {
+                               if (!theApp->gui().closeAll())
+                                       break;
+                               lyx_view_ = 0;
+                       }
+
+                       // FIXME: this code needs to be transfered somewhere else
+                       // as lyx_view_ will most certainly be null and a same buffer
+                       // might be visible in more than one LyXView.
                        if (lyx_view_ && lyx_view_->view()->buffer()) {
                                // save cursor Position for opened files to .lyx/session
-                               LyX::ref().session().saveFilePosition(lyx_view_->buffer()->fileName(),
+                               LyX::ref().session().lastFilePos().save(lyx_view_->buffer()->fileName(),
                                        boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
-                               // save bookmarks to .lyx/session
-                               view()->saveSavedPositions();
-                       }                       
-                       LyX::ref().quit(argument == "force");
+                       }
+
+                       LyX::ref().quit();
                        break;
 
                case LFUN_TOC_VIEW: {
@@ -1045,7 +1066,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
 
                case LFUN_RECONFIGURE:
-                       reconfigure(view());
+                       BOOST_ASSERT(lyx_view_);
+                       reconfigure(*lyx_view_);
                        break;
 
                case LFUN_HELP_OPEN: {
@@ -1230,6 +1252,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                            name == "bibtex" ||
                            name == "index" ||
                            name == "label" ||
+                           name == "nomenclature" ||
                            name == "ref" ||
                            name == "toc" ||
                            name == "url") {
@@ -1332,7 +1355,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        // FIXME Should use bformat
                        setMessage(_("Opening child document ") +
                                         makeDisplayPath(filename) + "...");
-                       view()->savePosition(0);
+                       view()->saveBookmark(false);
                        string const parentfilename = lyx_view_->buffer()->fileName();
                        if (theBufferList().exists(filename))
                                lyx_view_->setBuffer(theBufferList().getBuffer(filename));
@@ -1650,6 +1673,33 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        // We return here because lyx_view does not exists anymore.
                        return;
 
+               case LFUN_BOOKMARK_GOTO: {
+                       BOOST_ASSERT(lyx_view_);
+                       unsigned int idx = convert<unsigned int>(to_utf8(cmd.argument()));
+                       BookmarksSection::Bookmark const bm = LyX::ref().session().bookmarks().bookmark(idx);
+                       BOOST_ASSERT(!bm.filename.empty());
+                       // if the file is not opened, open it.
+                       if (!theBufferList().exists(bm.filename))
+                               dispatch(FuncRequest(LFUN_FILE_OPEN, bm.filename));
+                       // open may fail, so we need to test it again
+                       if (theBufferList().exists(bm.filename)) {
+                               // if the current buffer is not that one, switch to it.
+                               if (lyx_view_->buffer()->fileName() != bm.filename)
+                                       dispatch(FuncRequest(LFUN_BUFFER_SWITCH, bm.filename));
+                               // BOOST_ASSERT(lyx_view_->buffer()->fileName() != bm.filename);
+                               view()->moveToPosition(bm.par_id, bm.par_pos);
+                       } 
+                       break;
+               }
+
+               case LFUN_BOOKMARK_CLEAR:
+                       LyX::ref().session().bookmarks().clear();
+                       break;
+
+               case LFUN_TOOLBAR_TOGGLE_STATE:
+                       lyx_view_->toggleToolbarState(argument);
+                       break;
+
                default: {
                        BOOST_ASSERT(lyx_view_);
                        view()->cursor().dispatch(cmd);
@@ -1665,15 +1715,11 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        // Redraw screen unless explicitly told otherwise.
                        // This also initializes the position cache for all insets
                        // in (at least partially) visible top-level paragraphs.
-                       bool needSecondUpdate = false;
-                       if (updateFlags != Update::None)
-                               view()->update(updateFlags);
-                       else
-                               needSecondUpdate = view()->fitCursor();
+                       std::pair<bool, bool> needSecondUpdate = view()->update(updateFlags);
+
+                       if (needSecondUpdate.first)
+                               view()->buffer()->changed(needSecondUpdate.second);
 
-                       if (needSecondUpdate || updateFlags != Update::None) {
-                               view()->buffer()->changed();
-                       }
                        lyx_view_->updateStatusBar();
 
                        // if we executed a mutating lfun, mark the buffer as dirty
@@ -1687,26 +1733,18 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        }
                }
        }
-       if (!quitting)
-               // FIXME UNICODE: _() does not support anything but ascii.
-               // Do we need a to_ascii() method?
+       if (!quitting) {
+               lyx_view_->updateMenubar();
+               lyx_view_->updateToolbars();
                sendDispatchMessage(getMessage(), cmd);
+       }
 }
 
 
 void LyXFunc::sendDispatchMessage(docstring const & msg, FuncRequest const & cmd)
 {
-       /* When an action did not originate from the UI/kbd, it makes
-        * sense to avoid updating the GUI. It turns out that this
-        * fixes bug 1941, for reasons that are described here:
-        * http://bugzilla.lyx.org/show_bug.cgi?id=1941#c4
-        */
-       if (cmd.origin != FuncRequest::INTERNAL) {
-               lyx_view_->updateMenubar();
-               lyx_view_->updateToolbars();
-       }
-
-       const bool verbose = (cmd.origin == FuncRequest::UI
+       const bool verbose = (cmd.origin == FuncRequest::MENU
+                             || cmd.origin == FuncRequest::TOOLBAR
                              || cmd.origin == FuncRequest::COMMANDBUFFER);
 
        if (cmd.action == LFUN_SELF_INSERT || !verbose) {
@@ -1958,7 +1996,7 @@ void LyXFunc::doImport(string const & argument)
 void LyXFunc::closeBuffer()
 {
        // save current cursor position
-       LyX::ref().session().saveFilePosition(lyx_view_->buffer()->fileName(),
+       LyX::ref().session().lastFilePos().save(lyx_view_->buffer()->fileName(),
                boost::tie(view()->cursor().pit(), view()->cursor().pos()) );
        if (theBufferList().close(lyx_view_->buffer(), true) && !quitting) {
                if (theBufferList().empty()) {
@@ -2050,6 +2088,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_LOADSESSION:
        case LyXRC::RC_CHKTEX_COMMAND:
        case LyXRC::RC_CONVERTER:
+       case LyXRC::RC_CONVERTER_CACHE_MAXAGE:
        case LyXRC::RC_COPIER:
        case LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR:
        case LyXRC::RC_CUSTOM_EXPORT_COMMAND:
@@ -2146,6 +2185,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_USER_NAME:
        case LyXRC::RC_USETEMPDIR:
        case LyXRC::RC_USE_ALT_LANG:
+       case LyXRC::RC_USE_CONVERTER_CACHE:
        case LyXRC::RC_USE_ESC_CHARS:
        case LyXRC::RC_USE_INP_ENC:
        case LyXRC::RC_USE_PERS_DICT: