@@ -22,6 +22,7 @@ export class JsEnginePluginSettingTab extends PluginSettingTab {
2222
2323 display ( ) : void {
2424 const containerEl = this . containerEl ;
25+ const vault = this . app . vault ;
2526 const settings = this . plugin . settings ;
2627 containerEl . empty ( ) ;
2728
@@ -55,7 +56,7 @@ export class JsEnginePluginSettingTab extends PluginSettingTab {
5556 } ) ;
5657 } ) ;
5758
58- const startupScriptsDirectory = this . app . vault . getFolderByPath ( settings . startupScriptsDirectory ?? '/' ) ;
59+ const startupScriptsDirectory = vault . getFolderByPath ( settings . startupScriptsDirectory ?? '/' ) ;
5960 let startupScripts : TFile [ ] = [ ] ;
6061 if ( startupScriptsDirectory != null ) {
6162 startupScripts = this . listJSfilesInDirectory ( startupScriptsDirectory ) ;
@@ -71,6 +72,23 @@ export class JsEnginePluginSettingTab extends PluginSettingTab {
7172 el . setValue ( settings . startupScripts . contains ( file . path ) ) . onChange ( async val => this . toggleStartupScript ( file , val ) ) ;
7273 } ) ;
7374 }
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+ }
7492 }
7593
7694 async openStartupScriptsDirectory ( ) : Promise < void > {
@@ -97,4 +115,19 @@ export class JsEnginePluginSettingTab extends PluginSettingTab {
97115 }
98116 await this . plugin . saveSettings ( ) ;
99117 }
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+ }
100133}
0 commit comments