Skip to content

Commit

Permalink
Add Empty state for the language preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Maksimov committed Dec 22, 2023
1 parent 8f990c1 commit 0b3c041
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 31 deletions.
78 changes: 48 additions & 30 deletions data/ui/preferences_languages.blp
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,36 @@ template $PreferencesLanguagesPage : Adw.PreferencesPage {
SearchEntry language_search_entry {
margin-start: 4;
margin-end: 4;
placeholder-text: _('Search Languages…');
}
}

Revealer revealer {
reveal-child: bind search_bar.search-mode-enabled bidirectional inverted;

Adw.ClampScrollable {
maximum-size: 600;

Box {
margin-top: 12;
margin-start: 12;
margin-end: 12;
Box {
margin-top: 12;
margin-start: 12;
margin-end: 12;

Label caption_label {
label: _("Installed languages");
hexpand: true;
halign: start;
Label caption_label {
label: _("Installed languages");
hexpand: true;
halign: start;

styles ["heading", "h4"]
}
styles ["heading", "h4"]
}

Button {
icon-name: "list-add-symbolic";
tooltip-text: "Add language";
clicked => $_on_add_language();
Button {
icon-name: "list-add-symbolic";
tooltip-text: "Add language";
clicked => $_on_add_language();

styles ["flat"]
styles ["flat"]
}
}
}
}
Expand All @@ -58,24 +62,38 @@ template $PreferencesLanguagesPage : Adw.PreferencesPage {
Adw.ClampScrollable {
maximum-size: 600;

ListView list_view {
name: "lang_list";
Stack views {

show-separators: true;
enable-rubberband: false;
model: NoSelection selection {
model: FilterListModel model {
model: Gio.ListStore list_store {
item-type: typeof<$LanguageItem>;
StackPage {
name: 'languages_page';
child: ListView list_view {
name: "lang_list";
enable-rubberband: false;

model: NoSelection selection {
model: FilterListModel model {
model: Gio.ListStore list_store {
item-type: typeof<$LanguageItem>;
};
};
};
factory: SignalListItemFactory factory {
setup => $_on_item_setup();
bind => $_on_item_bind();
};
};
};
factory: SignalListItemFactory factory {
setup => $_on_item_setup();
bind => $_on_item_bind();
};

styles ["boxed-list", "card"]
styles ["boxed-list", "card"]
};
}

StackPage {
name: 'empty_page';
child: Adw.StatusPage {
icon-name: "system-search-symbolic";
title: _('No Results Found');
styles ["compact"]
};
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion frog/language_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ def get_downloaded_languages(self, force: bool = False) -> List[str]:
def download(self, code):
self.emit('added', code)
self.loading_languages[code] = DownloadState()
self.emit('downloading', code, 0.1)
GObjectWorker.call(self.download_begin, (code,), self.download_done)
self.emit('downloading', code, 0)

def download_begin(self, code):

Expand Down
8 changes: 8 additions & 0 deletions frog/widgets/preferences_languages_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
class PreferencesLanguagesPage(Adw.PreferencesPage):
__gtype_name__ = 'PreferencesLanguagesPage'

views: Gtk.Stack = Gtk.Template.Child()
search_bar: Gtk.SearchBar = Gtk.Template.Child()
language_search_entry: Gtk.SearchEntry = Gtk.Template.Child()
list_view: Gtk.ListView = Gtk.Template.Child()
Expand Down Expand Up @@ -112,6 +113,7 @@ def is_search_mode(self):
def activate_filter(self, search_text: str = None) -> None:
_filter: Gtk.CustomFilter = Gtk.CustomFilter.new(PreferencesLanguagesPage.filter_func, search_text)
self.model.set_filter(_filter)
self.toggle_empty_state(not self.model.get_n_items())

def deactivate_filter(self):
self.model.set_filter(None)
Expand Down Expand Up @@ -143,3 +145,9 @@ def on_language_added(self, _sender, _code: str = None) -> None:
def on_language_removed(self, _sender, _code) -> None:
if not self.search_bar.get_search_mode():
self.activate_filter()

def toggle_empty_state(self, is_empty: bool = False) -> None:
if is_empty:
self.views.set_visible_child_name('empty_page')
else:
self.views.set_visible_child_name('languages_page')

0 comments on commit 0b3c041

Please sign in to comment.