]> git.lyx.org Git - features.git/commitdiff
Transfer some LFUNs from LyXFunc to GuiView.
authorAbdelrazak Younes <younes@lyx.org>
Mon, 19 Nov 2007 20:56:05 +0000 (20:56 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 19 Nov 2007 20:56:05 +0000 (20:56 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21681 a592a061-630c-0410-9148-cb99ea01b6c8

src/LyXFunc.cpp
src/frontends/Application.h
src/frontends/Delegates.h
src/frontends/LyXView.h
src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiApplication.h
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiView.h

index bd8d8da8ff51cd9d2bc675a76820ea0680036138..8960b102544a7853e96a442d3db7d9060410f3cb 100644 (file)
@@ -544,6 +544,16 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        // to handle (Andre')
        bool enable = true;
        switch (cmd.action) {
+
+       case LFUN_DIALOG_TOGGLE:
+       case LFUN_DIALOG_SHOW:
+       case LFUN_DIALOG_UPDATE:
+       case LFUN_TOOLBAR_TOGGLE:
+               if (lyx_view_)
+                       return lyx_view_->getStatus(cmd);
+               enable = false;
+               break;
+
        case LFUN_BUFFER_TOGGLE_READ_ONLY:
                flag.setOnOff(buf->isReadonly());
                break;
@@ -609,48 +619,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                break;
        }
 
-       case LFUN_DIALOG_TOGGLE:
-               flag.setOnOff(lyx_view_?
-                       lyx_view_->isDialogVisible(cmd.getArg(0)) : false);
-               // fall through to set "enable"
-       case LFUN_DIALOG_SHOW: {
-               string const name = cmd.getArg(0);
-               if (!buf)
-                       enable = name == "aboutlyx"
-                               || name == "file" //FIXME: should be removed.
-                               || name == "prefs"
-                               || name == "texinfo";
-               else if (name == "print")
-                       enable = buf->isExportable("dvi")
-                               && lyxrc.print_command != "none";
-               else if (name == "character") {
-                       if (!view())
-                               enable = false;
-                       else {
-                               InsetCode ic = view()->cursor().inset().lyxCode();
-                               enable = ic != ERT_CODE && ic != LISTINGS_CODE;
-                       }
-               }
-               else if (name == "latexlog")
-                       enable = FileName(buf->logName()).isFileReadable();
-               else if (name == "spellchecker")
-#if defined (USE_ASPELL) || defined (USE_ISPELL) || defined (USE_PSPELL)
-                       enable = !buf->isReadonly();
-#else
-                       enable = false;
-#endif
-               else if (name == "vclog")
-                       enable = buf->lyxvc().inUse();
-               break;
-       }
-
-       case LFUN_DIALOG_UPDATE: {
-               string const name = cmd.getArg(0);
-               if (!buf)
-                       enable = name == "prefs";
-               break;
-       }
-
        case LFUN_CITATION_INSERT: {
                FuncRequest fr(LFUN_INSET_INSERT, "citation");
                enable = getStatus(fr).enabled();
@@ -696,16 +664,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                enable = LyX::ref().session().bookmarks().size() > 0;
                break;
 
-       case LFUN_TOOLBAR_TOGGLE: {
-               bool const current = lyx_view_?
-                       lyx_view_->isToolbarVisible(cmd.getArg(0)) : false;
-               flag.setOnOff(current);
-               break;
-       }
-       case LFUN_WINDOW_CLOSE: {
+       case LFUN_WINDOW_CLOSE:
                enable = theApp()->viewCount() > 0;
                break;
-       }
 
        // this one is difficult to get right. As a half-baked
        // solution, we consider only the first action of the sequence
@@ -920,6 +881,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                case LFUN_DROP_LAYOUTS_CHOICE:
                case LFUN_MENU_OPEN:
                case LFUN_TOOLBAR_TOGGLE:
+               case LFUN_DIALOG_UPDATE:
+               case LFUN_DIALOG_TOGGLE:
+               case LFUN_DIALOG_DISCONNECT_INSET:
+               case LFUN_DIALOG_HIDE:
                        BOOST_ASSERT(lyx_view_);
                        lyx_view_->dispatch(cmd);
                        break;
@@ -1418,36 +1383,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               case LFUN_DIALOG_SHOW: {
-                       BOOST_ASSERT(lyx_view_);
-                       string const name = cmd.getArg(0);
-                       string data = trim(to_utf8(cmd.argument()).substr(name.size()));
-
-                       if (name == "character") {
-                               data = freefont2string();
-                               if (!data.empty())
-                                       lyx_view_->showDialog("character", data);
-                       } else if (name == "latexlog") {
-                               Buffer::LogType type; 
-                               string const logfile = lyx_view_->buffer()->logName(&type);
-                               switch (type) {
-                               case Buffer::latexlog:
-                                       data = "latex ";
-                                       break;
-                               case Buffer::buildlog:
-                                       data = "literate ";
-                                       break;
-                               }
-                               data += Lexer::quoteString(logfile);
-                               lyx_view_->showDialog("log", data);
-                       } else if (name == "vclog") {
-                               string const data = "vc " +
-                                       Lexer::quoteString(lyx_view_->buffer()->lyxvc().getLogFile());
-                               lyx_view_->showDialog("log", data);
-                       } else
-                               lyx_view_->showDialog(name, data);
-                       break;
-               }
 
                case LFUN_DIALOG_SHOW_NEW_INSET: {
                        BOOST_ASSERT(lyx_view_);
@@ -1546,44 +1481,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               case LFUN_DIALOG_UPDATE: {
-                       BOOST_ASSERT(lyx_view_);
-                       string const & name = argument;
-                       // Can only update a dialog connected to an existing inset
-                       Inset * inset = lyx_view_->getOpenInset(name);
-                       if (inset) {
-                               FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument());
-                               inset->dispatch(view()->cursor(), fr);
-                       } else if (name == "paragraph") {
-                               dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
-                       } else if (name == "prefs") {
-                               lyx_view_->updateDialog(name, string());
-                       }
-                       break;
-               }
-
-               case LFUN_DIALOG_HIDE: {
-                       if (quitting || !use_gui)
-                               break;
-                       theApp()->hideDialogs(argument, 0);
-                       break;
-               }
-
-               case LFUN_DIALOG_TOGGLE: {
-                       BOOST_ASSERT(lyx_view_);
-                       if (lyx_view_->isDialogVisible(cmd.getArg(0)))
-                               dispatch(FuncRequest(LFUN_DIALOG_HIDE, argument));
-                       else
-                               dispatch(FuncRequest(LFUN_DIALOG_SHOW, argument));
-                       break;
-               }
-
-               case LFUN_DIALOG_DISCONNECT_INSET:
-                       BOOST_ASSERT(lyx_view_);
-                       lyx_view_->disconnectDialog(argument);
-                       break;
-
-
                case LFUN_CITATION_INSERT: {
                        BOOST_ASSERT(lyx_view_);
                        if (!argument.empty()) {
index af275ec348751d2eb06447867eb3284ff700bdfc..7c3abdd50e654b53cb914248d2b90bb29dae8935 100644 (file)
@@ -154,8 +154,6 @@ public:
        ///
        virtual bool closeAllViews() = 0;
        ///
-       virtual LyXView & view(int id) const = 0;
-       ///
        virtual size_t viewCount() const = 0;
        ///
        virtual void hideDialogs(std::string const & name, Inset * inset) const = 0;
index fc96786a3972e15fabb31a7d6f1c559fabd8f5b3..76d34b9726405727b9ab41bb4655336259a75e42 100644 (file)
@@ -34,6 +34,10 @@ public:
                std::string const & data, Inset * inset = 0) = 0;
 
        /// This function is called when some dialogs needs to be updated.
+       /** \param name == "citation", "bibtex" etc; an identifier used\r
+           to update the contents of a particular dialog with \param data.\r
+           See the comments to 'show', above.\r
+       */\r
        virtual void updateDialog(std::string const & name,
                std::string const & data) = 0;
 };
index 573934d0db7b800a326e6d9c3366b199061d47a3..1cf209bdf66d953554eb061a021135a14d93d9ba 100644 (file)
@@ -22,6 +22,7 @@ namespace support { class FileName; }
 
 class Buffer;
 class BufferView;
+class FuncStatus;
 class FuncRequest;
 class Inset;
 
@@ -67,9 +68,6 @@ public:
        /// set a buffer to the current workarea.
        virtual void setBuffer(Buffer * b) = 0; ///< \c Buffer to set.
 
-       ///
-       virtual bool isToolbarVisible(std::string const & id) = 0;
-
        //@}
 
        /// updates the possible layouts selectable
@@ -81,6 +79,8 @@ public:
        /// display a message in the view
        virtual void message(docstring const &) = 0;
 
+       ///
+       virtual FuncStatus getStatus(FuncRequest const & cmd) = 0;
        /// dispatch to current BufferView
        virtual void dispatch(FuncRequest const & cmd) = 0;
 
@@ -124,19 +124,6 @@ public:
        virtual void showDialog(std::string const & name,
                std::string const & data, Inset * inset = 0) = 0;
 
-       /** \param name == "citation", "bibtex" etc; an identifier used
-           to update the contents of a particular dialog with \param data.
-           See the comments to 'show', above.
-       */
-       virtual void updateDialog(std::string const & name, std::string const & data) = 0;
-
-       /// Is the dialog currently visible?
-       virtual bool isDialogVisible(std::string const & name) const = 0;
-
-       /** All Dialogs of the given \param name will be closed if they are
-           connected to the given \param inset.
-       */
-       virtual void hideDialog(std::string const & name, Inset * inset) = 0;
        ///
        virtual void disconnectDialog(std::string const & name) = 0;
        ///
index c954aba91c38fa6b314f739f50ab77ab9a0d04b2..0161891f74a2997e329d7966346515f6c5ec6b3f 100644 (file)
@@ -495,7 +495,7 @@ bool GuiApplication::closeAllViews()
 }
 
 
-LyXView & GuiApplication::view(int id) const
+GuiView & GuiApplication::view(int id) const
 {
        BOOST_ASSERT(views_.find(id) != views_.end());
        return *views_.find(id)->second;
index 7b51eb4777d22ff7388979bfe8eb1c23687b0894..40cec19fd981fe031e1d6d1a8f1bec941bd32a59 100644 (file)
@@ -105,7 +105,7 @@ public:
        ///
        virtual bool unregisterView(int id);
        ///
-       virtual LyXView & view(int id) const;
+       virtual GuiView & view(int id) const;
        ///
        virtual void hideDialogs(std::string const & name, Inset * inset) const;
        ///
index 7415abc94fc965f0c4e7977c8da4a21d13388e6f..c8d403eaa4a7e998a5e90e5ba92b24866ffef8b5 100644 (file)
@@ -43,9 +43,11 @@ using std::string;
 #include "gettext.h"
 #include "Intl.h"
 #include "Layout.h"
+#include "Lexer.h"
 #include "LyXFunc.h"
 #include "LyX.h"
 #include "LyXRC.h"
+#include "LyXVC.h"
 #include "MenuBackend.h"
 #include "Paragraph.h"
 #include "TextClass.h"
@@ -54,6 +56,7 @@ using std::string;
 #include "version.h"
 
 #include "support/convert.h"
+#include "support/FileName.h"
 #include "support/lstrings.h"
 #include "support/os.h"
 #include "support/Timeout.h"
@@ -100,6 +103,8 @@ extern bool quitting;
 namespace frontend {
 
 using support::bformat;
+using support::FileName;
+using support::trim;
 
 namespace {
 
@@ -805,11 +810,6 @@ void GuiView::updateLayoutChoice(bool force)
 }
 
 
-bool GuiView::isToolbarVisible(std::string const & id)
-{
-       return d.toolbars_->visible(id);
-}
-
 void GuiView::updateToolbars()
 {
        if (d.current_work_area_) {
@@ -950,8 +950,75 @@ void GuiView::resetAutosaveTimers()
 }
 
 
+FuncStatus GuiView::getStatus(FuncRequest const & cmd)
+{
+       FuncStatus flag;
+       bool enable = true;
+       Buffer * buf = buffer();
+
+       switch(cmd.action) {
+       case LFUN_TOOLBAR_TOGGLE:
+               flag.setOnOff(d.toolbars_->visible(cmd.getArg(0)));
+               break;
+
+       case LFUN_DIALOG_TOGGLE:
+               flag.setOnOff(isDialogVisible(cmd.getArg(0)));
+               // fall through to set "enable"
+       case LFUN_DIALOG_SHOW: {
+               string const name = cmd.getArg(0);
+               if (!buf)
+                       enable = name == "aboutlyx"
+                               || name == "file" //FIXME: should be removed.
+                               || name == "prefs"
+                               || name == "texinfo";
+               else if (name == "print")
+                       enable = buf->isExportable("dvi")
+                               && lyxrc.print_command != "none";
+               else if (name == "character") {
+                       if (!view())
+                               enable = false;
+                       else {
+                               InsetCode ic = view()->cursor().inset().lyxCode();
+                               enable = ic != ERT_CODE && ic != LISTINGS_CODE;
+                       }
+               }
+               else if (name == "latexlog")
+                       enable = FileName(buf->logName()).isFileReadable();
+               else if (name == "spellchecker")
+#if defined (USE_ASPELL) || defined (USE_ISPELL) || defined (USE_PSPELL)
+                       enable = !buf->isReadonly();
+#else
+                       enable = false;
+#endif
+               else if (name == "vclog")
+                       enable = buf->lyxvc().inUse();
+               break;
+       }
+
+       case LFUN_DIALOG_UPDATE: {
+               string const name = cmd.getArg(0);
+               if (!buf)
+                       enable = name == "prefs";
+               break;
+       }
+
+       default:
+               if (!view()) {
+                       enable = false;
+                       break;
+               }
+       }
+
+       if (!enable)
+               flag.enabled(false);
+
+       return flag;
+}
+
+
 void GuiView::dispatch(FuncRequest const & cmd)
 {
+       Buffer * buf = buffer();
        switch(cmd.action) {
                case LFUN_BUFFER_SWITCH:
                        setBuffer(theBufferList().getBuffer(to_utf8(cmd.argument())));
@@ -1001,6 +1068,70 @@ void GuiView::dispatch(FuncRequest const & cmd)
                        break;
                }
 
+               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) {
+                               FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument());
+                               inset->dispatch(view()->cursor(), fr);
+                       } else if (name == "paragraph") {
+                               lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
+                       } else if (name == "prefs") {
+                               updateDialog(name, string());
+                       }
+                       break;
+               }
+
+               case LFUN_DIALOG_TOGGLE: {
+                       if (isDialogVisible(cmd.getArg(0)))
+                               dispatch(FuncRequest(LFUN_DIALOG_HIDE, cmd.argument()));
+                       else
+                               dispatch(FuncRequest(LFUN_DIALOG_SHOW, cmd.argument()));
+                       break;
+               }
+
+               case LFUN_DIALOG_DISCONNECT_INSET:
+                       disconnectDialog(to_utf8(cmd.argument()));
+                       break;
+
+               case LFUN_DIALOG_HIDE: {
+                       if (quitting)
+                               break;
+                       guiApp->hideDialogs(to_utf8(cmd.argument()), 0);
+                       break;
+               }
+
+               case LFUN_DIALOG_SHOW: {
+                       string const name = cmd.getArg(0);
+                       string data = trim(to_utf8(cmd.argument()).substr(name.size()));
+
+                       if (name == "character") {
+                               data = freefont2string();
+                               if (!data.empty())
+                                       showDialog("character", data);
+                       } else if (name == "latexlog") {
+                               Buffer::LogType type; 
+                               string const logfile = buf->logName(&type);
+                               switch (type) {
+                               case Buffer::latexlog:
+                                       data = "latex ";
+                                       break;
+                               case Buffer::buildlog:
+                                       data = "literate ";
+                                       break;
+                               }
+                               data += Lexer::quoteString(logfile);
+                               showDialog("log", data);
+                       } else if (name == "vclog") {
+                               string const data = "vc " +
+                                       Lexer::quoteString(buf->lyxvc().getLogFile());
+                               showDialog("log", data);
+                       } else
+                               showDialog(name, data);
+                       break;
+               }
+
                default:
                        theLyXFunc().setLyXView(this);
                        lyx::dispatch(cmd);
index e7b08aa48fcb17cae788eb18543b84c2c300ba6d..2479dba84fff3b7db35865b221bdfde53a0cb8d5 100644 (file)
@@ -70,12 +70,9 @@ public:
        virtual void message(docstring const & str);
        virtual bool hasFocus() const;
        void updateLayoutChoice(bool force);
-       bool isToolbarVisible(std::string const & id);
        void updateToolbars();
-       ///
        QMenu * createPopupMenu();
-
-       /// dispatch to current BufferView
+       FuncStatus getStatus(FuncRequest const & cmd);
        void dispatch(FuncRequest const & cmd);
 
        /// \return the buffer currently shown in this window
@@ -218,9 +215,6 @@ public:
        */
        void updateDialog(std::string const & name, std::string const & data);
 
-       /// Is the dialog currently visible?
-       bool isDialogVisible(std::string const & name) const;
-
        /** All Dialogs of the given \param name will be closed if they are
            connected to the given \param inset.
        */
@@ -231,6 +225,8 @@ public:
        Inset * getOpenInset(std::string const & name) const;
 
 private:
+       /// Is the dialog currently visible?
+       bool isDialogVisible(std::string const & name) const;
        ///
        Dialog * find_or_build(std::string const & name);
        ///