Skip to content
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
11 changes: 6 additions & 5 deletions src/commands/copy-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

import moment = require('moment');
import * as vscode from 'vscode';
import * as J from '..';
import { InlineString, InlineTemplate } from '../model';
import { Ctrl } from '../util';

export enum ShiftTarget {
nextWorkingDay,
Expand All @@ -42,13 +43,13 @@ export class CopyTaskCommand implements vscode.Command {
command: string = "journal.commands.copy-task";


protected constructor(public ctrl: J.Util.Ctrl) { }
protected constructor(public ctrl: Ctrl) { }

public async dispose(): Promise<void> {
// do nothing
}

public static create(ctrl: J.Util.Ctrl): vscode.Disposable {
public static create(ctrl: Ctrl): vscode.Disposable {
const cmd = new this(ctrl);
vscode.commands.registerCommand(cmd.command, (document, range, target) => cmd.execute(document, range, target));
return cmd;
Expand Down Expand Up @@ -88,9 +89,9 @@ export class CopyTaskCommand implements vscode.Command {

private async insertTaskToEntry(taskString: string, date: Date) {
const doc: vscode.TextDocument = await this.ctrl.reader.loadEntryForDay(date);
const tpl: J.Model.InlineTemplate = await this.ctrl.config.getTaskInlineTemplate();
const tpl: InlineTemplate = await this.ctrl.config.getTaskInlineTemplate();
const pos = this.ctrl.inject.computePositionForInput(doc, tpl);
const inlineString: J.Model.InlineString = await this.ctrl.inject.buildInlineString(doc, tpl, ["${input}", taskString]);
const inlineString: InlineString = await this.ctrl.inject.buildInlineString(doc, tpl, ["${input}", taskString]);
this.ctrl.inject.injectInlineString(inlineString);

doc.save();
Expand Down
6 changes: 3 additions & 3 deletions src/commands/open-journal-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'use strict';

import * as vscode from 'vscode';
import * as J from '..';
import { Ctrl } from '../util';
import { isRemoteSession, toLocalFileUri } from '../journal/paths';


Expand All @@ -27,13 +27,13 @@ export class OpenJournalWorkspaceCommand implements vscode.Command, vscode.Dispo
command: string = 'journal.open';


protected constructor(public ctrl: J.Util.Ctrl) { }
protected constructor(public ctrl: Ctrl) { }

public async dispose(): Promise<void> {
// do nothing
}

public static create(ctrl: J.Util.Ctrl): vscode.Disposable {
public static create(ctrl: Ctrl): vscode.Disposable {
const cmd = new this(ctrl);
vscode.commands.registerCommand(cmd.command, () => cmd.openWorkspace());
return cmd;
Expand Down
7 changes: 4 additions & 3 deletions src/commands/open-next-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
'use strict';

import * as vscode from 'vscode';
import * as J from '..';
import { Input } from '../model';
import { Ctrl } from '../util';
import { AbstractLoadEntryForDateCommand } from './show-entry-for-date';
import { daysBetween, findAdjacentEntry, getAdjacentWeekInput, resolveAnchor, Mode } from '../journal/navigation';

export class OpenNextEntryCommand extends AbstractLoadEntryForDateCommand {
title: string = "Open the next journal entry";
command: string = "journal.openNext";

public static create(ctrl: J.Util.Ctrl): vscode.Disposable {
public static create(ctrl: Ctrl): vscode.Disposable {
const cmd = new this(ctrl);
vscode.commands.registerCommand(cmd.command, () => cmd.run());
return cmd;
Expand All @@ -36,7 +37,7 @@ export class OpenNextEntryCommand extends AbstractLoadEntryForDateCommand {
await vscode.window.showInformationMessage(vscode.l10n.t("No later journal entry found."));
return;
}
const input = new J.Model.Input();
const input = new Input();
input.date = target;
input.scope = anchor.scope;
await this.execute(input);
Expand Down
7 changes: 4 additions & 3 deletions src/commands/open-previous-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
'use strict';

import * as vscode from 'vscode';
import * as J from '..';
import { Input } from '../model';
import { Ctrl } from '../util';
import { AbstractLoadEntryForDateCommand } from './show-entry-for-date';
import { daysBetween, findAdjacentEntry, getAdjacentWeekInput, resolveAnchor, Mode } from '../journal/navigation';

export class OpenPreviousEntryCommand extends AbstractLoadEntryForDateCommand {
title: string = "Open the previous journal entry";
command: string = "journal.openPrevious";

public static create(ctrl: J.Util.Ctrl): vscode.Disposable {
public static create(ctrl: Ctrl): vscode.Disposable {
const cmd = new this(ctrl);
vscode.commands.registerCommand(cmd.command, () => cmd.run());
return cmd;
Expand All @@ -36,7 +37,7 @@ export class OpenPreviousEntryCommand extends AbstractLoadEntryForDateCommand {
await vscode.window.showInformationMessage(vscode.l10n.t("No earlier journal entry found."));
return;
}
const input = new J.Model.Input();
const input = new Input();
input.date = target;
input.scope = anchor.scope;
await this.execute(input);
Expand Down
9 changes: 5 additions & 4 deletions src/commands/print-current-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@
'use strict';

import * as vscode from 'vscode';
import * as J from '..';
import { ScopedTemplate } from '../model';
import { Ctrl } from '../util';


export class PrintTimeCommand implements vscode.Command, vscode.Disposable {
title: string = "Print current time";
command: string = "journal.printTime";

protected constructor(public ctrl: J.Util.Ctrl) {}
protected constructor(public ctrl: Ctrl) {}

public async dispose(): Promise<void> {
// do nothing
}

public static create(ctrl: J.Util.Ctrl): vscode.Disposable {
public static create(ctrl: Ctrl): vscode.Disposable {
const cmd = new this(ctrl);
vscode.commands.registerCommand(cmd.command, () => cmd.printTime());
return cmd;
Expand All @@ -47,7 +48,7 @@ export class PrintTimeCommand implements vscode.Command, vscode.Disposable {
let editor: vscode.TextEditor = <vscode.TextEditor>vscode.window.activeTextEditor;

// Todo: identify scope of the active editot
let template: J.Model.ScopedTemplate = await this.ctrl.config.getTimeStringTemplate();
let template: ScopedTemplate = await this.ctrl.config.getTimeStringTemplate();

let currentPosition: vscode.Position = editor.selection.active;

Expand Down
16 changes: 8 additions & 8 deletions src/commands/print-duration-between-selected-times.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@

import moment = require('moment');
import * as vscode from 'vscode';
import * as J from '..';
import { Ctrl, isNullOrUndefined } from '../util';


export class PrintDurationCommand implements vscode.Command, vscode.Disposable {
title: string = "Print duration between two selected times";
command: string = "journal.printDuration";

protected constructor(public ctrl: J.Util.Ctrl) {}
protected constructor(public ctrl: Ctrl) {}

public async dispose(): Promise<void> {
// do nothing
}

public static create(ctrl: J.Util.Ctrl): vscode.Disposable {
public static create(ctrl: Ctrl): vscode.Disposable {
const cmd = new this(ctrl);
vscode.commands.registerCommand(cmd.command, () => cmd.printDuration());
return cmd;
Expand Down Expand Up @@ -67,7 +67,7 @@ export class PrintDurationCommand implements vscode.Command, vscode.Disposable {
let range: vscode.Range | undefined = editor.document.getWordRangeAtPosition(selection.active, regExp);


if (J.Util.isNullOrUndefined(range)) {
if (isNullOrUndefined(range)) {
target = selection.active;
return;
}
Expand Down Expand Up @@ -111,7 +111,7 @@ export class PrintDurationCommand implements vscode.Command, vscode.Disposable {
}

// parsing glued hours
if (J.Util.isNullOrUndefined(start)) {
if (isNullOrUndefined(start)) {
start = time;
} else if (start!.isAfter(time)) {
end = start;
Expand All @@ -121,9 +121,9 @@ export class PrintDurationCommand implements vscode.Command, vscode.Disposable {
}
});

if (J.Util.isNullOrUndefined(start)) { throw new Error("No valid start time selected"); } // tslint:disable-line
else if (J.Util.isNullOrUndefined(end)) { throw new Error("No valid end time selected"); } // tslint:disable-line
else if (J.Util.isNullOrUndefined(target)) { throw new Error("No valid target selected for printing the duration."); } // tslint:disable-line
if (isNullOrUndefined(start)) { throw new Error("No valid start time selected"); } // tslint:disable-line
else if (isNullOrUndefined(end)) { throw new Error("No valid end time selected"); } // tslint:disable-line
else if (isNullOrUndefined(target)) { throw new Error("No valid target selected for printing the duration."); } // tslint:disable-line
else {
let duration = moment.duration(start!.diff(end!));
let formattedDuration = Math.abs(duration.asHours()).toFixed(2);
Expand Down
10 changes: 5 additions & 5 deletions src/commands/print-sum-of-selected-numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
'use strict';

import * as vscode from 'vscode';
import * as J from '..';
import { Ctrl, isNullOrUndefined } from '../util';


export class PrintSumCommand implements vscode.Command, vscode.Disposable {
title: string = "Print sum of two selected numbers";
command: string = "journal.printSum";

protected constructor(public ctrl: J.Util.Ctrl) {}
protected constructor(public ctrl: Ctrl) {}

public async dispose(): Promise<void> {
// do nothing
}

public static create(ctrl: J.Util.Ctrl): vscode.Disposable {
public static create(ctrl: Ctrl): vscode.Disposable {
const cmd = new this(ctrl);
vscode.commands.registerCommand(cmd.command, () => cmd.execute());
return cmd;
Expand All @@ -53,7 +53,7 @@ export class PrintSumCommand implements vscode.Command, vscode.Disposable {
editor.selections.forEach((selection: vscode.Selection) => {
let range: vscode.Range | undefined = editor.document.getWordRangeAtPosition(selection.active, regExp);

if (J.Util.isNullOrUndefined(range)) {
if (isNullOrUndefined(range)) {
target = selection.active;
return;
}
Expand All @@ -76,7 +76,7 @@ export class PrintSumCommand implements vscode.Command, vscode.Disposable {
});

if (numbers.length < 2) { throw Error("You have to select at least two numbers"); } // tslint:disable-line
else if (J.Util.isNullOrUndefined(target!)) { throw Error("No valid target selected for printing the sum."); } // tslint:disable-line
else if (isNullOrUndefined(target!)) { throw Error("No valid target selected for printing the sum."); } // tslint:disable-line
else {
let result: string = numbers.reduce((previous, current) => previous + current).toString();
this.ctrl.inject.injectString(editor.document, result + "", target!);
Expand Down
16 changes: 9 additions & 7 deletions src/commands/show-entry-for-date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
'use strict';

import * as vscode from 'vscode';
import * as J from '..';
import { LoadNotes } from '../features';
import { Input } from '../model';
import { Ctrl } from '../util';
import { NoteInput, SelectedInput, ScopedTemplate } from '../model';
import { getWeekFromURIAndConfig, isRemoteSession, toLocalFileUri } from '../journal/paths';
import { SyncDailyLinks } from '../features/sync/sync-daily-links';


export class AbstractLoadEntryForDateCommand implements vscode.Disposable {

constructor(public ctrl: J.Util.Ctrl) { }
constructor(public ctrl: Ctrl) { }

public async dispose(): Promise<void> {
// do nothing
Expand All @@ -36,7 +38,7 @@ export class AbstractLoadEntryForDateCommand implements vscode.Disposable {
* Implements commands "yesterday", "today", "yesterday", where the input is predefined (no input box appears)
* @param offset
*/
public async execute(input: J.Model.Input): Promise<void> {
public async execute(input: Input): Promise<void> {
try {
if (await this.promptLocalOrRemoteInRemoteSession(input)) {
return;
Expand All @@ -52,7 +54,7 @@ export class AbstractLoadEntryForDateCommand implements vscode.Disposable {
}
}

private async promptLocalOrRemoteInRemoteSession(input: J.Model.Input): Promise<boolean> {
private async promptLocalOrRemoteInRemoteSession(input: Input): Promise<boolean> {
if (!isRemoteSession()) {
return false;
}
Expand All @@ -78,7 +80,7 @@ export class AbstractLoadEntryForDateCommand implements vscode.Disposable {
return false;
}

private async openLocalJournal(input: J.Model.Input): Promise<void> {
private async openLocalJournal(input: Input): Promise<void> {
const localBase = this.ctrl.config.getBasePathForLocalOpen();
let targetPath = localBase;

Expand Down Expand Up @@ -117,14 +119,14 @@ export class AbstractLoadEntryForDateCommand implements vscode.Disposable {
* Expects any user input from the magic input and either opens the file or creates it.
* @param input
*/
protected async loadPageForInput(input: J.Model.Input): Promise<vscode.TextDocument> {
protected async loadPageForInput(input: Input): Promise<vscode.TextDocument> {

if (input instanceof SelectedInput) {
// we just load the path
return this.ctrl.ui.openDocument((<SelectedInput>input).path);
} if (input instanceof NoteInput) {
// we create or load the notes
return new J.Features.LoadNotes(input, this.ctrl).loadWithPath(input.path);
return new LoadNotes(input, this.ctrl).loadWithPath(input.path);

} else {
return this.ctrl.reader.loadEntryForInput(input)
Expand Down
7 changes: 4 additions & 3 deletions src/commands/show-entry-for-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
'use strict';

import * as vscode from 'vscode';
import * as J from '..';
import { Input } from '../model';
import { Ctrl } from '../util';
import { AbstractLoadEntryForDateCommand } from './show-entry-for-date';


export class ShowEntryForInputCommand extends AbstractLoadEntryForDateCommand {
title: string = "Show journal entry for given user input";
command: string = "journal.day";

public static create(ctrl: J.Util.Ctrl): vscode.Disposable {
public static create(ctrl: Ctrl): vscode.Disposable {
const cmd = new this(ctrl);
vscode.commands.registerCommand(cmd.command, () => cmd.execute());
return cmd;
Expand All @@ -41,7 +42,7 @@ export class ShowEntryForInputCommand extends AbstractLoadEntryForDateCommand {
public async execute(): Promise<void> {
this.ctrl.logger.trace("Executing command: ", this.command);

const input: J.Model.Input = await this.ctrl.ui.getUserInputWithValidation();
const input: Input = await this.ctrl.ui.getUserInputWithValidation();
super.execute(input);
}

Expand Down
7 changes: 4 additions & 3 deletions src/commands/show-entry-for-today.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
'use strict';

import * as vscode from 'vscode';
import * as J from '..';
import { Input } from '../model';
import { Ctrl } from '../util';
import { AbstractLoadEntryForDateCommand } from './show-entry-for-date';


Expand All @@ -27,10 +28,10 @@ export class ShowEntryForTodayCommand extends AbstractLoadEntryForDateCommand {
command: string = "journal.today";


public static create(ctrl: J.Util.Ctrl): vscode.Disposable {
public static create(ctrl: Ctrl): vscode.Disposable {
const cmd = new this(ctrl);

let input = new J.Model.Input();
let input = new Input();
input.offset = 0;

vscode.commands.registerCommand(cmd.command, () => cmd.execute(input));
Expand Down
7 changes: 4 additions & 3 deletions src/commands/show-entry-for-tomorrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
'use strict';

import * as vscode from 'vscode';
import * as J from '..';
import { Input } from '../model';
import { Ctrl } from '../util';
import { AbstractLoadEntryForDateCommand } from './show-entry-for-date';


Expand All @@ -27,10 +28,10 @@ export class ShowEntryForTomorrowCommand extends AbstractLoadEntryForDateCommand
command: string = "journal.tomorrow";


public static create(ctrl: J.Util.Ctrl): vscode.Disposable {
public static create(ctrl: Ctrl): vscode.Disposable {
const cmd = new this(ctrl);

let input = new J.Model.Input();
let input = new Input();
input.offset = 1;

vscode.commands.registerCommand(cmd.command, () => cmd.execute(input));
Expand Down
Loading
Loading