129
138
QList<int> modecontext;
130
139
modecontext << m_core->uniqueIDManager()->uniqueIdentifier(Constants::C_MODE_HELP);
141
QString locale = qApp->property("qtc_locale").toString();
142
if (!locale.isEmpty()) {
143
QTranslator *qtr = new QTranslator(this);
144
QTranslator *qhelptr = new QTranslator(this);
145
const QString &creatorTrPath =
146
Core::ICore::instance()->resourcePath() + QLatin1String("/translations");
147
const QString &qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
148
const QString &trFile = QLatin1String("assistant_") + locale;
149
const QString &helpTrFile = QLatin1String("qt_help_") + locale;
150
if (qtr->load(trFile, qtTrPath) || qtr->load(trFile, creatorTrPath))
151
qApp->installTranslator(qtr);
152
if (qhelptr->load(helpTrFile, qtTrPath) || qhelptr->load(helpTrFile, creatorTrPath))
153
qApp->installTranslator(qhelptr);
157
QWebSettings *webSettings = QWebSettings::globalSettings();
158
const QFont applicationFont = QApplication::font();
159
webSettings->setFontFamily(QWebSettings::StandardFont, applicationFont.family());
160
//webSettings->setFontSize(QWebSettings::DefaultFontSize, applicationFont.pointSize());
132
163
// FIXME shouldn't the help engine create the directory if it doesn't exist?
133
164
QFileInfo fi(m_core->settings()->fileName());
134
165
QDir directory(fi.absolutePath()+"/qtcreator");
135
166
if (!directory.exists())
136
167
directory.mkpath(directory.absolutePath());
137
m_helpEngine = new QHelpEngine(directory.absolutePath()
138
+ QLatin1String("/helpcollection.qhc"), this);
139
connect(m_helpEngine, SIGNAL(setupFinished()),
140
this, SLOT(updateFilterComboBox()));
168
m_helpEngine = new QHelpEngine(directory.absolutePath() +
169
QLatin1String("/helpcollection.qhc"), this);
170
connect(m_helpEngine, SIGNAL(setupFinished()), this,
171
SLOT(updateFilterComboBox()));
142
173
addAutoReleasedObject(new HelpManager(m_helpEngine));
160
191
m_bookmarkManager = new BookmarkManager(m_helpEngine);
161
192
m_bookmarkWidget = new BookmarkWidget(m_bookmarkManager, 0, false);
162
193
m_bookmarkWidget->setWindowTitle(tr("Bookmarks"));
163
connect(m_bookmarkWidget, SIGNAL(addBookmark()),
164
this, SLOT(addBookmark()));
194
connect(m_bookmarkWidget, SIGNAL(addBookmark()), this, SLOT(addBookmark()));
166
196
Core::ActionManager *am = m_core->actionManager();
167
197
Core::Command *cmd;
169
199
// Add Home, Previous and Next actions (used in the toolbar)
170
QAction *homeAction = new QAction(QIcon(QLatin1String(":/help/images/home.png")), tr("Home"), this);
200
QAction *homeAction =
201
new QAction(QIcon(QLatin1String(":/help/images/home.png")), tr("Home"),
171
203
cmd = am->registerAction(homeAction, QLatin1String("Help.Home"), globalcontext);
173
QAction *previousAction = new QAction(QIcon(QLatin1String(":/help/images/previous.png")),
205
QAction *previousAction =
206
new QAction(QIcon(QLatin1String(":/help/images/previous.png")),
174
207
tr("Previous"), this);
175
cmd = am->registerAction(previousAction, QLatin1String("Help.Previous"), modecontext);
176
cmd->setDefaultKeySequence(QKeySequence(Qt::Key_Backspace));
208
cmd = am->registerAction(previousAction, QLatin1String("Help.Previous"),
210
cmd->setDefaultKeySequence(QKeySequence::Back);
178
QAction *nextAction = new QAction(QIcon(QLatin1String(":/help/images/next.png")), tr("Next"), this);
212
QAction *nextAction =
213
new QAction(QIcon(QLatin1String(":/help/images/next.png")), tr("Next"),
179
215
cmd = am->registerAction(nextAction, QLatin1String("Help.Next"), modecontext);
216
cmd->setDefaultKeySequence(QKeySequence::Forward);
181
QAction *addBookmarkAction = new QAction(QIcon(QLatin1String(":/help/images/bookmark.png")),
218
QAction *addBookmarkAction =
219
new QAction(QIcon(QLatin1String(":/help/images/bookmark.png")),
182
220
tr("Add Bookmark"), this);
183
cmd = am->registerAction(addBookmarkAction, QLatin1String("Help.AddBookmark"), modecontext);
221
cmd = am->registerAction(addBookmarkAction, QLatin1String("Help.AddBookmark"),
184
223
cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::Key_M));
186
225
// Add Index, Contents, and Context menu items and a separator to the Help menu
187
226
QAction *indexAction = new QAction(tr("Index"), this);
188
cmd = am->registerAction(indexAction, QLatin1String("Help.Index"), globalcontext);
189
am->actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP);
227
cmd = am->registerAction(indexAction, QLatin1String("Help.Index"),
229
am->actionContainer(Core::Constants::M_HELP)->addAction(cmd,
230
Core::Constants::G_HELP_HELP);
191
232
QAction *contentsAction = new QAction(tr("Contents"), this);
192
cmd = am->registerAction(contentsAction, QLatin1String("Help.Contents"), globalcontext);
193
am->actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP);
233
cmd = am->registerAction(contentsAction, QLatin1String("Help.Contents"),
235
am->actionContainer(Core::Constants::M_HELP)->addAction(cmd,
236
Core::Constants::G_HELP_HELP);
195
238
QAction *searchAction = new QAction(tr("Search"), this);
196
cmd = am->registerAction(searchAction, QLatin1String("Help.Search"), globalcontext);
197
am->actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP);
239
cmd = am->registerAction(searchAction, QLatin1String("Help.Search"),
241
am->actionContainer(Core::Constants::M_HELP)->addAction(cmd,
242
Core::Constants::G_HELP_HELP);
199
244
QAction *contextAction = new QAction(tr("Context Help"), this);
200
cmd = am->registerAction(contextAction, QLatin1String("Help.Context"), globalcontext);
245
cmd = am->registerAction(contextAction, QLatin1String("Help.Context"),
201
247
cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F1));
202
am->actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP);
248
am->actionContainer(Core::Constants::M_HELP)->addAction(cmd,
249
Core::Constants::G_HELP_HELP);
205
252
QAction *sep = new QAction(this);
206
253
sep->setSeparator(true);
207
254
cmd = am->registerAction(sep, QLatin1String("Help.Separator"), globalcontext);
208
am->actionContainer(Core::Constants::M_HELP)->addAction(cmd, Core::Constants::G_HELP_HELP);
255
am->actionContainer(Core::Constants::M_HELP)->addAction(cmd,
256
Core::Constants::G_HELP_HELP);
211
m_centralWidget = new CentralWidget(m_helpEngine);
259
m_centralWidget = new Help::Internal::CentralWidget(m_helpEngine);
212
260
Aggregation::Aggregate *agg = new Aggregation::Aggregate;
213
261
agg->add(m_centralWidget);
214
262
agg->add(new HelpFindSupport(m_centralWidget));
252
300
QMap<QString, Core::Command*> shortcutMap;
253
301
QShortcut *shortcut = new QShortcut(splitter);
254
302
shortcut->setWhatsThis(tr("Activate Index in Help mode"));
255
cmd = am->registerShortcut(shortcut, QLatin1String("Help.IndexShortcut"), modecontext);
303
cmd = am->registerShortcut(shortcut, QLatin1String("Help.IndexShortcut"),
256
305
cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::Key_I));
257
306
connect(shortcut, SIGNAL(activated()), this, SLOT(activateIndex()));
258
307
shortcutMap.insert(m_indexWidget->windowTitle(), cmd);
260
309
shortcut = new QShortcut(splitter);
261
310
shortcut->setWhatsThis(tr("Activate Contents in Help mode"));
262
cmd = am->registerShortcut(shortcut, QLatin1String("Help.ContentsShortcut"), modecontext);
311
cmd = am->registerShortcut(shortcut, QLatin1String("Help.ContentsShortcut"),
263
313
cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::Key_T));
264
314
connect(shortcut, SIGNAL(activated()), this, SLOT(activateContents()));
265
315
shortcutMap.insert(m_contentWidget->windowTitle(), cmd);
267
317
shortcut = new QShortcut(splitter);
268
318
shortcut->setWhatsThis(tr("Activate Search in Help mode"));
269
cmd = am->registerShortcut(shortcut, QLatin1String("Help.SearchShortcut"), modecontext);
319
cmd = am->registerShortcut(shortcut, QLatin1String("Help.SearchShortcut"),
270
321
cmd->setDefaultKeySequence(QKeySequence(Qt::CTRL + Qt::Key_S));
271
322
connect(shortcut, SIGNAL(activated()), this, SLOT(activateSearch()));
272
323
shortcutMap.insert(m_searchWidget->windowTitle(), cmd);
278
329
connect(previousAction, SIGNAL(triggered()), m_centralWidget, SLOT(backward()));
279
330
connect(nextAction, SIGNAL(triggered()), m_centralWidget, SLOT(forward()));
280
331
connect(addBookmarkAction, SIGNAL(triggered()), this, SLOT(addBookmark()));
281
connect(m_contentWidget, SIGNAL(linkActivated(const QUrl&)),
282
m_centralWidget, SLOT(setSource(const QUrl&)));
283
connect(m_indexWidget, SIGNAL(linkActivated(const QUrl&)),
284
m_centralWidget, SLOT(setSource(const QUrl&)));
285
connect(m_searchWidget, SIGNAL(requestShowLink(const QUrl&)),
286
m_centralWidget, SLOT(setSource(const QUrl&)));
287
connect(m_searchWidget, SIGNAL(requestShowLinkInNewTab(const QUrl&)),
288
m_centralWidget, SLOT(setSourceInNewTab(const QUrl&)));
289
connect(m_bookmarkWidget, SIGNAL(requestShowLink(const QUrl&)),
290
m_centralWidget, SLOT(setSource(const QUrl&)));
332
connect(m_contentWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget,
333
SLOT(setSource(QUrl)));
334
connect(m_indexWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget,
335
SLOT(setSource(QUrl)));
336
connect(m_searchWidget, SIGNAL(requestShowLink(QUrl)), m_centralWidget,
337
SLOT(setSource(QUrl)));
338
connect(m_searchWidget, SIGNAL(requestShowLinkInNewTab(QUrl)),
339
m_centralWidget, SLOT(setSourceInNewTab(QUrl)));
340
connect(m_bookmarkWidget, SIGNAL(requestShowLink(QUrl)), m_centralWidget,
341
SLOT(setSource(const QUrl&)));
292
343
connect(m_centralWidget, SIGNAL(backwardAvailable(bool)),
293
344
previousAction, SLOT(setEnabled(bool)));
294
345
connect(m_centralWidget, SIGNAL(forwardAvailable(bool)),
295
346
nextAction, SLOT(setEnabled(bool)));
296
connect(m_centralWidget, SIGNAL(addNewBookmark(const QString&, const QString&)),
297
this, SLOT(addNewBookmark(const QString&, const QString&)));
347
connect(m_centralWidget, SIGNAL(addNewBookmark(QString, QString)), this,
348
SLOT(addNewBookmark(QString, QString)));
299
350
QList<QAction*> actionList;
300
351
actionList << previousAction
314
365
connect(m_core->modeManager(), SIGNAL(currentModeChanged(Core::IMode*)),
315
366
this, SLOT(modeChanged(Core::IMode*)));
317
connect(m_contentWidget, SIGNAL(linkActivated(const QUrl&)),
318
m_centralWidget, SLOT(setSource(const QUrl&)));
319
connect(m_indexWidget, SIGNAL(linkActivated(const QUrl&)),
320
m_centralWidget, SLOT(setSource(const QUrl&)));
321
connect(m_indexWidget, SIGNAL(linksActivated(const QMap<QString, QUrl>&, const QString&)),
322
m_centralWidget, SLOT(showTopicChooser(const QMap<QString, QUrl>&, const QString&)));
368
connect(m_contentWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget,
369
SLOT(setSource(QUrl)));
370
connect(m_indexWidget, SIGNAL(linkActivated(QUrl)), m_centralWidget,
371
SLOT(setSource(QUrl)));
372
connect(m_indexWidget, SIGNAL(linksActivated(QMap<QString, QUrl>, QString)),
373
m_centralWidget, SLOT(showTopicChooser(QMap<QString, QUrl>, QString)));
324
375
HelpIndexFilter *helpIndexFilter = new HelpIndexFilter(this, m_helpEngine);
325
376
addAutoReleasedObject(helpIndexFilter);
326
connect(helpIndexFilter, SIGNAL(linkActivated(QUrl)),
327
this, SLOT(switchToHelpMode(QUrl)));
328
connect(helpIndexFilter, SIGNAL(linksActivated(const QMap<QString, QUrl>&, const QString&)),
329
this, SLOT(switchToHelpMode(const QMap<QString, QUrl>&, const QString&)));
377
connect(helpIndexFilter, SIGNAL(linkActivated(QUrl)), this,
378
SLOT(switchToHelpMode(QUrl)));
379
connect(helpIndexFilter, SIGNAL(linksActivated(QMap<QString, QUrl>, QString)),
380
this, SLOT(switchToHelpMode(QMap<QString, QUrl>, QString)));
331
382
previousAction->setEnabled(m_centralWidget->isBackwardAvailable());
332
383
nextAction->setEnabled(m_centralWidget->isForwardAvailable());
334
385
createRightPaneSideBar();
387
QDesktopServices::setUrlHandler("qthelp", this, "openHelpPage");
339
392
void HelpPlugin::createRightPaneSideBar()
341
394
QAction *switchToHelpMode = new QAction("Go to Help Mode", this);
342
m_rightPaneBackwardAction = new QAction(QIcon(QLatin1String(":/help/images/previous.png")), tr("Previous"), this);
343
m_rightPaneForwardAction = new QAction(QIcon(QLatin1String(":/help/images/next.png")), tr("Next"), this);
395
m_rightPaneBackwardAction =
396
new QAction(QIcon(QLatin1String(":/help/images/previous.png")),
397
tr("Previous"), this);
398
m_rightPaneForwardAction =
399
new QAction(QIcon(QLatin1String(":/help/images/next.png")), tr("Next"),
345
402
QToolBar *rightPaneToolBar = new QToolBar();
346
403
rightPaneToolBar->addAction(switchToHelpMode);
348
405
rightPaneToolBar->addAction(m_rightPaneForwardAction);
350
407
connect(switchToHelpMode, SIGNAL(triggered()), this, SLOT(switchToHelpMode()));
351
connect(m_rightPaneBackwardAction, SIGNAL(triggered()), this, SLOT(rightPaneBackward()));
352
connect(m_rightPaneForwardAction, SIGNAL(triggered()), this, SLOT(rightPaneForward()));
408
connect(m_rightPaneBackwardAction, SIGNAL(triggered()), this,
409
SLOT(rightPaneBackward()));
410
connect(m_rightPaneForwardAction, SIGNAL(triggered()), this,
411
SLOT(rightPaneForward()));
354
413
QToolButton *closeButton = new QToolButton();
355
414
closeButton->setProperty("type", QLatin1String("dockbutton"));
465
530
QHelpEngineCore hc(fi.absoluteFilePath());
467
532
QString fileNamespace = QHelpEngineCore::namespaceName(qchFileName);
468
if (!fileNamespace.isEmpty() && !hc.registeredDocumentations().contains(fileNamespace)) {
469
if (!hc.registerDocumentation(qchFileName))
470
qDebug() << hc.error();
533
if (!fileNamespace.isEmpty()
534
&& !hc.registeredDocumentations().contains(fileNamespace)) {
535
if (!hc.registerDocumentation(qchFileName))
536
qDebug() << hc.error();
475
int i = m_helpEngine->customValue(
476
QLatin1String("UnfilteredFilterInserted")).toInt();
541
QLatin1String key("UnfilteredFilterInserted");
542
int i = m_helpEngine->customValue(key).toInt();
479
545
QHelpEngineCore hc(m_helpEngine->collectionFile());
481
547
hc.addCustomFilter(tr("Unfiltered"), QStringList());
482
hc.setCustomValue(QLatin1String("UnfilteredFilterInserted"), 1);
548
hc.setCustomValue(key, 1);
484
550
m_helpEngine->blockSignals(true);
485
551
m_helpEngine->setCurrentFilter(tr("Unfiltered"));
602
void HelpPlugin::openContextHelpPage(const QString &url)
604
Core::RightPaneWidget::instance()->setShown(true);
605
m_helpViewerForSideBar->setSource(QUrl(url));
608
void HelpPlugin::updateSideBarSource()
610
const QUrl &url = m_centralWidget->currentSource();
612
updateSideBarSource(url);
615
void HelpPlugin::updateSideBarSource(const QUrl &newUrl)
617
if (m_helpViewerForSideBar)
618
m_helpViewerForSideBar->setSource(newUrl);
529
621
void HelpPlugin::activateContext()
531
using namespace Core;
532
// case 1 sidebar shown and has focus, we show whatever we have in the
534
RightPanePlaceHolder* placeHolder = RightPanePlaceHolder::current();
623
Core::RightPanePlaceHolder* placeHolder = Core::RightPanePlaceHolder::current();
535
624
if (placeHolder && Core::RightPaneWidget::instance()->hasFocus()) {
536
625
switchToHelpMode();
627
} else if (m_core->modeManager()->currentMode() == m_mode)
540
bool useSideBar = false;
541
if (placeHolder && !Core::RightPaneWidget::instance()->hasFocus())
631
QMap<QString, QUrl> links;
544
633
// Find out what to show
545
HelpViewer *viewer = 0;
546
if (IContext *context = m_core->currentContextObject()) {
634
if (Core::IContext *context = m_core->currentContextObject()) {
547
635
if (!m_contextHelpEngine) {
548
m_contextHelpEngine = new QHelpEngineCore(m_helpEngine->collectionFile(), this);
549
//m_contextHelpEngine->setAutoSaveFilter(false);
636
m_contextHelpEngine =
637
new QHelpEngineCore(m_helpEngine->collectionFile(), this);
550
638
m_contextHelpEngine->setupData();
551
639
m_contextHelpEngine->setCurrentFilter(tr("Unfiltered"));
554
const QString &id = context->contextHelpId();
555
QMap<QString, QUrl> links = m_contextHelpEngine->linksForIdentifier(id);
556
if (!links.isEmpty()) {
558
Core::RightPaneWidget::instance()->setShown(true);
559
viewer = m_helpViewerForSideBar;
561
viewer = m_centralWidget->currentHelpViewer();
562
m_core->modeManager()->activateMode(QLatin1String(Constants::ID_MODE_HELP));
642
id = context->contextHelpId();
643
links = m_contextHelpEngine->linksForIdentifier(id);
566
QUrl source = *links.begin();
567
if (viewer->source() != source)
568
viewer->setSource(source);
574
Core::RightPaneWidget::instance()->setShown(true);
575
viewer = m_helpViewerForSideBar;
577
viewer = m_centralWidget->currentHelpViewer();
582
viewer->setHtml(tr("<html><head><title>No Documentation</title></head><body><br/>"
583
"<center><b>%1</b><br/>No documentation available.</center></body></html>").
585
viewer->setSource(QUrl());
646
HelpViewer *viewer = 0;
647
if (placeHolder && !Core::RightPaneWidget::instance()->hasFocus()) {
648
Core::RightPaneWidget::instance()->setShown(true);
649
viewer = m_helpViewerForSideBar;
592
Core::RightPaneWidget::instance()->setShown(true);
593
viewer = m_helpViewerForSideBar;
595
viewer = m_centralWidget->currentHelpViewer();
651
viewer = m_centralWidget->currentHelpViewer();
656
if (links.isEmpty()) {
657
// No link found or no context object
658
viewer->setHtml(tr("<html><head><title>No Documentation</title>"
659
"</head><body><br/><center><b>%1</b><br/>No documentation "
660
"available.</center></body></html>").arg(id));
600
661
viewer->setSource(QUrl());
601
viewer->setHtml("<html><head><title>No Documentation</title></head><body><br/><br/><center>No"
602
" documentation available.</center></body></html>");
663
QUrl source = *links.begin();
664
if (viewer->source() != source)
665
viewer->setSource(source);
682
745
void HelpPlugin::addBookmark()
684
addNewBookmark(m_centralWidget->currentTitle(), m_centralWidget->currentSource().toString());
747
addNewBookmark(m_centralWidget->currentTitle(),
748
m_centralWidget->currentSource().toString());
687
751
void HelpPlugin::addNewBookmark(const QString &title, const QString &url)
753
if (url.isEmpty() || url == QLatin1String("about:blank"))
692
756
m_bookmarkManager->showBookmarkDialog(m_centralWidget, title, url);
695
void HelpPlugin::openGettingStarted()
759
void HelpPlugin::openHelpPage(const QUrl& url)
698
m_centralWidget->setSource(
699
QString("qthelp://com.nokia.qtcreator.%1%2/doc/index.html")
700
.arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR));
761
openHelpPage(url.toString());
764
void HelpPlugin::openHelpPage(const QString& url)
766
if (m_helpEngine->findFile(url).isValid()) {
768
m_centralWidget->setSource(url);
770
// local help not installed, resort to external web help
772
if (url.startsWith("qthelp://com.nokia.qtcreator")) {
773
urlPrefix = QString::fromLatin1("http://doc.trolltech.com/qtcreator-%1.%2/")
774
.arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR);
776
urlPrefix = QLatin1String("http://doc.trolltech.com/latest/");
778
QDesktopServices::openUrl(urlPrefix + url.mid(url.lastIndexOf('/') + 1));
704
782
Q_EXPORT_PLUGIN(HelpPlugin)