Skip to content

Commit

Permalink
Fix for #3404. Menu options to open working directory and terminal.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Dec 4, 2015
1 parent 405ec94 commit c43a7c5
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 37 deletions.
56 changes: 54 additions & 2 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -904,9 +904,9 @@ void MainWindow::fetchInterfaceData(LibraryTreeItem *pLibraryTreeItem)
if (mpOptionsDialog->getTLMPage()->getTLMManagerProcessTextBox()->text().isEmpty()) {
QString message;
#ifdef Q_OS_MAC
message = GUIMessages::getMessage(GUIMessages::TLMMANAGER_NOT_SET).arg(GUIMessages::getMessage(GUIMessages::TLMMANAGER_NOT_SET_MSG_MAC));
message = GUIMessages::getMessage(GUIMessages::TLMMANAGER_NOT_SET).arg(Helper::toolsOptionsPathMAC);
#else
message = GUIMessages::getMessage(GUIMessages::TLMMANAGER_NOT_SET).arg(GUIMessages::getMessage(GUIMessages::TLMMANAGER_NOT_SET_MSG));
message = GUIMessages::getMessage(GUIMessages::TLMMANAGER_NOT_SET).arg(Helper::toolsOptionsPath);
#endif
QMessageBox::information(this, QString(Helper::applicationName).append(" - ").append(Helper::information), message, Helper::ok);
} else {
Expand Down Expand Up @@ -1964,6 +1964,47 @@ void MainWindow::TLMSimulate()
}
}

/*!
* \brief MainWindow::openWorkingDirectory
* Opens the current working directory.
*/
void MainWindow::openWorkingDirectory()
{
QUrl workingDirectory (QString("file:///%1").arg(mpOptionsDialog->getGeneralSettingsPage()->getWorkingDirectory()));
if (!QDesktopServices::openUrl(workingDirectory)) {
mpMessagesWidget->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0,
GUIMessages::getMessage(GUIMessages::UNABLE_TO_OPEN_FILE).arg(workingDirectory.toString()),
Helper::scriptingKind, Helper::errorLevel));
}
}

/*!
* \brief MainWindow::openTerminal
* Opens the terminal.
*/
void MainWindow::openTerminal()
{
QString terminalCommand = mpOptionsDialog->getGeneralSettingsPage()->getTerminalCommand();
if (terminalCommand.isEmpty()) {
QString message;
#ifdef Q_OS_MAC
message = GUIMessages::getMessage(GUIMessages::TERMINAL_COMMAND_NOT_SET).arg(Helper::toolsOptionsPathMAC);
#else
message = GUIMessages::getMessage(GUIMessages::TERMINAL_COMMAND_NOT_SET).arg(Helper::toolsOptionsPath);
#endif
mpMessagesWidget->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, message, Helper::scriptingKind,
Helper::errorLevel));
return;
}
QString arguments = mpOptionsDialog->getGeneralSettingsPage()->getTerminalCommandArguments();
QStringList args = arguments.split(" ");
if (!QProcess::startDetached(terminalCommand, args, mpOptionsDialog->getGeneralSettingsPage()->getWorkingDirectory())) {
QString errorString = tr("Unable to run terminal command <b>%1</b> with arguments <b>%2</b>.").arg(terminalCommand).arg(arguments);
mpMessagesWidget->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, errorString, Helper::scriptingKind,
Helper::errorLevel));
}
}

