2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-03-29 14:57:02 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2010-03-29 14:57:02 +02: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.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-03-29 14:57:02 +02:00
|
|
|
|
|
|
|
|
#include "openpagesmanager.h"
|
|
|
|
|
|
|
|
|
|
#include "centralwidget.h"
|
|
|
|
|
#include "helpconstants.h"
|
|
|
|
|
#include "helpviewer.h"
|
2010-11-16 14:15:23 +01:00
|
|
|
#include "localhelpmanager.h"
|
2010-03-29 14:57:02 +02:00
|
|
|
#include "openpagesmodel.h"
|
2010-04-12 16:43:23 +02:00
|
|
|
#include "openpagesswitcher.h"
|
2010-03-29 14:57:02 +02:00
|
|
|
#include "openpageswidget.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
|
|
|
|
2010-09-21 17:00:41 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/helpmanager.h>
|
|
|
|
|
#include <coreplugin/modemanager.h>
|
|
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
using namespace Core;
|
2010-03-29 14:57:02 +02:00
|
|
|
using namespace Help::Internal;
|
|
|
|
|
|
|
|
|
|
OpenPagesManager *OpenPagesManager::m_instance = 0;
|
|
|
|
|
|
|
|
|
|
// -- OpenPagesManager
|
|
|
|
|
|
|
|
|
|
OpenPagesManager::OpenPagesManager(QObject *parent)
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
, m_comboBox(0)
|
|
|
|
|
, m_model(0)
|
|
|
|
|
, m_openPagesWidget(0)
|
2010-04-12 16:43:23 +02:00
|
|
|
, m_openPagesSwitcher(0)
|
2010-03-29 14:57:02 +02:00
|
|
|
{
|
|
|
|
|
Q_ASSERT(!m_instance);
|
|
|
|
|
|
|
|
|
|
m_instance = this;
|
|
|
|
|
m_model = new OpenPagesModel(this);
|
|
|
|
|
|
|
|
|
|
m_comboBox = new QComboBox;
|
|
|
|
|
m_comboBox->setModel(m_model);
|
2010-08-16 15:25:27 +02:00
|
|
|
m_comboBox->setContextMenuPolicy(Qt::CustomContextMenu);
|
2010-03-31 13:15:04 +02:00
|
|
|
connect(m_comboBox, SIGNAL(activated(int)), this, SLOT(setCurrentPage(int)));
|
2010-08-16 15:25:27 +02:00
|
|
|
connect(m_comboBox, SIGNAL(customContextMenuRequested(QPoint)), this,
|
|
|
|
|
SLOT(openPagesContextMenu(QPoint)));
|
2010-04-12 14:55:41 +02:00
|
|
|
|
2010-04-12 16:43:23 +02:00
|
|
|
m_openPagesSwitcher = new OpenPagesSwitcher(m_model);
|
|
|
|
|
connect(m_openPagesSwitcher, SIGNAL(closePage(QModelIndex)), this,
|
2010-04-12 14:55:41 +02:00
|
|
|
SLOT(closePage(QModelIndex)));
|
2010-04-12 16:43:23 +02:00
|
|
|
connect(m_openPagesSwitcher, SIGNAL(setCurrentPage(QModelIndex)), this,
|
2010-04-12 14:55:41 +02:00
|
|
|
SLOT(setCurrentPage(QModelIndex)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenPagesManager ::~OpenPagesManager()
|
|
|
|
|
{
|
|
|
|
|
m_instance = 0;
|
2010-04-12 16:43:23 +02:00
|
|
|
delete m_openPagesSwitcher;
|
2010-03-29 14:57:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenPagesManager &OpenPagesManager::instance()
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(m_instance);
|
|
|
|
|
return *m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
|
|
|
|
m_openPagesWidget = new OpenPagesWidget(m_model);
|
|
|
|
|
connect(m_openPagesWidget, SIGNAL(setCurrentPage(QModelIndex)), this,
|
|
|
|
|
SLOT(setCurrentPage(QModelIndex)));
|
|
|
|
|
connect(m_openPagesWidget, SIGNAL(closePage(QModelIndex)), this,
|
|
|
|
|
SLOT(closePage(QModelIndex)));
|
|
|
|
|
connect(m_openPagesWidget, SIGNAL(closePagesExcept(QModelIndex)), this,
|
|
|
|
|
SLOT(closePagesExcept(QModelIndex)));
|
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int OpenPagesManager::pageCount() const
|
|
|
|
|
{
|
|
|
|
|
return m_model->rowCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList splitString(const QVariant &value)
|
|
|
|
|
{
|
|
|
|
|
using namespace Help::Constants;
|
|
|
|
|
return value.toString().split(ListSeparator, QString::SkipEmptyParts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenPagesManager::setupInitialPages()
|
|
|
|
|
{
|
2010-06-11 13:11:37 +02:00
|
|
|
const QHelpEngineCore &engine = LocalHelpManager::helpEngine();
|
2010-03-29 14:57:02 +02:00
|
|
|
const int option = engine.customValue(QLatin1String("StartOption"),
|
|
|
|
|
Help::Constants::ShowLastPages).toInt();
|
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) {
|
|
|
|
|
case Help::Constants::ShowHomePage: {
|
2014-10-22 14:47:04 +02:00
|
|
|
m_model->addPage(homePage);
|
2010-03-29 14:57:02 +02:00
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
case Help::Constants::ShowBlankPage: {
|
|
|
|
|
m_model->addPage(QUrl(Help::Constants::AboutBlank));
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
case Help::Constants::ShowLastPages: {
|
|
|
|
|
const QStringList &lastShownPageList = splitString(engine
|
|
|
|
|
.customValue(QLatin1String("LastShownPages")));
|
|
|
|
|
const int pageCount = lastShownPageList.count();
|
|
|
|
|
|
|
|
|
|
if (pageCount > 0) {
|
|
|
|
|
QStringList zoomFactors = splitString(engine
|
|
|
|
|
.customValue(QLatin1String("LastShownPagesZoom")));
|
|
|
|
|
while (zoomFactors.count() < pageCount)
|
|
|
|
|
zoomFactors.append(Help::Constants::DefaultZoomFactor);
|
|
|
|
|
|
|
|
|
|
initialPage = engine.customValue(QLatin1String("LastTabPage"), 0).toInt();
|
|
|
|
|
for (int curPage = 0; curPage < pageCount; ++curPage) {
|
|
|
|
|
const QString &curFile = lastShownPageList.at(curPage);
|
|
|
|
|
if (engine.findFile(curFile).isValid()
|
|
|
|
|
|| curFile == Help::Constants::AboutBlank) {
|
|
|
|
|
m_model->addPage(curFile, zoomFactors.at(curPage).toFloat());
|
|
|
|
|
} else if (curPage <= initialPage && initialPage > 0) {
|
|
|
|
|
--initialPage;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_model->rowCount() == 0)
|
|
|
|
|
m_model->addPage(homePage);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_model->rowCount(); ++i)
|
2014-09-25 16:29:56 +02:00
|
|
|
CentralWidget::instance()->addViewer(m_model->pageAt(i));
|
2010-03-29 17:27:04 +02:00
|
|
|
|
|
|
|
|
emit pagesChanged();
|
2010-10-12 16:53:00 +02:00
|
|
|
setCurrentPage((initialPage >= m_model->rowCount())
|
|
|
|
|
? m_model->rowCount() - 1 : initialPage);
|
2010-04-12 16:43:23 +02:00
|
|
|
m_openPagesSwitcher->selectCurrentPage();
|
2010-03-29 14:57:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -- public slots
|
|
|
|
|
|
|
|
|
|
HelpViewer *OpenPagesManager::createPage()
|
|
|
|
|
{
|
|
|
|
|
return createPage(QUrl(Help::Constants::AboutBlank));
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 14:20:03 +01:00
|
|
|
HelpViewer *OpenPagesManager::createPage(const QUrl &url)
|
2010-03-29 14:57:02 +02:00
|
|
|
{
|
2014-05-14 13:15:01 +02:00
|
|
|
if (url.isValid() && HelpViewer::launchWithExternalApp(url))
|
2010-03-29 14:57:02 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
m_model->addPage(url);
|
|
|
|
|
|
|
|
|
|
const int index = m_model->rowCount() - 1;
|
|
|
|
|
HelpViewer * const page = m_model->pageAt(index);
|
2014-10-31 14:20:03 +01:00
|
|
|
CentralWidget::instance()->addViewer(page);
|
2010-03-29 14:57:02 +02:00
|
|
|
|
|
|
|
|
emit pagesChanged();
|
|
|
|
|
setCurrentPage(index);
|
|
|
|
|
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenPagesManager::setCurrentPage(int index)
|
|
|
|
|
{
|
2014-09-25 16:29:56 +02:00
|
|
|
CentralWidget::instance()->setCurrentViewer(m_model->pageAt(index));
|
2010-03-29 14:57:02 +02:00
|
|
|
|
2010-04-12 14:55:41 +02:00
|
|
|
m_comboBox->setCurrentIndex(index);
|
2010-09-15 11:02:45 +02:00
|
|
|
if (m_openPagesWidget)
|
|
|
|
|
m_openPagesWidget->selectCurrentPage();
|
2010-03-29 14:57:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenPagesManager::setCurrentPage(const QModelIndex &index)
|
|
|
|
|
{
|
2010-04-12 14:55:41 +02:00
|
|
|
if (index.isValid())
|
|
|
|
|
setCurrentPage(index.row());
|
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
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
const bool closeOnReturn = HelpManager::customValue(QLatin1String("ReturnOnClose"),
|
2010-09-21 17:00:41 +02:00
|
|
|
false).toBool();
|
|
|
|
|
|
|
|
|
|
if (m_model->rowCount() == 1 && closeOnReturn) {
|
2013-08-29 19:00:34 +02:00
|
|
|
ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
2010-09-21 17:00:41 +02:00
|
|
|
} else {
|
|
|
|
|
Q_ASSERT(indexes.count() == 1);
|
|
|
|
|
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;
|
|
|
|
|
HelpViewer *viewer = m_model->pageAt(index.row());
|
|
|
|
|
while (m_model->rowCount() > 1) {
|
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 (m_model->pageAt(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->selectCurrentPage();
|
|
|
|
|
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->selectCurrentPage();
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(m_model->rowCount() > 1);
|
|
|
|
|
|
|
|
|
|
m_model->removePage(index);
|
2014-09-25 16:29:56 +02:00
|
|
|
CentralWidget::instance()->removeViewerAt(index);
|
2010-03-29 14:57:02 +02:00
|
|
|
|
|
|
|
|
emit pagesChanged();
|
2010-09-15 11:02:45 +02:00
|
|
|
if (m_openPagesWidget)
|
|
|
|
|
m_openPagesWidget->selectCurrentPage();
|
2010-04-12 14:55:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenPagesManager::showTwicherOrSelectPage() const
|
|
|
|
|
{
|
|
|
|
|
if (QApplication::keyboardModifiers() != Qt::NoModifier) {
|
|
|
|
|
const int width = CentralWidget::instance()->width();
|
|
|
|
|
const int height = CentralWidget::instance()->height();
|
|
|
|
|
const QPoint p(CentralWidget::instance()->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
|
|
|
|
|
|
|
|
// -- private slots
|
|
|
|
|
|
|
|
|
|
void OpenPagesManager::openPagesContextMenu(const QPoint &point)
|
|
|
|
|
{
|
|
|
|
|
const QModelIndex &index = m_model->index(m_comboBox->currentIndex(), 0);
|
|
|
|
|
const QString &fileName = m_model->data(index, Qt::ToolTipRole).toString();
|
|
|
|
|
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);
|
|
|
|
|
}
|