542 lines
41 KiB
JavaScript
542 lines
41 KiB
JavaScript
|
/*
|
||
|
THIS IS A GENERATED/BUNDLED FILE BY ROLLUP
|
||
|
if you want to view the source visit the plugins github repository
|
||
|
*/
|
||
|
|
||
|
'use strict';
|
||
|
|
||
|
var obsidian = require('obsidian');
|
||
|
|
||
|
/*! *****************************************************************************
|
||
|
Copyright (c) Microsoft Corporation.
|
||
|
|
||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||
|
purpose with or without fee is hereby granted.
|
||
|
|
||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||
|
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||
|
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||
|
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||
|
PERFORMANCE OF THIS SOFTWARE.
|
||
|
***************************************************************************** */
|
||
|
|
||
|
function __awaiter(thisArg, _arguments, P, generator) {
|
||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||
|
});
|
||
|
}
|
||
|
|
||
|
const COLLAPSE_ALL_ICON = '<svg viewBox="0 0 100 100" class="double-up-arrow-glyph" width="18" height="18"><path fill="currentColor" stroke="currentColor" d="M49.9,16.7c-0.9,0-1.7,0.4-2.3,1L14.3,51c-0.9,0.8-1.2,2.1-0.9,3.2c0.3,1.2,1.2,2.1,2.4,2.4s2.4,0,3.2-0.9l31-31l31,31 c0.8,0.9,2.1,1.2,3.2,0.9c1.2-0.3,2.1-1.2,2.4-2.4s0-2.4-0.9-3.2L52.4,17.6C51.7,17,50.8,16.7,49.9,16.7L49.9,16.7z M49.9,40 c-0.9,0-1.7,0.4-2.3,1L14.3,74.3c-0.9,0.8-1.2,2.1-0.9,3.2c0.3,1.2,1.2,2.1,2.4,2.4s2.4,0,3.2-0.9l31-31l31,31 c0.8,0.9,2.1,1.2,3.2,0.9c1.2-0.3,2.1-1.2,2.4-2.4c0.3-1.2,0-2.4-0.9-3.2L52.4,41C51.7,40.3,50.8,40,49.9,40L49.9,40z"></path></svg>';
|
||
|
const EXPAND_ALL_ICON = '<svg viewBox="0 0 100 100" class="double-down-arrow-glyph" width="18" height="18"><path fill="currentColor" stroke="currentColor" d="M83.3,20c-0.9,0-1.7,0.4-2.3,1L50,52L19,21c-0.6-0.6-1.5-1-2.4-1c-1.4,0-2.6,0.8-3.1,2.1c-0.5,1.3-0.2,2.7,0.8,3.6 L47.6,59c1.3,1.3,3.4,1.3,4.7,0l33.3-33.3c1-1,1.3-2.4,0.8-3.7C85.9,20.7,84.7,19.9,83.3,20z M83.3,43.3c-0.9,0-1.7,0.4-2.3,1 l-31,31l-31-31c-0.6-0.6-1.5-1-2.4-1c-1.4,0-2.6,0.8-3.1,2.1s-0.2,2.7,0.8,3.6l33.3,33.3c1.3,1.3,3.4,1.3,4.7,0L85.7,49 c1-1,1.3-2.4,0.8-3.7C85.9,44.1,84.7,43.3,83.3,43.3L83.3,43.3z"></path></svg>';
|
||
|
const DEFAULT_SETTINGS = {
|
||
|
commands: {
|
||
|
global: true,
|
||
|
FileExplorer: false,
|
||
|
TagPane: false
|
||
|
},
|
||
|
folderContextMenu: true,
|
||
|
expandAttachmentFolder: false,
|
||
|
splitButtons: false
|
||
|
};
|
||
|
var ProviderType;
|
||
|
(function (ProviderType) {
|
||
|
ProviderType["FileExplorer"] = "FileExplorer";
|
||
|
ProviderType["TagPane"] = "TagPane";
|
||
|
})(ProviderType || (ProviderType = {}));
|
||
|
|
||
|
class ProviderBase {
|
||
|
constructor(plugin) {
|
||
|
this.plugin = plugin;
|
||
|
}
|
||
|
/**
|
||
|
* Collapse command config
|
||
|
*/
|
||
|
get collapseCommand() {
|
||
|
return {
|
||
|
id: `collapse-all-collapse-${this.leafType}`,
|
||
|
name: this.collapseCommandName,
|
||
|
icon: 'double-up-arrow-glyph',
|
||
|
callback: () => {
|
||
|
this.collapseAll();
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
/**
|
||
|
* Expand command config
|
||
|
*/
|
||
|
get expandCommand() {
|
||
|
return {
|
||
|
id: `collapse-all-expand-${this.leafType}`,
|
||
|
name: this.expandCommandName,
|
||
|
icon: 'double-down-arrow-glyph',
|
||
|
callback: () => {
|
||
|
this.expandAll();
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
/**
|
||
|
* Collapse all open items in the given leaf or all leaves
|
||
|
*/
|
||
|
collapseAll(updateIcon = true, singleLeaf = null) {
|
||
|
const leaves = singleLeaf ? [singleLeaf] : this.leaves;
|
||
|
leaves.forEach((leaf) => {
|
||
|
this.collapseOrExpandAll(leaf, true);
|
||
|
if (updateIcon) {
|
||
|
this.updateButtonIcon(leaf, undefined, true);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
/**
|
||
|
* Expand all collapsed items in the given leaf or all leaves
|
||
|
*/
|
||
|
expandAll(updateIcon = true, singleLeaf = null) {
|
||
|
const leaves = singleLeaf ? [singleLeaf] : this.leaves;
|
||
|
leaves.forEach((leaf) => {
|
||
|
this.collapseOrExpandAll(leaf, false);
|
||
|
if (updateIcon) {
|
||
|
this.updateButtonIcon(leaf, undefined, false);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
/**
|
||
|
* Adds collapse buttons to all leaves.
|
||
|
*/
|
||
|
addButtons() {
|
||
|
this.leaves.forEach((leaf) => {
|
||
|
const container = leaf.view.containerEl;
|
||
|
const navContainer = container.querySelector('div.nav-buttons-container');
|
||
|
if (!navContainer) {
|
||
|
return null;
|
||
|
}
|
||
|
if (!this.plugin.settings.splitButtons) {
|
||
|
this.addSingleButton(leaf, navContainer);
|
||
|
}
|
||
|
else {
|
||
|
this.addSplitButtons(leaf, navContainer);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
addSingleButton(leaf, navContainer) {
|
||
|
const existingButton = this.getCollapseButtons(leaf)[0];
|
||
|
if (existingButton) {
|
||
|
return;
|
||
|
}
|
||
|
const newIcon = document.createElement('div');
|
||
|
this.updateButtonIcon(leaf, newIcon);
|
||
|
newIcon.className = `${this.collapseButtonClass} collapse-all-plugin-button`;
|
||
|
this.plugin.registerDomEvent(newIcon, 'click', () => {
|
||
|
this.onSingleButtonClick(leaf);
|
||
|
});
|
||
|
navContainer.appendChild(newIcon);
|
||
|
// Register click handler on leaf to toggle button icon
|
||
|
const handler = () => {
|
||
|
this.updateButtonIcon(leaf, newIcon);
|
||
|
};
|
||
|
leaf.view.containerEl.on('click', this.collapseClickTarget, handler);
|
||
|
this.plugin.register(() => {
|
||
|
leaf.view.containerEl.off('click', this.collapseClickTarget, handler);
|
||
|
});
|
||
|
}
|
||
|
addSplitButtons(leaf, navContainer) {
|
||
|
const existingButtons = this.getCollapseButtons(leaf);
|
||
|
if (existingButtons.length == 2) {
|
||
|
return;
|
||
|
}
|
||
|
// Add collapse button
|
||
|
const collapseButton = document.createElement('div');
|
||
|
this.updateButtonIcon(leaf, collapseButton, false);
|
||
|
collapseButton.className = `${this.collapseButtonClass} collapse-all-plugin-button`;
|
||
|
this.plugin.registerDomEvent(collapseButton, 'click', () => {
|
||
|
this.collapseAll(false, leaf);
|
||
|
});
|
||
|
navContainer.appendChild(collapseButton);
|
||
|
// Add expand button
|
||
|
const expandButton = document.createElement('div');
|
||
|
this.updateButtonIcon(leaf, expandButton, true);
|
||
|
expandButton.className = `${this.collapseButtonClass} collapse-all-plugin-button`;
|
||
|
this.plugin.registerDomEvent(expandButton, 'click', () => {
|
||
|
this.expandAll(false, leaf);
|
||
|
});
|
||
|
navContainer.appendChild(expandButton);
|
||
|
}
|
||
|
/**
|
||
|
* Refresh icons for all leaves to the correct state.
|
||
|
*/
|
||
|
updateButtonIcons() {
|
||
|
this.leaves.forEach((leaf) => {
|
||
|
this.updateButtonIcon(leaf);
|
||
|
});
|
||
|
}
|
||
|
/**
|
||
|
* Remove the collapse button from all leaves.
|
||
|
*/
|
||
|
removeCollapseButtons() {
|
||
|
this.leaves.forEach((leaf) => {
|
||
|
const buttons = this.getCollapseButtons(leaf);
|
||
|
buttons.forEach((button) => {
|
||
|
button.remove();
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
/**
|
||
|
* Returns all loaded leaves of the class leafType
|
||
|
*/
|
||
|
get leaves() {
|
||
|
return this.plugin.app.workspace.getLeavesOfType(this.leafType);
|
||
|
}
|
||
|
/**
|
||
|
* Get the collapse button for a given leaf, if it exists
|
||
|
*/
|
||
|
getCollapseButtons(leaf) {
|
||
|
return leaf.view.containerEl.querySelectorAll('.collapse-all-plugin-button');
|
||
|
}
|
||
|
/**
|
||
|
* Update icon for given leaf/button to collapse/expand all.
|
||
|
* Providing the forceAllCollapsed parameter will skip checking and assume that state
|
||
|
*/
|
||
|
updateButtonIcon(leaf, button, forceAllCollapsed) {
|
||
|
if (!button) {
|
||
|
button = this.getCollapseButtons(leaf)[0] || null;
|
||
|
}
|
||
|
if (button && forceAllCollapsed === undefined) {
|
||
|
const allCollapsed = this.allCollapsed(leaf);
|
||
|
button.innerHTML = allCollapsed ? EXPAND_ALL_ICON : COLLAPSE_ALL_ICON;
|
||
|
button.setAttribute('aria-label', allCollapsed ? 'Expand all' : 'Collapse all');
|
||
|
}
|
||
|
else if (button) {
|
||
|
button.innerHTML = forceAllCollapsed
|
||
|
? EXPAND_ALL_ICON
|
||
|
: COLLAPSE_ALL_ICON;
|
||
|
button.setAttribute('aria-label', forceAllCollapsed ? 'Expand all' : 'Collapse all');
|
||
|
}
|
||
|
}
|
||
|
/**
|
||
|
* Collapses or expands all items in the given leaf
|
||
|
*/
|
||
|
onSingleButtonClick(leaf) {
|
||
|
if (leaf) {
|
||
|
if (this.allCollapsed(leaf)) {
|
||
|
this.expandAll(true, leaf);
|
||
|
}
|
||
|
else {
|
||
|
this.collapseAll(true, leaf);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class FileExplorerProvider extends ProviderBase {
|
||
|
constructor(plugin) {
|
||
|
super(plugin);
|
||
|
this.providerType = ProviderType.FileExplorer;
|
||
|
this.displayName = 'File Explorer';
|
||
|
this.collapseButtonClass = 'clickable-icon nav-action-button';
|
||
|
this.collapseClickTarget = '.nav-folder-title';
|
||
|
this.leafType = 'file-explorer';
|
||
|
this.collapseCommandName = 'Collapse open folders in all file explorers';
|
||
|
this.expandCommandName = 'Expand closed folders in all file explorers';
|
||
|
}
|
||
|
handleMenu(menu, file, source) {
|
||
|
if (this.plugin.settings.folderContextMenu &&
|
||
|
source === 'file-explorer-context-menu' &&
|
||
|
file instanceof obsidian.TFolder) {
|
||
|
const leaf = this.plugin.app.workspace
|
||
|
.getLeavesOfType('file-explorer')
|
||
|
.first();
|
||
|
menu.addItem((item) => {
|
||
|
item
|
||
|
.setTitle('Collapse this level')
|
||
|
.setIcon('double-up-arrow-glyph')
|
||
|
.onClick(() => this.collapseOrExpandAll(leaf, true, file));
|
||
|
});
|
||
|
menu.addItem((item) => {
|
||
|
item
|
||
|
.setTitle('Expand this level')
|
||
|
.setIcon('double-down-arrow-glyph')
|
||
|
.onClick(() => this.collapseOrExpandAll(leaf, false, file));
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
collapseOrExpandAll(leaf, collapsed, parentFolder = null) {
|
||
|
let items = [];
|
||
|
if (parentFolder) {
|
||
|
items = this.getCurrentLevelItems(leaf, parentFolder);
|
||
|
}
|
||
|
else {
|
||
|
items = this.getExplorerItems(leaf);
|
||
|
}
|
||
|
items.forEach((item) => {
|
||
|
if (this.explorerItemIsFolder(item) && item.collapsed !== collapsed) {
|
||
|
if (collapsed === false &&
|
||
|
this.expandAttachmentFolder === false &&
|
||
|
this.folderIsAttachmentFolder(item.file)) {
|
||
|
return;
|
||
|
}
|
||
|
item.setCollapsed(collapsed);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
allCollapsed(leaf) {
|
||
|
const items = this.getExplorerItems(leaf);
|
||
|
return items.every((i) => !this.explorerItemIsFolder(i) || i.collapsed === true);
|
||
|
}
|
||
|
get attachmentFolder() {
|
||
|
return this.plugin.app.vault.config.attachmentFolderPath || '';
|
||
|
}
|
||
|
get expandAttachmentFolder() {
|
||
|
return this.plugin.settings.expandAttachmentFolder;
|
||
|
}
|
||
|
/**
|
||
|
* Get all `fileItems` on explorer view. This property is not documented.
|
||
|
*/
|
||
|
getExplorerItems(leaf) {
|
||
|
return Object.values(leaf.view.fileItems);
|
||
|
}
|
||
|
/**
|
||
|
* Get all FileExplorerItems that are descendants of the current folder
|
||
|
*/
|
||
|
getCurrentLevelItems(leaf, parentFolder) {
|
||
|
const allItems = this.getExplorerItems(leaf);
|
||
|
// This is a very naiive but cheap way to do this.
|
||
|
return allItems.filter((item) => item.file.path.startsWith(`${parentFolder.path}/`) ||
|
||
|
item.file.path === parentFolder.path);
|
||
|
}
|
||
|
/**
|
||
|
* Ensures given explorer item is a folder and not the root or a note
|
||
|
*/
|
||
|
explorerItemIsFolder(item) {
|
||
|
return (item.file instanceof obsidian.TFolder &&
|
||
|
item.file.path !== '/' &&
|
||
|
item.collapsed !== undefined);
|
||
|
}
|
||
|
folderIsAttachmentFolder(folder) {
|
||
|
if (!this.attachmentFolder || this.attachmentFolder === './') {
|
||
|
return false;
|
||
|
}
|
||
|
if (folder.path === this.attachmentFolder) {
|
||
|
return true;
|
||
|
}
|
||
|
if (this.attachmentFolder.startsWith('./') &&
|
||
|
folder.path.endsWith(this.attachmentFolder.slice(1))) {
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class TagPaneProvider extends ProviderBase {
|
||
|
constructor(plugin) {
|
||
|
super(plugin);
|
||
|
this.providerType = ProviderType.TagPane;
|
||
|
this.displayName = 'Tag Pane';
|
||
|
this.collapseButtonClass = 'clickable-icon nav-action-button';
|
||
|
this.collapseClickTarget = '.tag-container .tree-item';
|
||
|
this.leafType = 'tag';
|
||
|
this.collapseCommandName = 'Collapse open tags in all tag explorers';
|
||
|
this.expandCommandName = 'Expand closed tags in all tag explorers';
|
||
|
}
|
||
|
collapseOrExpandAll(leaf, collapsed) {
|
||
|
// Get tags
|
||
|
const items = this.getTagItems(leaf);
|
||
|
// Collapse / expand
|
||
|
items.forEach((item) => {
|
||
|
if (this.getChildrenSafe(item).length > 0 &&
|
||
|
item.collapsed !== collapsed) {
|
||
|
item.setCollapsed(collapsed);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
allCollapsed(leaf) {
|
||
|
return this.tagsAreCollapsed(this.getTagItems(leaf));
|
||
|
}
|
||
|
/**
|
||
|
* Get the root tag pane items from the tag pane view. This property is not documented.
|
||
|
*/
|
||
|
getTagItems(tagPane) {
|
||
|
return Object.values(tagPane.view.tagDoms);
|
||
|
}
|
||
|
/**
|
||
|
* Given the root tags, checks all children to confirm they are closed. Note that this is recursive.
|
||
|
*/
|
||
|
tagsAreCollapsed(items) {
|
||
|
return items.every((i) => this.getChildrenSafe(i).length === 0 || i.collapsed === true);
|
||
|
}
|
||
|
getChildrenSafe(item) {
|
||
|
var _a;
|
||
|
return (_a = item.children) !== null && _a !== void 0 ? _a : item.vChildren.children;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class CollapseAllPluginSettings extends obsidian.PluginSettingTab {
|
||
|
constructor(app, plugin) {
|
||
|
super(app, plugin);
|
||
|
this.plugin = plugin;
|
||
|
}
|
||
|
display() {
|
||
|
this.containerEl.empty();
|
||
|
this.containerEl.createEl('h2', { text: 'Collapse all plugin settings.' });
|
||
|
new obsidian.Setting(this.containerEl)
|
||
|
.setName('Split buttons')
|
||
|
.setDesc('If enabled, instead of swapping between collapse and expand, there will be two separate buttons, one for collapse and one for expand.')
|
||
|
.addToggle((toggle) => {
|
||
|
toggle
|
||
|
.setTooltip('Split buttons')
|
||
|
.setValue(this.plugin.settings.splitButtons)
|
||
|
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
|
||
|
this.plugin.settings.splitButtons = value;
|
||
|
this.plugin.onunload();
|
||
|
this.plugin.allProviders.forEach((provider) => {
|
||
|
provider.addButtons();
|
||
|
});
|
||
|
yield this.plugin.saveSettings();
|
||
|
}));
|
||
|
});
|
||
|
new obsidian.Setting(this.containerEl)
|
||
|
.setName('Folder context menu')
|
||
|
.setDesc('If enabled, add commands to the folder right-click context menu to collapse and expand that folder and its children only.')
|
||
|
.addToggle((toggle) => {
|
||
|
toggle
|
||
|
.setTooltip('Folder context menu')
|
||
|
.setValue(this.plugin.settings.folderContextMenu)
|
||
|
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
|
||
|
this.plugin.settings.folderContextMenu = value;
|
||
|
yield this.plugin.saveSettings();
|
||
|
}));
|
||
|
});
|
||
|
new obsidian.Setting(this.containerEl)
|
||
|
.setName('Expand attachment folder')
|
||
|
.setDesc('If enabled, the attachment folder will be expanded with other folders. Otherwise, it will be skipped.')
|
||
|
.addToggle((toggle) => {
|
||
|
toggle
|
||
|
.setTooltip('Expand attachment folder')
|
||
|
.setValue(this.plugin.settings.expandAttachmentFolder)
|
||
|
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
|
||
|
this.plugin.settings.expandAttachmentFolder = value;
|
||
|
yield this.plugin.saveSettings();
|
||
|
}));
|
||
|
});
|
||
|
this.containerEl.createEl('h3', { text: 'Command settings' });
|
||
|
this.containerEl.createEl('p', {
|
||
|
text: 'Each toggle controls whether commands should be added to collapse and expand that view, or global which operates on all available views. Updates on app reload.'
|
||
|
});
|
||
|
// Add global toggle
|
||
|
new obsidian.Setting(this.containerEl).setName('Global').addToggle((toggle) => {
|
||
|
toggle
|
||
|
.setTooltip('Global')
|
||
|
.setValue(this.plugin.settings.commands.global)
|
||
|
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
|
||
|
this.plugin.settings.commands.global = value;
|
||
|
yield this.plugin.saveSettings();
|
||
|
}));
|
||
|
});
|
||
|
// Add individual toggles
|
||
|
this.plugin.allProviders.forEach((provider) => {
|
||
|
new obsidian.Setting(this.containerEl)
|
||
|
.setName(provider.displayName)
|
||
|
.addToggle((toggle) => {
|
||
|
toggle
|
||
|
.setTooltip(provider.displayName)
|
||
|
.setValue(this.plugin.settings.commands[provider.providerType])
|
||
|
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
|
||
|
this.plugin.settings.commands[provider.providerType] = value;
|
||
|
yield this.plugin.saveSettings();
|
||
|
}));
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class CollapseAllPlugin extends obsidian.Plugin {
|
||
|
constructor() {
|
||
|
super(...arguments);
|
||
|
this.settings = DEFAULT_SETTINGS;
|
||
|
this.providers = {
|
||
|
[ProviderType.FileExplorer]: new FileExplorerProvider(this),
|
||
|
[ProviderType.TagPane]: new TagPaneProvider(this)
|
||
|
};
|
||
|
}
|
||
|
get allProviders() {
|
||
|
return Object.values(this.providers);
|
||
|
}
|
||
|
onload() {
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
// Load settings
|
||
|
this.settings = Object.assign({}, DEFAULT_SETTINGS, yield this.loadData());
|
||
|
// Initialize
|
||
|
this.app.workspace.onLayoutReady(() => {
|
||
|
this.allProviders.forEach((provider) => {
|
||
|
provider.addButtons();
|
||
|
});
|
||
|
});
|
||
|
this.app.workspace.on('file-menu', (menu, file, source) => {
|
||
|
this.providers.FileExplorer.handleMenu(menu, file, source);
|
||
|
});
|
||
|
// File explorers that get opened later on
|
||
|
this.registerEvent(this.app.workspace.on('layout-change', () => {
|
||
|
this.allProviders.forEach((provider) => {
|
||
|
provider.addButtons();
|
||
|
});
|
||
|
}));
|
||
|
// Update icon when files are opened
|
||
|
this.registerEvent(this.app.workspace.on('file-open', () => {
|
||
|
if (!this.settings.splitButtons) {
|
||
|
this.allProviders.forEach((provider) => {
|
||
|
provider.updateButtonIcons();
|
||
|
});
|
||
|
}
|
||
|
}));
|
||
|
if (this.settings.commands.global) {
|
||
|
// Add global collapse command to palette
|
||
|
this.addCommand({
|
||
|
id: 'collapse-all-collapse',
|
||
|
name: 'Collapse open items in all supported explorers',
|
||
|
icon: 'double-up-arrow-glyph',
|
||
|
callback: () => {
|
||
|
this.allProviders.forEach((provider) => {
|
||
|
provider.collapseAll();
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
// Add global expand command to palette
|
||
|
this.addCommand({
|
||
|
id: 'collapse-all-expand',
|
||
|
name: 'Expand closed items in all supported explorers',
|
||
|
icon: 'double-down-arrow-glyph',
|
||
|
callback: () => {
|
||
|
this.allProviders.forEach((provider) => {
|
||
|
provider.expandAll();
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
// Add individual commands for each provider
|
||
|
this.allProviders.forEach((provider) => {
|
||
|
if (this.settings.commands[provider.providerType]) {
|
||
|
this.addCommand(provider.collapseCommand);
|
||
|
this.addCommand(provider.expandCommand);
|
||
|
}
|
||
|
});
|
||
|
// Add settings tab
|
||
|
this.addSettingTab(new CollapseAllPluginSettings(this.app, this));
|
||
|
});
|
||
|
}
|
||
|
onunload() {
|
||
|
// Remove all collapse buttons
|
||
|
this.allProviders.forEach((provider) => {
|
||
|
provider.removeCollapseButtons();
|
||
|
});
|
||
|
}
|
||
|
saveSettings() {
|
||
|
return this.saveData(this.settings);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = CollapseAllPlugin;
|
||
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJza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