1
// SPDX-License-Identifier: LGPL-2.1-or-later
3
/****************************************************************************
4
* Copyright (c) 2002 Jürgen Riegel <juergen.riegel@web.de> *
5
* Copyright (c) 2023 FreeCAD Project Association *
7
* This file is part of FreeCAD. *
9
* FreeCAD is free software: you can redistribute it and/or modify it *
10
* under the terms of the GNU Lesser General Public License as *
11
* published by the Free Software Foundation, either version 2.1 of the *
12
* License, or (at your option) any later version. *
14
* FreeCAD is distributed in the hope that it will be useful, but *
15
* WITHOUT ANY WARRANTY; without even the implied warranty of *
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
17
* Lesser General Public License for more details. *
19
* You should have received a copy of the GNU Lesser General Public *
20
* License along with FreeCAD. If not, see *
21
* <https://www.gnu.org/licenses/>. *
23
***************************************************************************/
25
#include "PreCompiled.h"
27
# include <QApplication>
28
# include <QMessageBox>
29
# include <QRegularExpression>
30
# include <QRegularExpressionMatch>
34
#include <App/Document.h>
35
#include <Base/Exception.h>
36
#include <Base/Interpreter.h>
37
#include <Base/Sequencer.h>
40
#include "BitmapFactory.h"
42
#include "DlgCustomizeImp.h"
43
#include "DlgParameterImp.h"
44
#include "DlgPreferencesImp.h"
45
#include "DlgUnitsCalculatorImp.h"
46
#include "GuiConsole.h"
47
#include "MainWindow.h"
48
#include "OnlineDocumentation.h"
50
#include "Splashscreen.h"
53
#include "WorkbenchManager.h"
59
namespace sp = std::placeholders;
62
//===========================================================================
64
//===========================================================================
66
DEF_STD_CMD_AC(StdCmdWorkbench)
68
StdCmdWorkbench::StdCmdWorkbench()
69
: Command("Std_Workbench")
72
sMenuText = QT_TR_NOOP("Workbench");
73
sToolTipText = QT_TR_NOOP("Switch between workbenches");
74
sWhatsThis = "Std_Workbench";
75
sStatusTip = QT_TR_NOOP("Switch between workbenches");
80
void StdCmdWorkbench::activated(int i)
83
Workbench* w = WorkbenchManager::instance()->active();
84
QList<QAction*> items = static_cast<WorkbenchGroup*>(_pcAction)->actions();
85
std::string switch_to = (const char*)items[i]->objectName().toLatin1();
87
std::string current_w = w->name();
88
if (switch_to == current_w)
91
doCommand(Gui, "Gui.activateWorkbench(\"%s\")", switch_to.c_str());
93
catch(const Base::PyException& e) {
94
QString msg(QLatin1String(e.what()));
95
// ignore '<type 'exceptions.*Error'>' prefixes
96
QRegularExpression rx;
97
rx.setPattern(QLatin1String(R"(^\s*<type 'exceptions.\w*'>:\s*)"));
98
auto match = rx.match(msg);
100
msg = msg.mid(match.capturedLength());
101
QMessageBox::critical(getMainWindow(), QObject::tr("Cannot load workbench"), msg);
104
QMessageBox::critical(getMainWindow(), QObject::tr("Cannot load workbench"),
105
QObject::tr("A general error occurred while loading the workbench"));
109
bool StdCmdWorkbench::isActive()
114
Action * StdCmdWorkbench::createAction()
118
pcAction = new WorkbenchGroup(this,getMainWindow());
119
pcAction->setShortcut(QString::fromLatin1(getAccel()));
120
applyCommandData(this->className(), pcAction);
122
pcAction->setIcon(Gui::BitmapFactory().iconFromTheme(getPixmap()));
127
//===========================================================================
129
//===========================================================================
131
DEF_STD_CMD_C(StdCmdRecentFiles)
133
StdCmdRecentFiles::StdCmdRecentFiles()
134
:Command("Std_RecentFiles")
137
sMenuText = QT_TR_NOOP("Open Recent");
138
sToolTipText = QT_TR_NOOP("Recent file list");
139
sWhatsThis = "Std_RecentFiles";
140
sStatusTip = QT_TR_NOOP("Recent file list");
141
sPixmap = "Std_RecentFiles";
142
eType = NoTransaction;
146
* Opens the recent file at position \a iMsg in the menu.
147
* If the file does not exist or cannot be loaded this item is removed
150
void StdCmdRecentFiles::activated(int iMsg)
152
auto act = qobject_cast<RecentFilesAction*>(_pcAction);
153
if (act) act->activateFile( iMsg );
157
* Creates the QAction object containing the recent files.
159
Action * StdCmdRecentFiles::createAction()
161
auto pcAction = new RecentFilesAction(this, getMainWindow());
162
pcAction->setObjectName(QLatin1String("recentFiles"));
163
pcAction->setDropDownMenu(true);
164
applyCommandData(this->className(), pcAction);
168
//===========================================================================
170
//===========================================================================
172
DEF_STD_CMD_C(StdCmdRecentMacros)
174
StdCmdRecentMacros::StdCmdRecentMacros()
175
:Command("Std_RecentMacros")
178
sMenuText = QT_TR_NOOP("Recent macros");
179
sToolTipText = QT_TR_NOOP("Recent macro list");
180
sWhatsThis = "Std_RecentMacros";
181
sStatusTip = QT_TR_NOOP("Recent macro list");
182
sPixmap = "Std_RecentMacros";
183
eType = NoTransaction;
187
* Opens the recent macro at position \a iMsg in the menu.
188
* If the macro does not exist or cannot be loaded this item is removed
191
void StdCmdRecentMacros::activated(int iMsg)
193
auto act = qobject_cast<RecentMacrosAction*>(_pcAction);
194
if (act) act->activateFile( iMsg );
198
* Creates the QAction object containing the recent macros.
200
Action * StdCmdRecentMacros::createAction()
202
auto pcAction = new RecentMacrosAction(this, getMainWindow());
203
pcAction->setObjectName(QLatin1String("recentMacros"));
204
pcAction->setDropDownMenu(true);
205
applyCommandData(this->className(), pcAction);
209
//===========================================================================
211
//===========================================================================
213
DEF_STD_CMD_ACL(StdCmdAbout)
215
StdCmdAbout::StdCmdAbout()
216
:Command("Std_About")
219
sMenuText = QT_TR_NOOP("&About %1");
220
sToolTipText = QT_TR_NOOP("About %1");
221
sWhatsThis = "Std_About";
222
sStatusTip = QT_TR_NOOP("About %1");
226
Action * StdCmdAbout::createAction()
230
QString exe = qApp->applicationName();
231
pcAction = new Action(this, getMainWindow());
232
pcAction->setText(QCoreApplication::translate(
233
this->className(), getMenuText()).arg(exe));
234
pcAction->setToolTip(QCoreApplication::translate(
235
this->className(), getToolTipText()).arg(exe));
236
pcAction->setStatusTip(QCoreApplication::translate(
237
this->className(), getStatusTip()).arg(exe));
238
pcAction->setWhatsThis(QLatin1String(getWhatsThis()));
239
pcAction->setIcon(QApplication::windowIcon());
240
pcAction->setShortcut(QString::fromLatin1(getAccel()));
241
// Needs to have AboutRole set to avoid duplicates if adding the about action more than once on macOS
242
pcAction->setMenuRole(QAction::AboutRole);
246
bool StdCmdAbout::isActive()
252
* Shows information about the application.
254
void StdCmdAbout::activated(int iMsg)
257
const Gui::Dialog::AboutDialogFactory* f = Gui::Dialog::AboutDialogFactory::defaultFactory();
258
boost::scoped_ptr<QDialog> dlg(f->create(getMainWindow()));
262
void StdCmdAbout::languageChange()
265
QString exe = qApp->applicationName();
266
_pcAction->setText(QCoreApplication::translate(
267
this->className(), getMenuText()).arg(exe));
268
_pcAction->setToolTip(QCoreApplication::translate(
269
this->className(), getToolTipText()).arg(exe));
270
_pcAction->setStatusTip(QCoreApplication::translate(
271
this->className(), getStatusTip()).arg(exe));
272
_pcAction->setWhatsThis(QLatin1String(getWhatsThis()));
276
//===========================================================================
278
//===========================================================================
279
DEF_STD_CMD(StdCmdAboutQt)
281
StdCmdAboutQt::StdCmdAboutQt()
282
:Command("Std_AboutQt")
285
sMenuText = QT_TR_NOOP("About &Qt");
286
sToolTipText = QT_TR_NOOP("About Qt");
287
sWhatsThis = "Std_AboutQt";
288
sStatusTip = QT_TR_NOOP("About Qt");
292
void StdCmdAboutQt::activated(int iMsg)
298
//===========================================================================
300
//===========================================================================
301
DEF_STD_CMD(StdCmdWhatsThis)
303
StdCmdWhatsThis::StdCmdWhatsThis()
304
:Command("Std_WhatsThis")
307
sMenuText = QT_TR_NOOP("&What's This?");
308
sToolTipText = QT_TR_NOOP("What's This");
309
sWhatsThis = "Std_WhatsThis";
310
sStatusTip = QT_TR_NOOP("What's This");
311
sAccel = keySequenceToAccel(QKeySequence::WhatsThis);
312
sPixmap = "WhatsThis";
316
void StdCmdWhatsThis::activated(int iMsg)
319
QWhatsThis::enterWhatsThisMode();
322
//===========================================================================
324
//===========================================================================
325
DEF_STD_CMD(StdCmdDlgParameter)
327
StdCmdDlgParameter::StdCmdDlgParameter()
328
:Command("Std_DlgParameter")
331
sMenuText = QT_TR_NOOP("E&dit parameters ...");
332
sToolTipText = QT_TR_NOOP("Opens a Dialog to edit the parameters");
333
sWhatsThis = "Std_DlgParameter";
334
sStatusTip = QT_TR_NOOP("Opens a Dialog to edit the parameters");
335
sPixmap = "Std_DlgParameter";
339
void StdCmdDlgParameter::activated(int iMsg)
342
Gui::Dialog::DlgParameterImp cDlg(getMainWindow());
343
cDlg.resize(QSize(800, 600));
347
//===========================================================================
349
//===========================================================================
350
DEF_STD_CMD_C(StdCmdDlgPreferences)
352
StdCmdDlgPreferences::StdCmdDlgPreferences()
353
:Command("Std_DlgPreferences")
356
sMenuText = QT_TR_NOOP("&Preferences ...");
357
sToolTipText = QT_TR_NOOP("Opens a Dialog to edit the preferences");
358
sWhatsThis = "Std_DlgPreferences";
359
sStatusTip = QT_TR_NOOP("Opens a Dialog to edit the preferences");
360
sPixmap = "preferences-system";
364
Action * StdCmdDlgPreferences::createAction()
366
Action *pcAction = Command::createAction();
367
pcAction->setMenuRole(QAction::PreferencesRole);
372
void StdCmdDlgPreferences::activated(int iMsg)
376
static QString groupName{};
379
Gui::Dialog::DlgPreferencesImp cDlg(getMainWindow());
380
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences");
381
if (hGrp->GetBool("RestoreGroupPage", true)) {
382
cDlg.activateGroupPage(groupName, index);
386
cDlg.activeGroupPage(groupName, index);
390
//===========================================================================
392
//===========================================================================
393
DEF_STD_CMD(StdCmdDlgCustomize)
395
StdCmdDlgCustomize::StdCmdDlgCustomize()
396
:Command("Std_DlgCustomize")
399
sMenuText = QT_TR_NOOP("Cu&stomize...");
400
sToolTipText = QT_TR_NOOP("Customize toolbars and command bars");
401
sWhatsThis = "Std_DlgCustomize";
402
sStatusTip = QT_TR_NOOP("Customize toolbars and command bars");
403
sPixmap = "applications-accessories";
407
void StdCmdDlgCustomize::activated(int iMsg)
410
static QPointer<QDialog> dlg = nullptr;
412
dlg = new Gui::Dialog::DlgCustomizeImp(getMainWindow());
413
dlg->setAttribute(Qt::WA_DeleteOnClose);
417
//===========================================================================
419
//===========================================================================
420
DEF_STD_CMD(StdCmdCommandLine)
422
StdCmdCommandLine::StdCmdCommandLine()
423
:Command("Std_CommandLine")
426
sMenuText = QT_TR_NOOP("Start command &line...");
427
sToolTipText = QT_TR_NOOP("Opens the command line in the console");
428
sWhatsThis = "Std_CommandLine";
429
sStatusTip = QT_TR_NOOP("Opens the command line in the console");
430
sPixmap = "utilities-terminal";
434
void StdCmdCommandLine::activated(int iMsg)
437
bool show = getMainWindow()->isMaximized ();
439
// pop up the Gui command window
442
getMainWindow()->showMinimized () ;
443
qApp->processEvents();
445
// create temporary console sequencer
447
Base::ConsoleSequencer seq;
448
Base::Interpreter().runCommandLine("Console mode");
452
// On X11 this may not work. For further information see QWidget::showMaximized
454
// workaround for X11
455
getMainWindow()->hide();
456
getMainWindow()->show();
459
// pop up the main window
460
show ? getMainWindow()->showMaximized () : getMainWindow()->showNormal () ;
461
qApp->processEvents();
464
//===========================================================================
466
//===========================================================================
468
DEF_STD_CMD(StdCmdOnlineHelp)
470
StdCmdOnlineHelp::StdCmdOnlineHelp()
471
:Command("Std_OnlineHelp")
474
sMenuText = QT_TR_NOOP("Help");
475
sToolTipText = QT_TR_NOOP("Show help to the application");
476
sWhatsThis = "Std_OnlineHelp";
477
sStatusTip = QT_TR_NOOP("Help");
478
sPixmap = "help-browser";
479
sAccel = keySequenceToAccel(QKeySequence::HelpContents);
483
void StdCmdOnlineHelp::activated(int iMsg)
486
Gui::getMainWindow()->showDocumentation(QString::fromLatin1("Online_Help_Startpage"));
489
//===========================================================================
490
// Std_OnlineHelpWebsite
491
//===========================================================================
493
DEF_STD_CMD(StdCmdOnlineHelpWebsite)
495
StdCmdOnlineHelpWebsite::StdCmdOnlineHelpWebsite()
496
:Command("Std_OnlineHelpWebsite")
499
sMenuText = QT_TR_NOOP("Help Website");
500
sToolTipText = QT_TR_NOOP("The website where the help is maintained");
501
sWhatsThis = "Std_OnlineHelpWebsite";
502
sStatusTip = QT_TR_NOOP("Help Website");
506
void StdCmdOnlineHelpWebsite::activated(int iMsg)
509
std::string defaulturl = QCoreApplication::translate(this->className(),"https://wiki.freecad.org/Online_Help_Toc").toStdString();
510
ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
511
std::string url = hURLGrp->GetASCII("OnlineHelp", defaulturl.c_str());
512
hURLGrp->SetASCII("OnlineHelp", url.c_str());
513
OpenURLInBrowser(url.c_str());
516
//===========================================================================
517
// Std_FreeCADDonation
518
//===========================================================================
520
DEF_STD_CMD(StdCmdFreeCADDonation)
522
StdCmdFreeCADDonation::StdCmdFreeCADDonation()
523
:Command("Std_FreeCADDonation")
526
sMenuText = QT_TR_NOOP("Donate");
527
sToolTipText = QT_TR_NOOP("Donate to FreeCAD development");
528
sWhatsThis = "Std_FreeCADDonation";
529
sStatusTip = sToolTipText;
530
sPixmap = "internet-web-browser";
534
void StdCmdFreeCADDonation::activated(int iMsg)
537
ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
538
std::string url = hURLGrp->GetASCII("DonatePage", "https://wiki.freecad.org/Donate");
539
hURLGrp->SetASCII("DonatePage", url.c_str());
540
OpenURLInBrowser(url.c_str());
543
//===========================================================================
545
//===========================================================================
547
DEF_STD_CMD(StdCmdFreeCADWebsite)
549
StdCmdFreeCADWebsite::StdCmdFreeCADWebsite()
550
:Command("Std_FreeCADWebsite")
553
sMenuText = QT_TR_NOOP("FreeCAD Website");
554
sToolTipText = QT_TR_NOOP("The FreeCAD website");
555
sWhatsThis = "Std_FreeCADWebsite";
556
sStatusTip = QT_TR_NOOP("FreeCAD Website");
557
sPixmap = "internet-web-browser";
561
void StdCmdFreeCADWebsite::activated(int iMsg)
564
std::string defaulturl = QCoreApplication::translate(this->className(),"https://www.freecad.org").toStdString();
565
ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
566
std::string url = hURLGrp->GetASCII("WebPage", defaulturl.c_str());
567
hURLGrp->SetASCII("WebPage", url.c_str());
568
OpenURLInBrowser(url.c_str());
571
//===========================================================================
573
//===========================================================================
575
DEF_STD_CMD(StdCmdFreeCADUserHub)
577
StdCmdFreeCADUserHub::StdCmdFreeCADUserHub()
578
:Command("Std_FreeCADUserHub")
581
sMenuText = QT_TR_NOOP("Users documentation");
582
sToolTipText = QT_TR_NOOP("Documentation for users on the FreeCAD website");
583
sWhatsThis = "Std_FreeCADUserHub";
584
sStatusTip = QT_TR_NOOP("Users documentation");
585
sPixmap = "internet-web-browser";
589
void StdCmdFreeCADUserHub::activated(int iMsg)
592
std::string defaulturl = QCoreApplication::translate(this->className(),"https://wiki.freecad.org/User_hub").toStdString();
593
ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
594
std::string url = hURLGrp->GetASCII("Documentation", defaulturl.c_str());
595
hURLGrp->SetASCII("Documentation", url.c_str());
596
OpenURLInBrowser(url.c_str());
599
//===========================================================================
600
// Std_FreeCADPowerUserHub
601
//===========================================================================
603
DEF_STD_CMD(StdCmdFreeCADPowerUserHub)
605
StdCmdFreeCADPowerUserHub::StdCmdFreeCADPowerUserHub()
606
:Command("Std_FreeCADPowerUserHub")
609
sMenuText = QT_TR_NOOP("Python scripting documentation");
610
sToolTipText = QT_TR_NOOP("Python scripting documentation on the FreeCAD website");
611
sWhatsThis = "Std_FreeCADPowerUserHub";
612
sStatusTip = QT_TR_NOOP("PowerUsers documentation");
613
sPixmap = "internet-web-browser";
617
void StdCmdFreeCADPowerUserHub::activated(int iMsg)
620
std::string defaulturl = QCoreApplication::translate(this->className(),"https://wiki.freecad.org/Power_users_hub").toStdString();
621
ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
622
std::string url = hURLGrp->GetASCII("PowerUsers", defaulturl.c_str());
623
hURLGrp->SetASCII("PowerUsers", url.c_str());
624
OpenURLInBrowser(url.c_str());
627
//===========================================================================
629
//===========================================================================
631
DEF_STD_CMD(StdCmdFreeCADForum)
633
StdCmdFreeCADForum::StdCmdFreeCADForum()
634
:Command("Std_FreeCADForum")
637
sMenuText = QT_TR_NOOP("FreeCAD Forum");
638
sToolTipText = QT_TR_NOOP("The FreeCAD forum, where you can find help from other users");
639
sWhatsThis = "Std_FreeCADForum";
640
sStatusTip = QT_TR_NOOP("The FreeCAD Forum");
641
sPixmap = "internet-web-browser";
645
void StdCmdFreeCADForum::activated(int iMsg)
648
std::string defaulturl = QCoreApplication::translate(this->className(),"https://forum.freecad.org").toStdString();
649
ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
650
std::string url = hURLGrp->GetASCII("UserForum", defaulturl.c_str());
651
hURLGrp->SetASCII("UserForum", url.c_str());
652
OpenURLInBrowser(url.c_str());
655
//===========================================================================
657
//===========================================================================
659
DEF_STD_CMD(StdCmdFreeCADFAQ)
661
StdCmdFreeCADFAQ::StdCmdFreeCADFAQ()
662
:Command("Std_FreeCADFAQ")
665
sMenuText = QT_TR_NOOP("FreeCAD FAQ");
666
sToolTipText = QT_TR_NOOP("Frequently Asked Questions on the FreeCAD website");
667
sWhatsThis = "Std_FreeCADFAQ";
668
sStatusTip = QT_TR_NOOP("Frequently Asked Questions");
669
sPixmap = "internet-web-browser";
673
void StdCmdFreeCADFAQ::activated(int iMsg)
676
std::string defaulturl = QCoreApplication::translate(this->className(),"https://wiki.freecad.org/Frequently_asked_questions").toStdString();
677
ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
678
std::string url = hURLGrp->GetASCII("FAQ", defaulturl.c_str());
679
hURLGrp->SetASCII("FAQ", url.c_str());
680
OpenURLInBrowser(url.c_str());
683
//===========================================================================
685
//===========================================================================
687
DEF_STD_CMD(StdCmdPythonWebsite)
689
StdCmdPythonWebsite::StdCmdPythonWebsite()
690
:Command("Std_PythonWebsite")
693
sMenuText = QT_TR_NOOP("Python Website");
694
sToolTipText = QT_TR_NOOP("The official Python website");
695
sWhatsThis = "Std_PythonWebsite";
696
sStatusTip = QT_TR_NOOP("Python Website");
697
sPixmap = "applications-python";
701
void StdCmdPythonWebsite::activated(int iMsg)
704
OpenURLInBrowser("https://www.python.org");
708
//===========================================================================
710
//===========================================================================
712
DEF_STD_CMD(StdCmdReportBug)
714
StdCmdReportBug::StdCmdReportBug()
715
:Command("Std_ReportBug")
718
sMenuText = QT_TR_NOOP("Report a bug");
719
sToolTipText = QT_TR_NOOP("Report a bug or suggest a feature");
720
sWhatsThis = "Std_ReportBug";
721
sStatusTip = QT_TR_NOOP("Report a bug or suggest a feature");
722
sPixmap = "internet-web-browser";
726
void StdCmdReportBug::activated(int iMsg)
729
ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Websites");
730
std::string url = hURLGrp->GetASCII("IssuesPage", "https://github.com/FreeCAD/FreeCAD/issues");
731
hURLGrp->SetASCII("IssuesPage", url.c_str());
732
OpenURLInBrowser(url.c_str());
735
//===========================================================================
737
//===========================================================================
739
DEF_STD_CMD_A(StdCmdTextDocument)
741
StdCmdTextDocument::StdCmdTextDocument()
742
:Command("Std_TextDocument")
745
sMenuText = QT_TR_NOOP("Add text document");
746
sToolTipText = QT_TR_NOOP("Add text document to active document");
747
sWhatsThis = "Std_TextDocument";
748
sStatusTip = QT_TR_NOOP("Add text document to active document");
749
sPixmap = "TextDocument";
753
void StdCmdTextDocument::activated(int iMsg)
757
openCommand(QT_TRANSLATE_NOOP("Command", "Insert text document"));
758
doCommand(Doc, "App.ActiveDocument.addObject(\"App::TextDocument\",\"%s\").Label=\"%s\"","Text document","Text document");
759
doCommand(Gui, "Gui.ActiveDocument.ActiveObject.doubleClicked()");
764
bool StdCmdTextDocument::isActive()
766
return hasActiveDocument();
769
//===========================================================================
770
// Std_UnitsCalculator
771
//===========================================================================
772
DEF_STD_CMD(StdCmdUnitsCalculator)
774
StdCmdUnitsCalculator::StdCmdUnitsCalculator()
775
: Command("Std_UnitsCalculator")
778
sMenuText = QT_TR_NOOP("&Units converter...");
779
sToolTipText = QT_TR_NOOP("Start the units converter");
780
sWhatsThis = "Std_UnitsCalculator";
781
sStatusTip = QT_TR_NOOP("Start the units converter");
782
sPixmap = "accessories-calculator";
786
void StdCmdUnitsCalculator::activated(int iMsg)
789
auto dlg = new Gui::Dialog::DlgUnitsCalculator( getMainWindow() );
793
//===========================================================================
795
//===========================================================================
796
class StdCmdUserEditMode : public Gui::Command
799
StdCmdUserEditMode();
800
~StdCmdUserEditMode() override = default;
801
void languageChange() override;
802
const char* className() const override {return "StdCmdUserEditMode";}
803
void updateIcon(int mode);
805
void activated(int iMsg) override;
806
bool isActive() override;
807
Gui::Action * createAction() override;
810
StdCmdUserEditMode::StdCmdUserEditMode()
811
: Command("Std_UserEditMode")
814
sMenuText = QT_TR_NOOP("Edit mode");
815
sToolTipText = QT_TR_NOOP("Defines behavior when editing an object from tree");
816
sStatusTip = QT_TR_NOOP("Defines behavior when editing an object from tree");
817
sWhatsThis = "Std_UserEditMode";
818
sPixmap = "Std_UserEditModeDefault";
821
this->getGuiApplication()->signalUserEditModeChanged.connect([this](int mode) {
822
this->updateIcon(mode);
826
Gui::Action * StdCmdUserEditMode::createAction()
828
auto pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
829
pcAction->setDropDownMenu(true);
830
pcAction->setIsMode(true);
831
applyCommandData(this->className(), pcAction);
833
for (auto const &uem : Gui::Application::Instance->listUserEditModes()) {
834
QAction* act = pcAction->addAction(QString());
835
auto modeName = QString::fromStdString(uem.second.first);
836
act->setCheckable(true);
837
act->setIcon(BitmapFactory().iconFromTheme(qPrintable(QString::fromLatin1("Std_UserEditMode")+modeName)));
838
act->setObjectName(QString::fromLatin1("Std_UserEditMode")+modeName);
839
act->setWhatsThis(QString::fromLatin1(getWhatsThis()));
840
act->setToolTip(QString::fromStdString(uem.second.second));
842
if (uem.first == 0) {
843
pcAction->setIcon(act->icon());
844
act->setChecked(true);
848
_pcAction = pcAction;
850
int lastMode = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")->
851
GetInt("UserEditMode", 0);
852
Gui::Application::Instance->setUserEditMode(lastMode);
858
void StdCmdUserEditMode::languageChange()
860
Command::languageChange();
864
auto pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
865
QList<QAction*> a = pcAction->actions();
867
for (int i = 0 ; i < a.count() ; i++) {
868
auto modeName = Gui::Application::Instance->getUserEditModeUIStrings(i);
869
a[i]->setText(QCoreApplication::translate(
870
"EditMode", modeName.first.c_str()));
871
a[i]->setToolTip(QCoreApplication::translate(
872
"EditMode", modeName.second.c_str()));
876
void StdCmdUserEditMode::updateIcon(int mode)
878
auto actionGroup = dynamic_cast<Gui::ActionGroup *>(_pcAction);
882
actionGroup->setCheckedAction(mode);
885
void StdCmdUserEditMode::activated(int iMsg)
887
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")->
888
SetInt("UserEditMode", iMsg);
889
Gui::Application::Instance->setUserEditMode(iMsg);
892
bool StdCmdUserEditMode::isActive()
897
//===========================================================================
898
// Std_ReloadStylesheet
899
//===========================================================================
900
DEF_STD_CMD(StdCmdReloadStyleSheet)
902
StdCmdReloadStyleSheet::StdCmdReloadStyleSheet()
903
: Command("Std_ReloadStyleSheet")
906
sMenuText = QT_TR_NOOP("&Reload stylesheet");
907
sToolTipText = QT_TR_NOOP("Reloads the current stylesheet");
908
sWhatsThis = "Std_ReloadStyleSheet";
909
sStatusTip = QT_TR_NOOP("Reloads the current stylesheet");
910
sPixmap = "view-refresh";
911
sWhatsThis = "Std_ReloadStyleSheet";
914
void StdCmdReloadStyleSheet::activated(int )
916
auto mw = getMainWindow();
918
auto qssFile = mw->property("fc_currentStyleSheet").toString();
919
auto tiledBackground = mw->property("fc_tiledBackground").toBool();
921
Gui::Application::Instance->setStyleSheet(qssFile, tiledBackground);
926
void CreateStdCommands()
928
CommandManager &rcCmdMgr = Application::Instance->commandManager();
930
rcCmdMgr.addCommand(new StdCmdAbout());
931
rcCmdMgr.addCommand(new StdCmdAboutQt());
933
rcCmdMgr.addCommand(new StdCmdDlgParameter());
934
rcCmdMgr.addCommand(new StdCmdDlgPreferences());
935
rcCmdMgr.addCommand(new StdCmdDlgCustomize());
936
rcCmdMgr.addCommand(new StdCmdCommandLine());
937
rcCmdMgr.addCommand(new StdCmdWorkbench());
938
rcCmdMgr.addCommand(new StdCmdRecentFiles());
939
rcCmdMgr.addCommand(new StdCmdRecentMacros());
940
rcCmdMgr.addCommand(new StdCmdWhatsThis());
941
rcCmdMgr.addCommand(new StdCmdPythonHelp());
942
rcCmdMgr.addCommand(new StdCmdOnlineHelp());
943
rcCmdMgr.addCommand(new StdCmdOnlineHelpWebsite());
944
rcCmdMgr.addCommand(new StdCmdFreeCADWebsite());
945
rcCmdMgr.addCommand(new StdCmdFreeCADDonation());
946
rcCmdMgr.addCommand(new StdCmdFreeCADUserHub());
947
rcCmdMgr.addCommand(new StdCmdFreeCADPowerUserHub());
948
rcCmdMgr.addCommand(new StdCmdFreeCADForum());
949
rcCmdMgr.addCommand(new StdCmdFreeCADFAQ());
950
rcCmdMgr.addCommand(new StdCmdPythonWebsite());
951
rcCmdMgr.addCommand(new StdCmdReportBug());
952
rcCmdMgr.addCommand(new StdCmdTextDocument());
953
rcCmdMgr.addCommand(new StdCmdUnitsCalculator());
954
rcCmdMgr.addCommand(new StdCmdUserEditMode());
955
rcCmdMgr.addCommand(new StdCmdReloadStyleSheet());
956
//rcCmdMgr.addCommand(new StdCmdDownloadOnlineHelp());
957
//rcCmdMgr.addCommand(new StdCmdDescription());