Skip to content

Commit

Permalink
Temporarily disable formulas
Browse files Browse the repository at this point in the history
  • Loading branch information
tgrosinger committed Nov 21, 2020
1 parent 0188983 commit 3c45de5
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"name": "Advanced Tables",
"description": "Improved table navigation, formatting, manipulation, and formulas",
"isDesktopOnly": false,
"version": "0.6.1",
"version": "0.6.2",
"js": "main.js"
}
34 changes: 34 additions & 0 deletions src/disabled-formulas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { App, Modal } from 'obsidian';

export class DisabledFormulasModal extends Modal {
constructor(app: App) {
super(app);
}

onOpen() {
let { contentEl } = this;
const header = document.createElement('h2');
header.appendText('Table formulas temporarily disabled');
contentEl.appendChild(header);

const body = document.createElement('p');
body.appendText(
'I have discovered changes which will dramatically simplify how formulas ' +
'function, but implementing them will take some time. In the mean time, ' +
'I am disabling functions to prevent people from writing the old format. ' +
'Sorry for the inconvenience!',
);
contentEl.appendChild(body);

const end = document.createElement('p');
end.appendText(
'I look forward to showing you the new, simplified format 🙂',
);
contentEl.appendChild(end);
}

onClose() {
let { contentEl } = this;
contentEl.empty();
}
}
9 changes: 6 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import {
addIcon,
App,
MarkdownView,
Modal,
Notice,
Plugin,
PluginSettingTab,
Setting,
} from 'obsidian';
import { DisabledFormulasModal } from './disabled-formulas';

export default class TableEditorPlugin extends Plugin {
public settings: TableEditorPluginSettings;
Expand Down Expand Up @@ -201,7 +203,8 @@ export default class TableEditorPlugin extends Plugin {
id: 'evaluate-formulas',
name: 'Evaluate table formulas',
callback: this.newPerformTableAction((te: TableEditor) => {
te.evaluateFormulas();
// te.evaluateFormulas();
new DisabledFormulasModal(this.app).open();
}),
});

Expand All @@ -215,7 +218,7 @@ export default class TableEditorPlugin extends Plugin {
},
],
callback: this.newPerformTableAction((te: TableEditor) => {
this.tableControls = te.openTableControls();
this.tableControls = te.openTableControls(this.app);
}),
});

Expand Down Expand Up @@ -390,7 +393,7 @@ export default class TableEditorPlugin extends Plugin {
addIcon('spreadsheet', tableControlsIcon);
this.addRibbonIcon('spreadsheet', 'Advanced Tables Toolbar', () => {
this.newPerformTableAction((te: TableEditor) => {
this.tableControls = te.openTableControls();
this.tableControls = te.openTableControls(this.app);
})();
});
}
Expand Down
9 changes: 7 additions & 2 deletions src/table-controls.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { App } from 'obsidian';
import { DisabledFormulasModal } from './disabled-formulas';
import { TableEditor } from './table-editor';

/**
Expand All @@ -7,6 +9,7 @@ import { TableEditor } from './table-editor';
export class TableControls {
private readonly cm: CodeMirror.Editor;
private readonly te: TableEditor;
private readonly app: App;

/**
* Stores the position of the cursor when this widget was created.
Expand All @@ -19,9 +22,10 @@ export class TableControls {
*/
private widget: CodeMirror.LineWidget;

constructor(cm: CodeMirror.Editor, te: TableEditor) {
constructor(cm: CodeMirror.Editor, te: TableEditor, app: App) {
this.cm = cm;
this.te = te;
this.app = app;

this.cursorPos = cm.getCursor();
}
Expand Down Expand Up @@ -155,7 +159,8 @@ export class TableControls {
node.appendChild(
this.createButtonSvg(formula, 'Evaluate formulas', () => {
this.cm.setCursor(this.cursorPos);
this.te.evaluateFormulas();
new DisabledFormulasModal(this.app).open();
//this.te.evaluateFormulas();
}),
);

Expand Down
6 changes: 3 additions & 3 deletions src/table-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
SortOrder,
TableEditor as MTEEditor,
} from '@tgrosinger/md-advanced-tables';
import { Notice } from 'obsidian';
import { App, Notice } from 'obsidian';

export class TableEditor {
private readonly settings: TableEditorPluginSettings;
Expand Down Expand Up @@ -103,8 +103,8 @@ export class TableEditor {
}
};

public readonly openTableControls = (): TableControls => {
const controls = new TableControls(this.editor, this);
public readonly openTableControls = (app: App): TableControls => {
const controls = new TableControls(this.editor, this, app);
controls.display();
return controls;
};
Expand Down

0 comments on commit 3c45de5

Please sign in to comment.