generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from kraibse/feature-settings-page
feature: Added settings page and with advanced logging
- Loading branch information
Showing
9 changed files
with
172 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import TableSort from "../main"; | ||
import { Table } from "./table"; | ||
import { Column } from "./column"; | ||
|
||
|
||
export function getMousedownHandler(plugin: TableSort) { | ||
return async (evt: MouseEvent) => { | ||
|
||
if (evt.target == null) { | ||
return; | ||
} | ||
const element: HTMLElement = evt.target as HTMLElement; | ||
if (element.tagName !== "TH") { | ||
return; | ||
} | ||
const tableElement: HTMLTableElement | undefined = plugin.getTableElement(element); | ||
if (!tableElement || plugin.hasCustomClasses(tableElement)) { | ||
return; | ||
} | ||
|
||
evt.preventDefault(); | ||
|
||
const tableID: number = plugin.getTableID(tableElement); | ||
|
||
let table; | ||
if (plugin.isNewTable(tableID)) { | ||
table = new Table(tableID, tableElement, plugin); | ||
plugin.storage.push(table); | ||
} else { | ||
table = plugin.storage[tableID]; | ||
} | ||
|
||
const columnIndex = table.getColumnIndex(element); | ||
const column: Column = table.getColumnDataAt(columnIndex); | ||
|
||
table.handleClick(column, evt.ctrlKey == true); | ||
table.sort(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import TableSort from "main"; | ||
import { App, PluginSettingTab, Setting } from "obsidian"; | ||
|
||
|
||
export interface TableSortSettings { | ||
isEnabled: boolean; | ||
isDevmodeEnabled: boolean; | ||
} | ||
|
||
export const DEFAULT_SETTINGS: Partial<TableSortSettings> = { | ||
isEnabled: true, | ||
isDevmodeEnabled: false, | ||
} | ||
|
||
|
||
export class TableSortSettingsTab extends PluginSettingTab { | ||
plugin: TableSort; | ||
|
||
constructor(app: App, plugin: TableSort) { | ||
super(app, plugin); | ||
this.plugin = plugin; | ||
} | ||
|
||
display(): void { | ||
const { containerEl } = this; | ||
containerEl.empty(); | ||
|
||
const general_heading = containerEl.createEl("div"); | ||
general_heading.createEl("h2", { text: "General Settings" }); | ||
|
||
new Setting(containerEl) | ||
.setName("Toggle table sorting") | ||
.setDesc("This toggles the activation state of this plugin.") | ||
.addToggle((toggle) => { | ||
toggle | ||
.setDisabled(false) | ||
.setValue(TableSort.settings.isEnabled) | ||
.onChange(async (value) => { | ||
TableSort.settings.isEnabled = value; | ||
await this.plugin.saveSettings(); | ||
}) | ||
}); | ||
|
||
const developer_heading = containerEl.createEl("div"); | ||
developer_heading.createEl("h2", { text: "Developer Settings" }); | ||
|
||
new Setting(containerEl) | ||
.setName("Developer mode") | ||
.setDesc("This enables development logging in the console.") | ||
.addToggle((toggle) => { | ||
toggle | ||
.setDisabled(false) | ||
.setValue(TableSort.settings.isDevmodeEnabled) | ||
.onChange(async (value) => { | ||
TableSort.settings.isDevmodeEnabled = value; | ||
await this.plugin.saveSettings(); | ||
}) | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"1.0.0": "0.15.0", | ||
"1.1.0": "0.15.0", | ||
"1.2.0": "0.15.0" | ||
"1.2.0": "0.15.0", | ||
"1.3.0": "0.15.0" | ||
} |