diff --git a/src/Gui/DlgCustomizeImp.cpp b/src/Gui/DlgCustomizeImp.cpp index c28997c1a335..b9394b546ef5 100644 --- a/src/Gui/DlgCustomizeImp.cpp +++ b/src/Gui/DlgCustomizeImp.cpp @@ -78,6 +78,7 @@ DlgCustomizeImp::DlgCustomizeImp(QWidget* parent, Qt::WindowFlags fl) customLayout->addLayout( layout, 1, 0 ); tabWidget = new QTabWidget( this ); + tabWidget->setObjectName(QString::fromLatin1("Gui__Dialog__TabWidget"));//so we can find it in DlgMacroExecuteImp // make sure that pages are ready to create GetWidgetFactorySupplier(); diff --git a/src/Gui/DlgMacroExecute.ui b/src/Gui/DlgMacroExecute.ui index d0215480f78f..2b6d588363c3 100644 --- a/src/Gui/DlgMacroExecute.ui +++ b/src/Gui/DlgMacroExecute.ui @@ -166,9 +166,6 @@ Qt::StrongFocus - - Gui::FileChooser::Directory - @@ -266,13 +263,23 @@ + + false + - Duplicate + Duplicate + + + + - false + false - + + Toolbar + + @@ -320,6 +327,7 @@ editButton renameButton duplicateButton + toolbarButton addonsButton fileChooser diff --git a/src/Gui/DlgMacroExecuteImp.cpp b/src/Gui/DlgMacroExecuteImp.cpp index 78916285c41f..527b77f3798e 100644 --- a/src/Gui/DlgMacroExecuteImp.cpp +++ b/src/Gui/DlgMacroExecuteImp.cpp @@ -26,6 +26,8 @@ # include # include # include +# include +# include #endif #include "DlgMacroExecuteImp.h" @@ -38,6 +40,8 @@ #include "Document.h" #include "EditorView.h" #include "PythonEditor.h" +#include "DlgCustomizeImp.h" +#include "DlgToolbarsImp.h" #include #include @@ -136,6 +140,7 @@ void DlgMacroExecuteImp::on_userMacroListBox_currentItemChanged(QTreeWidgetItem* executeButton->setEnabled(true); deleteButton->setEnabled(true); + toolbarButton->setEnabled(true); createButton->setEnabled(true); editButton->setEnabled(true); renameButton->setEnabled(true); @@ -144,6 +149,7 @@ void DlgMacroExecuteImp::on_userMacroListBox_currentItemChanged(QTreeWidgetItem* else { executeButton->setEnabled(false); deleteButton->setEnabled(false); + toolbarButton->setEnabled(false); createButton->setEnabled(true); editButton->setEnabled(false); renameButton->setEnabled(false); @@ -158,6 +164,7 @@ void DlgMacroExecuteImp::on_systemMacroListBox_currentItemChanged(QTreeWidgetIte executeButton->setEnabled(true); deleteButton->setEnabled(false); + toolbarButton->setEnabled(false); createButton->setEnabled(false); editButton->setEnabled(true); //look but don't touch renameButton->setEnabled(false); @@ -166,6 +173,7 @@ void DlgMacroExecuteImp::on_systemMacroListBox_currentItemChanged(QTreeWidgetIte else { executeButton->setEnabled(false); deleteButton->setEnabled(false); + toolbarButton->setEnabled(false); createButton->setEnabled(false); editButton->setEnabled(false); renameButton->setEnabled(false); @@ -182,6 +190,7 @@ void DlgMacroExecuteImp::on_tabMacroWidget_currentChanged(int index) if (item) { executeButton->setEnabled(true); deleteButton->setEnabled(true); + toolbarButton->setEnabled(true); createButton->setEnabled(true); editButton->setEnabled(true); renameButton->setEnabled(true); @@ -190,6 +199,7 @@ void DlgMacroExecuteImp::on_tabMacroWidget_currentChanged(int index) else { executeButton->setEnabled(false); deleteButton->setEnabled(false); + toolbarButton->setEnabled(false); createButton->setEnabled(true); editButton->setEnabled(false); renameButton->setEnabled(false); @@ -202,6 +212,7 @@ void DlgMacroExecuteImp::on_tabMacroWidget_currentChanged(int index) if (item) { executeButton->setEnabled(true); deleteButton->setEnabled(false); + toolbarButton->setEnabled(false); createButton->setEnabled(false); editButton->setEnabled(true); //but you can't save it renameButton->setEnabled(false); @@ -210,6 +221,7 @@ void DlgMacroExecuteImp::on_tabMacroWidget_currentChanged(int index) else { executeButton->setEnabled(false); deleteButton->setEnabled(false); + toolbarButton->setEnabled(false); createButton->setEnabled(false); editButton->setEnabled(false); renameButton->setEnabled(false); @@ -401,6 +413,142 @@ void DlgMacroExecuteImp::on_deleteButton_clicked() } } +/** + * Walk user through process of adding macro to global custom toolbar + * We create a custom customize dialog with instructions embedded + * within the dialog itself for the user, and the buttons to push in red text + * There are 2 dialogs we need to create: the macros dialog and the + * toolbar dialog. + */ + +void DlgMacroExecuteImp::on_toolbarButton_clicked(){ + + /** advise user of what we are doing, offer chance to cancel **/ + QMessageBox msgBox; + msgBox.setText(tr("Guided Walkthrough")); + msgBox.setInformativeText(tr("This will guide you in setting up this macro in a custom \ +global toolbar. Instructions will be in red text in the 2 dialogs that follow.\n")); + msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Ok); + int result = msgBox.exec(); + if (result == QMessageBox::Cancel){ + return; + } + QTreeWidgetItem* item = userMacroListBox->currentItem(); + if (!item) + return; + + QString fn = item->text(0); + QString bareFileName = fn; //for use as default menu text (filename without extension) + bareFileName.remove(QString::fromLatin1(".FCMacro").remove(QString::fromLatin1(".py"))); + + /** check if user already has custom toolbar, so we can tailor instructions accordingly **/ + bool hasCustomToolbar = true; + if (App::GetApplication().GetParameterGroupByPath( QByteArray("User parameter:BaseApp/Workbench/Global/Toolbar"))->GetGroups().size()==0){ + hasCustomToolbar=false; + } + + /** first the custom macros page dialog **/ + + static QPointer dlg = 0; + if (!dlg) + dlg = new Gui::Dialog::DlgCustomizeImp(getMainWindow()); + dlg->setAttribute(Qt::WA_DeleteOnClose); + dlg->setModal(true); + /** title is normally "Customize" **/ + dlg->setWindowTitle(tr("Walkthrough, dialog 1 of 2")); + + QTabWidget* tabWidget = dlg->findChild(QString::fromLatin1("Gui__Dialog__TabWidget")); + QWidget* setupCustomMacrosPage = tabWidget->findChild(QString::fromUtf8("Gui__Dialog__DlgCustomActions")); + tabWidget->setCurrentWidget(setupCustomMacrosPage); + QGroupBox* groupBox7 = setupCustomMacrosPage->findChild(QString::fromUtf8("GroupBox7")); + QPushButton* buttonAddAction = setupCustomMacrosPage->findChild(QString::fromUtf8("buttonAddAction")); + buttonAddAction->setStyleSheet(QString::fromLatin1("color:red")); + + /** normally the groupbox title is "Setup Custom Macros", but we change it here **/ + groupBox7->setTitle(tr("Walkthrough instructions: Fill in missing fields (optional) then click Add, then Close")); + groupBox7->setStyleSheet(QString::fromLatin1("QGroupBox::title {color:red}")); + + QComboBox* macroListBox = setupCustomMacrosPage->findChild(QString::fromUtf8("actionMacros")); + int macroIndex = macroListBox->findText(fn); //fn is the macro filename + macroListBox->setCurrentIndex(macroIndex); //select it for the user so he doesn't have to + QLineEdit* menuText = setupCustomMacrosPage->findChild(QString::fromUtf8("actionMenu")); + menuText->setText(bareFileName); //user can fill in other fields, e.g. tooltip + dlg->exec(); + + /** now for the toolbar selection dialog **/ + + dlg = 0; + if (!dlg){ + dlg = new Gui::Dialog::DlgCustomizeImp(getMainWindow()); + } + dlg->setAttribute(Qt::WA_DeleteOnClose); + dlg->setModal(true); + dlg->setWindowTitle(tr("Walkthrough, dialog 2 of 2")); + + tabWidget = dlg->findChild(QString::fromLatin1("Gui__Dialog__TabWidget")); + DlgCustomToolbars* setupToolbarPage = tabWidget->findChild(QString::fromUtf8("Gui__Dialog__DlgCustomToolbars")); + tabWidget->setCurrentWidget(setupToolbarPage); + QPushButton* moveActionRightButton = setupToolbarPage->findChild(QString::fromUtf8("moveActionRightButton")); + moveActionRightButton->setStyleSheet(QString::fromLatin1("background-color: red")); + + /** tailor instructions depending on whether user already has custom toolbar created + * if not he needs to click New button to create one first + **/ + + QString instructions2 = tr("Walkthrough instructions: Click right arrow button (->), then Close."); + QComboBox* workbenchBox = setupToolbarPage->findChild(QString::fromUtf8("workbenchBox")); + if (!hasCustomToolbar){ + QPushButton* newButton = setupToolbarPage->findChild(QString::fromUtf8("newButton")); + newButton->setStyleSheet(QString::fromLatin1("color:red")); + instructions2 = tr("Walkthrough instructions: Click New, then right arrow (->) button, then Close."); + } + + /** "label" normally says "Note: the changes become active the next time you load the appropriate workbench" **/ + + QLabel *label = setupToolbarPage->findChild(QString::fromLatin1("label")); + label->setText(instructions2); + label->setStyleSheet(QString::fromLatin1("color:red")); + + /** find the Global workbench and select it for the user **/ + + int globalIdx = workbenchBox->findText(tr("Global")); + if (globalIdx != -1){ + workbenchBox->setCurrentIndex(globalIdx); + setupToolbarPage->on_workbenchBox_activated(globalIdx); + } else { + workbenchBox->setCurrentIndex(0); + setupToolbarPage->on_workbenchBox_activated(0); + } + + /** find Macros category and select it for the user **/ + + QComboBox* categoryBox = setupToolbarPage->findChild(QString::fromUtf8("categoryBox")); + int macrosIdx = categoryBox->findText(tr("Macros")); + if (macrosIdx != -1){ + categoryBox->setCurrentIndex(macrosIdx); + setupToolbarPage->on_categoryBox_activated(macrosIdx); + } else { + categoryBox->setCurrentIndex(7); //Macros is our desired selection + setupToolbarPage->on_categoryBox_activated(7); + } + + /** the macro we just added in the first dialog will be at the bottom of this list **/ + + QTreeWidget* commandTreeWidget = setupToolbarPage->findChild(QString::fromUtf8("commandTreeWidget")); + commandTreeWidget->setCurrentItem(commandTreeWidget->topLevelItem(commandTreeWidget->topLevelItemCount()-1)); + commandTreeWidget->scrollToItem(commandTreeWidget->currentItem()); + + dlg->exec(); + + QMessageBox msgBox2; + msgBox2.setText(tr("Guided Walkthrough")); + msgBox2.setInformativeText(tr("Your changes will take effect when you switch workbenches.")); + msgBox2.exec(); +} + + + /** * renames the selected macro */ diff --git a/src/Gui/DlgMacroExecuteImp.h b/src/Gui/DlgMacroExecuteImp.h index 83be29f994ea..1c477683e2fc 100644 --- a/src/Gui/DlgMacroExecuteImp.h +++ b/src/Gui/DlgMacroExecuteImp.h @@ -52,6 +52,7 @@ public Q_SLOTS: void on_editButton_clicked(); void on_renameButton_clicked(); void on_duplicateButton_clicked(); + void on_toolbarButton_clicked(); void on_addonsButton_clicked(); protected Q_SLOTS: diff --git a/src/Gui/DlgToolbarsImp.h b/src/Gui/DlgToolbarsImp.h index ff0c4424e5ab..5c0486be3aa3 100644 --- a/src/Gui/DlgToolbarsImp.h +++ b/src/Gui/DlgToolbarsImp.h @@ -26,6 +26,7 @@ #include "ui_DlgToolbars.h" #include "PropertyPage.h" +#include "DlgMacroExecuteImp.h" namespace Gui { namespace Dialog { @@ -43,6 +44,7 @@ class DlgCustomToolbars : public CustomizeActionPage, public Ui_DlgCustomToolbar Q_OBJECT protected: + friend class DlgMacroExecuteImp; enum Type { Toolbar, Toolboxbar }; DlgCustomToolbars(Type, QWidget* parent = 0);