@@ -25,12 +25,13 @@ export class PresetSearch extends HandlebarsApplicationMixin(ApplicationV2) {
2525 resizable : true ,
2626 } ,
2727 position : {
28- width : 300 ,
28+ width : 350 ,
2929 height : 500 ,
3030 } ,
3131 classes : [ 'tokenmagic' , 'search' , 'flexcol' ] ,
3232 actions : {
3333 delete : PresetSearch . _onDeletePreset ,
34+ edit : PresetSearch . _onEditPreset ,
3435 toggleTemplates : PresetSearch . _onToggleTemplates ,
3536 } ,
3637 } ;
@@ -45,7 +46,7 @@ export class PresetSearch extends HandlebarsApplicationMixin(ApplicationV2) {
4546 } ,
4647 presets : {
4748 template : `modules/tokenmagic/templates/apps/filter-editor/filter-list.hbs` ,
48- scrollable : [ '.filter-list ' ] ,
49+ scrollable : [ '' ] ,
4950 } ,
5051 } ;
5152
@@ -60,7 +61,7 @@ export class PresetSearch extends HandlebarsApplicationMixin(ApplicationV2) {
6061 context . controls = [
6162 {
6263 action : 'toggleTemplates' ,
63- tooltip : 'Toggle Template presets' ,
64+ tooltip : game . i18n . localize ( 'TMFX.app.searchPreset.controls.templateToggle' ) ,
6465 icon : 'fa-fw fa-solid fa-ruler-combined' ,
6566 active : Boolean ( this . _templates ) ,
6667 } ,
@@ -88,16 +89,23 @@ export class PresetSearch extends HandlebarsApplicationMixin(ApplicationV2) {
8889 if ( terms . length ) {
8990 presets = presets . filter ( ( p ) => {
9091 const name = p . name . toLocaleLowerCase ( ) ;
91- return terms . every ( ( t ) => name . includes ( t ) ) ;
92+ const filterTypes = p . params . map ( ( param ) => param . filterType . toLocaleLowerCase ( ) ) ;
93+ return terms . every ( ( t ) => name . includes ( t ) || filterTypes . some ( ( type ) => type . includes ( t ) ) ) ;
9294 } ) ;
9395 }
9496 }
9597
9698 const controls = [
99+ {
100+ class : 'edit' ,
101+ action : 'edit' ,
102+ tooltip : game . i18n . localize ( 'SIDEBAR.Edit' ) ,
103+ icon : 'fa-solid fa-pen-to-square' ,
104+ } ,
97105 {
98106 class : 'delete' ,
99107 action : 'delete' ,
100- tooltip : ' Delete',
108+ tooltip : game . i18n . localize ( 'SIDEBAR. Delete') ,
101109 icon : 'fa-solid fa-trash' ,
102110 } ,
103111 ] ;
@@ -169,4 +177,87 @@ export class PresetSearch extends HandlebarsApplicationMixin(ApplicationV2) {
169177 this . render ( { parts : [ 'presets' ] } ) ;
170178 }
171179 }
180+
181+ static async _onEditPreset ( event , element ) {
182+ const { filterId : name , filterType : library } = element . closest ( '.filter' ) . dataset ;
183+ const preset = TokenMagic . getPresets ( library ) . find ( ( p ) => p . name === name ) ;
184+ if ( preset ) new PresetEdit ( { preset, parentApp : this } ) . render ( true ) ;
185+ }
186+ }
187+
188+ export class PresetEdit extends HandlebarsApplicationMixin ( ApplicationV2 ) {
189+ constructor ( { preset, parentApp } ) {
190+ super ( { } ) ;
191+ this . _preset = foundry . utils . deepClone ( preset ) ;
192+ this . _parentApp = parentApp ;
193+ }
194+
195+ /** @override */
196+ static DEFAULT_OPTIONS = {
197+ id : 'tmfx-preset-edit' ,
198+ tag : 'form' ,
199+ window : {
200+ resizable : false ,
201+ contentClasses : [ 'standard-form' ] ,
202+ } ,
203+ form : {
204+ handler : PresetEdit . _onSubmit ,
205+ submitOnChange : false ,
206+ closeOnSubmit : true ,
207+ } ,
208+ position : {
209+ width : 450 ,
210+ height : 'auto' ,
211+ } ,
212+ classes : [ 'tokenmagic' , 'flexcol' ] ,
213+ actions : {
214+ delete : PresetSearch . _onDeletePreset ,
215+ edit : PresetSearch . _onEditPreset ,
216+ toggleTemplates : PresetSearch . _onToggleTemplates ,
217+ } ,
218+ } ;
219+
220+ get title ( ) {
221+ return this . _preset . name ;
222+ }
223+
224+ /** @override */
225+ static PARTS = {
226+ main : {
227+ template : `modules/tokenmagic/templates/apps/preset-search/preset-edit.hbs` ,
228+ } ,
229+ footer : { template : 'templates/generic/form-footer.hbs' } ,
230+ } ;
231+
232+ /** @override */
233+ async _preparePartContext ( partId , context , options ) {
234+ context . partId = partId ;
235+ switch ( partId ) {
236+ case 'main' :
237+ context . name = this . _preset . name ;
238+ context . library = this . _preset . library ;
239+ context . defaultTexture = this . _preset . defaultTexture ;
240+ context . params = JSON . stringify ( this . _preset . params , null , 2 ) ;
241+ break ;
242+ case 'footer' :
243+ context . buttons = [
244+ { type : 'submit' , icon : 'fa-solid fa-floppy-disk' , label : game . i18n . localize ( 'TMFX.save' ) , action : 'save' } ,
245+ ] ;
246+ break ;
247+ }
248+ return context ;
249+ }
250+
251+ static async _onSubmit ( event , form , formData ) {
252+ const name = formData . object . name . trim ( ) ;
253+ const defaultTexture = formData . object . defaultTexture ?. trim ( ) ;
254+ if ( this . _preset . name === name && this . _preset . defaultTexture === defaultTexture ) return ;
255+ if ( ! name ) return ;
256+
257+ await TokenMagic . deletePreset ( { name : this . _preset . name , library : this . _preset . library } , true ) ;
258+ await TokenMagic . addPreset ( { name, library : this . _preset . library , defaultTexture } , this . _preset . params , true ) ;
259+ if ( this . _parentApp . state === ApplicationV2 . RENDER_STATES . RENDERED ) {
260+ this . _parentApp . render ( { parts : [ 'presets' ] } ) ;
261+ }
262+ }
172263}
0 commit comments