From 69f3f98f5a2cc573bba8733c055e3c3471c5215a Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 8 Aug 2013 11:09:18 +0200 Subject: [PATCH] Hide console on Windows Show command line help text in dialog, accessible from About menu Show command line help dialog instead of console output on Windows p4#: 22130 --- .../Application/RiaApplication.cpp | 100 ++++++++++++------ ApplicationCode/Application/RiaApplication.h | 3 + ApplicationCode/CMakeLists.txt | 6 ++ ApplicationCode/RiaMain.cpp | 26 ----- .../UserInterface/RiuMainWindow.cpp | 13 +++ ApplicationCode/UserInterface/RiuMainWindow.h | 2 + 6 files changed, 91 insertions(+), 59 deletions(-) diff --git a/ApplicationCode/Application/RiaApplication.cpp b/ApplicationCode/Application/RiaApplication.cpp index 713f016409..84979df753 100644 --- a/ApplicationCode/Application/RiaApplication.cpp +++ b/ApplicationCode/Application/RiaApplication.cpp @@ -837,42 +837,14 @@ bool RiaApplication::parseArguments() if (showHelp) { - QString helpText = QString("\n%1 v. %2\n").arg(RI_APPLICATION_NAME).arg(getVersionStringApp(false)); - helpText += "Copyright Statoil ASA, Ceetron AS 2011, 2012\n\n"; - - helpText += - "\nParameter Description\n" - "-----------------------------------------------------------------\n" - "-last Open last used project\n" - "\n" - "-project Open project file \n" - "\n" - "-case Open Eclipse case \n" - " (do not include .GRID/.EGRID)\n" - "\n" - "-startdir The default directory for open/save commands\n" - "\n" - "-savesnapshots Save snapshot of all views to 'snapshots' folder in project file folder\n" - " Application closes after snapshots are written to file\n" - "\n" - "-regressiontest Run a regression test on all sub-folders starting with \"" + RegTestNames::testFolderFilter + "\" of the given folder: \n" - " " + RegTestNames::testProjectName + " files in the sub-folders will be opened and \n" - " snapshots of all the views is written to the sub-sub-folder " + RegTestNames::generatedFolderName + ". \n" - " Then difference images is generated in the sub-sub-folder " + RegTestNames::diffFolderName + " based \n" - " on the images in sub-sub-folder " + RegTestNames::baseFolderName + ".\n" - " The results are presented in " + RegTestNames::reportFileName + " that is\n" - " written in the given folder.\n" - "\n" - "-updateregressiontestbase For all sub-folders starting with \"" + RegTestNames::testFolderFilter + "\" of the given folder: \n" - " Copy the images in the sub-sub-folder " + RegTestNames::generatedFolderName + " to the sub-sub-folder\n" - " " + RegTestNames::baseFolderName + " after deleting " + RegTestNames::baseFolderName + " completely.\n" - "\n" - "-help, -? Displays help text\n" - "-----------------------------------------------------------------"; + QString helpText = commandLineParameterHelp(); +#if defined(_MSC_VER) && defined(_WIN32) + showFormattedTextInMessageBox(helpText); +#else fprintf(stdout, "%s\n", helpText.toAscii().data()); fflush(stdout); - +#endif return false; } @@ -1578,3 +1550,65 @@ RimProject* RiaApplication::project() return m_project; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaApplication::showFormattedTextInMessageBox(const QString& text) +{ + QString helpText = text; + + QMessageBox msgBox; + msgBox.setIcon(QMessageBox::Information); + msgBox.setWindowTitle("ResInsight"); + + helpText.replace("&", "&"); + helpText.replace("<", "<"); + helpText.replace(">", ">"); + + helpText = QString("
%1
").arg(helpText); + msgBox.setText(helpText); + + msgBox.exec(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RiaApplication::commandLineParameterHelp() const +{ + QString text = QString("\n%1 v. %2\n").arg(RI_APPLICATION_NAME).arg(getVersionStringApp(false)); + text += "Copyright Statoil ASA, Ceetron AS 2011, 2012\n\n"; + + text += + "\nParameter Description\n" + "-----------------------------------------------------------------\n" + "-last Open last used project\n" + "\n" + "-project Open project file \n" + "\n" + "-case Open Eclipse case \n" + " (do not include .GRID/.EGRID)\n" + "\n" + "-startdir The default directory for open/save commands\n" + "\n" + "-savesnapshots Save snapshot of all views to 'snapshots' folder in project file folder\n" + " Application closes after snapshots are written to file\n" + "\n" + "-regressiontest Run a regression test on all sub-folders starting with \"" + RegTestNames::testFolderFilter + "\" of the given folder: \n" + " " + RegTestNames::testProjectName + " files in the sub-folders will be opened and \n" + " snapshots of all the views is written to the sub-sub-folder " + RegTestNames::generatedFolderName + ". \n" + " Then difference images is generated in the sub-sub-folder " + RegTestNames::diffFolderName + " based \n" + " on the images in sub-sub-folder " + RegTestNames::baseFolderName + ".\n" + " The results are presented in " + RegTestNames::reportFileName + " that is\n" + " written in the given folder.\n" + "\n" + "-updateregressiontestbase For all sub-folders starting with \"" + RegTestNames::testFolderFilter + "\" of the given folder: \n" + " Copy the images in the sub-sub-folder " + RegTestNames::generatedFolderName + " to the sub-sub-folder\n" + " " + RegTestNames::baseFolderName + " after deleting " + RegTestNames::baseFolderName + " completely.\n" + "\n" + "-help, -? Displays help text\n" + "-----------------------------------------------------------------"; + + return text; +} + diff --git a/ApplicationCode/Application/RiaApplication.h b/ApplicationCode/Application/RiaApplication.h index 47c10e12f2..a1ae026aff 100644 --- a/ApplicationCode/Application/RiaApplication.h +++ b/ApplicationCode/Application/RiaApplication.h @@ -125,6 +125,9 @@ public: cvf::Font* standardFont(); + QString commandLineParameterHelp() const; + void showFormattedTextInMessageBox(const QString& text); + private: void onProjectOpenedOrClosed(); void setWindowCaptionFromAppState(); diff --git a/ApplicationCode/CMakeLists.txt b/ApplicationCode/CMakeLists.txt index 5ef2cbb908..9e8ba02454 100644 --- a/ApplicationCode/CMakeLists.txt +++ b/ApplicationCode/CMakeLists.txt @@ -237,6 +237,12 @@ endif() target_link_libraries( ResInsight ${LINK_LIBRARIES} ${EXTERNAL_LINK_LIBRARIES}) +if(WIN32) # Check if we are on Windows + if(MSVC) # Check if we are using the Visual Studio compiler + set_target_properties(ResInsight PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS") + endif() +ENDIF() + # Copy Dlls if (MSVC) diff --git a/ApplicationCode/RiaMain.cpp b/ApplicationCode/RiaMain.cpp index 43262ced32..b930b3449f 100644 --- a/ApplicationCode/RiaMain.cpp +++ b/ApplicationCode/RiaMain.cpp @@ -21,32 +21,6 @@ #include "RiuMainWindow.h" -// Cmake is able to control subsystem on Windows using the following method http://www.cmake.org/Wiki/VSConfigSpecificSettings -// -// if(WIN32) -// set_target_properties(WindowApplicationExample PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE") -// set_target_properties(WindowApplicationExample PROPERTIES COMPILE_DEFINITIONS_DEBUG "_CONSOLE") -// set_target_properties(WindowApplicationExample PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:CONSOLE") -// set_target_properties(WindowApplicationExample PROPERTIES COMPILE_DEFINITIONS_RELWITHDEBINFO "_CONSOLE") -// set_target_properties(WindowApplicationExample PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS") -// set_target_properties(WindowApplicationExample PROPERTIES LINK_FLAGS_MINSIZEREL "/SUBSYSTEM:WINDOWS") -// endif(WIN32) -// -// -// Due to a bug in Cmake, use workaround described here http://public.kitware.com/Bug/view.php?id=12566 -#if defined(_MSC_VER) && defined(_WIN32) - - #ifdef _DEBUG - #pragma comment(linker, "/SUBSYSTEM:CONSOLE") - #else - #pragma comment(linker, "/SUBSYSTEM:WINDOWS") - #endif // _DEBUG - -#endif // defined(_MSC_VER) && defined(_WIN32) - - - - int main(int argc, char *argv[]) { RiaApplication app(argc, argv); diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index bde850085f..7a26780d9a 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -267,6 +267,8 @@ void RiuMainWindow::createActions() // Help actions m_aboutAction = new QAction("&About", this); connect(m_aboutAction, SIGNAL(triggered()), SLOT(slotAbout())); + m_commandLineHelpAction = new QAction("&Command Line Help", this); + connect(m_commandLineHelpAction, SIGNAL(triggered()), SLOT(slotShowCommandLineHelp())); // Draw style actions m_dsActionGroup = new QActionGroup(this); @@ -365,6 +367,7 @@ void RiuMainWindow::createMenus() // Help menu QMenu* helpMenu = menuBar()->addMenu("&Help"); helpMenu->addAction(m_aboutAction); + helpMenu->addAction(m_commandLineHelpAction); } @@ -1647,3 +1650,13 @@ void RiuMainWindow::slotImportWellPathsFromSSIHub() if (app->project()) app->project()->createDisplayModelAndRedrawAllViews(); } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuMainWindow::slotShowCommandLineHelp() +{ + RiaApplication* app = RiaApplication::instance(); + QString text = app->commandLineParameterHelp(); + app->showFormattedTextInMessageBox(text); +} diff --git a/ApplicationCode/UserInterface/RiuMainWindow.h b/ApplicationCode/UserInterface/RiuMainWindow.h index 032d3f5992..20abcd2176 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.h +++ b/ApplicationCode/UserInterface/RiuMainWindow.h @@ -156,6 +156,7 @@ private: // Help actions QAction* m_aboutAction; + QAction* m_commandLineHelpAction; // Animation caf::AnimationToolBar* m_animationToolBar; @@ -231,6 +232,7 @@ private slots: // Help slots void slotAbout(); + void slotShowCommandLineHelp(); void slotSubWindowActivated(QMdiSubWindow* subWindow); void slotCurrentChanged(const QModelIndex & current, const QModelIndex & previous);