From e9c84384d8d0e5b91678eb4722ae30bd3693703f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 19 Jun 2012 01:31:14 +0300 Subject: Add help search commands (?text). Example: ?warps It will open help page about warps. --- src/gui/helpwindow.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/gui/helpwindow.cpp') diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp index 82a70bca9..c2b0d873f 100644 --- a/src/gui/helpwindow.cpp +++ b/src/gui/helpwindow.cpp @@ -80,6 +80,7 @@ HelpWindow::HelpWindow(): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); + loadTags(); } void HelpWindow::action(const gcn::ActionEvent &event) @@ -120,3 +121,56 @@ void HelpWindow::loadFile(const std::string &file) for (unsigned int i = 0; i < lines.size(); ++i) mBrowserBox->addRow(lines[i]); } + +void HelpWindow::loadTags() +{ + std::string helpPath = branding.getStringValue("helpPath"); + if (helpPath.empty()) + helpPath = paths.getStringValue("help"); + StringVect lines; + ResourceManager::loadTextFile(helpPath + "tags.idx", lines); + for (StringVectCIter it = lines.begin(), it_end = lines.end(); + it != it_end; ++ it) + { + const std::string &str = *it; + size_t idx = str.find('|'); + if (idx != std::string::npos) + mTagFileMap[str.substr(idx + 1)].insert(str.substr(0, idx)); + } +} + +void HelpWindow::search(const std::string &text0) +{ + std::string text = text0; + toLower(text); + if (mTagFileMap.find(text) == mTagFileMap.end()) + { + loadHelp("searchnotfound"); + } + else + { + const HelpNames &names = mTagFileMap[text]; + if (names.size() == 1) + { + loadHelp(*names.begin()); + } + else + { + if (!translator) + return; + mBrowserBox->clearRows(); + loadFile("header"); + loadFile("searchmany"); + for (HelpNamesCIter it = names.begin(), it_end = names.end(); + it != it_end; ++ it) + { + const char *str = (*it).c_str(); + mBrowserBox->addRow(strprintf(" -> @@%s|%s@@", str, + translator->getChar(str))); + } + loadFile("footer"); + mScrollArea->setVerticalScrollAmount(0); + setVisible(true); + } + } +} -- cgit v1.2.3-60-g2f50