diff --git a/src/Editor/ResourceBrowser/CResourceBrowser.cpp b/src/Editor/ResourceBrowser/CResourceBrowser.cpp index 7458baba..24dfdd96 100644 --- a/src/Editor/ResourceBrowser/CResourceBrowser.cpp +++ b/src/Editor/ResourceBrowser/CResourceBrowser.cpp @@ -72,6 +72,35 @@ CResourceBrowser::~CResourceBrowser() delete mpUI; } +void CResourceBrowser::SelectResource(CResourceEntry *pEntry) +{ + ASSERT(pEntry); + + // Clear search + mpUI->SearchBar->clear(); + UpdateFilter(); + + // Select target directory + SelectDirectory(pEntry->Directory()); + + // Select resource + int Row = mpModel->GetIndexForEntry(pEntry).row(); + mpUI->ResourceTableView->selectionModel()->clearSelection(); + + for (int iCol = 0; iCol < mpModel->columnCount(QModelIndex()); iCol++) + { + QModelIndex Index = mpModel->index(Row, iCol, QModelIndex()); + QModelIndex ProxyIndex = mpProxyModel->mapFromSource(Index); + mpUI->ResourceTableView->selectionModel()->setCurrentIndex(ProxyIndex, QItemSelectionModel::Select); + } +} + +void CResourceBrowser::SelectDirectory(CVirtualDirectory *pDir) +{ + QModelIndex Index = mpDirectoryModel->GetIndexForDirectory(pDir); + mpUI->DirectoryTreeView->selectionModel()->setCurrentIndex(Index, QItemSelectionModel::ClearAndSelect); +} + void CResourceBrowser::RefreshResources() { // Fill resource table @@ -157,8 +186,7 @@ void CResourceBrowser::OnDoubleClickTable(QModelIndex Index) if (mpModel->IsIndexDirectory(SourceIndex)) { CVirtualDirectory *pDir = mpModel->IndexDirectory(SourceIndex); - QModelIndex Index = mpDirectoryModel->GetIndexForDirectory(pDir); - mpUI->DirectoryTreeView->selectionModel()->setCurrentIndex(Index, QItemSelectionModel::ClearAndSelect); + SelectDirectory(pDir); } // Resource - open resource for editing diff --git a/src/Editor/ResourceBrowser/CResourceBrowser.h b/src/Editor/ResourceBrowser/CResourceBrowser.h index b243f1a1..7d732177 100644 --- a/src/Editor/ResourceBrowser/CResourceBrowser.h +++ b/src/Editor/ResourceBrowser/CResourceBrowser.h @@ -27,6 +27,8 @@ class CResourceBrowser : public QDialog public: explicit CResourceBrowser(QWidget *pParent = 0); ~CResourceBrowser(); + void SelectResource(CResourceEntry *pEntry); + void SelectDirectory(CVirtualDirectory *pDir); // Accessors inline CResourceEntry* SelectedEntry() const { return mpSelectedEntry; } diff --git a/src/Editor/ResourceBrowser/CResourceTableModel.h b/src/Editor/ResourceBrowser/CResourceTableModel.h index f6efac0c..d0c74b62 100644 --- a/src/Editor/ResourceBrowser/CResourceTableModel.h +++ b/src/Editor/ResourceBrowser/CResourceTableModel.h @@ -85,6 +85,21 @@ public: return QVariant::Invalid; } + QModelIndex GetIndexForEntry(CResourceEntry *pEntry) const + { + for (int iRes = 0; iRes < mEntries.size(); iRes++) + { + if (mEntries[iRes] == pEntry) + { + QModelIndex Out = index(mDirectories.size() + iRes, 0); + ASSERT(IndexEntry(Out) == pEntry); + return Out; + } + } + + return QModelIndex(); + } + CResourceEntry* IndexEntry(const QModelIndex& rkIndex) const { int Index = rkIndex.row() - mDirectories.size(); @@ -144,7 +159,12 @@ protected: void RecursiveAddDirectoryContents(CVirtualDirectory *pDir) { for (u32 iRes = 0; iRes < pDir->NumResources(); iRes++) - mEntries << pDir->ResourceByIndex(iRes); + { + CResourceEntry *pEntry = pDir->ResourceByIndex(iRes); + + if (pEntry->TypeInfo()->IsVisibleInBrowser() && !pEntry->IsHidden()) + mEntries << pDir->ResourceByIndex(iRes); + } for (u32 iDir = 0; iDir < pDir->NumSubdirectories(); iDir++) RecursiveAddDirectoryContents(pDir->SubdirectoryByIndex(iDir)); diff --git a/src/Editor/Widgets/CResourceSelector.cpp b/src/Editor/Widgets/CResourceSelector.cpp index c5df11e2..b8acb3e7 100644 --- a/src/Editor/Widgets/CResourceSelector.cpp +++ b/src/Editor/Widgets/CResourceSelector.cpp @@ -47,6 +47,7 @@ CResourceSelector::CResourceSelector(QWidget *pParent /*= 0*/) // UI Connections connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(CreateContextMenu(QPoint))); connect(mpSetButton, SIGNAL(clicked()), this, SLOT(Set())); + connect(mpFindButton, SIGNAL(clicked()), this, SLOT(Find())); connect(mpClearButton, SIGNAL(clicked()), this, SLOT(Clear())); // Set up context menu @@ -144,6 +145,14 @@ void CResourceSelector::Set() } } +void CResourceSelector::Find() +{ + CResourceBrowser *pBrowser = gpEdApp->ResourceBrowser(); + pBrowser->SelectResource(mpResEntry); + pBrowser->show(); + pBrowser->raise(); +} + void CResourceSelector::Clear() { mpResEntry = nullptr; diff --git a/src/Editor/Widgets/CResourceSelector.h b/src/Editor/Widgets/CResourceSelector.h index e24778eb..414f5c27 100644 --- a/src/Editor/Widgets/CResourceSelector.h +++ b/src/Editor/Widgets/CResourceSelector.h @@ -39,6 +39,7 @@ public: public slots: void CreateContextMenu(const QPoint& rkPoint); void Set(); + void Find(); void Clear(); void EditAsset(); void CopyName();