]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
Minimal fix needed to give Qt a label dialog again.
[lyx.git] / src / BufferView_pimpl.C
index dd0074921b1e150800e18256e0807b1e76c80f02..cac2fb0e59a4a7cb11d29fc71c422818989e4fbb 100644 (file)
@@ -9,51 +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/insetbibitem.h"
-#include "insets/insetbibtex.h"
-#include "insets/insetcite.h"
-#include "insets/insetert.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 "insets/inseturl.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"
 
@@ -173,9 +165,9 @@ void BufferView::Pimpl::buffer(Buffer * b)
        // set current buffer
        buffer_ = b;
 
-       // if we're quitting lyx, don't bother updating stuff 
+       // if we're quitting lyx, don't bother updating stuff
        if (quitting)
-               return; 
+               return;
 
        // if we are closing the buffer, use the first buffer as current
        if (!buffer_) {
@@ -269,7 +261,7 @@ int BufferView::Pimpl::resizeCurrentBuffer()
        bool mark_set  = false;
 
        owner_->busy(true);
+
        owner_->message(_("Formatting document..."));
 
        if (bv_->text) {
@@ -629,14 +621,14 @@ bool BufferView::Pimpl::available() const
 
 Change const BufferView::Pimpl::getCurrentChange()
 {
-       if (!bv_->buffer()->params.tracking_changes) 
+       if (!bv_->buffer()->params.tracking_changes)
                return Change(Change::UNCHANGED);
 
        LyXText * t(bv_->getLyXText());
+
        if (!t->selection.set())
                return Change(Change::UNCHANGED);
+
        LyXCursor const & cur(t->selection.start);
        return cur.par()->lookupChangeFull(cur.pos());
 }
@@ -949,7 +941,7 @@ void BufferView::Pimpl::trackChanges()
        } else {
                bv_->update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
                bv_->text->setCursor(bv_, &(*buf->paragraphs.begin()), 0);
-#warning changes FIXME 
+#warning changes FIXME
                //moveCursorUpdate(false);
 
                bool found = lyxfind::findNextChange(bv_);
@@ -964,13 +956,17 @@ void BufferView::Pimpl::trackChanges()
                }
                buf->params.tracking_changes = false;
        }
+
        buf->redostack.clear();
 }
 
 
