From e897ec197d486a1b7cc670ee22aea688bb65377c Mon Sep 17 00:00:00 2001 From: Nasreddine Date: Fri, 1 Dec 2017 02:04:08 +0100 Subject: [PATCH 1/3] Update numbers and statistics. --- .vscode/tags | 6 ++++ samples/How to use To Do Tasks.todo | 12 +++----- src/TodoDocument.ts | 10 ++++++- src/TodoDocumentEditor.ts | 2 ++ src/TodoExtensionMain.ts | 20 ++++++++++++-- src/TodoStatus.ts | 43 +++++++++++++++++++++++++++++ 6 files changed, 81 insertions(+), 12 deletions(-) create mode 100644 .vscode/tags create mode 100644 src/TodoStatus.ts diff --git a/.vscode/tags b/.vscode/tags new file mode 100644 index 0000000..d01d39b --- /dev/null +++ b/.vscode/tags @@ -0,0 +1,6 @@ +!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ +!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ +!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/ +!_TAG_PROGRAM_NAME Exuberant Ctags // +!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ +!_TAG_PROGRAM_VERSION 5.8 // diff --git a/samples/How to use To Do Tasks.todo b/samples/How to use To Do Tasks.todo index 66c17b2..c3666d1 100644 --- a/samples/How to use To Do Tasks.todo +++ b/samples/How to use To Do Tasks.todo @@ -3,20 +3,18 @@ Projects: ☐ You can nest projects inside each other ☐ You can fold projects and sub projects Folding and Indentation: - ☐ Demo folidng - Tasks: New Task: - ☐ Press Cmd+Enter (Ctrl+Enter on Windows and Linux) to add a new task ☐ You can also use the Command pallette to create a new task by typing To Do:New Task - ☐ If you are on a new line, it will create a new task on the current line + ☐ If you are on a line with some text pressing new task shortcut will convert it to a task ☐ If you are on a line with some text pressing new task shortcut will convert it to a task ☐ New tasks are nested as much as the previous task More Actions: ✔ Complete a task by pressing Alt+d @done - ☐ Re-open a completed task by pressing Alt+d ✘ Cancel a task by pressing Alt+c @cancelled - ☐ Complete a cancelled task by pressing Alt+d + ☐ Complete a cancell + ☐ Complete a cancell + ☐ Complete a cancell ☐ You can also use the Command pallette to complete or cancel a task by typing To Do:Complete Task or To Do:Cancel Task Tagging: ☐ You can add tags using @ sign, like this @tag @@ -24,5 +22,3 @@ Tasks: ☐ Auto intellisense is provided to help you in finding tags ☐ More to come... Check https://github.com/sandy081/vscode-todotasks - - diff --git a/src/TodoDocument.ts b/src/TodoDocument.ts index 68a1b21..c081b4d 100644 --- a/src/TodoDocument.ts +++ b/src/TodoDocument.ts @@ -1,6 +1,7 @@ 'use strict'; import {TextDocument, TextLine, Position, CompletionItem, Range} from 'vscode'; +import {getStatus} from './TodoStatus'; export class TodoDocument { @@ -19,12 +20,15 @@ export class TodoDocument { public static ACTION_CANCELLED= "cancelled"; constructor(private _textDocument: TextDocument) { + getStatus().reset(); + let s = this.getTasks(); } public getProject(pos: Position): Project { let line= this._textDocument.lineAt(pos.line) let projectText= line.text.trim(); if (projectText.endsWith(TodoDocument.SYMBOL_PROJECT)) { + getStatus().upProjects(); return new Project(line); } return null; @@ -37,7 +41,11 @@ export class TodoDocument { var match; while (match = regEx.exec(text)) { let line= this._textDocument.lineAt(this._textDocument.positionAt(match.index + 1).line); - result.push(new Task(line)); + let _ = new Task(line); + getStatus().upTodo(); + if(_.isDone()) + getStatus().upDone(); + result.push(_); } return result; } diff --git a/src/TodoDocumentEditor.ts b/src/TodoDocumentEditor.ts index 389363b..3ebd44d 100644 --- a/src/TodoDocumentEditor.ts +++ b/src/TodoDocumentEditor.ts @@ -3,6 +3,7 @@ import { commands, TextEditor, TextEditorEdit, Range, Position, TextLine, TextDocumentChangeEvent } from 'vscode'; import {TodoDocument} from './TodoDocument'; import TodoDocumentDecorator from './TodoDocumentDecorator'; +import {getStatus} from './TodoStatus'; export class TodoDocumentEditor { constructor(private _textEditor: TextEditor, private _textEditorEdit: TextEditorEdit) { } @@ -57,6 +58,7 @@ export class TodoDocumentEditor { } this.updateTask(task.taskLine, task.getDescription(), TodoDocument.SYMBOL_CANCEL_TASK, TodoDocument.ACTION_CANCELLED); + } private updateTask(taskLine: TextLine, taskDescription: string, symbol: string, tag?: string) { diff --git a/src/TodoExtensionMain.ts b/src/TodoExtensionMain.ts index c693180..7db2737 100644 --- a/src/TodoExtensionMain.ts +++ b/src/TodoExtensionMain.ts @@ -1,16 +1,20 @@ 'use strict'; -import { workspace, window, ExtensionContext, TextDocumentChangeEvent, languages, env, commands, TextEditor, TextEditorEdit, Position } from 'vscode'; +import { workspace, window, ExtensionContext, TextDocumentChangeEvent, languages, env, commands, TextEditor, TextEditorEdit, Position, StatusBarAlignment, StatusBarItem, TextEdit } from 'vscode'; import {TodoCommands} from './TodoCommands'; import TodoCompletionItemProvider from './TodoCompletionItemProvider'; import TodoDocumentDecorator from './TodoDocumentDecorator'; import TodoCodeActionProvider from './TodoCodeActionProvider'; +import { getStatus } from './TodoStatus'; +import { TodoDocument } from './TodoDocument'; +let status_ = null; export function activate(context: ExtensionContext): any { context.subscriptions.push(languages.registerCompletionItemProvider('todo', new TodoCompletionItemProvider(), '@')); context.subscriptions.push(languages.registerCodeActionsProvider('todo', new TodoCodeActionProvider())); - + status_ = window.createStatusBarItem(StatusBarAlignment.Left, 100); + context.subscriptions.push(status_); languages.setLanguageConfiguration('todo', { wordPattern: /(-?\d*\.\d\w*)|([^\-\`\~\!\#\%\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g, indentationRules: { @@ -25,6 +29,11 @@ export function activate(context: ExtensionContext): any { context.subscriptions.push(todoCommands.registerCancelTaskCommand()); context.subscriptions.push(workspace.onDidChangeTextDocument((e: TextDocumentChangeEvent) => { _decorateEditor(true); + new TodoDocument(e.document); + updateStatus(status_); + })); + context.subscriptions.push(window.onDidChangeActiveTextEditor(e =>{ + updateStatus(status_); })); window.onDidChangeActiveTextEditor(editor => { @@ -32,8 +41,13 @@ export function activate(context: ExtensionContext): any { }, null, context.subscriptions); _decorateEditor(); + updateStatus(status_); +} +function updateStatus(status: StatusBarItem):void{ + let a = getStatus(); + status.text = "Todos: " + a.todo; + status.show(); } - function _decorateEditor(delayed?:boolean) { let editor= window.activeTextEditor; if (editor && "todo" === editor.document.languageId ) { diff --git a/src/TodoStatus.ts b/src/TodoStatus.ts new file mode 100644 index 0000000..c1d4fc0 --- /dev/null +++ b/src/TodoStatus.ts @@ -0,0 +1,43 @@ +'use strict'; + +class StateContext{ + todo: number; + done: number; + projects: number; + constructor(){ + this.todo = 0; + this.done = 0; + this.projects = 0; + } + reset(){ + this.todo = 0; + this.done = 0; + this.projects = 0; + } + upTodo(){ + this.todo++; + } + downTodo(){ + this.todo--; + } + upDone(){ + this.done ++; + } + downDone(){ + this.done--; + } + upProjects(){ + this.projects++; + } + downProjects(){ + this.projects--; + } +} + +let myState = null; + +export function getStatus(){ + if(myState == null) + myState = new StateContext(); + return myState; +} \ No newline at end of file From bbfa0d8b544cf0fc34a5a3b39c17a628734b5b7a Mon Sep 17 00:00:00 2001 From: Nasreddine Date: Fri, 1 Dec 2017 02:15:55 +0100 Subject: [PATCH 2/3] DONE. --- src/TodoDocument.ts | 1 + src/TodoExtensionMain.ts | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/TodoDocument.ts b/src/TodoDocument.ts index c081b4d..fa9f81a 100644 --- a/src/TodoDocument.ts +++ b/src/TodoDocument.ts @@ -22,6 +22,7 @@ export class TodoDocument { constructor(private _textDocument: TextDocument) { getStatus().reset(); let s = this.getTasks(); + let a = getStatus() } public getProject(pos: Position): Project { diff --git a/src/TodoExtensionMain.ts b/src/TodoExtensionMain.ts index 7db2737..a672388 100644 --- a/src/TodoExtensionMain.ts +++ b/src/TodoExtensionMain.ts @@ -45,7 +45,20 @@ export function activate(context: ExtensionContext): any { } function updateStatus(status: StatusBarItem):void{ let a = getStatus(); - status.text = "Todos: " + a.todo; + let asciis = [ + '[----------]', + '[#---------]', + '[##--------]', + '[###-------]', + '[####------]', + '[#####-----]', + '[######----]', + '[#######---]', + '[########--]', + '[#########-]', + '[##########]' + ]; + status.text = asciis[Math.ceil((a.done/a.todo)*10)]; status.show(); } function _decorateEditor(delayed?:boolean) { From 5480add9eae98766841e649a1a80aa7a1c4b39c1 Mon Sep 17 00:00:00 2001 From: Nasreddine Date: Fri, 1 Dec 2017 13:30:46 +0100 Subject: [PATCH 3/3] Added change document events. --- src/TodoExtensionMain.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/TodoExtensionMain.ts b/src/TodoExtensionMain.ts index a672388..a87f3a2 100644 --- a/src/TodoExtensionMain.ts +++ b/src/TodoExtensionMain.ts @@ -29,11 +29,20 @@ export function activate(context: ExtensionContext): any { context.subscriptions.push(todoCommands.registerCancelTaskCommand()); context.subscriptions.push(workspace.onDidChangeTextDocument((e: TextDocumentChangeEvent) => { _decorateEditor(true); + let a = window.activeTextEditor new TodoDocument(e.document); - updateStatus(status_); + let reg_file = /.*\.todo$/mg; + if(reg_file.test(e.document.fileName)) + updateStatus(status_); + else + status_.hide(); })); context.subscriptions.push(window.onDidChangeActiveTextEditor(e =>{ - updateStatus(status_); + let reg_file = /.*\.todo$/mg; + if(reg_file.test(e.document.fileName)) + updateStatus(status_); + else + status_.hide(); })); window.onDidChangeActiveTextEditor(editor => {