forked from qt-creator/qt-creator
ProjectTree: Add command to manually sync current document and project tree
Add a command to manually sync the current document and the project tree. Task-number: QTCREATORBUG-19625 Change-Id: I2423853ca1a876c6203a004b465adde949eb6c5b Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
#include "projectmodels.h"
|
#include "projectmodels.h"
|
||||||
#include "projecttree.h"
|
#include "projecttree.h"
|
||||||
|
|
||||||
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
#include <coreplugin/actionmanager/command.h>
|
#include <coreplugin/actionmanager/command.h>
|
||||||
#include <coreplugin/documentmanager.h>
|
#include <coreplugin/documentmanager.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
@@ -255,6 +256,13 @@ ProjectTreeWidget::ProjectTreeWidget(QWidget *parent) : QWidget(parent)
|
|||||||
connect(m_filterGeneratedFilesAction, &QAction::toggled,
|
connect(m_filterGeneratedFilesAction, &QAction::toggled,
|
||||||
this, &ProjectTreeWidget::setGeneratedFilesFilter);
|
this, &ProjectTreeWidget::setGeneratedFilesFilter);
|
||||||
|
|
||||||
|
auto focusDocumentInProjectTree = new QAction(tr("Focus Document in Project Tree"), this);
|
||||||
|
Command *cmd = ActionManager::registerAction(focusDocumentInProjectTree,
|
||||||
|
"ProjectExplorer.FocusDocumentInProjectTree");
|
||||||
|
cmd->setDefaultKeySequence(QKeySequence(tr("Alt+Shift+L")));
|
||||||
|
connect(focusDocumentInProjectTree, &QAction::triggered,
|
||||||
|
this, [this]() { syncFromDocumentManager(); });
|
||||||
|
|
||||||
m_trimEmptyDirectoriesAction = new QAction(tr("Hide Empty Directories"), this);
|
m_trimEmptyDirectoriesAction = new QAction(tr("Hide Empty Directories"), this);
|
||||||
m_trimEmptyDirectoriesAction->setCheckable(true);
|
m_trimEmptyDirectoriesAction->setCheckable(true);
|
||||||
m_trimEmptyDirectoriesAction->setChecked(true);
|
m_trimEmptyDirectoriesAction->setChecked(true);
|
||||||
@@ -393,14 +401,8 @@ void ProjectTreeWidget::setAutoSynchronization(bool sync)
|
|||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << (m_autoSync ? "Enabling auto synchronization" : "Disabling auto synchronization");
|
qDebug() << (m_autoSync ? "Enabling auto synchronization" : "Disabling auto synchronization");
|
||||||
|
|
||||||
if (m_autoSync) {
|
if (m_autoSync)
|
||||||
// sync from document manager
|
syncFromDocumentManager();
|
||||||
FileName fileName;
|
|
||||||
if (IDocument *doc = EditorManager::currentDocument())
|
|
||||||
fileName = doc->filePath();
|
|
||||||
if (!currentNode() || currentNode()->filePath() != fileName)
|
|
||||||
setCurrentItem(ProjectTreeWidget::nodeForFile(fileName));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectTreeWidget::collapseAll()
|
void ProjectTreeWidget::collapseAll()
|
||||||
@@ -429,12 +431,28 @@ void ProjectTreeWidget::renamed(const FileName &oldPath, const FileName &newPath
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProjectTreeWidget::syncFromDocumentManager()
|
||||||
|
{
|
||||||
|
// sync from document manager
|
||||||
|
FileName fileName;
|
||||||
|
if (IDocument *doc = EditorManager::currentDocument())
|
||||||
|
fileName = doc->filePath();
|
||||||
|
if (!currentNode() || currentNode()->filePath() != fileName)
|
||||||
|
setCurrentItem(ProjectTreeWidget::nodeForFile(fileName));
|
||||||
|
}
|
||||||
|
|
||||||
void ProjectTreeWidget::setCurrentItem(Node *node)
|
void ProjectTreeWidget::setCurrentItem(Node *node)
|
||||||
{
|
{
|
||||||
const QModelIndex mainIndex = m_model->indexForNode(node);
|
const QModelIndex mainIndex = m_model->indexForNode(node);
|
||||||
|
|
||||||
if (mainIndex.isValid()) {
|
if (mainIndex.isValid()) {
|
||||||
if (mainIndex != m_view->selectionModel()->currentIndex()) {
|
if (mainIndex != m_view->selectionModel()->currentIndex()) {
|
||||||
|
// Expand everything between the index and the root index!
|
||||||
|
QModelIndex parent = mainIndex.parent();
|
||||||
|
while (parent.isValid()) {
|
||||||
|
m_view->setExpanded(parent, true);
|
||||||
|
parent = parent.parent();
|
||||||
|
}
|
||||||
m_view->setCurrentIndex(mainIndex);
|
m_view->setCurrentIndex(mainIndex);
|
||||||
m_view->scrollTo(mainIndex);
|
m_view->scrollTo(mainIndex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,6 +81,8 @@ private:
|
|||||||
void rowsInserted(const QModelIndex &parent, int start, int end);
|
void rowsInserted(const QModelIndex &parent, int start, int end);
|
||||||
void renamed(const Utils::FileName &oldPath, const Utils::FileName &newPath);
|
void renamed(const Utils::FileName &oldPath, const Utils::FileName &newPath);
|
||||||
|
|
||||||
|
void syncFromDocumentManager();
|
||||||
|
|
||||||
QTreeView *m_view = nullptr;
|
QTreeView *m_view = nullptr;
|
||||||
FlatModel *m_model = nullptr;
|
FlatModel *m_model = nullptr;
|
||||||
QAction *m_filterProjectsAction = nullptr;
|
QAction *m_filterProjectsAction = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user