Skip to content

Commit

Permalink
New storage button as part of the same list
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbende committed Dec 21, 2023
1 parent df9dcef commit fa9eac4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
13 changes: 10 additions & 3 deletions cozy/ui/widgets/storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,16 @@ class StorageLocations(Adw.PreferencesGroup):
_view_model: StoragesViewModel = inject.attr(StoragesViewModel)

storage_locations_list: Gtk.ListBox = Gtk.Template.Child()
new_storage_button: Adw.ActionRow = Gtk.Template.Child()
storage_menu: Gio.Menu = Gtk.Template.Child()

def __init__(self) -> None:
super().__init__()

self.new_storage_button.connect("activated", self._on_new_storage_clicked)

self._view_model.bind_to("storage_locations", self._reload_storage_list)
self._view_model.bind_to("storage_attributes", self._reload_storage_list)

self._create_actions()
self.new_storage_button = self._create_new_storage_button()

self._reload_storage_list()

Expand All @@ -132,6 +130,13 @@ def _create_actions(self) -> None:
self.make_default_action.connect("activate", self._set_default_storage_location)
self.action_group.add_action(self.make_default_action)

def _create_new_storage_button(self) -> Adw.ActionRow:
icon = Gtk.Image(icon_name="list-add-symbolic", margin_top=18, margin_bottom=18)
row = Adw.ActionRow(selectable=False, activatable=True)
row.connect("activated", self._on_new_storage_clicked)
row.set_child(icon)
return row

def _reload_storage_list(self) -> None:
self.storage_locations_list.remove_all()

Expand All @@ -141,6 +146,8 @@ def _reload_storage_list(self) -> None:
row.connect("menu-opened", self._on_storage_menu_opened)
self.storage_locations_list.append(row)

self.storage_locations_list.append(self.new_storage_button)

def _remove_storage_location(self, *_) -> None:
self._view_model.remove(self._view_model.selected_storage)

Expand Down
20 changes: 0 additions & 20 deletions data/ui/storage_locations.ui
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,6 @@
</style>
</object>
</child>
<child>
<object class="GtkListBox">
<child>
<object class="AdwActionRow" id="new_storage_button">
<property name="selectable">false</property>
<property name="activatable">true</property>
<property name="child">
<object class="GtkImage">
<property name="icon-name">list-add-symbolic</property>
<property name="margin-top">18</property>
<property name="margin-bottom">18</property>
</object>
</property>
</object>
</child>
<style>
<class name="boxed-list"/>
</style>
</object>
</child>
</template>
<menu id="storage_menu">
<section>
Expand Down

0 comments on commit fa9eac4

Please sign in to comment.