Skip to content

Commit bea7edf

Browse files
author
Stephan Dilly
committed
reorder
1 parent 242319b commit bea7edf

File tree

1 file changed

+125
-125
lines changed

1 file changed

+125
-125
lines changed

src/components/commit.rs

Lines changed: 125 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -49,131 +49,6 @@ pub struct CommitComponent {
4949

5050
const FIRST_LINE_LIMIT: usize = 50;
5151

52-
impl DrawableComponent for CommitComponent {
53-
fn draw<B: Backend>(
54-
&self,
55-
f: &mut Frame<B>,
56-
rect: Rect,
57-
) -> Result<()> {
58-
if self.is_visible() {
59-
self.input.draw(f, rect)?;
60-
self.draw_branch_name(f);
61-
self.draw_warnings(f);
62-
}
63-
64-
Ok(())
65-
}
66-
}
67-
68-
impl Component for CommitComponent {
69-
fn commands(
70-
&self,
71-
out: &mut Vec<CommandInfo>,
72-
force_all: bool,
73-
) -> CommandBlocking {
74-
self.input.commands(out, force_all);
75-
76-
if self.is_visible() || force_all {
77-
out.push(CommandInfo::new(
78-
strings::commands::commit_enter(&self.key_config),
79-
self.can_commit(),
80-
true,
81-
));
82-
83-
out.push(CommandInfo::new(
84-
strings::commands::commit_amend(&self.key_config),
85-
self.can_amend(),
86-
true,
87-
));
88-
89-
out.push(CommandInfo::new(
90-
strings::commands::commit_open_editor(
91-
&self.key_config,
92-
),
93-
true,
94-
true,
95-
));
96-
}
97-
98-
visibility_blocking(self)
99-
}
100-
101-
fn event(&mut self, ev: Event) -> Result<EventState> {
102-
if self.is_visible() {
103-
if self.input.event(ev)?.is_consumed() {
104-
return Ok(EventState::Consumed);
105-
}
106-
107-
if let Event::Key(e) = ev {
108-
if e == self.key_config.enter && self.can_commit() {
109-
try_or_popup!(
110-
self,
111-
"commit error:",
112-
self.commit()
113-
);
114-
} else if e == self.key_config.commit_amend
115-
&& self.can_amend()
116-
{
117-
self.amend()?;
118-
} else if e == self.key_config.open_commit_editor {
119-
self.queue.borrow_mut().push_back(
120-
InternalEvent::OpenExternalEditor(None),
121-
);
122-
self.hide();
123-
} else {
124-
}
125-
// stop key event propagation
126-
return Ok(EventState::Consumed);
127-
}
128-
}
129-
130-
Ok(EventState::NotConsumed)
131-
}
132-
133-
fn is_visible(&self) -> bool {
134-
self.input.is_visible()
135-
}
136-
137-
fn hide(&mut self) {
138-
self.input.hide()
139-
}
140-
141-
fn show(&mut self) -> Result<()> {
142-
//only clear text if it was not a normal commit dlg before, so to preserve old commit msg that was edited
143-
if !matches!(self.mode, Mode::Normal) {
144-
self.input.clear();
145-
}
146-
147-
self.mode = Mode::Normal;
148-
149-
self.mode = if sync::repo_state(CWD)? == RepoState::Merge {
150-
let ids = sync::mergehead_ids(CWD)?;
151-
self.input.set_title(strings::commit_title_merge());
152-
self.input.set_text(sync::merge_msg(CWD)?);
153-
Mode::Merge(ids)
154-
} else {
155-
self.commit_template =
156-
get_config_string(CWD, "commit.template")
157-
.ok()
158-
.flatten()
159-
.and_then(|path| read_to_string(path).ok());
160-
161-
if self.is_empty() {
162-
if let Some(s) = &self.commit_template {
163-
self.input.set_text(s.clone());
164-
}
165-
}
166-
167-
self.input.set_title(strings::commit_title());
168-
Mode::Normal
169-
};
170-
171-
self.input.show()?;
172-
173-
Ok(())
174-
}
175-
}
176-
17752
impl CommitComponent {
17853
///
17954
pub fn new(
@@ -409,3 +284,128 @@ impl CommitComponent {
409284
Ok(())
410285
}
411286
}
287+
288+
impl DrawableComponent for CommitComponent {
289+
fn draw<B: Backend>(
290+
&self,
291+
f: &mut Frame<B>,
292+
rect: Rect,
293+
) -> Result<()> {
294+
if self.is_visible() {
295+
self.input.draw(f, rect)?;
296+
self.draw_branch_name(f);
297+
self.draw_warnings(f);
298+
}
299+
300+
Ok(())
301+
}
302+
}
303+
304+
impl Component for CommitComponent {
305+
fn commands(
306+
&self,
307+
out: &mut Vec<CommandInfo>,
308+
force_all: bool,
309+
) -> CommandBlocking {
310+
self.input.commands(out, force_all);
311+
312+
if self.is_visible() || force_all {
313+
out.push(CommandInfo::new(
314+
strings::commands::commit_enter(&self.key_config),
315+
self.can_commit(),
316+
true,
317+
));
318+
319+
out.push(CommandInfo::new(
320+
strings::commands::commit_amend(&self.key_config),
321+
self.can_amend(),
322+
true,
323+
));
324+
325+
out.push(CommandInfo::new(
326+
strings::commands::commit_open_editor(
327+
&self.key_config,
328+
),
329+
true,
330+
true,
331+
));
332+
}
333+
334+
visibility_blocking(self)
335+
}
336+
337+
fn event(&mut self, ev: Event) -> Result<EventState> {
338+
if self.is_visible() {
339+
if self.input.event(ev)?.is_consumed() {
340+
return Ok(EventState::Consumed);
341+
}
342+
343+
if let Event::Key(e) = ev {
344+
if e == self.key_config.enter && self.can_commit() {
345+
try_or_popup!(
346+
self,
347+
"commit error:",
348+
self.commit()
349+
);
350+
} else if e == self.key_config.commit_amend
351+
&& self.can_amend()
352+
{
353+
self.amend()?;
354+
} else if e == self.key_config.open_commit_editor {
355+
self.queue.borrow_mut().push_back(
356+
InternalEvent::OpenExternalEditor(None),
357+
);
358+
self.hide();
359+
} else {
360+
}
361+
// stop key event propagation
362+
return Ok(EventState::Consumed);
363+
}
364+
}
365+
366+
Ok(EventState::NotConsumed)
367+
}
368+
369+
fn is_visible(&self) -> bool {
370+
self.input.is_visible()
371+
}
372+
373+
fn hide(&mut self) {
374+
self.input.hide()
375+
}
376+
377+
fn show(&mut self) -> Result<()> {
378+
//only clear text if it was not a normal commit dlg before, so to preserve old commit msg that was edited
379+
if !matches!(self.mode, Mode::Normal) {
380+
self.input.clear();
381+
}
382+
383+
self.mode = Mode::Normal;
384+
385+
self.mode = if sync::repo_state(CWD)? == RepoState::Merge {
386+
let ids = sync::mergehead_ids(CWD)?;
387+
self.input.set_title(strings::commit_title_merge());
388+
self.input.set_text(sync::merge_msg(CWD)?);
389+
Mode::Merge(ids)
390+
} else {
391+
self.commit_template =
392+
get_config_string(CWD, "commit.template")
393+
.ok()
394+
.flatten()
395+
.and_then(|path| read_to_string(path).ok());
396+
397+
if self.is_empty() {
398+
if let Some(s) = &self.commit_template {
399+
self.input.set_text(s.clone());
400+
}
401+
}
402+
403+
self.input.set_title(strings::commit_title());
404+
Mode::Normal
405+
};
406+
407+
self.input.show()?;
408+
409+
Ok(())
410+
}
411+
}

0 commit comments

Comments
 (0)