Skip to content

Commit

Permalink
panel/files: Show filesystem mounts on dropdown menu
Browse files Browse the repository at this point in the history
  • Loading branch information
sjohannes committed Feb 13, 2020
1 parent a31d8b1 commit 728a2ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
6 changes: 4 additions & 2 deletions data/ui/panel/files.ui
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkListStore" id="liststore_libraries_location">
<columns>
<!-- column-name value -->
<!-- column-name text -->
<column type="gchararray"/>
<!-- column-name uri -->
<column type="gchararray"/>
</columns>
</object>
Expand Down
37 changes: 23 additions & 14 deletions xlgui/panel/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def _setup_widgets(self):
self.fill_libraries_location, 'libraries_modified', self.collection
)
self.fill_libraries_location()
self.location_bar.set_row_separator_func(lambda m, i: m[i][1] is None)
self.entry = self.location_bar.get_children()[0]
self.entry.connect('activate', self.entry_activate)

Expand All @@ -189,19 +190,26 @@ def _setup_widgets(self):
)

def fill_libraries_location(self, *e):
libraries = []
for library in self.collection._serial_libraries:
f = Gio.File.new_for_commandline_arg(library['location'])
libraries.append((f.get_parse_name(), f.get_uri()))

mounts = []
for mount in Gio.VolumeMonitor.get().get_mounts():
name = mount.get_name()
uri = mount.get_default_location().get_uri()
mounts.append((name, uri))
mounts.sort(key=lambda row: locale.strxfrm(row[0]))

model = self.location_bar.get_model()
model.clear()
libraries = self.collection._serial_libraries

if len(libraries) > 0:
for library in libraries:
model.append(
[
Gio.File.new_for_commandline_arg(
library['location']
).get_parse_name()
]
)
for row in libraries:
model.append(row)
if libraries and mounts:
model.append((None, None))
for row in mounts:
model.append(row)
self.location_bar.set_model(model)

def on_location_bar_changed(self, widget, *args):
Expand All @@ -210,9 +218,9 @@ def on_location_bar_changed(self, widget, *args):
if not iter:
return
model = self.location_bar.get_model()
location = model.get_value(iter, 0)
if location != '':
self.load_directory(Gio.File.new_for_commandline_arg(location))
uri = model.get_value(iter, 1)
if uri:
self.load_directory(Gio.File.new_for_uri(uri))

def on_key_released(self, widget, event):
"""
Expand Down Expand Up @@ -272,6 +280,7 @@ def refresh(self, widget):
treepath = self.tree.get_cursor()[0]
cursorf = self.model[treepath][0] if treepath else None
self.load_directory(self.current, history=False, cursor_file=cursorf)
self.fill_libraries_location()

def entry_activate(self, widget, event=None):
"""
Expand Down

0 comments on commit 728a2ea

Please sign in to comment.