Skip to content

Commit

Permalink
Added initial support for projects
Browse files Browse the repository at this point in the history
The initial project is simply a list of folders. Each folder is scanned
recursively for files that seem to be one of the supported formats
(based on their file extension).

Since there's no automatic refresh at the moment, the Project menu
contains an action to trigger the refresh manually.

The last open project is automatically loaded on startup.

There's no way yet to remove folders from a project. Need to edit the
file by hand for now.

Issue #1665
  • Loading branch information
bjorn committed Dec 4, 2019
1 parent 122379f commit 013f7a0
Show file tree
Hide file tree
Showing 13 changed files with 823 additions and 12 deletions.
32 changes: 27 additions & 5 deletions src/tiled/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "documentmanager.h"
#include "exportasimagedialog.h"
#include "exporthelper.h"
#include "issuescounter.h"
#include "issuesdock.h"
#include "languagemanager.h"
#include "layer.h"
Expand All @@ -52,12 +53,14 @@
#include "mapview.h"
#include "minimaprenderer.h"
#include "newmapdialog.h"
#include "newsbutton.h"
#include "newtilesetdialog.h"
#include "objectgroup.h"
#include "objecttypeseditor.h"
#include "offsetmapdialog.h"
#include "donationdialog.h"
#include "pluginmanager.h"
#include "projectdock.h"
#include "resizedialog.h"
#include "scriptmanager.h"
#include "templatemanager.h"
Expand Down Expand Up @@ -99,8 +102,6 @@
#include <QtPlatformHeaders\QWindowsWindowFunctions>
#endif

#include "issuescounter.h"
#include "newsbutton.h"
#include "qtcompat_p.h"

using namespace Tiled;
Expand Down Expand Up @@ -201,6 +202,7 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
, mUi(new Ui::MainWindow)
, mActionHandler(new MapDocumentActionHandler(this))
, mConsoleDock(new ConsoleDock(this))
, mProjectDock(new ProjectDock(this))
, mIssuesDock(new IssuesDock(this))
, mObjectTypesEditor(new ObjectTypesEditor(this))
, mAutomappingManager(new AutomappingManager(this))
Expand Down Expand Up @@ -342,6 +344,7 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
ActionManager::registerAction(undoAction, "Undo");
ActionManager::registerAction(redoAction, "Redo");

addDockWidget(Qt::LeftDockWidgetArea, mProjectDock);
addDockWidget(Qt::BottomDockWidgetArea, mConsoleDock);
addDockWidget(Qt::BottomDockWidgetArea, mIssuesDock);
tabifyDockWidget(mConsoleDock, mIssuesDock);
Expand Down Expand Up @@ -464,7 +467,7 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
mLayerMenu->addSeparator();
mLayerMenu->addAction(mActionHandler->actionLayerProperties());

menuBar()->insertMenu(mUi->menuHelp->menuAction(), mLayerMenu);
menuBar()->insertMenu(mUi->menuProject->menuAction(), mLayerMenu);

ActionManager::registerMenu(mLayerMenu, "Layer");
ActionManager::registerMenu(mNewLayerMenu, "NewLayer");
Expand Down Expand Up @@ -567,6 +570,12 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
connect(mUi->actionTilesetProperties, &QAction::triggered,
this, &MainWindow::editTilesetProperties);

connect(mUi->actionOpenProject, &QAction::triggered, mProjectDock, &ProjectDock::openProject);
connect(mUi->actionSaveProjectAs, &QAction::triggered, mProjectDock, &ProjectDock::saveProjectAs);
connect(mUi->actionCloseProject, &QAction::triggered, mProjectDock, &ProjectDock::closeProject);
connect(mUi->actionAddFolderToProject, &QAction::triggered, mProjectDock, &ProjectDock::addFolderToProject);
connect(mUi->actionRefreshProjectFolders, &QAction::triggered, mProjectDock, &ProjectDock::refreshProjectFolders);

connect(mUi->actionDocumentation, &QAction::triggered, this, &MainWindow::openDocumentation);
connect(mUi->actionForum, &QAction::triggered, this, &MainWindow::openForum);
connect(mUi->actionDonate, &QAction::triggered, this, &MainWindow::showDonationDialog);
Expand All @@ -587,6 +596,8 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
mUi->menuRecentFiles->insertSeparator(mUi->actionClearRecentFiles);
mUi->menuRecentFiles->setToolTipsVisible(true);

connect(mProjectDock, &ProjectDock::projectFileNameChanged, this, &MainWindow::updateWindowTitle);

setThemeIcon(mUi->menuNew, "document-new");
setThemeIcon(mUi->actionOpen, "document-open");
setThemeIcon(mUi->menuRecentFiles, "document-open-recent");
Expand All @@ -607,6 +618,11 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
setThemeIcon(mUi->actionFitInView, "zoom-fit-best");
setThemeIcon(mUi->actionResizeMap, "document-page-setup");
setThemeIcon(mUi->actionMapProperties, "document-properties");
setThemeIcon(mUi->actionOpenProject, "document-open");
setThemeIcon(mUi->actionSaveProjectAs, "document-save-as");
setThemeIcon(mUi->actionCloseProject, "window-close");
setThemeIcon(mUi->actionAddFolderToProject, "folder-new");
setThemeIcon(mUi->actionRefreshProjectFolders, "view-refresh");
setThemeIcon(mUi->actionDocumentation, "help-contents");
setThemeIcon(mUi->actionAbout, "help-about");

Expand Down Expand Up @@ -1684,12 +1700,18 @@ void MainWindow::readSettings()

void MainWindow::updateWindowTitle()
{
QString projectName = mProjectDock->projectFileName();
if (!projectName.isEmpty()) {
projectName = QFileInfo(projectName).completeBaseName();
projectName = QString(QLatin1String(" (%1)")).arg(projectName);
}

if (Document *document = mDocumentManager->currentDocument()) {
setWindowTitle(tr("[*]%1").arg(document->displayName()));
setWindowTitle(tr("[*]%1%2").arg(document->displayName(), projectName));
setWindowFilePath(document->fileName());
setWindowModified(document->isModified());
} else {
setWindowTitle(QString());
setWindowTitle(projectName);
setWindowFilePath(QString());
setWindowModified(false);
}
Expand Down
2 changes: 2 additions & 0 deletions src/tiled/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class MapEditor;
class MapScene;
class MapView;
class ObjectTypesEditor;
class ProjectDock;
class TilesetDocument;
class TilesetEditor;
class Zoomable;
Expand Down Expand Up @@ -208,6 +209,7 @@ class MainWindow : public QMainWindow
Zoomable *mZoomable = nullptr;
MapDocumentActionHandler *mActionHandler;
ConsoleDock *mConsoleDock;
ProjectDock *mProjectDock;
IssuesDock *mIssuesDock;
ObjectTypesEditor *mObjectTypesEditor;
QSettings mSettings;
Expand Down
42 changes: 42 additions & 0 deletions src/tiled/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,23 @@
</property>
<addaction name="actionTilesetProperties"/>
</widget>
<widget class="QMenu" name="menuProject">
<property name="title">
<string>&amp;Project</string>
</property>
<addaction name="actionOpenProject"/>
<addaction name="actionSaveProjectAs"/>
<addaction name="actionCloseProject"/>
<addaction name="separator"/>
<addaction name="actionAddFolderToProject"/>
<addaction name="actionRefreshProjectFolders"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuView"/>
<addaction name="menuMap"/>
<addaction name="menuTileset"/>
<addaction name="menuProject"/>
<addaction name="menuHelp"/>
</widget>
<action name="actionOpen">
Expand Down Expand Up @@ -655,6 +667,36 @@
<string>Community Forum ↗</string>
</property>
</action>
<action name="actionOpenProject">
<property name="text">
<string>&amp;Open Project...</string>
</property>
</action>
<action name="actionCloseProject">
<property name="text">
<string>&amp;Close Project</string>
</property>
</action>
<action name="actionClearRecentProjects">
<property name="text">
<string>Clear Recent Projects</string>
</property>
</action>
<action name="actionAddFolderToProject">
<property name="text">
<string>Add Folder to Project...</string>
</property>
</action>
<action name="actionSaveProjectAs">
<property name="text">
<string>Save Project As...</string>
</property>
</action>
<action name="actionRefreshProjectFolders">
<property name="text">
<string>Refresh Folders</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
Expand Down
2 changes: 0 additions & 2 deletions src/tiled/mapsdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@
#include <QBoxLayout>
#include <QCompleter>
#include <QDirModel>
#include <QEvent>
#include <QFileDialog>
#include <QFileSystemModel>
#include <QHeaderView>
#include <QLabel>
#include <QLineEdit>
#include <QMouseEvent>
#include <QPushButton>
Expand Down
8 changes: 3 additions & 5 deletions src/tiled/mapsdock.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
#include <QTreeView>

class QFileSystemModel;
class QLabel;
class QLineEdit;
class QModelIndex;
class QTreeView;

namespace Tiled {

Expand Down Expand Up @@ -69,10 +66,11 @@ class MapsView : public QTreeView
*/
QSize sizeHint() const override;

void mousePressEvent(QMouseEvent *event) override;

QFileSystemModel *model() const { return mFileSystemModel; }

protected:
void mousePressEvent(QMouseEvent *event) override;

private:
void onMapsDirectoryChanged();
void onActivated(const QModelIndex &index);
Expand Down
Loading

0 comments on commit 013f7a0

Please sign in to comment.