Skip to content

Commit

Permalink
feat: horizontal layout (#75)
Browse files Browse the repository at this point in the history
fix #22
wiiznokes authored Aug 29, 2024
1 parent 9d4bc73 commit 31314b8
Showing 10 changed files with 451 additions and 345 deletions.
3 changes: 2 additions & 1 deletion i18n/en/cosmic_ext_applet_clipboard_manager.ftl
Original file line number Diff line number Diff line change
@@ -4,4 +4,5 @@ incognito = Incognito
clear_entries = Clear
show_qr_code = Show QR code
return_to_clipboard = Return to clipboard
qr_code_error = Error while generating the QR code
qr_code_error = Error while generating the QR code
horizontal_layout = Horizontal
3 changes: 2 additions & 1 deletion i18n/fr/cosmic_ext_applet_clipboard_manager.ftl
Original file line number Diff line number Diff line change
@@ -4,4 +4,5 @@ incognito = Incognito
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
qr_code_error = Erreur pendant la génération du code QR
horizontal_layout = Horizontal
209 changes: 123 additions & 86 deletions src/app.rs

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ use cosmic::{

use serde::{Deserialize, Serialize};

use crate::{app::APPID, message::AppMessage, utils};
use crate::{app::APPID, message::AppMsg, utils};

pub const CONFIG_VERSION: u64 = 2;

@@ -16,6 +16,7 @@ pub struct Config {
pub private_mode: bool,
pub maximum_entries_lifetime: Option<Duration>,
pub maximum_entries_number: Option<u32>,
pub horizontal: bool,
}

impl Default for Config {
@@ -24,13 +25,14 @@ impl Default for Config {
private_mode: false,
maximum_entries_lifetime: Some(Duration::from_secs(30 * 24 * 60 * 60)), // 30 days,
maximum_entries_number: Some(500),
horizontal: false,
}
}
}

pub static PRIVATE_MODE: AtomicBool = AtomicBool::new(false);

pub fn sub() -> Subscription<AppMessage> {
pub fn sub() -> Subscription<AppMsg> {
struct ConfigSubscription;

cosmic_config::config_subscription(
@@ -42,6 +44,6 @@ pub fn sub() -> Subscription<AppMessage> {
if !update.errors.is_empty() {
error!("can't load config {:?}: {:?}", update.keys, update.errors);
}
AppMessage::ChangeConfig(update.config)
AppMsg::ChangeConfig(update.config)
})
}
2 changes: 1 addition & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ use mime::Mime;
use crate::{
app::{APP, APPID, ORG, QUALIFIER},
config::Config,
message::AppMessage,
message::AppMsg,
utils::{self, now_millis, remove_dir_contents},
};

4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
#![allow(unused_macros)]
#![allow(unused_imports)]

use app::{Flags, Window};
use app::{AppState, Flags};
use config::{Config, CONFIG_VERSION};
use cosmic::cosmic_config;
use cosmic::cosmic_config::CosmicConfigEntry;
@@ -70,5 +70,5 @@ fn main() -> cosmic::iced::Result {
config_handler,
config,
};
cosmic::applet::run::<Window>(true, flags)
cosmic::applet::run::<AppState>(true, flags)
}
10 changes: 8 additions & 2 deletions src/message.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ use crate::{
};

#[derive(Clone, Debug)]
pub enum AppMessage {
pub enum AppMsg {
ChangeConfig(Config),
TogglePopup,
ToggleQuickSettings,
@@ -18,10 +18,16 @@ pub enum AppMessage {
RetryConnectingClipboard,
Copy(Entry),
Delete(Entry),
PrivateMode(bool),
Clear,
Navigation(NavigationMessage),
Db(DbMessage),
ShowQrCode(Entry),
ReturnToClipboard,
Config(ConfigMsg),
}

#[derive(Clone, Debug)]
pub enum ConfigMsg {
PrivateMode(bool),
Horizontal(bool),
}
22 changes: 9 additions & 13 deletions src/navigation.rs
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@ pub enum NavigationMessage {
Previous,
Enter,
Quit,
Event(cosmic::iced::keyboard::key::Named),
None,
}

#[allow(clippy::collapsible_match)]
@@ -19,19 +21,13 @@ pub fn sub() -> Subscription<NavigationMessage> {
cosmic::iced::keyboard::Event::KeyPressed { key, .. } => {
match key {
cosmic::iced::keyboard::Key::Named(named) => match named {
cosmic::iced::keyboard::key::Named::Enter => {
Some(NavigationMessage::Enter)
}

cosmic::iced::keyboard::key::Named::Escape => {
Some(NavigationMessage::Quit)
}

cosmic::iced::keyboard::key::Named::ArrowDown => {
Some(NavigationMessage::Next)
}
cosmic::iced::keyboard::key::Named::ArrowUp => {
Some(NavigationMessage::Previous)
cosmic::iced::keyboard::key::Named::Enter
| cosmic::iced::keyboard::key::Named::Escape
| cosmic::iced::keyboard::key::Named::ArrowDown
| cosmic::iced::keyboard::key::Named::ArrowUp
| cosmic::iced::keyboard::key::Named::ArrowLeft
| cosmic::iced::keyboard::key::Named::ArrowRight => {
Some(NavigationMessage::Event(named))
}

/*
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ use cosmic::{app::Message, iced::Padding, iced_runtime::command::Action, Command

use crate::app::APPID;

pub fn formated_value(value: &str, max_lines: usize, max_chars: usize) -> Cow<str> {
pub fn formatted_value(value: &str, max_lines: usize, max_chars: usize) -> Cow<str> {
let value = value.trim();

if value.lines().count() <= max_lines && value.len() <= max_chars {
533 changes: 298 additions & 235 deletions src/view.rs

Large diffs are not rendered by default.

0 comments on commit 31314b8

Please sign in to comment.