From 3f659d13639db5ba1b59eff371858b5e0c4d5db9 Mon Sep 17 00:00:00 2001
From: poanse <50020771+poanse@users.noreply.github.com>
Date: Fri, 17 Apr 2026 01:09:02 +0300
Subject: [PATCH] changed logo, added folder setting
---
src/Constants.ts | 12 ++++
src/Context.svelte.ts | 39 +++++++++----
src/IconService.ts | 12 ----
src/TaskmapSettingTab.ts | 24 +++++++-
...apPluginSettings.ts => TaskmapSettings.ts} | 6 +-
src/components/Button.svelte | 2 +-
src/components/TaskText.svelte | 2 +-
src/components/Toolbar.svelte | 2 +-
src/helpers/FolderSuggest.ts | 56 +++++++++++++++++++
src/{ => helpers}/LinkSuggest.ts | 8 +--
src/{Custom.js => helpers/svelte.js} | 0
src/main.ts | 11 ++--
12 files changed, 135 insertions(+), 39 deletions(-)
delete mode 100644 src/IconService.ts
rename src/{TaskmapPluginSettings.ts => TaskmapSettings.ts} (50%)
create mode 100644 src/helpers/FolderSuggest.ts
rename src/{ => helpers}/LinkSuggest.ts (93%)
rename src/{Custom.js => helpers/svelte.js} (100%)
diff --git a/src/Constants.ts b/src/Constants.ts
index 6bc7f58..35e47e5 100644
--- a/src/Constants.ts
+++ b/src/Constants.ts
@@ -26,3 +26,15 @@ export function parseNumber(value: string | null | undefined): number | null {
const num = Number(value);
return isNaN(num) || value.trim() === "" ? null : num;
}
+
+export const LOGO_NAME = "TaskmapLogo";
+
+export const LOGO_CONTENT = `
+
+
+
+
+
+
+
+`;
diff --git a/src/Context.svelte.ts b/src/Context.svelte.ts
index 22001d0..fbf9d9e 100644
--- a/src/Context.svelte.ts
+++ b/src/Context.svelte.ts
@@ -88,7 +88,10 @@ export class Context {
* so pan/zoom and the scene stay intact.
*/
public reloadFromDisk(projectData: ProjectData): void {
- this.versionedData = new VersionedData(projectData, new HistoryManager());
+ this.versionedData = new VersionedData(
+ projectData,
+ new HistoryManager(),
+ );
this.taskDraggingManager.reset();
this.draggedTaskId = NoTaskId;
this.reparentingTaskId = NoTaskId;
@@ -409,7 +412,8 @@ export class Context {
public save() {
// Cannot have reference to the view, so save all opened views
- this.app.workspace.getLeavesOfType(TASKMAP_VIEW_TYPE)
+ this.app.workspace
+ .getLeavesOfType(TASKMAP_VIEW_TYPE)
.map((leaf) => leaf.view)
.filter((view) => view instanceof TaskmapView)
.forEach((view) => view.debouncedSave());
@@ -483,10 +487,18 @@ export class Context {
* Creates note named after task name if not exists already.
* Changes task name to a link to the node.
* Opens the note on the right side.
- * @param taskId
*/
- public async createLinkedNote(taskId: TaskId) {
- const filepath = this.filePathFromTask(taskId);
+ public async createLinkedNote(taskId: TaskId, plugin: TaskmapPlugin) {
+ const taskmapPath =
+ plugin.app.workspace.getActiveViewOfType(TaskmapView)?.file?.parent
+ ?.path;
+ let folderPath = "";
+ if (plugin.settings.newNoteFolder) {
+ folderPath = plugin.settings.newNoteFolder;
+ } else if (taskmapPath) {
+ folderPath = taskmapPath;
+ }
+ const filepath = this.filePathFromTask(taskId, folderPath);
try {
const abstractFile = this.app.vault.getAbstractFileByPath(filepath);
@@ -499,7 +511,7 @@ export class Context {
);
this.versionedData.setName(
taskId,
- tasknameFromFilePath(filepath),
+ tasknameFromFilePath(this.versionedData.getTask(taskId).name),
filepath,
);
this.save();
@@ -509,19 +521,25 @@ export class Context {
await this.openOrFocusNote(tfile);
} catch (error) {
new Notice(
- "Error creating note. It might already exist or the name is invalid.",
+ `Error creating note. It might already exist or the name is invalid. ${String(error)}`,
);
console.error(error);
}
}
- public filePathFromTask(taskId: TaskId) {
+ public filePathFromTask(taskId: TaskId, folder: string = "") {
const task = this.versionedData.getTask(taskId);
const taskName = task.name;
// Sanitize the name for Obsidian filenames
let sanitizedName = taskName.replace(/[\\/:*?"<>|]/g, "-");
sanitizedName = delink(sanitizedName);
- return `${sanitizedName}.md`;
+ if (folder === "" || folder === "/") {
+ return `${sanitizedName}.md`;
+ }
+ if (!folder.endsWith("/")) {
+ folder = folder + "/";
+ }
+ return `${folder}${sanitizedName}.md`;
}
/**
@@ -569,7 +587,8 @@ export class Context {
const candidateLeaves = rootLeaves
.reverse()
.filter(
- (leaf) => leaf !== activeLeaf && !(leaf.view instanceof TaskmapView),
+ (leaf) =>
+ leaf !== activeLeaf && !(leaf.view instanceof TaskmapView),
);
let anotherUnpinnedLeaf: WorkspaceLeaf | null = null;
diff --git a/src/IconService.ts b/src/IconService.ts
deleted file mode 100644
index 2089af4..0000000
--- a/src/IconService.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import { IconCode, StatusCode } from "./types";
-
-export const LOGO_NAME = "TaskmapLogo";
-export const LOGO_CONTENT = `
-
-
-
-
-`;
-
-export const LOGO_CONTENT_SMALL = `
-`;
diff --git a/src/TaskmapSettingTab.ts b/src/TaskmapSettingTab.ts
index 027f83a..f4d8f4b 100644
--- a/src/TaskmapSettingTab.ts
+++ b/src/TaskmapSettingTab.ts
@@ -1,5 +1,6 @@
-import { PluginSettingTab, App, Setting } from "obsidian";
+import { PluginSettingTab, App, Setting, TFolder, Notice } from "obsidian";
import type TaskmapPlugin from "./main";
+import { FolderSuggest } from "./helpers/FolderSuggest";
export class TaskmapSettingTab extends PluginSettingTab {
plugin: TaskmapPlugin;
@@ -38,5 +39,26 @@ export class TaskmapSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
}),
);
+ new Setting(containerEl)
+ .setName("Note folder")
+ .setDesc(
+ "Notes created from tasks will be placed in this folder. If blank, they will be placed in the default location for this vault.",
+ )
+ .addText((text) => {
+ new FolderSuggest(this.app, text.inputEl);
+ text.setPlaceholder("")
+ .setValue(this.plugin.settings.newNoteFolder)
+ .onChange(async (value) => {
+ if (
+ value === "" ||
+ this.plugin.app.vault.getAbstractFileByPath(
+ value,
+ ) instanceof TFolder
+ ) {
+ this.plugin.settings.newNoteFolder = value;
+ await this.plugin.saveSettings();
+ }
+ });
+ });
}
}
diff --git a/src/TaskmapPluginSettings.ts b/src/TaskmapSettings.ts
similarity index 50%
rename from src/TaskmapPluginSettings.ts
rename to src/TaskmapSettings.ts
index bf28dad..56623ff 100644
--- a/src/TaskmapPluginSettings.ts
+++ b/src/TaskmapSettings.ts
@@ -1,9 +1,11 @@
-export interface TaskmapPluginSettings {
+export interface TaskmapSettings {
zoomSensitivityTouchpad: string;
zoomSensitivityMouse: string;
+ newNoteFolder: string;
}
-export const DEFAULT_SETTINGS: TaskmapPluginSettings = {
+export const DEFAULT_SETTINGS: TaskmapSettings = {
zoomSensitivityTouchpad: "100",
zoomSensitivityMouse: "100",
+ newNoteFolder: "",
};
diff --git a/src/components/Button.svelte b/src/components/Button.svelte
index 02574cc..366b8a1 100644
--- a/src/components/Button.svelte
+++ b/src/components/Button.svelte
@@ -89,7 +89,7 @@
} else if (iconCode == IconCode.REMOVE_MULTIPLE) {
context.removeTaskBranch(context.selectedTaskId);
} else if (iconCode == IconCode.CREATE_LINKED_NOTE) {
- context.createLinkedNote(context.selectedTaskId);
+ context.createLinkedNote(context.selectedTaskId, context.plugin);
} else if (iconCode == IconCode.KEY) {
context.chosenBlockedId = context.chosenBlockedId === NoTaskId ? context.selectedTaskId : NoTaskId;
} else if (iconCode == IconCode.LOCK) {
diff --git a/src/components/TaskText.svelte b/src/components/TaskText.svelte
index 5dfd0bf..22fbf89 100644
--- a/src/components/TaskText.svelte
+++ b/src/components/TaskText.svelte
@@ -1,7 +1,7 @@