-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 << ']'
@@ -1094,9 +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_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));
@@ -1169,214 +1171,36 @@ 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_BIBITEM_APPLY: {
-               InsetCommandParams params;
-               InsetCommandMailer::string2params(ev.argument, params);
+       case LFUN_INSET_APPLY: {
+               string const name = ev.getArg(0);
 
-               InsetBase * base =
-                       owner_->getDialogs().getOpenInset("bibitem");
-               InsetBibitem * inset = 0;
+               InsetBase * base = owner_->getDialogs().getOpenInset(name);
                if (base) {
-                       inset = dynamic_cast<InsetBibitem *>(base);
-                       if (!inset)
-                               break;
-                       
-                       if (params.getContents() !=
-                           inset->params().getContents()) {
-                               bv_->ChangeCitationsIfUnique(
-                                       inset->params().getContents(),
-                                       params.getContents());
-                       }
-                       inset->setParams(params);
+                       // This works both for 'original' and 'mathed' insets.
+                       // Note that the localDispatch performs updateInset
+                       // also.
+                       FuncRequest fr(bv_, LFUN_INSET_MODIFY, ev.argument);
+                       base->localDispatch(fr);
                } else {
-                       inset = new InsetBibitem(params);
-                       if (!insertInset(inset)) {
+                       Inset * inset = createInset(ev);
+                       if (inset && insertInset(inset)) {
+                               updateInset(inset, true);
+                       } else {
                                delete inset;
-                               break;
                        }
                }
-               updateInset(inset, true);
 
-               // We need to do a redraw because the maximum
-               // InsetBibitem width could have changed
+               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_BIBTEX_APPLY: {
-               InsetCommandParams params;
-               InsetCommandMailer::string2params(ev.argument, params);
-
-               InsetBase * base =
-                       owner_->getDialogs().getOpenInset("bibtex");
-               InsetBibtex * inset = 0;
-               if (base) {
-                       inset = dynamic_cast<InsetBibtex *>(base);
-                       if (!inset)
-                               break;
-
-                       if (params.getContents() !=
-                           inset->params().getContents()) {
-                               bv_->ChangeCitationsIfUnique(
-                                       inset->params().getContents(),
-                                       params.getContents());
-                       }
-                       inset->setParams(params);
-               } else {
-                       inset = new InsetBibtex(params);
-                       if (!insertInset(inset)) {
-                               delete inset;
-                               break;
-                       }
+                       bv_->repaint();
+                       bv_->fitCursor();
                }
-               updateInset(inset, true);
-       }
-       break;
-
-       case LFUN_CITATION_APPLY: {
-               InsetCommandParams params;
-               InsetCommandMailer::string2params(ev.argument, params);
-
-               InsetBase * base =
-                       owner_->getDialogs().getOpenInset("citation");
-               InsetCitation * inset = 0;
-               if (base) {
-                       inset = dynamic_cast<InsetCitation *>(base);
-                       if (!inset)
-                               break;
-
-                       inset->setParams(params);
-               } else {
-                       inset = new InsetCitation(params);
-                       if (!insertInset(inset)) {
-                               delete inset;
-                               break;
-                       } else {
-                               inset->setLoadingBuffer(bv_->buffer(), false);
-                       }
-               }
-               updateInset(inset, true);
-       }
-       break;
-
-       case LFUN_ERT_APPLY: {
-               InsetBase * base = owner_->getDialogs().getOpenInset("ert");
-               InsetERT * inset = 0;
-               if (base) {
-                       inset = dynamic_cast<InsetERT *>(base);
-                       if (!inset)
-                               break;
-               } else {
-                       inset = new InsetERT(bv_->buffer()->params);
-                       if (!insertInset(inset)) {
-                               delete inset;
-                               break;
-                       }
-               }
-
-               InsetERT::ERTStatus status;
-               InsetERTMailer::string2params(ev.argument, status);
-
-               inset->status(bv_, status);
-               updateInset(inset, true);
-       }
-       break;
-
-       case LFUN_INDEX_APPLY: {
-               InsetCommandParams params;
-               InsetCommandMailer::string2params(ev.argument, params);
-
-               InsetBase * base = owner_->getDialogs().getOpenInset("index");
-               InsetIndex * inset = 0;
-               if (base) {
-                       inset = dynamic_cast<InsetIndex *>(base);
-                       if (!inset)
-                               break;
-
-                       inset->setParams(params);
-               } else {
-                       InsetIndex * inset = new InsetIndex(params);
-                       if (!insertInset(inset)) {
-                               delete inset;
-                               break;
-                       }
-               }
-               updateInset(inset, true);
-       }
-       break;
-
-       case LFUN_REF_APPLY: {
-               InsetCommandParams params;
-               InsetCommandMailer::string2params(ev.argument, params);
-
-               InsetBase * base = owner_->getDialogs().getOpenInset("ref");
-               InsetRef * inset = 0;
-               if (base) {
-                       inset = dynamic_cast<InsetRef *>(base);
-                       if (!inset)
-                               break;
-
-                       inset->setParams(params);
-               } else {
-                       InsetRef * inset = new InsetRef(params, *buffer_);
-                       if (!insertInset(inset)) {
-                               delete inset;
-                               break;
-                       }
-               }
-               updateInset(inset, true);
-       }
-       break;
-
-       case LFUN_TOC_APPLY: {
-               InsetCommandParams params;
-               InsetCommandMailer::string2params(ev.argument, params);
-
-               InsetBase * base = owner_->getDialogs().getOpenInset("toc");
-               InsetTOC * inset = 0;
-               if (base) {
-                       InsetTOC * inset = dynamic_cast<InsetTOC *>(base);
-                       if (!inset)
-                               break;
-
-                       inset->setParams(params);
-               } else {
-                       InsetTOC * inset = new InsetTOC(params);
-                       if (!insertInset(inset)) {
-                               delete inset;
-                               break;
-                       }
-               }
-               updateInset(inset, true);
-       }
-       break;
-
-       case LFUN_URL_APPLY: {
-               InsetCommandParams params;
-               InsetCommandMailer::string2params(ev.argument, params);
-
-               InsetBase * base = owner_->getDialogs().getOpenInset("url");
-               InsetUrl * inset = 0;
-               if (base) {
-                       inset = dynamic_cast<InsetUrl *>(base);
-                       if (!inset)
-                               break;
-
-                       inset->setParams(params);
-               } else {
-                       InsetUrl * inset = new InsetUrl(params);
-                       if (!insertInset(inset)) {
-                               delete inset;
-                               break;
-                       }
-               }
-               updateInset(inset, true);
        }
        break;
 
@@ -1432,15 +1256,15 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
        case LFUN_TRACK_CHANGES:
                trackChanges();
                break;
+
        case LFUN_MERGE_CHANGES:
                owner_->getDialogs().showMergeChanges();
                break;
+
        case LFUN_ACCEPT_ALL_CHANGES: {
                bv_->update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
                bv_->text->setCursor(bv_, &(*bv_->buffer()->paragraphs.begin()), 0);
-#warning FIXME changes 
+#warning FIXME changes
                //moveCursorUpdate(false);
 
                while (lyxfind::findNextChange(bv_)) {
@@ -1450,11 +1274,11 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
                        BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
                break;
        }
+
        case LFUN_REJECT_ALL_CHANGES: {
                bv_->update(bv_->text, BufferView::SELECT | BufferView::FITCUR);
                bv_->text->setCursor(bv_, &(*bv_->buffer()->paragraphs.begin()), 0);
-#warning FIXME changes 
+#warning FIXME changes
                //moveCursorUpdate(false);
 
                while (lyxfind::findNextChange(bv_)) {
@@ -1464,7 +1288,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
                        BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
                break;
        }
+
        case LFUN_ACCEPT_CHANGE: {
                bv_->getLyXText()->acceptChange(bv_);
                update(bv_->text,
@@ -1478,7 +1302,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
                        BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
                break;
        }
+
        case LFUN_UNKNOWN_ACTION:
                ev.errorMessage(N_("Unknown function!"));
                break;