From 401b223dfbc457424e80e86e9b8125cbe7d69cea Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sun, 27 Sep 2009 10:29:13 +0000 Subject: [PATCH] Transfer LFUN_INSET_APPLY from GuiView to BufferView. The list of dialog edited inset is now stored in BufferView. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31472 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.cpp | 55 +++++++++++++++++++++++++ src/BufferView.h | 4 ++ src/frontends/qt4/GuiView.cpp | 77 ++++++----------------------------- src/frontends/qt4/GuiView.h | 3 -- 4 files changed, 72 insertions(+), 67 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 61a40a2ead..3f35b90ee5 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -276,6 +276,9 @@ struct BufferView::Private /// Cache for Find Next FuncRequest search_request_cache_; + + /// + map 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::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; @@ -1823,6 +1856,28 @@ 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); + // useful if we are called from a dialog. + cur.beginUndoGroup(); + cur.recordUndo(); + FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument()); + inset->dispatch(cur, fr); + cur.endUndoGroup(); + processUpdateFlags(Update::SinglePar | Update::FitCursor); + break; + } + + default: return false; } diff --git a/src/BufferView.h b/src/BufferView.h index 9cbb3cf60a..5b277c4edc 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -304,6 +304,10 @@ public: void insertLyXFile(support::FileName const & f); /// save temporary bookmark for jump back navigation void bookmarkEditPosition(); + /// Find and return the inset associated with given dialog name. + Inset * editedInset(std::string const & name) const; + /// Associate an inset associated with given dialog name. + void editInset(std::string const & name, Inset * inset); private: /// noncopyable diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index b9462b4710..575933fa47 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -275,9 +275,6 @@ public: */ LayoutBox * layout_; - /// - map open_insets_; - /// map dialogs_; @@ -1323,25 +1320,6 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag) // Nothing to check. break; - case LFUN_INSET_APPLY: { - string const name = cmd.getArg(0); - Inset * inset = getOpenInset(name); - if (inset) { - FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument()); - FuncStatus fs; - if (!inset->getStatus(currentBufferView()->cursor(), 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); - } - enable = flag.enabled(); - break; - } - case LFUN_COMPLETION_INLINE: if (!d.current_work_area_ || !d.current_work_area_->completer().inlinePossible( @@ -2591,9 +2569,11 @@ bool GuiView::dispatch(FuncRequest const & cmd) case LFUN_DIALOG_UPDATE: { string const name = to_utf8(cmd.argument()); - // Can only update a dialog connected to an existing inset - Inset * inset = getOpenInset(name); - if (inset) { + if (currentBufferView()) { + Inset * inset = currentBufferView()->editedInset(name); + // Can only update a dialog connected to an existing inset + if (!inset) + break; FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument()); inset->dispatch(currentBufferView()->cursor(), fr); } else if (name == "paragraph") { @@ -2664,28 +2644,6 @@ bool GuiView::dispatch(FuncRequest const & cmd) message(cmd.argument()); break; - case LFUN_INSET_APPLY: { - string const name = cmd.getArg(0); - Inset * inset = getOpenInset(name); - if (inset) { - // put cursor in front of inset. - if (!currentBufferView()->setCursorFromInset(inset)) { - LASSERT(false, break); - } - BufferView * bv = currentBufferView(); - // useful if we are called from a dialog. - bv->cursor().beginUndoGroup(); - bv->cursor().recordUndo(); - FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument()); - inset->dispatch(bv->cursor(), fr); - bv->cursor().endUndoGroup(); - } else { - FuncRequest fr(LFUN_INSET_INSERT, cmd.argument()); - lyx::dispatch(fr); - } - break; - } - case LFUN_UI_TOGGLE: lfunUiToggle(cmd); // Make sure the keyboard focus stays in the work area. @@ -3004,8 +2962,8 @@ void GuiView::showDialog(string const & name, string const & data, Dialog * dialog = findOrBuild(name, false); if (dialog) { dialog->showData(data); - if (inset) - d.open_insets_[name] = inset; + if (inset && currentBufferView()) + currentBufferView()->editInset(name, inset); } } catch (ExceptionMessage const & ex) { @@ -3031,13 +2989,15 @@ void GuiView::hideDialog(string const & name, Inset * inset) if (it == d.dialogs_.end()) return; - if (inset && inset != getOpenInset(name)) + if (inset && currentBufferView() + && inset != currentBufferView()->editedInset(name)) return; Dialog * const dialog = it->second.get(); if (dialog->isVisibleView()) dialog->hideView(); - d.open_insets_[name] = 0; + if (currentBufferView()) + currentBufferView()->editInset(name, 0); } @@ -3045,19 +3005,8 @@ void GuiView::disconnectDialog(string const & name) { if (!isValidName(name)) return; - - if (d.open_insets_.find(name) != d.open_insets_.end()) - d.open_insets_[name] = 0; -} - - -Inset * GuiView::getOpenInset(string const & name) const -{ - if (!isValidName(name)) - return 0; - - map::const_iterator it = d.open_insets_.find(name); - return it == d.open_insets_.end() ? 0 : it->second; + if (currentBufferView()) + currentBufferView()->editInset(name, 0); } diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 8201850505..b4fa5bc297 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -324,9 +324,6 @@ private: /// void gotoNextOrPreviousBuffer(NextOrPrevious np); - /// - Inset * getOpenInset(std::string const & name) const; - /// Is the dialog currently visible? bool isDialogVisible(std::string const & name) const; /// -- 2.39.2