Skip to content

Commit 542e546

Browse files
committed
FIX pasting of a rule in an empty group
1 parent 006760c commit 542e546

8 files changed

Lines changed: 32 additions & 14 deletions

File tree

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- The online JSON documentation now shows references between UID fields.
77
- Fixed a crash when updating an external CastleDB file
88
- Fixed support for Aseprite 1.3.5 files
9+
- Fixed the pasting of a copied rule inside an empty group
910
- CastleDB: fixed support for unique IDs in lists (note: nested lists in lists are not supported yet)
1011

1112
# 1.5.3

src/electron.renderer/ui/FieldDefsForm.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ class FieldDefsForm {
275275
ui.modal.ContextMenu.attachTo_new(li, (ctx:ui.modal.ContextMenu)->{
276276
ctx.addElement( Ctx_CopyPaster({
277277
elementName: "field",
278-
clipType: CFieldDef,
279278
copy: ()->App.ME.clipboard.copyData(CFieldDef, fd.toJson()),
280279
cut: ()->{
281280
App.ME.clipboard.copyData(CFieldDef, fd.toJson());
@@ -286,6 +285,7 @@ class FieldDefsForm {
286285
editor.ge.emit(FieldDefAdded(copy));
287286
selectField(copy);
288287
},
288+
pasteAcceptedTypes: [CFieldDef],
289289
duplicate: ()->{
290290
var copy = duplicateFieldDef(fd);
291291
editor.ge.emit( FieldDefAdded(copy) );

src/electron.renderer/ui/modal/ContextMenu.hx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ typedef CtxActionSettings = {
3838

3939
typedef CtxCopyPasterSettings = {
4040
var elementName : String;
41-
var clipType : ClipboardType;
4241
var copy : Null< Void->Void >;
4342
var cut : Null< Void->Void >;
4443
var paste : Null< Void->Void >;
44+
var pasteAcceptedTypes : Array<ClipboardType>;
4545
var duplicate : Null< Void->Void >;
4646
var delete : Null< Void->Void >;
4747
}
@@ -332,7 +332,16 @@ class ContextMenu extends ui.Modal {
332332
addElement( Ctx_Action({
333333
iconId : "paste",
334334
cb : settings.paste,
335-
enable: ()->settings.paste!=null && App.ME.clipboard.is(settings.clipType),
335+
enable: ()->{
336+
if( settings.paste==null )
337+
return false;
338+
339+
for( type in settings.pasteAcceptedTypes )
340+
if( App.ME.clipboard.is(type) )
341+
return true;
342+
343+
return false;
344+
},
336345
tip : L._PasteAfter(settings.elementName),
337346
}), jElement );
338347

src/electron.renderer/ui/modal/panel/EditAllAutoLayerRules.hx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ class EditAllAutoLayerRules extends ui.modal.Panel {
375375
for(r in copy.rules)
376376
invalidateRuleAndOnesBelow(r);
377377
},
378-
enable: ()->return App.ME.clipboard.is(CRuleGroup),
378+
enable: ()->App.ME.clipboard.is(CRuleGroup),
379379
});
380380
});
381381

@@ -645,18 +645,26 @@ class EditAllAutoLayerRules extends ui.modal.Panel {
645645
ContextMenu.attachTo_new(jGroup, jGroupHeader, (ctx)->{
646646
ctx.addElement( Ctx_CopyPaster({
647647
elementName: "group",
648-
clipType: CRuleGroup,
649648
copy: ()->App.ME.clipboard.copyData(CRuleGroup, rg.toJson(li.def)),
650649
cut: ()->{
651650
App.ME.clipboard.copyData(CRuleGroup, rg.toJson(li.def));
652651
deleteRuleGroup(rg, false);
653652
},
654653
paste: ()->{
655-
var copy = ld.pasteRuleGroup(project, App.ME.clipboard, rg);
656-
editor.ge.emit(LayerRuleGroupAdded(copy));
657-
for(r in copy.rules)
658-
invalidateRuleAndOnesBelow(r);
654+
if( App.ME.clipboard.is(CRule) ) {
655+
var copy = ld.pasteRule(project, rg, App.ME.clipboard);
656+
lastRule = copy;
657+
editor.ge.emit( LayerRuleAdded(copy) );
658+
invalidateRuleAndOnesBelow(copy);
659+
}
660+
else if( App.ME.clipboard.is(CRuleGroup) ) {
661+
var copy = ld.pasteRuleGroup(project, App.ME.clipboard, rg);
662+
editor.ge.emit(LayerRuleGroupAdded(copy));
663+
for(r in copy.rules)
664+
invalidateRuleAndOnesBelow(r);
665+
}
659666
},
667+
pasteAcceptedTypes: [CRuleGroup, CRule],
660668
duplicate: ()-> {
661669
var copy = ld.duplicateRuleGroup(project, rg);
662670
editor.ge.emit( LayerRuleGroupAdded(copy) );
@@ -1050,7 +1058,6 @@ class EditAllAutoLayerRules extends ui.modal.Panel {
10501058
ContextMenu.attachTo_new(jRule, (ctx:ContextMenu)->{
10511059
ctx.addElement( Ctx_CopyPaster({
10521060
elementName: "rule",
1053-
clipType: CRule,
10541061

10551062
copy: ()->App.ME.clipboard.copyData(CRule, r.toJson(ld)),
10561063
cut: ()->{
@@ -1063,6 +1070,7 @@ class EditAllAutoLayerRules extends ui.modal.Panel {
10631070
editor.ge.emit( LayerRuleAdded(copy) );
10641071
invalidateRuleAndOnesBelow(copy);
10651072
},
1073+
pasteAcceptedTypes: [CRule],
10661074
duplicate: ()->{
10671075
var copy = ld.duplicateRule(project, rg, r);
10681076
lastRule = copy;

src/electron.renderer/ui/modal/panel/EditEntityDefs.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,6 @@ class EditEntityDefs extends ui.modal.Panel {
636636
ContextMenu.attachTo_new(jEnt, (ctx:ContextMenu)->{
637637
ctx.addElement( Ctx_CopyPaster({
638638
elementName: "entity",
639-
clipType: CEntityDef,
640639
copy: ()->App.ME.clipboard.copyData(CEntityDef, ed.toJson(project)),
641640
cut: ()->{
642641
App.ME.clipboard.copyData(CEntityDef, ed.toJson(project));
@@ -647,6 +646,7 @@ class EditEntityDefs extends ui.modal.Panel {
647646
editor.ge.emit(EntityDefAdded);
648647
selectEntity(copy);
649648
},
649+
pasteAcceptedTypes: [CEntityDef],
650650
duplicate: ()->{
651651
var copy = project.defs.duplicateEntityDef(ed);
652652
editor.ge.emit(EntityDefAdded);

src/electron.renderer/ui/modal/panel/EditEnumDefs.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ class EditEnumDefs extends ui.modal.Panel {
221221
ContextMenu.attachTo_new(jLi, (ctx:ContextMenu)->{
222222
ctx.addElement( Ctx_CopyPaster({
223223
elementName: "enum",
224-
clipType: CLayerDef,
225224

226225
copy: ()->App.ME.clipboard.copyData(CEnumDef, ed.toJson(project)),
227226
cut: ()->{
@@ -233,6 +232,7 @@ class EditEnumDefs extends ui.modal.Panel {
233232
editor.ge.emit(EnumDefAdded);
234233
selectEnum(copy);
235234
},
235+
pasteAcceptedTypes: [CLayerDef],
236236
duplicate: ()->{
237237
var copy = project.defs.duplicateEnumDef(ed);
238238
editor.ge.emit(EnumDefAdded);

src/electron.renderer/ui/modal/panel/EditLayerDefs.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,6 @@ class EditLayerDefs extends ui.modal.Panel {
10241024
ContextMenu.attachTo_new(jLi, (ctx:ContextMenu)->{
10251025
ctx.addElement( Ctx_CopyPaster({
10261026
elementName: "layer",
1027-
clipType: CLayerDef,
10281027
copy: ()->App.ME.clipboard.copyData(CLayerDef, ld.toJson()),
10291028
cut: ()->{
10301029
App.ME.clipboard.copyData(CLayerDef, ld.toJson());
@@ -1037,6 +1036,7 @@ class EditLayerDefs extends ui.modal.Panel {
10371036
select(copy);
10381037
}
10391038
},
1039+
pasteAcceptedTypes: [CLayerDef],
10401040
duplicate: ()->{
10411041
var copy = project.defs.duplicateLayerDef(ld);
10421042
editor.ge.emit(LayerDefAdded);

src/electron.renderer/ui/modal/panel/EditTilesetDefs.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ class EditTilesetDefs extends ui.modal.Panel {
342342
ContextMenu.attachTo_new(jLi, (ctx:ContextMenu)->{
343343
ctx.addElement( Ctx_CopyPaster({
344344
elementName: "tileset",
345-
clipType: CTilesetDef,
346345
copy: td.isUsingEmbedAtlas() ? null : ()->App.ME.clipboard.copyData(CTilesetDef, td.toJson()),
347346
cut: td.isUsingEmbedAtlas() ? null : ()->{
348347
App.ME.clipboard.copyData(CTilesetDef, td.toJson());
@@ -353,6 +352,7 @@ class EditTilesetDefs extends ui.modal.Panel {
353352
editor.ge.emit( TilesetDefAdded(copy) );
354353
selectTileset(copy);
355354
},
355+
pasteAcceptedTypes: [CTilesetDef],
356356
duplicate: td.isUsingEmbedAtlas() ? null : ()->{
357357
var copy = project.defs.duplicateTilesetDef(td);
358358
editor.ge.emit( TilesetDefAdded(copy) );

0 commit comments

Comments
 (0)