mirror of
https://github.com/hangeol-chang/obsidian-csv-allinone.git
synced 2026-07-22 05:37:25 +00:00
[FEAT] csv explorer module
This commit is contained in:
parent
e99fd4b982
commit
0094f8028a
3 changed files with 69 additions and 1 deletions
11
main.ts
11
main.ts
|
|
@ -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() {}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
52
src/csvexplorer.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue