Automatically show Start page the very first time when activating the Start workbench
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/FileDialog.h>
|
||||
#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<QWidget*> ch = Gui::getMainWindow()->windows();
|
||||
for (QList<QWidget*>::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();
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user