Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Tobias Hunger
qt-creator
Commits
575495b9
Commit
575495b9
authored
May 14, 2009
by
Christian Hoenig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement CppCurrentDocumentFilter for symbols in current document
parent
57bb98b6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
232 additions
and
14 deletions
+232
-14
src/plugins/cpptools/cppcurrentdocumentfilter.cpp
src/plugins/cpptools/cppcurrentdocumentfilter.cpp
+138
-0
src/plugins/cpptools/cppcurrentdocumentfilter.h
src/plugins/cpptools/cppcurrentdocumentfilter.h
+75
-0
src/plugins/cpptools/cpptools.pro
src/plugins/cpptools/cpptools.pro
+2
-0
src/plugins/cpptools/cpptoolsplugin.cpp
src/plugins/cpptools/cpptoolsplugin.cpp
+2
-0
src/plugins/cpptools/searchsymbols.cpp
src/plugins/cpptools/searchsymbols.cpp
+10
-7
src/plugins/cpptools/searchsymbols.h
src/plugins/cpptools/searchsymbols.h
+5
-7
No files found.
src/plugins/cpptools/cppcurrentdocumentfilter.cpp
0 → 100644
View file @
575495b9
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
**
**************************************************************************/
#include "cppcurrentdocumentfilter.h"
#include "cppmodelmanager.h"
#include <coreplugin/editormanager/editormanager.h>
#include <cplusplus/CppDocument.h>
using
namespace
CppTools
::
Internal
;
using
namespace
CPlusPlus
;
CppCurrentDocumentFilter
::
CppCurrentDocumentFilter
(
CppModelManager
*
manager
,
Core
::
EditorManager
*
editorManager
)
:
m_modelManager
(
manager
)
{
setShortcutString
(
"."
);
setIncludedByDefault
(
false
);
search
.
setSymbolsToSearchFor
(
SearchSymbols
::
Declarations
|
SearchSymbols
::
Enums
|
SearchSymbols
::
Functions
|
SearchSymbols
::
Classes
);
search
.
setSeparateScope
(
true
);
connect
(
manager
,
SIGNAL
(
documentUpdated
(
CPlusPlus
::
Document
::
Ptr
)),
this
,
SLOT
(
onDocumentUpdated
(
CPlusPlus
::
Document
::
Ptr
)));
connect
(
editorManager
,
SIGNAL
(
currentEditorChanged
(
Core
::
IEditor
*
)),
this
,
SLOT
(
onCurrentEditorChanged
(
Core
::
IEditor
*
)));
connect
(
editorManager
,
SIGNAL
(
editorAboutToClose
(
Core
::
IEditor
*
)),
this
,
SLOT
(
onEditorAboutToClose
(
Core
::
IEditor
*
)));
}
QList
<
QuickOpen
::
FilterEntry
>
CppCurrentDocumentFilter
::
matchesFor
(
const
QString
&
origEntry
)
{
QString
entry
=
trimWildcards
(
origEntry
);
QList
<
QuickOpen
::
FilterEntry
>
goodEntries
;
QList
<
QuickOpen
::
FilterEntry
>
betterEntries
;
QStringMatcher
matcher
(
entry
,
Qt
::
CaseInsensitive
);
const
QRegExp
regexp
(
"*"
+
entry
+
"*"
,
Qt
::
CaseInsensitive
,
QRegExp
::
Wildcard
);
if
(
!
regexp
.
isValid
())
return
goodEntries
;
bool
hasWildcard
=
(
entry
.
contains
(
'*'
)
||
entry
.
contains
(
'?'
));
if
(
m_currentFileName
.
isEmpty
())
return
goodEntries
;
if
(
m_itemsOfCurrentDoc
.
isEmpty
())
{
Snapshot
snapshot
=
m_modelManager
->
snapshot
();
Document
::
Ptr
thisDocument
=
snapshot
.
value
(
m_currentFileName
);
if
(
thisDocument
)
m_itemsOfCurrentDoc
=
search
(
thisDocument
);
}
foreach
(
const
ModelItemInfo
&
info
,
m_itemsOfCurrentDoc
)
{
if
((
hasWildcard
&&
regexp
.
exactMatch
(
info
.
symbolName
))
||
(
!
hasWildcard
&&
matcher
.
indexIn
(
info
.
symbolName
)
!=
-
1
))
{
QString
symbolName
=
info
.
symbolName
;
// + (info.type == ModelItemInfo::Declaration ? ";" : " {...}");
QVariant
id
=
qVariantFromValue
(
info
);
QuickOpen
::
FilterEntry
filterEntry
(
this
,
symbolName
,
id
,
info
.
icon
);
filterEntry
.
extraInfo
=
info
.
symbolType
;
if
(
info
.
symbolName
.
startsWith
(
entry
))
betterEntries
.
append
(
filterEntry
);
else
goodEntries
.
append
(
filterEntry
);
}
}
// entries are unsorted by design!
betterEntries
+=
goodEntries
;
return
betterEntries
;
}
void
CppCurrentDocumentFilter
::
accept
(
QuickOpen
::
FilterEntry
selection
)
const
{
ModelItemInfo
info
=
qvariant_cast
<
CppTools
::
Internal
::
ModelItemInfo
>
(
selection
.
internalData
);
TextEditor
::
BaseTextEditor
::
openEditorAt
(
info
.
fileName
,
info
.
line
);
}
void
CppCurrentDocumentFilter
::
refresh
(
QFutureInterface
<
void
>
&
future
)
{
Q_UNUSED
(
future
);
}
void
CppCurrentDocumentFilter
::
onDocumentUpdated
(
Document
::
Ptr
doc
)
{
if
(
m_currentFileName
==
doc
->
fileName
())
{
m_itemsOfCurrentDoc
.
clear
();
}
}
void
CppCurrentDocumentFilter
::
onCurrentEditorChanged
(
Core
::
IEditor
*
currentEditor
)
{
if
(
currentEditor
)
{
m_currentFileName
=
currentEditor
->
file
()
->
fileName
();
}
else
{
m_currentFileName
.
clear
();
}
m_itemsOfCurrentDoc
.
clear
();
}
void
CppCurrentDocumentFilter
::
onEditorAboutToClose
(
Core
::
IEditor
*
editorAboutToClose
)
{
if
(
!
editorAboutToClose
)
return
;
if
(
m_currentFileName
==
editorAboutToClose
->
file
()
->
fileName
())
{
m_currentFileName
.
clear
();
m_itemsOfCurrentDoc
.
clear
();
}
}
src/plugins/cpptools/cppcurrentdocumentfilter.h
0 → 100644
View file @
575495b9
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
**
**************************************************************************/
#ifndef CPPCURRENTDOCUMENTFILTER_H
#define CPPCURRENTDOCUMENTFILTER_H
#include "searchsymbols.h"
#include <quickopen/iquickopenfilter.h>
namespace
Core
{
class
EditorManager
;
class
IEditor
;
}
namespace
CppTools
{
namespace
Internal
{
class
CppModelManager
;
class
CppCurrentDocumentFilter
:
public
QuickOpen
::
IQuickOpenFilter
{
Q_OBJECT
public:
CppCurrentDocumentFilter
(
CppModelManager
*
manager
,
Core
::
EditorManager
*
editorManager
);
~
CppCurrentDocumentFilter
()
{}
QString
trName
()
const
{
return
tr
(
"Methods in current Document"
);
}
QString
name
()
const
{
return
QLatin1String
(
"Methods in current Document"
);
}
Priority
priority
()
const
{
return
Medium
;
}
QList
<
QuickOpen
::
FilterEntry
>
matchesFor
(
const
QString
&
entry
);
void
accept
(
QuickOpen
::
FilterEntry
selection
)
const
;
void
refresh
(
QFutureInterface
<
void
>
&
future
);
private
slots
:
void
onDocumentUpdated
(
CPlusPlus
::
Document
::
Ptr
doc
);
void
onCurrentEditorChanged
(
Core
::
IEditor
*
currentEditor
);
void
onEditorAboutToClose
(
Core
::
IEditor
*
currentEditor
);
private:
CppModelManager
*
m_modelManager
;
QString
m_currentFileName
;
QList
<
ModelItemInfo
>
m_itemsOfCurrentDoc
;
SearchSymbols
search
;
};
}
// namespace Internal
}
// namespace CppTools
#endif // CPPCURRENTDOCUMENTFILTER_H
src/plugins/cpptools/cpptools.pro
View file @
575495b9
...
@@ -11,6 +11,7 @@ DEFINES += CPPTOOLS_LIBRARY
...
@@ -11,6 +11,7 @@ DEFINES += CPPTOOLS_LIBRARY
HEADERS
+=
completionsettingspage
.
h
\
HEADERS
+=
completionsettingspage
.
h
\
cppclassesfilter
.
h
\
cppclassesfilter
.
h
\
cppcodecompletion
.
h
\
cppcodecompletion
.
h
\
cppcurrentdocumentfilter
.
h
\
cppfunctionsfilter
.
h
\
cppfunctionsfilter
.
h
\
cppmodelmanager
.
h
\
cppmodelmanager
.
h
\
cppmodelmanagerinterface
.
h
\
cppmodelmanagerinterface
.
h
\
...
@@ -26,6 +27,7 @@ HEADERS += completionsettingspage.h \
...
@@ -26,6 +27,7 @@ HEADERS += completionsettingspage.h \
SOURCES
+=
completionsettingspage
.
cpp
\
SOURCES
+=
completionsettingspage
.
cpp
\
cppclassesfilter
.
cpp
\
cppclassesfilter
.
cpp
\
cppcodecompletion
.
cpp
\
cppcodecompletion
.
cpp
\
cppcurrentdocumentfilter
.
cpp
\
cppfunctionsfilter
.
cpp
\
cppfunctionsfilter
.
cpp
\
cppmodelmanager
.
cpp
\
cppmodelmanager
.
cpp
\
cppquickopenfilter
.
cpp
\
cppquickopenfilter
.
cpp
\
...
...
src/plugins/cpptools/cpptoolsplugin.cpp
View file @
575495b9
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
#include "cppclassesfilter.h"
#include "cppclassesfilter.h"
#include "cppcodecompletion.h"
#include "cppcodecompletion.h"
#include "cppfunctionsfilter.h"
#include "cppfunctionsfilter.h"
#include "cppcurrentdocumentfilter.h"
#include "cppmodelmanager.h"
#include "cppmodelmanager.h"
#include "cpptoolsconstants.h"
#include "cpptoolsconstants.h"
#include "cppquickopenfilter.h"
#include "cppquickopenfilter.h"
...
@@ -92,6 +93,7 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
...
@@ -92,6 +93,7 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
addAutoReleasedObject
(
quickOpenFilter
);
addAutoReleasedObject
(
quickOpenFilter
);
addAutoReleasedObject
(
new
CppClassesFilter
(
m_modelManager
,
core
->
editorManager
()));
addAutoReleasedObject
(
new
CppClassesFilter
(
m_modelManager
,
core
->
editorManager
()));
addAutoReleasedObject
(
new
CppFunctionsFilter
(
m_modelManager
,
core
->
editorManager
()));
addAutoReleasedObject
(
new
CppFunctionsFilter
(
m_modelManager
,
core
->
editorManager
()));
addAutoReleasedObject
(
new
CppCurrentDocumentFilter
(
m_modelManager
,
core
->
editorManager
()));
addAutoReleasedObject
(
new
CompletionSettingsPage
(
m_completion
));
addAutoReleasedObject
(
new
CompletionSettingsPage
(
m_completion
));
addAutoReleasedObject
(
new
CppFileSettingsPage
(
m_fileSettings
));
addAutoReleasedObject
(
new
CppFileSettingsPage
(
m_fileSettings
));
...
...
src/plugins/cpptools/searchsymbols.cpp
View file @
575495b9
...
@@ -128,17 +128,20 @@ bool SearchSymbols::visit(Namespace *symbol)
...
@@ -128,17 +128,20 @@ bool SearchSymbols::visit(Namespace *symbol)
return
false
;
return
false
;
}
}
#if 0
bool
SearchSymbols
::
visit
(
Declaration
*
symbol
)
bool
SearchSymbols
::
visit
(
Declaration
*
symbol
)
{
{
if (symbol->type()->isFunction()) {
if
(
!
(
symbolsToSearchFor
&
Declarations
))
QString name = scopedSymbolName(symbol);
return
false
;
QString type = overview.prettyType(symbol->type());
appendItems(name, type, ModelItemInfo::Method, symbol->fileName());
QString
name
=
symbolName
(
symbol
);
}
QString
scopedName
=
scopedSymbolName
(
name
);
QString
type
=
overview
.
prettyType
(
symbol
->
type
(),
separateScope
?
symbol
->
identity
()
:
0
);
appendItem
(
separateScope
?
type
:
scopedName
,
separateScope
?
_scope
:
type
,
ModelItemInfo
::
Declaration
,
symbol
);
return
false
;
return
false
;
}
}
#endif
bool
SearchSymbols
::
visit
(
Class
*
symbol
)
bool
SearchSymbols
::
visit
(
Class
*
symbol
)
{
{
...
...
src/plugins/cpptools/searchsymbols.h
View file @
575495b9
...
@@ -48,7 +48,7 @@ namespace Internal {
...
@@ -48,7 +48,7 @@ namespace Internal {
struct
ModelItemInfo
struct
ModelItemInfo
{
{
enum
ItemType
{
Enum
,
Class
,
Method
};
enum
ItemType
{
Enum
,
Class
,
Method
,
Declaration
};
ModelItemInfo
()
ModelItemInfo
()
{
}
{
}
...
@@ -80,9 +80,10 @@ class SearchSymbols: public std::unary_function<CPlusPlus::Document::Ptr, QList<
...
@@ -80,9 +80,10 @@ class SearchSymbols: public std::unary_function<CPlusPlus::Document::Ptr, QList<
{
{
public:
public:
enum
SymbolType
{
enum
SymbolType
{
Classes
=
0x1
,
Classes
=
0x1
,
Functions
=
0x2
,
Functions
=
0x2
,
Enums
=
0x4
Enums
=
0x4
,
Declarations
=
0x8
};
};
Q_DECLARE_FLAGS
(
SymbolTypes
,
SymbolType
)
Q_DECLARE_FLAGS
(
SymbolTypes
,
SymbolType
)
...
@@ -106,10 +107,7 @@ protected:
...
@@ -106,10 +107,7 @@ protected:
virtual
bool
visit
(
CPlusPlus
::
Enum
*
symbol
);
virtual
bool
visit
(
CPlusPlus
::
Enum
*
symbol
);
virtual
bool
visit
(
CPlusPlus
::
Function
*
symbol
);
virtual
bool
visit
(
CPlusPlus
::
Function
*
symbol
);
virtual
bool
visit
(
CPlusPlus
::
Namespace
*
symbol
);
virtual
bool
visit
(
CPlusPlus
::
Namespace
*
symbol
);
#if 0
// This visit method would make function declaration be included in QuickOpen
virtual
bool
visit
(
CPlusPlus
::
Declaration
*
symbol
);
virtual
bool
visit
(
CPlusPlus
::
Declaration
*
symbol
);
#endif
virtual
bool
visit
(
CPlusPlus
::
Class
*
symbol
);
virtual
bool
visit
(
CPlusPlus
::
Class
*
symbol
);
QString
scopedSymbolName
(
const
QString
&
symbolName
)
const
;
QString
scopedSymbolName
(
const
QString
&
symbolName
)
const
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment