Automatically create actions for each template
This commit is contained in:
parent
bbf5bbbcbc
commit
08bfdc4875
|
@ -701,10 +701,14 @@ void PythonConsole::runSource(const QString& line)
|
|||
catch (const Base::SystemExitException&) {
|
||||
ParameterGrp::handle hPrefGrp = getWindowParameter();
|
||||
bool check = hPrefGrp->GetBool("CheckSystemExit",true);
|
||||
if (!check) qApp->quit();
|
||||
int ret = QMessageBox::question(this, tr("System exit"), tr("The application is still running.\nDo you want to exit without saving your data?"),
|
||||
QMessageBox::Yes, QMessageBox::No|QMessageBox::Escape|QMessageBox::Default);
|
||||
int ret = QMessageBox::Yes;
|
||||
if (check) {
|
||||
ret = QMessageBox::question(this, tr("System exit"),
|
||||
tr("The application is still running.\nDo you want to exit without saving your data?"),
|
||||
QMessageBox::Yes, QMessageBox::No|QMessageBox::Escape|QMessageBox::Default);
|
||||
}
|
||||
if (ret == QMessageBox::Yes) {
|
||||
PyErr_Clear();
|
||||
qApp->quit();
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -12,7 +12,12 @@
|
|||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
# include <QCoreApplication>
|
||||
# include <QDir>
|
||||
# include <QFile>
|
||||
# include <QFileInfo>
|
||||
# include <QMessageBox>
|
||||
# include <QRegExp>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
|
@ -89,17 +94,16 @@ CmdDrawingNewPage::CmdDrawingNewPage()
|
|||
|
||||
void CmdDrawingNewPage::activated(int iMsg)
|
||||
{
|
||||
Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
|
||||
QAction* a = pcAction->actions()[iMsg];
|
||||
|
||||
std::string FeatName = getUniqueObjectName("Page");
|
||||
|
||||
std::stringstream out;
|
||||
out << App::Application::getResourceDir()
|
||||
<< "Mod/Drawing/Templates/"
|
||||
<< "A" << iMsg << "_Landscape.svg";
|
||||
Base::FileInfo tfi(out.str());
|
||||
QFileInfo tfi(a->property("Template").toString());
|
||||
if (tfi.isReadable()) {
|
||||
openCommand("Drawing create page");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Drawing::FeaturePage','%s')",FeatName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Template = '%s'",FeatName.c_str(), tfi.filePath().c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Template = '%s'",FeatName.c_str(), (const char*)tfi.filePath().toUtf8());
|
||||
commitCommand();
|
||||
}
|
||||
else {
|
||||
|
@ -115,25 +119,45 @@ Gui::Action * CmdDrawingNewPage::createAction(void)
|
|||
pcAction->setDropDownMenu(true);
|
||||
applyCommandData(pcAction);
|
||||
|
||||
QAction* a0 = pcAction->addAction(QString());
|
||||
a0->setIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape-A0"));
|
||||
QAction* defaultAction = 0;
|
||||
int defaultId = 0;
|
||||
|
||||
QAction* a1 = pcAction->addAction(QString());
|
||||
a1->setIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape-A1"));
|
||||
std::string path = App::Application::getResourceDir();
|
||||
path += "Mod/Drawing/Templates/";
|
||||
QDir dir(QString::fromUtf8(path.c_str()), QString::fromAscii("A*_Landscape.svg"));
|
||||
for (unsigned int i=0; i<dir.count(); i++ ) {
|
||||
QRegExp rx(QString::fromAscii("A(\\d)_Landscape.svg"));
|
||||
if (rx.indexIn(dir[i]) > -1) {
|
||||
int id = rx.cap(1).toInt();
|
||||
QFile file(QString::fromAscii(":/icons/actions/drawing-landscape-A0.svg"));
|
||||
QAction* a = pcAction->addAction(QString());
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
QString s = QString::fromAscii("style=\"font-size:22px\">A%1</tspan></text>").arg(id);
|
||||
QByteArray data = file.readAll();
|
||||
data.replace("style=\"font-size:22px\">A0</tspan></text>", s.toAscii());
|
||||
a->setIcon(Gui::BitmapFactory().pixmapFromSvg(data, QSize(24,24)));
|
||||
}
|
||||
|
||||
QAction* a2 = pcAction->addAction(QString());
|
||||
a2->setIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape-A2"));
|
||||
a->setProperty("TemplateId", id);
|
||||
a->setProperty("Template", dir.absoluteFilePath(dir[i]));
|
||||
|
||||
QAction* a3 = pcAction->addAction(QString());
|
||||
a3->setIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape-A3"));
|
||||
|
||||
QAction* a4 = pcAction->addAction(QString());
|
||||
a4->setIcon(Gui::BitmapFactory().pixmap("actions/drawing-landscape-A4"));
|
||||
if (id == 3) {
|
||||
defaultAction = a;
|
||||
defaultId = pcAction->actions().size() - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_pcAction = pcAction;
|
||||
languageChange();
|
||||
pcAction->setIcon(a3->icon());
|
||||
pcAction->setProperty("defaultAction", QVariant(3));
|
||||
if (defaultAction) {
|
||||
pcAction->setIcon(defaultAction->icon());
|
||||
pcAction->setProperty("defaultAction", QVariant(defaultId));
|
||||
}
|
||||
else if (!pcAction->actions().isEmpty()) {
|
||||
pcAction->setIcon(pcAction->actions()[0]->icon());
|
||||
pcAction->setProperty("defaultAction", QVariant(0));
|
||||
}
|
||||
|
||||
return pcAction;
|
||||
}
|
||||
|
@ -146,41 +170,15 @@ void CmdDrawingNewPage::languageChange()
|
|||
return;
|
||||
Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
|
||||
QList<QAction*> a = pcAction->actions();
|
||||
|
||||
a[0]->setText(QCoreApplication::translate(
|
||||
"Drawing_NewPage", "A0 landscape", 0,
|
||||
QCoreApplication::CodecForTr));
|
||||
a[0]->setToolTip(QCoreApplication::translate(
|
||||
"Drawing_NewPage", "Insert new A0 landscape drawing", 0,
|
||||
QCoreApplication::CodecForTr));
|
||||
|
||||
a[1]->setText(QCoreApplication::translate(
|
||||
"Drawing_NewPage", "A1 landscape", 0,
|
||||
QCoreApplication::CodecForTr));
|
||||
a[1]->setToolTip(QCoreApplication::translate(
|
||||
"Drawing_NewPage", "Insert new A1 landscape drawing", 0,
|
||||
QCoreApplication::CodecForTr));
|
||||
|
||||
a[2]->setText(QCoreApplication::translate(
|
||||
"Drawing_NewPage", "A2 landscape", 0,
|
||||
QCoreApplication::CodecForTr));
|
||||
a[2]->setToolTip(QCoreApplication::translate(
|
||||
"Drawing_NewPage", "Insert new A2 landscape drawing", 0,
|
||||
QCoreApplication::CodecForTr));
|
||||
|
||||
a[3]->setText(QCoreApplication::translate(
|
||||
"Drawing_NewPage", "A3 landscape", 0,
|
||||
QCoreApplication::CodecForTr));
|
||||
a[3]->setToolTip(QCoreApplication::translate(
|
||||
"Drawing_NewPage", "Insert new A3 landscape drawing", 0,
|
||||
QCoreApplication::CodecForTr));
|
||||
|
||||
a[4]->setText(QCoreApplication::translate(
|
||||
"Drawing_NewPage", "A4 landscape", 0,
|
||||
QCoreApplication::CodecForTr));
|
||||
a[4]->setToolTip(QCoreApplication::translate(
|
||||
"Drawing_NewPage", "Insert new A4 landscape drawing", 0,
|
||||
QCoreApplication::CodecForTr));
|
||||
for (QList<QAction*>::iterator it = a.begin(); it != a.end(); ++it) {
|
||||
int id = (*it)->property("TemplateId").toInt();
|
||||
(*it)->setText(QCoreApplication::translate(
|
||||
"Drawing_NewPage", "A%1 landscape", 0,
|
||||
QCoreApplication::CodecForTr).arg(id));
|
||||
(*it)->setToolTip(QCoreApplication::translate(
|
||||
"Drawing_NewPage", "Insert new A%1 landscape drawing", 0,
|
||||
QCoreApplication::CodecForTr).arg(id));
|
||||
}
|
||||
}
|
||||
|
||||
bool CmdDrawingNewPage::isActive(void)
|
||||
|
|
Binary file not shown.
|
@ -251,6 +251,14 @@
|
|||
<source>Insert new A4 landscape drawing</source>
|
||||
<translation>Neue A3-Zeichung einfügen (im Querformat) {4 ?}</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Insert new A%1 landscape drawing</source>
|
||||
<translation>Neue A%1-Zeichung im Querformat einfügen</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>A%1 landscape</source>
|
||||
<translation>A%1 im Querformat</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>QObject</name>
|
||||
|
|
Loading…
Reference in New Issue
Block a user