/*!
* \brief MainWindow::openConfigurationOptions
* Slot activated when mpOptionsAction triggered signal is raised.
Expand Down Expand Up @@ -2553,6 +2594,14 @@ void MainWindow::createActions()
mpImportNgspiceNetlistAction = new QAction(Helper::importNgspiceNetlist, this);
mpImportNgspiceNetlistAction->setStatusTip(Helper::importNgspiceNetlistTip);
connect(mpImportNgspiceNetlistAction, SIGNAL(triggered()), SLOT(importNgspiceNetlist()));
// open working directory action
mpOpenWorkingDirectoryAction = new QAction(tr("Open Working Directory"), this);
mpOpenWorkingDirectoryAction->setStatusTip(tr("Opens the current working directory"));
connect(mpOpenWorkingDirectoryAction, SIGNAL(triggered()), SLOT(openWorkingDirectory()));
// open terminal action
mpOpenTerminalAction = new QAction(tr("Open Terminal"), this);
mpOpenTerminalAction->setStatusTip(tr("Opens the terminal"));
connect(mpOpenTerminalAction, SIGNAL(triggered()), SLOT(openTerminal()));
// open options action
mpOptionsAction = new QAction(QIcon(":/Resources/icons/options.svg"), tr("Options"), this);
mpOptionsAction->setStatusTip(tr("Shows the options window"));
Expand Down Expand Up @@ -2830,6 +2879,9 @@ void MainWindow::createMenus()
pToolsMenu->addSeparator();
pToolsMenu->addAction(mpImportNgspiceNetlistAction);
pToolsMenu->addSeparator();
pToolsMenu->addAction(mpOpenWorkingDirectoryAction);
pToolsMenu->addAction(mpOpenTerminalAction);
pToolsMenu->addSeparator();
pToolsMenu->addAction(mpOptionsAction);
// add Tools menu to menu bar
menuBar()->addAction(pToolsMenu->menuAction());
Expand Down
4 changes: 4 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -278,6 +278,8 @@ class MainWindow : public QMainWindow
QAction *mpExportToOMNotebookAction;
QAction *mpImportFromOMNotebookAction;
QAction *mpImportNgspiceNetlistAction;
QAction *mpOpenWorkingDirectoryAction;
QAction *mpOpenTerminalAction;
QAction *mpOptionsAction;
// Help Menu
QAction *mpUsersGuideAction;
Expand Down Expand Up @@ -373,6 +375,8 @@ public slots:
void exportToClipboard();
void fetchInterfaceData();
void TLMSimulate();
void openWorkingDirectory();
void openTerminal();
void openConfigurationOptions();
void openUsersGuide();
void openUsersGuidePdf();
Expand Down
55 changes: 53 additions & 2 deletions OMEdit/OMEditGUI/Options/OptionsDialog.cpp
Expand Up @@ -119,6 +119,14 @@ void OptionsDialog::readGeneralSettings()
if (mpSettings->contains("userCustomizations")) {
mpGeneralSettingsPage->setPreserveUserCustomizations(mpSettings->value("userCustomizations").toBool());
}
// read the terminal command
if (mpSettings->contains("terminalCommand")) {
mpGeneralSettingsPage->setTerminalCommand(mpSettings->value("terminalCommand").toString());
}
// read the terminal command arguments
if (mpSettings->contains("terminalCommandArgs")) {
mpGeneralSettingsPage->setTerminalCommandArguments(mpSettings->value("terminalCommandArgs").toString());
}
// read library icon size
if (mpSettings->contains("libraryIconSize")) {
mpGeneralSettingsPage->getLibraryIconSizeSpinBox()->setValue(mpSettings->value("libraryIconSize").toInt());
Expand Down Expand Up @@ -601,6 +609,10 @@ void OptionsDialog::saveGeneralSettings()
mpSettings->setValue("toolbarIconSize", mpGeneralSettingsPage->getToolbarIconSizeSpinBox()->value());
// save user customizations
mpSettings->setValue("userCustomizations", mpGeneralSettingsPage->getPreserveUserCustomizations());
// save terminal command
mpSettings->setValue("terminalCommand", mpGeneralSettingsPage->getTerminalCommand());
// save terminal command arguments
mpSettings->setValue("terminalCommandArgs", mpGeneralSettingsPage->getTerminalCommandArguments());
// save library icon size
mpSettings->setValue("libraryIconSize", mpGeneralSettingsPage->getLibraryIconSizeSpinBox()->value());
// save show protected classes
Expand Down Expand Up @@ -1160,6 +1172,22 @@ GeneralSettingsPage::GeneralSettingsPage(OptionsDialog *pOptionsDialog)
mpToolbarIconSizeSpinBox->setValue(24);
// Store Customizations Option
mpPreserveUserCustomizations = new QCheckBox(tr("Preserve User's GUI Customizations"));
// terminal command
mpTerminalCommandLabel = new Label(tr("Terminal Command:"));
mpTerminalCommandTextBox = new QLineEdit;
#ifdef Q_OS_WIN32
mpTerminalCommandTextBox->setText("cmd.exe");
#elif Q_OS_MAC
mpTerminalCommandTextBox->setText("");
#else
mpTerminalCommandTextBox->setText("");
#endif
mpTerminalCommandBrowseButton = new QPushButton(Helper::browse);
mpTerminalCommandBrowseButton->setAutoDefault(false);
connect(mpTerminalCommandBrowseButton, SIGNAL(clicked()), SLOT(selectTerminalCommand()));
// terminal command args
mpTerminalCommandArgumentsLabel = new Label(tr("Terminal Command Arguments:"));
mpTerminalCommandArgumentsTextBox = new QLineEdit;
// set the layout of general settings group
QGridLayout *generalSettingsLayout = new QGridLayout;
generalSettingsLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
Expand All @@ -1171,6 +1199,11 @@ GeneralSettingsPage::GeneralSettingsPage(OptionsDialog *pOptionsDialog)
generalSettingsLayout->addWidget(mpToolbarIconSizeLabel, 2, 0);
generalSettingsLayout->addWidget(mpToolbarIconSizeSpinBox, 2, 1, 1, 2);
generalSettingsLayout->addWidget(mpPreserveUserCustomizations, 3, 0, 1, 3);
generalSettingsLayout->addWidget(mpTerminalCommandLabel, 4, 0);
generalSettingsLayout->addWidget(mpTerminalCommandTextBox, 4, 1);
generalSettingsLayout->addWidget(mpTerminalCommandBrowseButton, 4, 2);
generalSettingsLayout->addWidget(mpTerminalCommandArgumentsLabel, 5, 0);
generalSettingsLayout->addWidget(mpTerminalCommandArgumentsTextBox, 5, 1, 1, 2);
mpGeneralSettingsGroupBox->setLayout(generalSettingsLayout);
// Libraries Browser group box
mpLibrariesBrowserGroupBox = new QGroupBox(tr("Libraries Browser"));
Expand Down Expand Up @@ -1421,13 +1454,31 @@ QCheckBox* GeneralSettingsPage::getShowLatestNewsCheckBox()
return mpShowLatestNewsCheckBox;
}

//! Slot activated when mpWorkingDirectoryBrowseButton clicked signal is raised.
//! Allows user to choose a new working directory.
/*!
* \brief GeneralSettingsPage::selectWorkingDirectory
* Slot activated when mpWorkingDirectoryBrowseButton clicked signal is raised.
* Allows user to choose a new working directory.
*/
void GeneralSettingsPage::selectWorkingDirectory()
{
mpWorkingDirectoryTextBox->setText(StringHandler::getExistingDirectory(this, QString(Helper::applicationName).append(" - ").append(Helper::chooseDirectory), NULL));
}

