diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index 51cc490c7..a8006d2b4 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -20,6 +20,7 @@ CS::Editor::Editor() setupDataFiles(); mNewGame.setLocalData (mLocal); + mFileDialog.setLocalData (mLocal); connect (&mViewManager, SIGNAL (newGameRequest ()), this, SLOT (createGame ())); connect (&mViewManager, SIGNAL (newAddonRequest ()), this, SLOT (createAddon ())); @@ -31,9 +32,11 @@ CS::Editor::Editor() connect (&mStartup, SIGNAL (loadDocument()), this, SLOT (loadDocument ())); connect (&mStartup, SIGNAL (editConfig()), this, SLOT (showSettings ())); - connect (&mFileDialog, SIGNAL(openFiles()), this, SLOT(openFiles())); - connect (&mFileDialog, SIGNAL(createNewFile ()), - this, SLOT(createNewFile ())); + connect (&mFileDialog, SIGNAL(signalOpenFiles (const boost::filesystem::path&)), + this, SLOT(openFiles (const boost::filesystem::path&))); + + connect (&mFileDialog, SIGNAL(signalCreateNewFile (const boost::filesystem::path&)), + this, SLOT(createNewFile (const boost::filesystem::path&))); connect (&mNewGame, SIGNAL (createRequest (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); } -void CS::Editor::openFiles() +void CS::Editor::openFiles (const boost::filesystem::path &savePath) { std::vector files; - foreach (const QString &path, mFileDialog.selectedFilePaths()) { + foreach (const QString &path, mFileDialog.selectedFilePaths()) files.push_back(path.toStdString()); - } - - boost::filesystem::path savePath = mFileDialog.filename().toStdString(); CSMDoc::Document *document = mDocumentManager.addDocument (files, savePath, false); @@ -141,7 +141,7 @@ void CS::Editor::openFiles() mFileDialog.hide(); } -void CS::Editor::createNewFile () +void CS::Editor::createNewFile (const boost::filesystem::path &savePath) { std::vector files; @@ -151,8 +151,6 @@ void CS::Editor::createNewFile () files.push_back(mFileDialog.filename().toStdString()); - boost::filesystem::path savePath = mFileDialog.filename().toStdString(); - CSMDoc::Document *document = mDocumentManager.addDocument (files, savePath, true); mViewManager.addView (document); diff --git a/apps/opencs/editor.hpp b/apps/opencs/editor.hpp index ef013bc8f..930aa9d64 100644 --- a/apps/opencs/editor.hpp +++ b/apps/opencs/editor.hpp @@ -59,8 +59,8 @@ namespace CS void createAddon(); void loadDocument(); - void openFiles(); - void createNewFile (); + void openFiles (const boost::filesystem::path &path); + void createNewFile (const boost::filesystem::path& path); void createNewGame (const boost::filesystem::path& file); void showStartup(); diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index fb6c0a0e8..eb94aa5f4 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -17,14 +17,17 @@ #include "filewidget.hpp" #include "adjusterwidget.hpp" +#include + CSVDoc::FileDialog::FileDialog(QWidget *parent) : - QDialog(parent), mSelector (0) + QDialog(parent), mSelector (0), mFileWidget (0), mAdjusterWidget (0) { ui.setupUi (this); resize(400, 400); setObjectName ("FileDialog"); mSelector = new ContentSelectorView::ContentSelector (ui.contentSelectorWidget); + mAdjusterWidget = new AdjusterWidget (this); } void CSVDoc::FileDialog::addFiles(const QString &path) @@ -42,6 +45,14 @@ QStringList CSVDoc::FileDialog::selectedFilePaths() 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) { mDialogType = dialogType; @@ -63,7 +74,6 @@ void CSVDoc::FileDialog::showDialog(DialogType dialogType) connect (mSelector, SIGNAL (signalCurrentGamefileIndexChanged (int)), this, SLOT (slotUpdateAcceptButton (int))); - connect (ui.projectButtonBox, SIGNAL (accepted()), this, SIGNAL (createNewFile())); connect (ui.projectButtonBox, SIGNAL (rejected()), this, SLOT (slotRejected())); show(); @@ -85,17 +95,26 @@ void CSVDoc::FileDialog::buildNewFileView() mFileWidget->extensionLabelIsVisible(true); 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)), this, SLOT (slotUpdateAcceptButton(const QString &, bool))); + + connect (ui.projectButtonBox, SIGNAL (accepted()), this, SLOT (slotNewFile())); } void CSVDoc::FileDialog::buildOpenFileView() { setWindowTitle(tr("Open")); ui.projectGroupBox->setTitle (QString("")); + ui.projectGroupBox->layout()->addWidget (mAdjusterWidget); ui.projectButtonBox->button(QDialogButtonBox::Ok)->setEnabled (false); + + connect (ui.projectButtonBox, SIGNAL (accepted()), this, SLOT (slotOpenFile())); } void CSVDoc::FileDialog::slotUpdateAcceptButton (int) @@ -121,7 +140,7 @@ void CSVDoc::FileDialog::slotUpdateAcceptButton(const QString &name, bool) QString CSVDoc::FileDialog::filename() const { if (mDialogType == DialogType_New) - return mFileWidget->getName(); + return ""; return mSelector->currentFile(); } @@ -131,3 +150,17 @@ void CSVDoc::FileDialog::slotRejected() emit rejected(); 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()); +} diff --git a/apps/opencs/view/doc/filedialog.hpp b/apps/opencs/view/doc/filedialog.hpp index 30f2f5d56..777ee31e4 100644 --- a/apps/opencs/view/doc/filedialog.hpp +++ b/apps/opencs/view/doc/filedialog.hpp @@ -4,6 +4,13 @@ #include #include +#include + +#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" class DataFilesModel; @@ -17,6 +24,7 @@ namespace ContentSelectorView namespace CSVDoc { class FileWidget; + class AdjusterWidget; class FileDialog : public QDialog { @@ -36,6 +44,7 @@ namespace CSVDoc Ui::FileDialog ui; DialogType mDialogType; FileWidget *mFileWidget; + AdjusterWidget *mAdjusterWidget; public: @@ -47,6 +56,8 @@ namespace CSVDoc QString filename() const; QStringList selectedFilePaths(); + void setLocalData (const boost::filesystem::path& localData); + private: void buildNewFileView(); @@ -54,13 +65,15 @@ namespace CSVDoc signals: - void openFiles(); - void createNewFile (); + void signalOpenFiles (const boost::filesystem::path &path); + void signalCreateNewFile (const boost::filesystem::path &path); void signalUpdateAcceptButton (bool, int); private slots: + void slotNewFile(); + void slotOpenFile(); void slotUpdateAcceptButton (int); void slotUpdateAcceptButton (const QString &, bool); void slotRejected(); diff --git a/files/ui/filedialog.ui b/files/ui/filedialog.ui index 114345e53..b3af166da 100644 --- a/files/ui/filedialog.ui +++ b/files/ui/filedialog.ui @@ -7,7 +7,7 @@ 0 0 518 - 108 + 109 @@ -52,7 +52,7 @@ - +