Skip to content

Commit

Permalink
Merge pull request #37 from terryli710/hotfixes/issue31-34
Browse files Browse the repository at this point in the history
Hotfixes/issue31 34
  • Loading branch information
terryli710 authored Sep 13, 2023
2 parents 391490a + b9707a0 commit 86f5dd5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
15 changes: 14 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App, Plugin } from 'obsidian';
import type { Editor, PluginManifest, Workspace, WorkspaceLeaf } from 'obsidian';
import type { Editor, EditorPosition, PluginManifest, Workspace, WorkspaceLeaf } from 'obsidian';
import type { TaskCardSettings } from './settings';
import { DefaultSettings, SettingStore, SettingsTab } from './settings';
import { logger } from './utils/log';
Expand Down Expand Up @@ -121,6 +121,19 @@ export default class TaskCardPlugin extends Plugin {
)
}
})

this.addCommand({
id: 'task-card-add-task',
name: 'Add Task',
editorCallback: (editor: Editor) => {
const editorPos: EditorPosition = editor.getCursor();
editor.replaceRange(
`\n- [ ] #${this.settings.parsingSettings.indicatorTag}\n`,
editorPos
)
editor.setCursor(editor.getCursor().line + 1, 6)
}
})
}

registerPostProcessors() {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/postProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export { TaskItemSvelteAdapter } from './taskItemSvelteAdapter';

export type TaskDisplayMode = 'single-line' | 'multi-line';
export interface TaskDisplayParams {
mode: TaskDisplayMode | null;
mode?: TaskDisplayMode | null;
}


Expand Down
21 changes: 17 additions & 4 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,10 @@ export class SettingsTab extends PluginSettingTab {
if (isEditMode) {
// Save changes
isEditMode = false;
logger.info(`Project updated: ${project.name}`);
new Notice(`[TaskCard] Project updated: ${project.name}.`);
// new Notice(`[TaskCard] Project updated: ${project.name}.`);
const originalProject: Project = this.plugin.projectModule.getProjectById(project.id);
this.announceProjectChange(originalProject, project);
this.plugin.projectModule.updateProject(project);
this.display();
} else if (isDeleteWarning) {
// Cancel delete warning
Expand All @@ -326,6 +328,17 @@ export class SettingsTab extends PluginSettingTab {
// Initialize the UI
updateUI();
}

announceProjectChange(originalProject: Project, newProject: Project) {
// if name changed, if color changed, if name + color changed
if (originalProject.name !== newProject.name && originalProject.color !== newProject.color) {
new Notice(`[TaskCard] Project name and color updated: ${newProject.name}.`);
} else if (originalProject.name !== newProject.name) {
new Notice(`[TaskCard] Project name updated: ${newProject.name}.`);
} else if (originalProject.color !== newProject.color) {
new Notice(`[TaskCard] Project color updated: ${newProject.color}.`);
}
}


cardParsingSettings() {
Expand Down Expand Up @@ -483,8 +496,8 @@ export class SettingsTab extends PluginSettingTab {
.addDropdown((dropdown) => {
dropdown
.addOptions({
'single-line': 'Single Line',
'multi-line': 'Multi Line'
'single-line': 'Preview Mode',
'multi-line': 'Detailed Mode'
})
.setValue(this.plugin.settings.displaySettings.defaultMode)
.onChange(async (value: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/Due.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
logger.error(e);
}
if (!newDue) {
new Notice(`Invalid due date: ${dueString}`);
new Notice(`[TaskCard] Invalid due date: ${dueString}`);
dueString = due ? due.string : '';
} else {
due = newDue;
Expand Down
14 changes: 11 additions & 3 deletions src/ui/TaskItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@
import TaskCard from "./TaskCard.svelte";
import TaskCardPlugin from "..";
import { ObsidianTaskSyncManager } from "../taskModule/taskSyncManager";
import { SettingStore } from "../settings";
export let taskSyncManager: ObsidianTaskSyncManager;
export let plugin: TaskCardPlugin;
// export let defaultParams: TaskDisplayParams;
let params: TaskDisplayParams;
params = { ...taskSyncManager.obsidianTask.metadata.taskDisplayParams };
let params: TaskDisplayParams = { ...taskSyncManager.obsidianTask.metadata.taskDisplayParams };
let defaultMode: TaskDisplayMode = 'single-line';
SettingStore.subscribe(settings => {
defaultMode = settings.displaySettings.defaultMode as TaskDisplayMode;
});
if (!('mode' in params)) {
params.mode = defaultMode
}
// Find the input element with class "task-list-item-checkbox" within taskItemEl
const inputElement = taskSyncManager.taskItemEl.querySelector('input.task-list-item-checkbox');
Expand Down

0 comments on commit 86f5dd5

Please # to comment.