Fix for file path issues

actorid
graffy76 11 years ago
parent ba365ff49e
commit 9b483c3ae3

@ -20,6 +20,7 @@ CS::Editor::Editor()
setupDataFiles(); setupDataFiles();
mNewGame.setLocalData (mLocal); mNewGame.setLocalData (mLocal);
mFileDialog.setLocalData (mLocal);
connect (&mViewManager, SIGNAL (newGameRequest ()), this, SLOT (createGame ())); connect (&mViewManager, SIGNAL (newGameRequest ()), this, SLOT (createGame ()));
connect (&mViewManager, SIGNAL (newAddonRequest ()), this, SLOT (createAddon ())); connect (&mViewManager, SIGNAL (newAddonRequest ()), this, SLOT (createAddon ()));
@ -31,9 +32,11 @@ CS::Editor::Editor()
connect (&mStartup, SIGNAL (loadDocument()), this, SLOT (loadDocument ())); connect (&mStartup, SIGNAL (loadDocument()), this, SLOT (loadDocument ()));
connect (&mStartup, SIGNAL (editConfig()), this, SLOT (showSettings ())); connect (&mStartup, SIGNAL (editConfig()), this, SLOT (showSettings ()));
connect (&mFileDialog, SIGNAL(openFiles()), this, SLOT(openFiles())); connect (&mFileDialog, SIGNAL(signalOpenFiles (const boost::filesystem::path&)),
connect (&mFileDialog, SIGNAL(createNewFile ()), this, SLOT(openFiles (const boost::filesystem::path&)));
this, SLOT(createNewFile ()));
connect (&mFileDialog, SIGNAL(signalCreateNewFile (const boost::filesystem::path&)),
this, SLOT(createNewFile (const boost::filesystem::path&)));
connect (&mNewGame, SIGNAL (createRequest (const boost::filesystem::path&)), connect (&mNewGame, SIGNAL (createRequest (const boost::filesystem::path&)),
this, SLOT (createNewGame (const boost::filesystem::path&))); this, SLOT (createNewGame (const boost::filesystem::path&)));
@ -125,15 +128,12 @@ void CS::Editor::loadDocument()
mFileDialog.showDialog (CSVDoc::FileDialog::DialogType_Open); mFileDialog.showDialog (CSVDoc::FileDialog::DialogType_Open);
} }
void CS::Editor::openFiles() void CS::Editor::openFiles (const boost::filesystem::path &savePath)
{ {
std::vector<boost::filesystem::path> files; std::vector<boost::filesystem::path> files;
foreach (const QString &path, mFileDialog.selectedFilePaths()) { foreach (const QString &path, mFileDialog.selectedFilePaths())
files.push_back(path.toStdString()); files.push_back(path.toStdString());
}
boost::filesystem::path savePath = mFileDialog.filename().toStdString();
CSMDoc::Document *document = mDocumentManager.addDocument (files, savePath, false); CSMDoc::Document *document = mDocumentManager.addDocument (files, savePath, false);
@ -141,7 +141,7 @@ void CS::Editor::openFiles()
mFileDialog.hide(); mFileDialog.hide();
} }
void CS::Editor::createNewFile () void CS::Editor::createNewFile (const boost::filesystem::path &savePath)
{ {
std::vector<boost::filesystem::path> files; std::vector<boost::filesystem::path> files;
@ -151,8 +151,6 @@ void CS::Editor::createNewFile ()
files.push_back(mFileDialog.filename().toStdString()); files.push_back(mFileDialog.filename().toStdString());
boost::filesystem::path savePath = mFileDialog.filename().toStdString();
CSMDoc::Document *document = mDocumentManager.addDocument (files, savePath, true); CSMDoc::Document *document = mDocumentManager.addDocument (files, savePath, true);
mViewManager.addView (document); mViewManager.addView (document);

@ -59,8 +59,8 @@ namespace CS
void createAddon(); void createAddon();
void loadDocument(); void loadDocument();
void openFiles(); void openFiles (const boost::filesystem::path &path);
void createNewFile (); void createNewFile (const boost::filesystem::path& path);
void createNewGame (const boost::filesystem::path& file); void createNewGame (const boost::filesystem::path& file);
void showStartup(); void showStartup();

@ -17,14 +17,17 @@
#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) QDialog(parent), mSelector (0), mFileWidget (0), mAdjusterWidget (0)
{ {
ui.setupUi (this); ui.setupUi (this);
resize(400, 400); resize(400, 400);
setObjectName ("FileDialog"); setObjectName ("FileDialog");
mSelector = new ContentSelectorView::ContentSelector (ui.contentSelectorWidget); mSelector = new ContentSelectorView::ContentSelector (ui.contentSelectorWidget);
mAdjusterWidget = new AdjusterWidget (this);
} }
void CSVDoc::FileDialog::addFiles(const QString &path) void CSVDoc::FileDialog::addFiles(const QString &path)
@ -42,6 +45,14 @@ QStringList CSVDoc::FileDialog::selectedFilePaths()
return filePaths; return filePaths;
} }
void CSVDoc::FileDialog::setLocalData (const boost::filesystem::path& localData)
{
if (mDialogType != DialogType_New)
return;
mAdjusterWidget->setLocalData (localData);
}
void CSVDoc::FileDialog::showDialog(DialogType dialogType) void CSVDoc::FileDialog::showDialog(DialogType dialogType)
{ {
mDialogType = dialogType; mDialogType = dialogType;
@ -63,7 +74,6 @@ void CSVDoc::FileDialog::showDialog(DialogType dialogType)
connect (mSelector, SIGNAL (signalCurrentGamefileIndexChanged (int)), connect (mSelector, SIGNAL (signalCurrentGamefileIndexChanged (int)),
this, SLOT (slotUpdateAcceptButton (int))); this, SLOT (slotUpdateAcceptButton (int)));
connect (ui.projectButtonBox, SIGNAL (accepted()), this, SIGNAL (createNewFile()));
connect (ui.projectButtonBox, SIGNAL (rejected()), this, SLOT (slotRejected())); connect (ui.projectButtonBox, SIGNAL (rejected()), this, SLOT (slotRejected()));
show(); show();
@ -85,17 +95,26 @@ void CSVDoc::FileDialog::buildNewFileView()
mFileWidget->extensionLabelIsVisible(true); mFileWidget->extensionLabelIsVisible(true);
ui.projectGroupBoxLayout->insertWidget (0, mFileWidget); ui.projectGroupBoxLayout->insertWidget (0, mFileWidget);
ui.projectGroupBoxLayout->insertWidget (1, mAdjusterWidget);
connect (mFileWidget, SIGNAL (nameChanged (const QString&, bool)),
mAdjusterWidget, SLOT (setName (const QString&, bool)));
connect (mFileWidget, SIGNAL (nameChanged(const QString &, bool)), connect (mFileWidget, SIGNAL (nameChanged(const QString &, bool)),
this, SLOT (slotUpdateAcceptButton(const QString &, bool))); this, SLOT (slotUpdateAcceptButton(const QString &, bool)));
connect (ui.projectButtonBox, SIGNAL (accepted()), this, SLOT (slotNewFile()));
} }
void CSVDoc::FileDialog::buildOpenFileView() void CSVDoc::FileDialog::buildOpenFileView()
{ {
setWindowTitle(tr("Open")); setWindowTitle(tr("Open"));
ui.projectGroupBox->setTitle (QString("")); ui.projectGroupBox->setTitle (QString(""));
ui.projectGroupBox->layout()->addWidget (mAdjusterWidget);
ui.projectButtonBox->button(QDialogButtonBox::Ok)->setEnabled (false); ui.projectButtonBox->button(QDialogButtonBox::Ok)->setEnabled (false);
connect (ui.projectButtonBox, SIGNAL (accepted()), this, SLOT (slotOpenFile()));
} }
void CSVDoc::FileDialog::slotUpdateAcceptButton (int) void CSVDoc::FileDialog::slotUpdateAcceptButton (int)
@ -121,7 +140,7 @@ void CSVDoc::FileDialog::slotUpdateAcceptButton(const QString &name, bool)
QString CSVDoc::FileDialog::filename() const QString CSVDoc::FileDialog::filename() const
{ {
if (mDialogType == DialogType_New) if (mDialogType == DialogType_New)
return mFileWidget->getName(); return "";
return mSelector->currentFile(); return mSelector->currentFile();
} }
@ -131,3 +150,17 @@ void CSVDoc::FileDialog::slotRejected()
emit rejected(); emit rejected();
close(); close();
} }
void CSVDoc::FileDialog::slotNewFile()
{
emit signalCreateNewFile (mAdjusterWidget->getPath());
}
void CSVDoc::FileDialog::slotOpenFile()
{
ContentSelectorModel::EsmFile *file = mSelector->selectedFiles().back();
mAdjusterWidget->setName (file->fileName(), !file->isGameFile());
emit signalOpenFiles (mAdjusterWidget->getPath());
}

