]> git.lyx.org Git - lyx.git/blobdiff - src/LyXFunc.cpp
make index label translatable
[lyx.git] / src / LyXFunc.cpp
index 3961a39c6df49f666dc624e169dcea263bff747c..ff466d0323510149fbc11b6a652c20f14662b590 100644 (file)
@@ -84,9 +84,7 @@
 #include "frontends/Gui.h"
 #include "frontends/KeySymbol.h"
 #include "frontends/LyXView.h"
-#include "frontends/Menubar.h"
 #include "frontends/Selection.h"
-#include "frontends/Toolbars.h"
 #include "frontends/WorkArea.h"
 
 #include "support/environment.h"
@@ -265,23 +263,32 @@ void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer)
                        return;
        }
        // open may fail, so we need to test it again
-       if (theBufferList().exists(file)) {
-               // if the current buffer is not that one, switch to it.
-               if (lyx_view_->buffer()->fileName() != file) {
-                       if (switchToBuffer)
-                               dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
-                       else
-                               return;
-               }
-               // moveToPosition use par_id, and par_pit and return new par_id.
-               pit_type new_pit;
-               pos_type new_pos;
-               int new_id;
-               boost::tie(new_pit, new_pos, new_id) = view()->moveToPosition(bm.bottom_pit, bm.bottom_pos, bm.top_id, bm.top_pos);
-               // if bottom_pit, bottom_pos or top_id has been changed, update bookmark
-               // see http://bugzilla.lyx.org/show_bug.cgi?id=3092
-               if (bm.bottom_pit != new_pit || bm.bottom_pos != new_pos || bm.top_id != new_id )
-                       const_cast<BookmarksSection::Bookmark &>(bm).updatePos(new_pit, new_pos, new_id);
+       if (!theBufferList().exists(file))
+               return;
+
+       // if the current buffer is not that one, switch to it.
+       if (lyx_view_->buffer()->fileName() != file) {
+               if (!switchToBuffer)
+                       return;
+               dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
+       }
+       // moveToPosition try paragraph id first and then paragraph (pit, pos).
+       if (!view()->moveToPosition(bm.bottom_pit, bm.bottom_pos,
+               bm.top_id, bm.top_pos))
+               return;
+
+       // Cursor jump succeeded!
+       Cursor const & cur = view()->cursor();
+       pit_type new_pit = cur.pit();
+       pos_type new_pos = cur.pos();
+       int new_id = cur.paragraph().id();
+
+       // if bottom_pit, bottom_pos or top_id has been changed, update bookmark
+       // see http://bugzilla.lyx.org/show_bug.cgi?id=3092
+       if (bm.bottom_pit != new_pit || bm.bottom_pos != new_pos 
+               || bm.top_id != new_id) {
+               const_cast<BookmarksSection::Bookmark &>(bm).updatePos(
+                       new_pit, new_pos, new_id);
        }
 }
 
@@ -657,7 +664,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                break;
 
        case LFUN_TOOLBAR_TOGGLE: {
-               bool const current = lyx_view_->getToolbars().visible(cmd.getArg(0));
+               bool const current = lyx_view_->isToolbarVisible(cmd.getArg(0));
                flag.setOnOff(current);
                break;
        }
@@ -722,6 +729,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        case LFUN_TEXTCLASS_LOAD:
        case LFUN_BUFFER_SAVE_AS_DEFAULT:
        case LFUN_BUFFER_PARAMS_APPLY:
+       case LFUN_LAYOUT_MODULES_CLEAR:
+       case LFUN_LAYOUT_MODULE_ADD:
+       case LFUN_LAYOUT_RELOAD:
        case LFUN_LYXRC_APPLY:
        case LFUN_BUFFER_NEXT:
        case LFUN_BUFFER_PREVIOUS:
@@ -809,10 +819,10 @@ void loadTextclass(string const & name)
        textclass_type const tc = tc_pair.second;
 
        if (!textclasslist[tc].load()) {
-               docstring s = bformat(_("The document could not be converted\n"
-                                                 "into the document class %1$s."),
+               docstring s = bformat(_("The document class %1$s."
+                                  "could not be loaded."),
                                   from_utf8(textclasslist[tc].name()));
-               Alert::error(_("Could not change class"), s);
+               Alert::error(_("Could not load class"), s);
        }
 }
 
@@ -879,8 +889,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                case LFUN_COMMAND_EXECUTE:
                        BOOST_ASSERT(lyx_view_);
-                       lyx_view_->getToolbars().display("minibuffer", true);
-                       lyx_view_->focus_command_buffer();
+                       lyx_view_->showMiniBuffer(true);
                        break;
 
                case LFUN_CANCEL:
@@ -1285,12 +1294,12 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                case LFUN_DROP_LAYOUTS_CHOICE:
                        BOOST_ASSERT(lyx_view_);
-                       lyx_view_->getToolbars().openLayoutList();
+                       lyx_view_->openLayoutList();
                        break;
 
                case LFUN_MENU_OPEN:
                        BOOST_ASSERT(lyx_view_);
-                       lyx_view_->getMenubar().openByName(from_utf8(argument));
+                       lyx_view_->openMenu(from_utf8(argument));
                        break;
 
                // --- lyxserver commands ----------------------------
@@ -1737,33 +1746,66 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                case LFUN_BUFFER_PARAMS_APPLY: {
                        BOOST_ASSERT(lyx_view_);
-                       biblio::CiteEngine const engine =
-                               lyx_view_->buffer()->params().getEngine();
+                       biblio::CiteEngine const oldEngine =
+                                       lyx_view_->buffer()->params().getEngine();
+                       
+                       Buffer * buffer = lyx_view_->buffer();
 
+                       TextClass_ptr oldClass = buffer->params().getTextClass_ptr();
+                       recordUndoFullDocument(view());
+                       
                        istringstream ss(argument);
                        Lexer lex(0,0);
                        lex.setStream(ss);
-                       int const unknown_tokens =
-                               lyx_view_->buffer()->readHeader(lex);
+                       int const unknown_tokens = buffer->readHeader(lex);
 
                        if (unknown_tokens != 0) {
                                lyxerr << "Warning in LFUN_BUFFER_PARAMS_APPLY!\n"
-                                      << unknown_tokens << " unknown token"
-                                      << (unknown_tokens == 1 ? "" : "s")
-                                      << endl;
+                                               << unknown_tokens << " unknown token"
+                                               << (unknown_tokens == 1 ? "" : "s")
+                                               << endl;
                        }
-                       if (engine == lyx_view_->buffer()->params().getEngine())
-                               break;
-
-                       Cursor & cur = view()->cursor();
-                       FuncRequest fr(LFUN_INSET_REFRESH);
-
-                       Inset & inset = lyx_view_->buffer()->inset();
-                       InsetIterator it  = inset_iterator_begin(inset);
-                       InsetIterator const end = inset_iterator_end(inset);
-                       for (; it != end; ++it)
-                               if (it->lyxCode() == Inset::CITE_CODE)
-                                       it->dispatch(cur, fr);
+                       
+                       updateLayout(oldClass, buffer);
+                       
+                       biblio::CiteEngine const newEngine =
+                                       lyx_view_->buffer()->params().getEngine();
+                       
+                       if (oldEngine != newEngine) {
+                               Cursor & cur = view()->cursor();
+                               FuncRequest fr(LFUN_INSET_REFRESH);
+       
+                               Inset & inset = lyx_view_->buffer()->inset();
+                               InsetIterator it  = inset_iterator_begin(inset);
+                               InsetIterator const end = inset_iterator_end(inset);
+                               for (; it != end; ++it)
+                                       if (it->lyxCode() == Inset::CITE_CODE)
+                                               it->dispatch(cur, fr);
+                       }
+                       
+                       updateFlags = Update::Force | Update::FitCursor;
+                       break;
+               }
+               
+               case LFUN_LAYOUT_MODULES_CLEAR: {
+                       BOOST_ASSERT(lyx_view_);
+                       Buffer * buffer = lyx_view_->buffer();
+                       TextClass_ptr oldClass = buffer->params().getTextClass_ptr();
+                       recordUndoFullDocument(view());
+                       buffer->params().clearLayoutModules();
+                       updateLayout(oldClass, buffer);
+                       updateFlags = Update::Force | Update::FitCursor;
+                       break;
+               }
+               
+               case LFUN_LAYOUT_MODULE_ADD: {
+                       BOOST_ASSERT(lyx_view_);
+                       Buffer * buffer = lyx_view_->buffer();
+                       TextClass_ptr oldClass = buffer->params().getTextClass_ptr();
+                       recordUndoFullDocument(view());
+                       buffer->params().addLayoutModule(argument);
+                       updateLayout(oldClass, buffer);
+                       updateFlags = Update::Force | Update::FitCursor;
                        break;
                }
 