/*!
* \brief GeneralSettingsPage::selectTerminalCommand
* Slot activated when mpTerminalCommandBrowseButton clicked signal is raised.
* Allows user to select a new terminal command.
*/
void GeneralSettingsPage::selectTerminalCommand()
{
mpTerminalCommandTextBox->setText(StringHandler::getOpenFileName(this, QString("%1 - %2").arg(Helper::applicationName).arg(Helper::chooseFile), NULL, NULL, NULL));
}

/*!
* \brief GeneralSettingsPage::autoSaveIntervalValueChanged
* Slot activated when mpAutoSaveIntervalSpinBox valueChanged signal is raised.
* \param value
*/
void GeneralSettingsPage::autoSaveIntervalValueChanged(int value)
{
mpAutoSaveSecondsLabel->setText(tr("(%1 minute(s))").arg((double)value/60));
Expand Down
10 changes: 10 additions & 0 deletions OMEdit/OMEditGUI/Options/OptionsDialog.h
Expand Up @@ -165,6 +165,10 @@ class GeneralSettingsPage : public QWidget
QSpinBox* getToolbarIconSizeSpinBox() {return mpToolbarIconSizeSpinBox;}
void setPreserveUserCustomizations(bool value);
bool getPreserveUserCustomizations();
void setTerminalCommand(QString value) {mpTerminalCommandTextBox->setText(value);}
QString getTerminalCommand() {return mpTerminalCommandTextBox->text();}
void setTerminalCommandArguments(QString value) {mpTerminalCommandArgumentsTextBox->setText(value);}
QString getTerminalCommandArguments() {return mpTerminalCommandArgumentsTextBox->text();}
QSpinBox* getLibraryIconSizeSpinBox() {return mpLibraryIconSizeSpinBox;}
void setShowProtectedClasses(bool value);
bool getShowProtectedClasses();
Expand All @@ -190,6 +194,11 @@ class GeneralSettingsPage : public QWidget
Label *mpToolbarIconSizeLabel;
QSpinBox *mpToolbarIconSizeSpinBox;
QCheckBox *mpPreserveUserCustomizations;
Label *mpTerminalCommandLabel;
QLineEdit *mpTerminalCommandTextBox;
QPushButton *mpTerminalCommandBrowseButton;
Label *mpTerminalCommandArgumentsLabel;
QLineEdit *mpTerminalCommandArgumentsTextBox;
QGroupBox *mpLibrariesBrowserGroupBox;
Label *mpLibraryIconSizeLabel;
QSpinBox *mpLibraryIconSizeSpinBox;
Expand All @@ -214,6 +223,7 @@ class GeneralSettingsPage : public QWidget
QCheckBox *mpShowLatestNewsCheckBox;
public slots:
void selectWorkingDirectory();
void selectTerminalCommand();
void autoSaveIntervalValueChanged(int value);
};

