Skip to content

Commit

Permalink
Automatically show Start page the very first time when activating the…
Browse files Browse the repository at this point in the history
… Start workbench
  • Loading branch information
wwmayer committed Sep 11, 2019
1 parent 5a542d3 commit f312878
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 54 deletions.
54 changes: 2 additions & 52 deletions src/Mod/Start/Gui/Command.cpp
Expand Up @@ -31,6 +31,7 @@
#include <Gui/Command.h>
#include <Gui/MainWindow.h>
#include <Gui/FileDialog.h>
#include "Workbench.h"


using namespace std;
Expand All @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions src/Mod/Start/Gui/Workbench.cpp
Expand Up @@ -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");
Expand Down
6 changes: 4 additions & 2 deletions src/Mod/Start/Gui/Workbench.h
Expand Up @@ -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;
Expand Down

0 comments on commit f312878

Please sign in to comment.