Skip to content

Commit

Permalink
Merge pull request #7 from OfficerHalf/folder-suggest
Browse files Browse the repository at this point in the history
feat: add folder suggester for selecting folder path
  • Loading branch information
nathonius authored Nov 2, 2021
2 parents 764cb45 + 8357356 commit b8db414
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/folder-suggest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { App, FuzzySuggestModal, TFolder } from 'obsidian';

export class FolderSuggestModal extends FuzzySuggestModal<TFolder> {
items: TFolder[] = [];
callback: (folder: TFolder) => void | undefined;
selectedFolder: TFolder | null = null;

constructor(app: App, private readonly input: HTMLInputElement, private readonly items: TFolder[]) {
constructor(app: App) {
super(app);
}

Expand All @@ -16,8 +18,9 @@ export class FolderSuggestModal extends FuzzySuggestModal<TFolder> {
}

onChooseItem(item: TFolder): void {
this.input.value = item.path;
this.selectedFolder = item;
if (this.callback) {
this.callback(item);
}
this.close();
}
}
25 changes: 22 additions & 3 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { App, PluginSettingTab } from 'obsidian';
import { App, PluginSettingTab, setIcon, TFolder } from 'obsidian';
import { FolderSuggestModal } from './folder-suggest';
import { AutoClassPluginSettings } from './interfaces';
import { AutoClassPlugin } from './plugin';

export class AutoClassPluginSettingsTab extends PluginSettingTab {
private readonly folderSuggestModal: FolderSuggestModal = new FolderSuggestModal(this.app);

constructor(readonly app: App, private readonly plugin: AutoClassPlugin) {
super(app, plugin);
}
Expand Down Expand Up @@ -52,12 +55,28 @@ export class AutoClassPluginSettingsTab extends PluginSettingTab {
cls: ['auto-class-settings__table-row', 'auto-class-settings__input-row']
});
const pathCell = inputRow.createEl('td');
const pathInput = pathCell.createEl('input', {
const pathCellFlexContainer = pathCell.createDiv({ cls: 'auto-class-settings__flex-container' });
const pathButton = pathCellFlexContainer.createEl('button', { cls: 'auto-class-settings__input-button' });
setIcon(pathButton, 'folder');
const folders: TFolder[] = this.app.vault.getAllLoadedFiles().filter((f) => f instanceof TFolder) as TFolder[];
pathButton.addEventListener('click', () => {
this.folderSuggestModal.selectedFolder = null;
this.folderSuggestModal.items = folders;
this.folderSuggestModal.callback = (folder: TFolder) => {
pathInput.value = folder.path;
};
this.folderSuggestModal.open();
});
// const pathInputContainer = pathCell.createDiv();
const pathInput = pathCellFlexContainer.createEl('input', {
attr: { placeholder: 'Folder', type: 'text' }
});

const classCell = inputRow.createEl('td');
const classInput = classCell.createEl('input', { attr: { placeholder: 'class1, class2', type: 'text' } });
const classCellFlexContainer = classCell.createDiv({ cls: 'auto-class-settings__flex-container' });
const classInput = classCellFlexContainer.createEl('input', {
attr: { placeholder: 'class1, class2', type: 'text' }
});

const addCell = inputRow.createEl('td', { cls: 'auto-class-settings__button-cell' });
const addButton = addCell.createEl('button', { cls: 'mod-cta', text: 'Add' });
Expand Down
7 changes: 5 additions & 2 deletions src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
}
}
&__input-row {
border-bottom: 1px solid var(--background-modifier-border);
box-shadow: 0px 1px var(--background-modifier-border);
}
&__flex-container {
display: flex;
input {
width: 150px;
flex-grow: 1;
background-color: transparent;
border: 0;
padding: 0;
Expand Down

0 comments on commit b8db414

Please sign in to comment.