@@ -1181,6 +1181,71 @@ export function addCommands(
1181
1181
await dialog . launch ( ) ;
1182
1182
}
1183
1183
} ) ;
1184
+ commands . addCommand ( CommandIDs . copyObject , {
1185
+ label : trans . __ ( 'Copy Object' ) ,
1186
+ isEnabled : ( ) => {
1187
+ const current = tracker . currentWidget ;
1188
+ return current ? current . context . model . sharedModel . editable : false ;
1189
+ } ,
1190
+ execute : ( ) => {
1191
+ const current = tracker . currentWidget ;
1192
+ if ( ! current ) {
1193
+ return ;
1194
+ }
1195
+
1196
+ const objectId = getSelectedObjectId ( current ) ;
1197
+ if ( ! objectId ) {
1198
+ console . warn ( 'No object is selected to copy.' ) ;
1199
+ return ;
1200
+ }
1201
+
1202
+ const sharedModel = current . context . model . sharedModel ;
1203
+ const objectData = sharedModel . getObjectByName ( objectId ) ;
1204
+
1205
+ if ( ! objectData ) {
1206
+ console . warn ( 'Could not retrieve object data.' ) ;
1207
+ return ;
1208
+ }
1209
+
1210
+ sharedModel . awareness . setLocalStateField ( 'clipboard' , objectData ) ;
1211
+ }
1212
+ } ) ;
1213
+ commands . addCommand ( CommandIDs . pasteObject , {
1214
+ label : trans . __ ( 'Paste Object' ) ,
1215
+ isEnabled : ( ) => {
1216
+ const current = tracker . currentWidget ;
1217
+ const clipboard =
1218
+ current ?. context . model . sharedModel . awareness . getLocalState ( ) ?. clipboard ;
1219
+ return current && clipboard && current . context . model . sharedModel . editable ;
1220
+ } ,
1221
+ execute : ( ) => {
1222
+ const current = tracker . currentWidget ;
1223
+ if ( ! current ) {
1224
+ return ;
1225
+ }
1226
+
1227
+ const sharedModel = current . context . model . sharedModel ;
1228
+ const clipboard = sharedModel . awareness . getLocalState ( ) ?. clipboard ;
1229
+
1230
+ if ( ! clipboard ) {
1231
+ console . warn ( 'No data in clipboard to paste.' ) ;
1232
+ return ;
1233
+ }
1234
+
1235
+ const originalName = clipboard . name || 'Unnamed Object' ;
1236
+ let newName = originalName ;
1237
+
1238
+ let counter = 1 ;
1239
+ while ( sharedModel . objects . some ( obj => obj . name === newName ) ) {
1240
+ newName = `${ originalName } Copy${ counter > 1 ? ` ${ counter } ` : '' } ` ;
1241
+ counter ++ ;
1242
+ }
1243
+
1244
+ const newObject = { ...clipboard , name : newName } ;
1245
+ sharedModel . addObject ( newObject ) ;
1246
+ }
1247
+ } ) ;
1248
+
1184
1249
loadKeybindings ( commands , keybindings ) ;
1185
1250
}
1186
1251
@@ -1208,6 +1273,9 @@ export namespace CommandIDs {
1208
1273
export const wireframe = 'jupytercad:wireframe' ;
1209
1274
export const transform = 'jupytercad:transform' ;
1210
1275
1276
+ export const copyObject = 'jupytercad:copyObject' ;
1277
+ export const pasteObject = 'jupytercad:pasteObject' ;
1278
+
1211
1279
export const chamfer = 'jupytercad:chamfer' ;
1212
1280
export const fillet = 'jupytercad:fillet' ;
1213
1281
0 commit comments