]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
Implement os::current_root for native Win32 builds.
[lyx.git] / src / lyxfunc.C
index b5c3ad161bf90a3a99a692beb678cb354d1738b3..defb342f1bc95ca1edc1f8d55bf09371840176a9 100644 (file)
 #include "frontends/Menubar.h"
 #include "frontends/Toolbars.h"
 
+#include "support/filefilterlist.h"
 #include "support/FileInfo.h"
 #include "support/filetools.h"
 #include "support/forkedcontr.h"
-#include "support/globbing.h"
 #include "support/lstrings.h"
 #include "support/path.h"
 #include "support/path_defines.h"
@@ -134,7 +134,6 @@ namespace biblio = lyx::biblio;
 
 extern BufferList bufferlist;
 extern LyXServer * lyxserver;
-extern bool selection_possible;
 
 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
 
@@ -286,7 +285,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                buf = owner->buffer();
 
        if (cmd.action == LFUN_NOACTION) {
-               setStatusMessage(N_("Nothing to do"));
+               flag.message(N_("Nothing to do"));
                flag.enabled(false);
                return flag;
        }
@@ -304,19 +303,20 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        }
 
        if (flag.unknown()) {
-               setStatusMessage(N_("Unknown action"));
+               flag.message(N_("Unknown action"));
                return flag;
        }
 
-       // the default error message if we disable the command
-       setStatusMessage(N_("Command disabled"));
-       if (!flag.enabled())
+       if (!flag.enabled()) {
+               if (flag.message().empty())
+                       flag.message(N_("Command disabled"));
                return flag;
+       }
 
        // Check whether we need a buffer
        if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !buf) {
                // no, exit directly
-               setStatusMessage(N_("Command not allowed with"
+               flag.message(N_("Command not allowed with"
                                    "out any document open"));
                flag.enabled(false);
                return flag;
@@ -396,27 +396,27 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                if (!inset)
                        break;
 
-               InsetOld::Code code = inset->lyxCode();
+               InsetBase::Code code = inset->lyxCode();
                switch (code) {
-                       case InsetOld::TABULAR_CODE:
+                       case InsetBase::TABULAR_CODE:
                                enable = cmd.argument == "tabular";
                                break;
-                       case InsetOld::ERT_CODE:
+                       case InsetBase::ERT_CODE:
                                enable = cmd.argument == "ert";
                                break;
-                       case InsetOld::FLOAT_CODE:
+                       case InsetBase::FLOAT_CODE:
                                enable = cmd.argument == "float";
                                break;
-                       case InsetOld::WRAP_CODE:
+                       case InsetBase::WRAP_CODE:
                                enable = cmd.argument == "wrap";
                                break;
-                       case InsetOld::NOTE_CODE:
+                       case InsetBase::NOTE_CODE:
                                enable = cmd.argument == "note";
                                break;
-                       case InsetOld::BRANCH_CODE:
+                       case InsetBase::BRANCH_CODE:
                                enable = cmd.argument == "branch";
                                break;
-                       case InsetOld::BOX_CODE:
+                       case InsetBase::BOX_CODE:
                                enable = cmd.argument == "box";
                                break;
                        default:
@@ -437,7 +437,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                        enable = Exporter::IsExportable(*buf, "dvi")
                                && lyxrc.print_command != "none";
                else if (name == "character")
-                       enable = cur.inset().lyxCode() != InsetOld::ERT_CODE;
+                       enable = cur.inset().lyxCode() != InsetBase::ERT_CODE;
                else if (name == "vclog")
                        enable = buf->lyxvc().inUse();
                else if (name == "latexlog")
@@ -522,9 +522,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
 
        default:
 
-               cur.getStatus(cmd, flag);
-               if (!flag.enabled())
-                       flag = view()->getStatus(cmd);
+               if (!cur.getStatus(cmd, flag))
+                       flag |= view()->getStatus(cmd);
        }
 
        if (!enable)
@@ -534,11 +533,14 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        if (buf && buf->isReadonly()
            && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
            && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
-               setStatusMessage(N_("Document is read-only"));
+               flag.message(N_("Document is read-only"));
                flag.enabled(false);
        }
 
-       //lyxerr << "LyXFunc::getStatus: got: " << flag.enabled() << endl;
+       // the default error message if we disable the command
+       if (!flag.enabled() && flag.message().empty())
+               flag.message(N_("Command disabled"));
+
        return flag;
 }
 
@@ -602,6 +604,7 @@ void loadTextclass(string const & name)
 
 void LyXFunc::dispatch(FuncRequest const & cmd)
 {
+       BOOST_ASSERT(view());
        string const argument = cmd.argument;
        kb_action const action = cmd.action;
 
@@ -611,18 +614,17 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
        // we have not done anything wrong yet.
        errorstat = false;
        dispatch_buffer.erase();
-       selection_possible = false;
 
        bool update = true;
 
-       // We cannot use this function here
-       if (!getStatus(cmd).enabled()) {
+       FuncStatus const flag = getStatus(cmd);
+       if (!flag.enabled()) {
+               // We cannot use this function here
                lyxerr[Debug::ACTION] << "LyXFunc::dispatch: "
                       << lyxaction.getActionName(action)
                       << " [" << action << "] is disabled at this location"
                       << endl;
-               setErrorMessage(getStatusMessage());
-
+               setErrorMessage(flag.message());
        } else {
 
                if (view()->available())
@@ -1451,7 +1453,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                update |= view()->cursor().result().update();
                        else
                                update |= view()->dispatch(cmd);
-
                        break;
                }
                }
@@ -1460,14 +1461,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        // Redraw screen unless explicitly told otherwise.
                        // This also initializes the position cache for all insets
                        // in (at least partially) visible top-level paragraphs.
-                       if (update)
-                               view()->update();
-
-                       // fitCursor() needs valid inset position. The previous call to
-                       // update() makes sure we have such even for freshly created
-                       // insets.
-                       if (view()->fitCursor())
-                               view()->update();
+                       view()->update(true, update);
+
                        // if we executed a mutating lfun, mark the buffer as dirty
                        if (getStatus(cmd).enabled()
                                        && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)
@@ -1477,9 +1472,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                if (view()->cursor().inTexted()) {
                        view()->owner()->updateLayoutChoice();
-                       sendDispatchMessage(getMessage(), cmd);
                }
        }
+       sendDispatchMessage(getMessage(), cmd);
 }
 
 
@@ -1779,12 +1774,6 @@ void LyXFunc::setMessage(string const & m) const
 }
 
 
-void LyXFunc::setStatusMessage(string const & m) const
-{
-       status_buffer = m;
-}
-
-
 string const LyXFunc::viewStatusMessage()
 {
        // When meta-fake key is pressed, show the key sequence so far + "M-".