aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/projectexplorer/currentprojectfilter.cpp
blob: d0f9ed99b0a9efdd1b280344245e83db1ef6d15a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "currentprojectfilter.h"

#include "project.h"
#include "projectexplorertr.h"
#include "projecttree.h"

using namespace Core;
using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;
using namespace Utils;

CurrentProjectFilter::CurrentProjectFilter()
{
    setId("Files in current project");
    setDisplayName(Tr::tr("Files in Current Project"));
    setDescription(Tr::tr("Locates files from the current document's project. Append \"+<number>\" "
                          "or \":<number>\" to jump to the given line number. Append another "
                          "\"+<number>\" or \":<number>\" to jump to the column number as well."));
    setDefaultShortcutString("p");
    setRefreshRecipe(Tasking::Sync([this] { invalidate(); }));

    connect(ProjectTree::instance(), &ProjectTree::currentProjectChanged,
            this, &CurrentProjectFilter::currentProjectChanged);

    m_cache.setGeneratorProvider([this] {
        const FilePaths paths = m_project ? m_project->files(Project::SourceFiles) : FilePaths();
        return LocatorFileCache::filePathsGenerator(paths);
    });
}

void CurrentProjectFilter::currentProjectChanged()
{
    Project *project = ProjectTree::currentProject();
    if (project == m_project)
        return;

    if (m_project)
        disconnect(m_project, &Project::fileListChanged, this, &CurrentProjectFilter::invalidate);
    m_project = project;
    if (m_project)
        connect(m_project, &Project::fileListChanged, this, &CurrentProjectFilter::invalidate);

    invalidate();
}