forked from qt-creator/qt-creator
Help: Implement history menus for text browser backend
Change-Id: Idbdb3f9807c8282f8c9050ba28c1e28a7e3865e7 Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
#include <coreplugin/find/findplugin.h>
|
#include <coreplugin/find/findplugin.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
@@ -193,6 +194,28 @@ bool TextBrowserHelpViewer::isBackwardAvailable() const
|
|||||||
return m_textBrowser->isBackwardAvailable();
|
return m_textBrowser->isBackwardAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextBrowserHelpViewer::addBackHistoryItems(QMenu *backMenu)
|
||||||
|
{
|
||||||
|
for (int i = 1; i <= m_textBrowser->backwardHistoryCount(); ++i) {
|
||||||
|
QAction *action = new QAction(backMenu);
|
||||||
|
action->setText(m_textBrowser->historyTitle(-i));
|
||||||
|
action->setData(-i);
|
||||||
|
connect(action, SIGNAL(triggered()), this, SLOT(goToHistoryItem()));
|
||||||
|
backMenu->addAction(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextBrowserHelpViewer::addForwardHistoryItems(QMenu *forwardMenu)
|
||||||
|
{
|
||||||
|
for (int i = 1; i <= m_textBrowser->forwardHistoryCount(); ++i) {
|
||||||
|
QAction *action = new QAction(forwardMenu);
|
||||||
|
action->setText(m_textBrowser->historyTitle(i));
|
||||||
|
action->setData(i);
|
||||||
|
connect(action, SIGNAL(triggered()), this, SLOT(goToHistoryItem()));
|
||||||
|
forwardMenu->addAction(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TextBrowserHelpViewer::setOpenInNewWindowActionVisible(bool visible)
|
void TextBrowserHelpViewer::setOpenInNewWindowActionVisible(bool visible)
|
||||||
{
|
{
|
||||||
m_textBrowser->showOpenInNewWindowAction = visible;
|
m_textBrowser->showOpenInNewWindowAction = visible;
|
||||||
@@ -277,6 +300,25 @@ void TextBrowserHelpViewer::print(QPrinter *printer)
|
|||||||
m_textBrowser->print(printer);
|
m_textBrowser->print(printer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextBrowserHelpViewer::goToHistoryItem()
|
||||||
|
{
|
||||||
|
QAction *action = qobject_cast<QAction *>(sender());
|
||||||
|
QTC_ASSERT(action, return);
|
||||||
|
bool ok = false;
|
||||||
|
int index = action->data().toInt(&ok);
|
||||||
|
QTC_ASSERT(ok, return);
|
||||||
|
// go back?
|
||||||
|
while (index < 0) {
|
||||||
|
m_textBrowser->backward();
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
// go forward?
|
||||||
|
while (index > 0) {
|
||||||
|
m_textBrowser->forward();
|
||||||
|
--index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// -- private
|
// -- private
|
||||||
|
|
||||||
TextBrowserHelpWidget::TextBrowserHelpWidget(int zoom, TextBrowserHelpViewer *parent)
|
TextBrowserHelpWidget::TextBrowserHelpWidget(int zoom, TextBrowserHelpViewer *parent)
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ public:
|
|||||||
QString selectedText() const;
|
QString selectedText() const;
|
||||||
bool isForwardAvailable() const;
|
bool isForwardAvailable() const;
|
||||||
bool isBackwardAvailable() const;
|
bool isBackwardAvailable() const;
|
||||||
void addBackHistoryItems(QMenu *backMenu) { Q_UNUSED(backMenu) }
|
void addBackHistoryItems(QMenu *backMenu);
|
||||||
void addForwardHistoryItems(QMenu *forwardMenu) { Q_UNUSED(forwardMenu) }
|
void addForwardHistoryItems(QMenu *forwardMenu);
|
||||||
void setOpenInNewWindowActionVisible(bool visible);
|
void setOpenInNewWindowActionVisible(bool visible);
|
||||||
|
|
||||||
bool findText(const QString &text, Core::FindFlags flags,
|
bool findText(const QString &text, Core::FindFlags flags,
|
||||||
@@ -84,6 +84,9 @@ public slots:
|
|||||||
void backward();
|
void backward();
|
||||||
void print(QPrinter *printer);
|
void print(QPrinter *printer);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void goToHistoryItem();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVariant loadResource(int type, const QUrl &name);
|
QVariant loadResource(int type, const QUrl &name);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user