1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:58:11 +00:00

Browser: Add bookmarks bar

This patchset adds a bookmark bar that is backed by a json file backend.
The json file is loaded and checked for the format. According to the
format, the bookmarks bar is populated with the bookmark items.

If the bookmarks do not fit into one line, an expader button is shown
that brings up a menu containing the missing bookmark items.

There is currently no way to add or remove bookmarks. A hover over a
bookmark is also not yet showing the url in the statusbar.
This commit is contained in:
Emanuel Sprung 2020-03-21 20:24:32 +01:00 committed by Andreas Kling
parent a9e943ae4c
commit 337ade9e4c
5 changed files with 245 additions and 8 deletions

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "BookmarksBarWidget.h"
#include "History.h"
#include "InspectorWidget.h"
#include <LibCore/File.h>
@ -53,6 +54,7 @@
#include <stdlib.h>
static const char* home_url = "file:///home/anon/www/welcome.html";
static const char* bookmarks_filename = "/home/anon/bookmarks.json";
int main(int argc, char** argv)
{
@ -71,7 +73,6 @@ int main(int argc, char** argv)
return 1;
}
auto window = GUI::Window::construct();
window->set_rect(100, 100, 640, 480);
@ -80,14 +81,15 @@ int main(int argc, char** argv)
widget.set_layout<GUI::VerticalBoxLayout>();
widget.layout()->set_spacing(0);
bool bookmarksbar_enabled = true;
auto& toolbar = widget.add<GUI::ToolBar>();
auto& bookmarksbar = widget.add<GUI::Widget>();
auto& bookmarksbar = widget.add<BookmarksBarWidget>(bookmarks_filename, bookmarksbar_enabled);
auto& html_widget = widget.add<Web::HtmlView>();
bool bookmarksbar_enabled = true;
bookmarksbar.set_layout<GUI::HorizontalBoxLayout>();
bookmarksbar.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
bookmarksbar.set_preferred_size(0, bookmarksbar_enabled ? 20 : 0);
bookmarksbar.on_bookmark_click = [&](auto&, auto& url) {
html_widget.load(url);
};
History<URL> history;
@ -163,6 +165,10 @@ int main(int argc, char** argv)
statusbar.set_text(href);
};
bookmarksbar.on_bookmark_hover = [&](auto&, auto& url) {
statusbar.set_text(url);
};
Web::ResourceLoader::the().on_load_counter_change = [&] {
if (Web::ResourceLoader::the().pending_loads() == 0) {
statusbar.set_text("");
@ -241,7 +247,7 @@ int main(int argc, char** argv)
auto bookmarks_menu = GUI::Menu::construct("Bookmarks");
auto show_bookmarksbar_action = GUI::Action::create("Show bookmarks bar", [&](auto& action) {
action.set_checked(!action.is_checked());
bookmarksbar.set_preferred_size(0, action.is_checked() ? 20 : 0);
bookmarksbar.set_visible(action.is_checked());
bookmarksbar.update();
});
show_bookmarksbar_action->set_checkable(true);