Browse Source

Merge branch 'add-lock-and-close-commands' into next

pull/190/head
meld-cp 2 years ago
parent
commit
e13257a9ff
  1. 31
      src/features/feature-whole-note-encrypt/FeatureWholeNoteEncrypt.ts

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

@ -49,16 +49,23 @@ export default class FeatureWholeNoteEncryptV2 implements IMeldEncryptPluginFeat @@ -49,16 +49,23 @@ export default class FeatureWholeNoteEncryptV2 implements IMeldEncryptPluginFeat
this.statusIndicator.setText('🔐');
// editor context menu
this.plugin.registerEvent( this.plugin.app.workspace.on('editor-menu', (menu, editor, info) => {
if( info.file == null || !ENCRYPTED_FILE_EXTENSIONS.includes( info.file.extension ) ){
this.plugin.registerEvent( this.plugin.app.workspace.on('editor-menu', (menu, editor, view) => {
if( view.file == null || !ENCRYPTED_FILE_EXTENSIONS.includes( view.file.extension ) ){
return;
}
if (info instanceof EncryptedMarkdownView){
if (view instanceof EncryptedMarkdownView){
menu.addItem( (item) => {
item
.setTitle('Change Password')
.setIcon('key-round')
.onClick( async () => await view.changePassword() );
}
);
menu.addItem( (item) => {
item
.setTitle('Lock & Close')
.setIcon('lock')
.onClick( async () => await info.changePassword() );
.onClick( () => this.lockAndClose(view) );
}
);
}
@ -80,10 +87,17 @@ export default class FeatureWholeNoteEncryptV2 implements IMeldEncryptPluginFeat @@ -80,10 +87,17 @@ export default class FeatureWholeNoteEncryptV2 implements IMeldEncryptPluginFeat
menu.addItem( (item) => {
item
.setTitle('Change Password')
.setIcon('lock')
.setIcon('key-round')
.onClick( async () => await view.changePassword() );
}
);
menu.addItem( (item) => {
item
.setTitle('Lock & Close')
.setIcon('lock')
.onClick( () => this.lockAndClose(view) );
}
);
}))
@ -138,6 +152,13 @@ export default class FeatureWholeNoteEncryptV2 implements IMeldEncryptPluginFeat @@ -138,6 +152,13 @@ export default class FeatureWholeNoteEncryptV2 implements IMeldEncryptPluginFeat
}
private lockAndClose( view: EncryptedMarkdownView ) : void {
view.detachSafely();
if ( view.file != null ){
SessionPasswordService.clearForFile( view.file );
}
}
private getDefaultFileFolder() : TFolder {
const activeFile = this.plugin.app.workspace.getActiveFile();

Loading…
Cancel
Save