Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: shortcut to set priority are now hardcoded #533

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@
self.get_context()?;
let task_uuids = self.selected_task_uuids();
if self.current_selection_uuid.is_none() && self.current_selection_id.is_none() && task_uuids.len() == 1 {
if let Some(uuid) = task_uuids.get(0) {

Check failure on line 1307 in src/app.rs

View workflow job for this annotation

GitHub Actions / Clippy

accessing first element with `task_uuids.get(0)`
self.current_selection_uuid = Some(*uuid);
}
}
Expand Down Expand Up @@ -1794,7 +1794,7 @@
};

if task_uuids.len() == 1 {
if let Some(uuid) = task_uuids.get(0) {

Check failure on line 1797 in src/app.rs

View workflow job for this annotation

GitHub Actions / Clippy

accessing first element with `task_uuids.get(0)`
self.current_selection_uuid = Some(*uuid);
}
}
Expand Down Expand Up @@ -1904,7 +1904,7 @@
};

if task_uuids.len() == 1 {
if let Some(uuid) = task_uuids.get(0) {

Check failure on line 1907 in src/app.rs

View workflow job for this annotation

GitHub Actions / Clippy

accessing first element with `task_uuids.get(0)`
self.current_selection_uuid = Some(*uuid);
}
}
Expand Down Expand Up @@ -1957,7 +1957,7 @@
};

if task_uuids.len() == 1 {
if let Some(uuid) = task_uuids.get(0) {

Check failure on line 1960 in src/app.rs

View workflow job for this annotation

GitHub Actions / Clippy

accessing first element with `task_uuids.get(0)`
self.current_selection_uuid = Some(*uuid);
}
}
Expand Down Expand Up @@ -2009,7 +2009,7 @@
};

if task_uuids.len() == 1 {
if let Some(uuid) = task_uuids.get(0) {

Check failure on line 2012 in src/app.rs

View workflow job for this annotation

GitHub Actions / Clippy

accessing first element with `task_uuids.get(0)`
self.current_selection_uuid = Some(*uuid);
}
}
Expand Down Expand Up @@ -2096,7 +2096,7 @@
}

if task_uuids.len() == 1 {
if let Some(uuid) = task_uuids.get(0) {

Check failure on line 2099 in src/app.rs

View workflow job for this annotation

GitHub Actions / Clippy

accessing first element with `task_uuids.get(0)`
self.current_selection_uuid = Some(*uuid);
}
}
Expand Down Expand Up @@ -2136,7 +2136,7 @@
}

if task_uuids.len() == 1 {
if let Some(uuid) = task_uuids.get(0) {

Check failure on line 2139 in src/app.rs

View workflow job for this annotation

GitHub Actions / Clippy

accessing first element with `task_uuids.get(0)`
self.current_selection_uuid = Some(*uuid);
}
}
Expand Down Expand Up @@ -2202,6 +2202,37 @@
r
}

pub fn task_priority(&mut self, priority: &str) -> Result<(), String> {
if self.tasks.is_empty() {
return Ok(());
}
let mut priority_arg = String::from("priority:");
priority_arg.push_str(priority);
let task_uuids = self.selected_task_uuids();
let mut cmd = std::process::Command::new("task");
cmd
.arg("rc.bulk=0")
.arg("rc.confirmation=off")
.arg("rc.dependency.confirmation=off")
.arg("rc.recurrence.confirmation=off")
.arg("modify")
.arg(&priority_arg);
for task_uuid in &task_uuids {
cmd.arg(task_uuid.to_string());
}
let output = cmd.output();
let r = match output {
Ok(_) => Ok(()),
Err(_) => Err(format!(
"Cannot run `task modify priority` for task `{}`. Check documentation for more information",
task_uuids.iter().map(ToString::to_string).collect::<Vec<String>>().join(" ")
)),
};
self.current_selection_uuid = None;
self.current_selection_id = None;
r
}

pub fn task_undo(&mut self) -> Result<(), String> {
let output = std::process::Command::new("task").arg("rc.confirmation=off").arg("undo").output();

Expand Down Expand Up @@ -2697,6 +2728,38 @@
self.mode = Mode::Tasks(Action::Error);
}
}
} else if input == self.keyconfig.priority_h {
match self.task_priority("H") {
Ok(_) => self.update(true).await?,
Err(e) => {
self.error = Some(e);
self.mode = Mode::Tasks(Action::Error);
}
}
} else if input == self.keyconfig.priority_m {
match self.task_priority("M") {
Ok(_) => self.update(true).await?,
Err(e) => {
self.error = Some(e);
self.mode = Mode::Tasks(Action::Error);
}
}
} else if input == self.keyconfig.priority_l {
match self.task_priority("L") {
Ok(_) => self.update(true).await?,
Err(e) => {
self.error = Some(e);
self.mode = Mode::Tasks(Action::Error);
}
}
} else if input == self.keyconfig.priority_n {
match self.task_priority("") {
Ok(_) => self.update(true).await?,
Err(e) => {
self.error = Some(e);
self.mode = Mode::Tasks(Action::Error);
}
}
} else if input == self.keyconfig.shortcut2 {
match self.task_shortcut(2).await {
Ok(_) => self.update(true).await?,
Expand Down
8 changes: 8 additions & 0 deletions src/keyconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ pub struct KeyConfig {
pub context_menu: KeyCode,
pub next_tab: KeyCode,
pub previous_tab: KeyCode,
pub priority_h: KeyCode,
pub priority_m: KeyCode,
pub priority_l: KeyCode,
pub priority_n: KeyCode,
pub shortcut0: KeyCode,
pub shortcut1: KeyCode,
pub shortcut2: KeyCode,
Expand Down Expand Up @@ -77,6 +81,10 @@ impl Default for KeyConfig {
context_menu: KeyCode::Char('c'),
next_tab: KeyCode::Char(']'),
previous_tab: KeyCode::Char('['),
priority_h: KeyCode::Char('H'),
priority_m: KeyCode::Char('M'),
priority_l: KeyCode::Char('L'),
priority_n: KeyCode::Char('N'),
shortcut0: KeyCode::Char('0'),
shortcut1: KeyCode::Char('1'),
shortcut2: KeyCode::Char('2'),
Expand Down
Loading