Skip to content

Commit

Permalink
Enable opening of object template files
Browse files Browse the repository at this point in the history
Rather than showing a loading error when double-clicking a template or
when selecting a template in the Open File in Project action, show the
template in the Template Editor view (and bring this view to the front).
  • Loading branch information
bjorn committed Jun 24, 2020
1 parent 8c47043 commit c129d49
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/tiled/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,13 @@ bool MainWindow::openFile(const QString &fileName, FileFormat *fileFormat)
DocumentPtr document = mDocumentManager->loadDocument(fileName, fileFormat, &error);

if (!document) {
// HACK: Templates can't open as documents, but we can instead show
// them in the Template Editor.
if (mMapEditor->templatesDock()->tryOpenTemplate(fileName)) {
mMapEditor->templatesDock()->bringToFront();
return true;
}

QMessageBox::critical(this,
tr("Error Opening File"),
tr("Error opening '%1':\n%2").arg(fileName, error));
Expand Down
7 changes: 5 additions & 2 deletions src/tiled/templatesdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,14 @@ void TemplatesDock::openTemplate(const QString &path)
setTemplate(TemplateManager::instance()->loadObjectTemplate(path));
}

void TemplatesDock::tryOpenTemplate(const QString &filePath)
bool TemplatesDock::tryOpenTemplate(const QString &filePath)
{
auto objectTemplate = TemplateManager::instance()->loadObjectTemplate(filePath);
if (objectTemplate->object())
if (objectTemplate->object()) {
setTemplate(objectTemplate);
return true;
}
return false;
}

void TemplatesDock::bringToFront()
Expand Down
2 changes: 1 addition & 1 deletion src/tiled/templatesdock.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class TemplatesDock : public QDockWidget

public slots:
void openTemplate(const QString &path);
void tryOpenTemplate(const QString &filePath);
bool tryOpenTemplate(const QString &filePath);
void bringToFront();

protected:
Expand Down

0 comments on commit c129d49

Please sign in to comment.