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

Added your todo progress into the the statusBar #39

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .vscode/tags
Original file line number Diff line number Diff line change
@@ -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 /[email protected]/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.8 //
12 changes: 4 additions & 8 deletions samples/How to use To Do Tasks.todo
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@ 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
☐ You can use following pre-existing tags to mark tasks @critical @high @low @today
☐ Auto intellisense is provided to help you in finding tags

☐ More to come... Check https://github.com/sandy081/vscode-todotasks


11 changes: 10 additions & 1 deletion src/TodoDocument.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

import {TextDocument, TextLine, Position, CompletionItem, Range} from 'vscode';
import {getStatus} from './TodoStatus';

export class TodoDocument {

Expand All @@ -19,12 +20,16 @@ export class TodoDocument {
public static ACTION_CANCELLED= "cancelled";

constructor(private _textDocument: TextDocument) {
getStatus().reset();
let s = this.getTasks();
let a = getStatus()
}

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;
Expand All @@ -37,7 +42,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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/TodoDocumentEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
Expand Down Expand Up @@ -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) {
Expand Down
42 changes: 39 additions & 3 deletions src/TodoExtensionMain.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -25,15 +29,47 @@ 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);
let reg_file = /.*\.todo$/mg;
if(reg_file.test(e.document.fileName))
updateStatus(status_);
else
status_.hide();
}));
context.subscriptions.push(window.onDidChangeActiveTextEditor(e =>{
let reg_file = /.*\.todo$/mg;
if(reg_file.test(e.document.fileName))
updateStatus(status_);
else
status_.hide();
}));

window.onDidChangeActiveTextEditor(editor => {
_decorateEditor();
}, null, context.subscriptions);

_decorateEditor();
updateStatus(status_);
}
function updateStatus(status: StatusBarItem):void{
let a = getStatus();
let asciis = [
'[----------]',
'[#---------]',
'[##--------]',
'[###-------]',
'[####------]',
'[#####-----]',
'[######----]',
'[#######---]',
'[########--]',
'[#########-]',
'[##########]'
];
status.text = asciis[Math.ceil((a.done/a.todo)*10)];
status.show();
}

function _decorateEditor(delayed?:boolean) {
let editor= window.activeTextEditor;
if (editor && "todo" === editor.document.languageId ) {
Expand Down
43 changes: 43 additions & 0 deletions src/TodoStatus.ts
Original file line number Diff line number Diff line change
@@ -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;
}