]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
Compilation fix
[lyx.git] / src / BufferView_pimpl.C
index b974d55d478f30e40dbd7e5fb864654d41f87f50..6bfa31a50242eaa4fd570d4e4f034f6665f12ddb 100644 (file)
@@ -9,48 +9,43 @@
 #include <config.h>
 
 #include "BufferView_pimpl.h"
-#include "frontends/WorkArea.h"
-#include "frontends/screen.h"
-#include "frontends/LyXScreenFactory.h"
-#include "frontends/WorkAreaFactory.h"
-#include "frontends/Dialogs.h"
-#include "frontends/Alert.h"
-#include "frontends/FileDialog.h"
-#include "frontends/mouse_state.h"
-#include "lyxtext.h"
-#include "lyxrow.h"
-#include "paragraph.h"
-#include "frontends/LyXView.h"
+#include "bufferlist.h"
+#include "bufferview_funcs.h"
 #include "commandtags.h"
-#include "lyxfunc.h"
 #include "debug.h"
-#include "bufferview_funcs.h"
-#include "TextCache.h"
-#include "bufferlist.h"
-#include "lyxrc.h"
-#include "intl.h"
-// added for Dispatch functions
-#include "lyx_cb.h"
-#include "lyx_main.h"
+#include "factory.h"
 #include "FloatList.h"
-#include "gettext.h"
-#include "ParagraphParameters.h"
-#include "undo_funcs.h"
 #include "funcrequest.h"
+#include "gettext.h"
+#include "intl.h"
 #include "iterators.h"
+#include "lyx_cb.h" // added for Dispatch functions
+#include "lyx_main.h"
 #include "lyxfind.h"
+#include "lyxfunc.h"
+#include "lyxtext.h"
+#include "lyxrc.h"
+#include "lyxrow.h"
+#include "paragraph.h"
+#include "ParagraphParameters.h"
+#include "TextCache.h"
+#include "undo_funcs.h"
 
-#include "insets/insetbibtex.h"
-#include "insets/insetcite.h"
 #include "insets/insetfloatlist.h"
 #include "insets/insetgraphics.h"
 #include "insets/insetinclude.h"
-#include "insets/insetindex.h"
-#include "insets/insetlatexaccent.h"
-#include "insets/insetmarginal.h"
 #include "insets/insetref.h"
 #include "insets/insettext.h"
-#include "insets/insettoc.h"
+
+#include "frontends/Alert.h"
+#include "frontends/Dialogs.h"
+#include "frontends/FileDialog.h"
+#include "frontends/LyXView.h"
+#include "frontends/LyXScreenFactory.h"
+#include "frontends/mouse_state.h"
+#include "frontends/screen.h"
+#include "frontends/WorkArea.h"
+#include "frontends/WorkAreaFactory.h"
 
 #include "mathed/formulabase.h"
 
@@ -872,8 +867,7 @@ void BufferView::Pimpl::MenuInsertLyXFile(string const & filen)
                                initpath = trypath;
                }
 
