]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
Try to deal with one of the big problems here, namely, that we
[lyx.git] / src / BufferView.cpp
index 61a40a2eadf53555d2361e7004ed05dd7a8ada9f..70ce4b8ce5738897b7a0e8c4fa2dc59b7ea52e62 100644 (file)
@@ -276,6 +276,9 @@ struct BufferView::Private
 
        /// Cache for Find Next
        FuncRequest search_request_cache_;
+
+       ///
+       map<string, Inset *> edited_insets_;
 };
 
 
@@ -1153,6 +1156,23 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                flag.setEnabled(lyx::getStatus(fr).enabled());
                break;
        }
+       case LFUN_INSET_APPLY: {
+               string const name = cmd.getArg(0);
+               Inset * inset = editedInset(name);
+               if (inset) {
+                       FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
+                       FuncStatus fs;
+                       if (!inset->getStatus(cur, fr, fs)) {
+                               // Every inset is supposed to handle this
+                               LASSERT(false, break);
+                       }
+                       flag |= fs;
+               } else {
+                       FuncRequest fr(LFUN_INSET_INSERT, cmd.argument());
+                       flag |= lyx::getStatus(fr);
+               }
+               break;
+       }
 
        default:
                flag.setEnabled(false);
@@ -1163,6 +1183,19 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 }
 
 
+Inset * BufferView::editedInset(string const & name) const
+{
+       map<string, Inset *>::const_iterator it = d->edited_insets_.find(name);
+       return it == d->edited_insets_.end() ? 0 : it->second;
+}
+
+
+void BufferView::editInset(string const & name, Inset * inset)
+{
+       d->edited_insets_[name] = inset;
+}
+
+
 bool BufferView::dispatch(FuncRequest const & cmd)
 {
        //lyxerr << [ cmd = " << cmd << "]" << endl;
@@ -1181,6 +1214,11 @@ bool BufferView::dispatch(FuncRequest const & cmd)
        if (buffer_.isInternal() && lyxaction.funcHasFlag(cmd.action, LyXAction::NoInternal))
                return false;
 
+       // We'll set this back to false if need be.
+       bool dispatched = true;
+       if (cmd.action != LFUN_UNDO && cmd.action != LFUN_REDO)
+               buffer_.undo().beginUndoGroup();
+
        switch (cmd.action) {
 
        case LFUN_BUFFER_PARAMS_APPLY: {
@@ -1823,11 +1861,33 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                break;
        }
 
+       case LFUN_INSET_APPLY: {
+               string const name = cmd.getArg(0);
+               Inset * inset = editedInset(name);
+               if (!inset) {
+                       FuncRequest fr(LFUN_INSET_INSERT, cmd.argument());
+                       lyx::dispatch(fr);
+                       break;
+               }
+               // put cursor in front of inset.
+               if (!setCursorFromInset(inset)) {
+                       LASSERT(false, break);
+               }
+               cur.recordUndo();
+               FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument());
+               inset->dispatch(cur, fr);
+               processUpdateFlags(Update::SinglePar | Update::FitCursor);
+               break;
+       }
+
        default:
-               return false;
+               dispatched = false;
+               break;
        }
 
-       return true;
+       if (cmd.action != LFUN_UNDO && cmd.action != LFUN_REDO)
+               buffer_.undo().endUndoGroup();
+       return dispatched;
 }
 
 
@@ -1890,7 +1950,7 @@ Inset const * BufferView::getCoveringInset(Text const & text,
        if (!inset)
                return 0;
 
-       if (!inset->descendable())
+       if (!inset->descendable(*this))
                // No need to go further down if the inset is not
                // descendable.
                return inset;