2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-03-29 14:57:02 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-03-29 14:57:02 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-03-29 14:57:02 +02: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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-03-29 14:57:02 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-03-29 14:57:02 +02:00
|
|
|
|
|
|
|
|
#include "openpagesmanager.h"
|
|
|
|
|
|
|
|
|
|
#include "helpconstants.h"
|
|
|
|
|
#include "helpviewer.h"
|
2019-09-02 15:52:01 +02:00
|
|
|
#include "helpwidget.h"
|
2010-11-16 14:15:23 +01:00
|
|
|
#include "localhelpmanager.h"
|
2010-04-12 16:43:23 +02:00
|
|
|
#include "openpagesswitcher.h"
|
2010-03-29 14:57:02 +02:00
|
|
|
#include "openpageswidget.h"
|
|
|
|
|
|
2020-06-17 06:35:31 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/modemanager.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/stringutils.h>
|
|
|
|
|
#include <utils/styledbar.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QClipboard>
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QMenu>
|
2010-03-29 14:57:02 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QHelpEngine>
|
2010-03-29 14:57:02 +02:00
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
using namespace Core;
|
2010-03-29 14:57:02 +02:00
|
|
|
using namespace Help::Internal;
|
|
|
|
|
|
|
|
|
|
// -- OpenPagesManager
|
|
|
|
|
|
2019-09-02 15:52:01 +02:00
|
|
|
OpenPagesManager::OpenPagesManager(HelpWidget *helpWidget)
|
|
|
|
|
: m_helpWidget(helpWidget)
|
2010-03-29 14:57:02 +02:00
|
|
|
{
|
|
|
|
|
m_comboBox = new QComboBox;
|
2019-09-02 15:52:01 +02:00
|
|
|
m_comboBox->setModel(m_helpWidget->model());
|
2010-08-16 15:25:27 +02:00
|
|
|
m_comboBox->setContextMenuPolicy(Qt::CustomContextMenu);
|
2019-09-03 09:03:38 +02:00
|
|
|
connect(m_comboBox,
|
|
|
|
|
QOverload<int>::of(&QComboBox::activated),
|
|
|
|
|
m_helpWidget,
|
|
|
|
|
&HelpWidget::setCurrentIndex);
|
|
|
|
|
connect(m_helpWidget, &HelpWidget::currentIndexChanged, m_comboBox, &QComboBox::setCurrentIndex);
|
|
|
|
|
connect(m_comboBox,
|
|
|
|
|
&QWidget::customContextMenuRequested,
|
|
|
|
|
this,
|
|
|
|
|
&OpenPagesManager::openPagesContextMenu);
|
2010-04-12 14:55:41 +02:00
|
|
|
|
2019-09-02 15:52:01 +02:00
|
|
|
m_openPagesSwitcher = new OpenPagesSwitcher(m_helpWidget->model());
|
2016-06-28 23:07:19 +03:00
|
|
|
connect(m_openPagesSwitcher, &OpenPagesSwitcher::closePage, this,
|
|
|
|
|
&OpenPagesManager::closePage);
|
2019-09-03 09:03:38 +02:00
|
|
|
connect(m_openPagesSwitcher,
|
|
|
|
|
&OpenPagesSwitcher::setCurrentPage,
|
|
|
|
|
m_helpWidget,
|
|
|
|
|
[this](const QModelIndex &index) { m_helpWidget->setCurrentIndex(index.row()); });
|
|
|
|
|
connect(m_helpWidget,
|
|
|
|
|
&HelpWidget::currentIndexChanged,
|
|
|
|
|
m_openPagesSwitcher,
|
|
|
|
|
&OpenPagesSwitcher::selectCurrentPage);
|
2010-04-12 14:55:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenPagesManager ::~OpenPagesManager()
|
|
|
|
|
{
|
2010-04-12 16:43:23 +02:00
|
|
|
delete m_openPagesSwitcher;
|
2010-03-29 14:57:02 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-12 14:39:23 +02:00
|
|
|
QWidget *OpenPagesManager::openPagesWidget() const
|
2010-03-29 14:57:02 +02:00
|
|
|
{
|
2010-09-15 11:02:45 +02:00
|
|
|
if (!m_openPagesWidget) {
|
2019-09-02 15:52:01 +02:00
|
|
|
m_openPagesWidget = new OpenPagesWidget(m_helpWidget->model());
|
2019-09-03 09:03:38 +02:00
|
|
|
connect(m_openPagesWidget,
|
|
|
|
|
&OpenPagesWidget::setCurrentPage,
|
|
|
|
|
m_helpWidget,
|
|
|
|
|
[this](const QModelIndex &index) { m_helpWidget->setCurrentIndex(index.row()); });
|
|
|
|
|
connect(m_helpWidget,
|
|
|
|
|
&HelpWidget::currentIndexChanged,
|
|
|
|
|
m_openPagesWidget,
|
|
|
|
|
&OpenPagesWidget::selectCurrentPage);
|
2016-06-28 23:07:19 +03:00
|
|
|
connect(m_openPagesWidget, &OpenPagesWidget::closePage,
|
|
|
|
|
this, &OpenPagesManager::closePage);
|
|
|
|
|
connect(m_openPagesWidget, &OpenPagesWidget::closePagesExcept,
|
|
|
|
|
this, &OpenPagesManager::closePagesExcept);
|
2010-09-15 11:02:45 +02:00
|
|
|
}
|
2010-03-29 14:57:02 +02:00
|
|
|
return m_openPagesWidget;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-12 14:39:23 +02:00
|
|
|
QComboBox *OpenPagesManager::openPagesComboBox() const
|
2010-03-29 14:57:02 +02:00
|
|
|
{
|
|
|
|
|
return m_comboBox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList splitString(const QVariant &value)
|
|
|
|
|
{
|
|
|
|
|
using namespace Help::Constants;
|
2020-06-17 06:35:31 +02:00
|
|
|
return value.toString().split(ListSeparator, Utils::SkipEmptyParts);
|
2010-03-29 14:57:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenPagesManager::setupInitialPages()
|
|
|
|
|
{
|
2010-06-11 13:11:37 +02:00
|
|
|
const QHelpEngineCore &engine = LocalHelpManager::helpEngine();
|
2015-04-02 16:49:04 +02:00
|
|
|
const LocalHelpManager::StartOption option = LocalHelpManager::startOption();
|
2014-10-22 14:47:04 +02:00
|
|
|
QString homePage = LocalHelpManager::homePage();
|
2010-03-29 14:57:02 +02:00
|
|
|
|
|
|
|
|
int initialPage = 0;
|
|
|
|
|
switch (option) {
|
2019-09-02 15:52:01 +02:00
|
|
|
case LocalHelpManager::ShowHomePage:
|
|
|
|
|
m_helpWidget->addViewer(homePage);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LocalHelpManager::ShowBlankPage:
|
|
|
|
|
m_helpWidget->addViewer(QUrl(Help::Constants::AboutBlank));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LocalHelpManager::ShowLastPages: {
|
|
|
|
|
const QStringList &lastShownPageList = LocalHelpManager::lastShownPages();
|
|
|
|
|
const int pageCount = lastShownPageList.count();
|
|
|
|
|
|
|
|
|
|
if (pageCount > 0) {
|
|
|
|
|
QList<float> zoomFactors = LocalHelpManager::lastShownPagesZoom();
|
|
|
|
|
while (zoomFactors.count() < pageCount)
|
|
|
|
|
zoomFactors.append(0.);
|
|
|
|
|
|
|
|
|
|
initialPage = LocalHelpManager::lastSelectedTab();
|
|
|
|
|
for (int curPage = 0; curPage < pageCount; ++curPage) {
|
|
|
|
|
const QString &curFile = lastShownPageList.at(curPage);
|
|
|
|
|
if (engine.findFile(curFile).isValid() || curFile == Help::Constants::AboutBlank) {
|
|
|
|
|
m_helpWidget->addViewer(curFile, zoomFactors.at(curPage));
|
|
|
|
|
} else if (curPage <= initialPage && initialPage > 0) {
|
|
|
|
|
--initialPage;
|
2010-03-29 14:57:02 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-09-02 15:52:01 +02:00
|
|
|
}
|
|
|
|
|
} break;
|
2010-03-29 14:57:02 +02:00
|
|
|
|
2019-09-02 15:52:01 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
2010-03-29 14:57:02 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-02 15:52:01 +02:00
|
|
|
if (m_helpWidget->viewerCount() == 0)
|
|
|
|
|
m_helpWidget->addViewer(homePage);
|
2010-03-29 17:27:04 +02:00
|
|
|
|
2019-09-03 09:03:38 +02:00
|
|
|
m_helpWidget->setCurrentIndex(std::max(initialPage, m_helpWidget->viewerCount() - 1));
|
2010-03-29 14:57:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenPagesManager::closeCurrentPage()
|
|
|
|
|
{
|
2010-09-15 11:02:45 +02:00
|
|
|
if (!m_openPagesWidget)
|
|
|
|
|
return;
|
2010-09-21 17:00:41 +02:00
|
|
|
|
2010-03-29 14:57:02 +02:00
|
|
|
QModelIndexList indexes = m_openPagesWidget->selectionModel()->selectedRows();
|
|
|
|
|
if (indexes.isEmpty())
|
|
|
|
|
return;
|
2010-09-21 17:00:41 +02:00
|
|
|
|
2015-04-02 16:49:04 +02:00
|
|
|
const bool returnOnClose = LocalHelpManager::returnOnClose();
|
2010-09-21 17:00:41 +02:00
|
|
|
|
2019-09-02 15:52:01 +02:00
|
|
|
if (m_helpWidget->viewerCount() == 1 && returnOnClose) {
|
2013-08-29 19:00:34 +02:00
|
|
|
ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
2010-09-21 17:00:41 +02:00
|
|
|
} else {
|
2019-09-02 15:52:01 +02:00
|
|
|
QTC_ASSERT(indexes.count() == 1, return );
|
2010-09-21 17:00:41 +02:00
|
|
|
removePage(indexes.first().row());
|
|
|
|
|
}
|
2010-03-29 14:57:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenPagesManager::closePage(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
if (index.isValid())
|
|
|
|
|
removePage(index.row());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenPagesManager::closePagesExcept(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
if (index.isValid()) {
|
|
|
|
|
int i = 0;
|
2019-09-02 15:52:01 +02:00
|
|
|
HelpViewer *viewer = m_helpWidget->viewerAt(index.row());
|
|
|
|
|
while (m_helpWidget->viewerCount() > 1) {
|
|
|
|
|
if (m_helpWidget->viewerAt(i) != viewer)
|
2010-03-29 14:57:02 +02:00
|
|
|
removePage(i);
|
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
|
|
|
else
|
2010-03-29 14:57:02 +02:00
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-12 14:55:41 +02:00
|
|
|
void OpenPagesManager::gotoNextPage()
|
|
|
|
|
{
|
2010-04-12 16:43:23 +02:00
|
|
|
if (!m_openPagesSwitcher->isVisible()) {
|
|
|
|
|
m_openPagesSwitcher->gotoNextPage();
|
2010-04-12 14:55:41 +02:00
|
|
|
showTwicherOrSelectPage();
|
|
|
|
|
} else {
|
2010-04-12 16:43:23 +02:00
|
|
|
m_openPagesSwitcher->gotoNextPage();
|
2010-04-12 14:55:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-03-29 14:57:02 +02:00
|
|
|
|
2010-04-12 14:55:41 +02:00
|
|
|
void OpenPagesManager::gotoPreviousPage()
|
2010-03-29 14:57:02 +02:00
|
|
|
{
|
2010-04-12 16:43:23 +02:00
|
|
|
if (!m_openPagesSwitcher->isVisible()) {
|
|
|
|
|
m_openPagesSwitcher->gotoPreviousPage();
|
2010-04-12 14:55:41 +02:00
|
|
|
showTwicherOrSelectPage();
|
|
|
|
|
} else {
|
2010-04-12 16:43:23 +02:00
|
|
|
m_openPagesSwitcher->gotoPreviousPage();
|
2010-04-12 14:55:41 +02:00
|
|
|
}
|
2010-03-29 14:57:02 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-12 14:55:41 +02:00
|
|
|
// -- private
|
|
|
|
|
|
2010-03-29 14:57:02 +02:00
|
|
|
void OpenPagesManager::removePage(int index)
|
|
|
|
|
{
|
2019-09-02 15:52:01 +02:00
|
|
|
QTC_ASSERT(index < m_helpWidget->viewerCount(), return );
|
2010-03-29 14:57:02 +02:00
|
|
|
|
2019-09-02 15:52:01 +02:00
|
|
|
m_helpWidget->removeViewerAt(index);
|
2010-04-12 14:55:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenPagesManager::showTwicherOrSelectPage() const
|
|
|
|
|
{
|
|
|
|
|
if (QApplication::keyboardModifiers() != Qt::NoModifier) {
|
2019-09-02 15:52:01 +02:00
|
|
|
const int width = m_helpWidget->width();
|
|
|
|
|
const int height = m_helpWidget->height();
|
|
|
|
|
const QPoint p(m_helpWidget->mapToGlobal(QPoint(0, 0)));
|
2010-04-12 16:43:23 +02:00
|
|
|
m_openPagesSwitcher->move((width - m_openPagesSwitcher->width()) / 2 + p.x(),
|
|
|
|
|
(height - m_openPagesSwitcher->height()) / 2 + p.y());
|
|
|
|
|
m_openPagesSwitcher->setVisible(true);
|
2010-04-12 14:55:41 +02:00
|
|
|
} else {
|
2010-04-12 16:43:23 +02:00
|
|
|
m_openPagesSwitcher->selectAndHide();
|
2010-04-12 14:55:41 +02:00
|
|
|
}
|
2010-03-29 14:57:02 +02:00
|
|
|
}
|
2010-08-16 15:25:27 +02:00
|
|
|
|
|
|
|
|
void OpenPagesManager::openPagesContextMenu(const QPoint &point)
|
|
|
|
|
{
|
2019-09-02 15:52:01 +02:00
|
|
|
const QModelIndex &index = m_helpWidget->model()->index(m_comboBox->currentIndex(), 0);
|
|
|
|
|
const QString &fileName = m_helpWidget->model()->data(index, Qt::ToolTipRole).toString();
|
2010-08-16 15:25:27 +02:00
|
|
|
if (fileName.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QMenu menu;
|
|
|
|
|
menu.addAction(tr("Copy Full Path to Clipboard"));
|
|
|
|
|
if (menu.exec(m_comboBox->mapToGlobal(point)))
|
|
|
|
|
QApplication::clipboard()->setText(fileName);
|
|
|
|
|
}
|