Skip to content

Commit 06cf20e

Browse files
committed
Added bookmark button class
1 parent f555f0c commit 06cf20e

File tree

3 files changed

+40
-25
lines changed

3 files changed

+40
-25
lines changed

src/bookmarks.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# You should have received a copy of the GNU General Public License
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

18-
from gi.repository import Gio, GLib, GObject
18+
from gi.repository import Gio, GLib, GObject, Gtk
1919

2020
from . import logger
2121
from . import utils
@@ -79,3 +79,32 @@ def toggle_bookmark(self, button, path):
7979
else:
8080
self._add_bookmark(path)
8181
self._save_bookmarks()
82+
83+
class PortfolioBookmarkButton(Gtk.Button):
84+
__gtype_name__ = "PortfolioBookmarkButton"
85+
86+
87+
def __init__(self, bookmarks):
88+
Gtk.Button.__init__(self)
89+
self.connect("clicked", self._on_bookmark_toggle)
90+
self._bookmarks = bookmarks
91+
self.props.icon_name = "bookmark-filled-symbolic"
92+
93+
def _change_icon(self):
94+
if self._bookmarks.is_bookmarked(self._path):
95+
self.props.icon_name = "bookmark-filled-symbolic"
96+
else:
97+
self.props.icon_name = "bookmark-outline-symbolic"
98+
99+
def _on_bookmark_toggle(self, button):
100+
self._bookmarks.toggle_bookmark(button, self._path)
101+
self._change_icon()
102+
103+
@property
104+
def path(self):
105+
self._path
106+
107+
@path.setter
108+
def path(self, path):
109+
self._path = path
110+
self._change_icon()

src/window.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from .files import PortfolioFiles
4444
from .menu import PortfolioMenu
4545
from .settings import PortfolioSettings
46-
from .bookmarks import PortfolioBookmarks
46+
from .bookmarks import PortfolioBookmarks, PortfolioBookmarkButton
4747
from .trash import default_trash
4848

4949

@@ -62,7 +62,7 @@ class PortfolioWindow(Adw.ApplicationWindow):
6262
paste = Gtk.Template.Child()
6363
select_all = Gtk.Template.Child()
6464
select_none = Gtk.Template.Child()
65-
bookmark = Gtk.Template.Child()
65+
bookmark_box = Gtk.Template.Child()
6666
new_folder = Gtk.Template.Child()
6767
delete_trash = Gtk.Template.Child()
6868
restore_trash = Gtk.Template.Child()
@@ -150,7 +150,7 @@ def _setup(self):
150150
self.select_all.connect("clicked", self._on_select_all)
151151
self.select_none.connect("clicked", self._on_select_none)
152152
self.new_folder.connect("clicked", self._on_new_folder)
153-
self.bookmark.connect("clicked", self._on_bookmark_toggle)
153+
154154
self.close_button.connect("clicked", self._on_button_closed)
155155
self.go_top_button.connect("clicked", self._go_to_top)
156156
self.stop_button.connect("clicked", self._on_stop_clicked)
@@ -185,6 +185,10 @@ def _setup(self):
185185
self.files.sort_order = self._settings.sort_order
186186
self.content_inner_box.append(self.files)
187187
self._bookmarks = PortfolioBookmarks()
188+
189+
self._bookmark_button = PortfolioBookmarkButton(self._bookmarks)
190+
self.bookmark_box.append(self._bookmark_button)
191+
188192
places = PortfolioPlaces(self._bookmarks)
189193
places.connect("updated", self._on_places_updated)
190194
places.connect("removing", self._on_places_removing)
@@ -227,11 +231,8 @@ def _populate(self, directory):
227231
self._worker.connect("finished", self._on_load_finished)
228232
self._worker.connect("failed", self._on_load_failed)
229233
self._worker.start()
234+
self._bookmark_button.path = directory
230235

231-
if self._bookmarks.is_bookmarked(directory):
232-
self.bookmark.props.icon_name = "bookmark-filled-symbolic"
233-
else:
234-
self.bookmark.props.icon_name = "bookmark-outline-symbolic"
235236

236237
def _paste(self, Worker, to_paste):
237238
directory = self._history[self._index]
@@ -867,14 +868,6 @@ def _on_new_folder(self, button):
867868
directory = self._history[self._index]
868869
self.files.add_new_folder_row(directory)
869870

870-
def _on_bookmark_toggle(self, button):
871-
path = self._history[self._index]
872-
self._bookmarks.toggle_bookmark(button, path)
873-
if self._bookmarks.is_bookmarked(path):
874-
self.bookmark.props.icon_name = "bookmark-filled-symbolic"
875-
else:
876-
self.bookmark.props.icon_name = "bookmark-outline-symbolic"
877-
878871
def _on_restore_trash_clicked(self, button):
879872
selection = self.files.get_selection()
880873
paths = [default_trash.get_orig_path(path) for path, ref in selection]

src/window.ui

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -361,17 +361,10 @@
361361
<object class="GtkBox" id="navigation_tools">
362362
<property name="halign">end</property>
363363
<child>
364-
<object class="GtkButton" id="bookmark">
365-
<property name="sensitive">1</property>
366-
<property name="receives-default">1</property>
364+
<object class="GtkBox" id="bookmark_box">
367365
<child>
368-
<object class="GtkImage">
369-
<property name="icon-name">bookmark-outline-symbolic</property>
370-
</object>
366+
<placeholder/>
371367
</child>
372-
<style>
373-
<class name="tool-button"/>
374-
</style>
375368
</object>
376369
</child>
377370
<child>

0 commit comments

Comments
 (0)