@ -4,6 +4,13 @@
#include <QDialog> #include <QDialog>
#include <QModelIndex> #include <QModelIndex>
#include <boost/filesystem/path.hpp>
#ifndef CS_QT_BOOST_FILESYSTEM_PATH_DECLARED
#define CS_QT_BOOST_FILESYSTEM_PATH_DECLARED
Q_DECLARE_METATYPE (boost::filesystem::path)
#endif
#include "ui_filedialog.h" #include "ui_filedialog.h"
class DataFilesModel; class DataFilesModel;
@ -17,6 +24,7 @@ namespace ContentSelectorView
namespace CSVDoc namespace CSVDoc
{ {
class FileWidget; class FileWidget;
class AdjusterWidget;
class FileDialog : public QDialog class FileDialog : public QDialog
{ {
@ -36,6 +44,7 @@ namespace CSVDoc
Ui::FileDialog ui; Ui::FileDialog ui;
DialogType mDialogType; DialogType mDialogType;
FileWidget *mFileWidget; FileWidget *mFileWidget;
AdjusterWidget *mAdjusterWidget;
public: public:
@ -47,6 +56,8 @@ namespace CSVDoc
QString filename() const; QString filename() const;
QStringList selectedFilePaths(); QStringList selectedFilePaths();
void setLocalData (const boost::filesystem::path& localData);
private: private:
void buildNewFileView(); void buildNewFileView();
@ -54,13 +65,15 @@ namespace CSVDoc
signals: signals:
void openFiles(); void signalOpenFiles (const boost::filesystem::path &path);
void createNewFile (); void signalCreateNewFile (const boost::filesystem::path &path);
void signalUpdateAcceptButton (bool, int); void signalUpdateAcceptButton (bool, int);
private slots: private slots:
void slotNewFile();
void slotOpenFile();
void slotUpdateAcceptButton (int); void slotUpdateAcceptButton (int);
void slotUpdateAcceptButton (const QString &, bool); void slotUpdateAcceptButton (const QString &, bool);
void slotRejected(); void slotRejected();

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>518</width> <width>518</width>
<height>108</height> <height>109</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -52,7 +52,7 @@
</property> </property>
<item> <item>
<widget class="QWidget" name="projectWidget" native="true"> <widget class="QWidget" name="projectWidget" native="true">
<layout class="QHBoxLayout" name="projectButtonBoxLayout"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QDialogButtonBox" name="projectButtonBox"> <widget class="QDialogButtonBox" name="projectButtonBox">
<property name="standardButtons"> <property name="standardButtons">

Loading…
Cancel
Save