Skip to content

Commit

Permalink
ticket:4305 Added checkbox to remember user's decision in text editor…
Browse files Browse the repository at this point in the history
… error dialog.
  • Loading branch information
adeas31 committed Oct 19, 2017
1 parent 6882da0 commit 1506f4d
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 28 deletions.
38 changes: 25 additions & 13 deletions OMEdit/OMEditGUI/Editors/CompositeModelEditor.cpp
Expand Up @@ -33,6 +33,7 @@
#include "Options/OptionsDialog.h"
#include "Modeling/MessagesWidget.h"
#include "Modeling/Commands.h"
#include "Options/NotificationsDialog.h"

#include <QMessageBox>
#include <QMenu>
Expand Down Expand Up @@ -81,19 +82,30 @@ bool CompositeModelEditor::validateText()
if (mTextChanged) {
// if the user makes few mistakes in the text then dont let him change the perspective
if (!mpModelWidget->compositeModelEditorTextChanged()) {
QMessageBox *pMessageBox = new QMessageBox(MainWindow::instance());
pMessageBox->setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::error));
pMessageBox->setIcon(QMessageBox::Critical);
pMessageBox->setAttribute(Qt::WA_DeleteOnClose);
pMessageBox->setText(GUIMessages::getMessage(GUIMessages::ERROR_IN_TEXT).arg("Composite Model")
.append(GUIMessages::getMessage(GUIMessages::CHECK_MESSAGES_BROWSER))
.append(GUIMessages::getMessage(GUIMessages::REVERT_PREVIOUS_OR_FIX_ERRORS_MANUALLY)));
QPushButton *pAcceptRoleButton = pMessageBox->addButton(Helper::fixErrorsManually, QMessageBox::AcceptRole);
pMessageBox->addButton(Helper::revertToLastCorrectVersion, QMessageBox::RejectRole);
pMessageBox->setEscapeButton(pAcceptRoleButton);
// we set focus to this widget here so when the error dialog is closed Qt gives back the focus to this widget.
mpPlainTextEdit->setFocus(Qt::ActiveWindowFocusReason);
int answer = pMessageBox->exec();
QSettings *pSettings = Utilities::getApplicationSettings();
int answer = 1;
if (pSettings->contains("textEditor/revertPreviousOrFixErrorsManually")) {
answer = pSettings->value("textEditor/revertPreviousOrFixErrorsManually").toInt();
}
if (OptionsDialog::instance()->getNotificationsPage()->getAlwaysAskForTextEditorErrorCheckBox()->isChecked()) {
NotificationsDialog *pNotificationsDialog = new NotificationsDialog(NotificationsDialog::RevertPreviousOrFixErrorsManually,
NotificationsDialog::CriticalIcon,
MainWindow::instance());
pNotificationsDialog->setNotificationLabelString(GUIMessages::getMessage(GUIMessages::ERROR_IN_TEXT).arg("Composite Model")
.append(GUIMessages::getMessage(GUIMessages::CHECK_MESSAGES_BROWSER))
.append(GUIMessages::getMessage(GUIMessages::REVERT_PREVIOUS_OR_FIX_ERRORS_MANUALLY)));
pNotificationsDialog->getOkButton()->setText(Helper::revertToLastCorrectVersion);
pNotificationsDialog->getOkButton()->setAutoDefault(false);
pNotificationsDialog->getCancelButton()->setText(Helper::fixErrorsManually);
pNotificationsDialog->getCancelButton()->setAutoDefault(true);
pNotificationsDialog->getButtonBox()->removeButton(pNotificationsDialog->getOkButton());
pNotificationsDialog->getButtonBox()->removeButton(pNotificationsDialog->getCancelButton());
pNotificationsDialog->getButtonBox()->addButton(pNotificationsDialog->getCancelButton(), QDialogButtonBox::ActionRole);
pNotificationsDialog->getButtonBox()->addButton(pNotificationsDialog->getOkButton(), QDialogButtonBox::ActionRole);
// we set focus to this widget here so when the error dialog is closed Qt gives back the focus to this widget.
mpPlainTextEdit->setFocus(Qt::ActiveWindowFocusReason);
answer = pNotificationsDialog->exec();
}
switch (answer) {
case QMessageBox::RejectRole:
mTextChanged = false;
Expand Down
38 changes: 25 additions & 13 deletions OMEdit/OMEditGUI/Editors/ModelicaEditor.cpp
Expand Up @@ -38,6 +38,7 @@
#include "Options/OptionsDialog.h"
#include "Debugger/Breakpoints/BreakpointMarker.h"
#include "Util/Helper.h"
#include "Options/NotificationsDialog.h"
#include <QCompleter>
#include <QMenu>
#include <QMessageBox>
Expand Down Expand Up @@ -171,19 +172,30 @@ bool ModelicaEditor::validateText(LibraryTreeItem **pLibraryTreeItem)
if (isTextChanged()) {
// if the user makes few mistakes in the text then dont let him change the perspective
if (!mpModelWidget->modelicaEditorTextChanged(pLibraryTreeItem)) {
QMessageBox *pMessageBox = new QMessageBox(MainWindow::instance());
pMessageBox->setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::error));
pMessageBox->setIcon(QMessageBox::Critical);
pMessageBox->setAttribute(Qt::WA_DeleteOnClose);
pMessageBox->setText(GUIMessages::getMessage(GUIMessages::ERROR_IN_TEXT).arg("Modelica")
.append(GUIMessages::getMessage(GUIMessages::CHECK_MESSAGES_BROWSER))
.append(GUIMessages::getMessage(GUIMessages::REVERT_PREVIOUS_OR_FIX_ERRORS_MANUALLY)));
QPushButton *pAcceptRoleButton = pMessageBox->addButton(Helper::fixErrorsManually, QMessageBox::AcceptRole);
pMessageBox->addButton(Helper::revertToLastCorrectVersion, QMessageBox::RejectRole);
pMessageBox->setEscapeButton(pAcceptRoleButton);
// we set focus to this widget here so when the error dialog is closed Qt gives back the focus to this widget.
mpPlainTextEdit->setFocus(Qt::ActiveWindowFocusReason);
int answer = pMessageBox->exec();
QSettings *pSettings = Utilities::getApplicationSettings();
int answer = 1;
if (pSettings->contains("textEditor/revertPreviousOrFixErrorsManually")) {
answer = pSettings->value("textEditor/revertPreviousOrFixErrorsManually").toInt();
}
if (OptionsDialog::instance()->getNotificationsPage()->getAlwaysAskForTextEditorErrorCheckBox()->isChecked()) {
NotificationsDialog *pNotificationsDialog = new NotificationsDialog(NotificationsDialog::RevertPreviousOrFixErrorsManually,
NotificationsDialog::CriticalIcon,
MainWindow::instance());
pNotificationsDialog->setNotificationLabelString(GUIMessages::getMessage(GUIMessages::ERROR_IN_TEXT).arg("Modelica")
.append(GUIMessages::getMessage(GUIMessages::CHECK_MESSAGES_BROWSER))
.append(GUIMessages::getMessage(GUIMessages::REVERT_PREVIOUS_OR_FIX_ERRORS_MANUALLY)));
pNotificationsDialog->getOkButton()->setText(Helper::revertToLastCorrectVersion);
pNotificationsDialog->getOkButton()->setAutoDefault(false);
pNotificationsDialog->getCancelButton()->setText(Helper::fixErrorsManually);
pNotificationsDialog->getCancelButton()->setAutoDefault(true);
pNotificationsDialog->getButtonBox()->removeButton(pNotificationsDialog->getOkButton());
pNotificationsDialog->getButtonBox()->removeButton(pNotificationsDialog->getCancelButton());
pNotificationsDialog->getButtonBox()->addButton(pNotificationsDialog->getCancelButton(), QDialogButtonBox::ActionRole);
pNotificationsDialog->getButtonBox()->addButton(pNotificationsDialog->getOkButton(), QDialogButtonBox::ActionRole);
// we set focus to this widget here so when the error dialog is closed Qt gives back the focus to this widget.
mpPlainTextEdit->setFocus(Qt::ActiveWindowFocusReason);
answer = pNotificationsDialog->exec();
}
switch (answer) {
case QMessageBox::RejectRole:
setTextChanged(false);
Expand Down
50 changes: 49 additions & 1 deletion OMEdit/OMEditGUI/Options/NotificationsDialog.cpp
Expand Up @@ -76,7 +76,7 @@ NotificationsDialog::NotificationsDialog(NotificationType notificationType, Noti
connect(mpOkButton, SIGNAL(clicked()), SLOT(saveNotification()));
mpCancelButton = new QPushButton(Helper::cancel);
mpCancelButton->setAutoDefault(false);
connect(mpCancelButton, SIGNAL(clicked()), SLOT(reject()));
connect(mpCancelButton, SIGNAL(clicked()), SLOT(rejectNotification()));
mpButtonBox = new QDialogButtonBox(Qt::Horizontal);
mpButtonBox->addButton(mpOkButton, QDialogButtonBox::ActionRole);
mpButtonBox->addButton(mpCancelButton, QDialogButtonBox::ActionRole);
Expand Down Expand Up @@ -149,6 +149,8 @@ QString NotificationsDialog::getNotificationTitleString()
case NotificationsDialog::InnerModelNameChanged:
case NotificationsDialog::SaveModelForBitmapInsertion:
return Helper::information;
case NotificationsDialog::RevertPreviousOrFixErrorsManually:
return Helper::error;
default:
// should never be reached
return "No String is defined for your notification type in NotificationsDialog::getNotificationTitleString()";
Expand All @@ -169,6 +171,7 @@ QString NotificationsDialog::getNotificationLabelString()
return GUIMessages::getMessage(GUIMessages::ITEM_DROPPED_ON_ITSELF);
case NotificationsDialog::ReplaceableIfPartial:
case NotificationsDialog::InnerModelNameChanged:
case RevertPreviousOrFixErrorsManually:
return "this string needs argument and will be set via NotificationsDialog::setNotificationLabelString(QString label)";
case NotificationsDialog::SaveModelForBitmapInsertion:
return tr("You must save the class before referencing a bitmap from local directory.");
Expand All @@ -194,6 +197,8 @@ QString NotificationsDialog::getNotificationCheckBoxString()
case NotificationsDialog::InnerModelNameChanged:
case NotificationsDialog::SaveModelForBitmapInsertion:
return Helper::dontShowThisMessageAgain;
case NotificationsDialog::RevertPreviousOrFixErrorsManually:
return tr("Remember my decision and do not ask again");
default:
// should never be reached
return "No String is defined for your notification type in NotificationsDialog::getNotificationCheckBoxString()";
Expand Down Expand Up @@ -258,6 +263,18 @@ void NotificationsDialog::saveModelForBitmapInsertionNotificationSettings()
OptionsDialog::instance()->getNotificationsPage()->getSaveModelForBitmapInsertionCheckBox()->setChecked(false);
}

/*!
* \brief NotificationsDialog::saveAlwaysAskForTextEditorErrorSettings
* Saves the notifications/alwaysAskForTextEditorError key settings to omedit.ini file.\n
* Sets the notifications/alwaysAskForTextEditorError notification checkbox on the NotificationsPage.
*/
void NotificationsDialog::saveAlwaysAskForTextEditorErrorSettings()
{
QSettings *pSettings = Utilities::getApplicationSettings();
pSettings->setValue("notifications/alwaysAskForTextEditorError", false);
OptionsDialog::instance()->getNotificationsPage()->getAlwaysAskForTextEditorErrorCheckBox()->setChecked(false);
}

/*!
* \brief NotificationsDialog::saveNotification
* Slot activated when mpOkButton clicked signal is raised.\n
Expand All @@ -282,10 +299,41 @@ void NotificationsDialog::saveNotification()
case NotificationsDialog::SaveModelForBitmapInsertion:
saveModelForBitmapInsertionNotificationSettings();
break;
case NotificationsDialog::RevertPreviousOrFixErrorsManually:
saveAlwaysAskForTextEditorErrorSettings();
break;
default:
// should never be reached
break;
}
}
if (mNotificationType == NotificationsDialog::RevertPreviousOrFixErrorsManually) {
QSettings *pSettings = Utilities::getApplicationSettings();
pSettings->setValue("textEditor/revertPreviousOrFixErrorsManually", 1);
}
accept();
}

/*!
* \brief NotificationsDialog::rejectNotification
* Slot activated when mpCancelButton clicked signal is raised.\n
* Checks the notification type and calls the appropriate method.
*/
void NotificationsDialog::rejectNotification()
{
if (mpNotificationCheckBox->isChecked()) {
switch (mNotificationType) {
case NotificationsDialog::RevertPreviousOrFixErrorsManually:
saveAlwaysAskForTextEditorErrorSettings();
break;
default:
// should never be reached
break;
}
}
if (mNotificationType == NotificationsDialog::RevertPreviousOrFixErrorsManually) {
QSettings *pSettings = Utilities::getApplicationSettings();
pSettings->setValue("textEditor/revertPreviousOrFixErrorsManually", 0);
}
reject();
}
8 changes: 7 additions & 1 deletion OMEdit/OMEditGUI/Options/NotificationsDialog.h
Expand Up @@ -49,12 +49,16 @@ class NotificationsDialog : public QDialog
ItemDroppedOnItself,
ReplaceableIfPartial,
InnerModelNameChanged,
SaveModelForBitmapInsertion
SaveModelForBitmapInsertion,
RevertPreviousOrFixErrorsManually
};
enum NotificationIcon {NoIcon, QuestionIcon, InformationIcon, WarningIcon, CriticalIcon};
NotificationsDialog(NotificationType notificationType, NotificationIcon notificationIcon, QWidget *pParent = 0);
void setNotificationLabelString(QString label);
QCheckBox* getNotificationCheckBox() {return mpNotificationCheckBox;}
QPushButton* getOkButton() {return mpOkButton;}
QPushButton* getCancelButton() {return mpCancelButton;}
QDialogButtonBox* getButtonBox() {return mpButtonBox;}
private:
Label *mpNotificationLabel;
QCheckBox *mpNotificationCheckBox;
Expand All @@ -71,8 +75,10 @@ class NotificationsDialog : public QDialog
void saveReplaceableIfPartialNotificationSettings();
void saveInnerModelNameChangedNotificationSettings();
void saveModelForBitmapInsertionNotificationSettings();
void saveAlwaysAskForTextEditorErrorSettings();
private slots:
void saveNotification();
void rejectNotification();
};

