Fixed path problem with adjuster widget and local data path.

actorid
graffy76 11 years ago
parent b51bef0d98
commit 0cb591e4f6

@ -10,8 +10,6 @@
#include "model/world/data.hpp"
#include <iostream>
#include <QDebug>
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);

@ -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");
bool isFilePathChanged = (path.parent_path().string() != mLocalData.string());
if (isLegacyPath)
path.replace_extension (addon ? ".omwaddon" : ".omwgame");
if (path.parent_path().string()==mLocalData.string())
//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 += "<p>But a file with the same name already exists. If you continue, it will be overwritten.";
message += "<p>A file with the same name already exists. If you continue, it will be overwritten.";
}
}
}

@ -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;

@ -17,8 +17,6 @@
#include "filewidget.hpp"
#include "adjusterwidget.hpp"
#include <QDebug>
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();

Loading…
Cancel
Save