obsidian#FolderItem TypeScript Examples

The following examples show how to use obsidian#FolderItem. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: click-handler.ts    From alx-folder-note with MIT License 6 votes vote down vote up
pressHandler = (
  item: FolderItem,
  _evt: LongPressEvent,
): boolean => {
  if (!item || item.fileExplorer.fileBeingRenamed === item.file) return false;
  const folder = item.file;
  item.fileExplorer.folderNoteUtils?.folderFocus.toggleFocusFolder(folder);
  return true;
}
Example #2
Source File: folder-focus.ts    From alx-folder-note with MIT License 6 votes vote down vote up
toggleFocusFolder(folder: TFolder | null) {
    const folderItem = folder
      ? (this.getAfItem(folder.path) as FolderItem | null)
      : null;
    if (this.focusedFolder) {
      this._focusFolder(this.focusedFolder, true);
    }
    // if given same folder as current cached, toggle it off
    if (folderItem && folderItem.file.path === this.focusedFolder?.file.path) {
      this.focusedFolder = null;
    } else {
      folderItem && this._focusFolder(folderItem, false);
      this.focusedFolder = folderItem;
    }
  }
Example #3
Source File: folder-mark.ts    From alx-folder-note with MIT License 6 votes vote down vote up
queues = {
    mark: {
      queue: new Map<string, [revert: boolean]>(),
      action: (path: string, revert: boolean) => {
        const item = this.getAfItem(path);
        if (!item) {
          console.warn("no afitem found for path %s, escaping...", path);
          return;
        }
        if (isFolder(item)) {
          if (revert === !!item.isFolderWithNote) {
            item.el.toggleClass(folderClass, !revert);
            item.isFolderWithNote = revert ? undefined : true;
            if (this.plugin.settings.hideCollapseIndicator)
              item.el.toggleClass(
                emptyFolderClass,
                revert ? false : item.file.children.length === 1,
              );
          }
          this._updateIcon(path, revert, item);
        } else if (revert === !!item.isFolderNote) {
          item.el.toggleClass(folderNoteClass, !revert);
          item.isFolderNote = revert ? undefined : true;
        }
      },
    },
    changedFolder: {
      queue: new Set<string>(),
      action: (path: string) => {
        let note = this.fncApi.getFolderNote(path);
        if (note) {
          (this.getAfItem(path) as FolderItem)?.el.toggleClass(
            emptyFolderClass,
            note.parent.children.length === 1,
          );
        }
      },
    },
  };
Example #4
Source File: click-handler.ts    From alx-folder-note with MIT License 5 votes vote down vote up
getClickHandler = (plugin: ALxFolderNote) => {
  const { getFolderNote, getFolderNotePath, getNewFolderNote } = plugin.CoreApi;
  return async (item: FolderItem, evt: MouseEvent): Promise<boolean> => {
    if (
      !item ||
      (Platform.isMobile && !plugin.settings.mobileClickToOpen) ||
      // allow folder shift selection to work
      evt.shiftKey ||
      // triggered only when click on title
      !(
        item.titleInnerEl === evt.target ||
        item.titleInnerEl.contains(evt.target as Node)
      ) ||
      // ignore file being renamed
      item.fileExplorer.fileBeingRenamed === item.file
    )
      return false;

    if (evt.type === "auxclick" && evt.button !== 1) return false;

    // get the folder path
    const folder = item.file;
    const createNew =
      (evt.type === "click" &&
        isModifier(evt, plugin.settings.modifierForNewNote)) ||
      (evt.type === "auxclick" && evt.button === 1);
    try {
      // check if folder note exists
      let folderNote = getFolderNote(folder),
        fnPath;
      if (createNew && !folderNote && (fnPath = getFolderNotePath(folder))) {
        folderNote = await plugin.app.vault.create(
          fnPath.path,
          getNewFolderNote(folder),
        );
      }

      if (!folderNote) return false;

      // show the note
      await plugin.app.workspace.openLinkText(
        folderNote.path,
        "",
        createNew || evt.type === "auxclick",
        { active: true },
      );
      if (plugin.settings.expandFolderOnClick && item.collapsed)
        await item.setCollapsed(false);
      return true;
    } catch (error) {
      console.error(error);
      return false;
    }
  };
}
Example #5
Source File: folder-focus.ts    From alx-folder-note with MIT License 5 votes vote down vote up
private _focusFolder(folder: FolderItem, revert = false) {
    if (folder.file.isRoot()) throw new Error("Cannot focus on root dir");
    folder.el.toggleClass(focusedFolderCls, !revert);
  }
Example #6
Source File: folder-focus.ts    From alx-folder-note with MIT License 5 votes vote down vote up
private _focusedFolder: {
    folder: FolderItem;
    collapsedCache: boolean;
  } | null = null;
Example #7
Source File: misc.ts    From alx-folder-note with MIT License 5 votes vote down vote up
isFolder = (item: AFItem): item is FolderItem =>
  (item as FolderItem).file instanceof TFolder