Skip to content

Commit

Permalink
command palette checkCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed Apr 17, 2021
1 parent 97ad4d6 commit d72a993
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 71 deletions.
2 changes: 1 addition & 1 deletion data.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"personRegexpString":"\\[{2}People\\/(.*?)\\]{2}","projectRegexpString":"\\[{2}Projects\\/(.*?)\\]{2}","locationRegexpString":"\\[{2}Locations\\/(.*?)\\]{2}","miscRegexpString":"","dateRegexpString":"#(\\d{4})\\/(\\d{2})\\/(\\d{2})","discussWithRegexpString":"#(discussWith)","waitingForRegexpString":"#(waitingFor)","promisedToRegexpString":"#(promisedTo)","somedayMaybeRegexpString":"#(someday)","excludeTagRegexpString":"#(exclude)","excludePath":"Templates/","excludeFilenameFragment":"checklist","isInboxVisible":true,"isAgingVisible":true,"isTodayVisible":true,"isScheduledVisible":true,"isStakeholderVisible":true,"isSomedayVisible":true,"inboxTooltip":"Inbox: Unclassified TODOs, i.e. without a date; without an Action Tag and a Context; without someday/maybe tag.","agingTooltip":"Overdue: Past the TODO's date.","todayTooltip":"Today: Scheduled for Today","scheduledTooltip":"Scheduled: Scheduled for a future date","stakeholderTooltip":"Context Actions: Only TODOs that have a valid Context (Person, Project, Location) and a valid Action Tag appear here.","somedayTooltip":"Someday / Maybe"}
{"personRegexpString":"\\[{2}People\\/(.*?)\\]{2}","projectRegexpString":"\\[{2}Projects\\/(.*?)\\]{2}","locationRegexpString":"\\[{2}Locations\\/(.*?)\\]{2}","miscRegexpString":"","dateRegexpString":"#(\\d{4})\\/(\\d{2})\\/(\\d{2})","actionTagOneRegexpString":"#(discussWith)","actionTagTwoRegexpString":"#(waitingFor)","actionTagThreeRegexpString":"#(promisedTo)","somedayMaybeRegexpString":"#(someday)","excludeTagRegexpString":"#(exclude)","excludePath":"Templates/","excludeFilenameFragment":"checklist","isInboxVisible":true,"isOverdueVisible":true,"isTodayVisible":true,"isScheduledVisible":true,"isStakeholderVisible":true,"isSomedayVisible":true,"inboxTooltip":"Inbox: Unclassified TODOs, i.e. without a date; without an Action Tag and a Context; without someday/maybe tag.","overdueTooltip":"Overdue: Past the TODO's date.","todayTooltip":"Today: Scheduled for Today","scheduledTooltip":"Scheduled: Scheduled for a future date","stakeholderTooltip":"Context Actions: Only TODOs that have a valid Context (Person, Project, Location) and a valid Action Tag appear here.","somedayTooltip":"Someday / Maybe","discussWithRegexpString":"#(discussWith)","waitingForRegexpString":"#(waitingFor)","promisedToRegexpString":"#(promisedTo)","isAgingVisible":true,"agingTooltip":"Overdue: Past the TODO's date."}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "obsidian-gtd-plugin",
"version": "0.9.7",
"description": "GTD action tracker",
"description": "Obsidian GTD action tracker",
"main": "main.js",
"scripts": {
"build": "rollup --config rollup.config.js --environment BUILD:production",
Expand Down
14 changes: 7 additions & 7 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ https://github.com/zsviczian/obsidian-stakeholder-actions
`;

export default {
input: 'src/main.ts',
input: './src/main.ts',
output: {
dir: isProd ? './dist' : '.',
sourcemap: 'inline',
sourcemapExcludeSources: isProd,
// sourcemapExcludeSources: isProd,
format: 'cjs',
exports: 'default',
banner
banner,
},
external: ['obsidian'],
plugins: [typescript(),
plugins: [copyAndWatch('src/styles.css','styles.css',true),
copyAndWatch('src/manifest.json','manifest.json',true),
typescript({inlineSources: !isProd}),
nodeResolve({ browser: true }),
commonjs(),
copyAndWatch('src/styles.css','styles.css',true),
copyAndWatch('src/manifest.json','manifest.json',true)],
commonjs()],
};

function copyAndWatch(fileIn, fileOut, isProd) {
Expand Down
73 changes: 57 additions & 16 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { App, Plugin, PluginManifest, TFile, WorkspaceLeaf, } from 'obsidian';
import { App, Plugin, PluginManifest, TFile, WorkspaceLeaf} from 'obsidian';
import { VIEW_TYPE_TODO } from './constants';
import { TodoItemView, TodoItemViewProps, TodoItemViewPane } from './ui/TodoItemView';
import { TodoItem, TodoItemStatus } from './model/TodoItem';
import { TodoIndex,TodoItemIndexProps } from './model/TodoIndex';
import {DEFAULT_SETTINGS, ActionTrackerSettings, ActionTrackerSettingTab} from './settings';
import { stringify } from 'querystring';
//import { stringify } from 'querystring';


export default class ActionTrackerPlugin extends Plugin {
Expand Down Expand Up @@ -35,7 +35,6 @@ export default class ActionTrackerPlugin extends Plugin {

async onload(): Promise<void> {
console.log('loading plugin');

await this.loadSettings();

this.todoIndex = new TodoIndex(this.app.vault, this.tick.bind(this),this.getTodoItemIndexProps());
Expand All @@ -52,16 +51,16 @@ export default class ActionTrackerPlugin extends Plugin {
this.todoIndex.setStatus(todo, newStatus);
},
isInboxVisible: this.getSettingValue('isInboxVisible'),
isOverdueVisible: this.getSettingValue('isOverdueVisible'),
isOverdueVisible: this.getSettingValue('isOverdueVisible'),
isTodayVisible: this.getSettingValue('isTodayVisible'),
isScheduledVisible: this.getSettingValue('isScheduledVisible'),
isStakeholderVisible: this.getSettingValue('isStakeholderVisible'),
isContextActionVisible: this.getSettingValue('isContextActionVisible'),
isSomedayVisible: this.getSettingValue('isSomedayVisible'),
inboxTooltip: this.getSettingValue('inboxTooltip'),
overdueTooltip: this.getSettingValue('overdueTooltip'),
overdueTooltip: this.getSettingValue('overdueTooltip'),
todayTooltip: this.getSettingValue('todayTooltip'),
scheduledTooltip: this.getSettingValue('scheduledTooltip'),
stakeholderTooltip: this.getSettingValue('stakeholderTooltip'),
contextActionTooltip: this.getSettingValue('contextActionTooltip'),
somedayTooltip: this.getSettingValue('somedayTooltip'),
};
this.view = new TodoItemView(leaf, props);
Expand All @@ -73,37 +72,79 @@ export default class ActionTrackerPlugin extends Plugin {
this.addCommand({
id: "show-inbox-view",
name: "Inbox View",
callback: () => this.view.setViewState({activePane: TodoItemViewPane.Inbox}),
checkCallback: (checking: boolean) => {
if (checking) {
return this.getSettingValue('isInboxVisible');
} else {
this.view.setViewState({activePane: TodoItemViewPane.Inbox});
return true;
}
},
});

this.addCommand({
id: "show-overdue-view",
name: "Overdue View",
callback: () => this.view.setViewState({activePane: TodoItemViewPane.Overdue}),
checkCallback: (checking: boolean) => {
if (checking) {
return this.getSettingValue('isOverdueVisible');
} else {
this.view.setViewState({activePane: TodoItemViewPane.Overdue});
return true;
}
},
});

this.addCommand({
id: "show-today-view",
name: "Today View",
callback: () => this.view.setViewState({activePane: TodoItemViewPane.Today}),
checkCallback: (checking: boolean) => {
if (checking) {
return this.getSettingValue('isTodayVisible');
} else {
this.view.setViewState({activePane: TodoItemViewPane.Today});
return true;
}
},
});

this.addCommand({
id: "show-scheduled-view",
name: "Scheduled View",
callback: () => this.view.setViewState({activePane: TodoItemViewPane.Scheduled}),
checkCallback: (checking: boolean) => {
if (checking) {
return this.getSettingValue('isScheduledVisible');
} else {
this.view.setViewState({activePane: TodoItemViewPane.Scheduled});
return true;
}
},
});

this.addCommand({
id: "show-context-actions-view",
name: "Context Actions View",
callback: () => this.view.setViewState({activePane: TodoItemViewPane.Stakeholder}),
checkCallback: (checking: boolean) => {
if (checking) {
return this.getSettingValue('isContextActionVisible');
} else {
this.view.setViewState({activePane: TodoItemViewPane.ContextAction});
return true;
}
},
});

this.addCommand({
id: "show-someday-view",
name: "Someday/Maybe View",
callback: () => this.view.setViewState({activePane: TodoItemViewPane.Someday}),
checkCallback: (checking: boolean) => {
if (checking) {
return this.getSettingValue('isSomedayVisible');
} else {
this.view.setViewState({activePane: TodoItemViewPane.Someday});
return true;
}
},
});

if (this.app.workspace.layoutReady) {
Expand Down Expand Up @@ -160,13 +201,13 @@ export default class ActionTrackerPlugin extends Plugin {
isOverdueVisible: this.getSettingValue('isOverdueVisible'),
isTodayVisible: this.getSettingValue('isTodayVisible'),
isScheduledVisible: this.getSettingValue('isScheduledVisible'),
isStakeholderVisible: this.getSettingValue('isStakeholderVisible'),
isContextActionVisible: this.getSettingValue('isContextActionVisible'),
isSomedayVisible: this.getSettingValue('isSomedayVisible'),
inboxTooltip: this.getSettingValue('inboxTooltip'),
overdueTooltip: this.getSettingValue('overdueTooltip'),
todayTooltip: this.getSettingValue('todayTooltip'),
scheduledTooltip: this.getSettingValue('scheduledTooltip'),
stakeholderTooltip: this.getSettingValue('stakeholderTooltip'),
contextActionTooltip: this.getSettingValue('contextActionTooltip'),
somedayTooltip: this.getSettingValue('somedayTooltip'),
});
}
Expand Down
18 changes: 9 additions & 9 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ export interface ActionTrackerSettings {
isOverdueVisible: boolean,
isTodayVisible: boolean,
isScheduledVisible: boolean,
isStakeholderVisible: boolean,
isContextActionVisible: boolean,
isSomedayVisible: boolean,
inboxTooltip: string,
overdueTooltip: string,
todayTooltip: string,
scheduledTooltip: string,
stakeholderTooltip: string,
contextActionTooltip: string,
somedayTooltip: string,
}

Expand All @@ -45,13 +45,13 @@ export const DEFAULT_SETTINGS: ActionTrackerSettings = {
isOverdueVisible: true,
isTodayVisible: true,
isScheduledVisible: true,
isStakeholderVisible: true,
isContextActionVisible: true,
isSomedayVisible: true,
inboxTooltip: 'Inbox: Unclassified TODOs, i.e. without a date; without an Action Tag and a Context; without someday/maybe tag.',
overdueTooltip: 'Overdue: Past the TODO\'s date.',
todayTooltip: 'Today: Scheduled for Today',
scheduledTooltip: 'Scheduled: Scheduled for a future date',
stakeholderTooltip: 'Context Actions: Only TODOs that have a valid Context (Person, Project, Location) and a valid Action Tag appear here.',
contextActionTooltip: 'Context Actions: Only TODOs that have a valid Context (Person, Project, Location) and a valid Action Tag appear here.',
somedayTooltip: 'Someday / Maybe',
}

Expand Down Expand Up @@ -339,18 +339,18 @@ export class ActionTrackerSettingTab extends PluginSettingTab {
new Setting(containerEl)
.setName('Show/hide Context Actions')
.addToggle(value => value
.setValue(this.plugin.settings.isStakeholderVisible)
.setValue(this.plugin.settings.isContextActionVisible)
.onChange(async (value) => {
this.plugin.settings.isStakeholderVisible = value;
this.plugin.settings.isContextActionVisible = value;
await this.plugin.saveViewDisplaySettings();
}));
new Setting(containerEl)
.setName('Context Actions tooltip')
.addTextArea(text => {
let t = text.setPlaceholder(DEFAULT_SETTINGS.stakeholderTooltip)
.setValue(this.plugin.settings.stakeholderTooltip)
let t = text.setPlaceholder(DEFAULT_SETTINGS.contextActionTooltip)
.setValue(this.plugin.settings.contextActionTooltip)
.onChange(async (value) => {
this.plugin.settings.stakeholderTooltip = value == '' ? DEFAULT_SETTINGS.stakeholderTooltip : value;
this.plugin.settings.contextActionTooltip = value == '' ? DEFAULT_SETTINGS.contextActionTooltip : value;
await this.plugin.saveViewDisplaySettings();
});
t.inputEl.setAttr("rows", 4);
Expand Down
65 changes: 32 additions & 33 deletions src/ui/TodoItemView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ export enum TodoItemViewPane {
Scheduled,
Inbox,
Someday,
Stakeholder,
ContextAction,
}

enum TodoSortStates {
None,
DateAsc,
DateDesc,
StakeholderAsc,
StakeholderDesc,
ContextActionAsc,
ContextActionDesc,
ProjectAsc,
ProjectDesc,
MiscAsc,
Expand All @@ -27,21 +27,21 @@ enum TodoSortStates {
}

export interface TodoItemViewProps {
todos: TodoItem[];
openFile: (filePath: string) => void;
toggleTodo: (todo: TodoItem, newStatus: TodoItemStatus) => void;
isInboxVisible: boolean;
isOverdueVisible: boolean;
isTodayVisible: boolean;
isScheduledVisible: boolean;
isStakeholderVisible: boolean;
isSomedayVisible: boolean;
inboxTooltip: string;
overdueTooltip: string;
todayTooltip: string;
scheduledTooltip: string;
stakeholderTooltip: string;
somedayTooltip: string;
todos: TodoItem[];
openFile: (filePath: string) => void;
toggleTodo: (todo: TodoItem, newStatus: TodoItemStatus) => void;
isInboxVisible: boolean;
isOverdueVisible: boolean;
isTodayVisible: boolean;
isScheduledVisible: boolean;
isContextActionVisible: boolean;
isSomedayVisible: boolean;
inboxTooltip: string;
overdueTooltip: string;
todayTooltip: string;
scheduledTooltip: string;
contextActionTooltip: string;
somedayTooltip: string;
}

interface TodoItemViewState {
Expand All @@ -61,7 +61,6 @@ export class TodoItemView extends ItemView {
private sortStateCount;

constructor(leaf: WorkspaceLeaf, props: TodoItemViewProps) {
//debugger;
super(leaf);
this.props = props;
this.state = {
Expand Down Expand Up @@ -95,13 +94,13 @@ export class TodoItemView extends ItemView {
this.props.isOverdueVisible = props.isOverdueVisible;
this.props.isTodayVisible = props.isTodayVisible;
this.props.isScheduledVisible = props.isScheduledVisible;
this.props.isStakeholderVisible = props.isStakeholderVisible;
this.props.isContextActionVisible = props.isContextActionVisible;
this.props.isSomedayVisible = props.isSomedayVisible;
this.props.inboxTooltip = props.inboxTooltip;
this.props.overdueTooltip = props.overdueTooltip;
this.props.todayTooltip = props.todayTooltip;
this.props.scheduledTooltip = props.scheduledTooltip;
this.props.stakeholderTooltip = props.stakeholderTooltip;
this.props.contextActionTooltip = props.contextActionTooltip;
this.props.somedayTooltip = props.somedayTooltip;
this.render();
}
Expand All @@ -115,8 +114,8 @@ export class TodoItemView extends ItemView {
this.state = newState;
if(newState.activePane == TodoItemViewPane.Overdue || newState.activePane == TodoItemViewPane.Scheduled || newState.activePane == TodoItemViewPane.Today)
this.sortState = {state: TodoSortStates.DateAsc};
else if (newState.activePane == TodoItemViewPane.Stakeholder)
this.sortState = {state: TodoSortStates.StakeholderAsc};
else if (newState.activePane == TodoItemViewPane.ContextAction)
this.sortState = {state: TodoSortStates.ContextActionAsc};
else
this.sortState = {state: TodoSortStates.FullTextAsc};
this.render();
Expand Down Expand Up @@ -173,9 +172,9 @@ export class TodoItemView extends ItemView {
return 'Sort by: Action Date Descending';
case TodoSortStates.DateAsc:
return 'Sort by: Action Date Ascending';
case TodoSortStates.StakeholderDesc:
case TodoSortStates.ContextActionDesc:
return 'Sort by: Person Descending';
case TodoSortStates.StakeholderAsc:
case TodoSortStates.ContextActionAsc:
return 'Sort by: Person Ascending';
case TodoSortStates.ProjectDesc:
return 'Sort by: Project Descending';
Expand Down Expand Up @@ -246,10 +245,10 @@ export class TodoItemView extends ItemView {
el.onClickEvent(() => setActivePane(TodoItemViewPane.Scheduled));
});

if (this.props.isStakeholderVisible)
container.createDiv(`todo-item-view-toolbar-item${activeClass(TodoItemViewPane.Stakeholder)}`, (el) => {
el.appendChild(RenderIcon(Icon.Stakeholder, this.props.stakeholderTooltip));
el.onClickEvent(() => setActivePane(TodoItemViewPane.Stakeholder));
if (this.props.isContextActionVisible)
container.createDiv(`todo-item-view-toolbar-item${activeClass(TodoItemViewPane.ContextAction)}`, (el) => {
el.appendChild(RenderIcon(Icon.ContextAction, this.props.contextActionTooltip));
el.onClickEvent(() => setActivePane(TodoItemViewPane.ContextAction));
});

if (this.props.isSomedayVisible)
Expand Down Expand Up @@ -310,9 +309,9 @@ export class TodoItemView extends ItemView {
sortResult = a.actionDate < b.actionDate ? -1 : a.actionDate > b.actionDate ? 1 : 0;break;
case TodoSortStates.DateDesc:
sortResult = a.actionDate > b.actionDate ? -1 : a.actionDate < b.actionDate ? 1 : 0;break;
case TodoSortStates.StakeholderAsc:
case TodoSortStates.ContextActionAsc:
sortResult = a.person < b.person ? -1 : a.person > b.person ? 1 : 0;break;
case TodoSortStates.StakeholderDesc:
case TodoSortStates.ContextActionDesc:
sortResult = a.person > b.person ? -1 : a.person < b.person ? 1 : 0;break;
case TodoSortStates.ProjectAsc:
sortResult = a.project < b.project ? -1 : a.project > b.project ? 1 : 0;break;
Expand All @@ -328,7 +327,7 @@ export class TodoItemView extends ItemView {
sortResult = a.description.toLowerCase() > b.description.toLowerCase() ? -1 : a.description.toLowerCase() < b.description.toLowerCase() ? 1 : 0;break;
}

if (this.state.activePane == TodoItemViewPane.Stakeholder) {
if (this.state.activePane == TodoItemViewPane.ContextAction) {
if (a.isDiscussWithNote && !b.isDiscussWithNote) {
return -1;
}
Expand Down Expand Up @@ -391,7 +390,7 @@ export class TodoItemView extends ItemView {
return isTodayNote;
case TodoItemViewPane.Overdue:
return isOverdueNote;
case TodoItemViewPane.Stakeholder:
case TodoItemViewPane.ContextAction:
return hasContext && isPeopleActionNote ;
}
} else return false;
Expand Down
Loading

0 comments on commit d72a993

Please sign in to comment.