Debian Codegraph @

src/Gui/CommandStd.cpp

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2
3 /****************************************************************************
4 * Copyright (c) 2002 Jürgen Riegel <[email protected]> *
5 * Copyright (c) 2023 FreeCAD Project Association *
6 * *
7 * This file is part of FreeCAD. *
8 * *
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. *
13 * *
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. *
18 * *
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/>. *
22 * *
23 ***************************************************************************/
24
25 #include <QApplication>
26 #include <QMessageBox>
27 #include <QRegularExpression>
28 #include <QRegularExpressionMatch>
29 #include <QWhatsThis>
30 #include <QAbstractButton>
31 #include <QTimer>
32 #include <QProcess>
33
34 #include <App/Document.h>
35 #include <Base/Exception.h>
36 #include <Base/Interpreter.h>
37 #include <Base/Sequencer.h>
38
39 #include "Action.h"
40 #include "BitmapFactory.h"
41 #include "Command.h"
42 #include "Dialogs/DlgAbout.h"
43 #include "Dialogs/DlgCustomizeImp.h"
44 #include "Dialogs/DlgParameterImp.h"
45 #include "Dialogs/DlgPreferencesImp.h"
46 #include "Dialogs/DlgUnitsCalculatorImp.h"
47 #include "GuiConsole.h"
48 #include "MainWindow.h"
49 #include "OnlineDocumentation.h"
50 #include "Selection.h"
51 #include "WhatsThis.h"
52 #include "Workbench.h"
53 #include "WorkbenchManager.h"
54
55
56 using Base::Console;
57 using Base::Sequencer;
58 using namespace Gui;
59 namespace sp = std::placeholders;
60
61
62 //===========================================================================
63 // Std_Workbench
64 //===========================================================================
65
66 DEF_STD_CMD_AC(StdCmdWorkbench)
67
68 StdCmdWorkbench::StdCmdWorkbench()
69 : Command("Std_Workbench")
70 {
71 sGroup = "View";
72 sMenuText = QT_TR_NOOP("&Workbench");
73 sToolTipText = QT_TR_NOOP("Switches between workbenches");
74 sWhatsThis = "Std_Workbench";
75 sStatusTip = sToolTipText;
76 sPixmap = "freecad";
77 eType = 0;
78 }
79
80 void StdCmdWorkbench::activated(int i)
81 {
82 try {
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();
86 if (w) {
87 std::string current_w = w->name();
88 if (switch_to == current_w) {
89 return;
90 }
91 }
92 doCommand(Gui, "Gui.activateWorkbench(\"%s\")", switch_to.c_str());
93 }
94 catch (const Base::PyException& e) {
95 QString msg(QLatin1String(e.what()));
96 // ignore '<type 'exceptions.*Error'>' prefixes
97 QRegularExpression rx;
98 rx.setPattern(QLatin1String(R"(^\s*<type 'exceptions.\w*'>:\s*)"));
99 auto match = rx.match(msg);
100 if (match.hasMatch()) {
101 msg = msg.mid(match.capturedLength());
102 }
103 QMessageBox::critical(getMainWindow(), QObject::tr("Cannot load workbench"), msg);
104 }
105 catch (...) {
106 QMessageBox::critical(
107 getMainWindow(),
108 QObject::tr("Cannot load workbench"),
109 QObject::tr("A general error occurred while loading the workbench")
110 );
111 }
112 }
113
114 bool StdCmdWorkbench::isActive()
115 {
116 return true;
117 }
118
119 Action* StdCmdWorkbench::createAction()
120 {
121 Action* pcAction;
122
123 pcAction = new WorkbenchGroup(this, getMainWindow());
124 pcAction->setShortcut(QString::fromLatin1(getAccel()));
125 applyCommandData(this->className(), pcAction);
126 if (getPixmap()) {
127 pcAction->setIcon(Gui::BitmapFactory().iconFromTheme(getPixmap()));
128 }
129
130 return pcAction;
131 }
132
133 //===========================================================================
134 // Std_RecentFiles
135 //===========================================================================
136
137 DEF_STD_CMD_C(StdCmdRecentFiles)
138
139 StdCmdRecentFiles::StdCmdRecentFiles()
140 : Command("Std_RecentFiles")
141 {
142 sGroup = "File";
143 sMenuText = QT_TR_NOOP("Open &Recent");
144 sToolTipText = QT_TR_NOOP("Displays the list of recently opened files");
145 sWhatsThis = "Std_RecentFiles";
146 sStatusTip = sToolTipText;
147 sPixmap = "Std_RecentFiles";
148 eType = NoTransaction;
149 }
150
151 /**
152 * Opens the recent file at position \a iMsg in the menu.
153 * If the file does not exist or cannot be loaded this item is removed
154 * from the list.
155 */
156 void StdCmdRecentFiles::activated(int iMsg)
157 {
158 auto act = qobject_cast<RecentFilesAction*>(_pcAction);
159 if (act) {
160 act->activateFile(iMsg);
161 }
162 }
163
164 /**
165 * Creates the QAction object containing the recent files.
166 */
167 Action* StdCmdRecentFiles::createAction()
168 {
169 auto pcAction = new RecentFilesAction(this, getMainWindow());
170 pcAction->setObjectName(QLatin1String("recentFiles"));
171 pcAction->setDropDownMenu(true);
172 applyCommandData(this->className(), pcAction);
173 return pcAction;
174 }
175
176 //===========================================================================
177 // Std_RecentMacros
178 //===========================================================================
179
180 DEF_STD_CMD_C(StdCmdRecentMacros)
181
182 StdCmdRecentMacros::StdCmdRecentMacros()
183 : Command("Std_RecentMacros")
184 {
185 sGroup = "Macro";
186 sMenuText = QT_TR_NOOP("&Recent Macros");
187 sToolTipText = QT_TR_NOOP("Displays the list of recently used macros");
188 sWhatsThis = "Std_RecentMacros";
189 sStatusTip = sToolTipText;
190 sPixmap = "Std_RecentMacros";
191 eType = NoTransaction;
192 }
193
194 /**
195 * Opens the recent macro at position \a iMsg in the menu.
196 * If the macro does not exist or cannot be loaded this item is removed
197 * from the list.
198 */
199 void StdCmdRecentMacros::activated(int iMsg)
200 {
201 auto act = qobject_cast<RecentMacrosAction*>(_pcAction);
202 if (act) {
203 act->activateFile(iMsg);
204 }
205 }
206
207 /**
208 * Creates the QAction object containing the recent macros.
209 */
210 Action* StdCmdRecentMacros::createAction()
211 {
212 auto pcAction = new RecentMacrosAction(this, getMainWindow());
213 pcAction->setObjectName(QLatin1String("recentMacros"));
214 pcAction->setDropDownMenu(true);
215 applyCommandData(this->className(), pcAction);
216 return pcAction;
217 }
218
219 //===========================================================================
220 // Std_About
221 //===========================================================================
222
223 DEF_STD_CMD_ACL(StdCmdAbout)
224
225 StdCmdAbout::StdCmdAbout()
226 : Command("Std_About")
227 {
228 sGroup = "Help";
229 sMenuText = QT_TR_NOOP("&About %1");
230 sToolTipText = QT_TR_NOOP("Displays information about %1");
231 sWhatsThis = "Std_About";
232 sStatusTip = sToolTipText;
233 eType = 0;
234 }
235
236 Action* StdCmdAbout::createAction()
237 {
238 Action* pcAction;
239
240 QString exe = qApp->applicationName();
241 pcAction = new Action(this, getMainWindow());
242 pcAction->setText(QCoreApplication::translate(this->className(), getMenuText()).arg(exe));
243 pcAction->setToolTip(QCoreApplication::translate(this->className(), getToolTipText()).arg(exe));
244 pcAction->setStatusTip(QCoreApplication::translate(this->className(), getStatusTip()).arg(exe));
245 pcAction->setWhatsThis(QLatin1String(getWhatsThis()));
246 pcAction->setIcon(QApplication::windowIcon());
247 pcAction->setShortcut(QString::fromLatin1(getAccel()));
248 // Needs to have AboutRole set to avoid duplicates if adding the about action more than once on macOS
249 pcAction->setMenuRole(QAction::AboutRole);
250 return pcAction;
251 }
252
253 bool StdCmdAbout::isActive()
254 {
255 return true;
256 }
257
258 /**
259 * Shows information about the application.
260 */
261 void StdCmdAbout::activated(int iMsg)
262 {
263 Q_UNUSED(iMsg);
264 const Gui::Dialog::AboutDialogFactory* f = Gui::Dialog::AboutDialogFactory::defaultFactory();
265 boost::scoped_ptr<QDialog> dlg(f->create(getMainWindow()));
266 dlg->exec();
267 }
268
269 void StdCmdAbout::languageChange()
270 {
271 if (_pcAction) {
272 QString exe = qApp->applicationName();
273 _pcAction->setText(QCoreApplication::translate(this->className(), getMenuText()).arg(exe));
274 _pcAction->setToolTip(
275 QCoreApplication::translate(this->className(), getToolTipText()).arg(exe)
276 );
277 _pcAction->setStatusTip(
278 QCoreApplication::translate(this->className(), getStatusTip()).arg(exe)
279 );
280 _pcAction->setWhatsThis(QLatin1String(getWhatsThis()));
281 }
282 }
283
284 //===========================================================================
285 // Std_AboutQt
286 //===========================================================================
287 DEF_STD_CMD(StdCmdAboutQt)
288
289 StdCmdAboutQt::StdCmdAboutQt()
290 : Command("Std_AboutQt")
291 {
292 sGroup = "Help";
293 sMenuText = QT_TR_NOOP("About &Qt");
294 sToolTipText = QT_TR_NOOP("Displays information about Qt");
295 sWhatsThis = "Std_AboutQt";
296 sStatusTip = sToolTipText;
297 eType = 0;
298 }
299
300 void StdCmdAboutQt::activated(int iMsg)
301 {
302 Q_UNUSED(iMsg);
303 qApp->aboutQt();
304 }
305
306 //===========================================================================
307 // Std_WhatsThis
308 //===========================================================================
309 DEF_STD_CMD(StdCmdWhatsThis)
310
311 StdCmdWhatsThis::StdCmdWhatsThis()
312 : Command("Std_WhatsThis")
313 {
314 sGroup = "Help";
315 sMenuText = QT_TR_NOOP("&What's This?");
316 sToolTipText = QT_TR_NOOP("Opens the documentation for the selected command");
317 sWhatsThis = "Std_WhatsThis";
318 sStatusTip = sToolTipText;
319 sAccel = keySequenceToAccel(QKeySequence::WhatsThis);
320 sPixmap = "WhatsThis";
321 eType = 0;
322 }
323
324 void StdCmdWhatsThis::activated(int iMsg)
325 {
326 Q_UNUSED(iMsg);
327 QWhatsThis::enterWhatsThisMode();
328 }
329
330 //===========================================================================
331 // Std_RestartInSafeMode
332 //===========================================================================
333 DEF_STD_CMD(StdCmdRestartInSafeMode)
334
335 StdCmdRestartInSafeMode::StdCmdRestartInSafeMode()
336 : Command("Std_RestartInSafeMode")
337 {
338 sGroup = "Help";
339 sMenuText = QT_TR_NOOP("Restart in Safe Mode");
340 sToolTipText = QT_TR_NOOP("Starts FreeCAD without any modules or plugins loaded");
341 sWhatsThis = "Std_RestartInSafeMode";
342 sStatusTip = sToolTipText;
343 sPixmap = "safe-mode-restart";
344 eType = 0;
345 }
346
347 void StdCmdRestartInSafeMode::activated(int iMsg)
348 {
349 Q_UNUSED(iMsg);
350
351 QMessageBox restartBox(Gui::getMainWindow());
352 restartBox.setIcon(QMessageBox::Warning);
353 restartBox.setWindowTitle(QObject::tr("Restart in Safe Mode"));
354 restartBox.setText(QObject::tr("Restart FreeCAD and enter safe mode?"));
355 restartBox.setInformativeText(
356 QObject::tr("Safe mode temporarily disables the configuration and addons.")
357 );
358 restartBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
359 restartBox.setDefaultButton(QMessageBox::No);
360
361 if (restartBox.exec() == QMessageBox::Yes) {
362 // restart FreeCAD after a delay to give time to this dialog to close
363 const int ms = 1000;
364 QTimer::singleShot(ms, []() {
365 QStringList args = QApplication::arguments();
366 args.pop_front();
367 auto const safeModeArgument = QStringLiteral("--safe-mode");
368 if (!args.contains(safeModeArgument)) {
369 args.append(safeModeArgument);
370 }
371 if (getMainWindow()->close()) {
372 QProcess::startDetached(QApplication::applicationFilePath(), args);
373 }
374 });
375 }
376 }
377
378 //===========================================================================
379 // Std_DlgParameter
380 //===========================================================================
381 DEF_STD_CMD(StdCmdDlgParameter)
382
383 StdCmdDlgParameter::StdCmdDlgParameter()
384 : Command("Std_DlgParameter")
385 {
386 sGroup = "Tools";
387 sMenuText = QT_TR_NOOP("E&dit Parameters");
388
389 sToolTipText = QT_TR_NOOP("Opens a dialog to edit the parameters");
390 sWhatsThis = "Std_DlgParameter";
391 sStatusTip = sToolTipText;
392 sPixmap = "Std_DlgParameter";
393 eType = 0;
394 }
395
396 void StdCmdDlgParameter::activated(int iMsg)
397 {
398 Q_UNUSED(iMsg);
399 Gui::Dialog::DlgParameterImp cDlg(getMainWindow());
400 cDlg.resize(QSize(800, 600));
401 cDlg.exec();
402 }
403
404 //===========================================================================
405 // Std_DlgPreferences
406 //===========================================================================
407 DEF_STD_CMD_C(StdCmdDlgPreferences)
408
409 StdCmdDlgPreferences::StdCmdDlgPreferences()
410 : Command("Std_DlgPreferences")
411 {
412 sGroup = "Tools";
413 sMenuText = QT_TR_NOOP("Prefere&nces");
414
415 sToolTipText = QT_TR_NOOP("Opens a dialog to edit the preferences");
416 sWhatsThis = "Std_DlgPreferences";
417 sStatusTip = sToolTipText;
418 sPixmap = "preferences-system";
419 eType = 0;
420 sAccel = "Ctrl+,";
421 }
422
423 Action* StdCmdDlgPreferences::createAction()
424 {
425 Action* pcAction = Command::createAction();
426 pcAction->setMenuRole(QAction::PreferencesRole);
427
428 return pcAction;
429 }
430
431 void StdCmdDlgPreferences::activated(int iMsg)
432 {
433 Q_UNUSED(iMsg);
434
435 static QString groupName {};
436 static int index {};
437
438 Gui::Dialog::DlgPreferencesImp cDlg(getMainWindow());
439 ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
440 "User parameter:BaseApp/Preferences"
441 );
442 if (hGrp->GetBool("RestoreGroupPage", true)) {
443 cDlg.activateGroupPage(groupName, index);
444 }
445
446 if (cDlg.exec()) {
447 cDlg.activeGroupPage(groupName, index);
448 }
449 }
450
451 //===========================================================================
452 // Std_DlgCustomize
453 //===========================================================================
454 DEF_STD_CMD(StdCmdDlgCustomize)
455
456 StdCmdDlgCustomize::StdCmdDlgCustomize()
457 : Command("Std_DlgCustomize")
458 {
459 sGroup = "Tools";
460 sMenuText = QT_TR_NOOP("Cu&stomize…");
461 sToolTipText = QT_TR_NOOP("Opens a dialog to edit toolbars, shortcuts, and macros");
462 sWhatsThis = "Std_DlgCustomize";
463 sStatusTip = sToolTipText;
464 sPixmap = "applications-accessories";
465 eType = 0;
466 }
467
468 void StdCmdDlgCustomize::activated(int iMsg)
469 {
470 Q_UNUSED(iMsg);
471 static QPointer<QDialog> dlg = nullptr;
472 if (!dlg) {
473 dlg = new Gui::Dialog::DlgCustomizeImp(getMainWindow());
474 }
475 dlg->setAttribute(Qt::WA_DeleteOnClose);
476 dlg->show();
477 }
478
479 //===========================================================================
480 // Std_CommandLine
481 //===========================================================================
482 DEF_STD_CMD(StdCmdCommandLine)
483
484 StdCmdCommandLine::StdCmdCommandLine()
485 : Command("Std_CommandLine")
486 {
487 sGroup = "Tools";
488 sMenuText = QT_TR_NOOP("Command &Line");
489
490 sToolTipText = QT_TR_NOOP("Opens a command line interface in the console");
491 sWhatsThis = "Std_CommandLine";
492 sStatusTip = sToolTipText;
493 sPixmap = "utilities-terminal";
494 eType = 0;
495 }
496
497 void StdCmdCommandLine::activated(int iMsg)
498 {
499 Q_UNUSED(iMsg);
500 bool show = getMainWindow()->isMaximized();
501
502 // pop up the Gui command window
503 GUIConsole Wnd;
504
505 getMainWindow()->showMinimized();
506 qApp->processEvents();
507
508 // create temporary console sequencer
509 {
510 Base::ConsoleSequencer seq;
511 Base::Interpreter().runCommandLine("Console mode");
512 }
513
514 #ifdef Q_WS_X11
515 // On X11 this may not work. For further information see QWidget::showMaximized
516 //
517 // workaround for X11
518 getMainWindow()->hide();
519 getMainWindow()->show();
520 #endif
521
522 // pop up the main window
523 show ? getMainWindow()->showMaximized() : getMainWindow()->showNormal();
524 qApp->processEvents();
525 }
526
527 //===========================================================================
528 // Std_OnlineHelp
529 //===========================================================================
530
531 DEF_STD_CMD(StdCmdOnlineHelp)
532
533 StdCmdOnlineHelp::StdCmdOnlineHelp()
534 : Command("Std_OnlineHelp")
535 {
536 sGroup = "Help";
537 sMenuText = QT_TR_NOOP("&Help");
538 sToolTipText = QT_TR_NOOP("Opens the Help documentation");
539 sWhatsThis = "Std_OnlineHelp";
540 sStatusTip = sToolTipText;
541 sPixmap = "help-browser";
542 sAccel = keySequenceToAccel(QKeySequence::HelpContents);
543 eType = 0;
544 }
545
546 void StdCmdOnlineHelp::activated(int iMsg)
547 {
548 Q_UNUSED(iMsg);
549 Gui::getMainWindow()->showDocumentation(QStringLiteral("Online_Help_Startpage"));
550 }
551
552 //===========================================================================
553 // Std_OnlineHelpWebsite
554 //===========================================================================
555
556 DEF_STD_CMD(StdCmdOnlineHelpWebsite)
557
558 StdCmdOnlineHelpWebsite::StdCmdOnlineHelpWebsite()
559 : Command("Std_OnlineHelpWebsite")
560 {
561 sGroup = "Help";
562 sMenuText = QT_TR_NOOP("Help Website");
563 sToolTipText = QT_TR_NOOP("Opens the help documentation");
564 sWhatsThis = "Std_OnlineHelpWebsite";
565 sStatusTip = sToolTipText;
566 eType = 0;
567 }
568
569 void StdCmdOnlineHelpWebsite::activated(int iMsg)
570 {
571 Q_UNUSED(iMsg);
572 std::string defaulturl
573 = QCoreApplication::translate(this->className(), "https://wiki.freecad.org/Online_Help_Toc")
574 .toStdString();
575 ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath(
576 "User parameter:BaseApp/Preferences/Websites"
577 );
578 std::string url = hURLGrp->GetASCII("OnlineHelp", defaulturl.c_str());
579 hURLGrp->SetASCII("OnlineHelp", url.c_str());
580 OpenURLInBrowser(url.c_str());
581 }
582
583 //===========================================================================
584 // Std_FreeCADDonation
585 //===========================================================================
586
587 DEF_STD_CMD(StdCmdFreeCADDonation)
588
589 StdCmdFreeCADDonation::StdCmdFreeCADDonation()
590 : Command("Std_FreeCADDonation")
591 {
592 sGroup = "Help";
593 sMenuText = QT_TR_NOOP("Donate to FreeCA&D");
594 sToolTipText = QT_TR_NOOP("Support the FreeCAD development");
595 sWhatsThis = "Std_FreeCADDonation";
596 sStatusTip = sToolTipText;
597 sPixmap = "internet-web-browser";
598 eType = 0;
599 }
600
601 void StdCmdFreeCADDonation::activated(int iMsg)
602 {
603 Q_UNUSED(iMsg);
604 ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath(
605 "User parameter:BaseApp/Preferences/Websites"
606 );
607 std::string url = hURLGrp->GetASCII("DonatePage", "https://www.freecad.org/sponsor");
608 hURLGrp->SetASCII("DonatePage", url.c_str());
609 OpenURLInBrowser(url.c_str());
610 }
611
612 //===========================================================================
613 // Std_FreeDevHandbook
614
615 //===========================================================================
616
617 DEF_STD_CMD(StdCmdDevHandbook)
618
619 StdCmdDevHandbook::StdCmdDevHandbook()
620
621 : Command("Std_DevHandbook")
622 {
623 sGroup = "Help";
624 sMenuText = QT_TR_NOOP("Developers Handbook");
625
626 sToolTipText = QT_TR_NOOP("Handbook about FreeCAD development");
627
628 sWhatsThis = "Std_DevHandbook";
629 sStatusTip = sToolTipText;
630 sPixmap = "internet-web-browser";
631 eType = 0;
632 }
633
634 void StdCmdDevHandbook::activated(int iMsg)
635
636 {
637 Q_UNUSED(iMsg);
638 ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath(
639 "User parameter:BaseApp/Preferences/Websites"
640 );
641 std::string url = hURLGrp->GetASCII("DevHandbook", "https://freecad.github.io/DevelopersHandbook/");
642
643 hURLGrp->SetASCII("DevHandbook", url.c_str());
644 OpenURLInBrowser(url.c_str());
645 }
646
647 //===========================================================================
648 // Std_FreeCADWebsite
649 //===========================================================================
650
651 DEF_STD_CMD(StdCmdFreeCADWebsite)
652
653 StdCmdFreeCADWebsite::StdCmdFreeCADWebsite()
654 : Command("Std_FreeCADWebsite")
655 {
656 sGroup = "Help";
657 sMenuText = QT_TR_NOOP("FreeCAD W&ebsite");
658 sToolTipText = QT_TR_NOOP("Navigates to the official FreeCAD website");
659 sWhatsThis = "Std_FreeCADWebsite";
660 sStatusTip = sToolTipText;
661 sPixmap = "internet-web-browser";
662 eType = 0;
663 }
664
665 void StdCmdFreeCADWebsite::activated(int iMsg)
666 {
667 Q_UNUSED(iMsg);
668 std::string defaulturl
669 = QCoreApplication::translate(this->className(), "https://www.freecad.org").toStdString();
670 ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath(
671 "User parameter:BaseApp/Preferences/Websites"
672 );
673 std::string url = hURLGrp->GetASCII("WebPage", defaulturl.c_str());
674 hURLGrp->SetASCII("WebPage", url.c_str());
675 OpenURLInBrowser(url.c_str());
676 }
677
678 //===========================================================================
679 // Std_FreeCADUserHub
680 //===========================================================================
681
682 DEF_STD_CMD(StdCmdFreeCADUserHub)
683
684 StdCmdFreeCADUserHub::StdCmdFreeCADUserHub()
685 : Command("Std_FreeCADUserHub")
686 {
687 sGroup = "Help";
688 sMenuText = QT_TR_NOOP("&User Documentation");
689 sToolTipText = QT_TR_NOOP("Opens the documentation for users");
690 sWhatsThis = "Std_FreeCADUserHub";
691 sStatusTip = sToolTipText;
692 sPixmap = "internet-web-browser";
693 eType = 0;
694 }
695
696 void StdCmdFreeCADUserHub::activated(int iMsg)
697 {
698 Q_UNUSED(iMsg);
699 std::string defaulturl
700 = QCoreApplication::translate(this->className(), "https://wiki.freecad.org/User_hub")
701 .toStdString();
702 ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath(
703 "User parameter:BaseApp/Preferences/Websites"
704 );
705 std::string url = hURLGrp->GetASCII("Documentation", defaulturl.c_str());
706 hURLGrp->SetASCII("Documentation", url.c_str());
707 OpenURLInBrowser(url.c_str());
708 }
709
710 //===========================================================================
711 // Std_FreeCADForum
712 //===========================================================================
713
714 DEF_STD_CMD(StdCmdFreeCADForum)
715
716 StdCmdFreeCADForum::StdCmdFreeCADForum()
717 : Command("Std_FreeCADForum")
718 {
719 sGroup = "Help";
720 sMenuText = QT_TR_NOOP("FreeCAD &Forum");
721 sToolTipText = QT_TR_NOOP("The FreeCAD forum, where you can find help from other users");
722 sWhatsThis = "Std_FreeCADForum";
723 sStatusTip = sToolTipText;
724 sPixmap = "internet-web-browser";
725 eType = 0;
726 }
727
728 void StdCmdFreeCADForum::activated(int iMsg)
729 {
730 Q_UNUSED(iMsg);
731 std::string defaulturl
732 = QCoreApplication::translate(this->className(), "https://forum.freecad.org").toStdString();
733 ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath(
734 "User parameter:BaseApp/Preferences/Websites"
735 );
736 std::string url = hURLGrp->GetASCII("UserForum", defaulturl.c_str());
737 hURLGrp->SetASCII("UserForum", url.c_str());
738 OpenURLInBrowser(url.c_str());
739 }
740
741 //===========================================================================
742 // Std_ReportBug
743 //===========================================================================
744
745 DEF_STD_CMD(StdCmdReportBug)
746
747 StdCmdReportBug::StdCmdReportBug()
748 : Command("Std_ReportBug")
749 {
750 sGroup = "Help";
751 sMenuText = QT_TR_NOOP("Report an &Issue");
752 sToolTipText = QT_TR_NOOP("Opens the bugtracker to report an issue");
753 sWhatsThis = "Std_ReportBug";
754 sStatusTip = sToolTipText;
755 sPixmap = "internet-web-browser";
756 eType = 0;
757 }
758
759 void StdCmdReportBug::activated(int iMsg)
760 {
761 Q_UNUSED(iMsg);
762 ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath(
763 "User parameter:BaseApp/Preferences/Websites"
764 );
765 std::string url = hURLGrp->GetASCII("IssuesPage", "https://github.com/FreeCAD/FreeCAD/issues");
766 hURLGrp->SetASCII("IssuesPage", url.c_str());
767 OpenURLInBrowser(url.c_str());
768 }
769
770 //===========================================================================
771 // Std_TextDocument
772 //===========================================================================
773
774 DEF_STD_CMD_A(StdCmdTextDocument)
775
776 StdCmdTextDocument::StdCmdTextDocument()
777 : Command("Std_TextDocument")
778 {
779 sGroup = "Tools";
780 sMenuText = QT_TR_NOOP("Te&xt Document");
781 sToolTipText = QT_TR_NOOP("Adds a text document to the active document");
782 sWhatsThis = "Std_TextDocument";
783 sStatusTip = sToolTipText;
784 sPixmap = "TextDocument";
785 eType = 0;
786 }
787
788 void StdCmdTextDocument::activated(int iMsg)
789 {
790 Q_UNUSED(iMsg);
791
792 openCommand(QT_TRANSLATE_NOOP("Command", "Insert text document"));
793 doCommand(
794 Doc,
795 "App.ActiveDocument.addObject(\"App::TextDocument\",\"%s\").Label=\"%s\"",
796 "Text document",
797 "Text document"
798 );
799 doCommand(Gui, "Gui.ActiveDocument.ActiveObject.doubleClicked()");
800 updateActive();
801 commitCommand();
802 }
803
804 bool StdCmdTextDocument::isActive()
805 {
806 return hasActiveDocument();
807 }
808
809 //===========================================================================
810 // Std_UnitsCalculator
811 //===========================================================================
812 DEF_STD_CMD(StdCmdUnitsCalculator)
813
814 StdCmdUnitsCalculator::StdCmdUnitsCalculator()
815 : Command("Std_UnitsCalculator")
816 {
817 sGroup = "Tools";
818 sMenuText = QT_TR_NOOP("&Units Converter");
819
820 sToolTipText = QT_TR_NOOP("Starts the units converter");
821 sWhatsThis = "Std_UnitsCalculator";
822 sStatusTip = sToolTipText;
823 sPixmap = "accessories-calculator";
824 eType = 0;
825 }
826
827 void StdCmdUnitsCalculator::activated(int iMsg)
828 {
829 Q_UNUSED(iMsg);
830 auto dlg = new Gui::Dialog::DlgUnitsCalculator(getMainWindow());
831 dlg->show();
832 }
833
834 //===========================================================================
835 // StdCmdUserEditMode
836 //===========================================================================
837 class StdCmdUserEditMode: public Gui::Command
838 {
839 public:
840 StdCmdUserEditMode();
841 ~StdCmdUserEditMode() override = default;
842 void languageChange() override;
843 const char* className() const override
844 {
845 return "StdCmdUserEditMode";
846 }
847 void updateIcon(int mode);
848
849 protected:
850 void activated(int iMsg) override;
851 bool isActive() override;
852 Gui::Action* createAction() override;
853 };
854
855 StdCmdUserEditMode::StdCmdUserEditMode()
856 : Command("Std_UserEditMode")
857 {
858 sGroup = "Edit";
859 sMenuText = QT_TR_NOOP("Edit &Mode");
860 sToolTipText = QT_TR_NOOP("Defines behavior when editing an object from the tree view");
861 sStatusTip = sToolTipText;
862 sWhatsThis = "Std_UserEditMode";
863 sPixmap = "Std_UserEditModeDefault";
864 eType = ForEdit;
865
866 this->getGuiApplication()->signalUserEditModeChanged.connect([this](int mode) {
867 this->updateIcon(mode);
868 });
869 }
870
871 Gui::Action* StdCmdUserEditMode::createAction()
872 {
873 auto pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
874 pcAction->setDropDownMenu(true);
875 pcAction->setIsMode(true);
876 applyCommandData(this->className(), pcAction);
877
878 for (auto const& uem : Gui::Application::Instance->listUserEditModes()) {
879 QAction* act = pcAction->addAction(QString());
880 auto modeName = QString::fromStdString(uem.second.first).remove(QChar::fromLatin1('&'));
881 act->setCheckable(true);
882 act->setIcon(
883 BitmapFactory().iconFromTheme(qPrintable(QStringLiteral("Std_UserEditMode") + modeName))
884 );
885 act->setObjectName(QStringLiteral("Std_UserEditMode") + modeName);
886 act->setWhatsThis(QString::fromLatin1(getWhatsThis()));
887 act->setToolTip(QString::fromStdString(uem.second.second));
888
889 if (uem.first == 0) {
890 pcAction->setIcon(act->icon());
891 act->setChecked(true);
892 }
893 }
894
895 _pcAction = pcAction;
896
897 int lastMode = App::GetApplication()
898 .GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")
899 ->GetInt("UserEditMode", 0);
900 Gui::Application::Instance->setUserEditMode(lastMode);
901
902 languageChange();
903 return pcAction;
904 }
905
906 void StdCmdUserEditMode::languageChange()
907 {
908 Command::languageChange();
909
910 if (!_pcAction) {
911 return;
912 }
913 auto pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
914 QList<QAction*> a = pcAction->actions();
915
916 for (int i = 0; i < a.count(); i++) {
917 auto modeName = Gui::Application::Instance->getUserEditModeUIStrings(i);
918 a[i]->setText(QCoreApplication::translate("EditMode", modeName.first.c_str()));
919 a[i]->setToolTip(QCoreApplication::translate("EditMode", modeName.second.c_str()));
920 }
921 }
922
923 void StdCmdUserEditMode::updateIcon(int mode)
924 {
925 auto actionGroup = dynamic_cast<Gui::ActionGroup*>(_pcAction);
926 if (!actionGroup) {
927 return;
928 }
929
930 actionGroup->setCheckedAction(mode);
931 }
932
933 void StdCmdUserEditMode::activated(int iMsg)
934 {
935 App::GetApplication()
936 .GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")
937 ->SetInt("UserEditMode", iMsg);
938 Gui::Application::Instance->setUserEditMode(iMsg);
939 }
940
941 bool StdCmdUserEditMode::isActive()
942 {
943 return true;
944 }
945
946 //===========================================================================
947 // Std_ReloadStylesheet
948 //===========================================================================
949 DEF_STD_CMD(StdCmdReloadStyleSheet)
950
951 StdCmdReloadStyleSheet::StdCmdReloadStyleSheet()
952 : Command("Std_ReloadStyleSheet")
953 {
954 sGroup = "View";
955 sMenuText = QT_TR_NOOP("&Reload Stylesheet");
956 sToolTipText = QT_TR_NOOP("Reloads the current stylesheet");
957 sWhatsThis = "Std_ReloadStyleSheet";
958 sStatusTip = sToolTipText;
959 sPixmap = "view-refresh";
960 sWhatsThis = "Std_ReloadStyleSheet";
961 }
962
963 void StdCmdReloadStyleSheet::activated(int)
964 {
965 Application::Instance->reloadStyleSheet();
966 }
967
968 namespace Gui
969 {
970
971 void CreateStdCommands()
972 {
973 CommandManager& rcCmdMgr = Application::Instance->commandManager();
974
975 rcCmdMgr.addCommand(new StdCmdAbout());
976 rcCmdMgr.addCommand(new StdCmdAboutQt());
977
978 rcCmdMgr.addCommand(new StdCmdDlgParameter());
979 rcCmdMgr.addCommand(new StdCmdDlgPreferences());
980 rcCmdMgr.addCommand(new StdCmdDlgCustomize());
981 rcCmdMgr.addCommand(new StdCmdCommandLine());
982 rcCmdMgr.addCommand(new StdCmdWorkbench());
983 rcCmdMgr.addCommand(new StdCmdRecentFiles());
984 rcCmdMgr.addCommand(new StdCmdRecentMacros());
985 rcCmdMgr.addCommand(new StdCmdWhatsThis());
986 rcCmdMgr.addCommand(new StdCmdRestartInSafeMode());
987 rcCmdMgr.addCommand(new StdCmdPythonHelp());
988 rcCmdMgr.addCommand(new StdCmdOnlineHelp());
989 rcCmdMgr.addCommand(new StdCmdOnlineHelpWebsite());
990 rcCmdMgr.addCommand(new StdCmdFreeCADWebsite());
991 rcCmdMgr.addCommand(new StdCmdFreeCADDonation());
992 rcCmdMgr.addCommand(new StdCmdFreeCADUserHub());
993 rcCmdMgr.addCommand(new StdCmdFreeCADForum());
994 rcCmdMgr.addCommand(new StdCmdReportBug());
995 rcCmdMgr.addCommand(new StdCmdTextDocument());
996 rcCmdMgr.addCommand(new StdCmdUnitsCalculator());
997 rcCmdMgr.addCommand(new StdCmdUserEditMode());
998 rcCmdMgr.addCommand(new StdCmdReloadStyleSheet());
999 rcCmdMgr.addCommand(new StdCmdDevHandbook());
1000 // rcCmdMgr.addCommand(new StdCmdDownloadOnlineHelp());
1001 // rcCmdMgr.addCommand(new StdCmdDescription());
1002 }
1003
1004 } // namespace Gui