Skip to content

Commit

Permalink
Merge pull request #33 from Aquitano/main
Browse files Browse the repository at this point in the history
  • Loading branch information
meld-cp authored Mar 12, 2022
2 parents 1263812 + 75a4eb1 commit f94ceb4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/DecryptModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { App, Modal } from 'obsidian';
export default class DecryptModal extends Modal {
text: string;
decryptInPlace: boolean = false;
showButton: boolean

constructor(app: App, title: string, text: string = '') {
constructor(app: App, title: string, text: string = '', showButton:boolean) {
super(app);
this.text = text;
this.titleEl.innerText = title;
this.showButton = showButton;
}

onOpen() {
Expand All @@ -24,6 +26,12 @@ export default class DecryptModal extends Modal {

const btnContainerEl = contentEl.createDiv('');

if (this.showButton){
const copyBtnEl = btnContainerEl.createEl('button', { text: 'Copy' });
copyBtnEl.addEventListener('click', () => {
navigator.clipboard.writeText(textEl.value);
}); }

const decryptInPlaceBtnEl = btnContainerEl.createEl('button', { text: 'Decrypt in-place' });
decryptInPlaceBtnEl.addEventListener('click', () => {
this.decryptInPlace = true;
Expand Down
14 changes: 14 additions & 0 deletions src/MeldEncryptSettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ export default class MeldEncryptSettingsTab extends PluginSettingTab {
})
;

new Setting(containerEl)
.setName('Copy button?')
.setDesc('Show a button to copy decrypted text.')
.addToggle( toggle =>{
toggle
.setValue(this.plugin.settings.showButton)
.onChange( async value =>{
this.plugin.settings.showButton = value;
await this.plugin.saveSettings();
this.updateSettingsUi();
})
})
;

new Setting(containerEl)
.setName('Remember password?')
.setDesc('Remember the last used password for this session.')
Expand Down
6 changes: 4 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ const _HINT: string = 'πŸ’‘';
interface MeldEncryptPluginSettings {
expandToWholeLines: boolean,
confirmPassword: boolean;
showButton: boolean;
rememberPassword: boolean;
rememberPasswordTimeout: number;
}

const DEFAULT_SETTINGS: MeldEncryptPluginSettings = {
expandToWholeLines: true,
confirmPassword: true,
showButton: false,
rememberPassword: true,
rememberPasswordTimeout: 30
}
Expand Down Expand Up @@ -345,7 +347,7 @@ export default class MeldEncrypt extends Plugin {
editor.setSelection(selectionStart, selectionEnd);
editor.replaceSelection(decryptedText);
} else {
const decryptModal = new DecryptModal(this.app, 'πŸ”“', decryptedText);
const decryptModal = new DecryptModal(this.app, 'πŸ”“', decryptedText, this.settings.showButton);
decryptModal.onClose = () => {
editor.focus();
if (decryptModal.decryptInPlace) {
Expand Down Expand Up @@ -378,7 +380,7 @@ export default class MeldEncrypt extends Plugin {
editor.setSelection(selectionStart, selectionEnd);
editor.replaceSelection(decryptedText);
} else {
const decryptModal = new DecryptModal(this.app, 'πŸ”“', decryptedText);
const decryptModal = new DecryptModal(this.app, 'πŸ”“', decryptedText, this.settings.showButton);
decryptModal.onClose = () => {
editor.focus();
if (decryptModal.decryptInPlace) {
Expand Down

0 comments on commit f94ceb4

Please sign in to comment.