mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
Help: Support loading help page by file path as command line argument
This commit is contained in:
parent
7f7656fe4e
commit
bd2a7c414c
2 changed files with 29 additions and 15 deletions
|
@ -88,10 +88,10 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
unveil(nullptr, nullptr);
|
unveil(nullptr, nullptr);
|
||||||
|
|
||||||
const char* term_to_search_for_at_launch = nullptr;
|
const char* start_page = nullptr;
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_positional_argument(term_to_search_for_at_launch, "Term to search for at launch", "term", Core::ArgsParser::Required::No);
|
args_parser.add_positional_argument(start_page, "Page to open at launch", "page", Core::ArgsParser::Required::No);
|
||||||
|
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(argc, argv);
|
||||||
|
|
||||||
|
@ -153,6 +153,7 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
auto open_page = [&](const String& path) {
|
auto open_page = [&](const String& path) {
|
||||||
if (path.is_null()) {
|
if (path.is_null()) {
|
||||||
|
window->set_title("Help");
|
||||||
page_view.load_empty_document();
|
page_view.load_empty_document();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -171,19 +172,19 @@ int main(int argc, char* argv[])
|
||||||
html = md_document->render_to_html();
|
html = md_document->render_to_html();
|
||||||
}
|
}
|
||||||
|
|
||||||
page_view.load_html(html, URL::create_with_file_protocol(path));
|
auto url = URL::create_with_file_protocol(path);
|
||||||
|
page_view.load_html(html, url);
|
||||||
|
|
||||||
String page_and_section = model->page_and_section(tree_view.selection().first());
|
auto tree_view_index = model->index_from_path(path);
|
||||||
|
if (tree_view_index.has_value())
|
||||||
|
tree_view.expand_tree(tree_view_index.value().parent());
|
||||||
|
|
||||||
|
String page_and_section = model->page_and_section(tree_view_index.value());
|
||||||
window->set_title(String::formatted("{} - Help", page_and_section));
|
window->set_title(String::formatted("{} - Help", page_and_section));
|
||||||
};
|
};
|
||||||
|
|
||||||
tree_view.on_selection_change = [&] {
|
tree_view.on_selection_change = [&] {
|
||||||
String path = model->page_path(tree_view.selection().first());
|
String path = model->page_path(tree_view.selection().first());
|
||||||
if (path.is_null()) {
|
|
||||||
page_view.load_empty_document();
|
|
||||||
window->set_title("Help");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
history.push(path);
|
history.push(path);
|
||||||
update_actions();
|
update_actions();
|
||||||
open_page(path);
|
open_page(path);
|
||||||
|
@ -263,6 +264,7 @@ int main(int argc, char* argv[])
|
||||||
auto go_home_action = GUI::CommonActions::make_go_home_action([&](auto&) {
|
auto go_home_action = GUI::CommonActions::make_go_home_action([&](auto&) {
|
||||||
String path = "/usr/share/man/man7/Help-index.md";
|
String path = "/usr/share/man/man7/Help-index.md";
|
||||||
history.push(path);
|
history.push(path);
|
||||||
|
update_actions();
|
||||||
open_page(path);
|
open_page(path);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -288,12 +290,19 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
app->set_menubar(move(menubar));
|
app->set_menubar(move(menubar));
|
||||||
|
|
||||||
if (term_to_search_for_at_launch) {
|
if (start_page) {
|
||||||
left_tab_bar.set_active_widget(&search_view);
|
URL url = URL::create_with_url_or_path(start_page);
|
||||||
search_box.set_text(term_to_search_for_at_launch);
|
if (url.is_valid() && url.path().ends_with(".md")) {
|
||||||
if (auto model = search_list_view.model()) {
|
history.push(url.path());
|
||||||
auto& search_model = *static_cast<GUI::FilteringProxyModel*>(model);
|
update_actions();
|
||||||
search_model.set_filter_term(search_box.text());
|
open_page(url.path());
|
||||||
|
} else {
|
||||||
|
left_tab_bar.set_active_widget(&search_view);
|
||||||
|
search_box.set_text(start_page);
|
||||||
|
if (auto model = search_list_view.model()) {
|
||||||
|
auto& search_model = *static_cast<GUI::FilteringProxyModel*>(model);
|
||||||
|
search_model.set_filter_term(search_box.text());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
go_home_action->activate();
|
go_home_action->activate();
|
||||||
|
|
|
@ -24,8 +24,10 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/URL.h>
|
||||||
#include <Applications/Terminal/TerminalSettingsWindowGML.h>
|
#include <Applications/Terminal/TerminalSettingsWindowGML.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
|
#include <LibDesktop/Launcher.h>
|
||||||
#include <LibGUI/AboutDialog.h>
|
#include <LibGUI/AboutDialog.h>
|
||||||
#include <LibGUI/Action.h>
|
#include <LibGUI/Action.h>
|
||||||
#include <LibGUI/ActionGroup.h>
|
#include <LibGUI/ActionGroup.h>
|
||||||
|
@ -471,6 +473,9 @@ int main(int argc, char** argv)
|
||||||
view_menu.add_action(pick_font_action);
|
view_menu.add_action(pick_font_action);
|
||||||
|
|
||||||
auto& help_menu = menubar->add_menu("Help");
|
auto& help_menu = menubar->add_menu("Help");
|
||||||
|
help_menu.add_action(GUI::CommonActions::make_help_action([](auto&) {
|
||||||
|
Desktop::Launcher::open(URL::create_with_file_protocol("/usr/share/man/man1/Terminal.md"), "/bin/Help");
|
||||||
|
}));
|
||||||
help_menu.add_action(GUI::Action::create("About", [&](auto&) {
|
help_menu.add_action(GUI::Action::create("About", [&](auto&) {
|
||||||
GUI::AboutDialog::show("Terminal", app_icon.bitmap_for_size(32), window);
|
GUI::AboutDialog::show("Terminal", app_icon.bitmap_for_size(32), window);
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue