diff --git a/src/Mod/Start/Gui/Command.cpp b/src/Mod/Start/Gui/Command.cpp index b18eb526ff..1afe60377b 100644 --- a/src/Mod/Start/Gui/Command.cpp +++ b/src/Mod/Start/Gui/Command.cpp @@ -31,6 +31,7 @@ #include #include #include +#include "Workbench.h" using namespace std; @@ -49,64 +50,13 @@ CmdStartPage::CmdStartPage() sPixmap = "StartWorkbench"; } - void CmdStartPage::activated(int iMsg) { Q_UNUSED(iMsg); - - // Ensure that we don't open the Start page multiple times - QString title = QCoreApplication::translate("Workbench", "Start page"); - QList ch = Gui::getMainWindow()->windows(); - for (QList::const_iterator c = ch.begin(); c != ch.end(); ++c) { - if ((*c)->windowTitle() == title) - return; - } - - try { - QByteArray utf8Title = title.toUtf8(); - QByteArray cmd; - QTextStream str(&cmd); - str << "import WebGui" << endl; - str << "from StartPage import StartPage" << endl; - str << endl; - str << "class WebPage(object):" << endl; - str << " def __init__(self):" << endl; - str << " self.browser=WebGui.openBrowserWindow('" << utf8Title << "')" << endl; -#if defined(FC_OS_WIN32) - str << " self.browser.setHtml(StartPage.handle(), App.getResourceDir() + 'Mod/Start/StartPage/')" << endl; -#else - str << " self.browser.setHtml(StartPage.handle(), 'file://' + App.getResourceDir() + 'Mod/Start/StartPage/')" << endl; -#endif - str << " def onChange(self, par, reason):" << endl; - str << " if reason == 'RecentFiles':" << endl; -#if defined(FC_OS_WIN32) - str << " self.browser.setHtml(StartPage.handle(), App.getResourceDir() + 'Mod/Start/StartPage/')" << endl; -#else - str << " self.browser.setHtml(StartPage.handle(), 'file://' + App.getResourceDir() + 'Mod/Start/StartPage/')" << endl; -#endif - str << endl; - str << "class WebView(object):" << endl; - str << " def __init__(self):" << endl; - str << " self.pargrp = FreeCAD.ParamGet('User parameter:BaseApp/Preferences/RecentFiles')" << endl; - str << " self.webPage = WebPage()" << endl; - str << " self.pargrp.Attach(self.webPage)" << endl; - str << " def __del__(self):" << endl; - str << " self.pargrp.Detach(self.webPage)" << endl; - str << endl; - str << "webView=WebView()" << endl; - - //Base::Interpreter().runString(cmd); - // Gui::Command::runCommand(Gui::Command::Gui, cmd); - Command::doCommand(Command::Gui, "import Start, StartGui"); - Command::doCommand(Command::Gui, cmd); - } - catch (const Base::Exception& e) { - Base::Console().Error("%s\n", e.what()); - } + StartGui::Workbench::loadStartPage(); } - void CreateStartCommands(void) { Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); diff --git a/src/Mod/Start/Gui/Workbench.cpp b/src/Mod/Start/Gui/Workbench.cpp index 76ce96fade..2851329ce1 100644 --- a/src/Mod/Start/Gui/Workbench.cpp +++ b/src/Mod/Start/Gui/Workbench.cpp @@ -61,6 +61,16 @@ StartGui::Workbench::~Workbench() } void StartGui::Workbench::activated() +{ + // Automatically display the StartPage only the very first time + static bool first = true; + if (first) { + loadStartPage(); + first = false; + } +} + +void StartGui::Workbench::loadStartPage() { // Ensure that we don't open the Start page multiple times QString title = QCoreApplication::translate("Workbench", "Start page"); diff --git a/src/Mod/Start/Gui/Workbench.h b/src/Mod/Start/Gui/Workbench.h index 76752b7a70..082e77f238 100644 --- a/src/Mod/Start/Gui/Workbench.h +++ b/src/Mod/Start/Gui/Workbench.h @@ -36,14 +36,16 @@ class StartGuiExport Workbench : public Gui::StdWorkbench TYPESYSTEM_HEADER(); public: - Workbench(); - virtual ~Workbench(); + Workbench(); + virtual ~Workbench(); /** Defines the standard context menu. */ virtual void setupContextMenu(const char* recipient,Gui::MenuItem*) const; /** Run some actions when the workbench gets activated. */ virtual void activated(); + static void loadStartPage(); + protected: /** Defines the standard menus. */ virtual Gui::MenuItem* setupMenuBar() const;