Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 11 additions & 3 deletions src/gui/ChoiceBuilder/choiceBuilder.ts
Comment thread
chhoumann marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type App, Modal, Setting } from "obsidian";
import { type App, Modal, Setting, setIcon } from "obsidian";
import type { SvelteComponent } from "svelte";
import { log } from "../../logger/logManager";
import type IChoice from "../../types/choices/IChoice";
Expand Down Expand Up @@ -85,7 +85,15 @@ export abstract class ChoiceBuilder extends Modal {
const headerEl: HTMLHeadingElement = this.contentEl.createEl("h2", {
cls: "choiceNameHeader",
});
headerEl.setText(choice.name);
const textEl = headerEl.createSpan({
text: choice.name,
cls: "choiceNameHeaderText",
});
const iconEl = headerEl.createSpan({
cls: "choiceNameHeaderIcon",
attr: { "aria-hidden": "true" },
});
setIcon(iconEl, "pencil");

headerEl.addEventListener("click", async (ev) => {
try {
Expand All @@ -97,7 +105,7 @@ export abstract class ChoiceBuilder extends Modal {
);
if (newName !== choice.name) {
choice.name = newName;
headerEl.setText(newName);
textEl.setText(newName);
}
} catch {
log.logMessage(`No new name given for ${choice.name}`);
Expand Down
2 changes: 2 additions & 0 deletions src/gui/choiceList/ChoiceList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
on:configureChoice
on:toggleCommand
on:duplicateChoice
on:renameChoice
on:moveChoice
startDrag={startDrag}
bind:choice
Expand All @@ -86,6 +87,7 @@
on:configureChoice
on:toggleCommand
on:duplicateChoice
on:renameChoice
on:moveChoice
on:reorderChoices
startDrag={startDrag}
Expand Down
1 change: 1 addition & 0 deletions src/gui/choiceList/ChoiceListItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

function onContextMenu(evt: MouseEvent) {
showChoiceContextMenu(app, evt, choice, roots, {
onRename: () => dispatcher("renameChoice", { choice }),
onToggle: () => toggleCommandForChoice(),
onConfigure: () => configureChoice(),
onDuplicate: () => duplicateChoice(),
Expand Down
28 changes: 28 additions & 0 deletions src/gui/choiceList/ChoiceView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import type IChoice from "../../types/choices/IChoice";
import { AIAssistantSettingsModal } from "../AIAssistantSettingsModal";
import ObsidianIcon from "../components/ObsidianIcon.svelte";
import GenericInputPrompt from "../GenericInputPrompt/GenericInputPrompt";
import AddChoiceBox from "./AddChoiceBox.svelte";
import ChoiceList from "./ChoiceList.svelte";
import { moveChoice as moveChoiceService } from "../../services/choiceService";
Expand Down Expand Up @@ -132,6 +133,31 @@
return oldChoice;
}

async function handleRenameChoice(e: any) {
const { choice } = e.detail;
if (!choice) return;

try {
const newName = await GenericInputPrompt.Prompt(
app,
choice.name,
"Choice name",
choice.name,
);
const trimmed = newName.trim();
if (!trimmed || trimmed === choice.name) return;

const updatedChoice = { ...choice, name: trimmed };
choices = choices.map((entry) =>
updateChoiceHelper(entry, updatedChoice),
);
commandRegistry.updateCommand(choice, updatedChoice);
saveChoices(choices);
} catch {
// Swallow cancellation/no input.
}
}

async function toggleCommandForChoice(e: any) {
const { choice: oldChoice } = e.detail;
const updatedChoice = createToggleCommandChoice(oldChoice);
Expand Down Expand Up @@ -209,6 +235,7 @@
on:configureChoice={handleConfigureChoice}
on:toggleCommand={toggleCommandForChoice}
on:duplicateChoice={handleDuplicateChoice}
on:renameChoice={handleRenameChoice}
on:moveChoice={handleMoveChoice}
on:reorderChoices={(e) => saveChoices(e.detail.choices)}
/>
Expand All @@ -223,6 +250,7 @@
on:configureChoice={handleConfigureChoice}
on:toggleCommand={toggleCommandForChoice}
on:duplicateChoice={handleDuplicateChoice}
on:renameChoice={handleRenameChoice}
on:moveChoice={handleMoveChoice}
/>
{/if}
Expand Down
2 changes: 2 additions & 0 deletions src/gui/choiceList/MultiChoiceListItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

function onContextMenu(evt: MouseEvent) {
showChoiceContextMenu(app, evt, choice, roots, {
onRename: () => dispatcher('renameChoice', { choice }),
onToggle: () => toggleCommandForChoice(),
onConfigure: () => configureChoice(),
onDuplicate: () => duplicateChoice(),
Expand Down Expand Up @@ -114,6 +115,7 @@
on:toggleCommand
on:duplicateChoice
on:moveChoice
on:renameChoice
on:reorderChoices={handleNestedReorder}
bind:multiChoice={choice}
bind:choices={choice.choices}
Expand Down
2 changes: 2 additions & 0 deletions src/gui/choiceList/contextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function isInvalidTarget(moving: IChoice, target: IChoice): boolean {
}

type MenuActions = {
onRename: () => void;
onToggle: () => void;
onConfigure: () => void;
onDuplicate: () => void;
Expand Down Expand Up @@ -79,6 +80,7 @@ export function showChoiceContextMenu(
.setIcon("zap")
.onClick(actions.onToggle),
)
.addItem((item) => item.setTitle("Rename").setIcon("pencil").onClick(actions.onRename))
.addItem((item) => item.setTitle("Configure").setIcon("settings").onClick(actions.onConfigure))
.addItem((item) => item.setTitle("Duplicate").setIcon("copy").onClick(actions.onDuplicate))
.addItem((item) => item.setTitle("Delete").setIcon("trash-2").onClick(actions.onDelete))
Expand Down
10 changes: 10 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,22 @@

.choiceNameHeader {
text-align: center;
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
}

.choiceNameHeader:hover {
cursor: pointer;
}

.choiceNameHeaderIcon {
display: inline-flex;
align-items: center;
opacity: 0.5;
}

.folderInputContainer {
display: flex;
align-content: center;
Expand Down