@@ -1771,9 +1813,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        BOOST_ASSERT(lyx_view_);
                        Buffer * buffer = lyx_view_->buffer();
 
-                       textclass_type const old_class =
-                               buffer->params().textclass;
-
                        loadTextclass(argument);
 
                        std::pair<bool, textclass_type> const tc_pair =
@@ -1782,24 +1821,30 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        if (!tc_pair.first)
                                break;
 
+                       textclass_type const old_class = buffer->params().getBaseClass();
                        textclass_type const new_class = tc_pair.second;
+
                        if (old_class == new_class)
                                // nothing to do
                                break;
 
-                       lyx_view_->message(_("Converting document to new document class..."));
+                       //Save the old, possibly modular, layout for use in conversion.
+                       TextClass_ptr oldClass = buffer->params().getTextClass_ptr();
                        recordUndoFullDocument(view());
-                       buffer->params().textclass = new_class;
-                       StableDocIterator backcur(view()->cursor());
-                       ErrorList & el = buffer->errorList("Class Switch");
-                       cap::switchBetweenClasses(
-                               old_class, new_class,
-                               static_cast<InsetText &>(buffer->inset()), el);
-
-                       view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
-
-                       buffer->errors("Class Switch");
-                       updateLabels(*buffer);
+                       buffer->params().setBaseClass(new_class);
+                       updateLayout(oldClass, buffer);
+                       updateFlags = Update::Force | Update::FitCursor;
+                       break;
+               }
+               
+               case LFUN_LAYOUT_RELOAD: {
+                       BOOST_ASSERT(lyx_view_);
+                       Buffer * buffer = lyx_view_->buffer();
+                       TextClass_ptr oldClass = buffer->params().getTextClass_ptr();
+                       textclass_type const tc = buffer->params().getBaseClass();
+                       textclasslist.reset(tc);
+                       buffer->params().setBaseClass(tc);
+                       updateLayout(oldClass, buffer);
                        updateFlags = Update::Force | Update::FitCursor;
                        break;
                }
@@ -1919,7 +1964,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                }
        }
        if (!quitting && lyx_view_) {
-               lyx_view_->updateMenubar();
                lyx_view_->updateToolbars();
                // Some messages may already be translated, so we cannot use _()
                sendDispatchMessage(translateIfPossible(getMessage()), cmd);
@@ -2262,6 +2306,24 @@ bool LyXFunc::wasMetaKey() const
 }
 
 
+void LyXFunc::updateLayout(TextClass_ptr const & oldlayout,
+                           Buffer * buffer)
+{
+       lyx_view_->message(_("Converting document to new document class..."));
+       
+       StableDocIterator backcur(view()->cursor());
+       ErrorList & el = buffer->errorList("Class Switch");
+       cap::switchBetweenClasses(
+                       oldlayout, buffer->params().getTextClass_ptr(),
+                       static_cast<InsetText &>(buffer->inset()), el);
+
+       view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
+
+       buffer->errors("Class Switch");
+       updateLabels(*buffer);
+}
+
+
 namespace {
 
 void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)