Skip to content

Commit

Permalink
refactor: rename IconFolderPlugin to IconizePlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianWoelki committed Jul 7, 2024
1 parent 5eb2f5e commit 4513d68
Show file tree
Hide file tree
Showing 38 changed files with 122 additions and 128 deletions.
6 changes: 3 additions & 3 deletions src/@types/internal-plugin-injector.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TAbstractFile, View, WorkspaceLeaf } from 'obsidian';
import IconFolderPlugin from '@app/main';
import IconizePlugin from '@app/main';

interface FileExplorerWorkspaceLeaf extends WorkspaceLeaf {
containerEl: HTMLElement;
Expand All @@ -11,9 +11,9 @@ interface FileExplorerView extends View {
}

export default abstract class InternalPluginInjector {
protected plugin: IconFolderPlugin;
protected plugin: IconizePlugin;

constructor(plugin: IconFolderPlugin) {
constructor(plugin: IconizePlugin) {
this.plugin = plugin;
}

Expand Down
4 changes: 2 additions & 2 deletions src/editor/icons-suggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { getAllLoadedIconNames } from '../icon-pack-manager';
import icon from '../lib/icon';
import emoji from '../emoji';
import { saveIconToIconPack } from '@app/util';
import IconFolderPlugin from '@app/main';
import IconizePlugin from '@app/main';

export default class SuggestionIcon extends EditorSuggest<string> {
constructor(
app: App,
public plugin: IconFolderPlugin,
public plugin: IconizePlugin,
) {
super(app);
}
Expand Down
4 changes: 2 additions & 2 deletions src/editor/live-preview/decorations/build-link-decorations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import IconFolderPlugin from '@app/main';
import IconizePlugin from '@app/main';
import { Decoration, EditorView } from '@codemirror/view';
import { MarkdownView, editorInfoField } from 'obsidian';
import { RangeSetBuilder } from '@codemirror/state';
Expand All @@ -9,7 +9,7 @@ import { HeaderToken } from '@app/lib/util/text';

export const buildLinkDecorations = (
view: EditorView,
plugin: IconFolderPlugin,
plugin: IconizePlugin,
) => {
const builder = new RangeSetBuilder<Decoration>();
const mdView = view.state.field(editorInfoField) as MarkdownView;
Expand Down
4 changes: 2 additions & 2 deletions src/editor/live-preview/decorations/build-text-decorations.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import IconFolderPlugin from '@app/main';
import IconizePlugin from '@app/main';
import { Decoration, EditorView } from '@codemirror/view';
import { editorLivePreviewField } from 'obsidian';
import { IconInTextWidget } from '@app/editor/live-preview/widgets';

export const buildTextDecorations = (
view: EditorView,
plugin: IconFolderPlugin,
plugin: IconizePlugin,
) => {
const ranges: [iconId: string, from: number, to: number][] = [];
const iconInfo = view.state.field(plugin.positionField);
Expand Down
6 changes: 3 additions & 3 deletions src/editor/live-preview/plugins/icon-in-links.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import IconFolderPlugin from '@app/main';
import IconizePlugin from '@app/main';
import {
DecorationSet,
EditorView,
Expand All @@ -7,11 +7,11 @@ import {
} from '@codemirror/view';
import { buildLinkDecorations } from '@app/editor/live-preview/decorations';

export const buildIconInLinksPlugin = (plugin: IconFolderPlugin) => {
export const buildIconInLinksPlugin = (plugin: IconizePlugin) => {
return ViewPlugin.fromClass(
class {
decorations: DecorationSet;
plugin: IconFolderPlugin;
plugin: IconizePlugin;

constructor(view: EditorView) {
this.plugin = plugin;
Expand Down
6 changes: 3 additions & 3 deletions src/editor/live-preview/plugins/icon-in-text.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import IconFolderPlugin from '@app/main';
import IconizePlugin from '@app/main';
import {
Decoration,
DecorationSet,
Expand All @@ -8,11 +8,11 @@ import {
} from '@codemirror/view';
import { buildTextDecorations } from '@app/editor/live-preview/decorations';

export const buildIconInTextPlugin = (plugin: IconFolderPlugin) => {
export const buildIconInTextPlugin = (plugin: IconizePlugin) => {
return ViewPlugin.fromClass(
class IconPlugin {
decorations: DecorationSet;
plugin: IconFolderPlugin;
plugin: IconizePlugin;

constructor(view: EditorView) {
this.plugin = plugin;
Expand Down
6 changes: 3 additions & 3 deletions src/editor/live-preview/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
RangeValue,
StateField,
} from '@codemirror/state';
import IconFolderPlugin from '@app/main';
import IconizePlugin from '@app/main';
import emoji from '@app/emoji';

export type PositionField = StateField<RangeSet<IconPosition>>;
Expand All @@ -23,7 +23,7 @@ type UpdateRangeFunc = (
remove: boolean,
) => void;

function checkForSourceMode(plugin: IconFolderPlugin): boolean {
function checkForSourceMode(plugin: IconizePlugin): boolean {
let isSourceMode = false;
// Iterate over all leaves to check if any is in source mode
plugin.app.workspace.iterateAllLeaves((leaf) => {
Expand Down Expand Up @@ -55,7 +55,7 @@ class IconPosition extends RangeValue {
* Builds a position field for the editor state. This field will track the
* positions of the icons in the document.
**/
export const buildPositionField = (plugin: IconFolderPlugin) => {
export const buildPositionField = (plugin: IconizePlugin) => {
/**
* Checks the ranges of the icons in the document. If the range is not
* excluded, the range is added to the range set. If the range is excluded,
Expand Down
4 changes: 2 additions & 2 deletions src/editor/live-preview/widgets/icon-in-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
HeaderToken,
} from '@app/lib/util/text';
import svg from '@app/lib/util/svg';
import IconFolderPlugin from '@app/main';
import IconizePlugin from '@app/main';
import { WidgetType } from '@codemirror/view';

export class IconInLinkWidget extends WidgetType {
constructor(
private plugin: IconFolderPlugin,
private plugin: IconizePlugin,
private iconData: Icon | string,
private path: string,
private headerType: HeaderToken | null,
Expand Down
4 changes: 2 additions & 2 deletions src/editor/live-preview/widgets/icon-in-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {
calculateFontTextSize,
calculateHeaderSize,
} from '@app/lib/util/text';
import IconFolderPlugin from '@app/main';
import IconizePlugin from '@app/main';
import { EditorView, WidgetType } from '@codemirror/view';

export class IconInTextWidget extends WidgetType {
private start = -1;
private end = -1;

constructor(
public plugin: IconFolderPlugin,
public plugin: IconizePlugin,
public id: string,
) {
super();
Expand Down
4 changes: 2 additions & 2 deletions src/editor/markdown-processors/icon-in-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {
HTMLHeader,
isHeader,
} from '@app/lib/util/text';
import IconFolderPlugin from '@app/main';
import IconizePlugin from '@app/main';
import { MarkdownPostProcessorContext } from 'obsidian';

export const processIconInLinkMarkdown = (
plugin: IconFolderPlugin,
plugin: IconizePlugin,
element: HTMLElement,
ctx: MarkdownPostProcessorContext,
) => {
Expand Down
8 changes: 4 additions & 4 deletions src/editor/markdown-processors/icon-in-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
calculateHeaderSize,
isHeader,
} from '@app/lib/util/text';
import IconFolderPlugin from '@app/main';
import IconizePlugin from '@app/main';
import emoji from '@app/emoji';

export const createIconShortcodeRegex = (plugin: IconFolderPlugin): RegExp => {
export const createIconShortcodeRegex = (plugin: IconizePlugin): RegExp => {
return new RegExp(
`(${
plugin.getSettings().iconIdentifier
Expand All @@ -24,7 +24,7 @@ export const createIconShortcodeRegex = (plugin: IconFolderPlugin): RegExp => {
};

const createTreeWalker = (
plugin: IconFolderPlugin,
plugin: IconizePlugin,
root: HTMLElement,
): TreeWalker => {
return document.createTreeWalker(root, NodeFilter.SHOW_ALL, {
Expand Down Expand Up @@ -76,7 +76,7 @@ const checkForTextNodes = (
};

export const processIconInTextMarkdown = (
plugin: IconFolderPlugin,
plugin: IconizePlugin,
element: HTMLElement,
) => {
// Ignore if codeblock
Expand Down
11 changes: 4 additions & 7 deletions src/icon-pack-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getFileFromJSZipFile, readZipFile } from './zip-util';
import JSZip from 'jszip';
import config from '@app/config';
import { logger } from '@app/lib/logger';
import IconFolderPlugin from './main';
import IconizePlugin from './main';
import { getExtraPath } from './icon-packs';

export const NATIVE_LUCIDE_ICON_PACK_NAME = 'lucide-icons';
Expand Down Expand Up @@ -345,10 +345,7 @@ export const createIconPackPrefix = (iconPackName: string): string => {
);
};

export const loadUsedIcons = async (
plugin: IconFolderPlugin,
icons: string[],
) => {
export const loadUsedIcons = async (plugin: IconizePlugin, icons: string[]) => {
const iconPacks = [
...(await listPath(plugin)).folders.map((iconPack) =>
iconPack.split('/').pop(),
Expand Down Expand Up @@ -379,7 +376,7 @@ export const nextIdentifier = (iconName: string) => {
};

export const loadIcon = async (
plugin: IconFolderPlugin,
plugin: IconizePlugin,
iconPackNames: string[],
iconName: string,
): Promise<void> => {
Expand Down Expand Up @@ -558,7 +555,7 @@ export const addIconToIconPack = (
};

export const removeIconFromIconPackDirectory = (
plugin: IconFolderPlugin,
plugin: IconizePlugin,
iconPackName: string,
iconName: string,
): Promise<void> => {
Expand Down
4 changes: 2 additions & 2 deletions src/internal-plugins/bookmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import InternalPluginInjector from '@app/@types/internal-plugin-injector';
import { BookmarkItem, BookmarkItemValue } from '@app/@types/obsidian';
import dom from '@lib/util/dom';
import icon from '@lib/icon';
import IconFolderPlugin from '@app/main';
import IconizePlugin from '@app/main';
import config from '@app/config';
import { DEFAULT_FILE_ICON, DEFAULT_FOLDER_ICON } from '@app/util';

Expand All @@ -13,7 +13,7 @@ interface BookmarksView extends View {
}

export default class BookmarkInternalPlugin extends InternalPluginInjector {
constructor(plugin: IconFolderPlugin) {
constructor(plugin: IconizePlugin) {
super(plugin);
}

Expand Down
4 changes: 2 additions & 2 deletions src/internal-plugins/outline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createIconShortcodeRegex } from '@app/editor/markdown-processors';
import svg from '@app/lib/util/svg';
import icon from '@app/lib/icon';
import { LoggerPrefix, logger } from '@app/lib/logger';
import IconFolderPlugin from '@app/main';
import IconizePlugin from '@app/main';
import { View } from 'obsidian';

const TREE_ITEM_CLASS = 'tree-item-self';
Expand All @@ -16,7 +16,7 @@ interface OutlineView extends View {
}

export default class OutlineInternalPlugin extends InternalPluginInjector {
constructor(plugin: IconFolderPlugin) {
constructor(plugin: IconizePlugin) {
super(plugin);
}

Expand Down
4 changes: 2 additions & 2 deletions src/internal-plugins/starred.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { StarredFile } from '@app/@types/obsidian';
import dom from '@lib/util/dom';
import icon from '@lib/icon';
import config from '@app/config';
import IconFolderPlugin from '@app/main';
import IconizePlugin from '@app/main';

interface StarredView extends View {
itemLookup: WeakMap<Element, StarredFile>;
Expand All @@ -15,7 +15,7 @@ interface StarredView extends View {
* @deprecated After obsidian 1.2.6 in favor of the bookmarks plugin.
*/
export default class StarredInternalPlugin extends InternalPluginInjector {
constructor(plugin: IconFolderPlugin) {
constructor(plugin: IconizePlugin) {
super(plugin);
}

Expand Down
22 changes: 11 additions & 11 deletions src/lib/custom-rule.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Plugin, TAbstractFile } from 'obsidian';
import IconFolderPlugin from '../main';
import IconizePlugin from '../main';
import { CustomRule } from '../settings/data';
import dom from './util/dom';
import { getFileItemTitleEl } from '../util';
Expand Down Expand Up @@ -56,11 +56,11 @@ const isApplicable = async (

/**
* Removes the icon from the custom rule from all the files and folders, if applicable.
* @param plugin IconFolderPlugin instance.
* @param plugin IconizePlugin instance.
* @param rule CustomRule where the icons will be removed based on this rule.
*/
const removeFromAllFiles = async (
plugin: IconFolderPlugin,
plugin: IconizePlugin,
rule: CustomRule,
): Promise<void> => {
const nodesWithIcon = document.querySelectorAll(
Expand Down Expand Up @@ -90,22 +90,22 @@ const removeFromAllFiles = async (

/**
* Gets all the custom rules sorted by their order property in ascending order.
* @param plugin IconFolderPlugin instance.
* @param plugin IconizePlugin instance.
* @returns CustomRule array sorted by their order property in ascending order.
*/
const getSortedRules = (plugin: IconFolderPlugin): CustomRule[] => {
const getSortedRules = (plugin: IconizePlugin): CustomRule[] => {
return plugin.getSettings().rules.sort((a, b) => a.order - b.order);
};

/**
* Tries to add all specific custom rule icons to all registered files and directories.
* It does that by calling the {@link add} function. Custom rules should have the lowest
* priority and will get ignored if an icon already exists in the file or directory.
* @param plugin IconFolderPlugin instance.
* @param plugin IconizePlugin instance.
* @param rule CustomRule that will be applied, if applicable, to all files and folders.
*/
const addToAllFiles = async (
plugin: IconFolderPlugin,
plugin: IconizePlugin,
rule: CustomRule,
): Promise<void> => {
const fileItems = await getFileItems(plugin, rule);
Expand All @@ -117,15 +117,15 @@ const addToAllFiles = async (
/**
* Tries to add the icon of the custom rule to a file or folder. This function also checks
* if the file type matches the `for` property of the custom rule.
* @param plugin IconFolderPlugin instance.
* @param plugin IconizePlugin instance.
* @param rule CustomRule that will be used to check if the rule is applicable to the file
* or directory.
* @param file TAbstractFile that will be used to possibly create the icon for.
* @param container HTMLElement where the icon will be added if the custom rules matches.
* @returns A promise that resolves to `true` if the icon was added, `false` otherwise.
*/
const add = async (
plugin: IconFolderPlugin,
plugin: IconizePlugin,
rule: CustomRule,
file: TAbstractFile,
container?: HTMLElement,
Expand Down Expand Up @@ -180,12 +180,12 @@ const doesMatchPath = (rule: CustomRule, path: string): boolean => {

/**
* Gets all the file items that can be applied to the specific custom rule.
* @param plugin Instance of IconFolderPlugin.
* @param plugin Instance of IconizePlugin.
* @param rule Custom rule that will be checked for.
* @returns A promise that resolves to an array of file items that match the custom rule.
*/
const getFileItems = async (
plugin: IconFolderPlugin,
plugin: IconizePlugin,
rule: CustomRule,
): Promise<FileItem[]> => {
const result: FileItem[] = [];
Expand Down
Loading

0 comments on commit 4513d68

Please sign in to comment.