From ccea2a5cd9410ebe47a83a76fece3fa68b1d6419 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Thu, 5 Jun 2008 16:03:08 +0000 Subject: [PATCH] Move inset lookup to Dialog class as this is generic enough to be reused by other dialogs. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25147 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/Dialog.cpp | 15 +++++++++++++++ src/frontends/qt4/Dialog.h | 6 ++++++ src/frontends/qt4/GuiInfo.cpp | 15 ++------------- src/frontends/qt4/GuiInfo.h | 4 ---- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/frontends/qt4/Dialog.cpp b/src/frontends/qt4/Dialog.cpp index 88cfcec95f..fe5a87fa9b 100644 --- a/src/frontends/qt4/Dialog.cpp +++ b/src/frontends/qt4/Dialog.cpp @@ -16,10 +16,14 @@ #include "qt_helpers.h" #include "Buffer.h" +#include "BufferView.h" +#include "Cursor.h" #include "FuncRequest.h" #include "FuncStatus.h" #include "LyXFunc.h" +#include "insets/Inset.h" + #include "support/debug.h" #include "support/lassert.h" @@ -204,6 +208,17 @@ bool Dialog::isVisibleView() const } +Inset * Dialog::inset(InsetCode code) const +{ + Inset * ins = bufferview()->cursor().innerInsetOfType(code); + if (!ins) + ins = bufferview()->cursor().nextInset(); + if (!ins || ins->lyxCode() != code) + return 0; + return ins; +} + + void Dialog::checkStatus() { // buffer independant dialogs are always active. diff --git a/src/frontends/qt4/Dialog.h b/src/frontends/qt4/Dialog.h index 9c7b3b6c56..0b5488f325 100644 --- a/src/frontends/qt4/Dialog.h +++ b/src/frontends/qt4/Dialog.h @@ -14,6 +14,8 @@ #include "FuncCode.h" +#include "insets/InsetCode.h" + #include "support/strfwd.h" #include @@ -25,6 +27,7 @@ namespace lyx { class Buffer; class BufferView; class FuncRequest; +class Inset; namespace frontend { @@ -89,6 +92,9 @@ public: virtual void showData(std::string const & data); //@} + /// \return inset at current cursor location. + Inset * inset(InsetCode code) const; + /** Check whether we may apply our data. * * The buttons are disabled if not and (re-)enabled if yes. diff --git a/src/frontends/qt4/GuiInfo.cpp b/src/frontends/qt4/GuiInfo.cpp index 00bb882a14..c07250aaec 100644 --- a/src/frontends/qt4/GuiInfo.cpp +++ b/src/frontends/qt4/GuiInfo.cpp @@ -50,20 +50,9 @@ void GuiInfo::on_closePB_clicked() } -InsetInfo * GuiInfo::inset() const -{ - Inset * ins = bufferview()->cursor().innerInsetOfType(INFO_CODE); - if (!ins) - ins = bufferview()->cursor().nextInset(); - if (ins->lyxCode() != INFO_CODE) - return 0; - return static_cast(ins); -} - - void GuiInfo::applyView() { - InsetInfo * ii = inset(); + InsetInfo * ii = static_cast(inset(INFO_CODE)); if (!ii) return; @@ -77,7 +66,7 @@ void GuiInfo::applyView() void GuiInfo::updateView() { - InsetInfo * ii = inset(); + InsetInfo * ii = static_cast(inset(INFO_CODE)); if (!ii) { // FIXME: A New button to create an InsetInfo at the cursor location // would be nice. diff --git a/src/frontends/qt4/GuiInfo.h b/src/frontends/qt4/GuiInfo.h index c23525a9c4..01fcffd40f 100644 --- a/src/frontends/qt4/GuiInfo.h +++ b/src/frontends/qt4/GuiInfo.h @@ -39,10 +39,6 @@ public: private Q_SLOTS: void on_closePB_clicked(); - -private: - /// - InsetInfo * inset() const; }; } // namespace frontend