Skip to content

Commit

Permalink
Don't disable import button if file selection was cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbende committed Dec 25, 2023
1 parent 254da19 commit 47d4053
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
10 changes: 7 additions & 3 deletions cozy/ui/main_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ def __init_actions(self):

def __init_components(self):
path = self._settings.default_location.path if self._settings.storage_locations else None
import_button = FirstImportButton(self._set_audiobook_path, path)
self.get_object("welcome_status_page").set_child(import_button)
self.import_button = FirstImportButton(self._set_audiobook_path, path)
self.get_object("welcome_status_page").set_child(self.import_button)

if not self._player.loaded_book:
self.block_ui_buttons(True)
Expand Down Expand Up @@ -293,7 +293,11 @@ def _on_drag_data_received(self, widget, value, *_):
thread.start()
return True

def _set_audiobook_path(self, path):
def _set_audiobook_path(self, path: str | None) -> None:
if path is None:
return

self.import_button.disable()
self._storages_view_model.add_first_storage_location(path)
self.scan(None, None)
self.fs_monitor.init_offline_mode()
Expand Down
8 changes: 2 additions & 6 deletions cozy/ui/widgets/first_import_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ class FirstImportButton(Gtk.Button):
def __init__(self, callback: Callable[[str], None], initial_folder: str) -> None:
super().__init__()

self._callback = callback
self._initial_folder = initial_folder
self.connect("clicked", lambda *_: ask_storage_location(callback, initial_folder))

self.connect("clicked", self._on_clicked)

def _on_clicked(self, *_) -> None:
ask_storage_location(self._callback, self._initial_folder)
def disable(self) -> None:
self.set_sensitive(False)
self.spinner.set_spinning(True)
self.stack.set_visible_child(self.spinner)
10 changes: 5 additions & 5 deletions cozy/ui/widgets/storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from cozy.view_model.storages_view_model import StoragesViewModel


def ask_storage_location(callback: Callable[[str], None], initial_folder: str | None = None):
def ask_storage_location(callback: Callable[[str | None], None], initial_folder: str | None = None):
location_chooser = Gtk.FileDialog(title=_("Set Audiobooks Directory"))

if initial_folder:
Expand All @@ -20,8 +20,7 @@ def finish_callback(dialog, result):
except GLib.GError:
pass
else:
if file is not None:
callback(file.get_path())
callback(None if file is None else file.get_path())

location_chooser.select_folder(inject.instance("MainWindow").window, None, finish_callback)

Expand Down Expand Up @@ -53,8 +52,9 @@ def model(self) -> Storage:
def ask_for_new_location(self, *_) -> None:
ask_storage_location(self._on_folder_changed, initial_folder=self._model.path)

def _on_folder_changed(self, new_path: str) -> None:
self.emit("location-changed", new_path)
def _on_folder_changed(self, new_path: str | None) -> None:
if new_path is not None:
self.emit("location-changed", new_path)

def _on_menu_opened(self, *_) -> None:
self.emit("menu-opened")
Expand Down
5 changes: 4 additions & 1 deletion cozy/view_model/storages_view_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def _rebase_storage_location(self, model: Storage, old_path: str) -> None:
name="RebaseStorageLocationThread",
).start()

def add_storage_location(self, path: str) -> None:
def add_storage_location(self, path: str | None) -> None:
if path is None:
return

model = Storage.new(self._db, path)
model.external = self._fs_monitor.is_external(path)

Expand Down

0 comments on commit 47d4053

Please sign in to comment.