7
7
//! - Add the module to the `declare_global_commands!` macro invocation below
8
8
//! - Implement the [`crate::command::Handler`] trait for the `Command` generated by `declare_commands!`.
9
9
10
- use ui:: popup:: keybindings_cheatsheet;
11
-
12
- use crate :: ui;
13
-
14
10
use super :: key:: { KeyMods , KeySequence } ;
11
+ use crate :: ui;
12
+ use ui:: popup:: keybindings_cheatsheet;
15
13
16
14
/// Handles commands which mutate state of the application.
17
15
///
18
16
/// A `Command` is a subset of a `Message` which can be bound to a keybinding, and
19
17
/// can therefore receive a `count`.
18
+ ///
19
+ /// You should use this as `crate::command::Handler`.
20
20
pub trait CommandHandler {
21
21
/// Handle the invoked command, mutating the `App`.
22
22
///
@@ -58,7 +58,7 @@ pub trait CommandHandler {
58
58
macro_rules! declare_commands {
59
59
(
60
60
$( #[ $Command_Attr: meta] ) *
61
- enum Command {
61
+ enum $ Command: ident {
62
62
$(
63
63
$( #[ $Keymappable_Command_Attr: meta] ) *
64
64
$Keymappable_Command: ident $( { $(
@@ -85,19 +85,13 @@ macro_rules! declare_commands {
85
85
}
86
86
) *
87
87
88
- /// A list of keybindings which exist in the app
89
- #[ derive( ferrishot_knus:: Decode , Debug , Clone ) ]
90
- pub enum KeymappableCommand {
91
- $(
92
- $Keymappable_Command( $Keymappable_Command) ,
93
- ) *
94
- }
95
-
96
- /// An action in the app
88
+ /// Contains a couple of commands, which are specific to this module.
89
+ ///
90
+ /// See [`Command`](crate::config::commands::Command) for more info.
97
91
#[ allow( clippy:: derive_partial_eq_without_eq, reason = "f32 cannot derive `Eq`" ) ]
98
92
#[ derive( Debug , Clone , PartialEq , Copy ) ]
99
93
$( #[ $Command_Attr] ) *
100
- pub enum Command {
94
+ pub enum $ Command {
101
95
$(
102
96
$( #[ $Keymappable_Command_Attr] ) *
103
97
$Keymappable_Command $(
@@ -110,7 +104,21 @@ macro_rules! declare_commands {
110
104
) *
111
105
}
112
106
107
+ /// Parses the corresponding commands in the KDL file.
108
+ ///
109
+ /// See [`KeymappableCommand`](crate::config::commands::KeymappableCommand) for more info.
110
+ #[ derive( ferrishot_knus:: Decode , Debug , Clone ) ]
111
+ pub enum KeymappableCommand {
112
+ $(
113
+ $Keymappable_Command( $Keymappable_Command) ,
114
+ ) *
115
+ }
116
+
113
117
impl KeymappableCommand {
118
+ /// # Returns
119
+ ///
120
+ /// The keys necessary to trigger the `Command`, as well as the `Command` itself.
121
+ /// This is a key-value pair which will be stored in the `KeyMap`.
114
122
pub fn action( self ) -> ( ( $crate:: config:: key:: KeySequence , $crate:: config:: key:: KeyMods ) , Command ) {
115
123
match self {
116
124
$(
0 commit comments