From 85055c39aa924acf77143a3fc44ee5034849d322 Mon Sep 17 00:00:00 2001 From: Filip Makowski Date: Sun, 11 Jun 2017 19:35:02 +0200 Subject: [PATCH] Added "Delete on import" setting, false by default. --- taskwarrior/taskwarrior.qml | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/taskwarrior/taskwarrior.qml b/taskwarrior/taskwarrior.qml index 447cf0a..0544795 100644 --- a/taskwarrior/taskwarrior.qml +++ b/taskwarrior/taskwarrior.qml @@ -8,6 +8,7 @@ import QOwnNotesTypes 1.0 QtObject { property string taskPath; property bool verbose; + property bool deleteOnImport; property variant settingsVariables: [ { @@ -23,6 +24,13 @@ QtObject { "description": "Should the script log every action?", "type": "boolean", "default": false + }, + { + "identifier": "deleteOnImport", + "name": "Delete on import", + "description": "Delete tasks on import?", + "type": "boolean", + "default": false } ]; @@ -195,8 +203,8 @@ QtObject { var result = script.startSynchronousProcess(taskPath, [ "pro.is:" + concatenatedProjectName, - "rc.report.next.columns=description.desc", - "rc.report.next.labels=Desc" + "rc.report.next.columns=id,description.desc", + "rc.report.next.labels=ID,Desc" ], ""); if (result) { @@ -226,9 +234,22 @@ QtObject { tasksSeparated.splice(tasksSeparated.length - 1, 1); // removing "X tasks" tasksSeparated.splice(tasksSeparated.length - 1, 1); // removing "" - tasksSeparated.forEach( function(taskDesc){ - script.noteTextEditWrite("* " + taskDesc + "\n"); + var taskIds = []; + tasksSeparated.forEach( function(task){ + var taskParamsRegexp = /(\d+)[\s*]?(.+)?[\s*]?/i; + var fetchTaskParams = taskParamsRegexp.exec(task); + logIfVerbose("Extracted data from task: ID " + fetchTaskParams[1] + " Desc: " + fetchTaskParams[2]); + script.noteTextEditWrite("* " + fetchTaskParams[2] + "\n"); + taskIds.push(fetchTaskParams[1]); }); + + if (deleteOnImport) { + script.startDetachedProcess(taskPath, + [ + taskIds.join(' '), + "delete" + ]); + } }