Skip to content

Commit

Permalink
chore: Clean up commands
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed May 13, 2024
1 parent 112ff52 commit 0d68d0e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
22 changes: 12 additions & 10 deletions src/global_defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ pub mod GlobalDefaults {

use crate::state::{Channel, EditorCommands, EditorView, KeyboardShortcuts, RadioAppState};

use super::{OpenSettingsCommand, SplitPanelCommand, ToggleCommander, ToggleFocus};
use super::{
OpenSettingsCommand, SplitPanelCommand, ToggleCommanderCommand, ToggleFocusCommand,
};

pub fn init(
keyboard_shorcuts: &mut KeyboardShortcuts,
Expand All @@ -18,8 +20,8 @@ pub mod GlobalDefaults {
) {
// Register Commands
commands.register(SplitPanelCommand(radio_app_state));
commands.register(ToggleCommander(radio_app_state));
commands.register(ToggleFocus(radio_app_state));
commands.register(ToggleCommanderCommand(radio_app_state));
commands.register(ToggleFocusCommand(radio_app_state));
commands.register(OpenSettingsCommand(radio_app_state));

// Register Shortcuts
Expand All @@ -32,7 +34,7 @@ pub mod GlobalDefaults {
match data.code {
// Pressing `Esc`
Code::Escape => {
commands.trigger(ToggleCommander::id());
commands.trigger(ToggleCommanderCommand::id());
}
// Pressing `Alt E`
Code::KeyE if is_pressing_alt => {
Expand Down Expand Up @@ -84,15 +86,15 @@ impl EditorCommand for SplitPanelCommand {
}

#[derive(Clone)]
pub struct ToggleCommander(pub RadioAppState);
pub struct ToggleCommanderCommand(pub RadioAppState);

impl ToggleCommander {
impl ToggleCommanderCommand {
pub fn id() -> &'static str {
"toggle-commander"
}
}

impl EditorCommand for ToggleCommander {
impl EditorCommand for ToggleCommanderCommand {
fn is_visible(&self) -> bool {
// It doesn't make sense to show this command in the Commander.
false
Expand Down Expand Up @@ -122,15 +124,15 @@ impl EditorCommand for ToggleCommander {
}

#[derive(Clone)]
pub struct ToggleFocus(pub RadioAppState);
pub struct ToggleFocusCommand(pub RadioAppState);

impl ToggleFocus {
impl ToggleFocusCommand {
pub fn id() -> &'static str {
"toggle-focus"
}
}

impl EditorCommand for ToggleFocus {
impl EditorCommand for ToggleFocusCommand {
fn matches(&self, input: &str) -> bool {
self.text().to_lowercase().contains(&input.to_lowercase())
}
Expand Down
12 changes: 6 additions & 6 deletions src/tabs/editor/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use crate::{
use crate::tabs::editor::utils::AppStateEditorUtils;

#[derive(Clone)]
pub struct IncreaseFontSize(pub RadioAppState);
pub struct IncreaseFontSizeCommand(pub RadioAppState);

impl IncreaseFontSize {
impl IncreaseFontSizeCommand {
pub fn id() -> &'static str {
"increase-editor-font-size"
}
}

impl EditorCommand for IncreaseFontSize {
impl EditorCommand for IncreaseFontSizeCommand {
fn matches(&self, input: &str) -> bool {
self.text().to_lowercase().contains(&input.to_lowercase())
}
Expand All @@ -39,15 +39,15 @@ impl EditorCommand for IncreaseFontSize {
}

#[derive(Clone)]
pub struct DecreaseFontSize(pub RadioAppState);
pub struct DecreaseFontSizeCommand(pub RadioAppState);

impl DecreaseFontSize {
impl DecreaseFontSizeCommand {
pub fn id() -> &'static str {
"decrease-editor-font-size"
}
}

impl EditorCommand for DecreaseFontSize {
impl EditorCommand for DecreaseFontSizeCommand {
fn matches(&self, input: &str) -> bool {
self.text().to_lowercase().contains(&input.to_lowercase())
}
Expand Down
10 changes: 5 additions & 5 deletions src/tabs/editor/editor_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use freya::prelude::*;
use skia_safe::textlayout::FontCollection;

use super::{
commands::{DecreaseFontSize, IncreaseFontSize, SaveFileCommand},
commands::{DecreaseFontSizeCommand, IncreaseFontSizeCommand, SaveFileCommand},
editor_data::{EditorData, EditorType},
editor_ui::EditorUi,
};
Expand Down Expand Up @@ -95,8 +95,8 @@ impl EditorTab {
radio_app_state: RadioAppState,
) {
// Register Commands
commands.register(IncreaseFontSize(radio_app_state));
commands.register(DecreaseFontSize(radio_app_state));
commands.register(IncreaseFontSizeCommand(radio_app_state));
commands.register(DecreaseFontSizeCommand(radio_app_state));
commands.register(SaveFileCommand(radio_app_state));

// Register Shortcuts
Expand All @@ -109,11 +109,11 @@ impl EditorTab {
match data.code {
// Pressing `Alt +`
_ if is_pressing_alt && data.key == Key::Character("+".to_string()) => {
commands.trigger(IncreaseFontSize::id());
commands.trigger(IncreaseFontSizeCommand::id());
}
// Pressing `Alt -`
_ if is_pressing_alt && data.key == Key::Character("-".to_string()) => {
commands.trigger(DecreaseFontSize::id());
commands.trigger(DecreaseFontSizeCommand::id());
}
// Pressing `Ctrl S`
Code::KeyS if is_pressing_ctrl => {
Expand Down

0 comments on commit 0d68d0e

Please sign in to comment.