Skip to content
Open
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
203 changes: 90 additions & 113 deletions src/gui/ChoiceBuilder/captureChoiceBuilder.ts

Large diffs are not rendered by default.

59 changes: 29 additions & 30 deletions src/gui/ChoiceBuilder/choiceBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type IChoice from "../../types/choices/IChoice";
import type { FileViewMode2, OpenLocation } from "../../types/fileOpening";
import GenericInputPrompt from "../GenericInputPrompt/GenericInputPrompt";
import { GenericTextSuggester } from "../suggesters/genericTextSuggester";
import { t } from "../../i18n/i18n";

export abstract class ChoiceBuilder extends Modal {
private resolvePromise: (input: IChoice) => void;
Expand Down Expand Up @@ -36,15 +37,13 @@ export abstract class ChoiceBuilder extends Modal {

protected addOnePageOverrideSetting(choice: IChoice): void {
new Setting(this.contentEl)
.setName("One-page input override")
.setDesc(
"Override the global setting for this choice. 'Always' forces the one-page modal even if disabled globally; 'Never' disables it even if enabled globally.",
)
.setName(t("builder.one_page_override.name"))
.setDesc(t("builder.one_page_override.desc"))
.addDropdown((dropdown) => {
dropdown.addOptions({
"": "Follow global setting",
always: "Always",
never: "Never",
"": t("builder.one_page_override.follow"),
always: t("builder.one_page_override.always"),
never: t("builder.one_page_override.never"),
});
dropdown.setValue((choice.onePageInput ?? "") as string);
dropdown.onChange((val: string) => {
Expand All @@ -60,7 +59,7 @@ export abstract class ChoiceBuilder extends Modal {
): void {
setting.addSearch((searchComponent) => {
searchComponent.setValue(value);
searchComponent.setPlaceholder("File path");
searchComponent.setPlaceholder(t("builder.file_path_placeholder"));

const markdownFiles: string[] = this.app.vault
.getMarkdownFiles()
Expand Down Expand Up @@ -88,7 +87,7 @@ export abstract class ChoiceBuilder extends Modal {
const newName: string = await GenericInputPrompt.Prompt(
this.app,
choice.name,
"Choice name",
t("builder.choice_name"),
choice.name,
);
if (newName !== choice.name) {
Expand All @@ -111,7 +110,7 @@ export abstract class ChoiceBuilder extends Modal {
if (choice.openFile === undefined) return; // Guard: nothing to configure

new Setting(this.contentEl)
.setName("Open")
.setName(t("builder.open"))
.setDesc(description)
.addToggle((toggle) => {
toggle.setValue(choice.openFile);
Expand Down Expand Up @@ -149,16 +148,16 @@ export abstract class ChoiceBuilder extends Modal {

// Location selector
new Setting(this.contentEl)
.setName("File Opening Location")
.setDesc(`Where to open the ${contextLabel} file`)
.setName(t("builder.location"))
.setDesc(t("builder.descriptions.location"))
.addDropdown((dropdown) => {
dropdown.addOptions({
reuse: "Reuse current tab",
tab: "New tab",
split: "Split pane",
window: "New window",
"left-sidebar": "Left sidebar",
"right-sidebar": "Right sidebar",
reuse: t("builder.options.reuse"),
tab: t("builder.options.tab"),
split: t("builder.options.split"),
window: t("builder.options.window"),
"left-sidebar": t("builder.options.left"),
"right-sidebar": t("builder.options.right"),
});
dropdown.setValue(fileOpening.location);
dropdown.onChange((value: any) => {
Expand All @@ -170,12 +169,12 @@ export abstract class ChoiceBuilder extends Modal {
// Split direction – only if location === "split"
if (fileOpening.location === "split") {
new Setting(this.contentEl)
.setName("Split Direction")
.setDesc("Direction for split panes")
.setName(t("builder.split_direction"))
.setDesc(t("builder.descriptions.split"))
.addDropdown((dropdown) => {
dropdown.addOptions({
vertical: "Vertical",
horizontal: "Horizontal",
vertical: t("builder.options.vertical"),
horizontal: t("builder.options.horizontal"),
});
dropdown.setValue(fileOpening.direction);
dropdown.onChange((value: any) => {
Expand All @@ -186,14 +185,14 @@ export abstract class ChoiceBuilder extends Modal {

// View mode selector
new Setting(this.contentEl)
.setName("View Mode")
.setDesc("How to display the opened file")
.setName(t("builder.viewMode"))
.setDesc(t("builder.descriptions.view_mode"))
.addDropdown((dropdown) => {
dropdown.addOptions({
source: "Source",
preview: "Preview",
live: "Live Preview",
default: "Default",
source: t("builder.options.source"),
preview: t("builder.options.preview"),
live: t("builder.options.live"),
default: t("builder.options.default"),
});
dropdown.setValue(
typeof fileOpening.mode === "string"
Expand All @@ -208,8 +207,8 @@ export abstract class ChoiceBuilder extends Modal {
// Focus toggle – only show for non-reuse locations
if (fileOpening.location !== "reuse") {
new Setting(this.contentEl)
.setName("Focus new pane")
.setDesc("Focus the opened tab immediately after opening")
.setName(t("builder.focus_pane"))
.setDesc(t("builder.descriptions.focus"))
.addToggle((toggle) =>
toggle.setValue(fileOpening.focus).onChange((value) => {
fileOpening.focus = value;
Expand Down
83 changes: 40 additions & 43 deletions src/gui/ChoiceBuilder/templateChoiceBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { ExclusiveSuggester } from "../suggesters/exclusiveSuggester";
import { FormatSyntaxSuggester } from "../suggesters/formatSyntaxSuggester";
import { ChoiceBuilder } from "./choiceBuilder";
import FolderList from "./FolderList.svelte";
import { t } from "../../i18n/i18n";

export class TemplateChoiceBuilder extends ChoiceBuilder {
choice: ITemplateChoice;
Expand All @@ -48,22 +49,22 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {
this.addCenteredChoiceNameHeader(this.choice);

// Template
new Setting(this.contentEl).setName("Template").setHeading();
new Setting(this.contentEl).setName(t("builder.common.template")).setHeading();
this.addTemplatePathSetting();
this.addFileNameFormatSetting();

// Location
new Setting(this.contentEl).setName("Location").setHeading();
new Setting(this.contentEl).setName(t("builder.common.location")).setHeading();
this.addFolderSetting();

// Linking
new Setting(this.contentEl).setName("Linking").setHeading();
new Setting(this.contentEl).setName(t("builder.common.linking")).setHeading();
this.addAppendLinkSetting();

// Behavior
new Setting(this.contentEl).setName("Behavior").setHeading();
new Setting(this.contentEl).setName(t("builder.common.behavior")).setHeading();
this.addFileAlreadyExistsSetting();
this.addOpenFileSetting("Open the created file.");
this.addOpenFileSetting(t("builder.descriptions.location"));
if (this.choice.openFile) {
this.addFileOpeningSetting("created");
}
Expand All @@ -72,8 +73,8 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {

private addTemplatePathSetting(): void {
new Setting(this.contentEl)
.setName("Template Path")
.setDesc("Path to the Template.");
.setName(t("builder.template.path"))
.setDesc(t("builder.template.path_desc"));

const templates: string[] = this.plugin
.getTemplateFiles()
Expand All @@ -83,7 +84,7 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {
app: this.app,
parent: this.contentEl,
initialValue: this.choice.templatePath,
placeholder: "Template path",
placeholder: t("builder.template.path"),
suggestions: templates,
maxSuggestions: 50,
validator: (raw) => {
Expand All @@ -101,7 +102,7 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {
let textField: TextComponent;
const enableSetting = new Setting(this.contentEl);
enableSetting
.setName("File name format")
.setName(t("builder.template.file_name_format"))
.setDesc("Set the file name format.")
.addToggle((toggleComponent) => {
toggleComponent
Expand All @@ -114,24 +115,24 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {

// Desc + preview row
const previewRow = this.contentEl.createDiv({ cls: "qa-preview-row" });
previewRow.createEl("span", { text: "Preview: ", cls: "qa-preview-label" });
previewRow.createEl("span", { text: t("builder.common.preview"), cls: "qa-preview-label" });
const formatDisplay = previewRow.createEl("span");
formatDisplay.setAttr("aria-live", "polite");
const displayFormatter: FileNameDisplayFormatter =
new FileNameDisplayFormatter(this.app, this.plugin);
formatDisplay.textContent = "Loading preview…";
formatDisplay.textContent = t("builder.common.loading");
void (async () => {
try {
formatDisplay.textContent = await displayFormatter.format(
this.choice.fileNameFormat.format,
);
} catch {
formatDisplay.textContent = "Preview unavailable";
formatDisplay.textContent = t("builder.common.unavailable");
}
})();

const formatInput = new TextComponent(this.contentEl);
formatInput.setPlaceholder("File name format");
formatInput.setPlaceholder(t("builder.template.file_name_format"));
textField = formatInput;
formatInput.inputEl.style.width = "100%";
formatInput.inputEl.style.marginBottom = "8px";
Expand All @@ -144,7 +145,7 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {
try {
formatDisplay.textContent = await displayFormatter.format(value);
} catch {
formatDisplay.textContent = "Preview unavailable";
formatDisplay.textContent = t("builder.common.unavailable");
}
});

Expand All @@ -154,10 +155,8 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {
private addFolderSetting(): void {
const folderSetting: Setting = new Setting(this.contentEl);
folderSetting
.setName("Create in folder")
.setDesc(
"Create the file in the specified folder. If multiple folders are specified, you will be prompted for which folder to create the file in.",
)
.setName(t("builder.template.folder"))
.setDesc(t("builder.template.folder_desc"))
.addToggle((toggle) => {
toggle.setValue(this.choice.folder.enabled);
toggle.onChange((value) => {
Expand All @@ -175,7 +174,7 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {
"chooseFolderWhenCreatingNoteContainer",
);
chooseFolderWhenCreatingNoteContainer.createEl("span", {
text: "Choose folder when creating a new note",
text: t("builder.template.choose_folder"),
});
const chooseFolderWhenCreatingNote: ToggleComponent = new ToggleComponent(
chooseFolderWhenCreatingNoteContainer,
Expand All @@ -196,7 +195,7 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {

const stn = new Setting(chooseFolderFromSubfolderContainer);
stn
.setName("Include subfolders")
.setName(t("builder.template.include_subfolders"))
.setDesc(
"Get prompted to choose from both the selected folders and their subfolders when creating the note.",
)
Expand All @@ -215,7 +214,7 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {
this.contentEl,
);
createInSameFolderAsActiveFileSetting
.setName("Create in same folder as active file")
.setName(t("builder.template.same_folder"))
.setDesc(
"Creates the file in the same folder as the currently active file. Will not create the file if there is no active file.",
)
Expand Down Expand Up @@ -316,12 +315,12 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {

const appendLinkSetting: Setting = new Setting(this.contentEl);
appendLinkSetting
.setName("Link to created file")
.setDesc("Choose how QuickAdd should insert a link to the created file in the current note.")
.setName(t("builder.append_link.name"))
.setDesc(t("builder.append_link.desc"))
.addDropdown((dropdown) => {
dropdown.addOption("required", "Enabled (requires active file)");
dropdown.addOption("optional", "Enabled (skip if no active file)");
dropdown.addOption("disabled", "Disabled");
dropdown.addOption("required", t("builder.append_link.options.required"));
dropdown.addOption("optional", t("builder.append_link.options.optional"));
dropdown.addOption("disabled", t("builder.append_link.options.disabled"));

dropdown.setValue(currentMode);
dropdown.onChange((value: AppendLinkMode) => {
Expand Down Expand Up @@ -354,13 +353,13 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {
if (currentMode !== "disabled") {
const placementSetting: Setting = new Setting(this.contentEl);
placementSetting
.setName("Link placement")
.setName(t("builder.append_link.placement"))
.setDesc("Where to place the link when appending")
.addDropdown((dropdown) => {
dropdown.addOption("replaceSelection", "Replace selection");
dropdown.addOption("afterSelection", "After selection");
dropdown.addOption("endOfLine", "End of line");
dropdown.addOption("newLine", "New line");
dropdown.addOption("replaceSelection", t("builder.append_link.options.replace"));
dropdown.addOption("afterSelection", t("builder.append_link.options.after"));
dropdown.addOption("endOfLine", t("builder.append_link.options.eol"));
dropdown.addOption("newLine", t("builder.append_link.options.newline"));

dropdown.setValue(normalizedOptions.placement);
dropdown.onChange((value: LinkPlacement) => {
Expand Down Expand Up @@ -390,11 +389,11 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {
if (placementSupportsEmbed(normalizedOptions.placement)) {
const linkTypeSetting: Setting = new Setting(this.contentEl);
linkTypeSetting
.setName("Link type")
.setName(t("builder.append_link.type"))
.setDesc("Choose whether replacing the selection should insert a link or an embed.")
.addDropdown((dropdown) => {
dropdown.addOption("link", "Link");
dropdown.addOption("embed", "Embed");
dropdown.addOption("link", t("builder.append_link.options.link"));
dropdown.addOption("embed", t("builder.append_link.options.embed"));
dropdown.setValue(normalizedLinkType);
dropdown.onChange((value: LinkType) => {
const currentValue = this.choice.appendLink;
Expand Down Expand Up @@ -422,10 +421,8 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {
private addFileAlreadyExistsSetting(): void {
const fileAlreadyExistsSetting: Setting = new Setting(this.contentEl);
fileAlreadyExistsSetting
.setName("Set default behavior if file already exists")
.setDesc(
"Set default behavior rather then prompting user on what to do if a file already exists.",
)
.setName(t("builder.template.conflict"))
.setDesc(t("builder.template.conflict_desc"))
.addToggle((toggle) => {
toggle.setValue(this.choice.setFileExistsBehavior);
toggle.onChange((value) => {
Expand All @@ -439,11 +436,11 @@ export class TemplateChoiceBuilder extends ChoiceBuilder {
this.choice.fileExistsMode = fileExistsDoNothing;

dropdown
.addOption(fileExistsAppendToBottom, fileExistsAppendToBottom)
.addOption(fileExistsAppendToTop, fileExistsAppendToTop)
.addOption(fileExistsIncrement, fileExistsIncrement)
.addOption(fileExistsOverwriteFile, fileExistsOverwriteFile)
.addOption(fileExistsDoNothing, fileExistsDoNothing)
.addOption(fileExistsAppendToBottom, t("builder.template.conflict_options.append_bottom"))
.addOption(fileExistsAppendToTop, t("builder.template.conflict_options.append_top"))
.addOption(fileExistsIncrement, t("builder.template.conflict_options.increment"))
.addOption(fileExistsOverwriteFile, t("builder.template.conflict_options.overwrite"))
.addOption(fileExistsDoNothing, t("builder.template.conflict_options.nothing"))
.setValue(this.choice.fileExistsMode)
.onChange(
(value: (typeof fileExistsChoices)[number]) =>
Expand Down
11 changes: 6 additions & 5 deletions src/gui/MacroGUIs/MacroBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import type { IConditionalCommand } from "../../types/macros/Conditional/IConditionalCommand";
import { ConditionalCommandSettingsModal } from "./ConditionalCommandSettingsModal";
import { ConditionalBranchEditorModal } from "./ConditionalBranchEditorModal";
import { t } from "../../i18n/i18n";

function getChoicesAsList(nestedChoices: IChoice[]): IChoice[] {
const arr: IChoice[] = [];
Expand Down Expand Up @@ -83,7 +84,7 @@ export class MacroBuilder extends Modal {
headerEl.addEventListener("click", async () => {
const newName: string = await GenericInputPrompt.Prompt(
this.app,
`Update name for ${this.choice.name}`,
`${t("macro.renaming")} ${this.choice.name}`,
this.choice.name,
this.choice.name
);
Expand All @@ -98,8 +99,8 @@ export class MacroBuilder extends Modal {

private addRunOnStartupSetting(): void {
new Setting(this.contentEl)
.setName("Run on startup")
.setDesc("Execute this macro when Obsidian starts")
.setName(t("macro.run_on_startup"))
.setDesc(t("macro.run_on_startup_desc"))
.addToggle(toggle => toggle
.setValue(this.choice.runOnStartup)
.onChange(value => {
Expand Down Expand Up @@ -153,12 +154,12 @@ export class MacroBuilder extends Modal {
command: IConditionalCommand,
branch: "then" | "else"
): Promise<boolean> {
const title = branch === "then" ? "Then branch" : "Else branch";
const title = branch === "then" ? t("macro.branches.then") : t("macro.branches.else");
const modal = new ConditionalBranchEditorModal({
app: this.app,
plugin: this.plugin,
choices: this.choices,
title: `Edit ${title} commands`,
title: `${t("macro.branches.edit")} ${title}`,
commands: branch === "then" ? command.thenCommands : command.elseCommands,
conditionalHandlers: this.buildConditionalHandlers(),
});
Expand Down
Loading