From 311ac9b192bc45f29b8c305b4519a09e3e30bccc Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 19 Sep 2006 13:36:20 +0000 Subject: [PATCH] This is the continuation of my BufferView/LyXView cleanup. This commit replaces BufferView->LyXView->getDialogs().[show(), update()] with BufferView signal emissions. The associated WorkArea is then responsible to connect these signals to its LyXView parent. * BufferView: - showDialog, showDialogWithData, showInsetDialog: new boost signals * LyXView: - connectBufferView(), disconnectBufferView(): new method in charge of the connection/disconnection of the above signal to associate private methods (showDialog(), etc). * WorkArea - setBufferView(): will connect/disconnect the BufferView to its LyXView parent. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15068 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 4 +-- src/BufferView.h | 16 ++++++++++++ src/frontends/LyXView.C | 50 ++++++++++++++++++++++++++++++++++++++ src/frontends/LyXView.h | 26 ++++++++++++++++++++ src/frontends/WorkArea.C | 6 ++++- src/insets/mailinset.C | 6 ++--- src/lyxfunc.h | 2 +- src/mathed/InsetMathHull.C | 2 +- src/mathed/InsetMathNest.C | 4 +-- src/mathed/InsetMathRef.C | 5 ++-- src/messages.C | 2 +- src/text3.C | 16 ++++++------ 12 files changed, 115 insertions(+), 24 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index e16a2da665..6b03a41239 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -858,7 +858,7 @@ bool BufferView::dispatch(FuncRequest const & cmd) case LFUN_CHANGES_MERGE: if (lyx::find::findNextChange(this)) - owner_->getDialogs().show("changes"); + showDialog("changes"); break; case LFUN_ALL_CHANGES_ACCEPT: { @@ -1454,7 +1454,7 @@ void BufferView::trackChanges() } else { cursor_.setCursor(doc_iterator_begin(buffer_->inset())); if (lyx::find::findNextChange(this)) { - owner_->getDialogs().show("changes"); + showDialog("changes"); return; } diff --git a/src/BufferView.h b/src/BufferView.h index 43f197be7a..94c1588e8a 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -217,6 +217,22 @@ public: /// This signal is emitted when some message shows up. boost::signal message; + /// This signal is emitted when some dialog needs to be shown. + boost::signal showDialog; + + /// This signal is emitted when some dialog needs to be shown with + /// some data + boost::signal showDialogWithData; + + /// This signal is emitted when some inset dialogs needs to be shown. + boost::signal showInsetDialog; + + /// This signal is emitted when some dialogs needs to be updated. + boost::signal updateDialog; + private: /// bool multiParSel(); diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C index 7b06cf9684..6e08fc4d0c 100644 --- a/src/frontends/LyXView.C +++ b/src/frontends/LyXView.C @@ -83,6 +83,7 @@ LyXView::LyXView(Gui & owner) lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl; } + LyXView::~LyXView() { } @@ -219,6 +220,28 @@ void LyXView::disconnectBuffer() } +void LyXView::connectBufferView(BufferView & bv) +{ + show_dialog_connection_ = bv.showDialog.connect( + boost::bind(&LyXView::showDialog, this, _1)); + show_dialog_with_data_connection_ = bv.showDialogWithData.connect( + boost::bind(&LyXView::showDialogWithData, this, _1, _2)); + show_inset_dialog_connection_ = bv.showInsetDialog.connect( + boost::bind(&LyXView::showInsetDialog, this, _1, _2, _3)); + update_dialog_connection_ = bv.updateDialog.connect( + boost::bind(&LyXView::updateDialog, this, _1, _2)); +} + + +void LyXView::disconnectBufferView() +{ + show_dialog_connection_.disconnect(); + show_dialog_with_data_connection_.disconnect(); + show_inset_dialog_connection_.disconnect(); + update_dialog_connection_.disconnect(); +} + + void LyXView::showErrorList(string const & error_type) { ErrorList & el = buffer()->errorList(error_type); @@ -228,6 +251,33 @@ void LyXView::showErrorList(string const & error_type) } +void LyXView::showDialog(string const & name) +{ + getDialogs().show(name); +} + + +void LyXView::showDialogWithData(string const & name, + string const & data) +{ + getDialogs().show(name, data); +} + + +void LyXView::showInsetDialog(string const & name, string const & data, + InsetBase * inset) +{ + getDialogs().show(name, data, 0); +} + + +void LyXView::updateDialog(string const & name, string const & data) +{ + if (getDialogs().visible(name)) + getDialogs().update(name, data); +} + + void LyXView::showReadonly(bool) { updateWindowTitle(); diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index b353571f03..13776f2529 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -165,6 +165,11 @@ public: /// show the error list to the user void showErrorList(std::string const &); + /// connect to signals in the given BufferView + void connectBufferView(BufferView & bv); + /// disconnect from signals in the given BufferView + void disconnectBufferView(); + protected: /// current work area (screen view of a BufferView). /** @@ -214,6 +219,27 @@ private: void connectBuffer(Buffer & buf); /// disconnect from signals in the given buffer void disconnectBuffer(); + + /// BufferView messages signal connection + //@{ + boost::signals::connection message_connection_; + boost::signals::connection show_dialog_connection_; + boost::signals::connection show_dialog_with_data_connection_; + boost::signals::connection show_inset_dialog_connection_; + boost::signals::connection update_dialog_connection_; + //@} + + /// Bind methods for BufferView messages signal connection + //@{ + void showDialog(std::string const & name); + void showDialogWithData(std::string const & name, + std::string const & data); + void showInsetDialog(std::string const & name, + std::string const & data, InsetBase * inset); + void updateDialog(std::string const & name, + std::string const & data); + //@} + /// notify readonly status void showReadonly(bool); diff --git a/src/frontends/WorkArea.C b/src/frontends/WorkArea.C index 41c7c62e6b..21005c4f50 100644 --- a/src/frontends/WorkArea.C +++ b/src/frontends/WorkArea.C @@ -159,8 +159,10 @@ WorkArea::WorkArea(LyXView & lyx_view) void WorkArea::setBufferView(BufferView * buffer_view) { - if (buffer_view_) + if (buffer_view_) { message_connection_.disconnect(); + lyx_view_.disconnectBufferView(); + } hideCursor(); buffer_view_ = buffer_view; @@ -168,6 +170,8 @@ void WorkArea::setBufferView(BufferView * buffer_view) message_connection_ = buffer_view_->message.connect( boost::bind(&WorkArea::displayMessage, this, _1)); + + lyx_view_.connectBufferView(*buffer_view); } diff --git a/src/insets/mailinset.C b/src/insets/mailinset.C index 6c63619af5..c059200b20 100644 --- a/src/insets/mailinset.C +++ b/src/insets/mailinset.C @@ -24,7 +24,7 @@ using std::string; void MailInset::showDialog(BufferView * bv) const { BOOST_ASSERT(bv); - bv->owner()->getDialogs().show(name(), inset2string(*bv->buffer()), + bv->showInsetDialog(name(), inset2string(*bv->buffer()), &inset()); } @@ -32,9 +32,7 @@ void MailInset::showDialog(BufferView * bv) const void MailInset::updateDialog(BufferView * bv) const { BOOST_ASSERT(bv); - if (bv->owner()->getDialogs().visible(name())) - bv->owner()->getDialogs().update(name(), - inset2string(*bv->buffer())); + bv->updateDialog(name(), inset2string(*bv->buffer())); } diff --git a/src/lyxfunc.h b/src/lyxfunc.h index 92ec7f6de9..47c0108eed 100644 --- a/src/lyxfunc.h +++ b/src/lyxfunc.h @@ -41,7 +41,7 @@ class LyXView; class LyXFunc : public boost::signals::trackable { public: /// - explicit LyXFunc(LyXView *); + explicit LyXFunc(LyXView * lv = 0); /// LyX dispatcher, executes lyx actions. void dispatch(FuncRequest const &); diff --git a/src/mathed/InsetMathHull.C b/src/mathed/InsetMathHull.C index 08d9d147a0..0054d6f461 100644 --- a/src/mathed/InsetMathHull.C +++ b/src/mathed/InsetMathHull.C @@ -1081,7 +1081,7 @@ void InsetMathHull::doDispatch(LCursor & cur, FuncRequest & cmd) string const data = InsetCommandMailer::params2string("label", p); if (cmd.argument().empty()) - cur.bv().owner()->getDialogs().show("label", data, 0); + cur.bv().showInsetDialog("label", data, 0); else { FuncRequest fr(LFUN_INSET_INSERT, data); dispatch(cur, fr); diff --git a/src/mathed/InsetMathNest.C b/src/mathed/InsetMathNest.C index 787b0b11a5..775543a63c 100644 --- a/src/mathed/InsetMathNest.C +++ b/src/mathed/InsetMathNest.C @@ -939,7 +939,7 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd) RefInset tmp(name); data = tmp.createDialogStr(name); } - cur.bv().owner()->getDialogs().show(name, data, 0); + cur.bv().showInsetDialog(name, data, 0); break; } @@ -1126,7 +1126,7 @@ void InsetMathNest::lfunMouseRelease(LCursor & cur, FuncRequest & cmd) if (cmd.button() == mouse_button::button3) { // try to dispatch to enclosed insets first - cur.bv().owner()->getDialogs().show("mathpanel"); + cur.bv().showDialog("mathpanel"); return; } diff --git a/src/mathed/InsetMathRef.C b/src/mathed/InsetMathRef.C index 606a1f5c79..4fbe793883 100644 --- a/src/mathed/InsetMathRef.C +++ b/src/mathed/InsetMathRef.C @@ -73,8 +73,7 @@ void RefInset::doDispatch(LCursor & cur, FuncRequest & cmd) case LFUN_INSET_DIALOG_UPDATE: { string const data = createDialogStr("ref"); - if (cur.bv().owner()->getDialogs().visible("ref")) - cur.bv().owner()->getDialogs().update("ref", data); + cur.bv().updateDialog("ref", data); break; } @@ -87,7 +86,7 @@ void RefInset::doDispatch(LCursor & cur, FuncRequest & cmd) if (cmd.button() == mouse_button::button1) { // Eventually trigger dialog with button 3, not 1 string const data = createDialogStr("ref"); - cur.bv().owner()->getDialogs().show("ref", data, this); + cur.bv().showInsetDialog("ref", data, this); break; } cur.undispatched(); diff --git a/src/messages.C b/src/messages.C index 1f192e9fc7..82f86c684d 100644 --- a/src/messages.C +++ b/src/messages.C @@ -196,7 +196,7 @@ public: lyxerr << "Undefined result from gettext" << endl; translated = from_ascii(tmp); } else if (msg == tmp) { - lyxerr << "Same as entered returned" << endl; + //lyxerr << "Same as entered returned" << endl; translated = from_ascii(tmp); } else { lyxerr << "We got a translation" << endl; diff --git a/src/text3.C b/src/text3.C index 7f0e846572..f5142a1c76 100644 --- a/src/text3.C +++ b/src/text3.C @@ -1091,14 +1091,14 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) case LFUN_URL_INSERT: { InsetCommandParams p("url"); string const data = InsetCommandMailer::params2string("url", p); - bv->owner()->getDialogs().show("url", data, 0); + bv->showInsetDialog("url", data, 0); break; } case LFUN_HTML_INSERT: { InsetCommandParams p("htmlurl"); string const data = InsetCommandMailer::params2string("url", p); - bv->owner()->getDialogs().show("url", data, 0); + bv->showInsetDialog("url", data, 0); break; } @@ -1111,7 +1111,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) string const data = InsetCommandMailer::params2string("label", p); if (cmd.argument().empty()) { - bv->owner()->getDialogs().show("label", data, 0); + bv->showInsetDialog("label", data, 0); } else { FuncRequest fr(LFUN_INSET_INSERT, data); dispatch(cur, fr); @@ -1146,7 +1146,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) if (doInsertInset(cur, this, cmd, false, true)) cur.posRight(); else - bv->owner()->getDialogs().show("tabularcreate"); + bv->showDialog("tabularcreate"); break; @@ -1351,13 +1351,11 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) string data; params2string(cur.paragraph(), data); data = "show\n" + data; - bv->owner()->getDialogs().show("paragraph", data); + bv->showDialogWithData("paragraph", data); break; } case LFUN_PARAGRAPH_UPDATE: { - if (!bv->owner()->getDialogs().visible("paragraph")) - break; string data; params2string(cur.paragraph(), data); @@ -1365,7 +1363,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) bool const accept = !cur.inset().forceDefaultParagraphs(cur.idx()); data = "update " + convert(accept) + '\n' + data; - bv->owner()->getDialogs().update("paragraph", data); + bv->updateDialog("paragraph", data); break; } @@ -1438,7 +1436,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) arg = cur.selectionAsString(false); } } - bv->owner()->getDialogs().show("thesaurus", lyx::to_utf8(arg)); + bv->showDialogWithData("thesaurus", lyx::to_utf8(arg)); break; } -- 2.39.2