forked from qt-creator/qt-creator
CppEditor: de-noise
Change-Id: I8b5c160912ca7da4bbd4ebb01a8b7d5360fb3bbc Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
@@ -83,6 +83,7 @@
|
|||||||
|
|
||||||
enum { UPDATE_FUNCTION_DECL_DEF_LINK_INTERVAL = 200 };
|
enum { UPDATE_FUNCTION_DECL_DEF_LINK_INTERVAL = 200 };
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
using namespace CppTools;
|
using namespace CppTools;
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
@@ -115,7 +116,7 @@ public:
|
|||||||
CppLocalRenaming m_localRenaming;
|
CppLocalRenaming m_localRenaming;
|
||||||
|
|
||||||
CppTools::SemanticInfo m_lastSemanticInfo;
|
CppTools::SemanticInfo m_lastSemanticInfo;
|
||||||
QList<TextEditor::QuickFixOperation::Ptr> m_quickFixes;
|
QList<QuickFixOperation::Ptr> m_quickFixes;
|
||||||
|
|
||||||
CppUseSelectionsUpdater m_useSelectionsUpdater;
|
CppUseSelectionsUpdater m_useSelectionsUpdater;
|
||||||
|
|
||||||
@@ -211,12 +212,12 @@ void CppEditorWidget::finalizeInitialization()
|
|||||||
// Tool bar creation
|
// Tool bar creation
|
||||||
d->m_preprocessorButton = new QToolButton(this);
|
d->m_preprocessorButton = new QToolButton(this);
|
||||||
d->m_preprocessorButton->setText(QLatin1String("#"));
|
d->m_preprocessorButton->setText(QLatin1String("#"));
|
||||||
Core::Command *cmd = Core::ActionManager::command(Constants::OPEN_PREPROCESSOR_DIALOG);
|
Command *cmd = ActionManager::command(Constants::OPEN_PREPROCESSOR_DIALOG);
|
||||||
connect(cmd, SIGNAL(keySequenceChanged()), this, SLOT(updatePreprocessorButtonTooltip()));
|
connect(cmd, SIGNAL(keySequenceChanged()), this, SLOT(updatePreprocessorButtonTooltip()));
|
||||||
updatePreprocessorButtonTooltip();
|
updatePreprocessorButtonTooltip();
|
||||||
connect(d->m_preprocessorButton, SIGNAL(clicked()), this, SLOT(showPreProcessorWidget()));
|
connect(d->m_preprocessorButton, SIGNAL(clicked()), this, SLOT(showPreProcessorWidget()));
|
||||||
insertExtraToolBarWidget(TextEditor::BaseTextEditorWidget::Left, d->m_preprocessorButton);
|
insertExtraToolBarWidget(BaseTextEditorWidget::Left, d->m_preprocessorButton);
|
||||||
insertExtraToolBarWidget(TextEditor::BaseTextEditorWidget::Left, d->m_cppEditorOutline->widget());
|
insertExtraToolBarWidget(BaseTextEditorWidget::Left, d->m_cppEditorOutline->widget());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppEditorWidget::finalizeInitializationAfterDuplication(BaseTextEditorWidget *other)
|
void CppEditorWidget::finalizeInitializationAfterDuplication(BaseTextEditorWidget *other)
|
||||||
@@ -285,7 +286,7 @@ void CppEditorWidget::onCodeWarningsUpdated(unsigned revision,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CppEditorWidget::onIfdefedOutBlocksUpdated(unsigned revision,
|
void CppEditorWidget::onIfdefedOutBlocksUpdated(unsigned revision,
|
||||||
const QList<TextEditor::BlockRange> ifdefedOutBlocks)
|
const QList<BlockRange> ifdefedOutBlocks)
|
||||||
{
|
{
|
||||||
if (revision != documentRevision())
|
if (revision != documentRevision())
|
||||||
return;
|
return;
|
||||||
@@ -343,7 +344,7 @@ void CppEditorWidget::renameSymbolUnderCursor()
|
|||||||
void CppEditorWidget::updatePreprocessorButtonTooltip()
|
void CppEditorWidget::updatePreprocessorButtonTooltip()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(d->m_preprocessorButton, return);
|
QTC_ASSERT(d->m_preprocessorButton, return);
|
||||||
Core::Command *cmd = Core::ActionManager::command(Constants::OPEN_PREPROCESSOR_DIALOG);
|
Command *cmd = ActionManager::command(Constants::OPEN_PREPROCESSOR_DIALOG);
|
||||||
QTC_ASSERT(cmd, return);
|
QTC_ASSERT(cmd, return);
|
||||||
d->m_preprocessorButton->setToolTip(cmd->action()->toolTip());
|
d->m_preprocessorButton->setToolTip(cmd->action()->toolTip());
|
||||||
}
|
}
|
||||||
@@ -470,7 +471,7 @@ bool CppEditorWidget::event(QEvent *e)
|
|||||||
|
|
||||||
void CppEditorWidget::performQuickFix(int index)
|
void CppEditorWidget::performQuickFix(int index)
|
||||||
{
|
{
|
||||||
TextEditor::QuickFixOperation::Ptr op = d->m_quickFixes.at(index);
|
QuickFixOperation::Ptr op = d->m_quickFixes.at(index);
|
||||||
op->perform();
|
op->perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,30 +487,25 @@ void CppEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
|||||||
|
|
||||||
QPointer<QMenu> menu(new QMenu(this));
|
QPointer<QMenu> menu(new QMenu(this));
|
||||||
|
|
||||||
Core::ActionContainer *mcontext = Core::ActionManager::actionContainer(Constants::M_CONTEXT);
|
ActionContainer *mcontext = ActionManager::actionContainer(Constants::M_CONTEXT);
|
||||||
QMenu *contextMenu = mcontext->menu();
|
QMenu *contextMenu = mcontext->menu();
|
||||||
|
|
||||||
QMenu *quickFixMenu = new QMenu(tr("&Refactor"), menu);
|
QMenu *quickFixMenu = new QMenu(tr("&Refactor"), menu);
|
||||||
quickFixMenu->addAction(Core::ActionManager::command(
|
quickFixMenu->addAction(ActionManager::command(Constants::RENAME_SYMBOL_UNDER_CURSOR)->action());
|
||||||
Constants::RENAME_SYMBOL_UNDER_CURSOR)->action());
|
|
||||||
|
|
||||||
QSignalMapper mapper;
|
QSignalMapper mapper;
|
||||||
connect(&mapper, SIGNAL(mapped(int)), this, SLOT(performQuickFix(int)));
|
connect(&mapper, SIGNAL(mapped(int)), this, SLOT(performQuickFix(int)));
|
||||||
if (isSemanticInfoValid()) {
|
if (isSemanticInfoValid()) {
|
||||||
TextEditor::IAssistInterface *interface =
|
IAssistInterface *interface = createAssistInterface(QuickFix, ExplicitlyInvoked);
|
||||||
createAssistInterface(TextEditor::QuickFix, TextEditor::ExplicitlyInvoked);
|
|
||||||
if (interface) {
|
if (interface) {
|
||||||
QScopedPointer<TextEditor::IAssistProcessor> processor(
|
QScopedPointer<IAssistProcessor> processor(
|
||||||
CppEditorPlugin::instance()->quickFixProvider()->createProcessor());
|
CppEditorPlugin::instance()->quickFixProvider()->createProcessor());
|
||||||
QScopedPointer<TextEditor::IAssistProposal> proposal(processor->perform(interface));
|
QScopedPointer<IAssistProposal> proposal(processor->perform(interface));
|
||||||
if (!proposal.isNull()) {
|
if (!proposal.isNull()) {
|
||||||
TextEditor::BasicProposalItemListModel *model =
|
auto model = static_cast<BasicProposalItemListModel *>(proposal->model());
|
||||||
static_cast<TextEditor::BasicProposalItemListModel *>(proposal->model());
|
|
||||||
for (int index = 0; index < model->size(); ++index) {
|
for (int index = 0; index < model->size(); ++index) {
|
||||||
TextEditor::BasicProposalItem *item =
|
auto item = static_cast<BasicProposalItem *>(model->proposalItem(index));
|
||||||
static_cast<TextEditor::BasicProposalItem *>(model->proposalItem(index));
|
QuickFixOperation::Ptr op = item->data().value<QuickFixOperation::Ptr>();
|
||||||
TextEditor::QuickFixOperation::Ptr op =
|
|
||||||
item->data().value<TextEditor::QuickFixOperation::Ptr>();
|
|
||||||
d->m_quickFixes.append(op);
|
d->m_quickFixes.append(op);
|
||||||
QAction *action = quickFixMenu->addAction(op->description());
|
QAction *action = quickFixMenu->addAction(op->description());
|
||||||
mapper.setMapping(action, index);
|
mapper.setMapping(action, index);
|
||||||
@@ -543,13 +539,13 @@ void CppEditorWidget::keyPressEvent(QKeyEvent *e)
|
|||||||
if (d->m_cppDocumentationCommentHelper.handleKeyPressEvent(e))
|
if (d->m_cppDocumentationCommentHelper.handleKeyPressEvent(e))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TextEditor::BaseTextEditorWidget::keyPressEvent(e);
|
BaseTextEditorWidget::keyPressEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppEditorWidget::applyFontSettings()
|
void CppEditorWidget::applyFontSettings()
|
||||||
{
|
{
|
||||||
// This also makes the document apply font settings
|
// This also makes the document apply font settings
|
||||||
TextEditor::BaseTextEditorWidget::applyFontSettings();
|
BaseTextEditorWidget::applyFontSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppEditorWidget::slotCodeStyleSettingsChanged(const QVariant &)
|
void CppEditorWidget::slotCodeStyleSettingsChanged(const QVariant &)
|
||||||
@@ -583,14 +579,14 @@ bool CppEditorWidget::openCppEditorAt(const Link &link, bool inNextSplit)
|
|||||||
if (!link.hasValidTarget())
|
if (!link.hasValidTarget())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Core::EditorManager::OpenEditorFlags flags;
|
EditorManager::OpenEditorFlags flags;
|
||||||
if (inNextSplit)
|
if (inNextSplit)
|
||||||
flags |= Core::EditorManager::OpenInOtherSplit;
|
flags |= EditorManager::OpenInOtherSplit;
|
||||||
return Core::EditorManager::openEditorAt(link.targetFileName,
|
return EditorManager::openEditorAt(link.targetFileName,
|
||||||
link.targetLine,
|
link.targetLine,
|
||||||
link.targetColumn,
|
link.targetColumn,
|
||||||
Constants::CPPEDITOR_ID,
|
Constants::CPPEDITOR_ID,
|
||||||
flags);
|
flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppEditorWidget::updateSemanticInfo(const SemanticInfo &semanticInfo,
|
void CppEditorWidget::updateSemanticInfo(const SemanticInfo &semanticInfo,
|
||||||
@@ -612,11 +608,9 @@ void CppEditorWidget::updateSemanticInfo(const SemanticInfo &semanticInfo,
|
|||||||
updateFunctionDeclDefLink();
|
updateFunctionDeclDefLink();
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditor::IAssistInterface *CppEditorWidget::createAssistInterface(
|
IAssistInterface *CppEditorWidget::createAssistInterface(AssistKind kind, AssistReason reason) const
|
||||||
TextEditor::AssistKind kind,
|
|
||||||
TextEditor::AssistReason reason) const
|
|
||||||
{
|
{
|
||||||
if (kind == TextEditor::Completion) {
|
if (kind == Completion) {
|
||||||
if (CppCompletionAssistProvider *cap = cppEditorDocument()->completionAssistProvider()) {
|
if (CppCompletionAssistProvider *cap = cppEditorDocument()->completionAssistProvider()) {
|
||||||
return cap->createAssistInterface(
|
return cap->createAssistInterface(
|
||||||
ProjectExplorer::ProjectExplorerPlugin::currentProject(),
|
ProjectExplorer::ProjectExplorerPlugin::currentProject(),
|
||||||
@@ -626,10 +620,9 @@ TextEditor::IAssistInterface *CppEditorWidget::createAssistInterface(
|
|||||||
position(),
|
position(),
|
||||||
reason);
|
reason);
|
||||||
}
|
}
|
||||||
} else if (kind == TextEditor::QuickFix) {
|
} else if (kind == QuickFix) {
|
||||||
if (!isSemanticInfoValid())
|
if (isSemanticInfoValid())
|
||||||
return 0;
|
return new CppQuickFixAssistInterface(const_cast<CppEditorWidget *>(this), reason);
|
||||||
return new CppQuickFixAssistInterface(const_cast<CppEditorWidget *>(this), reason);
|
|
||||||
} else {
|
} else {
|
||||||
return BaseTextEditorWidget::createAssistInterface(kind, reason);
|
return BaseTextEditorWidget::createAssistInterface(kind, reason);
|
||||||
}
|
}
|
||||||
@@ -641,7 +634,7 @@ QSharedPointer<FunctionDeclDefLink> CppEditorWidget::declDefLink() const
|
|||||||
return d->m_declDefLink;
|
return d->m_declDefLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppEditorWidget::onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker)
|
void CppEditorWidget::onRefactorMarkerClicked(const RefactorMarker &marker)
|
||||||
{
|
{
|
||||||
if (marker.data.canConvert<FunctionDeclDefLink::Marker>())
|
if (marker.data.canConvert<FunctionDeclDefLink::Marker>())
|
||||||
applyDeclDefLinkChanges(true);
|
applyDeclDefLinkChanges(true);
|
||||||
@@ -679,7 +672,7 @@ void CppEditorWidget::updateFunctionDeclDefLinkNow()
|
|||||||
if (noTracking)
|
if (noTracking)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (Core::EditorManager::currentEditor()->widget() != this)
|
if (EditorManager::currentEditor()->widget() != this)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const Snapshot semanticSnapshot = d->m_lastSemanticInfo.snapshot;
|
const Snapshot semanticSnapshot = d->m_lastSemanticInfo.snapshot;
|
||||||
@@ -708,10 +701,9 @@ void CppEditorWidget::onFunctionDeclDefLinkFound(QSharedPointer<FunctionDeclDefL
|
|||||||
{
|
{
|
||||||
abortDeclDefLink();
|
abortDeclDefLink();
|
||||||
d->m_declDefLink = link;
|
d->m_declDefLink = link;
|
||||||
Core::IDocument *targetDocument
|
IDocument *targetDocument = DocumentModel::documentForFilePath( d->m_declDefLink->targetFile->fileName());
|
||||||
= Core::DocumentModel::documentForFilePath( d->m_declDefLink->targetFile->fileName());
|
|
||||||
if (textDocument() != targetDocument) {
|
if (textDocument() != targetDocument) {
|
||||||
if (auto textDocument = qobject_cast<TextEditor::BaseTextDocument *>(targetDocument))
|
if (auto textDocument = qobject_cast<BaseTextDocument *>(targetDocument))
|
||||||
connect(textDocument, SIGNAL(contentsChanged()),
|
connect(textDocument, SIGNAL(contentsChanged()),
|
||||||
this, SLOT(abortDeclDefLink()));
|
this, SLOT(abortDeclDefLink()));
|
||||||
}
|
}
|
||||||
@@ -764,10 +756,9 @@ void CppEditorWidget::abortDeclDefLink()
|
|||||||
if (!d->m_declDefLink)
|
if (!d->m_declDefLink)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Core::IDocument *targetDocument
|
IDocument *targetDocument = DocumentModel::documentForFilePath(d->m_declDefLink->targetFile->fileName());
|
||||||
= Core::DocumentModel::documentForFilePath(d->m_declDefLink->targetFile->fileName());
|
|
||||||
if (textDocument() != targetDocument) {
|
if (textDocument() != targetDocument) {
|
||||||
if (auto textDocument = qobject_cast<TextEditor::BaseTextDocument *>(targetDocument))
|
if (auto textDocument = qobject_cast<BaseTextDocument *>(targetDocument))
|
||||||
disconnect(textDocument, SIGNAL(contentsChanged()),
|
disconnect(textDocument, SIGNAL(contentsChanged()),
|
||||||
this, SLOT(abortDeclDefLink()));
|
this, SLOT(abortDeclDefLink()));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user