-               FileDialog fileDlg(bv_->owner(),
-                                  _("Select LyX document to insert"),
+               FileDialog fileDlg(_("Select LyX document to insert"),
                        LFUN_FILE_INSERT,
                        make_pair(string(_("Documents|#o#O")),
                                  string(lyxrc.document_path)),
@@ -967,8 +961,12 @@ void BufferView::Pimpl::trackChanges()
 }
 
 
-bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
+bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
 {
+       // Make sure that the cached BufferView is correct.
+       FuncRequest ev = ev_in;
+       ev.setView(bv_);
+
        lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch:"
                << " action[" << ev.action << ']'
                << " arg[" << ev.argument << ']'
@@ -1092,25 +1090,15 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
                owner_->getLyXFunc().setMessage(currentState(bv_));
                break;
 
-       case LFUN_INSERT_LABEL:
-               MenuInsertLabel(bv_, ev.argument);
-               break;
-
-       case LFUN_REF_INSERT:
-               if (ev.argument.empty()) {
-                       InsetCommandParams p("ref");
-                       owner_->getDialogs().createRef(p.getAsString());
-               } else {
-                       InsetCommandParams p;
-                       p.setFromString(ev.argument);
-
-                       InsetRef * inset = new InsetRef(p, *buffer_);
-                       if (!insertInset(inset))
-                               delete inset;
-                       else
-                               updateInset(inset, true);
-               }
-               break;
+       case LFUN_INSERT_LABEL: {
+               // Try and generate a valid label
+               string const contents = ev.argument.empty() ?
+                       getPossibleLabel(*bv_) : ev.argument;
+               InsetCommandParams icp("label", contents);
+               string data = InsetCommandMailer::params2string("label", icp);
+               owner_->getDialogs().show("label", data, 0);
+       }
+       break;
 
        case LFUN_BOOKMARK_SAVE:
                savePosition(strToUnsignedInt(ev.argument));
@@ -1183,75 +1171,39 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
        case LFUN_MATH_DISPLAY:          // Open or create a displayed math inset
        case LFUN_MATH_MODE:             // Open or create an inlined math inset
        case LFUN_GREEK:                 // Insert a single greek letter
-               mathDispatch(FuncRequest(bv_, ev.action, ev.argument));
+               mathDispatch(ev);
                break;
 
-       case LFUN_CITATION_INSERT:
-       {
-               InsetCommandParams p;
-               p.setFromString(ev.argument);
+       case LFUN_INSET_APPLY: {
+               string const name = ev.getArg(0);
 
-               InsetCitation * inset = new InsetCitation(p);
-               if (!insertInset(inset))
-                       delete inset;
-               else {
-                       inset->setLoadingBuffer(bv_->buffer(), false);
-                       updateInset(inset, true);
+               InsetBase * base = owner_->getDialogs().getOpenInset(name);
+               Inset * inset = 0;
+               if (base) {
+                       // This works both for 'original' and 'mathed' insets.
+                       // Note that the localDispatch performs updateInset
+                       // also.
+                       base->localDispatch(ev);
+               } else {
+                       inset = createInset(ev);
+                       if (inset && insertInset(inset)) {
+                               updateInset(inset, true);
+                       } else {
+                               delete inset;
+                       }
                }
 
-       }
-       break;
-
-       case LFUN_INSERT_BIBTEX:
-       {
-               // ale970405+lasgoutt970425
-               // The argument can be up to two tokens separated
-               // by a space. The first one is the bibstyle.
-               string const db = token(ev.argument, ' ', 0);
-               string bibstyle = token(ev.argument, ' ', 1);
-               if (bibstyle.empty())
-                       bibstyle = "plain";
-
-               InsetCommandParams p("BibTeX", db, bibstyle);
-               InsetBibtex * inset = new InsetBibtex(p);
-
-               if (insertInset(inset)) {
-                       if (ev.argument.empty())
-                               inset->edit(bv_);
-               } else
-                       delete inset;
-       }
-       break;
-
-       // BibTeX data bases
-       case LFUN_BIBDB_ADD:
-       {
-               InsetBibtex * inset =
-                       static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
-               if (inset) {
-                       inset->addDatabase(ev.argument);
+               if (name == "bibitem") {
+                       // We need to do a redraw because the maximum
+                       // InsetBibitem width could have changed
+#warning please check you mean repaint() not update(),
+#warning and whether the repaint() is needed at all
+                       bv_->repaint();
+                       bv_->fitCursor();
                }
        }
        break;
 
-       case LFUN_BIBDB_DEL:
-       {
-               InsetBibtex * inset =
-                       static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
-               if (inset)
-                       inset->delDatabase(ev.argument);
-       }
-       break;
-
-       case LFUN_BIBTEX_STYLE:
-       {
-               InsetBibtex * inset =
-                       static_cast<InsetBibtex*>(getInsetByCode(Inset::BIBTEX_CODE));
-               if (inset)
-                       inset->setOptions(ev.argument);
-       }
-       break;
-
        case LFUN_CHILD_INSERT:
        {
                InsetInclude::Params p;