Skip to content

Commit

Permalink
Use new ToolbarView widget for bookmarks panel
Browse files Browse the repository at this point in the history
  • Loading branch information
hugolabe committed Dec 14, 2023
1 parent a3baa6a commit 66ce987
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 90 deletions.
126 changes: 61 additions & 65 deletions data/ui/bookmarks.ui
Original file line number Diff line number Diff line change
Expand Up @@ -5,90 +5,86 @@ SPDX-FileCopyrightText: 2021-23 Hugo Olabera <hugolabe@gmail.com>
SPDX-License-Identifier: GPL-3.0-or-later
-->

<!-- Bookmarks box for sidebar -->
<!-- Bookmarks panel for sidebar -->
<interface>
<template class="BookmarksBox" parent="GtkBox">
<property name="orientation">vertical</property>

<!-- Header -->
<template class="BookmarksPanel" parent="AdwBin">
<child>
<object class="GtkBox">
<property name="margin-start">6</property>
<property name="margin-end">6</property>
<property name="margin-top">6</property>
<property name="margin-bottom">6</property>
<property name="spacing">6</property>
<property name="hexpand">false</property>

<!-- Bookmark list selector -->
<child>
<object class="GtkDropDown" id="booklists_dropdown">
<property name="hexpand">true</property>
</object>
</child>
<object class="AdwToolbarView">

<!-- Add bookmark button -->
<child>
<object class="GtkButton" id="add_button">
<property name="icon-name">bookmark-new-symbolic</property>
<property name="tooltip-text" translatable="yes">Add Bookmark</property>
<property name="action-name">win.add-bookmark</property>
</object>
</child>
<!-- Header -->
<child type="top">
<object class="GtkBox">
<property name="margin-start">6</property>
<property name="margin-end">6</property>
<property name="margin-top">6</property>
<property name="margin-bottom">6</property>
<property name="spacing">6</property>
<property name="hexpand">false</property>

<!-- Menu button -->
<child>
<object class="GtkMenuButton" id="menu_button">
<property name="icon-name">view-more-symbolic</property>
</object>
</child>
<!-- Bookmark list selector -->
<child>
<object class="GtkDropDown" id="booklists_dropdown">
<property name="hexpand">true</property>
</object>
</child>

</object>
</child>
<!-- Add bookmark button -->
<child>
<object class="GtkButton" id="add_button">
<property name="icon-name">bookmark-new-symbolic</property>
<property name="tooltip-text" translatable="yes">Add Bookmark</property>
<property name="action-name">win.add-bookmark</property>
</object>
</child>

<!-- Separator -->
<child>
<object class="GtkSeparator" id="bookmarks_separator">
<property name="visible">false</property>
</object>
</child>
<!-- Menu button -->
<child>
<object class="GtkMenuButton" id="menu_button">
<property name="icon-name">view-more-symbolic</property>
</object>
</child>

<!-- Bookmarks scroller -->
<child>
<object class="GtkScrolledWindow" id="bookmarks_scroller">
<child>
<object class="GtkViewport">
</object>
</child>

<!-- Bookmarks list -->
<!-- Bookmarks scroller -->
<property name="content">
<object class="GtkScrolledWindow">
<child>
<object class="GtkListBox" id="bookmarks_list">
<property name="vexpand">true</property>
<property name="selection-mode">none</property>
<style>
<class name="navigation-sidebar"/>
</style>
<object class="GtkViewport">

<!-- Placeholder -->
<child type="placeholder">
<object class="AdwStatusPage">
<property name="title" translatable="yes">No Bookmarks</property>
<property name="description" translatable="yes">Use the Add Bookmark button or press Ctrl+D to add the current article to the list</property>
<property name="icon-name">user-bookmarks-symbolic</property>
<property name="margin-start">50</property>
<property name="margin-end">50</property>
<!-- Bookmarks list -->
<child>
<object class="GtkListBox" id="bookmarks_list">
<property name="vexpand">true</property>
<property name="selection-mode">none</property>
<style>
<class name="compact"/>
<class name="navigation-sidebar"/>
</style>

<!-- Placeholder -->
<child type="placeholder">
<object class="AdwStatusPage">
<property name="title" translatable="yes">No Bookmarks</property>
<property name="description" translatable="yes">Use the Add Bookmark button or press Ctrl+D to add the current article to the list</property>
<property name="icon-name">user-bookmarks-symbolic</property>
<property name="margin-start">50</property>
<property name="margin-end">50</property>
<style>
<class name="compact"/>
</style>
</object>
</child>

</object>
</child>

</object>
</child>

</object>
</child>
</property>

</object>
</child>

</template>
</interface>
25 changes: 7 additions & 18 deletions src/bookmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
# Box bookmarks in sidebar

@Gtk.Template(resource_path='/com/github/hugolabe/Wike/ui/bookmarks.ui')
class BookmarksBox(Gtk.Box):
class BookmarksPanel(Adw.Bin):

__gtype_name__ = 'BookmarksBox'
__gtype_name__ = 'BookmarksPanel'

booklists_dropdown = Gtk.Template.Child()
menu_button = Gtk.Template.Child()
bookmarks_list = Gtk.Template.Child()
bookmarks_scroller = Gtk.Template.Child()
bookmarks_separator = Gtk.Template.Child()

