Author: baum
Date: Thu Jan  6 19:40:39 2011
New Revision: 37134
URL: http://www.lyx.org/trac/changeset/37134

Log:
Fix crash in lyx -e latex lib/doc/Shortcuts.lyx: theApp() is 0 in batch mode.
Unfortunately the commandline export of InsetInfo is still broken for MENU_INFO.

Modified:
   lyx-devel/trunk/src/BranchList.cpp
   lyx-devel/trunk/src/IndicesList.cpp
   lyx-devel/trunk/src/frontends/Application.h
   lyx-devel/trunk/src/frontends/qt4/GuiApplication.cpp
   lyx-devel/trunk/src/frontends/qt4/GuiApplication.h
   lyx-devel/trunk/src/insets/InsetInfo.cpp

Modified: lyx-devel/trunk/src/BranchList.cpp
==============================================================================
--- lyx-devel/trunk/src/BranchList.cpp  Thu Jan  6 19:36:03 2011        (r37133)
+++ lyx-devel/trunk/src/BranchList.cpp  Thu Jan  6 19:40:39 2011        (r37134)
@@ -48,6 +48,8 @@
        // no theApp() with command line export
        if (theApp())
                theApp()->getRgbColor(Color_background, color_);
+       else
+               frontend::Application::getRgbColorUncached(Color_background, 
color_);
 }
 
 
@@ -106,9 +108,14 @@
 {
        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_);
+       }
 }
 
 

Modified: lyx-devel/trunk/src/IndicesList.cpp
==============================================================================
--- lyx-devel/trunk/src/IndicesList.cpp Thu Jan  6 19:36:03 2011        (r37133)
+++ lyx-devel/trunk/src/IndicesList.cpp Thu Jan  6 19:40:39 2011        (r37134)
@@ -69,6 +69,8 @@
        // no theApp() with command line export
        if (theApp())
                theApp()->getRgbColor(Color_indexlabel, color_);
+       else
+               frontend::Application::getRgbColorUncached(Color_indexlabel, 
color_);
 }
 
 
@@ -112,9 +114,14 @@
 {
        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_);
+       }
 }
 
 

Modified: lyx-devel/trunk/src/frontends/Application.h
==============================================================================
--- lyx-devel/trunk/src/frontends/Application.h Thu Jan  6 19:36:03 2011        
(r37133)
+++ lyx-devel/trunk/src/frontends/Application.h Thu Jan  6 19:40:39 2011        
(r37134)
@@ -209,6 +209,8 @@
        * 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 @@
                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()

Modified: lyx-devel/trunk/src/frontends/qt4/GuiApplication.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiApplication.cpp        Thu Jan  6 
19:36:03 2011        (r37133)
+++ lyx-devel/trunk/src/frontends/qt4/GuiApplication.cpp        Thu Jan  6 
19:40:39 2011        (r37134)
@@ -849,7 +849,7 @@
 }
 
 
-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 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()), "#");

Modified: lyx-devel/trunk/src/frontends/qt4/GuiApplication.h
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiApplication.h  Thu Jan  6 19:36:03 
2011        (r37133)
+++ lyx-devel/trunk/src/frontends/qt4/GuiApplication.h  Thu Jan  6 19:40:39 
2011        (r37134)
@@ -67,7 +67,6 @@
        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);
        //@}
 

Modified: lyx-devel/trunk/src/insets/InsetInfo.cpp
==============================================================================
--- lyx-devel/trunk/src/insets/InsetInfo.cpp    Thu Jan  6 19:36:03 2011        
(r37133)
+++ lyx-devel/trunk/src/insets/InsetInfo.cpp    Thu Jan  6 19:40:39 2011        
(r37134)
@@ -358,6 +358,10 @@
                        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 @@
        }
        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;

Reply via email to