fixes #0002323: Workbench Start recent list of 3 files is - after a crash - not sync with recent list in File Menu Recent list of 4 files
This commit is contained in:
@@ -69,8 +69,6 @@ public:
|
||||
}
|
||||
virtual void OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::MessageType Reason)
|
||||
{
|
||||
if (!Reason || Reason[0] == '\0')
|
||||
return;
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
ParameterGrp& rGrp = static_cast<ParameterGrp&>(rCaller);
|
||||
@@ -78,7 +76,9 @@ public:
|
||||
Py::Callable method(this->inst.getAttr(std::string("onChange")));
|
||||
Py::Tuple args(2);
|
||||
args.setItem(0, Py::asObject(GetPyObject(hGrp)));
|
||||
args.setItem(1, Py::String(Reason));
|
||||
// A Reason of null indicates to clear the parameter group
|
||||
if (Reason && Reason[0] != '\0')
|
||||
args.setItem(1, Py::String(Reason));
|
||||
method.apply(args);
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
|
||||
@@ -773,7 +773,6 @@ void RecentFilesAction::save()
|
||||
->GetGroup("Preferences")->GetGroup("RecentFiles");
|
||||
int count = hGrp->GetInt("RecentFiles", this->visibleItems); // save number of files
|
||||
hGrp->Clear();
|
||||
hGrp->SetInt("RecentFiles", count); // restore
|
||||
|
||||
// count all set items
|
||||
QList<QAction*> recentFiles = _group->actions();
|
||||
@@ -785,6 +784,8 @@ void RecentFilesAction::save()
|
||||
break;
|
||||
hGrp->SetASCII(key.toLatin1(), value.toUtf8());
|
||||
}
|
||||
|
||||
hGrp->SetInt("RecentFiles", count); // restore
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <QCoreApplication>
|
||||
# include <QTextStream>
|
||||
#endif
|
||||
|
||||
#include "Workbench.h"
|
||||
@@ -69,15 +70,39 @@ void StartGui::Workbench::activated()
|
||||
|
||||
try {
|
||||
QByteArray utf8Title = title.toUtf8();
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"import WebGui");
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"from StartPage import StartPage");
|
||||
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)
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"WebGui.openBrowserHTML"
|
||||
"(StartPage.handle(),App.getResourceDir() + 'Mod/Start/StartPage/','%s')", utf8Title.data());
|
||||
str << " self.browser.setHtml(StartPage.handle(), App.getResourceDir() + 'Mod/Start/StartPage/')" << endl;
|
||||
#else
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"WebGui.openBrowserHTML"
|
||||
"(StartPage.handle(),'file://' + App.getResourceDir() + 'Mod/Start/StartPage/','%s')", utf8Title.data());
|
||||
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;
|
||||
|
||||
|
||||
Gui::Command::runCommand(Gui::Command::Gui, cmd);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
Base::Console().Error("%s\n", e.what());
|
||||
|
||||
@@ -60,6 +60,8 @@ public:
|
||||
);
|
||||
add_varargs_method("openBrowserHTML",&Module::openBrowserHTML
|
||||
);
|
||||
add_varargs_method("openBrowserWindow",&Module::openBrowserWindow
|
||||
);
|
||||
initialize("This module is the WebGui module."); // register with Python
|
||||
}
|
||||
|
||||
@@ -94,11 +96,27 @@ private:
|
||||
WebGui::BrowserView* pcBrowserView = 0;
|
||||
pcBrowserView = new WebGui::BrowserView(Gui::getMainWindow());
|
||||
pcBrowserView->resize(400, 300);
|
||||
pcBrowserView->setHtml(QString::fromUtf8(HtmlCode),QUrl(QString::fromLatin1(BaseUrl)),QString::fromUtf8(TabName));
|
||||
pcBrowserView->setHtml(QString::fromUtf8(HtmlCode),QUrl(QString::fromLatin1(BaseUrl)));
|
||||
pcBrowserView->setWindowTitle(QString::fromUtf8(TabName));
|
||||
Gui::getMainWindow()->addWindow(pcBrowserView);
|
||||
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
Py::Object openBrowserWindow(const Py::Tuple& args)
|
||||
{
|
||||
const char* TabName = "Browser";
|
||||
if (! PyArg_ParseTuple(args.ptr(), "|s",&TabName))
|
||||
throw Py::Exception();
|
||||
|
||||
WebGui::BrowserView* pcBrowserView = 0;
|
||||
pcBrowserView = new WebGui::BrowserView(Gui::getMainWindow());
|
||||
pcBrowserView->resize(400, 300);
|
||||
pcBrowserView->setWindowTitle(QString::fromUtf8(TabName));
|
||||
Gui::getMainWindow()->addWindow(pcBrowserView);
|
||||
|
||||
return Py::asObject(pcBrowserView->getPyObject());
|
||||
}
|
||||
};
|
||||
|
||||
PyObject* initModule()
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
# include <QMenu>
|
||||
# include <QDesktopWidget>
|
||||
# include <QSignalMapper>
|
||||
# include <QPointer>
|
||||
#endif
|
||||
|
||||
#include "BrowserView.h"
|
||||
@@ -64,10 +65,68 @@
|
||||
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <CXX/Extensions.hxx>
|
||||
|
||||
using namespace WebGui;
|
||||
using namespace Gui;
|
||||
|
||||
namespace WebGui {
|
||||
class BrowserViewPy : public Py::PythonExtension<BrowserViewPy>
|
||||
{
|
||||
public:
|
||||
static void init_type(void); // announce properties and methods
|
||||
|
||||
BrowserViewPy(BrowserView* view);
|
||||
~BrowserViewPy();
|
||||
|
||||
Py::Object repr();
|
||||
|
||||
Py::Object setHtml(const Py::Tuple&);
|
||||
|
||||
private:
|
||||
QPointer<BrowserView> myWebView;
|
||||
};
|
||||
|
||||
void BrowserViewPy::init_type()
|
||||
{
|
||||
behaviors().name("BrowserView");
|
||||
behaviors().doc("Python interface class to BrowserView");
|
||||
// you must have overwritten the virtual functions
|
||||
behaviors().supportRepr();
|
||||
behaviors().supportGetattr();
|
||||
behaviors().supportSetattr();
|
||||
behaviors().readyType();
|
||||
|
||||
add_varargs_method("setHtml",&BrowserViewPy::setHtml,"setHtml(str)");
|
||||
}
|
||||
|
||||
BrowserViewPy::BrowserViewPy(BrowserView* view) : myWebView(view)
|
||||
{
|
||||
}
|
||||
|
||||
BrowserViewPy::~BrowserViewPy()
|
||||
{
|
||||
}
|
||||
|
||||
Py::Object BrowserViewPy::repr()
|
||||
{
|
||||
std::stringstream s;
|
||||
s << "<BrowserView at " << this << ">";
|
||||
return Py::String(s.str());
|
||||
}
|
||||
|
||||
Py::Object BrowserViewPy::setHtml(const Py::Tuple& args)
|
||||
{
|
||||
char* HtmlCode;
|
||||
char* BaseUrl;
|
||||
if (! PyArg_ParseTuple(args.ptr(), "ss",&HtmlCode,&BaseUrl))
|
||||
throw Py::Exception();
|
||||
if (myWebView)
|
||||
myWebView->setHtml(QString::fromUtf8(HtmlCode),QUrl(QString::fromLatin1(BaseUrl)));
|
||||
return Py::None();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a WebView widget which can be zoomed with Ctrl+Mousewheel
|
||||
*
|
||||
@@ -302,13 +361,12 @@ void BrowserView::load(const QUrl & url)
|
||||
setWindowIcon(QWebSettings::iconForUrl(url));
|
||||
}
|
||||
|
||||
void BrowserView::setHtml(const QString& HtmlCode,const QUrl & BaseUrl,const QString& TabName)
|
||||
void BrowserView::setHtml(const QString& HtmlCode,const QUrl & BaseUrl)
|
||||
{
|
||||
if (isLoading)
|
||||
stop();
|
||||
|
||||
view->setHtml(HtmlCode,BaseUrl);
|
||||
setWindowTitle(TabName);
|
||||
setWindowIcon(QWebSettings::iconForUrl(BaseUrl));
|
||||
}
|
||||
|
||||
@@ -416,5 +474,16 @@ bool BrowserView::canClose(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
PyObject* BrowserView::getPyObject(void)
|
||||
{
|
||||
static bool init = false;
|
||||
if (!init) {
|
||||
init = true;
|
||||
BrowserViewPy::init_type();
|
||||
}
|
||||
|
||||
return new BrowserViewPy(this);
|
||||
}
|
||||
|
||||
#include "moc_BrowserView.cpp"
|
||||
|
||||
|
||||
@@ -63,7 +63,8 @@ Q_SIGNALS:
|
||||
* A special view class which sends the messages from the application to
|
||||
* the editor and embeds it in a window.
|
||||
*/
|
||||
class WebGuiExport BrowserView : public Gui::MDIView, public Gui::WindowParameter
|
||||
class WebGuiExport BrowserView : public Gui::MDIView,
|
||||
public Gui::WindowParameter
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -73,34 +74,19 @@ public:
|
||||
|
||||
void load(const char* URL);
|
||||
void load(const QUrl & url);
|
||||
void setHtml(const QString& HtmlCode,const QUrl & BaseUrl,const QString& TabName=QString::fromLatin1("Browser"));
|
||||
void setHtml(const QString& HtmlCode,const QUrl & BaseUrl);
|
||||
void stop(void);
|
||||
|
||||
void OnChange(Base::Subject<const char*> &rCaller,const char* rcReason);
|
||||
|
||||
const char *getName(void) const {return "BrowserView";}
|
||||
void onUpdate(void){};
|
||||
virtual PyObject *getPyObject(void);
|
||||
|
||||
bool onMsg(const char* pMsg,const char** ppReturn);
|
||||
bool onHasMsg(const char* pMsg) const;
|
||||
|
||||
bool canClose(void);
|
||||
|
||||
/** @name Standard actions of the editor */
|
||||
//@{
|
||||
//bool open (const QString &f);
|
||||
//bool saveAs ();
|
||||
//void cut ();
|
||||
//void copy ();
|
||||
//void paste ();
|
||||
//void undo ();
|
||||
//void redo ();
|
||||
//void run ();
|
||||
//void print ();
|
||||
//void printPdf();
|
||||
//@}
|
||||
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onLoadStarted();
|
||||
void onLoadProgress(int);
|
||||
|
||||
Reference in New Issue
Block a user