Skip to content

Commit

Permalink
Merge pull request #445 from squidowl/reload-config-button
Browse files Browse the repository at this point in the history
reload button in sidebar
  • Loading branch information
casperstorm authored Jul 29, 2024
2 parents 5109ec6 + 1ef0fe3 commit eb19c0c
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Added:
- Support for CTCP queries CLIENTINFO, PING, SOURCE, and VERSION
- Custom notification sounds. Use your own sounds or select from a few new built-in options. For more details, see [notification configuration](https://halloy.squidowl.org/configuration/notifications.html).
- Support DCC Send requests with spaces in the filename
- Reload config button in Sidebar

Fixed:

Expand Down
6 changes: 6 additions & 0 deletions assets/icons/fontello-config.json → assets/fontello/config.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
"css": "search-1",
"code": 59400,
"src": "entypo"
},
{
"uid": "3bd18d47a12b8709e9f4fe9ead4f7518",
"css": "arrows-ccw",
"code": 59399,
"src": "entypo"
}
]
}
2 changes: 2 additions & 0 deletions book/src/configuration/sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ show_unread_indicators = true | false
[sidebar.buttons]
file_transfer = true | false
command_bar = true | false
reload_config = true | false
```

| Key | Description | Default |
| --------------- | -------------------------------- | ------- |
| `file_transfer` | File transfer button in sidebar. | `true` |
| `command_bar` | Command bar button in sidebar. | `true` |
| `reload_config` | Reload config button in sidebar. | `true` |
3 changes: 3 additions & 0 deletions data/src/config/sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ pub struct Buttons {
pub file_transfer: bool,
#[serde(default = "default_bool_true")]
pub command_bar: bool,
#[serde(default = "default_bool_true")]
pub reload_config: bool,
}

impl Default for Buttons {
fn default() -> Self {
Buttons {
file_transfer: default_bool_true(),
command_bar: default_bool_true(),
reload_config: default_bool_true(),
}
}
}
Expand Down
Binary file modified fonts/halloy-icons.ttf
Binary file not shown.
4 changes: 4 additions & 0 deletions src/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ pub fn file_transfer<'a>() -> Text<'a> {
to_text('\u{E802}')
}

pub fn refresh<'a>() -> Text<'a> {
to_text('\u{E807}')
}

fn to_text<'a>(unicode: char) -> Text<'a> {
text(unicode.to_string())
.style(theme::text::primary)
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,11 @@ impl Halloy {
}

fn view(&self) -> Element<Message> {
let now = Instant::now();

let screen = match &self.screen {
Screen::Dashboard(dashboard) => dashboard
.view(&self.clients, &self.version, &self.config, &self.theme)
.view(now, &self.clients, &self.version, &self.config, &self.theme)
.map(Message::Dashboard),
Screen::Help(help) => help.view().map(Message::Help),
Screen::Welcome(welcome) => welcome.view().map(Message::Welcome),
Expand Down
5 changes: 5 additions & 0 deletions src/screen/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ impl Dashboard {
None,
);
}
sidebar::Event::ReloadConfigFile => {
return (Task::none(), Some(Event::ReloadConfiguration));
}
}
}
Message::SelectedText(contents) => {
Expand Down Expand Up @@ -582,6 +585,7 @@ impl Dashboard {

pub fn view<'a>(
&'a self,
now: Instant,
clients: &'a client::Map,
version: &'a Version,
config: &'a Config,
Expand Down Expand Up @@ -618,6 +622,7 @@ impl Dashboard {
let side_menu = self
.side_menu
.view(
now,
clients,
&self.history,
&self.panes,
Expand Down
37 changes: 36 additions & 1 deletion src/screen/dashboard/sidebar.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::{Duration, Instant};

use data::dashboard::DefaultAction;
use data::{file_transfer, history, Buffer};
use iced::widget::{
Expand All @@ -19,6 +21,7 @@ pub enum Message {
Leave(Buffer),
ToggleFileTransfers,
ToggleCommandBar,
ReloadConfigFile,
}

#[derive(Debug, Clone)]
Expand All @@ -30,16 +33,21 @@ pub enum Event {
Leave(Buffer),
ToggleFileTransfers,
ToggleCommandBar,
ReloadConfigFile,
}

#[derive(Clone)]
pub struct Sidebar {
hidden: bool,
timestamp: Option<Instant>,
}

impl Sidebar {
pub fn new() -> Self {
Self { hidden: false }
Self {
hidden: false,
timestamp: None,
}
}

pub fn toggle_visibility(&mut self) {
Expand All @@ -55,11 +63,16 @@ impl Sidebar {
Message::Leave(buffer) => Event::Leave(buffer),
Message::ToggleFileTransfers => Event::ToggleFileTransfers,
Message::ToggleCommandBar => Event::ToggleCommandBar,
Message::ReloadConfigFile => {
self.timestamp = Some(Instant::now());
Event::ReloadConfigFile
}
}
}

pub fn view<'a>(
&'a self,
now: Instant,
clients: &data::client::Map,
history: &'a history::Manager,
panes: &pane_grid::State<Pane>,
Expand Down Expand Up @@ -139,6 +152,28 @@ impl Sidebar {

let mut menu_buttons = row![].spacing(1).padding(padding::bottom(4));

if config.buttons.reload_config {
let icon = self
.timestamp
.filter(|&timestamp| now.saturating_duration_since(timestamp) < Duration::new(1, 0))
.map_or_else(|| icon::refresh().style(theme::text::primary), |_| icon::checkmark().style(theme::text::success));

let button = button(center(icon))
.on_press(Message::ReloadConfigFile)
.padding(5)
.width(22)
.height(22)
.style(theme::button::side_menu);

let button_with_tooltip = tooltip(
button,
show_tooltips.then_some("Reload config file"),
tooltip::Position::Top,
);

menu_buttons = menu_buttons.push(button_with_tooltip);
}

if config.buttons.command_bar {
let button = button(center(icon::search()))
.on_press(Message::ToggleCommandBar)
Expand Down

0 comments on commit eb19c0c

Please sign in to comment.