mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
parent
dddb35ac15
commit
bb92067b19
3 changed files with 48 additions and 21 deletions
|
|
@ -88,6 +88,12 @@ impl TextInputComponent {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
pub fn set_input_type(&mut self, input_type: InputType) {
|
||||||
|
self.clear();
|
||||||
|
self.input_type = input_type;
|
||||||
|
}
|
||||||
|
|
||||||
/// Clear the `msg`.
|
/// Clear the `msg`.
|
||||||
pub fn clear(&mut self) {
|
pub fn clear(&mut self) {
|
||||||
self.msg.take();
|
self.msg.take();
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,13 @@ impl Component for TagCommitPopup {
|
||||||
if self.is_visible() || force_all {
|
if self.is_visible() || force_all {
|
||||||
self.input.commands(out, force_all);
|
self.input.commands(out, force_all);
|
||||||
|
|
||||||
|
let is_annotation_mode =
|
||||||
|
matches!(self.mode, Mode::Annotation { .. });
|
||||||
|
|
||||||
out.push(CommandInfo::new(
|
out.push(CommandInfo::new(
|
||||||
strings::commands::tag_commit_confirm_msg(
|
strings::commands::tag_commit_confirm_msg(
|
||||||
&self.key_config,
|
&self.key_config,
|
||||||
|
is_annotation_mode,
|
||||||
),
|
),
|
||||||
self.is_valid_tag(),
|
self.is_valid_tag(),
|
||||||
true,
|
true,
|
||||||
|
|
@ -66,37 +70,34 @@ impl Component for TagCommitPopup {
|
||||||
|
|
||||||
fn event(&mut self, ev: &Event) -> Result<EventState> {
|
fn event(&mut self, ev: &Event) -> Result<EventState> {
|
||||||
if self.is_visible() {
|
if self.is_visible() {
|
||||||
if self.input.event(ev)?.is_consumed() {
|
|
||||||
return Ok(EventState::Consumed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Event::Key(e) = ev {
|
if let Event::Key(e) = ev {
|
||||||
if key_match(e, self.key_config.keys.enter)
|
let is_annotation_mode =
|
||||||
|
matches!(self.mode, Mode::Annotation { .. });
|
||||||
|
|
||||||
|
if !is_annotation_mode
|
||||||
|
&& key_match(e, self.key_config.keys.enter)
|
||||||
&& self.is_valid_tag()
|
&& self.is_valid_tag()
|
||||||
{
|
{
|
||||||
try_or_popup!(self, "tag error:", self.tag());
|
try_or_popup!(self, "tag error:", self.tag());
|
||||||
|
return Ok(EventState::Consumed);
|
||||||
|
}
|
||||||
|
if is_annotation_mode
|
||||||
|
&& key_match(e, self.key_config.keys.commit)
|
||||||
|
{
|
||||||
|
try_or_popup!(self, "tag error:", self.tag());
|
||||||
|
return Ok(EventState::Consumed);
|
||||||
} else if key_match(
|
} else if key_match(
|
||||||
e,
|
e,
|
||||||
self.key_config.keys.tag_annotate,
|
self.key_config.keys.tag_annotate,
|
||||||
) && self.is_valid_tag()
|
) && self.is_valid_tag()
|
||||||
{
|
{
|
||||||
let tag_name: String =
|
self.start_annotate_mode();
|
||||||
self.input.get_text().into();
|
return Ok(EventState::Consumed);
|
||||||
|
|
||||||
self.input.clear();
|
|
||||||
self.input.set_title(
|
|
||||||
strings::tag_popup_annotation_title(
|
|
||||||
&tag_name,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
self.input.set_default_msg(
|
|
||||||
strings::tag_popup_annotation_msg(),
|
|
||||||
);
|
|
||||||
self.mode = Mode::Annotation { tag_name };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(EventState::Consumed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.input.event(ev)?;
|
||||||
|
return Ok(EventState::Consumed);
|
||||||
}
|
}
|
||||||
Ok(EventState::NotConsumed)
|
Ok(EventState::NotConsumed)
|
||||||
}
|
}
|
||||||
|
|
@ -111,6 +112,7 @@ impl Component for TagCommitPopup {
|
||||||
|
|
||||||
fn show(&mut self) -> Result<()> {
|
fn show(&mut self) -> Result<()> {
|
||||||
self.mode = Mode::Name;
|
self.mode = Mode::Name;
|
||||||
|
self.input.set_input_type(InputType::Singleline);
|
||||||
self.input.set_title(strings::tag_popup_name_title());
|
self.input.set_title(strings::tag_popup_name_title());
|
||||||
self.input.set_default_msg(strings::tag_popup_name_msg());
|
self.input.set_default_msg(strings::tag_popup_name_msg());
|
||||||
self.input.show()?;
|
self.input.show()?;
|
||||||
|
|
@ -166,6 +168,7 @@ impl TagCommitPopup {
|
||||||
.flatten()
|
.flatten()
|
||||||
.and_then(|val| val.parse::<bool>().ok())
|
.and_then(|val| val.parse::<bool>().ok())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
anyhow::ensure!(!gpgsign, "config tag.gpgsign=true detected.\ngpg signing not supported.\ndeactivate in your repo/gitconfig to be able to tag without signing.");
|
anyhow::ensure!(!gpgsign, "config tag.gpgsign=true detected.\ngpg signing not supported.\ndeactivate in your repo/gitconfig to be able to tag without signing.");
|
||||||
|
|
||||||
let (tag_name, tag_annotation) = self.tag_info();
|
let (tag_name, tag_annotation) = self.tag_info();
|
||||||
|
|
@ -201,4 +204,17 @@ impl TagCommitPopup {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn start_annotate_mode(&mut self) {
|
||||||
|
let tag_name: String = self.input.get_text().into();
|
||||||
|
|
||||||
|
self.input.clear();
|
||||||
|
self.input.set_input_type(InputType::Multiline);
|
||||||
|
self.input.set_title(strings::tag_popup_annotation_title(
|
||||||
|
&tag_name,
|
||||||
|
));
|
||||||
|
self.input
|
||||||
|
.set_default_msg(strings::tag_popup_annotation_msg());
|
||||||
|
self.mode = Mode::Annotation { tag_name };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1423,11 +1423,16 @@ pub mod commands {
|
||||||
}
|
}
|
||||||
pub fn tag_commit_confirm_msg(
|
pub fn tag_commit_confirm_msg(
|
||||||
key_config: &SharedKeyConfig,
|
key_config: &SharedKeyConfig,
|
||||||
|
is_annotation_mode: bool,
|
||||||
) -> CommandText {
|
) -> CommandText {
|
||||||
CommandText::new(
|
CommandText::new(
|
||||||
format!(
|
format!(
|
||||||
"Tag [{}]",
|
"Tag [{}]",
|
||||||
key_config.get_hint(key_config.keys.enter),
|
key_config.get_hint(if is_annotation_mode {
|
||||||
|
key_config.keys.commit
|
||||||
|
} else {
|
||||||
|
key_config.keys.enter
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
"tag commit",
|
"tag commit",
|
||||||
CMD_GROUP_LOG,
|
CMD_GROUP_LOG,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue