[FEAT] csv explorer module

This commit is contained in:
hihangeol 2025-01-11 21:54:36 +09:00
parent e99fd4b982
commit 0094f8028a
3 changed files with 69 additions and 1 deletions

11
main.ts
View file

@ -6,6 +6,7 @@ import {
App, Plugin, PluginSettingTab, Setting,
} from 'obsidian';
import CsvCreateModal from 'src/csvcreator';
import CsvExplorerModal, { getCsvFileStructure } from 'src/csvexplorer';
interface CsvPluginSettings {
mySetting: string;
@ -43,7 +44,6 @@ export default class CsvPlugin extends Plugin {
// This adds a settings tab so the user can configure various aspects of the plugin
this.addSettingTab(new CsvSettingTab(this.app, this));
// commands
this.addCommand({
id: "create-csv-table",
@ -52,6 +52,15 @@ export default class CsvPlugin extends Plugin {
new CsvCreateModal(this.app).open();
},
});
this.addCommand({
id: "open-csv-explorer",
name: "Open CSV Explorer",
callback: async () => {
const csvStructure = await getCsvFileStructure(this.app);
new CsvExplorerModal(this.app, csvStructure).open();
}
})
}
onunload() {}

View file

@ -29,6 +29,13 @@ export default class CsvCreateModal extends Modal {
}
createSCVFile() {
// .csv 파일 생성
// .csv.meta 파일 생성
}
// common api
onOpen() {
let {contentEl} = this;

52
src/csvexplorer.ts Normal file
View file

@ -0,0 +1,52 @@
import { App, Modal, TFile } from 'obsidian';
/*
obsidian csv ,\
.
*/
export const getCsvFileStructure = async (app: App): Promise<Record<string, string[]>> => {
const csvStructure: Record<string, string[]> = {};
const files = app.vault.getFiles();
// Vault 내의 모든 파일 순회
files.forEach((file: TFile) => {
if (file.extension === "csv") {
if(file.parent) {
const folderPath = file.parent.path;
if (!csvStructure[folderPath])
csvStructure[folderPath] = [];
csvStructure[folderPath].push(file.name);
}
}
});
return csvStructure;
}
export default class CsvExplorerModal extends Modal {
csvStructure: Record<string, string[]> = {};
constructor(app: App, csvStructure: Record<string, string[]>) {
super(app);
this.csvStructure = csvStructure;
}
onOpen() {
const { contentEl } = this;
contentEl.empty();
contentEl.createEl("h2", { text: "CSV Explorer" });
Object.keys(this.csvStructure).forEach((folder) => {
contentEl.createEl("h3", { text: folder });
this.csvStructure[folder].forEach((file) => {
contentEl.createEl("p", { text: file });
});
});
}
onClose() {
const { contentEl } = this;
contentEl.empty();
}
}