mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-25 17:57:19 +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.show-info=true
|
||||||
uda.taskwarrior-tui.task-report.looping=true
|
uda.taskwarrior-tui.task-report.looping=true
|
||||||
uda.taskwarrior-tui.task-report.jump-on-task-add=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.context.active=black on rgb444
|
||||||
uda.taskwarrior-tui.style.calendar.title=black on rgb444
|
uda.taskwarrior-tui.style.calendar.title=black on rgb444
|
||||||
uda.taskwarrior-tui.task-report.next.filter=$(task show report.next.filter)
|
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,
|
TaskError,
|
||||||
TaskContextMenu,
|
TaskContextMenu,
|
||||||
TaskJump,
|
TaskJump,
|
||||||
|
TaskDeletePrompt,
|
||||||
Calendar,
|
Calendar,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,6 +173,7 @@ pub struct TaskwarriorTuiApp {
|
||||||
pub context_table_state: TableState,
|
pub context_table_state: TableState,
|
||||||
pub current_context_filter: String,
|
pub current_context_filter: String,
|
||||||
pub current_context: String,
|
pub current_context: String,
|
||||||
|
pub delete: LineBuffer,
|
||||||
pub command: LineBuffer,
|
pub command: LineBuffer,
|
||||||
pub filter: LineBuffer,
|
pub filter: LineBuffer,
|
||||||
pub modify: LineBuffer,
|
pub modify: LineBuffer,
|
||||||
|
@ -244,6 +246,7 @@ impl TaskwarriorTuiApp {
|
||||||
current_selection_id: None,
|
current_selection_id: None,
|
||||||
current_context_filter: "".to_string(),
|
current_context_filter: "".to_string(),
|
||||||
current_context: "".to_string(),
|
current_context: "".to_string(),
|
||||||
|
delete: LineBuffer::with_capacity(MAX_LINE),
|
||||||
command: LineBuffer::with_capacity(MAX_LINE),
|
command: LineBuffer::with_capacity(MAX_LINE),
|
||||||
filter: LineBuffer::with_capacity(MAX_LINE),
|
filter: LineBuffer::with_capacity(MAX_LINE),
|
||||||
modify: LineBuffer::with_capacity(MAX_LINE),
|
modify: LineBuffer::with_capacity(MAX_LINE),
|
||||||
|
@ -313,6 +316,7 @@ impl TaskwarriorTuiApp {
|
||||||
| AppMode::TaskAdd
|
| AppMode::TaskAdd
|
||||||
| AppMode::TaskAnnotate
|
| AppMode::TaskAnnotate
|
||||||
| AppMode::TaskContextMenu
|
| AppMode::TaskContextMenu
|
||||||
|
| AppMode::TaskDeletePrompt
|
||||||
| AppMode::TaskError
|
| AppMode::TaskError
|
||||||
| AppMode::TaskHelpPopup
|
| AppMode::TaskHelpPopup
|
||||||
| AppMode::TaskSubprocess
|
| AppMode::TaskSubprocess
|
||||||
|
@ -565,6 +569,29 @@ impl TaskwarriorTuiApp {
|
||||||
);
|
);
|
||||||
self.draw_context_menu(f, 80, 50);
|
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");
|
panic!("Reached unreachable code. Something went wrong");
|
||||||
}
|
}
|
||||||
|
@ -2097,11 +2124,18 @@ impl TaskwarriorTuiApp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if input == self.keyconfig.delete {
|
} else if input == self.keyconfig.delete {
|
||||||
match self.task_delete() {
|
if self.config.uda_task_report_prompt_on_delete {
|
||||||
Ok(_) => self.update(true)?,
|
self.mode = AppMode::TaskDeletePrompt;
|
||||||
Err(e) => {
|
if self.task_current().is_none() {
|
||||||
self.mode = AppMode::TaskError;
|
self.mode = AppMode::TaskReport;
|
||||||
self.error = e;
|
}
|
||||||
|
} 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 {
|
} else if input == self.keyconfig.start_stop {
|
||||||
|
@ -2737,6 +2771,25 @@ impl TaskwarriorTuiApp {
|
||||||
self.dirty = true;
|
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::TaskError => self.mode = AppMode::TaskReport,
|
||||||
AppMode::Calendar => {
|
AppMode::Calendar => {
|
||||||
if input == self.keyconfig.quit || input == Key::Ctrl('c') {
|
if input == self.keyconfig.quit || input == Key::Ctrl('c') {
|
||||||
|
|
|
@ -65,6 +65,7 @@ pub struct Config {
|
||||||
pub uda_shortcuts: Vec<String>,
|
pub uda_shortcuts: Vec<String>,
|
||||||
pub uda_background_process: String,
|
pub uda_background_process: String,
|
||||||
pub uda_background_process_period: usize,
|
pub uda_background_process_period: usize,
|
||||||
|
pub uda_task_report_prompt_on_delete: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
@ -109,6 +110,7 @@ impl Config {
|
||||||
let uda_style_context_active = uda_style_context_active.unwrap_or_default();
|
let uda_style_context_active = uda_style_context_active.unwrap_or_default();
|
||||||
let uda_style_report_completion_pane =
|
let uda_style_report_completion_pane =
|
||||||
uda_style_report_completion_pane.unwrap_or_else(|| Style::default().bg(Color::Rgb(223, 223, 223)));
|
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 {
|
Ok(Self {
|
||||||
enabled,
|
enabled,
|
||||||
|
@ -141,6 +143,7 @@ impl Config {
|
||||||
uda_shortcuts,
|
uda_shortcuts,
|
||||||
uda_background_process,
|
uda_background_process,
|
||||||
uda_background_process_period,
|
uda_background_process_period,
|
||||||
|
uda_task_report_prompt_on_delete,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,6 +451,13 @@ impl Config {
|
||||||
.unwrap_or(true)
|
.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 {
|
fn get_uda_selection_indicator(data: &str) -> String {
|
||||||
let indicator = Self::get_config("uda.taskwarrior-tui.selection.indicator", data);
|
let indicator = Self::get_config("uda.taskwarrior-tui.selection.indicator", data);
|
||||||
match indicator {
|
match indicator {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue