obsidian#FileExplorerView TypeScript Examples

The following examples show how to use obsidian#FileExplorerView. 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: active-folder.ts    From alx-folder-note with MIT License 6 votes vote down vote up
constructor(plugin: ALxFolderNote, fileExplorer: FileExplorerView) {
    super(plugin, fileExplorer);
    const { workspace } = plugin.app;
    this.handleActiveLeafChange(workspace.activeLeaf);
    plugin.registerEvent(
      workspace.on(
        "active-leaf-change",
        this.handleActiveLeafChange.bind(this),
      ),
    );
    this.plugin.register(() => (this.activeFolder = null));
  }
Example #2
Source File: folder-focus.ts    From alx-folder-note with MIT License 6 votes vote down vote up
constructor(plugin: ALxFolderNote, fileExplorer: FileExplorerView) {
    super(plugin, fileExplorer);
    const { workspace } = plugin.app;
    this.plugin.register(
      () => this.focusedFolder && this.toggleFocusFolder(null),
    );

    [
      workspace.on("file-menu", (menu, af) => {
        if (!(af instanceof TFolder) || af.isRoot()) return;
        menu.addItem((item) =>
          item
            .setTitle("Toggle Focus")
            .setIcon("crossed-star")
            .onClick(() => this.toggleFocusFolder(af)),
        );
      }),
    ].forEach(this.plugin.registerEvent.bind(this.plugin));
  }
Example #3
Source File: folder-mark.ts    From alx-folder-note with MIT License 6 votes vote down vote up
constructor(plugin: ALxFolderNote, fileExplorer: FileExplorerView) {
    super(plugin, fileExplorer);
    this.initFolderMark();
    if (this.plugin.settings.folderIcon) {
      this.initFolderIcon();
    }
    if (this.plugin.settings.hideCollapseIndicator) {
      this.initHideCollapseIndicator();
    }
  }
Example #4
Source File: index.ts    From alx-folder-note with MIT License 6 votes vote down vote up
getFileExplorerHandlers = (
  plugin: ALxFolderNote,
  fileExplorer: FileExplorerView,
) => ({
  // initialized (mark folders, hook evt handlers...) when constructed
  plugin,
  folderFocus: new FolderFocus(plugin, fileExplorer),
  folderMark: new FolderMark(plugin, fileExplorer),
  activeFolder: new ActiveFolder(plugin, fileExplorer),
})
Example #5
Source File: base.ts    From alx-folder-note with MIT License 5 votes vote down vote up
constructor(
    public plugin: ALxFolderNote,
    public fileExplorer: FileExplorerView,
  ) {}
Example #6
Source File: base.ts    From alx-folder-note with MIT License 5 votes vote down vote up
longPressRegistered = new WeakSet<FileExplorerView>();
Example #7
Source File: fe-patch.ts    From alx-folder-note with MIT License 4 votes vote down vote up
PatchFileExplorer = (plugin: ALxFolderNote) => {
  const { getFolderFromNote } = plugin.CoreApi,
    clickHandler = getClickHandler(plugin);

  let FileExplorerViewInst: FEViewCls | null = getViewOfType<FEViewCls>(
      "file-explorer",
      plugin.app,
    ),
    FileExplorerPluginInst =
      plugin.app.internalPlugins.plugins["file-explorer"]?.instance;
  if (!FileExplorerViewInst || !FileExplorerPluginInst) return;

  // get constructors
  const FileExplorerView = FileExplorerViewInst.constructor as typeof FEViewCls,
    FileExplorerPlugin =
      FileExplorerPluginInst.constructor as typeof FEPluginCls,
    FolderItem = FileExplorerViewInst.createFolderDom(
      plugin.app.vault.getRoot(),
    ).constructor as typeof FolderItemCls;

  FileExplorerViewInst = null;

  const uninstallers: ReturnType<typeof around>[] = [
    around(FileExplorerView.prototype, {
      load: (next) =>
        function (this: FEViewCls) {
          const self = this;
          next.call(self);
          self.folderNoteUtils = getFileExplorerHandlers(plugin, self);
          AddLongPressEvt(plugin, self.dom.navFileContainerEl);
          self.containerEl.on(
            "auxclick",
            ".nav-folder",
            (evt: MouseEvent, navEl: HTMLElement) => {
              const item = getFolderItemFromEl(navEl, self);
              item && clickHandler(item, evt);
            },
          );
          self.containerEl.on(
            "long-press" as any,
            ".nav-folder",
            (evt: LongPressEvent, navEl: HTMLElement) => {
              const item = getFolderItemFromEl(navEl, self);
              item && pressHandler(item, evt);
            },
          );
        },
      onFileMouseover: (next) =>
        function (this: FileExplorerView, evt, navTitleEl) {
          next.call(this, evt, navTitleEl);
          if (!Rt(evt, navTitleEl)) return;
          const af = this.currentHoverFile;
          if (
            !af ||
            // if event is triggered on same file, do nothing
            (this._AFN_HOVER && this._AFN_HOVER === af) ||
            !(af instanceof TFolder)
          )
            return;
          const note = plugin.CoreApi.getFolderNote(af);
          if (note) {
            this.app.workspace.trigger("hover-link", {
              event: evt,
              source: "file-explorer",
              hoverParent: this,
              targetEl: navTitleEl,
              linktext: note.path,
            });
          }
          // indicate that this file is handled by monkey patch
          this._AFN_HOVER = af;
        },
      onFileMouseout: (next) =>
        function (this: FileExplorerView, evt, navTitleEl) {
          next.call(this, evt, navTitleEl);
          if (!Rt(evt, navTitleEl)) return;
          delete this._AFN_HOVER;
        },
    }),
    // patch reveal in folder to alter folder note target to linked folder
    around(FileExplorerPlugin.prototype, {
      revealInFolder: (next) =>
        function (this: FEPluginCls, file: TAbstractFile) {
          if (file instanceof TFile && plugin.settings.hideNoteInExplorer) {
            const findResult = getFolderFromNote(file);
            if (findResult) file = findResult;
          }
          return next.call(this, file);
        },
    }),
    around(FolderItem.prototype, {
      onTitleElClick: (next) =>
        async function (this: FolderItemCls, evt) {
          // if folder note click not success,
          // fallback to default
          if (!(await clickHandler(this, evt))) next.call(this, evt);
        },
    }),
  ];
  resetFileExplorer(plugin);
  plugin.register(() => {
    // uninstall monkey patches
    uninstallers.forEach((revert) => revert());
    resetFileExplorer(plugin);
  });
}