#endif // NOTIFICATIONSDIALOG_H
8 changes: 8 additions & 0 deletions OMEdit/OMEditGUI/Options/OptionsDialog.cpp
Expand Up @@ -599,6 +599,9 @@ void OptionsDialog::readNotificationsSettings()
if (mpSettings->contains("notifications/alwaysAskForDraggedComponentName")) {
mpNotificationsPage->getAlwaysAskForDraggedComponentName()->setChecked(mpSettings->value("notifications/alwaysAskForDraggedComponentName").toBool());
}
if (mpSettings->contains("notifications/alwaysAskForTextEditorError")) {
mpNotificationsPage->getAlwaysAskForTextEditorErrorCheckBox()->setChecked(mpSettings->value("notifications/alwaysAskForTextEditorError").toBool());
}
}

//! Reads the LineStyle section settings from omedit.ini
Expand Down Expand Up @@ -1087,6 +1090,7 @@ void OptionsDialog::saveNotificationsSettings()
mpSettings->setValue("notifications/innerModelNameChanged", mpNotificationsPage->getInnerModelNameChangedCheckBox()->isChecked());
mpSettings->setValue("notifications/saveModelForBitmapInsertion", mpNotificationsPage->getSaveModelForBitmapInsertionCheckBox()->isChecked());
mpSettings->setValue("notifications/alwaysAskForDraggedComponentName", mpNotificationsPage->getAlwaysAskForDraggedComponentName()->isChecked());
mpSettings->setValue("notifications/alwaysAskForTextEditorError", mpNotificationsPage->getAlwaysAskForTextEditorErrorCheckBox()->isChecked());
}

