Skip to content

Commit

Permalink
Updated copy pasters everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnight committed Dec 1, 2023
1 parent ffc45dd commit 2e5a942
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 131 deletions.
2 changes: 1 addition & 1 deletion app/assets/css/app.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3734,7 +3734,7 @@ textarea {

&.duplicate {
font-weight: bold;
color: $bgLighter;
color: $almostWhite;
font-size: 12pt;
text-transform: none;
}
Expand Down
34 changes: 13 additions & 21 deletions src/electron.renderer/ui/FieldDefsForm.hx
Original file line number Diff line number Diff line change
Expand Up @@ -271,38 +271,30 @@ class FieldDefsForm {
color: FieldDef.getTypeColorHex(fd.type, 1.5),
});

ui.modal.ContextMenu.attachTo(li, [
{
label: L._Copy(),
cb: ()->App.ME.clipboard.copyData(CFieldDef, fd.toJson()),
},
{
label: L._Cut(),
cb: ()->{

ui.modal.ContextMenu.attachTo_new(li, (ctx:ui.modal.ContextMenu)->{
ctx.addElement( Ctx_CopyPaster({
elementName: "field",
clipType: CFieldDef,
copy: ()->App.ME.clipboard.copyData(CFieldDef, fd.toJson()),
cut: ()->{
App.ME.clipboard.copyData(CFieldDef, fd.toJson());
deleteField(fd);
},
},
{
label: L._PasteAfter(),
cb: ()->{
paste: ()->{
var copy = pasteFieldDef(App.ME.clipboard, fd);
editor.ge.emit(FieldDefAdded(copy));
selectField(copy);
},
enable: ()->App.ME.clipboard.is(CFieldDef),
},
{
label: L._Duplicate(),
cb:()->{
duplicate: ()->{
var copy = duplicateFieldDef(fd);
editor.ge.emit( FieldDefAdded(copy) );
onAnyChange();
selectField(copy);
}
},
{ label: L._Delete(), cb:()->deleteField(fd) },
]);
},
delete: ()->deleteField(fd),
}) );
});

li.click( function(_) selectField(fd) );
}
Expand Down
51 changes: 38 additions & 13 deletions src/electron.renderer/ui/modal/ContextMenu.hx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ typedef CtxActionSettings = {
typedef CtxCopyPasterSettings = {
var elementName : String;
var clipType : ClipboardType;
var copy : Void->Void;
var cut : Void->Void;
var paste : Void->Void;
var duplicate : Void->Void;
var delete : Void->Void;
var copy : Null< Void->Void >;
var cut : Null< Void->Void >;
var paste : Null< Void->Void >;
var duplicate : Null< Void->Void >;
var delete : Null< Void->Void >;
}


Expand Down Expand Up @@ -307,16 +307,41 @@ class ContextMenu extends ui.Modal {

case Ctx_CopyPaster(settings):
jElement = new J('<div class="group"/>');
addElement( Ctx_Action({ iconId:"copy", cb:settings.copy, tip:L._Copy(settings.elementName) }), jElement );
addElement( Ctx_Action({ iconId:"cut", cb:settings.cut, tip:L._Cut(settings.elementName) }), jElement );
addElement( Ctx_Action({
iconId: "paste",
cb: settings.paste,
enable: ()->App.ME.clipboard.is(settings.clipType),
tip: L._PasteAfter(settings.elementName),
iconId : "copy",
cb : settings.copy,
enable: ()->settings.copy!=null,
tip : L._Copy(settings.elementName)
}), jElement );

addElement( Ctx_Action({
iconId : "cut",
cb : settings.cut,
enable: ()->settings.cut!=null,
tip : L._Cut(settings.elementName)
}), jElement );

addElement( Ctx_Action({
iconId : "paste",
cb : settings.paste,
enable: ()->settings.paste!=null && App.ME.clipboard.is(settings.clipType),
tip : L._PasteAfter(settings.elementName),
}), jElement );

addElement( Ctx_Action({
label : L.untranslated("x2"),
className : "duplicate",
cb : settings.duplicate,
enable: ()->settings.duplicate!=null,
tip : L._Duplicate(settings.elementName)
}), jElement );

addElement( Ctx_Action({
iconId : "delete",
cb : settings.delete,
enable: ()->settings.delete!=null,
tip : L._Delete(settings.elementName)
}), jElement );
addElement( Ctx_Action({ label:L.untranslated("x2"), className:"duplicate", cb:settings.duplicate, tip:L._Duplicate(settings.elementName) }), jElement );
addElement( Ctx_Action({ iconId:"delete", cb:settings.delete, tip:L._Delete(settings.elementName) }), jElement );

case Ctx_Title(label):
jElement = new J('<div class="title"/>');
Expand Down
33 changes: 12 additions & 21 deletions src/electron.renderer/ui/modal/panel/EditEntityDefs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -634,37 +634,28 @@ class EditEntityDefs extends ui.modal.Panel {
jEnt.css( "color", C.intToHex( C.toWhite(ed.color, 0.5) ) );

// Menu
ContextMenu.attachTo(jEnt, [
{
label: L._Copy(),
cb: ()->App.ME.clipboard.copyData(CEntityDef, ed.toJson(project)),
},
{
label: L._Cut(),
cb: ()->{
ContextMenu.attachTo_new(jEnt, (ctx:ContextMenu)->{
ctx.addElement( Ctx_CopyPaster({
elementName: "entity",
clipType: CEntityDef,
copy: ()->App.ME.clipboard.copyData(CEntityDef, ed.toJson(project)),
cut: ()->{
App.ME.clipboard.copyData(CEntityDef, ed.toJson(project));
deleteEntityDef(ed);
},
},
{
label: L._PasteAfter(),
cb: ()->{
paste: ()->{
var copy = project.defs.pasteEntityDef(App.ME.clipboard, ed);
editor.ge.emit(EntityDefAdded);
selectEntity(copy);
},
enable: ()->App.ME.clipboard.is(CEntityDef),
},
{
label: L._Duplicate(),
cb:()->{
duplicate: ()->{
var copy = project.defs.duplicateEntityDef(ed);
editor.ge.emit(EntityDefAdded);
selectEntity(copy);
}
},
{ label: L._Delete(), cb:deleteEntityDef.bind(ed) },
]);
},
delete: ()->deleteEntityDef(ed),
}) );
});

// Click
jEnt.click( function(_) selectEntity(ed) );
Expand Down
35 changes: 12 additions & 23 deletions src/electron.renderer/ui/modal/panel/EditEnumDefs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -229,40 +229,29 @@ class EditEnumDefs extends ui.modal.Panel {
selectEnum(ed);
});

ContextMenu.attachTo(jLi, [
{
label: L._Copy(),
cb: ()->App.ME.clipboard.copyData(CEnumDef, ed.toJson(project)),
},
{
label: L._Cut(),
cb: ()->{
ContextMenu.attachTo_new(jLi, (ctx:ContextMenu)->{
ctx.addElement( Ctx_CopyPaster({
elementName: "enum",
clipType: CLayerDef,

copy: ()->App.ME.clipboard.copyData(CEnumDef, ed.toJson(project)),
cut: ()->{
App.ME.clipboard.copyData(CEnumDef, ed.toJson(project));
deleteEnumDef(ed, true);
},
},
{
label: L._PasteAfter(),
cb: ()->{
paste: ()->{
var copy = project.defs.pasteEnumDef(App.ME.clipboard, ed);
editor.ge.emit(EnumDefAdded);
selectEnum(copy);
},
enable: ()->App.ME.clipboard.is(CEnumDef),
},
{
label: L._Duplicate(),
cb: ()->{
duplicate: ()->{
var copy = project.defs.duplicateEnumDef(ed);
editor.ge.emit(EnumDefAdded);
selectEnum(copy);
},
},
{
label: L._Delete(),
cb: deleteEnumDef.bind(ed,true),
}
]);
delete: ()->deleteEnumDef(ed,true),
}) );
});
}


Expand Down
36 changes: 11 additions & 25 deletions src/electron.renderer/ui/modal/panel/EditLayerDefs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -917,44 +917,30 @@ class EditLayerDefs extends ui.modal.Panel {
if( cur==ld )
jLi.addClass("active");

ContextMenu.attachTo(jLi, [
{
label: L._Copy(),
cb: ()->{
App.ME.clipboard.copyData(CLayerDef, ld.toJson());
},
},
{
label: L._Cut(),
cb: ()->{
ContextMenu.attachTo_new(jLi, (ctx:ContextMenu)->{
ctx.addElement( Ctx_CopyPaster({
elementName: "layer",
clipType: CLayerDef,
copy: ()->App.ME.clipboard.copyData(CLayerDef, ld.toJson()),
cut: ()->{
App.ME.clipboard.copyData(CLayerDef, ld.toJson());
deleteLayer(ld);
},
},
{
label: L._PasteAfter(),
cb: ()->{
paste: ()->{
var copy = project.defs.pasteLayerDef(App.ME.clipboard, ld);
if( copy!=null ) {
editor.ge.emit(LayerDefAdded);
select(copy);
}
},
enable: ()->App.ME.clipboard.is(CLayerDef),
},
{
label: L._Duplicate(),
cb: ()->{
duplicate: ()->{
var copy = project.defs.duplicateLayerDef(ld);
editor.ge.emit(LayerDefAdded);
select(copy);
},
},
{
label: L._Delete(),
cb: ()->deleteLayer(ld),
}
]);
delete: ()->deleteLayer(ld),
}) );
});

jLi.click( _->select(ld) );
}
Expand Down
37 changes: 11 additions & 26 deletions src/electron.renderer/ui/modal/panel/EditTilesetDefs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -348,43 +348,28 @@ class EditTilesetDefs extends ui.modal.Panel {

jLi.click( function(_) selectTileset(td) );

ContextMenu.attachTo(jLi, [
{
label: L._Copy(),
cb: ()->App.ME.clipboard.copyData(CTilesetDef, td.toJson()),
enable: ()->!td.isUsingEmbedAtlas(),
},
{
label: L._Cut(),
cb: ()->{
ContextMenu.attachTo_new(jLi, (ctx:ContextMenu)->{
ctx.addElement( Ctx_CopyPaster({
elementName: "tileset",
clipType: CTilesetDef,
copy: td.isUsingEmbedAtlas() ? null : ()->App.ME.clipboard.copyData(CTilesetDef, td.toJson()),
cut: td.isUsingEmbedAtlas() ? null : ()->{
App.ME.clipboard.copyData(CTilesetDef, td.toJson());
deleteTilesetDef(td);
},
enable: ()->!td.isUsingEmbedAtlas(),
},
{
label: L._PasteAfter(),
cb: ()->{
paste: ()->{
var copy = project.defs.pasteTilesetDef(App.ME.clipboard, td);
editor.ge.emit( TilesetDefAdded(copy) );
selectTileset(copy);
},
enable: ()->App.ME.clipboard.is(CTilesetDef),
},
{
label: L._Duplicate(),
cb: ()-> {
duplicate: td.isUsingEmbedAtlas() ? null : ()->{
var copy = project.defs.duplicateTilesetDef(td);
editor.ge.emit( TilesetDefAdded(copy) );
selectTileset(copy);
},
enable: ()->!td.isUsingEmbedAtlas(),
},
{
label: L._Delete(),
cb: deleteTilesetDef.bind(td),
},
]);
delete: ()->deleteTilesetDef(td),
}) );
});
}

// Make list sortable
Expand Down

0 comments on commit 2e5a942

Please sign in to comment.