Skip to content

Commit

Permalink
impl UI
Browse files Browse the repository at this point in the history
  • Loading branch information
wiiznokes committed Sep 29, 2024
1 parent 7ee0769 commit 5bb203a
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 4 deletions.
4 changes: 3 additions & 1 deletion i18n/en/cosmic_ext_applet_clipboard_manager.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ clear_entries = Clear
show_qr_code = Show QR code
return_to_clipboard = Return to clipboard
qr_code_error = Error while generating the QR code
horizontal_layout = Horizontal
horizontal_layout = Horizontal
add_favorite = Add Favorite
remove_favorite = Remove Favorite
4 changes: 3 additions & 1 deletion i18n/fr/cosmic_ext_applet_clipboard_manager.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ clear_entries = Nettoyer
show_qr_code = Afficher le code QR
return_to_clipboard = Retourner au presse-papier
qr_code_error = Erreur pendant la génération du code QR
horizontal_layout = Horizontal
horizontal_layout = Horizontal
add_favorite = Ajouter aux Favoris
remove_favorite = Retirer des Favoris
1 change: 1 addition & 0 deletions res/icons/star24.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions res/icons/star_fill24.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,20 @@ impl cosmic::Application for AppState {
config_set!(horizontal, horizontal);
}
},
AppMsg::AddFavorite(entry) => {
block_on(async {
if let Err(err) = self.db.add_favorite(&entry, None).await {
error!("{err}");
}
});
}
AppMsg::RemoveFavorite(entry) => {
block_on(async {
if let Err(err) = self.db.remove_favorite(&entry).await {
error!("{err}");
}
});
}
}
Command::none()
}
Expand Down
2 changes: 2 additions & 0 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub enum AppMsg {
ShowQrCode(Entry),
ReturnToClipboard,
Config(ConfigMsg),
AddFavorite(Entry),
RemoveFavorite(Entry),
}

#[derive(Clone, Debug)]
Expand Down
24 changes: 22 additions & 2 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ use crate::{
utils::{formatted_value, horizontal_padding, vertical_padding},
};

#[macro_export]
macro_rules! icon {
($name:literal) => {{
let bytes = include_bytes!(concat!("../../res/icons/", $name, "px.svg"));
cosmic::widget::icon::from_svg_bytes(bytes)
}};
}

impl AppState {
pub fn quick_settings_view(&self) -> Element<'_, AppMsg> {
fn toggle_settings<'a>(
Expand Down Expand Up @@ -339,9 +347,21 @@ impl AppState {
menu::Tree::new(
button::text(fl!("show_qr_code"))
.on_press(AppMsg::ShowQrCode(entry.clone()))
.width(Length::Fill)
.style(Button::Destructive),
.width(Length::Fill),
),
if entry.is_favorite {
menu::Tree::new(
button::text(fl!("remove_favorite"))
.on_press(AppMsg::RemoveFavorite(entry.clone()))
.width(Length::Fill),
)
} else {
menu::Tree::new(
button::text(fl!("add_favorite"))
.on_press(AppMsg::AddFavorite(entry.clone()))
.width(Length::Fill),
)
},
]),
)
.into()
Expand Down

0 comments on commit 5bb203a

Please sign in to comment.