diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index 1c861ed67e..63afe7a9dd 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -10,8 +10,6 @@ #include "model/world/data.hpp" #include -#include - CS::Editor::Editor() : mDocumentManager (mCfgMgr), mViewManager (mDocumentManager) { @@ -119,13 +117,13 @@ void CS::Editor::createGame() void CS::Editor::createAddon() { mStartup.hide(); - mFileDialog.showDialog (CSVDoc::FileDialog::DialogType_New); + mFileDialog.showDialog (CSVDoc::ContentAction_New); } void CS::Editor::loadDocument() { mStartup.hide(); - mFileDialog.showDialog (CSVDoc::FileDialog::DialogType_Open); + mFileDialog.showDialog (CSVDoc::ContentAction_Edit); } void CS::Editor::openFiles (const boost::filesystem::path &savePath) @@ -135,7 +133,6 @@ void CS::Editor::openFiles (const boost::filesystem::path &savePath) foreach (const QString &path, mFileDialog.selectedFilePaths()) files.push_back(path.toStdString()); - qDebug() << "save file path: " << savePath.c_str(); CSMDoc::Document *document = mDocumentManager.addDocument (files, savePath, false); mViewManager.addView (document); diff --git a/apps/opencs/view/doc/adjusterwidget.cpp b/apps/opencs/view/doc/adjusterwidget.cpp index 332d460758..09e58690fc 100644 --- a/apps/opencs/view/doc/adjusterwidget.cpp +++ b/apps/opencs/view/doc/adjusterwidget.cpp @@ -52,47 +52,56 @@ bool CSVDoc::AdjusterWidget::isValid() const { return mValid; } + +void CSVDoc::AdjusterWidget::setFilenameCheck (bool doCheck) +{ + mDoFilenameCheck = doCheck; +} + void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon) { QString message; - if (mAction == ContentAction_Undefined) - { - throw std::runtime_error("ContentAction_Undefined when AdjusterWidget::setName() called."); - return; - } + mValid = (!name.isEmpty()); - if (name.isEmpty()) + if (!mValid) { - mValid = false; message = "No name."; } else { boost::filesystem::path path (name.toUtf8().data()); - path.replace_extension (addon ? ".omwaddon" : ".omwgame"); + bool isLegacyPath = (path.extension() == ".esm" || + path.extension() == ".esp"); - if (path.parent_path().string()==mLocalData.string()) + bool isFilePathChanged = (path.parent_path().string() != mLocalData.string()); + + if (isLegacyPath) + path.replace_extension (addon ? ".omwaddon" : ".omwgame"); + + //if the file came from data-local and is not a legacy file to be converted, + //don't worry about doing a file check. + if (!isFilePathChanged && !isLegacyPath) { // path already points to the local data directory message = QString::fromUtf8 (("Will be saved as: " + path.string()).c_str()); mResultPath = path; - mValid = true; } + //in all other cases, ensure the path points to data-local and do an existing file check else { // path points somewhere else or is a leaf name. - path = mLocalData / path.filename(); + if (isFilePathChanged) + path = mLocalData / path.filename(); message = QString::fromUtf8 (("Will be saved as: " + path.string()).c_str()); mResultPath = path; - mValid = true; if (boost::filesystem::exists (path)) { /// \todo add an user setting to make this an error. - message += "

But a file with the same name already exists. If you continue, it will be overwritten."; + message += "

A file with the same name already exists. If you continue, it will be overwritten."; } } } diff --git a/apps/opencs/view/doc/adjusterwidget.hpp b/apps/opencs/view/doc/adjusterwidget.hpp index 627f89c1f8..91e308236f 100644 --- a/apps/opencs/view/doc/adjusterwidget.hpp +++ b/apps/opencs/view/doc/adjusterwidget.hpp @@ -28,6 +28,7 @@ namespace CSVDoc bool mValid; boost::filesystem::path mResultPath; ContentAction mAction; + bool mDoFilenameCheck; public: @@ -36,6 +37,7 @@ namespace CSVDoc void setLocalData (const boost::filesystem::path& localData); void setAction (ContentAction action); + void setFilenameCheck (bool doCheck); bool isValid() const; boost::filesystem::path getPath() const; diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index 57b61ff8b2..c0cda26dc9 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -17,8 +17,6 @@ #include "filewidget.hpp" #include "adjusterwidget.hpp" -#include - CSVDoc::FileDialog::FileDialog(QWidget *parent) : QDialog(parent), mSelector (0), mFileWidget (0), mAdjusterWidget (0) { @@ -47,9 +45,6 @@ QStringList CSVDoc::FileDialog::selectedFilePaths() void CSVDoc::FileDialog::setLocalData (const boost::filesystem::path& localData) { - if (mDialogType != DialogType_New) - return; - mAdjusterWidget->setLocalData (localData); } @@ -68,10 +63,13 @@ void CSVDoc::FileDialog::showDialog (ContentAction action) case ContentAction_Edit: buildOpenFileView(); break; + default: break; } + mAdjusterWidget->setFilenameCheck (mAction == ContentAction_New); + //connections common to both dialog view flavors connect (mSelector, SIGNAL (signalCurrentGamefileIndexChanged (int)), this, SLOT (slotUpdateAcceptButton (int))); @@ -124,7 +122,7 @@ void CSVDoc::FileDialog::slotUpdateAcceptButton (int) { QString name = ""; - if (mDialogType == DialogType_New) + if (mAction == ContentAction_New) name = mFileWidget->getName(); slotUpdateAcceptButton (name, true); @@ -134,11 +132,13 @@ void CSVDoc::FileDialog::slotUpdateAcceptButton(const QString &name, bool) { bool success = (mSelector->selectedFiles().size() > 0); - if (mDialogType == DialogType_New) + bool isNew = (mAction == ContentAction_New); + + if (isNew) success = success && !(name.isEmpty()); else { - ContentSelectorModel::EsmFile *file = mSelector->selectedFiles().back(); + ContentSelectorModel::EsmFile *file = mSelector->selectedFiles().back();; mAdjusterWidget->setName (file->fileName(), !file->isGameFile()); } @@ -147,7 +147,7 @@ void CSVDoc::FileDialog::slotUpdateAcceptButton(const QString &name, bool) QString CSVDoc::FileDialog::filename() const { - if (mDialogType == DialogType_New) + if (mAction == ContentAction_New) return ""; return mSelector->currentFile();