//! Saves the LineStyle section settings to omedit.ini
Expand Down Expand Up @@ -3582,6 +3586,9 @@ NotificationsPage::NotificationsPage(OptionsDialog *pOptionsDialog)
// create the save model for bitmap insertion checkbox
mpAlwaysAskForDraggedComponentName = new QCheckBox(tr("Always ask for the dragged component name"));
mpAlwaysAskForDraggedComponentName->setChecked(true);
// create the always ask for text editor error
mpAlwaysAskForTextEditorErrorCheckBox = new QCheckBox(tr("Always ask for what to do with the text editor error"));
mpAlwaysAskForTextEditorErrorCheckBox->setChecked(true);
// set the layout of notifications group
QGridLayout *pNotificationsLayout = new QGridLayout;
pNotificationsLayout->setAlignment(Qt::AlignTop);
Expand All @@ -3591,6 +3598,7 @@ NotificationsPage::NotificationsPage(OptionsDialog *pOptionsDialog)
pNotificationsLayout->addWidget(mpInnerModelNameChangedCheckBox, 3, 0);
pNotificationsLayout->addWidget(mpSaveModelForBitmapInsertionCheckBox, 4, 0);
pNotificationsLayout->addWidget(mpAlwaysAskForDraggedComponentName, 5, 0);
pNotificationsLayout->addWidget(mpAlwaysAskForTextEditorErrorCheckBox, 6, 0);
mpNotificationsGroupBox->setLayout(pNotificationsLayout);
// set the layout
QVBoxLayout *pLayout = new QVBoxLayout;
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Options/OptionsDialog.h
Expand Up @@ -659,6 +659,7 @@ class NotificationsPage : public QWidget
QCheckBox* getInnerModelNameChangedCheckBox() {return mpInnerModelNameChangedCheckBox;}
QCheckBox* getSaveModelForBitmapInsertionCheckBox() {return mpSaveModelForBitmapInsertionCheckBox;}
QCheckBox* getAlwaysAskForDraggedComponentName() {return mpAlwaysAskForDraggedComponentName;}
QCheckBox* getAlwaysAskForTextEditorErrorCheckBox() {return mpAlwaysAskForTextEditorErrorCheckBox;}
private:
OptionsDialog *mpOptionsDialog;
QGroupBox *mpNotificationsGroupBox;
Expand All @@ -668,6 +669,7 @@ class NotificationsPage : public QWidget
QCheckBox *mpInnerModelNameChangedCheckBox;
QCheckBox *mpSaveModelForBitmapInsertionCheckBox;
QCheckBox *mpAlwaysAskForDraggedComponentName;
QCheckBox *mpAlwaysAskForTextEditorErrorCheckBox;
};

class LineStylePage : public QWidget
Expand Down

0 comments on commit 1506f4d

Please sign in to comment.