From ed300ea4b817c6b87f8aedf3547240eacc64c8e3 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 22 Jul 2012 02:09:37 +0200 Subject: [PATCH] CHANGED: #1471 Don't execute action handlers and/or Lua scripts in editor mode. Warning log message when trying to look up non-existent action handlers. --HG-- branch : gsoc2012-gui-editor --- code/nel/include/nel/gui/action_handler.h | 10 +++++++++- code/nel/include/nel/gui/lua_manager.h | 3 +++ code/nel/src/gui/action_handler.cpp | 8 ++++++++ code/nel/src/gui/lua_manager.cpp | 4 ++++ .../src/plugins/gui_editor/nelgui_widget.cpp | 5 +++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/code/nel/include/nel/gui/action_handler.h b/code/nel/include/nel/gui/action_handler.h index 830139777..8f90cb942 100644 --- a/code/nel/include/nel/gui/action_handler.h +++ b/code/nel/include/nel/gui/action_handler.h @@ -72,7 +72,13 @@ namespace NLGUI IActionHandler *getActionHandler(const std::string &name) const { TFactoryMap::const_iterator it = FactoryMap.find(name); - return it != FactoryMap.end() ? it->second : NULL; + if( it == FactoryMap.end() ) + { + nlwarning( "Couldn't find action handler %s", name.c_str() ); + return NULL; + } + else + return it->second; } /// Return the name of the action handler given its pointer @@ -110,10 +116,12 @@ namespace NLGUI // Submit a generic event void submitEvent( const std::string &evt ); + static void setEditorMode( bool b ){ editorMode = b; } private: CAHManager(){} static CAHManager *_GlobalInstance; + static bool editorMode; }; diff --git a/code/nel/include/nel/gui/lua_manager.h b/code/nel/include/nel/gui/lua_manager.h index 9044dfcd5..63d21b959 100644 --- a/code/nel/include/nel/gui/lua_manager.h +++ b/code/nel/include/nel/gui/lua_manager.h @@ -61,11 +61,14 @@ namespace NLGUI /// Forces the Garbage Collector to run. void forceGarbageCollect(); + static void setEditorMode( bool b ){ editorMode = b; } + private: CLuaManager(); static CLuaManager *instance; static bool debugLua; + static bool editorMode; NLGUI::CLuaState *luaState; }; diff --git a/code/nel/src/gui/action_handler.cpp b/code/nel/src/gui/action_handler.cpp index b25dbb0c5..201f5a0e4 100644 --- a/code/nel/src/gui/action_handler.cpp +++ b/code/nel/src/gui/action_handler.cpp @@ -30,6 +30,7 @@ namespace NLGUI // ------------------------------------------------------------------------------------------------ CAHManager *CAHManager::_GlobalInstance = NULL; + bool CAHManager::editorMode = false; // ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ @@ -210,6 +211,9 @@ namespace NLGUI { if (ahCmdLine.empty()) return; + if( editorMode ) + return; + // Special AH form ("ah:params") ? string::size_type i = ahCmdLine.find(':'); string ahName; @@ -259,6 +263,10 @@ namespace NLGUI nlwarning ("no action handler"); return; } + + if( editorMode ) + return; + pAH->execute (pCaller, Params); string AHName = CAHManager::getInstance()->getAHName(pAH); diff --git a/code/nel/src/gui/lua_manager.cpp b/code/nel/src/gui/lua_manager.cpp index 0ce8ce979..79787ef99 100644 --- a/code/nel/src/gui/lua_manager.cpp +++ b/code/nel/src/gui/lua_manager.cpp @@ -22,6 +22,7 @@ namespace NLGUI { bool CLuaManager::debugLua = false; + bool CLuaManager::editorMode = false; CLuaManager* CLuaManager::instance = NULL; CLuaManager::CLuaManager() @@ -37,6 +38,9 @@ namespace NLGUI bool CLuaManager::executeLuaScript( const std::string &luaScript, bool smallScript ) { + if( editorMode ) + return true; + try { if( smallScript ) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp index f58426cd3..f6f8d0e61 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp @@ -20,6 +20,8 @@ #include "nel/gui/view_renderer.h" #include "nel/gui/interface_group.h" #include "nel/gui/widget_manager.h" +#include "nel/gui/action_handler.h" +#include "nel/gui/lua_manager.h" #include "nel/misc/path.h" #include "nel/misc/i18n.h" #include @@ -58,6 +60,9 @@ namespace GUIEditor Nel3DWidget::init(); createTextContext( "Ryzom.ttf" ); + NLGUI::CAHManager::setEditorMode( true ); + NLGUI::CLuaManager::setEditorMode( true ); + NLGUI::CViewRenderer::setDriver( getDriver() ); NLGUI::CViewRenderer::setTextContext( getTextContext() ); NLGUI::CViewRenderer::hwCursors = &hwCursors;