Skip to content

Commit

Permalink
- Added the cancel button to the close dialog.
Browse files Browse the repository at this point in the history
- If user has clicked the close button by mistake her should be able to cancel the event.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8230 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Mar 15, 2011
1 parent 4add998 commit 3b0f70e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
42 changes: 27 additions & 15 deletions OMShell/OMShellGUI/oms.cpp
Expand Up @@ -254,8 +254,8 @@ OMS::OMS( QWidget* parent )
createMenu();
createToolbar();

connect( this, SIGNAL( emitQuit() ),
qApp, SLOT( quit() ));
// connect( this, SIGNAL( emitQuit() ),
// qApp, SLOT( quit() ));

// start server
startServer();
Expand Down Expand Up @@ -451,7 +451,7 @@ void OMS::createAction()
exit_->setShortcut( tr("Ctrl+D") );
exit_->setStatusTip( tr("Quit the application") );
connect( exit_, SIGNAL( triggered() ),
this, SLOT( exit() ));
this, SLOT( close() ));

cut_ = new QAction( QIcon(":/Resources/cut.bmp"), tr("Cu&t"), this );
cut_->setShortcut( tr("Ctrl+X") );
Expand Down Expand Up @@ -646,7 +646,7 @@ void OMS::returnPressed()
// if 'quit()' exit WinMosh
if( commandText == "quit()" )
{
exit();
close();
return;
}

Expand Down Expand Up @@ -742,7 +742,7 @@ void OMS::exceptionInEval(exception &e)
{
QMessageBox::critical( 0, tr("Communication Error"),
tr("<B>Unable to communication correctlly with OMC. OMShell will therefore close.</B>") );
exit();
close();
}
}
}
Expand Down Expand Up @@ -969,7 +969,7 @@ void OMS::loadModelicaLibrary()
returnPressed();
}

void OMS::exit()
bool OMS::exit()
{
// check if omc is running, if so: ask if it is ok that omc also closes.
try
Expand All @@ -979,23 +979,32 @@ void OMS::exit()
delegate_->closeConnection();
delegate_->reconnect();

int result = QMessageBox::question( 0, tr("Close OMC"),
"OK to quit running OpenModelica Compiler process at exit?\n(Answer No if other OMShell/OMNotebook/Graphic editor is still running)",
QMessageBox::Yes | QMessageBox::Default,
QMessageBox::No );
QMessageBox *msgBox = new QMessageBox(0);
msgBox->setWindowTitle(tr("Close OMC"));
msgBox->setIcon(QMessageBox::Question);
msgBox->setText("OK to quit running OpenModelica Compiler process at exit?\n(Answer No if other OMShell/OMNotebook/Graphic editor is still running)");
msgBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
msgBox->setDefaultButton(QMessageBox::Yes);

int result = msgBox->exec();

if( result == QMessageBox::Yes )
{
stopServer();
return true;
}
else if (result == QMessageBox::No)
{
return true;
}
else if (result == QMessageBox::Cancel)
{
return false;
}
}
}
catch(exception e)
{}



emit emitQuit();
}

void OMS::cut()
Expand Down Expand Up @@ -1198,6 +1207,9 @@ void OMS::clear()

void OMS::closeEvent( QCloseEvent *event )
{
exit();
if (exit())
event->accept();
else
event->ignore();
}

6 changes: 1 addition & 5 deletions OMShell/OMShellGUI/oms.h
Expand Up @@ -72,10 +72,6 @@ class OMS : public QMainWindow
public:
OMS( QWidget* parent = 0 );
~OMS();

signals:
void emitQuit();

public slots:
void returnPressed();
void insertNewline();
Expand All @@ -87,7 +83,7 @@ public slots:

void loadModel();
void loadModelicaLibrary();
void exit();
bool exit();
void cut();
void copy();
void paste();
Expand Down

0 comments on commit 3b0f70e

Please sign in to comment.