Expand Down
Expand Up @@ -929,13 +929,9 @@ void TransformationsWidget::fetchOperations(const OMVariable &variable)
} else {
QString message;
#ifdef Q_OS_MAC
message = GUIMessages::getMessage(GUIMessages::SET_INFO_XML_FLAG)
.arg(GUIMessages::getMessage(GUIMessages::GENERATE_OPERATIONS_MSG_MAC))
.arg(GUIMessages::getMessage(GUIMessages::SET_INFO_XML_FLAG_MSG_MAC));
message = GUIMessages::getMessage(GUIMessages::SET_INFO_XML_FLAG).arg(Helper::toolsOptionsPathMAC).arg(Helper::toolsOptionsPathMAC);
#else
message = GUIMessages::getMessage(GUIMessages::SET_INFO_XML_FLAG)
.arg(GUIMessages::getMessage(GUIMessages::GENERATE_OPERATIONS_MSG))
.arg(GUIMessages::getMessage(GUIMessages::SET_INFO_XML_FLAG_MSG));
message = GUIMessages::getMessage(GUIMessages::SET_INFO_XML_FLAG).arg(Helper::toolsOptionsPath).arg(Helper::toolsOptionsPath);
#endif
QStringList values;
values << message;
Expand Down Expand Up @@ -1130,13 +1126,9 @@ void TransformationsWidget::fetchOperations(OMEquation *equation)
} else {
QString message;
#ifdef Q_OS_MAC
message = GUIMessages::getMessage(GUIMessages::SET_INFO_XML_FLAG)
.arg(GUIMessages::getMessage(GUIMessages::GENERATE_OPERATIONS_MSG_MAC))
.arg(GUIMessages::getMessage(GUIMessages::SET_INFO_XML_FLAG_MSG_MAC));
message = GUIMessages::getMessage(GUIMessages::SET_INFO_XML_FLAG).arg(Helper::toolsOptionsPathMAC).arg(Helper::toolsOptionsPathMAC);
#else
message = GUIMessages::getMessage(GUIMessages::SET_INFO_XML_FLAG)
.arg(GUIMessages::getMessage(GUIMessages::GENERATE_OPERATIONS_MSG))
.arg(GUIMessages::getMessage(GUIMessages::SET_INFO_XML_FLAG_MSG));
message = GUIMessages::getMessage(GUIMessages::SET_INFO_XML_FLAG).arg(Helper::toolsOptionsPath).arg(Helper::toolsOptionsPath);
#endif
QStringList values;
values << message;
Expand Down
20 changes: 6 additions & 14 deletions OMEdit/OMEditGUI/Util/Helper.cpp
Expand Up @@ -92,6 +92,8 @@ QString Helper::textOutput = "Text";
QString Helper::utf8 = "UTF-8";
QFontInfo Helper::systemFontInfo = QFontInfo(QFont());
QFontInfo Helper::monospacedFontInfo = QFontInfo(QFont());
QString Helper::toolsOptionsPath = "Tools->Options";
QString Helper::toolsOptionsPathMAC = "OMEdit->Preferences";
/* Meta Modelica Types */
QString Helper::MODELICA_METATYPE = QString("modelica_metatype");
QString Helper::MODELICA_STRING = QString("modelica_string");
Expand Down Expand Up @@ -573,15 +575,7 @@ QString GUIMessages::getMessage(int type)
case WRONG_MODIFIER:
return tr("The Modifier <b>%1</b> format is invalid. The correct format is <b>phi(start=1)</b>");
case SET_INFO_XML_FLAG:
return tr("The operations were not generated. Check Generate Operations in %1 OR you must set the +d=infoXmlOperations flag via %2 and simulate again.");
case GENERATE_OPERATIONS_MSG:
return tr("Tools->Options->Debugger->Transformational Debugger");
case GENERATE_OPERATIONS_MSG_MAC:
return tr("OMEdit->Preferences->Debugger->Transformational Debugger");
case SET_INFO_XML_FLAG_MSG:
return tr("Tools->Options->Simulation->OMC Flags");
case SET_INFO_XML_FLAG_MSG_MAC:
return tr("OMEdit->Preferences->Simulation->OMC Flags");
return tr("The operations were not generated. Check Generate Operations in <b>%1->Debugger->Transformational Debugger</b> OR you must set the +d=infoXmlOperations flag via <b>%2->Simulation->OMC Flags</b> and simulate again.");
case DEBUG_CONFIGURATION_EXISTS_MSG:
return tr("A debug configuration with name <b>%1</b> already exists. Error occurred while saving the debug configuration <b>%2<b>.");
case DEBUG_CONFIGURATION_SIZE_EXCEED:
Expand All @@ -597,15 +591,13 @@ QString GUIMessages::getMessage(int type)
case BREAKPOINT_INSERT_NOT_MODELICA_CLASS:
return tr("The class <b>%1</b> is not a modelica class. Breakpoints are only allowed on modelica classes.");
case TLMMANAGER_NOT_SET:
return tr("TLM Manager executable path is not set. Set it via <b>%1</b>");
case TLMMANAGER_NOT_SET_MSG:
return tr("Tools->Options->TLM");
case TLMMANAGER_NOT_SET_MSG_MAC:
return tr("OMEdit->Preferences->TLM");
return tr("TLM Manager executable path is not set. Set it via <b>%1->TLM</b>");
case METAMODEL_UNSAVED:
return tr("Metamodel <b>%1</b> has unsaved changes. Do you want to save?");
case TLMCOSIMULATION_ALREADY_RUNNING:
return tr("TLM co-simulation session is already running. Only one session is allowed.");
case TERMINAL_COMMAND_NOT_SET:
return tr("Terminal command is not set. You can define a new terminal command in <b>%1->General->Terminal Command</b>.");
default:
return "";
}
Expand Down
11 changes: 4 additions & 7 deletions OMEdit/OMEditGUI/Util/Helper.h
Expand Up @@ -99,6 +99,8 @@ class Helper : public QObject
static QString utf8;
static QFontInfo systemFontInfo;
static QFontInfo monospacedFontInfo;
static QString toolsOptionsPath;
static QString toolsOptionsPathMAC;
/* Meta Modelica Types */
static QString MODELICA_METATYPE;
static QString MODELICA_STRING;
Expand Down Expand Up @@ -352,10 +354,6 @@ class GUIMessages : public QObject
DELETE_TEXT_FILE_MSG,
WRONG_MODIFIER,
SET_INFO_XML_FLAG,
GENERATE_OPERATIONS_MSG,
GENERATE_OPERATIONS_MSG_MAC,
SET_INFO_XML_FLAG_MSG,
SET_INFO_XML_FLAG_MSG_MAC,
DEBUG_CONFIGURATION_EXISTS_MSG,
DEBUG_CONFIGURATION_SIZE_EXCEED,
DELETE_DEBUG_CONFIGURATION_MSG,
Expand All @@ -364,10 +362,9 @@ class GUIMessages : public QObject
BREAKPOINT_INSERT_NOT_SAVED,
BREAKPOINT_INSERT_NOT_MODELICA_CLASS,
TLMMANAGER_NOT_SET,
TLMMANAGER_NOT_SET_MSG,
TLMMANAGER_NOT_SET_MSG_MAC,
METAMODEL_UNSAVED,
TLMCOSIMULATION_ALREADY_RUNNING
TLMCOSIMULATION_ALREADY_RUNNING,
TERMINAL_COMMAND_NOT_SET
};

static QString getMessage(int type);
Expand Down

0 comments on commit c43a7c5

Please sign in to comment.