mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-30 09:06:43 +00:00
Fixed path problem with adjuster widget and local data path.
This commit is contained in:
parent
b51bef0d98
commit
0cb591e4f6
4 changed files with 35 additions and 27 deletions
|
@ -10,8 +10,6 @@
|
||||||
#include "model/world/data.hpp"
|
#include "model/world/data.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
CS::Editor::Editor()
|
CS::Editor::Editor()
|
||||||
: mDocumentManager (mCfgMgr), mViewManager (mDocumentManager)
|
: mDocumentManager (mCfgMgr), mViewManager (mDocumentManager)
|
||||||
{
|
{
|
||||||
|
@ -119,13 +117,13 @@ void CS::Editor::createGame()
|
||||||
void CS::Editor::createAddon()
|
void CS::Editor::createAddon()
|
||||||
{
|
{
|
||||||
mStartup.hide();
|
mStartup.hide();
|
||||||
mFileDialog.showDialog (CSVDoc::FileDialog::DialogType_New);
|
mFileDialog.showDialog (CSVDoc::ContentAction_New);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CS::Editor::loadDocument()
|
void CS::Editor::loadDocument()
|
||||||
{
|
{
|
||||||
mStartup.hide();
|
mStartup.hide();
|
||||||
mFileDialog.showDialog (CSVDoc::FileDialog::DialogType_Open);
|
mFileDialog.showDialog (CSVDoc::ContentAction_Edit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CS::Editor::openFiles (const boost::filesystem::path &savePath)
|
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())
|
foreach (const QString &path, mFileDialog.selectedFilePaths())
|
||||||
files.push_back(path.toStdString());
|
files.push_back(path.toStdString());
|
||||||
|
|
||||||
qDebug() << "save file path: " << savePath.c_str();
|
|
||||||
CSMDoc::Document *document = mDocumentManager.addDocument (files, savePath, false);
|
CSMDoc::Document *document = mDocumentManager.addDocument (files, savePath, false);
|
||||||
|
|
||||||
mViewManager.addView (document);
|
mViewManager.addView (document);
|
||||||
|
|
|
@ -52,47 +52,56 @@ bool CSVDoc::AdjusterWidget::isValid() const
|
||||||
{
|
{
|
||||||
return mValid;
|
return mValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVDoc::AdjusterWidget::setFilenameCheck (bool doCheck)
|
||||||
|
{
|
||||||
|
mDoFilenameCheck = doCheck;
|
||||||
|
}
|
||||||
|
|
||||||
void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon)
|
void CSVDoc::AdjusterWidget::setName (const QString& name, bool addon)
|
||||||
{
|
{
|
||||||
QString message;
|
QString message;
|
||||||
|
|
||||||
if (mAction == ContentAction_Undefined)
|
mValid = (!name.isEmpty());
|
||||||
{
|
|
||||||
throw std::runtime_error("ContentAction_Undefined when AdjusterWidget::setName() called.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name.isEmpty())
|
if (!mValid)
|
||||||
{
|
{
|
||||||
mValid = false;
|
|
||||||
message = "No name.";
|
message = "No name.";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
boost::filesystem::path path (name.toUtf8().data());
|
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
|
// path already points to the local data directory
|
||||||
message = QString::fromUtf8 (("Will be saved as: " + path.string()).c_str());
|
message = QString::fromUtf8 (("Will be saved as: " + path.string()).c_str());
|
||||||
mResultPath = path;
|
mResultPath = path;
|
||||||
mValid = true;
|
|
||||||
}
|
}
|
||||||
|
//in all other cases, ensure the path points to data-local and do an existing file check
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// path points somewhere else or is a leaf name.
|
// 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());
|
message = QString::fromUtf8 (("Will be saved as: " + path.string()).c_str());
|
||||||
mResultPath = path;
|
mResultPath = path;
|
||||||
mValid = true;
|
|
||||||
|
|
||||||
if (boost::filesystem::exists (path))
|
if (boost::filesystem::exists (path))
|
||||||
{
|
{
|
||||||
/// \todo add an user setting to make this an error.
|
/// \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;
|
bool mValid;
|
||||||
boost::filesystem::path mResultPath;
|
boost::filesystem::path mResultPath;
|
||||||
ContentAction mAction;
|
ContentAction mAction;
|
||||||
|
bool mDoFilenameCheck;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -36,6 +37,7 @@ namespace CSVDoc
|
||||||
void setLocalData (const boost::filesystem::path& localData);
|
void setLocalData (const boost::filesystem::path& localData);
|
||||||
void setAction (ContentAction action);
|
void setAction (ContentAction action);
|
||||||
|
|
||||||
|
void setFilenameCheck (bool doCheck);
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
|
|
||||||
boost::filesystem::path getPath() const;
|
boost::filesystem::path getPath() const;
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
#include "filewidget.hpp"
|
#include "filewidget.hpp"
|
||||||
#include "adjusterwidget.hpp"
|
#include "adjusterwidget.hpp"
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
CSVDoc::FileDialog::FileDialog(QWidget *parent) :
|
CSVDoc::FileDialog::FileDialog(QWidget *parent) :
|
||||||
QDialog(parent), mSelector (0), mFileWidget (0), mAdjusterWidget (0)
|
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)
|
void CSVDoc::FileDialog::setLocalData (const boost::filesystem::path& localData)
|
||||||
{
|
{
|
||||||
if (mDialogType != DialogType_New)
|
|
||||||
return;
|
|
||||||
|
|
||||||
mAdjusterWidget->setLocalData (localData);
|
mAdjusterWidget->setLocalData (localData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,10 +63,13 @@ void CSVDoc::FileDialog::showDialog (ContentAction action)
|
||||||
case ContentAction_Edit:
|
case ContentAction_Edit:
|
||||||
buildOpenFileView();
|
buildOpenFileView();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mAdjusterWidget->setFilenameCheck (mAction == ContentAction_New);
|
||||||
|
|
||||||
//connections common to both dialog view flavors
|
//connections common to both dialog view flavors
|
||||||
connect (mSelector, SIGNAL (signalCurrentGamefileIndexChanged (int)),
|
connect (mSelector, SIGNAL (signalCurrentGamefileIndexChanged (int)),
|
||||||
this, SLOT (slotUpdateAcceptButton (int)));
|
this, SLOT (slotUpdateAcceptButton (int)));
|
||||||
|
@ -124,7 +122,7 @@ void CSVDoc::FileDialog::slotUpdateAcceptButton (int)
|
||||||
{
|
{
|
||||||
QString name = "";
|
QString name = "";
|
||||||
|
|
||||||
if (mDialogType == DialogType_New)
|
if (mAction == ContentAction_New)
|
||||||
name = mFileWidget->getName();
|
name = mFileWidget->getName();
|
||||||
|
|
||||||
slotUpdateAcceptButton (name, true);
|
slotUpdateAcceptButton (name, true);
|
||||||
|
@ -134,11 +132,13 @@ void CSVDoc::FileDialog::slotUpdateAcceptButton(const QString &name, bool)
|
||||||
{
|
{
|
||||||
bool success = (mSelector->selectedFiles().size() > 0);
|
bool success = (mSelector->selectedFiles().size() > 0);
|
||||||
|
|
||||||
if (mDialogType == DialogType_New)
|
bool isNew = (mAction == ContentAction_New);
|
||||||
|
|
||||||
|
if (isNew)
|
||||||
success = success && !(name.isEmpty());
|
success = success && !(name.isEmpty());
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ContentSelectorModel::EsmFile *file = mSelector->selectedFiles().back();
|
ContentSelectorModel::EsmFile *file = mSelector->selectedFiles().back();;
|
||||||
mAdjusterWidget->setName (file->fileName(), !file->isGameFile());
|
mAdjusterWidget->setName (file->fileName(), !file->isGameFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ void CSVDoc::FileDialog::slotUpdateAcceptButton(const QString &name, bool)
|
||||||
|
|
||||||
QString CSVDoc::FileDialog::filename() const
|
QString CSVDoc::FileDialog::filename() const
|
||||||
{
|
{
|
||||||
if (mDialogType == DialogType_New)
|
if (mAction == ContentAction_New)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
return mSelector->currentFile();
|
return mSelector->currentFile();
|
||||||
|
|
Loading…
Reference in a new issue