@@ -22,6 +22,7 @@ export class JsEnginePluginSettingTab extends PluginSettingTab {
22
22
23
23
display ( ) : void {
24
24
const containerEl = this . containerEl ;
25
+ const vault = this . app . vault ;
25
26
const settings = this . plugin . settings ;
26
27
containerEl . empty ( ) ;
27
28
@@ -55,7 +56,7 @@ export class JsEnginePluginSettingTab extends PluginSettingTab {
55
56
} ) ;
56
57
} ) ;
57
58
58
- const startupScriptsDirectory = this . app . vault . getFolderByPath ( settings . startupScriptsDirectory ?? '/' ) ;
59
+ const startupScriptsDirectory = vault . getFolderByPath ( settings . startupScriptsDirectory ?? '/' ) ;
59
60
let startupScripts : TFile [ ] = [ ] ;
60
61
if ( startupScriptsDirectory != null ) {
61
62
startupScripts = this . listJSfilesInDirectory ( startupScriptsDirectory ) ;
@@ -71,6 +72,23 @@ export class JsEnginePluginSettingTab extends PluginSettingTab {
71
72
el . setValue ( settings . startupScripts . contains ( file . path ) ) . onChange ( async val => this . toggleStartupScript ( file , val ) ) ;
72
73
} ) ;
73
74
}
75
+
76
+ const oldScripts = settings . startupScripts
77
+ . map ( file => vault . getFileByPath ( file ) ! )
78
+ . filter ( file => ! file . parent ?. path . startsWith ( settings . startupScriptsDirectory ?? '' ) ) ;
79
+ if ( oldScripts . length > 0 ) {
80
+ this . containerEl . createEl ( 'div' , { cls : 'callout js-engine-settings-warning' , text : 'These scripts are not in the Snippets Folder' } ) ;
81
+ }
82
+ for ( const file of oldScripts ) {
83
+ new Setting ( containerEl )
84
+ . setName ( file . basename )
85
+ . setDesc ( `Apply JS snippet from "vault/${ file . path } "` )
86
+ . addExtraButton ( el => {
87
+ el . setTooltip ( 'Move to current Snippets Folder' )
88
+ . setIcon ( 'archive-restore' )
89
+ . onClick ( async ( ) => await this . moveStartupScriptToNewDirectory ( file ) ) ;
90
+ } ) ;
91
+ }
74
92
}
75
93
76
94
async openStartupScriptsDirectory ( ) : Promise < void > {
@@ -97,4 +115,19 @@ export class JsEnginePluginSettingTab extends PluginSettingTab {
97
115
}
98
116
await this . plugin . saveSettings ( ) ;
99
117
}
118
+
119
+ async moveStartupScriptToNewDirectory ( script : TFile ) : Promise < void > {
120
+ const settings = this . plugin . settings ;
121
+ const vault = this . app . vault ;
122
+ const startupScriptsDirectory = settings . startupScriptsDirectory ?? '/' ;
123
+ const newPath = startupScriptsDirectory . concat ( '/' , script . name ) ;
124
+ if ( ( await vault . adapter . exists ( startupScriptsDirectory ) ) == false ) {
125
+ await vault . createFolder ( startupScriptsDirectory ) ;
126
+ }
127
+ settings . startupScripts . remove ( script . path ) ;
128
+ await this . app . vault . rename ( script , newPath ) ;
129
+ settings . startupScripts . push ( newPath ) ;
130
+ await this . plugin . saveSettings ( ) ;
131
+ this . display ( ) ;
132
+ }
100
133
}
0 commit comments