mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
simplify code using macro
This commit is contained in:
parent
1991a20b21
commit
66cb359e18
1 changed files with 23 additions and 24 deletions
47
src/app.rs
47
src/app.rs
|
|
@ -42,6 +42,24 @@ enum Focus {
|
|||
Stage,
|
||||
}
|
||||
|
||||
/// allows generating code to make sure
|
||||
/// we always enumerate all components in both getter functions
|
||||
macro_rules! components {
|
||||
($self:ident, [$($element:ident),+]) => {
|
||||
fn components(& $self) -> Vec<&dyn Component> {
|
||||
vec![
|
||||
$(&$self.$element,)+
|
||||
]
|
||||
}
|
||||
|
||||
fn components_mut(&mut $self) -> Vec<&mut dyn Component> {
|
||||
vec![
|
||||
$(&mut $self.$element,)+
|
||||
]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
///
|
||||
pub struct App {
|
||||
focus: Focus,
|
||||
|
|
@ -251,6 +269,11 @@ impl App {
|
|||
|
||||
// private impls
|
||||
impl App {
|
||||
components!(
|
||||
self,
|
||||
[msg, reset, commit, help, index, index_wd, diff]
|
||||
);
|
||||
|
||||
fn update_diff(&mut self) {
|
||||
if let Some((path, is_stage)) = self.selected_path() {
|
||||
let diff_params = DiffParams(path.clone(), is_stage);
|
||||
|
|
@ -471,30 +494,6 @@ impl App {
|
|||
&& self.diff_target == DiffTarget::Stage
|
||||
}
|
||||
|
||||
fn components(&self) -> Vec<&dyn Component> {
|
||||
vec![
|
||||
&self.msg,
|
||||
&self.reset,
|
||||
&self.commit,
|
||||
&self.help,
|
||||
&self.index,
|
||||
&self.index_wd,
|
||||
&self.diff,
|
||||
]
|
||||
}
|
||||
|
||||
fn components_mut(&mut self) -> Vec<&mut dyn Component> {
|
||||
vec![
|
||||
&mut self.msg,
|
||||
&mut self.reset,
|
||||
&mut self.commit,
|
||||
&mut self.help,
|
||||
&mut self.index,
|
||||
&mut self.index_wd,
|
||||
&mut self.diff,
|
||||
]
|
||||
}
|
||||
|
||||
fn event_pump(
|
||||
ev: Event,
|
||||
components: &mut [&mut dyn Component],
|
||||
|
|
|
|||
Loading…
Reference in a new issue