| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #include <QDesktopServices>
|
| | #include <QInputDialog>
|
| | #include <QLabel>
|
| | #include <QMessageBox>
|
| | #include <QComboBox>
|
| | #include <QSignalBlocker>
|
| | #include <QTextStream>
|
| | #include <QTimer>
|
| |
|
| | #include <App/Document.h>
|
| | #include <Base/Interpreter.h>
|
| |
|
| | #include "Dialogs/DlgMacroExecuteImp.h"
|
| | #include "ui_DlgMacroExecute.h"
|
| | #include "Application.h"
|
| | #include "BitmapFactory.h"
|
| | #include "Command.h"
|
| | #include "Dialogs/DlgCustomizeImp.h"
|
| | #include "Dialogs/DlgToolbarsImp.h"
|
| | #include "Document.h"
|
| | #include "EditorView.h"
|
| | #include "Macro.h"
|
| | #include "MainWindow.h"
|
| | #include "PythonEditor.h"
|
| | #include "Workbench.h"
|
| | #include "WorkbenchManager.h"
|
| |
|
| |
|
| | using namespace Gui;
|
| | using namespace Gui::Dialog;
|
| |
|
| | namespace Gui
|
| | {
|
| | namespace Dialog
|
| | {
|
| | class MacroItem: public QTreeWidgetItem
|
| | {
|
| | public:
|
| | MacroItem(QTreeWidget* widget, bool systemwide, const QString& dirPath)
|
| | : QTreeWidgetItem(widget)
|
| | , systemWide(systemwide)
|
| | , dirPath(dirPath)
|
| | {}
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | void setFileName(int column, const QString& text)
|
| | {
|
| | QFileInfo file(dirPath, text);
|
| |
|
| | setToolTip(column, file.absoluteFilePath());
|
| | return QTreeWidgetItem::setText(column, text);
|
| | }
|
| |
|
| | ~MacroItem() override = default;
|
| |
|
| | bool systemWide;
|
| | QString dirPath;
|
| | };
|
| | }
|
| | }
|
| |
|
| |
|
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | DlgMacroExecuteImp::DlgMacroExecuteImp(QWidget* parent, Qt::WindowFlags fl)
|
| | : QDialog(parent, fl)
|
| | , WindowParameter("Macro")
|
| | , ui(new Ui_DlgMacroExecute)
|
| | {
|
| | watcher = std::make_unique<PythonTracingWatcher>(this);
|
| | ui->setupUi(this);
|
| | setupConnections();
|
| |
|
| |
|
| | {
|
| | QSignalBlocker blocker(ui->fileChooser);
|
| | std::string path = getWindowParameter()->GetASCII(
|
| | "MacroPath",
|
| | App::Application::getUserMacroDir().c_str()
|
| | );
|
| | this->macroPath = QString::fromUtf8(path.c_str());
|
| | ui->fileChooser->setFileName(this->macroPath);
|
| | }
|
| |
|
| |
|
| | QStringList labels;
|
| | labels << tr("Macros");
|
| | for (auto* listBox : {ui->userMacroListBox, ui->systemMacroListBox}) {
|
| | listBox->setHeaderLabels(labels);
|
| | listBox->header()->hide();
|
| | }
|
| | fillUpList();
|
| | ui->LineEditFind->setFocus();
|
| | ui->addonsButton->setEnabled(
|
| | Application::Instance->commandManager().getCommandByName("Std_AddonMgr") != nullptr
|
| | );
|
| | }
|
| |
|
| | |
| | |
| |
|
| | DlgMacroExecuteImp::~DlgMacroExecuteImp() = default;
|
| |
|
| | void DlgMacroExecuteImp::setupConnections()
|
| | {
|
| |
|
| | connect(ui->fileChooser, &FileChooser::fileNameChanged,
|
| | this, &DlgMacroExecuteImp::onFileChooserFileNameChanged);
|
| | connect(ui->createButton, &QPushButton::clicked,
|
| | this, &DlgMacroExecuteImp::onCreateButtonClicked);
|
| | connect(ui->deleteButton, &QPushButton::clicked,
|
| | this, &DlgMacroExecuteImp::onDeleteButtonClicked);
|
| | connect(ui->editButton, &QPushButton::clicked,
|
| | this, &DlgMacroExecuteImp::onEditButtonClicked);
|
| | connect(ui->renameButton, &QPushButton::clicked,
|
| | this, &DlgMacroExecuteImp::onRenameButtonClicked);
|
| | connect(ui->duplicateButton, &QPushButton::clicked,
|
| | this, &DlgMacroExecuteImp::onDuplicateButtonClicked);
|
| | connect(ui->toolbarButton, &QPushButton::clicked,
|
| | this, &DlgMacroExecuteImp::onToolbarButtonClicked);
|
| | connect(ui->addonsButton, &QPushButton::clicked,
|
| | this, &DlgMacroExecuteImp::onAddonsButtonClicked);
|
| | connect(ui->folderButton, &QPushButton::clicked,
|
| | this, &DlgMacroExecuteImp::onFolderButtonClicked);
|
| | connect(ui->userMacroListBox, &QTreeWidget::currentItemChanged,
|
| | this, &DlgMacroExecuteImp::onUserMacroListBoxCurrentItemChanged);
|
| | connect(ui->systemMacroListBox, &QTreeWidget::currentItemChanged,
|
| | this, &DlgMacroExecuteImp::onSystemMacroListBoxCurrentItemChanged);
|
| | connect(ui->tabMacroWidget, &QTabWidget::currentChanged,
|
| | this, &DlgMacroExecuteImp::onTabMacroWidgetCurrentChanged);
|
| | connect(ui->LineEditFind, &QLineEdit::textChanged,
|
| | this, &DlgMacroExecuteImp::onLineEditFindTextChanged);
|
| | connect(ui->LineEditFindInFiles, &QLineEdit::textChanged,
|
| | this, &DlgMacroExecuteImp::onLineEditFindInFilesTextChanged);
|
| |
|
| | }
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | QStringList DlgMacroExecuteImp::filterFiles(const QString& folder)
|
| | {
|
| | QDir dir(folder, QLatin1String("*.FCMacro *.py"));
|
| | QStringList unfiltered = dir.entryList();
|
| | QString fileFilter = ui->LineEditFind->text();
|
| | QString searchText = ui->LineEditFindInFiles->text();
|
| |
|
| | if (fileFilter.isEmpty() && searchText.isEmpty()) {
|
| | return unfiltered;
|
| | }
|
| | QStringList filteredByFileName;
|
| | if (fileFilter.isEmpty()) {
|
| | filteredByFileName = unfiltered;
|
| | }
|
| | else {
|
| | QRegularExpression regexFileName(fileFilter, QRegularExpression::CaseInsensitiveOption);
|
| | bool isValidFileFilter = regexFileName.isValid();
|
| | for (auto uf : unfiltered) {
|
| | if (isValidFileFilter) {
|
| | if (regexFileName.match(uf).hasMatch()) {
|
| | filteredByFileName.append(uf);
|
| | }
|
| | }
|
| | else {
|
| | if (uf.contains(fileFilter, Qt::CaseInsensitive)) {
|
| | filteredByFileName.append(uf);
|
| | }
|
| | }
|
| | }
|
| | }
|
| |
|
| | if (searchText.isEmpty()) {
|
| | return filteredByFileName;
|
| | }
|
| |
|
| | QRegularExpression regexContent(searchText, QRegularExpression::CaseInsensitiveOption);
|
| | bool isValidContentFilter = regexContent.isValid();
|
| | QStringList filteredByContent;
|
| | for (auto fn : filteredByFileName) {
|
| | const QString& fileName = fn;
|
| | QString filePath = dir.filePath(fileName);
|
| | QFile file(filePath);
|
| | if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
| | QTextStream in(&file);
|
| | QString fileContent = in.readAll();
|
| | if (isValidContentFilter) {
|
| | if (regexContent.match(fileContent).hasMatch()) {
|
| | filteredByContent.append(fileName);
|
| | }
|
| | }
|
| | else {
|
| | if (fileContent.contains(searchText, Qt::CaseInsensitive)) {
|
| | filteredByContent.append(fileName);
|
| | }
|
| | }
|
| | file.close();
|
| | }
|
| | }
|
| | return filteredByContent;
|
| | }
|
| |
|
| | |
| | |
| | |
| |
|
| | void DlgMacroExecuteImp::fillUpListForDir(const QString& dirPath, bool systemWide)
|
| | {
|
| | QStringList filteredByContent = this->filterFiles(dirPath);
|
| | auto* macroListBox = systemWide ? ui->systemMacroListBox : ui->userMacroListBox;
|
| | macroListBox->clear();
|
| | for (auto& fn : filteredByContent) {
|
| | auto item = new MacroItem(macroListBox, systemWide, dirPath);
|
| | item->setFileName(0, fn);
|
| | }
|
| | }
|
| |
|
| | |
| | |
| | |
| |
|
| | void DlgMacroExecuteImp::fillUpList()
|
| | {
|
| | fillUpListForDir(this->macroPath, false);
|
| |
|
| | QString dirstr = QString::fromStdString(App::Application::getHomePath())
|
| | + QStringLiteral("Macro");
|
| | fillUpListForDir(dirstr, true);
|
| |
|
| | auto& config = App::Application::Config();
|
| | auto additionalMacros = config.find("AdditionalMacroPaths");
|
| | if (additionalMacros != config.end()) {
|
| | QString dirsstrs = QString::fromStdString(additionalMacros->second);
|
| | QStringList dirs = dirsstrs.split(QChar::fromLatin1(';'));
|
| | for (const auto& dirstr : dirs) {
|
| | fillUpListForDir(dirstr, true);
|
| | }
|
| | }
|
| | }
|
| |
|
| |
|
| | |
| | |
| |
|
| | void DlgMacroExecuteImp::onUserMacroListBoxCurrentItemChanged(QTreeWidgetItem* item)
|
| | {
|
| | if (item) {
|
| | ui->LineEditMacroName->setText(item->text(0));
|
| |
|
| | ui->executeButton->setEnabled(true);
|
| | ui->deleteButton->setEnabled(true);
|
| | ui->toolbarButton->setEnabled(true);
|
| | ui->createButton->setEnabled(true);
|
| | ui->editButton->setEnabled(true);
|
| | ui->renameButton->setEnabled(true);
|
| | ui->duplicateButton->setEnabled(true);
|
| | }
|
| | else {
|
| | ui->executeButton->setEnabled(false);
|
| | ui->deleteButton->setEnabled(false);
|
| | ui->toolbarButton->setEnabled(false);
|
| | ui->createButton->setEnabled(true);
|
| | ui->editButton->setEnabled(false);
|
| | ui->renameButton->setEnabled(false);
|
| | ui->duplicateButton->setEnabled(false);
|
| | }
|
| | }
|
| |
|
| | void DlgMacroExecuteImp::onLineEditFindTextChanged(const QString& text)
|
| | {
|
| | Q_UNUSED(text);
|
| | this->fillUpList();
|
| | }
|
| |
|
| | void DlgMacroExecuteImp::onLineEditFindInFilesTextChanged(const QString& text)
|
| | {
|
| | Q_UNUSED(text);
|
| | this->fillUpList();
|
| | }
|
| |
|
| | void DlgMacroExecuteImp::onSystemMacroListBoxCurrentItemChanged(QTreeWidgetItem* item)
|
| | {
|
| | if (item) {
|
| | ui->LineEditMacroName->setText(item->text(0));
|
| |
|
| | ui->executeButton->setEnabled(true);
|
| | ui->deleteButton->setEnabled(false);
|
| | ui->toolbarButton->setEnabled(false);
|
| | ui->createButton->setEnabled(false);
|
| | ui->editButton->setEnabled(true);
|
| | ui->renameButton->setEnabled(false);
|
| | ui->duplicateButton->setEnabled(false);
|
| | }
|
| | else {
|
| | ui->executeButton->setEnabled(false);
|
| | ui->deleteButton->setEnabled(false);
|
| | ui->toolbarButton->setEnabled(false);
|
| | ui->createButton->setEnabled(false);
|
| | ui->editButton->setEnabled(false);
|
| | ui->renameButton->setEnabled(false);
|
| | ui->duplicateButton->setEnabled(false);
|
| | }
|
| | }
|
| |
|
| | void DlgMacroExecuteImp::onTabMacroWidgetCurrentChanged(int index)
|
| | {
|
| | QTreeWidgetItem* item;
|
| |
|
| | auto* macroListBox = index == 0 ? ui->userMacroListBox : ui->systemMacroListBox;
|
| | item = macroListBox->currentItem();
|
| | ui->executeButton->setEnabled(item);
|
| | ui->deleteButton->setEnabled(item);
|
| | ui->toolbarButton->setEnabled(item);
|
| | ui->createButton->setEnabled(item);
|
| | ui->editButton->setEnabled(item);
|
| | ui->renameButton->setEnabled(item);
|
| | ui->duplicateButton->setEnabled(item);
|
| |
|
| | ui->LineEditMacroName->setText(item ? item->text(0) : QString());
|
| | }
|
| |
|
| | |
| | |
| |
|
| | void DlgMacroExecuteImp::accept()
|
| | {
|
| | QTreeWidgetItem* item;
|
| |
|
| | int index = ui->tabMacroWidget->currentIndex();
|
| | auto* macroListBox = index == 0 ? ui->userMacroListBox : ui->systemMacroListBox;
|
| | item = macroListBox->currentItem();
|
| | if (!item) {
|
| | return;
|
| | }
|
| |
|
| | QDialog::accept();
|
| |
|
| | auto mitem = static_cast<MacroItem*>(item);
|
| |
|
| | QDir dir(mitem->dirPath);
|
| | QFileInfo fi(dir, item->text(0));
|
| | try {
|
| | getMainWindow()->setCursor(Qt::WaitCursor);
|
| | PythonTracingLocker tracelock(watcher->getTrace());
|
| |
|
| | getMainWindow()->appendRecentMacro(fi.filePath());
|
| | Application::Instance->macroManager()->run(Gui::MacroManager::File, fi.filePath().toUtf8());
|
| |
|
| | if (Application::Instance->activeDocument()) {
|
| | Application::Instance->activeDocument()->getDocument()->recompute();
|
| | }
|
| | getMainWindow()->unsetCursor();
|
| | }
|
| | catch (const Base::SystemExitException&) {
|
| |
|
| | Base::PyGILStateLocker locker;
|
| | Base::PyException e;
|
| | e.reportException();
|
| | getMainWindow()->unsetCursor();
|
| | }
|
| | }
|
| |
|
| | |
| | |
| |
|
| | void DlgMacroExecuteImp::onFileChooserFileNameChanged(const QString& fn)
|
| | {
|
| | if (!fn.isEmpty()) {
|
| |
|
| | this->macroPath = fn;
|
| | getWindowParameter()->SetASCII("MacroPath", fn.toUtf8());
|
| |
|
| | fillUpList();
|
| | }
|
| | }
|
| |
|
| | |
| | |
| |
|
| | void DlgMacroExecuteImp::onEditButtonClicked()
|
| | {
|
| | QTreeWidgetItem* item = nullptr;
|
| |
|
| | int index = ui->tabMacroWidget->currentIndex();
|
| | auto* macroListBox = index == 0 ? ui->userMacroListBox : ui->systemMacroListBox;
|
| | item = macroListBox->currentItem();
|
| | if (!item) {
|
| | return;
|
| | }
|
| |
|
| | auto mitem = static_cast<MacroItem*>(item);
|
| | QDir dir(mitem->dirPath);
|
| |
|
| | QString file = QStringLiteral("%1/%2").arg(dir.absolutePath(), item->text(0));
|
| | auto editor = new PythonEditor();
|
| | editor->setWindowIcon(Gui::BitmapFactory().iconFromTheme("applications-python"));
|
| | auto edit = new PythonEditorView(editor, getMainWindow());
|
| | edit->setDisplayName(PythonEditorView::FileName);
|
| | edit->open(file);
|
| | edit->resize(400, 300);
|
| | getMainWindow()->addWindow(edit);
|
| | getMainWindow()->appendRecentMacro(file);
|
| |
|
| | if (mitem->systemWide) {
|
| | editor->setReadOnly(true);
|
| | QString shownName;
|
| | shownName = QStringLiteral("%1[*] - [%2]").arg(item->text(0), tr("Read-Only"));
|
| | edit->setWindowTitle(shownName);
|
| | }
|
| | close();
|
| | }
|
| |
|
| |
|
| | void DlgMacroExecuteImp::onCreateButtonClicked()
|
| | {
|
| |
|
| | bool replaceSpaces = App::GetApplication()
|
| | .GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
| | ->GetBool("ReplaceSpaces", true);
|
| | App::GetApplication()
|
| | .GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
| | ->SetBool("ReplaceSpaces", replaceSpaces);
|
| |
|
| | QString fn = QInputDialog::getText(
|
| | this,
|
| | tr("Macro file"),
|
| | tr("Enter a file name:"),
|
| | QLineEdit::Normal,
|
| | QString(),
|
| | nullptr,
|
| | Qt::MSWindowsFixedSizeDialogHint
|
| | );
|
| |
|
| | if (replaceSpaces) {
|
| | fn = fn.replace(QStringLiteral(" "), QStringLiteral("_"));
|
| | }
|
| |
|
| | if (!fn.isEmpty()) {
|
| | QString suffix = QFileInfo(fn).suffix().toLower();
|
| | if (suffix != QLatin1String("fcmacro") && suffix != QLatin1String("py")) {
|
| | fn += QLatin1String(".FCMacro");
|
| | }
|
| | QDir dir(this->macroPath);
|
| |
|
| | if (!dir.exists()) {
|
| | dir.mkpath(this->macroPath);
|
| | }
|
| | QFileInfo fi(dir, fn);
|
| | if (fi.exists() && fi.isFile()) {
|
| | QMessageBox::warning(
|
| | this,
|
| | tr("Existing file"),
|
| | tr("'%1'.\nThis file already exists.").arg(fi.fileName())
|
| | );
|
| | }
|
| | else {
|
| | QFile file(fi.absoluteFilePath());
|
| | if (!file.open(QFile::WriteOnly)) {
|
| | QMessageBox::warning(
|
| | this,
|
| | tr("Cannot create file"),
|
| | tr("Creation of file '%1' failed.").arg(fi.absoluteFilePath())
|
| | );
|
| | return;
|
| | }
|
| | file.close();
|
| | auto editor = new PythonEditor();
|
| | editor->setWindowIcon(Gui::BitmapFactory().iconFromTheme("applications-python"));
|
| | auto edit = new PythonEditorView(editor, getMainWindow());
|
| | edit->open(fi.absoluteFilePath());
|
| | getMainWindow()->appendRecentMacro(fi.absoluteFilePath());
|
| | edit->setWindowTitle(QStringLiteral("%1[*]").arg(fn));
|
| | edit->resize(400, 300);
|
| | getMainWindow()->addWindow(edit);
|
| | close();
|
| | }
|
| | }
|
| | }
|
| |
|
| |
|
| | void DlgMacroExecuteImp::onDeleteButtonClicked()
|
| | {
|
| | int index = ui->tabMacroWidget->currentIndex();
|
| | auto* macroListBox = index == 0 ? ui->userMacroListBox : ui->systemMacroListBox;
|
| |
|
| | auto* item = dynamic_cast<MacroItem*>(macroListBox->currentItem());
|
| | if (!item) {
|
| | return;
|
| | }
|
| |
|
| | if (item->systemWide) {
|
| | QMessageBox::critical(
|
| | Gui::getMainWindow(),
|
| | QObject::tr("Delete macro"),
|
| | QObject::tr("Not allowed to delete system-wide macros")
|
| | );
|
| | return;
|
| | }
|
| |
|
| | QString fn = item->text(0);
|
| | auto ret = QMessageBox::question(
|
| | this,
|
| | tr("Delete macro"),
|
| | tr("Delete the macro '%1'?").arg(fn),
|
| | QMessageBox::Yes | QMessageBox::No,
|
| | QMessageBox::No
|
| | );
|
| | if (ret == QMessageBox::Yes) {
|
| | QDir dir(this->macroPath);
|
| | dir.remove(fn);
|
| | int index = macroListBox->indexOfTopLevelItem(item);
|
| | macroListBox->takeTopLevelItem(index);
|
| | delete item;
|
| | }
|
| | }
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | void DlgMacroExecuteImp::onToolbarButtonClicked()
|
| | {
|
| | |
| | |
| | |
| |
|
| |
|
| | bool showAgain = App::GetApplication()
|
| | .GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
| | ->GetBool("ShowWalkthroughMessage", true);
|
| | if (showAgain) {
|
| | QMessageBox msgBox(this);
|
| | QAbstractButton* doNotShowAgainButton
|
| | = msgBox.addButton(tr("Do not show again"), QMessageBox::YesRole);
|
| | msgBox.setText(tr("Guided Walkthrough"));
|
| | msgBox.setObjectName(QStringLiteral("macroGuideWalkthrough"));
|
| | msgBox.setInformativeText(tr("This will guide you in setting up this macro in a custom \
|
| | global toolbar. Instructions will be in red text inside the dialog.\n\
|
| | \n\
|
| | Note: your changes will be applied when you next switch workbenches\n"));
|
| | msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
| | msgBox.setDefaultButton(QMessageBox::Ok);
|
| | int result = msgBox.exec();
|
| | if (result == QMessageBox::Cancel) {
|
| | return;
|
| | }
|
| | if (msgBox.clickedButton() == doNotShowAgainButton) {
|
| | App::GetApplication()
|
| | .GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
| | ->SetBool("ShowWalkthroughMessage", false);
|
| | }
|
| | }
|
| |
|
| | QTreeWidgetItem* item = ui->userMacroListBox->currentItem();
|
| | if (!item) {
|
| | return;
|
| | }
|
| |
|
| | QString fn = item->text(0);
|
| | QString bareFileName = QFileInfo(fn).baseName();
|
| |
|
| |
|
| |
|
| | bool hasCustomToolbar = true;
|
| | if (App::GetApplication()
|
| | .GetParameterGroupByPath("User parameter:BaseApp/Workbench/Global/Toolbar")
|
| | ->GetGroups()
|
| | .empty()) {
|
| | hasCustomToolbar = false;
|
| | }
|
| |
|
| |
|
| | bool hasMacroCommand = false;
|
| | QString macroMenuText;
|
| | CommandManager& cCmdMgr = Application::Instance->commandManager();
|
| | std::vector<Command*> aCmds = cCmdMgr.getGroupCommands("Macros");
|
| | for (const auto& aCmd : aCmds) {
|
| | auto mc = dynamic_cast<MacroCommand*>(aCmd);
|
| | if (mc && fn.compare(QLatin1String(mc->getScriptName())) == 0) {
|
| | hasMacroCommand = true;
|
| | macroMenuText = QString::fromLatin1(mc->getMenuText());
|
| | }
|
| | }
|
| |
|
| | QTabWidget* tabWidget = nullptr;
|
| |
|
| | if (!hasMacroCommand) {
|
| |
|
| | Gui::Dialog::DlgCustomizeImp dlg(this);
|
| |
|
| |
|
| | dlg.setWindowTitle(tr("Walkthrough, Dialog 1 of 2"));
|
| |
|
| | tabWidget = dlg.findChild<QTabWidget*>(QStringLiteral("Gui__Dialog__TabWidget"));
|
| | if (!tabWidget) {
|
| | std::cerr << "Toolbar walkthrough error: Unable to find tabwidget" << std::endl;
|
| | return;
|
| | }
|
| |
|
| | auto setupCustomMacrosPage = tabWidget->findChild<QWidget*>(
|
| | QStringLiteral("Gui__Dialog__DlgCustomActions")
|
| | );
|
| | if (!setupCustomMacrosPage) {
|
| | std::cerr << "Toolbar walkthrough error: Unable to find setupCustomMacrosPage"
|
| | << std::endl;
|
| | return;
|
| | }
|
| | tabWidget->setCurrentWidget(setupCustomMacrosPage);
|
| |
|
| | auto groupBox7 = setupCustomMacrosPage->findChild<QGroupBox*>(QStringLiteral("GroupBox7"));
|
| | if (!groupBox7) {
|
| | Base::Console().warning("Toolbar walkthrough: Unable to find groupBox7\n");
|
| |
|
| | }
|
| | else {
|
| |
|
| | groupBox7->setTitle(
|
| | tr("Walkthrough instructions: Fill in missing fields (optional) "
|
| | "then click Add, then Close")
|
| | );
|
| | groupBox7->setStyleSheet(QStringLiteral("QGroupBox::title {color:red}"));
|
| | }
|
| |
|
| | auto buttonAddAction = setupCustomMacrosPage->findChild<QPushButton*>(
|
| | QStringLiteral("buttonAddAction")
|
| | );
|
| | if (!buttonAddAction) {
|
| | Base::Console().warning("Toolbar walkthrough: Unable to find buttonAddAction\n");
|
| | }
|
| | else {
|
| | buttonAddAction->setStyleSheet(QStringLiteral("color:red"));
|
| | }
|
| |
|
| | auto macroListBox = setupCustomMacrosPage->findChild<QComboBox*>(
|
| | QStringLiteral("actionMacros")
|
| | );
|
| | if (!macroListBox) {
|
| | Base::Console().warning("Toolbar walkthrough: Unable to find actionMacros combo box\n");
|
| | }
|
| | else {
|
| | int macroIndex = macroListBox->findText(fn);
|
| | macroListBox->setCurrentIndex(macroIndex);
|
| | }
|
| |
|
| | auto menuText = setupCustomMacrosPage->findChild<QLineEdit*>(QStringLiteral("actionMenu"));
|
| | if (!menuText) {
|
| | Base::Console().warning("Toolbar walkthrough: Unable to find actionMenu menuText\n");
|
| | }
|
| | else {
|
| | menuText->setText(bareFileName);
|
| | }
|
| |
|
| | dlg.exec();
|
| | }
|
| |
|
| |
|
| |
|
| | Gui::Dialog::DlgCustomizeImp dlg(this);
|
| | dlg.setWindowTitle(
|
| | hasMacroCommand ? tr("Walkthrough, Dialog 1 of 1") : tr("Walkthrough, Dialog 2 of 2")
|
| | );
|
| |
|
| | tabWidget = nullptr;
|
| | tabWidget = dlg.findChild<QTabWidget*>(QStringLiteral("Gui__Dialog__TabWidget"));
|
| | if (!tabWidget) {
|
| | std::cerr << "Toolbar walkthrough: Unable to find tabWidget Gui__Dialog__TabWidget"
|
| | << std::endl;
|
| | return;
|
| | }
|
| |
|
| | auto setupToolbarPage = tabWidget->findChild<DlgCustomToolbars*>(
|
| | QStringLiteral("Gui__Dialog__DlgCustomToolbars")
|
| | );
|
| | if (!setupToolbarPage) {
|
| | std::cerr
|
| | << "Toolbar walkthrough: Unable to find setupToolbarPage Gui__Dialog__DlgCustomToolbars"
|
| | << std::endl;
|
| | return;
|
| | }
|
| |
|
| | tabWidget->setCurrentWidget(setupToolbarPage);
|
| | auto moveActionRightButton = setupToolbarPage->findChild<QPushButton*>(
|
| | QStringLiteral("moveActionRightButton")
|
| | );
|
| | if (!moveActionRightButton) {
|
| | Base::Console().warning("Toolbar walkthrough: Unable to find moveActionRightButton\n");
|
| | }
|
| | else {
|
| | moveActionRightButton->setStyleSheet(QStringLiteral("background-color: red"));
|
| | }
|
| | |
| | |
| |
|
| |
|
| | QString instructions2
|
| | = tr("Walkthrough instructions: Select macro from list, then click right arrow button (->), then Close.");
|
| | auto workbenchBox = setupToolbarPage->findChild<QComboBox*>(QStringLiteral("workbenchBox"));
|
| | if (!workbenchBox) {
|
| | Base::Console().warning("Toolbar walkthrough: Unable to find workbenchBox\n");
|
| | }
|
| | else {
|
| |
|
| |
|
| | int globalIdx = workbenchBox->findData(QStringLiteral("Global"));
|
| | if (globalIdx != -1) {
|
| | workbenchBox->setCurrentIndex(globalIdx);
|
| | setupToolbarPage->activateWorkbenchBox(globalIdx);
|
| | }
|
| | else {
|
| | Base::Console().warning("Toolbar walkthrough: Unable to find Global workbench\n");
|
| | }
|
| |
|
| | if (!hasCustomToolbar) {
|
| | auto newButton = setupToolbarPage->findChild<QPushButton*>(QStringLiteral("newButton"));
|
| | if (!newButton) {
|
| | Base::Console().warning("Toolbar walkthrough: Unable to find newButton\n");
|
| | }
|
| | else {
|
| | newButton->setStyleSheet(QStringLiteral("color:red"));
|
| | instructions2 = tr(
|
| | "Walkthrough instructions: Click New, select macro, then right arrow (->) "
|
| | "button, then Close."
|
| | );
|
| | }
|
| | }
|
| | }
|
| | |
| |
|
| |
|
| | auto label = setupToolbarPage->findChild<QLabel*>(QStringLiteral("label"));
|
| | if (!label) {
|
| | Base::Console().warning("Toolbar walkthrough: Unable to find label\n");
|
| | }
|
| | else {
|
| | label->setText(instructions2);
|
| | label->setStyleSheet(QStringLiteral("color:red"));
|
| | }
|
| |
|
| |
|
| | auto categoryBox = setupToolbarPage->findChild<QComboBox*>(QStringLiteral("categoryBox"));
|
| | if (!categoryBox) {
|
| | Base::Console().warning("Toolbar walkthrough: Unable to find categoryBox\n");
|
| | }
|
| | else {
|
| | int macrosIdx = categoryBox->findText(tr("Macros"));
|
| | if (macrosIdx != -1) {
|
| | categoryBox->setCurrentIndex(macrosIdx);
|
| | }
|
| | else {
|
| | Base::Console().warning("Toolbar walkthrough: Unable to find Macros in categoryBox\n");
|
| | }
|
| | }
|
| |
|
| |
|
| | auto toolbarTreeWidget = setupToolbarPage->findChild<QTreeWidget*>(
|
| | QStringLiteral("toolbarTreeWidget")
|
| | );
|
| | if (!toolbarTreeWidget) {
|
| | Base::Console().warning("Toolbar walkthrough: Unable to find toolbarTreeWidget\n");
|
| | }
|
| | else {
|
| | toolbarTreeWidget->expandAll();
|
| | }
|
| |
|
| | |
| | |
| |
|
| | QTimer::singleShot(500, [=]() {
|
| | auto commandTreeWidget = setupToolbarPage->findChild<QTreeWidget*>(
|
| | QStringLiteral("commandTreeWidget")
|
| | );
|
| | if (!commandTreeWidget) {
|
| | Base::Console().warning("Toolbar walkthrough: Unable to find commandTreeWidget\n");
|
| | }
|
| | else {
|
| | if (!hasMacroCommand) {
|
| | commandTreeWidget->setCurrentItem(
|
| | commandTreeWidget->topLevelItem(commandTreeWidget->topLevelItemCount() - 1)
|
| | );
|
| | commandTreeWidget->scrollToItem(commandTreeWidget->currentItem());
|
| | }
|
| | else {
|
| | QList<QTreeWidgetItem*> items = commandTreeWidget->findItems(
|
| | macroMenuText,
|
| | Qt::MatchFixedString | Qt::MatchWrap,
|
| | 1
|
| | );
|
| | if (!items.empty()) {
|
| | commandTreeWidget->setCurrentItem(items[0]);
|
| | commandTreeWidget->scrollToItem(commandTreeWidget->currentItem());
|
| | }
|
| | }
|
| | }
|
| | });
|
| | dlg.exec();
|
| |
|
| | Workbench* active = Gui::WorkbenchManager::instance()->active();
|
| | if (active) {
|
| | active->activate();
|
| | }
|
| | }
|
| |
|
| |
|
| | |
| | |
| |
|
| | void DlgMacroExecuteImp::onRenameButtonClicked()
|
| | {
|
| | QDir dir;
|
| | QTreeWidgetItem* item = nullptr;
|
| |
|
| | int index = ui->tabMacroWidget->currentIndex();
|
| | if (index == 0) {
|
| | item = ui->userMacroListBox->currentItem();
|
| | dir.setPath(this->macroPath);
|
| | }
|
| |
|
| | if (!item) {
|
| | return;
|
| | }
|
| |
|
| | bool replaceSpaces = App::GetApplication()
|
| | .GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
| | ->GetBool("ReplaceSpaces", true);
|
| | App::GetApplication()
|
| | .GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
| | ->SetBool("ReplaceSpaces", replaceSpaces);
|
| |
|
| | QString oldName = item->text(0);
|
| | QFileInfo oldfi(dir, oldName);
|
| | QFile oldfile(oldfi.absoluteFilePath());
|
| |
|
| |
|
| | QString fn = QInputDialog::getText(
|
| | this,
|
| | tr("Renaming Macro File"),
|
| | tr("Enter new name"),
|
| | QLineEdit::Normal,
|
| | oldName,
|
| | nullptr,
|
| | Qt::MSWindowsFixedSizeDialogHint
|
| | );
|
| |
|
| | if (replaceSpaces) {
|
| | fn = fn.replace(QStringLiteral(" "), QStringLiteral("_"));
|
| | }
|
| |
|
| | if (!fn.isEmpty() && fn != oldName) {
|
| | QString suffix = QFileInfo(fn).suffix().toLower();
|
| | if (suffix != QLatin1String("fcmacro") && suffix != QLatin1String("py")) {
|
| | fn += QLatin1String(".FCMacro");
|
| | }
|
| | QFileInfo fi(dir, fn);
|
| |
|
| | if (fi.exists()) {
|
| | QMessageBox::warning(
|
| | this,
|
| | tr("Existing file"),
|
| | tr("'%1'\n already exists.").arg(fi.absoluteFilePath())
|
| | );
|
| | }
|
| | else if (!oldfile.rename(fi.absoluteFilePath())) {
|
| | QMessageBox::warning(
|
| | this,
|
| | tr("Rename Failed"),
|
| | tr("Failed to rename to '%1'.\nPerhaps a file permission error?")
|
| | .arg(fi.absoluteFilePath())
|
| | );
|
| | }
|
| | else {
|
| |
|
| | item->setText(0, fn);
|
| | ui->LineEditMacroName->setText(fn);
|
| | }
|
| | }
|
| | }
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | void DlgMacroExecuteImp::onDuplicateButtonClicked()
|
| | {
|
| | QDir dir;
|
| | QTreeWidgetItem* item = nullptr;
|
| |
|
| |
|
| |
|
| |
|
| | bool from001 = App::GetApplication()
|
| | .GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
| | ->GetBool("DuplicateFrom001", false);
|
| | App::GetApplication()
|
| | .GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
| | ->SetBool("DuplicateFrom001", from001);
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | bool ignoreExtra = App::GetApplication()
|
| | .GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
| | ->GetBool("DuplicateIgnoreExtraNote", false);
|
| | App::GetApplication()
|
| | .GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
| | ->SetBool("DuplicateIgnoreExtraNote", ignoreExtra);
|
| |
|
| |
|
| |
|
| |
|
| | bool replaceSpaces = App::GetApplication()
|
| | .GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
| | ->GetBool("ReplaceSpaces", true);
|
| | App::GetApplication()
|
| | .GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
| | ->SetBool("ReplaceSpaces", replaceSpaces);
|
| |
|
| | int index = ui->tabMacroWidget->currentIndex();
|
| | if (index == 0) {
|
| | item = ui->userMacroListBox->currentItem();
|
| | dir.setPath(this->macroPath);
|
| | }
|
| |
|
| | if (!item) {
|
| | return;
|
| | }
|
| |
|
| | QString oldName = item->text(0);
|
| | QFileInfo oldfi(dir, oldName);
|
| | QFile oldfile(oldfi.absoluteFilePath());
|
| | QString completeSuffix = oldfi.completeSuffix();
|
| | QString extraNote = completeSuffix.left(completeSuffix.size() - oldfi.suffix().size());
|
| | QString baseName = oldfi.baseName();
|
| | QString neutralSymbol = QStringLiteral("@");
|
| | QString last3 = baseName.right(3);
|
| | bool ok = true;
|
| | int nLast3 = last3.toInt(&ok);
|
| | last3 = QStringLiteral("001");
|
| | if (ok) {
|
| |
|
| | if (baseName.size() > 3) {
|
| | if (!from001) {
|
| | last3 = baseName.right(3);
|
| | }
|
| | baseName = baseName.left(baseName.size() - 3);
|
| | if (baseName.endsWith(neutralSymbol)) {
|
| | baseName = baseName.left(baseName.size() - 1);
|
| | }
|
| | }
|
| | }
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | if (ignoreExtra && !extraNote.isEmpty()) {
|
| | nLast3++;
|
| | last3 = QString::number(nLast3);
|
| | while (last3.size() < 3) {
|
| | last3.prepend(QStringLiteral("0"));
|
| | }
|
| | }
|
| |
|
| |
|
| | QString oldNameDigitized = baseName + neutralSymbol + last3 + QStringLiteral(".")
|
| | + completeSuffix;
|
| | QFileInfo fi(dir, oldNameDigitized);
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | while (fi.exists()) {
|
| | nLast3 = last3.toInt() + 1;
|
| | if (nLast3 >= 1000) {
|
| | break;
|
| | }
|
| | last3 = QString::number(nLast3);
|
| | while (last3.size() < 3) {
|
| | last3.prepend(QStringLiteral("0"));
|
| | }
|
| | oldNameDigitized = baseName + neutralSymbol + last3 + QStringLiteral(".") + completeSuffix;
|
| | fi = QFileInfo(dir, oldNameDigitized);
|
| | }
|
| |
|
| | if (ignoreExtra && !extraNote.isEmpty()) {
|
| | oldNameDigitized = oldNameDigitized.remove(extraNote);
|
| | }
|
| |
|
| |
|
| | QString fn = QInputDialog::getText(
|
| | this,
|
| | tr("Duplicate Macro"),
|
| | tr("Enter new name"),
|
| | QLineEdit::Normal,
|
| | oldNameDigitized,
|
| | nullptr,
|
| | Qt::MSWindowsFixedSizeDialogHint
|
| | );
|
| | if (replaceSpaces) {
|
| | fn = fn.replace(QStringLiteral(" "), QStringLiteral("_"));
|
| | }
|
| | if (!fn.isEmpty() && fn != oldName) {
|
| | QString suffix = QFileInfo(fn).suffix().toLower();
|
| | if (suffix != QLatin1String("fcmacro") && suffix != QLatin1String("py")) {
|
| | fn += QLatin1String(".FCMacro");
|
| | }
|
| | QFileInfo fi(dir, fn);
|
| |
|
| | if (fi.exists()) {
|
| | QMessageBox::warning(
|
| | this,
|
| | tr("Existing file"),
|
| | tr("'%1'\n already exists.").arg(fi.absoluteFilePath())
|
| | );
|
| | }
|
| | else if (!oldfile.copy(fi.absoluteFilePath())) {
|
| | QMessageBox::warning(
|
| | this,
|
| | tr("Duplicate Failed"),
|
| | tr("Failed to duplicate to '%1'.\nPerhaps a file permission error?")
|
| | .arg(fi.absoluteFilePath())
|
| | );
|
| | }
|
| |
|
| | this->fillUpList();
|
| | }
|
| | }
|
| |
|
| | |
| | |
| | |
| |
|
| | void DlgMacroExecuteImp::onAddonsButtonClicked()
|
| | {
|
| | CommandManager& rMgr = Application::Instance->commandManager();
|
| | rMgr.runCommandByName("Std_AddonMgr");
|
| | this->fillUpList();
|
| | }
|
| |
|
| | |
| | |
| | |
| |
|
| | void DlgMacroExecuteImp::onFolderButtonClicked()
|
| | {
|
| | QString path = QString::fromStdString(App::Application::getUserMacroDir());
|
| | QUrl url = QUrl::fromLocalFile(path);
|
| | QDesktopServices::openUrl(url);
|
| | }
|
| | #include "moc_DlgMacroExecuteImp.cpp"
|
| |
|