# Initialize widgets and connect signals

Expand Down Expand Up @@ -55,7 +53,6 @@ def __init__(self, window):
self.booklists_dropdown.connect('notify::selected', self._booklists_dropdown_selected_cb)
self.booklists_model.connect('items-changed', self._booklists_model_changed_cb)
self.bookmarks_list.connect('row-activated', self._list_activated_cb)
self.bookmarks_scroller.get_vadjustment().connect('value-changed', self._bookmarks_scrolled_cb)

# Set actions for bookmarks menu

Expand Down Expand Up @@ -342,14 +339,6 @@ def _row_remove_button_cb(self, remove_button, row):

self.refresh_buttons()

# Show/hide separator on scroll

def _bookmarks_scrolled_cb(self, adjustment):
if adjustment.get_value() > 0:
self.bookmarks_separator.set_visible(True)
else:
self.bookmarks_separator.set_visible(False)


# This object represent a bookmarks list in dropdown

Expand Down Expand Up @@ -405,22 +394,22 @@ class BookmarksMenuPopover(Gtk.PopoverMenu):

# Set menu model and connect signals

def __init__(self, bookmarks_box):
def __init__(self, bookmarks_panel):
super().__init__()

builder_menu = Gtk.Builder()
builder_menu.add_from_resource('/com/github/hugolabe/Wike/ui/bookmarks-menu.ui')
menu = builder_menu.get_object('bookmarks_menu')
self.set_menu_model(menu)

self.connect('show', self._popover_show_cb, bookmarks_box)
self.connect('show', self._popover_show_cb, bookmarks_panel)

# Enable or disable menu items on popover show

def _popover_show_cb(self, popover, bookmarks_box):
rename_list_action = bookmarks_box.actions_group.lookup_action('rename-list')
def _popover_show_cb(self, popover, bookmarks_panel):
rename_list_action = bookmarks_panel.actions_group.lookup_action('rename-list')

if bookmarks_box.booklists_dropdown.get_selected() == 0:
if bookmarks_panel.booklists_dropdown.get_selected() == 0:
rename_list_action.set_enabled(False)
else:
rename_list_action.set_enabled(True)
4 changes: 2 additions & 2 deletions src/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _wikiview_load_changed_cb(self, wikiview, event):
if tabpage.get_selected():
self._window.toc_panel.populate(wikiview.title, wikiview.sections)
self._window.langlinks_panel.populate(wikiview.langlinks)
self._window.bookmarks_box.refresh_buttons()
self._window.bookmarks_panel.refresh_buttons()
self._window.refresh_menu_actions(wikiview.is_local())

case WebKit.LoadEvent.FINISHED:
Expand Down Expand Up @@ -139,7 +139,7 @@ def _wikiview_new_page_cb(self, wikiview, uri):
# On webview event add new bookmark

def _wikiview_add_bookmark_cb(self, wikiview, uri, title, lang):
if self._window.bookmarks_box.add_bookmark(uri, title, lang):
if self._window.bookmarks_panel.add_bookmark(uri, title, lang):
message = _('Bookmark added: ') + title
self._window.send_notification(message)

Expand Down
10 changes: 5 additions & 5 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from gi.repository import GLib, GObject, Gio, Gdk, Gtk, Adw, WebKit

from wike.data import settings
from wike.bookmarks import BookmarksBox
from wike.bookmarks import BookmarksPanel
from wike.header import HeaderBar, ActionBar
from wike.history import HistoryPanel
from wike.langlinks import LanglinksPanel
Expand Down Expand Up @@ -68,8 +68,8 @@ def __init__(self, app, launch_uri):
self.langlinks_panel = LanglinksPanel(self)
langlinks_stack_page = self.flap_stack.add_named(self.langlinks_panel, 'langlinks')

self.bookmarks_box = BookmarksBox(self)
bookmarks_stack_page = self.flap_stack.add_named(self.bookmarks_box, 'bookmarks')
self.bookmarks_panel = BookmarksPanel(self)
bookmarks_stack_page = self.flap_stack.add_named(self.bookmarks_panel, 'bookmarks')

self.history_panel = HistoryPanel(self)
history_stack_page = self.flap_stack.add_named(self.history_panel, 'history')
Expand Down Expand Up @@ -322,7 +322,7 @@ def _tabview_selected_page_cb(self, tabview, value):
self.refresh_menu_actions(self.page.wikiview.is_local())
self.toc_panel.populate(self.page.wikiview.title, self.page.wikiview.sections)
self.langlinks_panel.populate(self.page.wikiview.langlinks)
self.bookmarks_box.refresh_buttons()
self.bookmarks_panel.refresh_buttons()

# On tab closed event destroy wikiview and confirm

Expand Down Expand Up @@ -378,7 +378,7 @@ def _add_bookmark_cb(self, action, parameter):
uri = self.page.wikiview.get_base_uri()
title = self.page.wikiview.title
lang = self.page.wikiview.get_lang()
if self.bookmarks_box.add_bookmark(uri, title, lang):
if self.bookmarks_panel.add_bookmark(uri, title, lang):
message = _('Bookmark added: ') + title
self.send_notification(message)

Expand Down

0 comments on commit 66ce987

Please sign in to comment.