From 160bb0e44356445a68b992e7f66cff0ae5178a2c Mon Sep 17 00:00:00 2001 From: quorafind <951011105@qq.com> Date: Fri, 11 Oct 2024 08:47:06 +0800 Subject: [PATCH 1/4] feat: support new icon-set after obsidian 1.7.3 --- .gitignore | 3 + scripts/esbuild.config.mjs | 6 +- src/constants.ts | 1187 ++++++++++++++++++------------------ src/main.ts | 4 +- src/ui/chooseIconModal.ts | 17 +- 5 files changed, 612 insertions(+), 605 deletions(-) diff --git a/.gitignore b/.gitignore index 37bd35c..c44c74d 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ data.json # Exclude macOS Finder (System Explorer) View States .DS_Store + +# ignore pnpm +pnpm-lock.yaml diff --git a/scripts/esbuild.config.mjs b/scripts/esbuild.config.mjs index 97b326e..9608b05 100644 --- a/scripts/esbuild.config.mjs +++ b/scripts/esbuild.config.mjs @@ -95,15 +95,15 @@ esbuild try { copyFileSync( "styles.css", - "../../vault/.obsidian/plugins/cmdr/styles.css" + "../vault/.obsidian/plugins/cmdr/styles.css" ); copyFileSync( "main.js", - "../../vault/.obsidian/plugins/cmdr/main.js" + "../vault/.obsidian/plugins/cmdr/main.js" ); copyFileSync( "manifest.json", - "../../vault/.obsidian/plugins/cmdr/manifest.json" + "../vault/.obsidian/plugins/cmdr/manifest.json" ); } catch (error) { console.error(error); diff --git a/src/constants.ts b/src/constants.ts index 6f9d09d..a16ba8b 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,3 +1,4 @@ +import { getIconIds, requireApiVersion } from "obsidian"; import { CommanderSettings } from "./types"; export const DEFAULT_SETTINGS: CommanderSettings = { @@ -30,595 +31,597 @@ export const DEFAULT_SETTINGS: CommanderSettings = { }, }; -export const ICON_LIST = [ - "activity", - "airplay", - "alarm-check", - "alarm-clock-off", - "alarm-clock", - "alarm-minus", - "alarm-plus", - "album", - "alert-circle", - "alert-octagon", - "alert-triangle", - "align-center-horizontal", - "align-center-vertical", - "align-center", - "align-end-horizontal", - "align-end-vertical", - "align-horizontal-distribute-center", - "align-horizontal-distribute-end", - "align-horizontal-distribute-start", - "align-horizontal-justify-center", - "align-horizontal-justify-end", - "align-horizontal-justify-start", - "align-horizontal-space-around", - "align-horizontal-space-between", - "align-justify", - "align-left", - "align-right", - "align-start-horizontal", - "align-start-vertical", - "align-vertical-distribute-center", - "align-vertical-distribute-end", - "align-vertical-distribute-start", - "align-vertical-justify-center", - "align-vertical-justify-end", - "align-vertical-justify-start", - "align-vertical-space-around", - "align-vertical-space-between", - "anchor", - "aperture", - "archive", - "arrow-big-down", - "arrow-big-left", - "arrow-big-right", - "arrow-big-up", - "arrow-down-circle", - "arrow-down-left", - "arrow-down-right", - "arrow-down", - "arrow-left-circle", - "arrow-left-right", - "arrow-left", - "arrow-right-circle", - "arrow-right", - "arrow-up-circle", - "arrow-up-left", - "arrow-up-right", - "arrow-up", - "asterisk", - "at-sign", - "award", - "axe", - "banknote", - "bar-chart-2", - "bar-chart", - "baseline", - "battery-charging", - "battery-full", - "battery-low", - "battery-medium", - "battery", - "beaker", - "bell-minus", - "bell-off", - "bell-plus", - "bell-ring", - "bell", - "bike", - "binary", - "bitcoin", - "bluetooth-connected", - "bluetooth-off", - "bluetooth-searching", - "bluetooth", - "bold", - "book-open", - "book", - "bookmark-minus", - "bookmark-plus", - "bookmark", - "bot", - "box-select", - "box", - "briefcase", - "brush", - "bug", - "building-2", - "building", - "bus", - "calculator", - "calendar", - "camera-off", - "camera", - "car", - "carrot", - "cast", - "check-circle-2", - "check-circle", - "check-square", - "check", - "chevron-down", - "chevron-first", - "chevron-last", - "chevron-left", - "chevron-right", - "chevron-up", - "chevrons-down-up", - "chevrons-down", - "chevrons-left", - "chevrons-right", - "chevrons-up-down", - "chevrons-up", - "chrome", - "circle-slashed", - "circle", - "clipboard-check", - "clipboard-copy", - "clipboard-list", - "clipboard-x", - "clipboard", - "clock-1", - "clock-10", - "clock-11", - "clock-12", - "clock-2", - "clock-3", - "clock-4", - "clock-5", - "clock-6", - "clock-7", - "clock-8", - "clock-9", - "lucide-clock", - "cloud-drizzle", - "cloud-fog", - "cloud-hail", - "cloud-lightning", - "cloud-moon", - "cloud-off", - "cloud-rain-wind", - "cloud-rain", - "cloud-snow", - "cloud-sun", - "lucide-cloud", - "cloudy", - "clover", - "code-2", - "code", - "codepen", - "codesandbox", - "coffee", - "coins", - "columns", - "command", - "compass", - "contact", - "contrast", - "cookie", - "copy", - "copyleft", - "copyright", - "corner-down-left", - "corner-down-right", - "corner-left-down", - "corner-left-up", - "corner-right-down", - "corner-right-up", - "corner-up-left", - "corner-up-right", - "cpu", - "credit-card", - "crop", - "lucide-cross", - "crosshair", - "crown", - "currency", - "database", - "delete", - "dice-1", - "dice-2", - "dice-3", - "dice-4", - "dice-5", - "dice-6", - "disc", - "divide-circle", - "divide-square", - "divide", - "dollar-sign", - "download-cloud", - "download", - "dribbble", - "droplet", - "droplets", - "drumstick", - "edit-2", - "edit-3", - "edit", - "egg", - "equal-not", - "equal", - "eraser", - "euro", - "expand", - "external-link", - "eye-off", - "eye", - "facebook", - "fast-forward", - "feather", - "figma", - "file-check-2", - "file-check", - "file-code", - "file-digit", - "file-input", - "file-minus-2", - "file-minus", - "file-output", - "file-plus-2", - "file-plus", - "file-search", - "file-text", - "file-x-2", - "file-x", - "file", - "files", - "film", - "filter", - "flag-off", - "flag-triangle-left", - "flag-triangle-right", - "flag", - "flame", - "flashlight-off", - "flashlight", - "flask-conical", - "flask-round", - "folder-minus", - "folder-open", - "folder-plus", - "lucide-folder", - "form-input", - "forward", - "frame", - "framer", - "frown", - "function-square", - "gamepad-2", - "gamepad", - "gauge", - "gavel", - "gem", - "ghost", - "gift", - "git-branch-plus", - "git-branch", - "git-commit", - "git-fork", - "git-merge", - "git-pull-request", - "github", - "gitlab", - "glasses", - "globe-2", - "globe", - "grab", - "graduation-cap", - "grid", - "grip-horizontal", - "grip-vertical", - "hammer", - "hand-metal", - "hand", - "hard-drive", - "hard-hat", - "hash", - "haze", - "headphones", - "heart", - "help-circle", - "hexagon", - "highlighter", - "history", - "home", - "image-minus", - "image-off", - "image-plus", - "image", - "import", - "inbox", - "indent", - "indian-rupee", - "infinity", - "lucide-info", - "inspect", - "instagram", - "italic", - "japanese-yen", - "key", - "keyboard", - "landmark", - "lucide-languages", - "laptop-2", - "laptop", - "lasso-select", - "lasso", - "layers", - "layout-dashboard", - "layout-grid", - "layout-list", - "layout-template", - "layout", - "library", - "life-buoy", - "lightbulb-off", - "lightbulb", - "link-2-off", - "link-2", - "lucide-link", - "linkedin", - "list-checks", - "list-minus", - "list-ordered", - "list-plus", - "list-x", - "list", - "loader-2", - "loader", - "locate-fixed", - "locate-off", - "locate", - "lock", - "log-in", - "log-out", - "mail", - "map-pin", - "map", - "maximize-2", - "maximize", - "megaphone", - "meh", - "menu", - "message-circle", - "message-square", - "mic-off", - "mic", - "minimize-2", - "minimize", - "minus-circle", - "minus-square", - "minus", - "monitor-off", - "monitor-speaker", - "monitor", - "moon", - "more-horizontal", - "more-vertical", - "mountain-snow", - "mountain", - "mouse-pointer-2", - "mouse-pointer-click", - "mouse-pointer", - "mouse", - "move-diagonal-2", - "move-diagonal", - "move-horizontal", - "move-vertical", - "move", - "music", - "navigation-2", - "navigation", - "network", - "octagon", - "option", - "outdent", - "package-check", - "package-minus", - "package-plus", - "package-search", - "package-x", - "package", - "palette", - "palmtree", - "paperclip", - "pause-circle", - "pause-octagon", - "pause", - "pen-tool", - "lucide-pencil", - "percent", - "person-standing", - "phone-call", - "phone-forwarded", - "phone-incoming", - "phone-missed", - "phone-off", - "phone-outgoing", - "phone", - "pie-chart", - "piggy-bank", - "lucide-pin", - "pipette", - "plane", - "play-circle", - "play", - "plug-zap", - "plus-circle", - "plus-square", - "plus", - "pocket", - "podcast", - "pointer", - "pound-sterling", - "power-off", - "power", - "printer", - "qr-code", - "quote", - "radio-receiver", - "radio", - "redo", - "refresh-ccw", - "refresh-cw", - "regex", - "repeat-1", - "repeat", - "reply-all", - "reply", - "rewind", - "rocket", - "rocking-chair", - "rotate-ccw", - "rotate-cw", - "rss", - "ruler", - "russian-ruble", - "save", - "scale", - "scan-line", - "scan", - "scissors", - "screen-share-off", - "screen-share", - "lucide-search", - "send", - "separator-horizontal", - "separator-vertical", - "server-crash", - "server-off", - "server", - "settings-2", - "settings", - "share-2", - "share", - "sheet", - "shield-alert", - "shield-check", - "shield-close", - "shield-off", - "shield", - "shirt", - "shopping-bag", - "shopping-cart", - "shovel", - "shrink", - "shuffle", - "sidebar-close", - "sidebar-open", - "sidebar", - "sigma", - "signal-high", - "signal-low", - "signal-medium", - "signal-zero", - "signal", - "skip-back", - "skip-forward", - "skull", - "slack", - "slash", - "sliders", - "smartphone-charging", - "smartphone", - "smile", - "snowflake", - "sort-asc", - "sort-desc", - "speaker", - "sprout", - "square", - "star-half", - "lucide-star", - "stop-circle", - "stretch-horizontal", - "stretch-vertical", - "strikethrough", - "subscript", - "sun", - "sunrise", - "sunset", - "superscript", - "swiss-franc", - "switch-camera", - "table", - "tablet", - "tag", - "target", - "tent", - "terminal-square", - "terminal", - "text-cursor-input", - "text-cursor", - "thermometer-snowflake", - "thermometer-sun", - "thermometer", - "thumbs-down", - "thumbs-up", - "ticket", - "timer-off", - "timer-reset", - "timer", - "toggle-left", - "toggle-right", - "tornado", - "trash-2", - "lucide-trash", - "trello", - "trending-down", - "trending-up", - "triangle", - "truck", - "tv-2", - "tv", - "twitch", - "twitter", - "type", - "umbrella", - "underline", - "undo", - "unlink-2", - "unlink", - "unlock", - "upload-cloud", - "upload", - "user-check", - "user-minus", - "user-plus", - "user-x", - "user", - "users", - "verified", - "vibrate", - "video-off", - "video", - "view", - "voicemail", - "volume-1", - "volume-2", - "volume-x", - "volume", - "wallet", - "wand", - "watch", - "waves", - "webcam", - "wifi-off", - "wifi", - "wind", - "wrap-text", - "wrench", - "x-circle", - "x-octagon", - "x-square", - "x", - "youtube", - "zap-off", - "zap", - "zoom-in", - "zoom-out", - "search-large", -]; +export const ICON_LIST = requireApiVersion("1.7.3") + ? getIconIds() + : [ + "activity", + "airplay", + "alarm-check", + "alarm-clock-off", + "alarm-clock", + "alarm-minus", + "alarm-plus", + "album", + "alert-circle", + "alert-octagon", + "alert-triangle", + "align-center-horizontal", + "align-center-vertical", + "align-center", + "align-end-horizontal", + "align-end-vertical", + "align-horizontal-distribute-center", + "align-horizontal-distribute-end", + "align-horizontal-distribute-start", + "align-horizontal-justify-center", + "align-horizontal-justify-end", + "align-horizontal-justify-start", + "align-horizontal-space-around", + "align-horizontal-space-between", + "align-justify", + "align-left", + "align-right", + "align-start-horizontal", + "align-start-vertical", + "align-vertical-distribute-center", + "align-vertical-distribute-end", + "align-vertical-distribute-start", + "align-vertical-justify-center", + "align-vertical-justify-end", + "align-vertical-justify-start", + "align-vertical-space-around", + "align-vertical-space-between", + "anchor", + "aperture", + "archive", + "arrow-big-down", + "arrow-big-left", + "arrow-big-right", + "arrow-big-up", + "arrow-down-circle", + "arrow-down-left", + "arrow-down-right", + "arrow-down", + "arrow-left-circle", + "arrow-left-right", + "arrow-left", + "arrow-right-circle", + "arrow-right", + "arrow-up-circle", + "arrow-up-left", + "arrow-up-right", + "arrow-up", + "asterisk", + "at-sign", + "award", + "axe", + "banknote", + "bar-chart-2", + "bar-chart", + "baseline", + "battery-charging", + "battery-full", + "battery-low", + "battery-medium", + "battery", + "beaker", + "bell-minus", + "bell-off", + "bell-plus", + "bell-ring", + "bell", + "bike", + "binary", + "bitcoin", + "bluetooth-connected", + "bluetooth-off", + "bluetooth-searching", + "bluetooth", + "bold", + "book-open", + "book", + "bookmark-minus", + "bookmark-plus", + "bookmark", + "bot", + "box-select", + "box", + "briefcase", + "brush", + "bug", + "building-2", + "building", + "bus", + "calculator", + "calendar", + "camera-off", + "camera", + "car", + "carrot", + "cast", + "check-circle-2", + "check-circle", + "check-square", + "check", + "chevron-down", + "chevron-first", + "chevron-last", + "chevron-left", + "chevron-right", + "chevron-up", + "chevrons-down-up", + "chevrons-down", + "chevrons-left", + "chevrons-right", + "chevrons-up-down", + "chevrons-up", + "chrome", + "circle-slashed", + "circle", + "clipboard-check", + "clipboard-copy", + "clipboard-list", + "clipboard-x", + "clipboard", + "clock-1", + "clock-10", + "clock-11", + "clock-12", + "clock-2", + "clock-3", + "clock-4", + "clock-5", + "clock-6", + "clock-7", + "clock-8", + "clock-9", + "lucide-clock", + "cloud-drizzle", + "cloud-fog", + "cloud-hail", + "cloud-lightning", + "cloud-moon", + "cloud-off", + "cloud-rain-wind", + "cloud-rain", + "cloud-snow", + "cloud-sun", + "lucide-cloud", + "cloudy", + "clover", + "code-2", + "code", + "codepen", + "codesandbox", + "coffee", + "coins", + "columns", + "command", + "compass", + "contact", + "contrast", + "cookie", + "copy", + "copyleft", + "copyright", + "corner-down-left", + "corner-down-right", + "corner-left-down", + "corner-left-up", + "corner-right-down", + "corner-right-up", + "corner-up-left", + "corner-up-right", + "cpu", + "credit-card", + "crop", + "lucide-cross", + "crosshair", + "crown", + "currency", + "database", + "delete", + "dice-1", + "dice-2", + "dice-3", + "dice-4", + "dice-5", + "dice-6", + "disc", + "divide-circle", + "divide-square", + "divide", + "dollar-sign", + "download-cloud", + "download", + "dribbble", + "droplet", + "droplets", + "drumstick", + "edit-2", + "edit-3", + "edit", + "egg", + "equal-not", + "equal", + "eraser", + "euro", + "expand", + "external-link", + "eye-off", + "eye", + "facebook", + "fast-forward", + "feather", + "figma", + "file-check-2", + "file-check", + "file-code", + "file-digit", + "file-input", + "file-minus-2", + "file-minus", + "file-output", + "file-plus-2", + "file-plus", + "file-search", + "file-text", + "file-x-2", + "file-x", + "file", + "files", + "film", + "filter", + "flag-off", + "flag-triangle-left", + "flag-triangle-right", + "flag", + "flame", + "flashlight-off", + "flashlight", + "flask-conical", + "flask-round", + "folder-minus", + "folder-open", + "folder-plus", + "lucide-folder", + "form-input", + "forward", + "frame", + "framer", + "frown", + "function-square", + "gamepad-2", + "gamepad", + "gauge", + "gavel", + "gem", + "ghost", + "gift", + "git-branch-plus", + "git-branch", + "git-commit", + "git-fork", + "git-merge", + "git-pull-request", + "github", + "gitlab", + "glasses", + "globe-2", + "globe", + "grab", + "graduation-cap", + "grid", + "grip-horizontal", + "grip-vertical", + "hammer", + "hand-metal", + "hand", + "hard-drive", + "hard-hat", + "hash", + "haze", + "headphones", + "heart", + "help-circle", + "hexagon", + "highlighter", + "history", + "home", + "image-minus", + "image-off", + "image-plus", + "image", + "import", + "inbox", + "indent", + "indian-rupee", + "infinity", + "lucide-info", + "inspect", + "instagram", + "italic", + "japanese-yen", + "key", + "keyboard", + "landmark", + "lucide-languages", + "laptop-2", + "laptop", + "lasso-select", + "lasso", + "layers", + "layout-dashboard", + "layout-grid", + "layout-list", + "layout-template", + "layout", + "library", + "life-buoy", + "lightbulb-off", + "lightbulb", + "link-2-off", + "link-2", + "lucide-link", + "linkedin", + "list-checks", + "list-minus", + "list-ordered", + "list-plus", + "list-x", + "list", + "loader-2", + "loader", + "locate-fixed", + "locate-off", + "locate", + "lock", + "log-in", + "log-out", + "mail", + "map-pin", + "map", + "maximize-2", + "maximize", + "megaphone", + "meh", + "menu", + "message-circle", + "message-square", + "mic-off", + "mic", + "minimize-2", + "minimize", + "minus-circle", + "minus-square", + "minus", + "monitor-off", + "monitor-speaker", + "monitor", + "moon", + "more-horizontal", + "more-vertical", + "mountain-snow", + "mountain", + "mouse-pointer-2", + "mouse-pointer-click", + "mouse-pointer", + "mouse", + "move-diagonal-2", + "move-diagonal", + "move-horizontal", + "move-vertical", + "move", + "music", + "navigation-2", + "navigation", + "network", + "octagon", + "option", + "outdent", + "package-check", + "package-minus", + "package-plus", + "package-search", + "package-x", + "package", + "palette", + "palmtree", + "paperclip", + "pause-circle", + "pause-octagon", + "pause", + "pen-tool", + "lucide-pencil", + "percent", + "person-standing", + "phone-call", + "phone-forwarded", + "phone-incoming", + "phone-missed", + "phone-off", + "phone-outgoing", + "phone", + "pie-chart", + "piggy-bank", + "lucide-pin", + "pipette", + "plane", + "play-circle", + "play", + "plug-zap", + "plus-circle", + "plus-square", + "plus", + "pocket", + "podcast", + "pointer", + "pound-sterling", + "power-off", + "power", + "printer", + "qr-code", + "quote", + "radio-receiver", + "radio", + "redo", + "refresh-ccw", + "refresh-cw", + "regex", + "repeat-1", + "repeat", + "reply-all", + "reply", + "rewind", + "rocket", + "rocking-chair", + "rotate-ccw", + "rotate-cw", + "rss", + "ruler", + "russian-ruble", + "save", + "scale", + "scan-line", + "scan", + "scissors", + "screen-share-off", + "screen-share", + "lucide-search", + "send", + "separator-horizontal", + "separator-vertical", + "server-crash", + "server-off", + "server", + "settings-2", + "settings", + "share-2", + "share", + "sheet", + "shield-alert", + "shield-check", + "shield-close", + "shield-off", + "shield", + "shirt", + "shopping-bag", + "shopping-cart", + "shovel", + "shrink", + "shuffle", + "sidebar-close", + "sidebar-open", + "sidebar", + "sigma", + "signal-high", + "signal-low", + "signal-medium", + "signal-zero", + "signal", + "skip-back", + "skip-forward", + "skull", + "slack", + "slash", + "sliders", + "smartphone-charging", + "smartphone", + "smile", + "snowflake", + "sort-asc", + "sort-desc", + "speaker", + "sprout", + "square", + "star-half", + "lucide-star", + "stop-circle", + "stretch-horizontal", + "stretch-vertical", + "strikethrough", + "subscript", + "sun", + "sunrise", + "sunset", + "superscript", + "swiss-franc", + "switch-camera", + "table", + "tablet", + "tag", + "target", + "tent", + "terminal-square", + "terminal", + "text-cursor-input", + "text-cursor", + "thermometer-snowflake", + "thermometer-sun", + "thermometer", + "thumbs-down", + "thumbs-up", + "ticket", + "timer-off", + "timer-reset", + "timer", + "toggle-left", + "toggle-right", + "tornado", + "trash-2", + "lucide-trash", + "trello", + "trending-down", + "trending-up", + "triangle", + "truck", + "tv-2", + "tv", + "twitch", + "twitter", + "type", + "umbrella", + "underline", + "undo", + "unlink-2", + "unlink", + "unlock", + "upload-cloud", + "upload", + "user-check", + "user-minus", + "user-plus", + "user-x", + "user", + "users", + "verified", + "vibrate", + "video-off", + "video", + "view", + "voicemail", + "volume-1", + "volume-2", + "volume-x", + "volume", + "wallet", + "wand", + "watch", + "waves", + "webcam", + "wifi-off", + "wifi", + "wind", + "wrap-text", + "wrench", + "x-circle", + "x-octagon", + "x-square", + "x", + "youtube", + "zap-off", + "zap", + "zoom-in", + "zoom-out", + "search-large", + ]; diff --git a/src/main.ts b/src/main.ts index c7e933c..632379b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,7 +5,7 @@ import { updateStyles, } from "src/util"; import { updateSpacing } from "src/util"; -import { Command, Plugin } from "obsidian"; +import { Command, getIconIds, Plugin } from "obsidian"; import { DEFAULT_SETTINGS } from "./constants"; import t from "./l10n"; import { @@ -83,6 +83,8 @@ export default class CommanderPlugin extends Plugin { registerCustomIcons(); + console.log(getIconIds()); + this.manager = { editorMenu: new EditorMenuCommandManager( this, diff --git a/src/ui/chooseIconModal.ts b/src/ui/chooseIconModal.ts index d41ceab..954f9ff 100644 --- a/src/ui/chooseIconModal.ts +++ b/src/ui/chooseIconModal.ts @@ -40,15 +40,14 @@ export default class ChooseIconModal extends FuzzySuggestModal { public renderSuggestion(item: FuzzyMatch, el: HTMLElement): void { el.addClass("mod-complex"); const content = el.createDiv({ cls: "suggestion-content" }); - content - .createDiv({ cls: "suggestion-title" }) - .setText( - item.item - .replace(/-/g, " ") - .replace(/(^\w{1})|(\s+\w{1})/g, (letter) => - letter.toUpperCase() - ) - ); + content.createDiv({ cls: "suggestion-title" }).setText( + item.item + .replace("lucide-", "") + .replace(/-/g, " ") + .replace(/(^\w{1})|(\s+\w{1})/g, (letter) => + letter.toUpperCase() + ) + ); const aux = el.createDiv({ cls: "suggestion-aux" }); setIcon(aux.createSpan({ cls: "suggestion-flair" }), item.item); From 6603ae9dc58da2fb2ba649866a02d98825f8a6d2 Mon Sep 17 00:00:00 2001 From: quorafind <951011105@qq.com> Date: Fri, 11 Oct 2024 09:16:41 +0800 Subject: [PATCH 2/4] chore: update version --- src/main.ts | 14 +++++------- src/manager/commands/explorerManager.ts | 20 +++++++++-------- src/manager/commands/leftRibbonManager.ts | 10 ++++----- src/manager/commands/menuManager.ts | 13 ++++++----- src/manager/commands/pageHeaderManager.ts | 18 ++++++++------- src/manager/commands/statusBarManager.ts | 14 +++++++----- src/manager/commands/titleBarManager.ts | 12 +++++----- src/ui/addCommandModal.ts | 4 ++-- src/ui/chooseCustomNameModal.ts | 8 +++++-- src/ui/chooseIconModal.ts | 2 +- src/ui/components/AdvancedToolbarSettings.tsx | 6 ++--- src/ui/components/ChangeableText.tsx | 1 + src/ui/components/MacroBuilder.tsx | 5 ++++- src/ui/components/MacroBuilderModal.ts | 2 +- src/ui/components/commandComponent.tsx | 10 +++++++-- src/ui/components/commandViewerComponent.tsx | 7 +++--- src/ui/components/hidingViewer.tsx | 4 ++-- src/ui/components/mobileModifyComponent.tsx | 5 ++++- src/ui/components/settingTabComponent.tsx | 8 +++---- src/ui/confirmDeleteModal.ts | 2 +- src/ui/mobileModifyModal.ts | 9 ++++++-- src/ui/settingTab.ts | 2 +- src/ui/settingTabModal.ts | 2 +- src/util.tsx | 22 ++++++++++++------- 24 files changed, 119 insertions(+), 81 deletions(-) diff --git a/src/main.ts b/src/main.ts index 632379b..a9fa57a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -53,7 +53,7 @@ export default class CommanderPlugin extends Plugin { for (const command of macro.macro) { switch (command.action) { case Action.COMMAND: { - await app.commands.executeCommandById(command.commandId); + await this.app.commands.executeCommandById(command.commandId); continue; } case Action.DELAY: { @@ -67,7 +67,7 @@ export default class CommanderPlugin extends Plugin { } case Action.LOOP: { for (let i = 0; i < command.times; i++) { - await app.commands.executeCommandById( + await this.app.commands.executeCommandById( command.commandId ); } @@ -83,8 +83,6 @@ export default class CommanderPlugin extends Plugin { registerCustomIcons(); - console.log(getIconIds()); - this.manager = { editorMenu: new EditorMenuCommandManager( this, @@ -108,25 +106,25 @@ export default class CommanderPlugin extends Plugin { }); this.registerEvent( - app.workspace.on( + this.app.workspace.on( "editor-menu", this.manager.editorMenu.applyEditorMenuCommands(this) ) ); this.registerEvent( - app.workspace.on( + this.app.workspace.on( "file-menu", this.manager.fileMenu.applyFileMenuCommands(this) ) ); - app.workspace.onLayoutReady(() => { + this.app.workspace.onLayoutReady(() => { updateHiderStylesheet(this.settings); updateMacroCommands(this); updateSpacing(this.settings.spacing); updateStyles(this.settings.advancedToolbar); - injectIcons(this.settings.advancedToolbar); + injectIcons(this.settings.advancedToolbar, this); this.executeStartupMacros(); }); diff --git a/src/manager/commands/explorerManager.ts b/src/manager/commands/explorerManager.ts index a96c86e..2155fe3 100644 --- a/src/manager/commands/explorerManager.ts +++ b/src/manager/commands/explorerManager.ts @@ -21,14 +21,14 @@ export default class ExplorerManager extends CommandManagerBase { } private getFileExplorers(): WorkspaceLeaf[] { - return app.workspace.getLeavesOfType("file-explorer"); + return this.plugin.app.workspace.getLeavesOfType("file-explorer"); } private init(): void { - app.workspace.onLayoutReady(() => { + this.plugin.app.workspace.onLayoutReady(() => { for (const cmd of this.pairs) { - if (isModeActive(cmd.mode)) { - app.workspace.onLayoutReady(() => { + if (isModeActive(cmd.mode, this.plugin)) { + this.plugin.app.workspace.onLayoutReady(() => { const explorers = this.getFileExplorers(); explorers.forEach((exp) => { this.addAction(cmd, exp); @@ -37,7 +37,7 @@ export default class ExplorerManager extends CommandManagerBase { // File explorers that get opened later on this.plugin.registerEvent( - app.workspace.on("layout-change", () => { + this.plugin.app.workspace.on("layout-change", () => { const explorers = this.getFileExplorers(); explorers.forEach((exp) => { this.addAction(cmd, exp); @@ -56,7 +56,7 @@ export default class ExplorerManager extends CommandManagerBase { public async addCommand(pair: CommandIconPair): Promise { this.pairs.push(pair); - app.workspace.onLayoutReady(() => { + this.plugin.app.workspace.onLayoutReady(() => { const explorers = this.getFileExplorers(); explorers.forEach((exp) => { this.addAction(pair, exp); @@ -65,7 +65,7 @@ export default class ExplorerManager extends CommandManagerBase { // File explorers that get opened later on this.plugin.registerEvent( - app.workspace.on("layout-change", () => { + this.plugin.app.workspace.on("layout-change", () => { const explorers = this.getFileExplorers(); explorers.forEach((exp) => { this.addAction(pair, exp); @@ -116,7 +116,8 @@ export default class ExplorerManager extends CommandManagerBase { const setNormal = (): void => { btn.empty(); setIcon(btn, pair.icon); - btn.onclick = (): void => app.commands.executeCommandById(pair.id); + btn.onclick = (): void => + this.plugin.app.commands.executeCommandById(pair.id); }; const setRemovable = (): void => { btn.empty(); @@ -176,7 +177,8 @@ export default class ExplorerManager extends CommandManagerBase { .setIcon("text-cursor-input") .onClick(async () => { const newName = await new ChooseCustomNameModal( - pair.name + pair.name, + this.plugin ).awaitSelection(); if (newName && newName !== pair.name) { pair.name = newName; diff --git a/src/manager/commands/leftRibbonManager.ts b/src/manager/commands/leftRibbonManager.ts index a59c6c2..a1e4654 100644 --- a/src/manager/commands/leftRibbonManager.ts +++ b/src/manager/commands/leftRibbonManager.ts @@ -15,7 +15,7 @@ export default class LeftRibbonManager extends CommandManagerBase { this.addCommand(pair, false) ); - app.workspace.onLayoutReady(() => { + this.plugin.app.workspace.onLayoutReady(() => { // if (this.plugin.settings.showAddCommand) { // this.plugin.addRibbonIcon("plus", t("Add new"), async () => // this.addCommand(await chooseNewCommand(plugin)) @@ -32,12 +32,12 @@ export default class LeftRibbonManager extends CommandManagerBase { this.plugin.settings.leftRibbon.push(pair); await this.plugin.saveSettings(); } - if (isModeActive(pair.mode)) { + if (isModeActive(pair.mode, this.plugin)) { this.plugin.addRibbonIcon(pair.icon, pair.name, () => - app.commands.executeCommandById(pair.id) + this.plugin.app.commands.executeCommandById(pair.id) ); // @ts-expect-error - const nativeAction = app.workspace.leftRibbon.items.find( + const nativeAction = this.plugin.app.workspace.leftRibbon.items.find( // @ts-expect-error (i) => i.icon === pair.icon && i.name === i.name ); @@ -60,7 +60,7 @@ export default class LeftRibbonManager extends CommandManagerBase { await this.plugin.saveSettings(); } // @ts-expect-error - const nativeAction = app.workspace.leftRibbon.items.find( + const nativeAction = this.plugin.app.workspace.leftRibbon.items.find( // @ts-expect-error (i) => i.icon === pair.icon && i.name === i.name ); diff --git a/src/manager/commands/menuManager.ts b/src/manager/commands/menuManager.ts index 92ac89f..4ac95e6 100644 --- a/src/manager/commands/menuManager.ts +++ b/src/manager/commands/menuManager.ts @@ -78,7 +78,8 @@ abstract class Base extends CommandManagerBase { .onClick(async () => { const newName = await new ChooseCustomNameModal( - cmdPair.name + cmdPair.name, + plugin ).awaitSelection(); if (newName && newName !== cmdPair.name) { cmdPair.name = newName; @@ -112,7 +113,9 @@ abstract class Base extends CommandManagerBase { item.setTitle(cmdPair.name ?? command.name) .setIcon(cmdPair.icon) - .onClick(() => app.commands.executeCommandById(cmdPair.id)); + .onClick(() => + plugin.app.commands.executeCommandById(cmdPair.id) + ); let isRemovable = false; const setNormal = (): void => { @@ -180,12 +183,12 @@ export class EditorMenuCommandManager extends Base { this.addCommandAddButton(plugin, menu, plugin.settings.editorMenu); for (const cmdPair of plugin.settings.editorMenu) { - const command = getCommandFromId(cmdPair.id); + const command = getCommandFromId(cmdPair.id, plugin); //Command has been removed if (!command) continue; - if (!isModeActive(cmdPair.mode)) continue; + if (!isModeActive(cmdPair.mode, plugin)) continue; //Use the check callbacks accordingly if ( @@ -221,7 +224,7 @@ export class FileMenuCommandManager extends Base { this.addCommandAddButton(plugin, menu, plugin.settings.fileMenu); for (const cmdPair of plugin.settings.fileMenu) { - const command = getCommandFromId(cmdPair.id); + const command = getCommandFromId(cmdPair.id, plugin); //Command has been removed if (!command) { diff --git a/src/manager/commands/pageHeaderManager.ts b/src/manager/commands/pageHeaderManager.ts index 1b6638e..0467714 100644 --- a/src/manager/commands/pageHeaderManager.ts +++ b/src/manager/commands/pageHeaderManager.ts @@ -27,8 +27,8 @@ export default class PageHeaderManager extends CommandManagerBase { if (!buttons || buttons.has(id)) return; const buttonIcon = (view as ItemView).addAction(icon, name, () => { - app.workspace.setActiveLeaf(leaf, { focus: true }); - app.commands.executeCommandById(id); + this.plugin.app.workspace.setActiveLeaf(leaf, { focus: true }); + this.plugin.app.commands.executeCommandById(id); }); buttons.set(id, buttonIcon); @@ -68,7 +68,8 @@ export default class PageHeaderManager extends CommandManagerBase { .setIcon("text-cursor-input") .onClick(async () => { const newName = await new ChooseCustomNameModal( - pair.name + pair.name, + this.plugin ).awaitSelection(); if (newName && newName !== pair.name) { pair.name = newName; @@ -102,11 +103,11 @@ export default class PageHeaderManager extends CommandManagerBase { this.removeButtonsFromAllLeaves(); }); this.plugin.registerEvent( - app.workspace.on("layout-change", () => { + this.plugin.app.workspace.on("layout-change", () => { this.addButtonsToAllLeaves(); }) ); - app.workspace.onLayoutReady(() => + this.plugin.app.workspace.onLayoutReady(() => setTimeout(() => this.addButtonsToAllLeaves(), 100) ); } @@ -126,7 +127,7 @@ export default class PageHeaderManager extends CommandManagerBase { private addButtonsToAllLeaves(refresh = false): void { activeWindow.requestAnimationFrame(() => - app.workspace.iterateAllLeaves((leaf) => + this.plugin.app.workspace.iterateAllLeaves((leaf) => this.addButtonsToLeaf(leaf, refresh) ) ); @@ -134,7 +135,7 @@ export default class PageHeaderManager extends CommandManagerBase { private removeButtonsFromAllLeaves(): void { activeWindow.requestAnimationFrame(() => - app.workspace.iterateAllLeaves((leaf) => + this.plugin.app.workspace.iterateAllLeaves((leaf) => this.removeButtonsFromLeaf(leaf) ) ); @@ -157,7 +158,8 @@ export default class PageHeaderManager extends CommandManagerBase { } for (let i = this.pairs.length - 1; i >= 0; i--) { const pair = this.pairs[i]; - if (isModeActive(pair.mode)) this.addPageHeaderButton(leaf, pair); + if (isModeActive(pair.mode, this.plugin)) + this.addPageHeaderButton(leaf, pair); } if (this.plugin.settings.showAddCommand) this.addAdderButton(leaf); } diff --git a/src/manager/commands/statusBarManager.ts b/src/manager/commands/statusBarManager.ts index b222432..8e0cf2c 100644 --- a/src/manager/commands/statusBarManager.ts +++ b/src/manager/commands/statusBarManager.ts @@ -25,15 +25,15 @@ export default class StatusBarManager extends CommandManagerBase { } private init(): void { - app.workspace.onLayoutReady(() => { - this.container = app.statusBar.containerEl; + this.plugin.app.workspace.onLayoutReady(() => { + this.container = this.plugin.app.statusBar.containerEl; for (const cmd of this.pairs) { //Command has been removed - if (!getCommandFromId(cmd.id)) { + if (!getCommandFromId(cmd.id, this.plugin)) { this.pairs.remove(cmd); } - if (isModeActive(cmd.mode)) { + if (isModeActive(cmd.mode, this.plugin)) { this.addAction(cmd); } } @@ -108,7 +108,8 @@ export default class StatusBarManager extends CommandManagerBase { const setNormal = (): void => { btn.empty(); setIcon(btn, pair.icon); - btn.onclick = (): void => app.commands.executeCommandById(pair.id); + btn.onclick = (): void => + this.plugin.app.commands.executeCommandById(pair.id); }; const setRemovable = (): void => { btn.empty(); @@ -168,7 +169,8 @@ export default class StatusBarManager extends CommandManagerBase { .setIcon("text-cursor-input") .onClick(async () => { const newName = await new ChooseCustomNameModal( - pair.name + pair.name, + this.plugin ).awaitSelection(); if (newName && newName !== pair.name) { pair.name = newName; diff --git a/src/manager/commands/titleBarManager.ts b/src/manager/commands/titleBarManager.ts index 81659a7..50ce9e0 100644 --- a/src/manager/commands/titleBarManager.ts +++ b/src/manager/commands/titleBarManager.ts @@ -25,18 +25,18 @@ export default class TitleBarManager extends CommandManagerBase { } private init(): void { - app.workspace.onLayoutReady(async () => { + this.plugin.app.workspace.onLayoutReady(async () => { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion this.container = document.querySelector( ".titlebar div.titlebar-button-container.mod-right" )!; for (const cmd of this.pairs) { //Command has been removed - if (!getCommandFromId(cmd.id)) { + if (!getCommandFromId(cmd.id, this.plugin)) { this.pairs.remove(cmd); } - if (isModeActive(cmd.mode)) { + if (isModeActive(cmd.mode, this.plugin)) { this.addTitleBarAction(cmd); } } @@ -79,7 +79,8 @@ export default class TitleBarManager extends CommandManagerBase { const setNormal = (): void => { btn.empty(); setIcon(btn, pair.icon); - btn.onclick = (): void => app.commands.executeCommandById(pair.id); + btn.onclick = (): void => + this.plugin.app.commands.executeCommandById(pair.id); }; const setRemovable = (): void => { btn.empty(); @@ -139,7 +140,8 @@ export default class TitleBarManager extends CommandManagerBase { .setIcon("text-cursor-input") .onClick(async () => { const newName = await new ChooseCustomNameModal( - pair.name + pair.name, + this.plugin ).awaitSelection(); if (newName && newName !== pair.name) { pair.name = newName; diff --git a/src/ui/addCommandModal.ts b/src/ui/addCommandModal.ts index 962d2f7..ce16e64 100644 --- a/src/ui/addCommandModal.ts +++ b/src/ui/addCommandModal.ts @@ -7,9 +7,9 @@ export default class AddCommandModal extends FuzzySuggestModal { private commands: Command[]; public constructor(plugin: CommanderPlugin) { - super(app); + super(plugin.app); this.plugin = plugin; - this.commands = Object.values(app.commands.commands); + this.commands = Object.values(plugin.app.commands.commands); this.setPlaceholder(t("Choose a Command to add")); this.setInstructions([ diff --git a/src/ui/chooseCustomNameModal.ts b/src/ui/chooseCustomNameModal.ts index c04228e..3e1390c 100644 --- a/src/ui/chooseCustomNameModal.ts +++ b/src/ui/chooseCustomNameModal.ts @@ -1,11 +1,15 @@ import { SuggestModal } from "obsidian"; import t from "src/l10n"; +import CommanderPlugin from "src/main"; export default class ChooseCustomNameModal extends SuggestModal { // This is used in onOpen, not sure why eslint doesn't recognize it // eslint-disable-next-line no-unused-vars - public constructor(private defaultName: string) { - super(app); + public constructor( + private defaultName: string, + private plugin: CommanderPlugin + ) { + super(plugin.app); this.setPlaceholder(t("Use a custom name")); this.resultContainerEl.style.display = "none"; diff --git a/src/ui/chooseIconModal.ts b/src/ui/chooseIconModal.ts index 954f9ff..e346550 100644 --- a/src/ui/chooseIconModal.ts +++ b/src/ui/chooseIconModal.ts @@ -7,7 +7,7 @@ export default class ChooseIconModal extends FuzzySuggestModal { private plugin: CommanderPlugin; public constructor(plugin: CommanderPlugin) { - super(app); + super(plugin.app); this.plugin = plugin; this.setPlaceholder(t("Choose a Icon for your new Command")); diff --git a/src/ui/components/AdvancedToolbarSettings.tsx b/src/ui/components/AdvancedToolbarSettings.tsx index 808d95a..012991f 100644 --- a/src/ui/components/AdvancedToolbarSettings.tsx +++ b/src/ui/components/AdvancedToolbarSettings.tsx @@ -109,7 +109,7 @@ function render(containerEl: HTMLElement, plugin: CommanderPlugin) { }); } await plugin.saveSettings(); - injectIcons(plugin.settings.advancedToolbar); + injectIcons(plugin.settings.advancedToolbar, plugin); render(containerEl, plugin); }); }) @@ -122,7 +122,7 @@ function render(containerEl: HTMLElement, plugin: CommanderPlugin) { (p) => p.commandID !== command.id ); delete command.icon; - delete app.commands.commands[command.id].icon; + delete plugin.app.commands.commands[command.id].icon; await plugin.saveSettings(); render(containerEl, plugin); new Notice( @@ -243,7 +243,7 @@ export default function AdvancedToolbarSettings({ {Platform.isMobile && (