]> git.lyx.org Git - lyx.git/commitdiff
Fix crash in lyx -e latex lib/doc/Shortcuts.lyx: theApp() is 0 in batch mode.
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Thu, 6 Jan 2011 18:40:39 +0000 (18:40 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Thu, 6 Jan 2011 18:40:39 +0000 (18:40 +0000)
Unfortunately the commandline export of InsetInfo is still broken for MENU_INFO.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37134 a592a061-630c-0410-9148-cb99ea01b6c8

src/BranchList.cpp
src/IndicesList.cpp
src/frontends/Application.h
src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiApplication.h
src/insets/InsetInfo.cpp

index 1277be23281a956a7d1dfe28314504ad0fac5655..7cb23ef5b499db62d99f25f3e99256c8cdef43cb 100644 (file)
@@ -48,6 +48,8 @@ Branch::Branch()
        // no theApp() with command line export
        if (theApp())
                theApp()->getRgbColor(Color_background, color_);
+       else
+               frontend::Application::getRgbColorUncached(Color_background, color_);
 }
 
 
@@ -106,9 +108,14 @@ void Branch::setColor(string const & str)
 {
        if (str.size() == 7 && str[0] == '#')
                color_ = rgbFromHexName(str);
-       else
+       else {
                // no color set or invalid color - use normal background
-               theApp()->getRgbColor(Color_background, color_);
+               // no theApp() with command line export
+               if (theApp())
+                       theApp()->getRgbColor(Color_background, color_);
+               else
+                       frontend::Application::getRgbColorUncached(Color_background, color_);
+       }
 }
 
 
index a73dbb90b042be053f81db83c8e918fc46d7b223..9f22373f3ab906f55af1b731fc27842bad8d8b13 100644 (file)
@@ -69,6 +69,8 @@ Index::Index()
        // no theApp() with command line export
        if (theApp())
                theApp()->getRgbColor(Color_indexlabel, color_);
+       else
+               frontend::Application::getRgbColorUncached(Color_indexlabel, color_);
 }
 
 
@@ -112,9 +114,14 @@ void Index::setColor(string const & str)
 {
        if (str.size() == 7 && str[0] == '#')
                color_ = rgbFromHexName(str);
-       else
+       else {
                // no color set or invalid color -- use predefined color
-               theApp()->getRgbColor(Color_indexlabel, color_);
+               // no theApp() with command line export
+               if (theApp())
+                       theApp()->getRgbColor(Color_indexlabel, color_);
+               else
+                       frontend::Application::getRgbColorUncached(Color_indexlabel, color_);
+       }
 }
 
 
index d5f48ae609597f7ab0ea088fb302c92321c49470..c12d8a938d301c8e0794d2676fdd0fc6f2b0d375 100644 (file)
@@ -209,6 +209,8 @@ public:
        * It returns false on failure and sets r, g, b to 0.
        */
        virtual bool getRgbColor(ColorCode col, RGBColor & rgbcol) = 0;
+       /// Like getRgbColor(), but static and slower
+       static bool getRgbColorUncached(ColorCode col, RGBColor & rgbcol);
 
        /** Eg, passing Color_black returns "000000",
        *      passing Color_white returns "ffffff".
@@ -232,7 +234,7 @@ public:
                docstring_list & names) const = 0;
 
        /// \return the icon file name for the given action.
-       virtual docstring iconName(FuncRequest const & f, bool unknown) = 0;
+       static docstring iconName(FuncRequest const & f, bool unknown);
 
        /// Handle a accented char key sequence
        /// FIXME: this is only needed for LFUN_ACCENT_* in Text::dispatch()
index 2862d30cdde12e181ae7b08f0f86e14ff63e1f34..bf5f4112fca480b220f66693c311b4de046a7ec1 100644 (file)
@@ -849,7 +849,7 @@ void GuiApplication::clearSession()
 }
 
 
-docstring GuiApplication::iconName(FuncRequest const & f, bool unknown)
+docstring Application::iconName(FuncRequest const & f, bool unknown)
 {
        return qstring_to_ucs4(lyx::frontend::iconName(f, unknown));
 }
@@ -2182,6 +2182,22 @@ bool GuiApplication::getRgbColor(ColorCode col, RGBColor & rgbcol)
 }
 
 
+bool Application::getRgbColorUncached(ColorCode col, RGBColor & rgbcol)
+{
+       QColor const qcol(lcolor.getX11Name(col).c_str());
+       if (!qcol.isValid()) {
+               rgbcol.r = 0;
+               rgbcol.g = 0;
+               rgbcol.b = 0;
+               return false;
+       }
+       rgbcol.r = qcol.red();
+       rgbcol.g = qcol.green();
+       rgbcol.b = qcol.blue();
+       return true;
+}
+
+
 string const GuiApplication::hexName(ColorCode col)
 {
        return ltrim(fromqstr(d->color_cache_.get(col).name()), "#");
index 342a276cc94d729a00de7d8106938360d1d57a42..c85c0b8b58cbe0a2f20540258063e7a1d9bbbe45 100644 (file)
@@ -67,7 +67,6 @@ public:
        void registerSocketCallback(int fd, SocketCallback func);
        void unregisterSocketCallback(int fd);
        bool searchMenu(FuncRequest const & func, docstring_list & names) const;
-       docstring iconName(FuncRequest const & f, bool unknown);
        void handleKeyFunc(FuncCode action);
        //@}
 
index b22c69f7b60b198d5ed11cc5c97ea77c136f80b2..be30d7fcdc42a6b2453b133329c2391e337681bc 100644 (file)
@@ -358,6 +358,10 @@ void InsetInfo::updateInfo()
                        break;
                }
                // iterate through the menubackend to find it
+               if (!theApp()) {
+                       error("Can't determine menu entry for action %1$s in batch mode");
+                       break;
+               }
                if (!theApp()->searchMenu(func, names)) {
                        error("No menu entry for action %1$s");
                        break;
@@ -389,11 +393,15 @@ void InsetInfo::updateInfo()
        }
        case ICON_INFO: {
                FuncRequest func = lyxaction.lookupFunc(name_);
-               docstring icon_name = theApp()->iconName(func, true);
+               docstring icon_name = frontend::Application::iconName(func, true);
                //FIXME: We should use the icon directly instead of
                // going through FileName. The code below won't work
                // if the icon is embedded in the executable through
                // the Qt resource system.
+               // This is only a negligible performance problem:
+               // If the installed icon differs from the resource icon the
+               // installed one is preferred anyway, and all icons that are
+               // embedded in the resources are installed as well.
                FileName file(to_utf8(icon_name));
                if (!file.exists())
                        break;