2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-02-18 10:36:52 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-02-18 10:36:52 +01:00
|
|
|
|
2010-07-08 11:15:26 +02:00
|
|
|
#include "outlinefactory.h"
|
2010-07-30 22:16:59 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2010-07-14 16:46:54 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2010-07-08 11:15:26 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2011-01-24 12:29:48 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QStackedWidget>
|
2011-01-24 12:29:48 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
2010-07-08 11:15:26 +02:00
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
OutlineWidgetStack::OutlineWidgetStack(OutlineFactory *factory) :
|
|
|
|
|
QStackedWidget(),
|
|
|
|
|
m_factory(factory),
|
2010-07-16 11:04:20 +02:00
|
|
|
m_syncWithEditor(true),
|
|
|
|
|
m_position(-1)
|
2010-07-08 11:15:26 +02:00
|
|
|
{
|
|
|
|
|
QLabel *label = new QLabel(tr("No outline available"), this);
|
|
|
|
|
label->setAlignment(Qt::AlignCenter);
|
2010-07-13 14:15:54 +02:00
|
|
|
|
|
|
|
|
// set background to be white
|
|
|
|
|
label->setAutoFillBackground(true);
|
|
|
|
|
label->setBackgroundRole(QPalette::Base);
|
|
|
|
|
|
2010-07-08 11:15:26 +02:00
|
|
|
addWidget(label);
|
|
|
|
|
|
|
|
|
|
m_toggleSync = new QToolButton;
|
2010-07-30 22:16:59 +02:00
|
|
|
m_toggleSync->setIcon(QIcon(QLatin1String(Core::Constants::ICON_LINK)));
|
2010-07-08 11:15:26 +02:00
|
|
|
m_toggleSync->setCheckable(true);
|
|
|
|
|
m_toggleSync->setChecked(true);
|
|
|
|
|
m_toggleSync->setToolTip(tr("Synchronize with Editor"));
|
|
|
|
|
connect(m_toggleSync, SIGNAL(clicked(bool)), this, SLOT(toggleCursorSynchronization()));
|
|
|
|
|
|
2010-07-14 16:46:54 +02:00
|
|
|
m_filterButton = new QToolButton;
|
2010-07-30 22:16:59 +02:00
|
|
|
m_filterButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_FILTER)));
|
2010-07-14 16:46:54 +02:00
|
|
|
m_filterButton->setToolTip(tr("Filter tree"));
|
|
|
|
|
m_filterButton->setPopupMode(QToolButton::InstantPopup);
|
2012-02-01 21:39:05 +01:00
|
|
|
m_filterButton->setProperty("noArrow", true);
|
2010-07-14 16:46:54 +02:00
|
|
|
m_filterMenu = new QMenu(m_filterButton);
|
|
|
|
|
m_filterButton->setMenu(m_filterMenu);
|
|
|
|
|
|
2013-08-29 15:46:04 +02:00
|
|
|
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
|
2010-07-08 11:15:26 +02:00
|
|
|
this, SLOT(updateCurrentEditor(Core::IEditor*)));
|
2012-05-08 09:43:14 +02:00
|
|
|
updateCurrentEditor(Core::EditorManager::currentEditor());
|
2010-07-08 11:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OutlineWidgetStack::~OutlineWidgetStack()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QToolButton *OutlineWidgetStack::toggleSyncButton()
|
|
|
|
|
{
|
|
|
|
|
return m_toggleSync;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-14 16:46:54 +02:00
|
|
|
QToolButton *OutlineWidgetStack::filterButton()
|
|
|
|
|
{
|
|
|
|
|
return m_filterButton;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-05 11:05:28 +01:00
|
|
|
static inline QString outLineKey(int position)
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String("Outline.") + QString::number(position) + QLatin1String(".SyncWithEditor");
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-16 11:04:20 +02:00
|
|
|
void OutlineWidgetStack::restoreSettings(int position)
|
|
|
|
|
{
|
|
|
|
|
m_position = position; // save it so that we can save/restore in updateCurrentEditor
|
|
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2012-01-05 11:05:28 +01:00
|
|
|
const bool toggleSync = settings->value(outLineKey(position), true).toBool();
|
2010-07-16 11:04:20 +02:00
|
|
|
toggleSyncButton()->setChecked(toggleSync);
|
|
|
|
|
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget()))
|
2010-07-16 11:04:20 +02:00
|
|
|
outlineWidget->restoreSettings(position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OutlineWidgetStack::saveSettings(int position)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(position == m_position);
|
|
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2012-01-05 11:05:28 +01:00
|
|
|
settings->setValue(outLineKey(position), toggleSyncButton()->isEnabled());
|
2010-07-16 11:04:20 +02:00
|
|
|
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget()))
|
2010-07-16 11:04:20 +02:00
|
|
|
outlineWidget->saveSettings(position);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-08 11:15:26 +02:00
|
|
|
bool OutlineWidgetStack::isCursorSynchronized() const
|
|
|
|
|
{
|
|
|
|
|
return m_syncWithEditor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OutlineWidgetStack::toggleCursorSynchronization()
|
|
|
|
|
{
|
|
|
|
|
m_syncWithEditor = !m_syncWithEditor;
|
|
|
|
|
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget()))
|
|
|
|
|
outlineWidget->setCursorSynchronization(m_syncWithEditor);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-14 16:46:54 +02:00
|
|
|
void OutlineWidgetStack::updateFilterMenu()
|
|
|
|
|
{
|
|
|
|
|
m_filterMenu->clear();
|
|
|
|
|
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget())) {
|
|
|
|
|
foreach (QAction *filterAction, outlineWidget->filterMenuActions()) {
|
|
|
|
|
m_filterMenu->addAction(filterAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-25 17:47:39 -04:00
|
|
|
m_filterButton->setVisible(!m_filterMenu->actions().isEmpty());
|
2010-07-14 16:46:54 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-08 11:15:26 +02:00
|
|
|
void OutlineWidgetStack::updateCurrentEditor(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
IOutlineWidget *newWidget = 0;
|
|
|
|
|
|
|
|
|
|
if (editor) {
|
|
|
|
|
foreach (IOutlineWidgetFactory *widgetFactory, m_factory->widgetFactories()) {
|
|
|
|
|
if (widgetFactory->supportsEditor(editor)) {
|
|
|
|
|
newWidget = widgetFactory->createWidget(editor);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (newWidget != currentWidget()) {
|
|
|
|
|
// delete old widget
|
|
|
|
|
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget())) {
|
2010-07-16 11:04:20 +02:00
|
|
|
if (m_position > -1)
|
|
|
|
|
outlineWidget->saveSettings(m_position);
|
2010-07-08 11:15:26 +02:00
|
|
|
removeWidget(outlineWidget);
|
|
|
|
|
delete outlineWidget;
|
|
|
|
|
}
|
|
|
|
|
if (newWidget) {
|
2010-07-16 11:04:20 +02:00
|
|
|
if (m_position > -1)
|
|
|
|
|
newWidget->restoreSettings(m_position);
|
2010-07-08 11:15:26 +02:00
|
|
|
newWidget->setCursorSynchronization(m_syncWithEditor);
|
|
|
|
|
addWidget(newWidget);
|
|
|
|
|
setCurrentWidget(newWidget);
|
2014-04-09 17:04:50 +02:00
|
|
|
setFocusProxy(newWidget);
|
2010-07-08 11:15:26 +02:00
|
|
|
}
|
2010-07-22 13:02:47 +02:00
|
|
|
|
|
|
|
|
updateFilterMenu();
|
2010-07-08 11:15:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 11:15:32 +02:00
|
|
|
OutlineFactory::OutlineFactory()
|
|
|
|
|
{
|
|
|
|
|
setDisplayName(tr("Outline"));
|
|
|
|
|
setId("Outline");
|
|
|
|
|
setPriority(600);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-08 11:15:26 +02:00
|
|
|
QList<IOutlineWidgetFactory*> OutlineFactory::widgetFactories() const
|
|
|
|
|
{
|
|
|
|
|
return m_factories;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OutlineFactory::setWidgetFactories(QList<IOutlineWidgetFactory*> factories)
|
|
|
|
|
{
|
|
|
|
|
m_factories = factories;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::NavigationView OutlineFactory::createWidget()
|
|
|
|
|
{
|
|
|
|
|
Core::NavigationView n;
|
|
|
|
|
OutlineWidgetStack *placeHolder = new OutlineWidgetStack(this);
|
|
|
|
|
n.widget = placeHolder;
|
2010-07-14 16:46:54 +02:00
|
|
|
n.dockToolBarWidgets.append(placeHolder->filterButton());
|
2010-07-22 12:58:19 +02:00
|
|
|
n.dockToolBarWidgets.append(placeHolder->toggleSyncButton());
|
2010-07-08 11:15:26 +02:00
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-16 08:18:56 +02:00
|
|
|
void OutlineFactory::saveSettings(int position, QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
OutlineWidgetStack *widgetStack = qobject_cast<OutlineWidgetStack *>(widget);
|
|
|
|
|
Q_ASSERT(widgetStack);
|
2010-07-16 11:04:20 +02:00
|
|
|
widgetStack->saveSettings(position);
|
2010-07-16 08:18:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OutlineFactory::restoreSettings(int position, QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
OutlineWidgetStack *widgetStack = qobject_cast<OutlineWidgetStack *>(widget);
|
|
|
|
|
Q_ASSERT(widgetStack);
|
2010-07-16 11:04:20 +02:00
|
|
|
widgetStack->restoreSettings(position);
|
2010-07-16 08:18:56 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-08 11:15:26 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace TextEditor
|