From fa10e39d8184c48f7e2b1cdf2f8ab873f97512f7 Mon Sep 17 00:00:00 2001 From: Martyn Gigg Date: Wed, 30 Jan 2013 13:18:38 +0000 Subject: [PATCH] Use native save dialogs for OSX running 10.6 package on 10.8. Re #6497 This changes all uses of getSaveFileName to a custom handler that we already had so that we can switch to Qt dialogs where necessary. --- .../MantidPlot/src/ApplicationWindow.cpp | 13 +++++---- Code/Mantid/MantidPlot/src/FitDialog.cpp | 7 +++-- .../src/Mantid/AlgorithmHistoryWindow.cpp | 3 +- .../InstrumentWidget/InstrumentWindow.cpp | 8 +++-- .../InstrumentWindowMaskTab.cpp | 4 ++- Code/Mantid/MantidPlot/src/Note.cpp | 3 +- Code/Mantid/MantidPlot/src/TextFileIO.cpp | 4 ++- .../API/inc/MantidQtAPI/FileDialogHandler.h | 29 ++++++++++++++++--- .../MantidQt/API/src/FilePropertyWidget.cpp | 4 +-- .../Mantid/MantidQt/API/src/UserSubWindow.cpp | 3 +- .../CustomInterfaces/src/MuonAnalysis.cpp | 2 +- .../CustomInterfaces/src/SANSRunWindow.cpp | 2 +- .../src/ProcessingAlgoWidget.cpp | 4 +-- .../MantidWidgets/src/ScriptEditor.cpp | 3 +- .../MantidQt/SliceViewer/src/SliceViewer.cpp | 3 +- 15 files changed, 64 insertions(+), 28 deletions(-) diff --git a/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp b/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp index 79ec600f882b..b74ce8416e44 100644 --- a/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp +++ b/Code/Mantid/MantidPlot/src/ApplicationWindow.cpp @@ -184,6 +184,7 @@ #include "Mantid/FirstTimeSetup.h" #include "Mantid/SetUpParaview.h" +#include "MantidQtAPI/FileDialogHandler.h" #include "MantidQtAPI/InterfaceManager.h" #include "MantidQtAPI/UserSubWindow.h" #include "MantidQtAPI/AlgorithmInputHistory.h" @@ -6060,7 +6061,7 @@ void ApplicationWindow::savetoNexusFile() if(fileDir.isEmpty()) {fileDir="C\\Mantid\\Test\\Nexus"; } - QString fileName = QFileDialog::getSaveFileName(this, tr("Save File As"), fileDir, filter, &selectedFilter); + QString fileName = MantidQt::API::FileDialogHandler::getSaveFileName(this, tr("Save File As"), fileDir, filter, &selectedFilter); if ( !fileName.isEmpty() ){ std::string wsName; MdiSubWindow *w = activeWindow(); @@ -6119,7 +6120,7 @@ void ApplicationWindow::saveProjectAs(const QString& fileName, bool compress) filter += tr("Compressed MantidPlot project")+" (*.mantid.gz)"; QString selectedFilter; - fn = QFileDialog::getSaveFileName(this, tr("Save Project As"), workingDir, filter, &selectedFilter); + fn = MantidQt::API::FileDialogHandler::getSaveFileName(this, tr("Save Project As"), workingDir, filter, &selectedFilter); if (selectedFilter.contains(".gz")) compress = true; } @@ -6199,7 +6200,7 @@ void ApplicationWindow::saveAsTemplate(MdiSubWindow* w, const QString& fileName) filter = tr("MantidPlot 3D Surface Template")+" (*.qst)"; QString selectedFilter; - fn = QFileDialog::getSaveFileName(this, tr("Save Window As Template"), templatesDir + "/" + w->objectName(), filter, &selectedFilter); + fn = MantidQt::API::FileDialogHandler::getSaveFileName(this, tr("Save Window As Template"), templatesDir + "/" + w->objectName(), filter, &selectedFilter); if (!fn.isEmpty()){ QFileInfo fi(fn); @@ -6528,7 +6529,7 @@ void ApplicationWindow::exportASCII(const QString& tableName, const QString& sep return; QString selectedFilter; - QString fname = QFileDialog::getSaveFileName(this, tr("Choose a filename to save under"), + QString fname = MantidQt::API::FileDialogHandler::getSaveFileName(this, tr("Choose a filename to save under"), asciiDirPath + "/" + w->objectName(), "*.txt;;*.dat;;*.DAT", &selectedFilter); if (!fname.isEmpty() ){ QFileInfo fi(fname); @@ -7567,7 +7568,7 @@ void ApplicationWindow::exportPDF() return; } - QString fname = QFileDialog::getSaveFileName(this, tr("Choose a filename to save under"), workingDir, "*.pdf"); + QString fname = MantidQt::API::FileDialogHandler::getSaveFileName(this, tr("Choose a filename to save under"), workingDir, "*.pdf"); if (!fname.isEmpty() ){ QFileInfo fi(fname); QString baseName = fi.fileName(); @@ -15220,7 +15221,7 @@ void ApplicationWindow::saveFolderAsProject(Folder *f) filter += tr("Compressed MantidPlot project")+" (*.qti.gz)"; QString selectedFilter; - QString fn = QFileDialog::getSaveFileName(this, tr("Save project as"), workingDir, filter, &selectedFilter); + QString fn = MantidQt::API::FileDialogHandler::getSaveFileName(this, tr("Save project as"), workingDir, filter, &selectedFilter); if ( !fn.isEmpty() ){ QFileInfo fi(fn); workingDir = fi.dirPath(true); diff --git a/Code/Mantid/MantidPlot/src/FitDialog.cpp b/Code/Mantid/MantidPlot/src/FitDialog.cpp index 64da500bfd89..70229d001a66 100644 --- a/Code/Mantid/MantidPlot/src/FitDialog.cpp +++ b/Code/Mantid/MantidPlot/src/FitDialog.cpp @@ -64,6 +64,9 @@ #include +#include "MantidQtAPI/FileDialogHandler.h" + + FitDialog::FitDialog(Graph *g, QWidget* parent, Qt::WFlags fl ) : QDialog( parent, fl ) { @@ -621,7 +624,7 @@ void FitDialog::saveUserFunction() ApplicationWindow *app = dynamic_cast(this->parent()); QString filter = tr("MantidPlot fit model")+" (*.fit);;"; filter += tr("All files")+" (*.*)"; - QString fn = QFileDialog::getSaveFileName(app, tr("MantidPlot") + " - " + tr("Save Fit Model As"), + QString fn = MantidQt::API::FileDialogHandler::getSaveFileName(app, tr("MantidPlot") + " - " + tr("Save Fit Model As"), app->fitModelsPath + "/" + name, filter); if (!fn.isEmpty()){ QFileInfo fi(fn); @@ -1359,7 +1362,7 @@ void FitDialog::saveInitialGuesses() ApplicationWindow *app = dynamic_cast(this->parent()); QString filter = tr("MantidPlot fit model") + " (*.fit);;"; filter += tr("All files") + " (*.*)"; - QString fn = QFileDialog::getSaveFileName(app, tr("MantidPlot") + " - " + tr("Save Fit Model As"), + QString fn = MantidQt::API::FileDialogHandler::getSaveFileName(app, tr("MantidPlot") + " - " + tr("Save Fit Model As"), app->fitModelsPath + "/" + d_current_fit->objectName(), filter); if (!fn.isEmpty()){ QFileInfo fi(fn); diff --git a/Code/Mantid/MantidPlot/src/Mantid/AlgorithmHistoryWindow.cpp b/Code/Mantid/MantidPlot/src/Mantid/AlgorithmHistoryWindow.cpp index 6d1693175a41..8cbcbffc34f2 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/AlgorithmHistoryWindow.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/AlgorithmHistoryWindow.cpp @@ -2,6 +2,7 @@ #include "MantidAPI/AlgorithmManager.h" #include "MantidQtAPI/AlgorithmInputHistory.h" +#include "MantidQtAPI/FileDialogHandler.h" #include #include @@ -300,7 +301,7 @@ void AlgorithmHistoryWindow::writeToScriptFile() { scriptDir = prevDir; } - QString filePath = QFileDialog::getSaveFileName(this,tr("Save Script As "),scriptDir,tr("Script files (*.py)")); + QString filePath = MantidQt::API::FileDialogHandler::getSaveFileName(this,tr("Save Script As "),scriptDir,tr("Script files (*.py)")); // An empty string indicates they clicked cancel if( filePath.isEmpty() ) return; diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp index beb3e9622647..de989e907778 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp @@ -42,6 +42,8 @@ #include #include +#include "MantidQtAPI/FileDialogHandler.h" + #include #include #include @@ -679,7 +681,7 @@ void InstrumentWindow::saveImage() } } QString selectedFilter = "*.png"; - QString filename = QFileDialog::getSaveFileName(this, "Save image ...", m_savedialog_dir, filter, &selectedFilter); + QString filename = MantidQt::API::FileDialogHandler::getSaveFileName(this, "Save image ...", m_savedialog_dir, filter, &selectedFilter); // If its empty, they cancelled the dialog if( filename.isEmpty() ) return; @@ -1073,7 +1075,7 @@ void InstrumentWindow::sumDetsToWorkspace() void InstrumentWindow::createIncludeGroupingFile() { - QString fname = QFileDialog::getSaveFileName(this,"Save grouping file"); + QString fname = MantidQt::API::FileDialogHandler::getSaveFileName(this,"Save grouping file"); if (!fname.isEmpty()) { DetXMLFile mapFile(m_selectedDetectors,DetXMLFile::Sum,fname); @@ -1083,7 +1085,7 @@ void InstrumentWindow::createIncludeGroupingFile() void InstrumentWindow::createExcludeGroupingFile() { - QString fname = QFileDialog::getSaveFileName(this,"Save grouping file"); + QString fname = MantidQt::API::FileDialogHandler::getSaveFileName(this,"Save grouping file"); if (!fname.isEmpty()) { DetXMLFile mapFile(m_instrumentActor->getAllDetIDs(),m_selectedDetectors,fname); diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowMaskTab.cpp b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowMaskTab.cpp index 375ec3816230..399b639d4742 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowMaskTab.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowMaskTab.cpp @@ -43,6 +43,8 @@ #include #include +#include "MantidQtAPI/FileDialogHandler.h" + #include #include #include @@ -490,7 +492,7 @@ void InstrumentWindowMaskTab::saveMaskingToFile(bool invertMask) { clearShapes(); QString saveDir = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory")); - QString fileName = QFileDialog::getSaveFileName(m_instrWindow,"Select location and name for the mask file",saveDir,"XML files (*.xml)"); + QString fileName = MantidQt::API::FileDialogHandler::getSaveFileName(m_instrWindow,"Select location and name for the mask file",saveDir,"XML files (*.xml)"); if (!fileName.isEmpty()) { diff --git a/Code/Mantid/MantidPlot/src/Note.cpp b/Code/Mantid/MantidPlot/src/Note.cpp index 9dc4eb9e9e8f..8ebad8b19008 100644 --- a/Code/Mantid/MantidPlot/src/Note.cpp +++ b/Code/Mantid/MantidPlot/src/Note.cpp @@ -36,6 +36,7 @@ #include #include #include "MantidKernel/ConfigService.h" +#include "MantidQtAPI/FileDialogHandler.h" Note::Note(const QString& label, ApplicationWindow* parent, const QString& name, Qt::WFlags f) : MdiSubWindow(parent, label, name, f) @@ -124,7 +125,7 @@ QString Note::exportASCII(const QString &filename) if (filename.isEmpty()) { QString dir(Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory").c_str()); - fn = QFileDialog::getSaveFileName(this, tr("Save Text to File"),dir,filter, &selectedFilter); + fn = MantidQt::API::FileDialogHandler::getSaveFileName(this, tr("Save Text to File"),dir,filter, &selectedFilter); } else fn = filename; diff --git a/Code/Mantid/MantidPlot/src/TextFileIO.cpp b/Code/Mantid/MantidPlot/src/TextFileIO.cpp index d65e9ef51ab8..c1f6c4094bc9 100644 --- a/Code/Mantid/MantidPlot/src/TextFileIO.cpp +++ b/Code/Mantid/MantidPlot/src/TextFileIO.cpp @@ -7,6 +7,8 @@ #include #include +#include "MantidQtAPI/FileDialogHandler.h" + /** * Construct an object with a list of file filters */ @@ -50,7 +52,7 @@ QString TextFileIO::askWhereToSave() const { QString selectedFilter; QString filter = m_filters.join(";;"); - QString filename = QFileDialog::getSaveFileName(NULL, "MantidPlot - Save", "",filter, &selectedFilter); + QString filename = MantidQt::API::FileDialogHandler::getSaveFileName(NULL, "MantidPlot - Save", "",filter, &selectedFilter); if( filename.isEmpty() ) return QString(); if( QFileInfo(filename).suffix().isEmpty() ) { diff --git a/Code/Mantid/MantidQt/API/inc/MantidQtAPI/FileDialogHandler.h b/Code/Mantid/MantidQt/API/inc/MantidQtAPI/FileDialogHandler.h index 5a6ed3202f03..51fef02f7f64 100644 --- a/Code/Mantid/MantidQt/API/inc/MantidQtAPI/FileDialogHandler.h +++ b/Code/Mantid/MantidQt/API/inc/MantidQtAPI/FileDialogHandler.h @@ -2,6 +2,11 @@ #define MANTIDQT_API_FILEDIALOGHANDLER_H_ #include +#ifdef Q_OS_DARWIN + #include + #include +#endif + namespace MantidQt { @@ -34,8 +39,9 @@ namespace API */ struct FileDialogHandler { - /** The MacOS's native save file browse button hangs so this function, which takes - * the same arguments as the Qt function, ensures a nonnative object is used on the Mac + /** The MacOS's native save dialog crashes when running a 10.6 package on 10.8 so this function, which takes + * the same arguments as the Qt function, ensures a nonnative object is used on the Mac when necessary. + * If compiled on 10.8 the native will be used * @param parent :: the dialog will be shown centered over this parent widget * @param caption :: The dialog's caption * @param dir :: The file dialog's working directory will be set to dir. If dir includes a file name, the file will be selected @@ -45,11 +51,26 @@ struct FileDialogHandler */ static QString getSaveFileName(QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), const QString & filter = QString(), QString * selectedFilter = 0, QFileDialog::Options options = 0) { -#ifdef Q_OS_DARWIN - options = options | QFileDialog::DontUseNativeDialog; +#if defined(Q_OS_DARWIN) && defined(__MAC_OS_X_VERSION_MAX_ALLOWED) + // If we are compiling on Snow Leopard + #if __MAC_OS_X_VERSION_MAX_ALLOWED == 1060 + static int runningMountainLion(-1); + if(runningMountainLion < 0) + { + // Check if we are running Mountain Lion + // osrelease 12.x.x is OS X 10.8: http://stackoverflow.com/questions/11072804/mac-os-x-10-8-replacement-for-gestalt-for-testing-os-version-at-runtime + char str[256]; + size_t size = sizeof(str); + sysctlbyname("kern.osrelease", str, &size, NULL, 0); + if(str[0] == '1' && str[1] == '2' ) runningMountainLion = 1; + else runningMountainLion = 0; + } + if(runningMountainLion) options = options | QFileDialog::DontUseNativeDialog; + #endif #endif return QFileDialog::getSaveFileName(parent, caption, dir, filter, selectedFilter, options); } + }; } diff --git a/Code/Mantid/MantidQt/API/src/FilePropertyWidget.cpp b/Code/Mantid/MantidQt/API/src/FilePropertyWidget.cpp index 189fdcd237cb..cd57a757193f 100644 --- a/Code/Mantid/MantidQt/API/src/FilePropertyWidget.cpp +++ b/Code/Mantid/MantidQt/API/src/FilePropertyWidget.cpp @@ -2,7 +2,7 @@ #include "MantidKernel/System.h" #include "MantidKernel/Property.h" #include "MantidQtAPI/AlgorithmInputHistory.h" -#include +#include "MantidQtAPI/FileDialogHandler.h" using namespace Mantid::Kernel; //using namespace Mantid::API; @@ -162,7 +162,7 @@ namespace API filter.chop(2); // Prepend the default filter QString selectedFilter; - filename = QFileDialog::getSaveFileName(NULL, "Save file", AlgorithmInputHistory::Instance().getPreviousDirectory(), filter, &selectedFilter); + filename = MantidQt::API::FileDialogHandler::getSaveFileName(NULL, "Save file", AlgorithmInputHistory::Instance().getPreviousDirectory(), filter, &selectedFilter); //Check the filename and append the selected filter if necessary if( QFileInfo(filename).completeSuffix().isEmpty() ) diff --git a/Code/Mantid/MantidQt/API/src/UserSubWindow.cpp b/Code/Mantid/MantidQt/API/src/UserSubWindow.cpp index 6654d6b1c2e8..a4fcf19efca0 100644 --- a/Code/Mantid/MantidQt/API/src/UserSubWindow.cpp +++ b/Code/Mantid/MantidQt/API/src/UserSubWindow.cpp @@ -7,6 +7,7 @@ #undef QT_NO_KEYWORDS #include "MantidQtAPI/UserSubWindow.h" #include "MantidQtAPI/AlgorithmInputHistory.h" +#include "MantidQtAPI/FileDialogHandler.h" #include #include @@ -200,7 +201,7 @@ QString UserSubWindow::openFileDialog(const bool save, const QStringList &exts) QString filename; if( save ) { - filename = QFileDialog::getSaveFileName(this, "Save file", AlgorithmInputHistory::Instance().getPreviousDirectory(), filter); + filename = MantidQt::API::FileDialogHandler::getSaveFileName(this, "Save file", AlgorithmInputHistory::Instance().getPreviousDirectory(), filter); } else { diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysis.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysis.cpp index 57eafd5100ad..4cdc2990f5ad 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysis.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysis.cpp @@ -358,7 +358,7 @@ void MuonAnalysis::runSaveGroupButton() QString filter; filter.append("Files (*.xml *.XML)"); filter += ";;AllFiles (*.*)"; - QString groupingFile = QFileDialog::getSaveFileName(this, + QString groupingFile = MantidQt::API::FileDialogHandler::getSaveFileName(this, "Save Grouping file as", prevPath, filter); // Add extension if the groupingFile specified doesn't have one. (Solving Linux problem). diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp index 77fa86310001..39d49553a00e 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp @@ -2175,7 +2175,7 @@ void SANSRunWindow::handleReduceButtonClick(const QString & typeStr) QString csv_file(m_uiForm.csv_filename->text()); if( m_dirty_batch_grid ) { - QString selected_file = QFileDialog::getSaveFileName(this, "Save as CSV", m_last_dir); + QString selected_file = MantidQt::API::FileDialogHandler::getSaveFileName(this, "Save as CSV", m_last_dir); csv_file = saveBatchGrid(selected_file); } py_code.prepend("import SANSBatchMode as batch\n"); diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/ProcessingAlgoWidget.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/ProcessingAlgoWidget.cpp index 8341db4dee02..9c42cf9c0037 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/src/ProcessingAlgoWidget.cpp +++ b/Code/Mantid/MantidQt/MantidWidgets/src/ProcessingAlgoWidget.cpp @@ -2,7 +2,7 @@ #include #include "MantidAPI/Algorithm.h" #include "MantidAPI/AlgorithmManager.h" -#include +#include "MantidQtAPI/FileDialogHandler.h" #include #include #include @@ -87,7 +87,7 @@ void ProcessingAlgoWidget::saveSettings() void ProcessingAlgoWidget::btnSaveClicked() { // Save to a .py file - QString fileselection = QFileDialog::getSaveFileName(this, "Save a Python Script", + QString fileselection = MantidQt::API::FileDialogHandler::getSaveFileName(this, "Save a Python Script", QFileInfo(m_lastFile).absoluteFilePath(), "Python scripts (*.py);;All files (*)"); if (!fileselection.isEmpty()) { diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/ScriptEditor.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/ScriptEditor.cpp index 3f5b999966fe..0794b07d5a8e 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/src/ScriptEditor.cpp +++ b/Code/Mantid/MantidQt/MantidWidgets/src/ScriptEditor.cpp @@ -3,6 +3,7 @@ //----------------------------------------------- #include "MantidQtMantidWidgets/ScriptEditor.h" #include "MantidQtMantidWidgets/FindReplaceDialog.h" +#include "MantidQtAPI/FileDialogHandler.h" // Qt #include @@ -254,7 +255,7 @@ void ScriptEditor::saveAs() { QString selectedFilter; QString filter = "Scripts (*.py *.PY);;All Files (*)"; - QString filename = QFileDialog::getSaveFileName(NULL, "MantidPlot - Save", "",filter, &selectedFilter); + QString filename = MantidQt::API::FileDialogHandler::getSaveFileName(NULL, "MantidPlot - Save", "",filter, &selectedFilter); if( filename.isEmpty() ) { diff --git a/Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp b/Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp index d4ec9486f81c..c620e07f103c 100644 --- a/Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp +++ b/Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp @@ -70,6 +70,7 @@ #include "MantidAPI/IAlgorithm.h" #include "MantidAPI/AlgorithmManager.h" #include "MantidQtAPI/AlgorithmRunner.h" +#include "MantidQtAPI/FileDialogHandler.h" using namespace Mantid; @@ -1105,7 +1106,7 @@ void SliceViewer::saveImage(const QString & filename) QString fileselection; if (filename.isEmpty()) { - fileselection = QFileDialog::getSaveFileName(this, tr("Pick a file to which to save the image"), + fileselection = MantidQt::API::FileDialogHandler::getSaveFileName(this, tr("Pick a file to which to save the image"), QFileInfo(m_lastSavedFile).absoluteFilePath(), tr("PNG files(*.png *.png)")); // User cancelled if filename is still empty