]> git.lyx.org Git - lyx.git/blobdiff - src/LyXFunc.cpp
do what the FIXME suggested
[lyx.git] / src / LyXFunc.cpp
index b5789e00690e05f0d38a4de4117ea477b96902da..1669a6c9497a2bc9f6c3c90d599ce33e6f08dee1 100644 (file)
@@ -367,19 +367,11 @@ void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state)
                        dispatch(FuncRequest(LFUN_SELF_INSERT, arg,
                                             FuncRequest::KEYBOARD));
                        LYXERR(Debug::KEY, "SelfInsert arg[`" << to_utf8(arg) << "']");
-                       lyx_view_->updateCompletion(true, true);
                }
        } else {
                dispatch(func);
                if (!lyx_view_)
                        return;
-               if (func.action == LFUN_CHAR_DELETE_BACKWARD)
-                       // backspace is not a self-insertion. But it
-                       // still should not hide the completion popup.
-                       // FIXME: more clever way to detect those movements
-                       lyx_view_->updateCompletion(false, true);
-               else
-                       lyx_view_->updateCompletion(false, false);
        }
 
        if (lyx_view_)
@@ -715,26 +707,23 @@ void showPrintError(string const & name)
 }
 
 
-void loadTextClass(string const & name, string const & buf_path)
+bool loadLayoutFile(string const & name, string const & buf_path)
 {
-       pair<bool, BaseClassIndex> const tc_pair =
-               baseclasslist.numberOfClass(name);
-
-       if (!tc_pair.first) {
+       if (!BaseClassList::get().haveClass(name)) {
                lyxerr << "Document class \"" << name
                       << "\" does not exist."
                       << endl;
-               return;
+               return false;
        }
 
-       BaseClassIndex const tc = tc_pair.second;
-
-       if (!baseclasslist[tc].load(buf_path)) {
+       LayoutFile & tc = BaseClassList::get()[name];
+       if (!tc.load(buf_path)) {
                docstring s = bformat(_("The document class %1$s."
-                                  "could not be loaded."),
-                                  from_utf8(baseclasslist[tc].name()));
+                                  "could not be loaded."), from_utf8(name));
                Alert::error(_("Could not load class"), s);
+               return false;
        }
+       return true;
 }
 
 
@@ -1534,13 +1523,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                case LFUN_BUFFER_PARAMS_APPLY: {
                        BOOST_ASSERT(lyx_view_);
-                       biblio::CiteEngine const oldEngine =
-                                       lyx_view_->buffer()->params().getEngine();
                        
                        Buffer * buffer = lyx_view_->buffer();
-
                        DocumentClass * oldClass = buffer->params().documentClassPtr();
-
                        Cursor & cur = view()->cursor();
                        cur.recordUndoFullDocument();
                        
@@ -1558,24 +1543,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        
                        updateLayout(oldClass, buffer);
                        
-                       biblio::CiteEngine const newEngine =
-                                       lyx_view_->buffer()->params().getEngine();
-                       
-                       if (oldEngine != newEngine) {
-                               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() == CITE_CODE)
-                                               it->dispatch(cur, fr);
-                       }
-                       
                        updateFlags = Update::Force | Update::FitCursor;
-                       // We are here most certainaly because of a change in the document
-                       // It is then better to make sure that all dialogs are in sync
-                       // with current document settings. LyXView::restartCursor() achieve this.
+                       // We are most certainly here because of a change in the document
+                       // It is then better to make sure that all dialogs are in sync with
+                       // current document settings. LyXView::restartCursor() achieve this.
                        lyx_view_->restartCursor();
                        break;
                }
@@ -1608,27 +1579,22 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        BOOST_ASSERT(lyx_view_);
                        Buffer * buffer = lyx_view_->buffer();
 
-                       loadTextClass(argument, buffer->filePath());
-
-                       pair<bool, BaseClassIndex> const tc_pair =
-                               baseclasslist.numberOfClass(argument);
-
-                       if (!tc_pair.first)
+                       if (!loadLayoutFile(argument, buffer->filePath()))
                                break;
 
-                       BaseClassIndex const old_class = buffer->params().baseClass();
-                       BaseClassIndex const new_class = tc_pair.second;
+                       LayoutFile const * old_layout = buffer->params().baseClass();
+                       LayoutFile const * new_layout = &(BaseClassList::get()[argument]);
 
-                       if (old_class == new_class)
+                       if (old_layout == new_layout)
                                // nothing to do
                                break;
 
                        //Save the old, possibly modular, layout for use in conversion.
-                       DocumentClass * oldClass = buffer->params().documentClassPtr();
+                       DocumentClass * oldDocClass = buffer->params().documentClassPtr();
                        view()->cursor().recordUndoFullDocument();
-                       buffer->params().setBaseClass(new_class);
+                       buffer->params().setBaseClass(argument);
                        buffer->params().makeDocumentClass();
-                       updateLayout(oldClass, buffer);
+                       updateLayout(oldDocClass, buffer);
                        updateFlags = Update::Force | Update::FitCursor;
                        break;
                }
@@ -1637,9 +1603,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        BOOST_ASSERT(lyx_view_);
                        Buffer * buffer = lyx_view_->buffer();
                        DocumentClass * oldClass = buffer->params().documentClassPtr();
-                       BaseClassIndex const tc = buffer->params().baseClass();
-                       baseclasslist.reset(tc);
-                       buffer->params().setBaseClass(tc);
+                       LayoutFileIndex bc = buffer->params().baseClassID();
+                       BaseClassList::get().reset(bc);
                        buffer->params().makeDocumentClass();
                        updateLayout(oldClass, buffer);
                        updateFlags = Update::Force | Update::FitCursor;
@@ -1647,7 +1612,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                }
 
                case LFUN_TEXTCLASS_LOAD:
-                       loadTextClass(argument, lyx_view_->buffer()->filePath());
+                       loadLayoutFile(argument, lyx_view_->buffer()->filePath());
                        break;
 
                case LFUN_LYXRC_APPLY: {
@@ -1722,6 +1687,18 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                        view()->cursor().fixIfBroken();
                        }
 
+                       // update completion. We do it here and not in
+                       // processKeySym to avoid another redraw just for a
+                       // changed inline completion
+                       if (cmd.origin == FuncRequest::KEYBOARD) {
+                               if (cmd.action == LFUN_SELF_INSERT)
+                                       lyx_view_->updateCompletion(view()->cursor(), true, true);
+                               else if (cmd.action == LFUN_CHAR_DELETE_BACKWARD)
+                                       lyx_view_->updateCompletion(view()->cursor(), false, true);
+                               else
+                                       lyx_view_->updateCompletion(view()->cursor(), false, false);
+                       }
+
                        updateFlags = view()->cursor().result().update();
                }