Browse Source

add key bindable command to toggle reading view

pull/125/head
Cleon 2 years ago
parent
commit
c7e25062c9
  1. 9
      src/features/feature-whole-note-encrypt/EncryptedFileContentView.ts
  2. 17
      src/features/feature-whole-note-encrypt/FeatureWholeNoteEncrypt.ts

9
src/features/feature-whole-note-encrypt/EncryptedFileContentView.ts

@ -51,8 +51,8 @@ export class EncryptedFileContentView extends TextFileView { @@ -51,8 +51,8 @@ export class EncryptedFileContentView extends TextFileView {
this.defaultEditNoteView = ( settings.defaultView as EditViewEnum ) ?? EditViewEnum.source;
this.currentEditNoteMode = this.defaultEditNoteView;
this.elActionEditView = this.addAction( this.iconSourceView, 'Source', () => this.actionToggleEditMode() );
this.elActionReadingView = this.addAction( this.iconReadingView, 'Reading', () => this.actionToggleEditMode() );
this.elActionEditView = this.addAction( this.iconSourceView, 'Source', () => this.toggleReadingView() );
this.elActionReadingView = this.addAction( this.iconReadingView, 'Reading', () => this.toggleReadingView() );
this.elActionIconLockNote = this.addAction( this.iconLockFile, 'Lock', () => this.actionLockFile() );
this.elActionChangePassword = this.addAction( this.iconChangePassword, 'Change Password', () => this.actionChangePassword() );
@ -64,9 +64,10 @@ export class EncryptedFileContentView extends TextFileView { @@ -64,9 +64,10 @@ export class EncryptedFileContentView extends TextFileView {
this.containerEl.classList.add('meld-encrypt-encrypted-note-view');
this.contentEl.classList.add('meld-encrypt-encrypted-note-view-content');
}
private actionToggleEditMode(){
public toggleReadingView(){
if ( this.currentView != EncryptedFileContentViewStateEnum.editNote ){
return;
}
@ -101,7 +102,7 @@ export class EncryptedFileContentView extends TextFileView { @@ -101,7 +102,7 @@ export class EncryptedFileContentView extends TextFileView {
.setSection('action')
.setIcon( this.iconToggleEditView )
.setTitle('Toggle Editing/Reading')
.onClick( () => this.actionToggleEditMode() )
.onClick( () => this.toggleReadingView() )
;
});
menu.addItem( m =>{

17
src/features/feature-whole-note-encrypt/FeatureWholeNoteEncrypt.ts

@ -32,6 +32,13 @@ export default class FeatureWholeNoteEncrypt implements IMeldEncryptPluginFeatur @@ -32,6 +32,13 @@ export default class FeatureWholeNoteEncrypt implements IMeldEncryptPluginFeatur
icon: 'file-lock-2',
callback: () => this.processCreateNewEncryptedNoteCommand(),
});
this.plugin.addCommand({
id: 'meld-encrypt-toggle-reading-view',
name: 'Toggle Reading View',
icon: 'edit',
callback: () => this.processToggleReadingViewCommand(),
});
}
@ -39,7 +46,12 @@ export default class FeatureWholeNoteEncrypt implements IMeldEncryptPluginFeatur @@ -39,7 +46,12 @@ export default class FeatureWholeNoteEncrypt implements IMeldEncryptPluginFeatur
this.plugin.app.workspace.detachLeavesOfType(VIEW_TYPE_ENCRYPTED_FILE_CONTENT);
}
private processCreateNewEncryptedNoteCommand(): boolean{
private processToggleReadingViewCommand() {
const view = this.plugin.app.workspace.getActiveViewOfType( EncryptedFileContentView );
view?.toggleReadingView();
}
private processCreateNewEncryptedNoteCommand() {
try{
const newFilename = moment().format('[Untitled] YYYYMMDD hhmmss[.encrypted]');
@ -62,12 +74,9 @@ export default class FeatureWholeNoteEncrypt implements IMeldEncryptPluginFeatur @@ -62,12 +74,9 @@ export default class FeatureWholeNoteEncrypt implements IMeldEncryptPluginFeatur
new Notice(reason, 10000);
});
return true;
}catch(e){
console.error(e);
new Notice(e, 10000);
return false;
}
}

Loading…
Cancel
Save