Skip to content

Commit

Permalink
More cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
divamgupta committed Sep 6, 2023
1 parent 9449cae commit 190a33e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 71 deletions.
71 changes: 4 additions & 67 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
import { App, Editor, MarkdownView, Notice, Plugin, PluginSettingTab, Setting, WorkspaceLeaf } from 'obsidian';
import { App, Editor, MarkdownView, Notice, Plugin, WorkspaceLeaf } from 'obsidian';
import { SpreadsheetView, VIEW_TYPE_SPREADSHEET } from "./view"


// Remember to rename these classes and interfaces!

interface SpreadsheetPluginSettings {
mySetting: string;
}

const DEFAULT_SETTINGS: SpreadsheetPluginSettings = {
mySetting: 'default'
}



async function create_new_file(app, folder_path, file_no){



if(folder_path){
try {
await app.vault.createFolder(folder_path);
Expand Down Expand Up @@ -59,44 +46,26 @@ async function create_new_file(app, folder_path, file_no){


export default class SpreadsheetPlugin extends Plugin {
settings: SpreadsheetPluginSettings;

async onload() {
await this.loadSettings();

// This creates an icon in the left ribbon.
const ribbonIconEl = this.addRibbonIcon('table', 'New Spreadsheet', (evt: MouseEvent) => {
// Called when the user clicks the icon.
create_new_file(this.app);

create_new_file(this.app, undefined, undefined);
});
// Perform additional things with the ribbon
ribbonIconEl.addClass('my-plugin-ribbon-class');


let that = this;
let app = this.app;

this.registerEvent(
this.app.workspace.on("file-menu", (menu, file) => {
menu.addItem((item) => {
item.setTitle("New spreadsheet").setIcon("document").onClick(function(){
create_new_file(that.app, file.path, 0 )
create_new_file(app, file.path, 0 )
});
});
})
);



// This adds a settings tab so the user can configure various aspects of the plugin
this.addSettingTab(new SampleSettingTab(this.app, this));



// When registering intervals, this function will automatically clear the interval when the plugin is disabled.
this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000));


this.registerView(
VIEW_TYPE_SPREADSHEET,
(leaf: WorkspaceLeaf) => new SpreadsheetView(leaf)
Expand All @@ -112,38 +81,6 @@ export default class SpreadsheetPlugin extends Plugin {

}

async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}

async saveSettings() {
await this.saveData(this.settings);
}
}


class SampleSettingTab extends PluginSettingTab {
plugin: SpreadsheetPlugin;

constructor(app: App, plugin: SpreadsheetPlugin) {
super(app, plugin);
this.plugin = plugin;
}

display(): void {
const {containerEl} = this;

containerEl.empty();

new Setting(containerEl)
.setName('Setting')
.setDesc('settings')
.addText(text => text
.setPlaceholder('...')
.setValue(this.plugin.settings.mySetting)
.onChange(async (value) => {
this.plugin.settings.mySetting = value;
await this.plugin.saveSettings();
}));
}
}
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "spreadsheets",
"name": "Spreadsheets",
"version": "1.0.0",
"version": "1.0.1",
"minAppVersion": "0.15.0",
"description": "Plugin to create spreadsheets in obsidian.",
"description": "Plugin to create spreadsheets in Obsidian.",
"author": "Divam Gupta",
"authorUrl": "https://divam.io",
"isDesktopOnly": true
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "spreadsheets-plugin",
"version": "1.0.0",
"description": "Plugin to create spreadsheets in obsidian",
"version": "1.0.1",
"description": "Plugin to create spreadsheets in Obsidian.",
"main": "main.js",
"scripts": {
"dev": "node esbuild.config.mjs",
Expand Down

0 comments on commit 190a33e

Please sign in to comment.