mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-25 08:47:18 +02:00
Merge pull request #48 from kdheepak/delete-prompt-and-change-delete-keybinding
Add delete prompt
This commit is contained in:
commit
72639f1b7a
3 changed files with 69 additions and 5 deletions
|
@ -18,6 +18,7 @@ uda.taskwarrior-tui.calendar.months-per-row=4
|
|||
uda.taskwarrior-tui.task-report.show-info=true
|
||||
uda.taskwarrior-tui.task-report.looping=true
|
||||
uda.taskwarrior-tui.task-report.jump-on-task-add=true
|
||||
uda.taskwarrior-tui.task-report.prompt-on-delete=false
|
||||
uda.taskwarrior-tui.style.context.active=black on rgb444
|
||||
uda.taskwarrior-tui.style.calendar.title=black on rgb444
|
||||
uda.taskwarrior-tui.task-report.next.filter=$(task show report.next.filter)
|
||||
|
|
63
src/app.rs
63
src/app.rs
|
@ -162,6 +162,7 @@ pub enum AppMode {
|
|||
TaskError,
|
||||
TaskContextMenu,
|
||||
TaskJump,
|
||||
TaskDeletePrompt,
|
||||
Calendar,
|
||||
}
|
||||
|
||||
|
@ -172,6 +173,7 @@ pub struct TaskwarriorTuiApp {
|
|||
pub context_table_state: TableState,
|
||||
pub current_context_filter: String,
|
||||
pub current_context: String,
|
||||
pub delete: LineBuffer,
|
||||
pub command: LineBuffer,
|
||||
pub filter: LineBuffer,
|
||||
pub modify: LineBuffer,
|
||||
|
@ -244,6 +246,7 @@ impl TaskwarriorTuiApp {
|
|||
current_selection_id: None,
|
||||
current_context_filter: "".to_string(),
|
||||
current_context: "".to_string(),
|
||||
delete: LineBuffer::with_capacity(MAX_LINE),
|
||||
command: LineBuffer::with_capacity(MAX_LINE),
|
||||
filter: LineBuffer::with_capacity(MAX_LINE),
|
||||
modify: LineBuffer::with_capacity(MAX_LINE),
|
||||
|
@ -313,6 +316,7 @@ impl TaskwarriorTuiApp {
|
|||
| AppMode::TaskAdd
|
||||
| AppMode::TaskAnnotate
|
||||
| AppMode::TaskContextMenu
|
||||
| AppMode::TaskDeletePrompt
|
||||
| AppMode::TaskError
|
||||
| AppMode::TaskHelpPopup
|
||||
| AppMode::TaskSubprocess
|
||||
|
@ -565,6 +569,29 @@ impl TaskwarriorTuiApp {
|
|||
);
|
||||
self.draw_context_menu(f, 80, 50);
|
||||
}
|
||||
AppMode::TaskDeletePrompt => {
|
||||
let label = if task_ids.len() > 1 {
|
||||
format!("Delete Tasks {}?", task_ids.join(","))
|
||||
} else {
|
||||
format!("Delete Task {}?", task_ids.join(","))
|
||||
};
|
||||
let x = match self.keyconfig.delete {
|
||||
Key::Char(c) => c.to_string(),
|
||||
_ => "Enter".to_string(),
|
||||
};
|
||||
let q = match self.keyconfig.quit {
|
||||
Key::Char(c) => c.to_string(),
|
||||
_ => "Esc".to_string(),
|
||||
};
|
||||
self.draw_command(
|
||||
f,
|
||||
rects[1],
|
||||
&format!("Press <{}> to confirm or <{}> to abort.", x, q),
|
||||
Span::styled(label, Style::default().add_modifier(Modifier::BOLD)),
|
||||
0,
|
||||
false,
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
panic!("Reached unreachable code. Something went wrong");
|
||||
}
|
||||
|
@ -2097,11 +2124,18 @@ impl TaskwarriorTuiApp {
|
|||
}
|
||||
}
|
||||
} else if input == self.keyconfig.delete {
|
||||
match self.task_delete() {
|
||||
Ok(_) => self.update(true)?,
|
||||
Err(e) => {
|
||||
self.mode = AppMode::TaskError;
|
||||
self.error = e;
|
||||
if self.config.uda_task_report_prompt_on_delete {
|
||||
self.mode = AppMode::TaskDeletePrompt;
|
||||
if self.task_current().is_none() {
|
||||
self.mode = AppMode::TaskReport;
|
||||
}
|
||||
} else {
|
||||
match self.task_delete() {
|
||||
Ok(_) => self.update(true)?,
|
||||
Err(e) => {
|
||||
self.mode = AppMode::TaskError;
|
||||
self.error = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if input == self.keyconfig.start_stop {
|
||||
|
@ -2737,6 +2771,25 @@ impl TaskwarriorTuiApp {
|
|||
self.dirty = true;
|
||||
}
|
||||
},
|
||||
AppMode::TaskDeletePrompt => {
|
||||
if input == self.keyconfig.delete || input == Key::Char('\n') {
|
||||
match self.task_delete() {
|
||||
Ok(_) => {
|
||||
self.mode = AppMode::TaskReport;
|
||||
self.update(true)?;
|
||||
}
|
||||
Err(e) => {
|
||||
self.mode = AppMode::TaskError;
|
||||
self.error = e;
|
||||
}
|
||||
}
|
||||
} else if input == self.keyconfig.quit || input == Key::Esc {
|
||||
self.delete.update("", 0);
|
||||
self.mode = AppMode::TaskReport;
|
||||
} else {
|
||||
handle_movement(&mut self.command, input);
|
||||
}
|
||||
}
|
||||
AppMode::TaskError => self.mode = AppMode::TaskReport,
|
||||
AppMode::Calendar => {
|
||||
if input == self.keyconfig.quit || input == Key::Ctrl('c') {
|
||||
|
|
|
@ -65,6 +65,7 @@ pub struct Config {
|
|||
pub uda_shortcuts: Vec<String>,
|
||||
pub uda_background_process: String,
|
||||
pub uda_background_process_period: usize,
|
||||
pub uda_task_report_prompt_on_delete: bool,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
@ -109,6 +110,7 @@ impl Config {
|
|||
let uda_style_context_active = uda_style_context_active.unwrap_or_default();
|
||||
let uda_style_report_completion_pane =
|
||||
uda_style_report_completion_pane.unwrap_or_else(|| Style::default().bg(Color::Rgb(223, 223, 223)));
|
||||
let uda_task_report_prompt_on_delete = Self::get_uda_task_report_prompt_on_delete(data);
|
||||
|
||||
Ok(Self {
|
||||
enabled,
|
||||
|
@ -141,6 +143,7 @@ impl Config {
|
|||
uda_shortcuts,
|
||||
uda_background_process,
|
||||
uda_background_process_period,
|
||||
uda_task_report_prompt_on_delete,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -448,6 +451,13 @@ impl Config {
|
|||
.unwrap_or(true)
|
||||
}
|
||||
|
||||
fn get_uda_task_report_prompt_on_delete(data: &str) -> bool {
|
||||
Self::get_config("uda.taskwarrior-tui.task-report.prompt-on-delete", data)
|
||||
.unwrap_or_default()
|
||||
.get_bool()
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn get_uda_selection_indicator(data: &str) -> String {
|
||||
let indicator = Self::get_config("uda.taskwarrior-tui.selection.indicator", data);
|
||||
match indicator {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue