Initial import of Scalos. To decrease size I have
[AROS-Contrib.git] / scalos / main / Undo.c
blob5748c23295e554bbaaa8691c7b8b31cd94d15a48
1 // Undo.c
2 // $Date$
3 // $Revision$
6 #include <exec/types.h>
7 #include <intuition/classes.h>
8 #include <intuition/classusr.h>
9 #include <utility/hooks.h>
10 #include <workbench/workbench.h>
11 #include <workbench/startup.h>
12 #include <libraries/asl.h>
13 #include <dos/dos.h>
15 #define __USE_SYSBASE
17 #include <proto/asl.h>
18 #include <proto/dos.h>
19 #include <proto/exec.h>
20 #include <proto/graphics.h>
21 #include <proto/intuition.h>
22 #include <proto/iconobject.h>
23 #include <proto/utility.h>
24 #include <proto/wb.h>
25 #include "debug.h"
26 #include <proto/scalos.h>
28 #include <clib/alib_protos.h>
30 #include <defs.h>
31 #include <datatypes/iconobject.h>
32 #include <scalos/scalos.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <stdio.h>
37 #include <stdarg.h>
38 #include <limits.h>
40 #include <DefIcons.h>
42 #include "scalos_structures.h"
43 #include "locale.h"
44 #include "functions.h"
45 #include "Variables.h"
47 //----------------------------------------------------------------------------
49 // local data structures
51 struct UndoStep
53 struct Node ust_Node;
54 struct List ust_EventList; // List of events in this step
55 ULONG ust_EventCount;
56 STRPTR ust_Description;
57 Object *ust_FileTransObj; // valid during Undo and Redo processing
60 struct UndoProcArg
62 struct UndoStep *upa_UndoStep;
63 struct internalScaWindowTask *upa_iwt;
66 //----------------------------------------------------------------------------
68 // local functions
70 static struct UndoStep *UndoCreateStep(void);
71 static void UndoDisposeStep(struct UndoStep *ust);
72 static struct UndoEvent *UndoCreateEvent(void);
73 static void UndoDisposeEvent(struct UndoEvent *uev);
74 static SAVEDS(LONG) UndoDummyFunc(struct Hook *hook, APTR object, struct UndoEvent *uev);
75 static void RedoCleanup(void);
76 static SAVEDS(ULONG) UndoTask(struct UndoProcArg *upa, struct SM_RunProcess *msg);
77 static SAVEDS(ULONG) RedoTask(struct UndoProcArg *upa, struct SM_RunProcess *msg);
79 static BOOL UndoAddCopyMoveEvent(struct UndoEvent *uev, struct TagItem *TagList);
80 static BOOL AddChangeIconPosEvent(struct UndoEvent *uev, struct TagItem *TagList);
81 static BOOL AddSnapshotEvent(struct UndoEvent *uev, struct TagItem *TagList);
82 static BOOL AddCleanupEvent(struct UndoEvent *uev, struct TagItem *TagList);
83 static BOOL AddRenameEvent(struct UndoEvent *uev, struct TagItem *TagList);
84 static BOOL AddRelabelEvent(struct UndoEvent *uev, struct TagItem *TagList);
85 static BOOL AddDeleteEvent(struct UndoEvent *uev, struct TagItem *TagList);
86 static BOOL AddSizeWindowEvent(struct UndoEvent *uev, struct TagItem *TagList);
87 static BOOL AddNewDrawerEvent(struct UndoEvent *uev, struct TagItem *TagList);
88 static BOOL AddLeaveOutPutAwayEvent(struct UndoEvent *uev, struct TagItem *TagList);
89 static BOOL AddSetProtectionEvent(struct UndoEvent *uev, struct TagItem *TagList);
90 static BOOL AddSetCommentEvent(struct UndoEvent *uev, struct TagItem *TagList);
91 static BOOL AddSetToolTypesEvent(struct UndoEvent *uev, struct TagItem *TagList);
92 static BOOL AddChangeIconObjectEvent(struct UndoEvent *uev, struct TagItem *TagList);
93 static BOOL AddCloseWindowEvent(struct UndoEvent *uev, struct TagItem *TagList);
95 static SAVEDS(void) UndoDisposeCopyMoveData(struct Hook *hook, APTR object, struct UndoEvent *uev);
96 static SAVEDS(void) UndoDisposeNewDrawerData(struct Hook *hook, APTR object, struct UndoEvent *uev);
97 static SAVEDS(void) UndoDisposeIconData(struct Hook *hook, APTR object, struct UndoEvent *uev);
98 static SAVEDS(void) UndoDisposeCleanupData(struct Hook *hook, APTR object, struct UndoEvent *uev);
99 static SAVEDS(void) UndoDisposeSnapshotData(struct Hook *hook, APTR object, struct UndoEvent *uev);
100 static SAVEDS(void) UndoDisposeSizeWindowData(struct Hook *hook, APTR object, struct UndoEvent *uev);
101 static SAVEDS(void) UndoDisposeSetProtectionData(struct Hook *hook, APTR object, struct UndoEvent *uev);
102 static SAVEDS(void) UndoDisposeSetCommentData(struct Hook *hook, APTR object, struct UndoEvent *uev);
103 static SAVEDS(void) UndoDisposeSetToolTypesData(struct Hook *hook, APTR object, struct UndoEvent *uev);
104 static SAVEDS(void) UndoDisposeChangeIconObjectData(struct Hook *hook, APTR object, struct UndoEvent *uev);
105 static SAVEDS(void) UndoDisposeCloseWindowData(struct Hook *hook, APTR object, struct UndoEvent *uev);
107 static SAVEDS(LONG) UndoCopyEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
108 static SAVEDS(LONG) UndoMoveEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
109 static SAVEDS(LONG) RedoCopyEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
110 static SAVEDS(LONG) RedoMoveEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
111 static SAVEDS(LONG) RedoCreateLinkEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
112 static SAVEDS(LONG) UndoChangeIconPosEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
113 static SAVEDS(LONG) RedoChangeIconPosEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
114 static SAVEDS(LONG) UndoCleanupEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
115 static SAVEDS(LONG) UndoLeaveOutEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
116 static SAVEDS(LONG) RedoLeaveOutEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
117 static SAVEDS(LONG) RedoCleanupEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
118 static SAVEDS(LONG) UndoSnapshotEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
119 static SAVEDS(LONG) RedoSnapshotPosEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
120 static SAVEDS(LONG) UndoRenameEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
121 static SAVEDS(LONG) RedoRenameEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
122 static SAVEDS(LONG) UndoRelabelEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
123 static SAVEDS(LONG) RedoRelabelEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
124 static SAVEDS(LONG) UndoSizeWindowEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
125 static SAVEDS(LONG) RedoSizeWindowEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
126 static SAVEDS(LONG) UndoNewDrawerEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
127 static SAVEDS(LONG) RedoNewDrawerEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
128 static SAVEDS(LONG) UndoSetProtectionEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
129 static SAVEDS(LONG) RedoSetProtectionEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
130 static SAVEDS(LONG) UndoSetCommentEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
131 static SAVEDS(LONG) RedoSetCommentEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
132 static SAVEDS(LONG) UndoSetToolTypesEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
133 static SAVEDS(LONG) RedoSetToolTypesEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
134 static SAVEDS(LONG) UndoChangeIconObjectEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
135 static SAVEDS(LONG) RedoChangeIconObjectEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
136 static SAVEDS(LONG) UndoCloseWindowEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
137 static SAVEDS(LONG) RedoCloseWindowEvent(struct Hook *hook, APTR object, struct UndoEvent *uev);
139 static BOOL MoveIconTo(CONST_STRPTR DirName, CONST_STRPTR IconName, LONG x, LONG y);
140 static STRPTR UndoBuildIconName(CONST_STRPTR ObjName);
141 static struct internalScaWindowTask *UndoFindWindowByDir(CONST_STRPTR DirName);
142 static struct internalScaWindowTask *UndoFindWindowByWindowTask(const struct ScaWindowTask *iwt);
143 static const struct UndoCleanupIconEntry *UndoFindCleanupIconEntry(const struct UndoEvent *uev, const struct ScaIconNode *in);
144 static struct ScaIconNode *UndoFindIconByName(struct internalScaWindowTask *iwt, CONST_STRPTR IconName);
145 static BOOL UndoSnapshotIcon(struct internalScaWindowTask *iwt, struct ScaIconNode *in);
146 static BOOL UndoUnsnapshotIcon(struct internalScaWindowTask *iwt,
147 struct ScaIconNode *in, BOOL SaveIcon);
148 static BOOL UndoFindWindowAndIcon(CONST_STRPTR DirName, CONST_STRPTR IconName,
149 struct internalScaWindowTask **iwt, struct ScaIconNode **in);
151 //----------------------------------------------------------------------------
153 // local Data items
155 //----------------------------------------------------------------------------
157 // public data items
159 struct List globalUndoList; // global Undo list for all file-related actions
160 SCALOSSEMAPHORE UndoListListSemaphore; // Semaphore to protect globalUndoList
161 static ULONG UndoCount; // Number of entries in globalUndoList
163 struct List globalRedoList; // global Redo list for all file-related actions
164 SCALOSSEMAPHORE RedoListListSemaphore; // Semaphore to protect globalRedoList
166 //----------------------------------------------------------------------------
168 void UndoCleanup(void)
170 struct UndoStep *ust;
172 ScalosObtainSemaphore(&UndoListListSemaphore);
174 while ((ust = (struct UndoStep *) RemHead(&globalUndoList)))
176 UndoCount--;
177 UndoDisposeStep(ust);
179 ScalosReleaseSemaphore(&UndoListListSemaphore);
181 RedoCleanup();
184 //----------------------------------------------------------------------------
186 BOOL UndoAddEvent(struct internalScaWindowTask *iwt, enum ScalosUndoType type, ULONG FirstTag, ...)
188 BOOL Success;
189 struct TagItem *TagList;
191 va_list args;
193 va_start(args, FirstTag);
195 TagList = ScalosVTagList(FirstTag, args);
196 Success = UndoAddEventTagList(iwt, type, TagList);
198 va_end(args);
200 if (TagList)
201 FreeTagItems(TagList);
203 return Success;
206 //----------------------------------------------------------------------------
208 BOOL UndoAddEventTagList(struct internalScaWindowTask *iwt, enum ScalosUndoType type, struct TagItem *TagList)
210 if (TagList)
212 struct UndoEvent *uev;
214 uev = UndoCreateEvent();
215 if (uev)
217 struct UndoStep *ustMulti;
218 struct UndoStep *ust;
220 ust = ustMulti = (struct UndoStep *) GetTagData(UNDOTAG_UndoMultiStep, (ULONG) NULL, TagList);
221 d1(kprintf("%s/%s/%ld: ust=%08lx\n", __FILE__, __FUNC__, __LINE__, ust));
222 if (NULL == ust)
224 ust = (struct UndoStep *) UndoBeginStep();
227 d1(kprintf("%s/%s/%ld: ust=%08lx\n", __FILE__, __FUNC__, __LINE__, ust));
229 if (ust)
231 BOOL Success = FALSE;
233 RedoCleanup();
235 uev->uev_Type = type;
237 uev->uev_CustomAddHook = (struct Hook *) GetTagData(UNDOTAG_CustomAddHook, (ULONG) NULL, TagList);
239 uev->uev_NewPosX = GetTagData(UNDOTAG_IconPosX, NO_ICON_POSITION_SHORT, TagList);
240 uev->uev_NewPosY = GetTagData(UNDOTAG_IconPosY, NO_ICON_POSITION_SHORT, TagList);
242 d1(kprintf("%s/%s/%ld: uev=%08lx uev_Type=%ld\n", __FILE__, __FUNC__, __LINE__, uev, uev->uev_Type));
243 d1(kprintf("%s/%s/%ld: uev_NewPosX=%ld uev_NewPosY=%ld\n", __FILE__, __FUNC__, __LINE__, uev->uev_NewPosX, uev->uev_NewPosY));
245 switch (uev->uev_Type)
247 case UNDO_Copy:
248 case UNDO_Move:
249 case UNDO_CreateLink:
250 Success = UndoAddCopyMoveEvent(uev, TagList);
251 break;
252 case UNDO_ChangeIconPos:
253 Success = AddChangeIconPosEvent(uev, TagList);
254 break;
255 case UNDO_Cleanup:
256 Success = AddCleanupEvent(uev, TagList);
257 break;
258 case UNDO_Snapshot:
259 case UNDO_Unsnapshot:
260 Success = AddSnapshotEvent(uev, TagList);
261 break;
262 case UNDO_Rename:
263 Success = AddRenameEvent(uev, TagList);
264 break;
265 case UNDO_Relabel:
266 Success = AddRelabelEvent(uev, TagList);
267 break;
268 case UNDO_SizeWindow:
269 Success = AddSizeWindowEvent(uev, TagList);
270 break;
271 case UNDO_Delete:
272 Success = AddDeleteEvent(uev, TagList);
273 break;
274 case UNDO_NewDrawer:
275 Success = AddNewDrawerEvent(uev, TagList);
276 break;
277 case UNDO_Leaveout:
278 case UNDO_PutAway:
279 Success = AddLeaveOutPutAwayEvent(uev, TagList);
280 break;
281 case UNDO_SetProtection:
282 Success = AddSetProtectionEvent(uev, TagList);
283 break;
284 case UNDO_SetComment:
285 Success = AddSetCommentEvent(uev, TagList);
286 break;
287 case UNDO_SetToolTypes:
288 Success = AddSetToolTypesEvent(uev, TagList);
289 break;
290 case UNDO_ChangeIconObject:
291 Success = AddChangeIconObjectEvent(uev, TagList);
292 break;
293 case UNDO_CloseWindow:
294 Success = AddCloseWindowEvent(uev, TagList);
295 break;
296 default:
297 if (uev->uev_CustomAddHook)
299 Success = CallHookPkt(uev->uev_CustomAddHook, NULL, uev);
301 break;
304 d1(kprintf("%s/%s/%ld: Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
306 if (Success)
308 uev->uev_UndoStep = ust;
309 ust->ust_EventCount++;
311 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
313 AddTail(&ust->ust_EventList, &uev->uev_Node);
314 uev = NULL;
316 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
318 if (NULL == ustMulti)
320 UndoEndStep(iwt, (APTR) ust);
323 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
328 d1(kprintf("%s/%s/%ld: uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
330 if (uev)
331 UndoDisposeEvent(uev);
334 d1(kprintf("%s/%s/%ld: END\n", __FILE__, __FUNC__, __LINE__));
336 return TRUE;
339 //----------------------------------------------------------------------------
341 APTR UndoBeginStep(void)
343 struct UndoStep *ust;
345 do {
346 ust = UndoCreateStep();
347 if (NULL == ust)
348 break;
349 } while (0);
351 return (APTR) ust;
354 //----------------------------------------------------------------------------
356 void UndoEndStep(struct internalScaWindowTask *iwt, APTR event)
358 struct UndoStep *ust = (struct UndoStep *) event;
360 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
362 do {
363 if (NULL == ust)
364 break;
366 if (IsListEmpty(&ust->ust_EventList))
367 break;
369 ScalosObtainSemaphore(&UndoListListSemaphore);
370 AddTail(&globalUndoList, &ust->ust_Node);
371 if (++UndoCount > CurrentPrefs.pref_MaxUndoSteps)
373 // pref_MaxUndoSteps exceeded - dispose oldest list entry
374 ust = (struct UndoStep *) RemHead(&globalUndoList);
375 UndoCount--;
377 else
379 ust = NULL; // do not dipose ust here!
382 ScalosReleaseSemaphore(&UndoListListSemaphore);
383 } while (0);
385 d1(kprintf("%s/%s/%ld: ust=%08lx\n", __FILE__, __FUNC__, __LINE__, ust));
387 if (ust)
388 UndoDisposeStep(ust);
390 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
392 SetMenuOnOff(iwt);
394 d1(kprintf("%s/%s/%ld: END\n", __FILE__, __FUNC__, __LINE__));
397 //----------------------------------------------------------------------------
399 static struct UndoStep *UndoCreateStep(void)
401 struct UndoStep *ust;
403 do {
404 ust = ScalosAlloc(sizeof(struct UndoStep));
405 if (NULL == ust)
406 break;
408 NewList(&ust->ust_EventList);
409 ust->ust_EventCount = 0;
410 ust->ust_Description = NULL;
411 ust->ust_FileTransObj = NULL;
412 } while (0);
414 return ust;
417 //----------------------------------------------------------------------------
419 static void UndoDisposeStep(struct UndoStep *ust)
421 if (ust)
423 struct UndoEvent *uev;
425 while ((uev = (struct UndoEvent *) RemHead(&ust->ust_EventList)))
427 ust->ust_EventCount--;
428 UndoDisposeEvent(uev);
431 if (ust->ust_Description)
433 FreeCopyString(ust->ust_Description);
434 ust->ust_Description = NULL;
437 ScalosFree(ust);
441 //----------------------------------------------------------------------------
443 static struct UndoEvent *UndoCreateEvent(void)
445 struct UndoEvent *uev;
447 do {
448 static struct Hook DummyHook =
450 { NULL, NULL },
451 HOOKFUNC_DEF(UndoDummyFunc), // h_Entry + h_SubEntry
452 NULL, // h_Data
455 uev = ScalosAlloc(sizeof(struct UndoEvent));
456 if (NULL == uev)
457 break;
459 memset(uev, 0, sizeof(struct UndoEvent));
461 uev->uev_UndoHook = &DummyHook;
462 uev->uev_RedoHook = &DummyHook;
463 uev->uev_DisposeHook = &DummyHook;
464 } while (0);
465 return uev;
468 //----------------------------------------------------------------------------
470 static void UndoDisposeEvent(struct UndoEvent *uev)
472 if (uev)
474 if (uev->uev_DisposeHook)
475 CallHookPkt(uev->uev_DisposeHook, NULL, uev); // cleanup type-specific data
476 ScalosFree(uev);
480 //----------------------------------------------------------------------------
482 static SAVEDS(LONG) UndoDummyFunc(struct Hook *hook, APTR object, struct UndoEvent *uev)
484 (void) hook;
485 (void) object;
486 (void) uev;
488 return 0;
491 //----------------------------------------------------------------------------
493 static void RedoCleanup(void)
495 struct UndoStep *ust;
497 ScalosObtainSemaphore(&RedoListListSemaphore);
499 while ((ust = (struct UndoStep *) RemHead(&globalRedoList)))
501 UndoDisposeStep(ust);
503 ScalosReleaseSemaphore(&RedoListListSemaphore);
506 //----------------------------------------------------------------------------
508 BOOL Undo(struct internalScaWindowTask *iwt)
510 struct UndoProcArg upa;
511 BOOL Success = FALSE;
513 upa.upa_iwt = iwt;
515 ScalosObtainSemaphore(&UndoListListSemaphore);
516 upa.upa_UndoStep = (struct UndoStep *) RemTail(&globalUndoList);
517 UndoCount--;
518 ScalosReleaseSemaphore(&UndoListListSemaphore);
520 d1(kprintf("%s/%s/%ld: ust=%08lx\n", __FILE__, __FUNC__, __LINE__, upa.upa_UndoStep));
522 if (upa.upa_UndoStep)
524 Success = DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_RunProcess, UndoTask,
525 &upa, sizeof(upa), iInfos.xii_iinfos.ii_MainMsgPort);
528 return Success;
531 //----------------------------------------------------------------------------
533 BOOL Redo(struct internalScaWindowTask *iwt)
535 struct UndoProcArg upa;
536 BOOL Success = FALSE;
538 upa.upa_iwt = iwt;
540 ScalosObtainSemaphore(&RedoListListSemaphore);
541 upa.upa_UndoStep = (struct UndoStep *) RemTail(&globalRedoList);
542 ScalosReleaseSemaphore(&RedoListListSemaphore);
544 d1(kprintf("%s/%s/%ld: ust=%08lx\n", __FILE__, __FUNC__, __LINE__, upa.upa_UndoStep));
546 if (upa.upa_UndoStep)
548 Success = DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_RunProcess, RedoTask,
549 &upa, sizeof(upa), iInfos.xii_iinfos.ii_MainMsgPort);
552 return Success;
555 //----------------------------------------------------------------------------
557 CONST_STRPTR UndoGetDescription(void)
559 static char buffer[200];
561 ScalosObtainSemaphore(&UndoListListSemaphore);
563 if (IsListEmpty(&globalUndoList))
565 snprintf(buffer, sizeof(buffer),
566 GetLocString(MSGID_UNDO_NOT_AVAILABLE),
567 GetLocString(MSGID_UNDO_UNDO));
569 else
571 struct UndoStep *ust = (struct UndoStep *) globalUndoList.lh_TailPred;
573 stccpy(buffer, GetLocString(MSGID_UNDO_UNDO), sizeof(buffer));
575 d1(kprintf("%s/%s/%ld: ust=%08lx\n", __FILE__, __FUNC__, __LINE__, ust));
577 if (!IsListEmpty(&ust->ust_EventList))
579 struct UndoEvent *uev = (struct UndoEvent *) ust->ust_EventList.lh_Head;
581 if (ust->ust_EventCount > 1)
583 snprintf(buffer, sizeof(buffer),
584 GetLocString(uev->uev_DescrMsgIDMultiple),
585 GetLocString(MSGID_UNDO_UNDO),
586 ust->ust_EventCount);
588 else if (uev->uev_DescrObjName && *uev->uev_DescrObjName)
590 snprintf(buffer, sizeof(buffer),
591 GetLocString(uev->uev_DescrMsgIDSingle),
592 GetLocString(MSGID_UNDO_UNDO),
593 *uev->uev_DescrObjName);
598 ScalosReleaseSemaphore(&UndoListListSemaphore);
600 return buffer;
603 //----------------------------------------------------------------------------
605 CONST_STRPTR RedoGetDescription(void)
607 static char buffer[200];
609 ScalosObtainSemaphore(&RedoListListSemaphore);
611 if (IsListEmpty(&globalRedoList))
613 snprintf(buffer, sizeof(buffer),
614 GetLocString(MSGID_UNDO_NOT_AVAILABLE),
615 GetLocString(MSGID_UNDO_REDO));
617 else
619 struct UndoStep *ust = (struct UndoStep *) globalRedoList.lh_TailPred;
621 stccpy(buffer, GetLocString(MSGID_UNDO_REDO), sizeof(buffer));
623 d1(kprintf("%s/%s/%ld: ust=%08lx\n", __FILE__, __FUNC__, __LINE__, ust));
625 if (!IsListEmpty(&ust->ust_EventList))
627 struct UndoEvent *uev = (struct UndoEvent *) ust->ust_EventList.lh_Head;
629 if (ust->ust_EventCount > 1)
631 snprintf(buffer, sizeof(buffer),
632 GetLocString(uev->uev_DescrMsgIDMultiple),
633 GetLocString(MSGID_UNDO_REDO),
634 ust->ust_EventCount);
636 else if (uev->uev_DescrObjName && *uev->uev_DescrObjName)
638 snprintf(buffer, sizeof(buffer),
639 GetLocString(uev->uev_DescrMsgIDSingle),
640 GetLocString(MSGID_UNDO_REDO),
641 *uev->uev_DescrObjName);
646 ScalosReleaseSemaphore(&RedoListListSemaphore);
648 return buffer;
651 //----------------------------------------------------------------------------
653 static SAVEDS(ULONG) UndoTask(struct UndoProcArg *upa, struct SM_RunProcess *msg)
655 static CONST_STRPTR ProgTaskName = "Scalos_UndoTask";
656 APTR prWindowPtr;
657 struct Process *myProc = (struct Process *) FindTask(NULL);
659 (void) msg;
661 d1(kprintf("%s/%s/%ld: START ust=%08lx\n", __FILE__, __FUNC__, __LINE__, upa->upa_UndoStep));
663 prWindowPtr = myProc->pr_WindowPtr;
664 myProc->pr_WindowPtr = (APTR) ~0; // suppress error requesters
666 myProc->pr_Task.tc_Node.ln_Name = (STRPTR) ProgTaskName;
667 SetProgramName(ProgTaskName);
669 upa->upa_UndoStep->ust_FileTransObj = SCA_NewScalosObjectTags((STRPTR) "FileTransfer.sca",
670 SCCA_FileTrans_Screen, (ULONG) iInfos.xii_iinfos.ii_Screen,
671 SCCA_FileTrans_ReplaceMode, SCCV_ReplaceMode_Ask,
672 TAG_END);
674 if (upa->upa_UndoStep->ust_FileTransObj)
676 struct UndoEvent *uev;
678 for (uev = (struct UndoEvent *) upa->upa_UndoStep->ust_EventList.lh_Head;
679 uev != (struct UndoEvent *) &upa->upa_UndoStep->ust_EventList.lh_Tail;
680 uev = (struct UndoEvent *) uev->uev_Node.ln_Succ)
682 d1(kprintf("%s/%s/%ld: uev=%08lx uev_Type=%ld uev_UndoHook=%08lx\n", __FILE__, __FUNC__, __LINE__, uev, uev->uev_Type, uev->uev_UndoHook));
683 if (uev->uev_UndoHook)
684 CallHookPkt(uev->uev_UndoHook, NULL, uev);
686 // Move undo step to redo list
687 ScalosObtainSemaphore(&RedoListListSemaphore);
688 AddTail(&globalRedoList, &upa->upa_UndoStep->ust_Node);
689 ScalosReleaseSemaphore(&RedoListListSemaphore);
691 SCA_DisposeScalosObject(upa->upa_UndoStep->ust_FileTransObj);
692 upa->upa_UndoStep->ust_FileTransObj = NULL;
694 else
696 UndoDisposeStep(upa->upa_UndoStep);
699 SetMenuOnOff(upa->upa_iwt);
701 // restore pr_WindowPtr
702 myProc->pr_WindowPtr = prWindowPtr;
704 d1(kprintf("%s/%s/%ld: END\n", __FILE__, __FUNC__, __LINE__));
706 return 0;
709 //----------------------------------------------------------------------------
711 static SAVEDS(ULONG) RedoTask(struct UndoProcArg *upa, struct SM_RunProcess *msg)
713 static CONST_STRPTR ProgTaskName = "Scalos_RedoTask";
714 APTR prWindowPtr;
715 struct Process *myProc = (struct Process *) FindTask(NULL);
717 (void) msg;
719 d1(kprintf("%s/%s/%ld: START ust=%08lx\n", __FILE__, __FUNC__, __LINE__, upa->upa_UndoStep));
721 prWindowPtr = myProc->pr_WindowPtr;
722 myProc->pr_WindowPtr = (APTR) ~0; // suppress error requesters
724 myProc->pr_Task.tc_Node.ln_Name = (STRPTR) ProgTaskName;
725 SetProgramName(ProgTaskName);
727 upa->upa_UndoStep->ust_FileTransObj = SCA_NewScalosObjectTags((STRPTR) "FileTransfer.sca",
728 SCCA_FileTrans_Screen, (ULONG) iInfos.xii_iinfos.ii_Screen,
729 SCCA_FileTrans_ReplaceMode, SCCV_ReplaceMode_Ask,
730 TAG_END);
732 if (upa->upa_UndoStep->ust_FileTransObj)
734 struct UndoEvent *uev;
736 for (uev = (struct UndoEvent *) upa->upa_UndoStep->ust_EventList.lh_Head;
737 uev != (struct UndoEvent *) &upa->upa_UndoStep->ust_EventList.lh_Tail;
738 uev = (struct UndoEvent *) uev->uev_Node.ln_Succ)
740 d1(kprintf("%s/%s/%ld: uev=%08lx uev_Type=%ld uev_RedoHook=%08lx\n", __FILE__, __FUNC__, __LINE__, uev, uev->uev_Type, uev->uev_RedoHook));
741 if (uev->uev_RedoHook)
742 CallHookPkt(uev->uev_RedoHook, NULL, uev);
745 // Move redo step to undo list
746 ScalosObtainSemaphore(&UndoListListSemaphore);
747 AddTail(&globalUndoList, &upa->upa_UndoStep->ust_Node);
748 UndoCount++;
749 ScalosReleaseSemaphore(&UndoListListSemaphore);
751 SCA_DisposeScalosObject(upa->upa_UndoStep->ust_FileTransObj);
752 upa->upa_UndoStep->ust_FileTransObj = NULL;
754 else
756 UndoDisposeStep(upa->upa_UndoStep);
759 SetMenuOnOff(upa->upa_iwt);
761 // restore pr_WindowPtr
762 myProc->pr_WindowPtr = prWindowPtr;
764 return 0;
767 //----------------------------------------------------------------------------
769 static BOOL UndoAddCopyMoveEvent(struct UndoEvent *uev, struct TagItem *TagList)
771 BOOL Success = FALSE;
772 STRPTR name;
774 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
776 do {
777 BPTR dirLock;
778 CONST_STRPTR fName;
779 struct UndoCopyMoveEventData *ucmed = &uev->uev_Data.uev_CopyMoveData;
780 static struct Hook UndoDisposeCopyMoveDataHook =
782 { NULL, NULL },
783 HOOKFUNC_DEF(UndoDisposeCopyMoveData), // h_Entry + h_SubEntry
784 NULL, // h_Data
786 static struct Hook UndoCopyEventHook =
788 { NULL, NULL },
789 HOOKFUNC_DEF(UndoCopyEvent), // h_Entry + h_SubEntry
790 NULL, // h_Data
792 static struct Hook RedoCopyEventHook =
794 { NULL, NULL },
795 HOOKFUNC_DEF(RedoCopyEvent), // h_Entry + h_SubEntry
796 NULL, // h_Data
798 static struct Hook UndoMoveEventHook =
800 { NULL, NULL },
801 HOOKFUNC_DEF(UndoMoveEvent), // h_Entry + h_SubEntry
802 NULL, // h_Data
804 static struct Hook RedoMoveEventHook =
806 { NULL, NULL },
807 HOOKFUNC_DEF(RedoMoveEvent), // h_Entry + h_SubEntry
808 NULL, // h_Data
810 static struct Hook RedoCreateLinkEventHook =
812 { NULL, NULL },
813 HOOKFUNC_DEF(RedoCreateLinkEvent), // h_Entry + h_SubEntry
814 NULL, // h_Data
817 uev->uev_DisposeHook = (struct Hook *) GetTagData(UNDOTAG_DisposeHook, (ULONG) &UndoDisposeCopyMoveDataHook, TagList);
819 if (UNDO_Copy == uev->uev_Type)
821 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &UndoCopyEventHook, TagList);
822 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &RedoCopyEventHook, TagList);
823 uev->uev_DescrMsgIDSingle = MSGID_UNDO_COPY_SINGLE;
824 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_COPY_MORE;
826 else if (UNDO_Move == uev->uev_Type)
828 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &UndoMoveEventHook, TagList);
829 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &RedoMoveEventHook, TagList);
830 uev->uev_DescrMsgIDSingle = MSGID_UNDO_MOVE_SINGLE;
831 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_MOVE_MORE;
833 else if (UNDO_CreateLink == uev->uev_Type)
835 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &UndoCopyEventHook, TagList);
836 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &RedoCreateLinkEventHook, TagList);
837 uev->uev_DescrMsgIDSingle = MSGID_UNDO_CREATELINK_SINGLE;
838 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_CREATELINK_MORE;
841 uev->uev_OldPosX = GetTagData(UNDOTAG_OldIconPosX, NO_ICON_POSITION_SHORT, TagList);
842 uev->uev_OldPosY = GetTagData(UNDOTAG_OldIconPosY, NO_ICON_POSITION_SHORT, TagList);
844 uev->uev_DescrObjName = &ucmed->ucmed_srcName;
846 name = AllocPathBuffer();
847 if (NULL == name)
848 break;
850 dirLock = (BPTR) GetTagData(UNDOTAG_CopySrcDirLock, 0, TagList);
851 if (BNULL == dirLock)
852 break;
854 if (!NameFromLock(dirLock, name, Max_PathLen))
855 break;
857 d1(kprintf("%s/%s/%ld: UNDOTAG_CopySrcDirLock=<%s>\n", __FILE__, __FUNC__, __LINE__, name));
859 ucmed->ucmed_srcDirName = AllocCopyString(name);
860 if (NULL == ucmed->ucmed_srcDirName)
861 break;
863 dirLock = (BPTR) GetTagData(UNDOTAG_CopyDestDirLock, 0, TagList);
864 if (BNULL == dirLock)
865 break;
867 if (!NameFromLock(dirLock, name, Max_PathLen))
868 break;
870 d1(kprintf("%s/%s/%ld: UNDOTAG_CopyDestDirLock=<%s>\n", __FILE__, __FUNC__, __LINE__, name));
872 ucmed->ucmed_destDirName = AllocCopyString(name);
873 if (NULL == ucmed->ucmed_destDirName)
874 break;
876 fName = (CONST_STRPTR) GetTagData(UNDOTAG_CopySrcName, (ULONG) NULL, TagList);
877 if (NULL == fName)
878 break;
880 d1(kprintf("%s/%s/%ld: UNDOTAG_CopySrcName=<%s>\n", __FILE__, __FUNC__, __LINE__, fName));
882 ucmed->ucmed_srcName = AllocCopyString(fName);
883 if (NULL == ucmed->ucmed_srcName)
884 break;
886 // special handling for volume copying: here is ucmed_srcName empty
887 if ((NULL == ucmed->ucmed_srcName) || (0 == strlen(ucmed->ucmed_srcName)))
888 uev->uev_DescrObjName = &ucmed->ucmed_srcDirName;
890 fName = (CONST_STRPTR) GetTagData(UNDOTAG_CopyDestName, (ULONG) ucmed->ucmed_srcName, TagList);
891 if (NULL == fName)
892 fName = ucmed->ucmed_srcName;
894 d1(kprintf("%s/%s/%ld: UNDOTAG_CopyDestName=<%s>\n", __FILE__, __FUNC__, __LINE__, fName));
896 ucmed->ucmed_destName = AllocCopyString(fName);
897 if (NULL == ucmed->ucmed_destName)
898 break;
900 if ((NO_ICON_POSITION_SHORT == uev->uev_OldPosX) || (NO_ICON_POSITION_SHORT == uev->uev_OldPosY))
902 struct internalScaWindowTask *iwt;
903 struct ScaIconNode *in = NULL;
905 do {
906 struct ExtGadget *gg;
908 if (!UndoFindWindowAndIcon(ucmed->ucmed_srcDirName, ucmed->ucmed_srcName, &iwt, &in))
909 break;
911 if (NULL == in)
912 break;
914 gg = (struct ExtGadget *) in->in_Icon;
916 uev->uev_OldPosX = gg->LeftEdge;
917 uev->uev_OldPosY = gg->TopEdge;
918 } while (0);
920 if (iwt)
922 if (in)
923 ScalosUnLockIconList(iwt);
924 SCA_UnLockWindowList();
928 Success = TRUE;
929 } while (0);
931 if (name)
932 FreePathBuffer(name);
934 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
936 return Success;
939 //----------------------------------------------------------------------------
941 static BOOL AddChangeIconPosEvent(struct UndoEvent *uev, struct TagItem *TagList)
943 BOOL Success = FALSE;
944 STRPTR name;
946 do {
947 BPTR dirLock;
948 struct ScaIconNode *in;
949 const struct ExtGadget *gg;
950 static struct Hook DisposeIconDataHook =
952 { NULL, NULL },
953 HOOKFUNC_DEF(UndoDisposeIconData), // h_Entry + h_SubEntry
954 NULL, // h_Data
956 static struct Hook UndoChangeIconPosEventHook =
958 { NULL, NULL },
959 HOOKFUNC_DEF(UndoChangeIconPosEvent), // h_Entry + h_SubEntry
960 NULL, // h_Data
962 static struct Hook RedoChangeIconPosEventHook =
964 { NULL, NULL },
965 HOOKFUNC_DEF(RedoChangeIconPosEvent), // h_Entry + h_SubEntry
966 NULL, // h_Data
969 uev->uev_DisposeHook = (struct Hook *) GetTagData(UNDOTAG_DisposeHook, (ULONG) &DisposeIconDataHook, TagList);
970 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &UndoChangeIconPosEventHook, TagList);
971 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &RedoChangeIconPosEventHook, TagList);
973 uev->uev_DescrMsgIDSingle = MSGID_UNDO_CHANGEICONPOS_SINGLE;
974 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_CHANGEICONPOS_MORE;
976 uev->uev_DescrObjName = &uev->uev_Data.uev_IconData.uid_IconName;
978 name = AllocPathBuffer();
979 if (NULL == name)
980 break;
982 dirLock = (BPTR) GetTagData(UNDOTAG_IconDirLock, 0, TagList);
983 if (BNULL == dirLock)
984 break;
986 if (!NameFromLock(dirLock, name, Max_PathLen))
987 break;
989 d1(kprintf("%s/%s/%ld: UNDOTAG_IconDirLock=<%s>\n", __FILE__, __FUNC__, __LINE__, name));
991 uev->uev_Data.uev_IconData.uid_DirName = AllocCopyString(name);
992 if (NULL == uev->uev_Data.uev_IconData.uid_DirName)
993 break;
995 in = (struct ScaIconNode *) GetTagData(UNDOTAG_IconNode, (ULONG) NULL, TagList);
996 if (NULL == in)
997 break;
999 d1(kprintf("%s/%s/%ld: UNDOTAG_IconNode=%08lx <%s>\n", __FILE__, __FUNC__, __LINE__, in, GetIconName(in)));
1001 uev->uev_Data.uev_IconData.uid_IconName = AllocCopyString(GetIconName(in));
1002 if (NULL == uev->uev_Data.uev_IconData.uid_IconName)
1003 break;
1005 gg = (const struct ExtGadget *) in->in_Icon;
1007 uev->uev_OldPosX = gg->LeftEdge;
1008 uev->uev_OldPosY = gg->TopEdge;
1010 d1(kprintf("%s/%s/%ld: UNDOTAG_IconOldPosX=%ld UNDOTAG_IconOldPosY=%ld\n", \
1011 __FILE__, __FUNC__, __LINE__, uev->uev_OldPosX, \
1012 uev->uev_OldPosY));
1014 Success = TRUE;
1015 } while (0);
1017 if (name)
1018 FreePathBuffer(name);
1020 return Success;
1023 //----------------------------------------------------------------------------
1025 static BOOL AddSnapshotEvent(struct UndoEvent *uev, struct TagItem *TagList)
1027 BOOL Success = FALSE;
1028 STRPTR name;
1030 do {
1031 BPTR oldDir;
1032 BPTR dirLock;
1033 struct ScaIconNode *in;
1034 const struct ExtGadget *gg;
1035 struct UndoSnaphotIconData *usid = &uev->uev_Data.uev_SnapshotData;
1036 static struct Hook DisposeIconDataHook =
1038 { NULL, NULL },
1039 HOOKFUNC_DEF(UndoDisposeSnapshotData), // h_Entry + h_SubEntry
1040 NULL, // h_Data
1042 static struct Hook UndoSnapshotEventHook =
1044 { NULL, NULL },
1045 HOOKFUNC_DEF(UndoSnapshotEvent), // h_Entry + h_SubEntry
1046 NULL, // h_Data
1048 static struct Hook RedoSnapshotPosEventHook =
1050 { NULL, NULL },
1051 HOOKFUNC_DEF(RedoSnapshotPosEvent), // h_Entry + h_SubEntry
1052 NULL, // h_Data
1055 uev->uev_DisposeHook = (struct Hook *) GetTagData(UNDOTAG_DisposeHook, (ULONG) &DisposeIconDataHook, TagList);
1056 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &UndoSnapshotEventHook, TagList);
1057 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &RedoSnapshotPosEventHook, TagList);
1059 uev->uev_DescrMsgIDSingle = MSGID_UNDO_SNAPSHOT_SINGLE;
1060 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_SNAPSHOT_MORE;
1062 uev->uev_DescrObjName = &usid->usid_IconName;
1064 name = AllocPathBuffer();
1065 if (NULL == name)
1066 break;
1068 dirLock = (BPTR) GetTagData(UNDOTAG_IconDirLock, 0, TagList);
1069 if (BNULL == dirLock)
1070 break;
1072 if (!NameFromLock(dirLock, name, Max_PathLen))
1073 break;
1075 d1(kprintf("%s/%s/%ld: UNDOTAG_IconDirLock=<%s>\n", __FILE__, __FUNC__, __LINE__, name));
1077 usid->usid_DirName = AllocCopyString(name);
1078 if (NULL == usid->usid_DirName)
1079 break;
1081 usid->usid_SaveIcon = GetTagData(UNDOTAG_SaveIcon, FALSE, TagList);
1083 d1(kprintf("%s/%s/%ld: UNDOTAG_SaveIcon=%ld\n", __FILE__, __FUNC__, __LINE__, usid->usid_SaveIcon));
1085 in = (struct ScaIconNode *) GetTagData(UNDOTAG_IconNode, (ULONG) NULL, TagList);
1086 if (NULL == in)
1087 break;
1089 d1(kprintf("%s/%s/%ld: UNDOTAG_IconNode=%08lx <%s>\n", __FILE__, __FUNC__, __LINE__, in, GetIconName(in)));
1091 usid->usid_IconName = AllocCopyString(GetIconName(in));
1092 if (NULL == usid->usid_IconName)
1093 break;
1095 oldDir = CurrentDir(dirLock);
1097 usid->usid_IconObj = (Object *) NewIconObjectTags(usid->usid_IconName,
1098 IDTA_SupportedIconTypes, CurrentPrefs.pref_SupportedIconTypes,
1099 IDTA_SizeConstraints, (ULONG) &CurrentPrefs.pref_IconSizeConstraints,
1100 IDTA_ScalePercentage, CurrentPrefs.pref_IconScaleFactor,
1101 IDTA_Text, (ULONG) usid->usid_IconName,
1102 DTA_Name, (ULONG) usid->usid_IconName,
1103 TAG_END);
1105 CurrentDir(oldDir);
1107 d1(kprintf("%s/%s/%ld: usid_IconObj=%08lx\n", __FILE__, __FUNC__, __LINE__, usid->usid_IconObj));
1109 if (NULL == usid->usid_IconObj)
1110 break;
1112 gg = (const struct ExtGadget *) in->in_Icon;
1114 uev->uev_OldPosX = gg->LeftEdge;
1115 uev->uev_OldPosY = gg->TopEdge;
1117 d1(kprintf("%s/%s/%ld: UNDOTAG_IconOldPosX=%ld UNDOTAG_IconOldPosY=%ld\n", \
1118 __FILE__, __FUNC__, __LINE__, uev->uev_OldPosX, \
1119 uev->uev_OldPosY));
1121 Success = TRUE;
1122 } while (0);
1124 if (name)
1125 FreePathBuffer(name);
1127 return Success;
1130 //----------------------------------------------------------------------------
1132 static BOOL AddCleanupEvent(struct UndoEvent *uev, struct TagItem *TagList)
1134 BOOL Success = FALSE;
1136 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
1138 do {
1139 struct UndoCleanupData *ucd = &uev->uev_Data.uev_CleanupData;
1140 const struct ScaIconNode *IconList;
1141 const struct ScaIconNode *in;
1142 struct UndoCleanupIconEntry *ucie;
1143 static struct Hook DisposeCleanupDataHook =
1145 { NULL, NULL },
1146 HOOKFUNC_DEF(UndoDisposeCleanupData), // h_Entry + h_SubEntry
1147 NULL, // h_Data
1149 static struct Hook UndoCleanupEventHook =
1151 { NULL, NULL },
1152 HOOKFUNC_DEF(UndoCleanupEvent), // h_Entry + h_SubEntry
1153 NULL, // h_Data
1155 static struct Hook RedoCleanupEventHook =
1157 { NULL, NULL },
1158 HOOKFUNC_DEF(RedoCleanupEvent), // h_Entry + h_SubEntry
1159 NULL, // h_Data
1162 uev->uev_DisposeHook = (struct Hook *) GetTagData(UNDOTAG_DisposeHook, (ULONG) &DisposeCleanupDataHook, TagList);
1163 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &UndoCleanupEventHook, TagList);
1164 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &RedoCleanupEventHook, TagList);
1166 uev->uev_DescrMsgIDSingle = MSGID_UNDO_CLEANUP;
1167 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_CLEANUP;
1169 ucd->ucd_CleanupMode = GetTagData(UNDOTAG_CleanupMode, CLEANUP_Default, TagList);
1171 d1(kprintf("%s/%s/%ld: UNDOTAG_CleanupMode=%ld\n", __FILE__, __FUNC__, __LINE__, ucd->ucd_CleanupMode));
1173 ucd->ucd_WindowTask = (struct ScaWindowTask *) GetTagData(UNDOTAG_WindowTask, (ULONG) NULL, TagList);
1174 if (NULL == ucd->ucd_WindowTask)
1175 break;
1177 ucd->ucd_WindowTitle = AllocCopyString(((struct internalScaWindowTask *) ucd->ucd_WindowTask)->iwt_WinTitle);
1178 if (NULL == ucd->ucd_WindowTitle)
1179 break;
1181 uev->uev_DescrObjName = &ucd->ucd_WindowTitle;
1183 d1(kprintf("%s/%s/%ld: UNDOTAG_WindowTask=%08lx\n", __FILE__, __FUNC__, __LINE__, ucd->ucd_WindowTask));
1184 d1(kprintf("%s/%s/%ld: ucd_WindowTitle=<%s>\n", __FILE__, __FUNC__, __LINE__, ucd->ucd_WindowTitle));
1186 IconList = (struct ScaIconNode *) GetTagData(UNDOTAG_IconList, (ULONG) NULL, TagList);
1187 if (NULL == IconList)
1188 break;
1190 d1(kprintf("%s/%s/%ld: UNDOTAG_IconList=%08lx\n", __FILE__, __FUNC__, __LINE__, IconList));
1192 ScalosLockIconListShared((struct internalScaWindowTask *) ucd->ucd_WindowTask);
1194 // count number of icons
1195 for (in = IconList; in; in = (const struct ScaIconNode *) in->in_Node.mln_Succ)
1197 ucd->ucd_IconCount++;
1200 d1(kprintf("%s/%s/%ld: ucd_IconCount=%lu\n", __FILE__, __FUNC__, __LINE__, ucd->ucd_IconCount));
1202 // create array to store icon positions
1203 ucd->ucd_Icons = ScalosAlloc(ucd->ucd_IconCount * sizeof(struct UndoCleanupIconEntry));
1204 if (NULL == ucd->ucd_Icons)
1205 break;
1207 // store icon positions in array
1208 for (ucie = ucd->ucd_Icons, in = IconList;
1209 in; in = (const struct ScaIconNode *) in->in_Node.mln_Succ, ucie++)
1211 const struct ExtGadget *gg = (const struct ExtGadget *) in->in_Icon;
1213 ucie->ucin_IconNode = in;
1214 ucie->ucin_Left = gg->LeftEdge;
1215 ucie->ucin_Top = gg->TopEdge;
1217 d1(kprintf("%s/%s/%ld: in=%08lx <%s> Left=%ld Top=%ld\n", \
1218 __FILE__, __FUNC__, __LINE__, in, GetIconName(in), \
1219 ucie->ucin_Left, ucie->ucin_Top));
1222 ScalosUnLockIconList((struct internalScaWindowTask *) ucd->ucd_WindowTask);
1224 d1(kprintf("%s/%s/%ld: ucd_WindowTask=%08lx\n", __FILE__, __FUNC__, __LINE__, ucd->ucd_WindowTask));
1226 Success = TRUE;
1227 } while (0);
1229 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
1231 return Success;
1234 //----------------------------------------------------------------------------
1236 static BOOL AddRenameEvent(struct UndoEvent *uev, struct TagItem *TagList)
1238 BOOL Success = FALSE;
1239 STRPTR name;
1241 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
1243 do {
1244 BPTR dirLock;
1245 CONST_STRPTR fName;
1246 struct UndoCopyMoveEventData *ucmed = &uev->uev_Data.uev_CopyMoveData;
1247 static struct Hook UndoDisposeCopyMoveDataHook =
1249 { NULL, NULL },
1250 HOOKFUNC_DEF(UndoDisposeCopyMoveData), // h_Entry + h_SubEntry
1251 NULL, // h_Data
1253 static struct Hook UndoRenameHook =
1255 { NULL, NULL },
1256 HOOKFUNC_DEF(UndoRenameEvent), // h_Entry + h_SubEntry
1257 NULL, // h_Data
1259 static struct Hook RedoRenameHook =
1261 { NULL, NULL },
1262 HOOKFUNC_DEF(RedoRenameEvent), // h_Entry + h_SubEntry
1263 NULL, // h_Data
1266 uev->uev_DisposeHook = (struct Hook *) GetTagData(UNDOTAG_DisposeHook, (ULONG) &UndoDisposeCopyMoveDataHook, TagList);
1268 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &UndoRenameHook, TagList);
1269 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &RedoRenameHook, TagList);
1271 uev->uev_DescrMsgIDSingle = MSGID_UNDO_RENAME_SINGLE;
1272 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_RENAME_MORE;
1274 uev->uev_DescrObjName = &ucmed->ucmed_srcName;
1276 name = AllocPathBuffer();
1277 if (NULL == name)
1278 break;
1280 d1(kprintf("%s/%s/%ld: name=%08lx\n", __FILE__, __FUNC__, __LINE__, name));
1282 dirLock = (BPTR) GetTagData(UNDOTAG_CopySrcDirLock, 0, TagList);
1283 d1(kprintf("%s/%s/%ld: dirLock=%08lx\n", __FILE__, __FUNC__, __LINE__, dirLock));
1284 if (BNULL == dirLock)
1285 break;
1287 if (!NameFromLock(dirLock, name, Max_PathLen))
1288 break;
1290 d1(kprintf("%s/%s/%ld: UNDOTAG_CopySrcDirLock=<%s>\n", __FILE__, __FUNC__, __LINE__, name));
1292 ucmed->ucmed_srcDirName = AllocCopyString(name);
1293 if (NULL == ucmed->ucmed_srcDirName)
1294 break;
1296 fName = (CONST_STRPTR) GetTagData(UNDOTAG_CopySrcName, (ULONG) NULL, TagList);
1297 if (NULL == fName)
1298 break;
1300 d1(kprintf("%s/%s/%ld: UNDOTAG_CopySrcName=<%s>\n", __FILE__, __FUNC__, __LINE__, fName));
1302 ucmed->ucmed_srcName = AllocCopyString(fName);
1303 if (NULL == ucmed->ucmed_srcName)
1304 break;
1306 fName = (CONST_STRPTR) GetTagData(UNDOTAG_CopyDestName, (ULONG) NULL, TagList);
1307 if (NULL == fName)
1308 break;
1309 d1(kprintf("%s/%s/%ld: UNDOTAG_CopyDestName=<%s>\n", __FILE__, __FUNC__, __LINE__, fName));
1311 ucmed->ucmed_destName = AllocCopyString(fName);
1312 if (NULL == ucmed->ucmed_destName)
1313 break;
1315 Success = TRUE;
1316 } while (0);
1318 if (name)
1319 FreePathBuffer(name);
1321 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
1323 return Success;
1326 //----------------------------------------------------------------------------
1328 static BOOL AddRelabelEvent(struct UndoEvent *uev, struct TagItem *TagList)
1330 BOOL Success = FALSE;
1331 STRPTR name;
1333 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
1335 do {
1336 CONST_STRPTR fName;
1337 struct UndoCopyMoveEventData *ucmed = &uev->uev_Data.uev_CopyMoveData;
1338 static struct Hook UndoDisposeCopyMoveDataHook =
1340 { NULL, NULL },
1341 HOOKFUNC_DEF(UndoDisposeCopyMoveData), // h_Entry + h_SubEntry
1342 NULL, // h_Data
1344 static struct Hook UndoRelabelHook =
1346 { NULL, NULL },
1347 HOOKFUNC_DEF(UndoRelabelEvent), // h_Entry + h_SubEntry
1348 NULL, // h_Data
1350 static struct Hook RedoRelabelHook =
1352 { NULL, NULL },
1353 HOOKFUNC_DEF(RedoRelabelEvent), // h_Entry + h_SubEntry
1354 NULL, // h_Data
1357 uev->uev_DisposeHook = (struct Hook *) GetTagData(UNDOTAG_DisposeHook, (ULONG) &UndoDisposeCopyMoveDataHook, TagList);
1359 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &UndoRelabelHook, TagList);
1360 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &RedoRelabelHook, TagList);
1362 uev->uev_DescrMsgIDSingle = MSGID_UNDO_RELABEL_SINGLE;
1363 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_RELABEL_MORE;
1365 uev->uev_DescrObjName = &ucmed->ucmed_srcName;
1367 name = AllocPathBuffer();
1368 if (NULL == name)
1369 break;
1371 d1(kprintf("%s/%s/%ld: name=%08lx\n", __FILE__, __FUNC__, __LINE__, name));
1373 ucmed->ucmed_srcDirName = AllocCopyString(name);
1374 if (NULL == ucmed->ucmed_srcDirName)
1375 break;
1377 fName = (CONST_STRPTR) GetTagData(UNDOTAG_CopySrcName, (ULONG) NULL, TagList);
1378 if (NULL == fName)
1379 break;
1381 // i.e. "Data1old:"
1382 d1(kprintf("%s/%s/%ld: UNDOTAG_CopySrcName=<%s>\n", __FILE__, __FUNC__, __LINE__, fName));
1384 ucmed->ucmed_srcName = AllocCopyString(fName);
1385 if (NULL == ucmed->ucmed_srcName)
1386 break;
1388 fName = (CONST_STRPTR) GetTagData(UNDOTAG_CopyDestName, (ULONG) NULL, TagList);
1389 if (NULL == fName)
1390 break;
1392 // i.e. "Data1new"
1393 d1(kprintf("%s/%s/%ld: UNDOTAG_CopyDestName=<%s>\n", __FILE__, __FUNC__, __LINE__, fName));
1395 ucmed->ucmed_destName = AllocCopyString(fName);
1396 if (NULL == ucmed->ucmed_destName)
1397 break;
1399 Success = TRUE;
1400 } while (0);
1402 if (name)
1403 FreePathBuffer(name);
1405 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
1407 return Success;
1410 //----------------------------------------------------------------------------
1412 static BOOL AddDeleteEvent(struct UndoEvent *uev, struct TagItem *TagList)
1414 BOOL Success = FALSE;
1415 STRPTR name;
1417 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
1419 do {
1420 BPTR dirLock;
1421 CONST_STRPTR fName;
1422 struct UndoCopyMoveEventData *ucmed = &uev->uev_Data.uev_CopyMoveData;
1423 static struct Hook UndoDisposeCopyMoveDataHook =
1425 { NULL, NULL },
1426 HOOKFUNC_DEF(UndoDisposeCopyMoveData), // h_Entry + h_SubEntry
1427 NULL, // h_Data
1429 static struct Hook UndoDeleteHook =
1431 { NULL, NULL },
1432 HOOKFUNC_DEF(UndoMoveEvent), // h_Entry + h_SubEntry
1433 NULL, // h_Data
1435 static struct Hook RedoDeleteHook =
1437 { NULL, NULL },
1438 HOOKFUNC_DEF(RedoMoveEvent), // h_Entry + h_SubEntry
1439 NULL, // h_Data
1442 uev->uev_DisposeHook = (struct Hook *) GetTagData(UNDOTAG_DisposeHook, (ULONG) &UndoDisposeCopyMoveDataHook, TagList);
1444 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &UndoDeleteHook, TagList);
1445 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &RedoDeleteHook, TagList);
1447 uev->uev_DescrMsgIDSingle = MSGID_UNDO_DELETE_SINGLE;
1448 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_DELETE_MORE;
1450 uev->uev_DescrObjName = &ucmed->ucmed_srcName;
1452 name = AllocPathBuffer();
1453 if (NULL == name)
1454 break;
1456 d1(kprintf("%s/%s/%ld: name=%08lx\n", __FILE__, __FUNC__, __LINE__, name));
1458 dirLock = (BPTR) GetTagData(UNDOTAG_CopySrcDirLock, 0, TagList);
1459 d1(kprintf("%s/%s/%ld: dirLock=%08lx\n", __FILE__, __FUNC__, __LINE__, dirLock));
1460 if (BNULL == dirLock)
1461 break;
1463 if (!NameFromLock(dirLock, name, Max_PathLen))
1464 break;
1466 d1(kprintf("%s/%s/%ld: UNDOTAG_CopySrcDirLock=<%s>\n", __FILE__, __FUNC__, __LINE__, name));
1468 ucmed->ucmed_srcDirName = AllocCopyString(name);
1469 if (NULL == ucmed->ucmed_srcDirName)
1470 break;
1472 fName = (CONST_STRPTR) GetTagData(UNDOTAG_CopySrcName, (ULONG) NULL, TagList);
1473 if (NULL == fName)
1474 break;
1476 d1(kprintf("%s/%s/%ld: UNDOTAG_CopySrcName=<%s>\n", __FILE__, __FUNC__, __LINE__, fName));
1478 ucmed->ucmed_srcName = AllocCopyString(fName);
1479 if (NULL == ucmed->ucmed_srcName)
1480 break;
1482 fName = (CONST_STRPTR) GetTagData(UNDOTAG_CopyDestName, (ULONG) "SYS:Trashcan", TagList);
1483 if (NULL == fName)
1484 break;
1485 d1(kprintf("%s/%s/%ld: UNDOTAG_CopyDestName=<%s>\n", __FILE__, __FUNC__, __LINE__, fName));
1487 ucmed->ucmed_destName = AllocCopyString(fName);
1488 if (NULL == ucmed->ucmed_destName)
1489 break;
1491 Success = TRUE;
1492 } while (0);
1494 if (name)
1495 FreePathBuffer(name);
1497 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
1499 return Success;
1502 //----------------------------------------------------------------------------
1504 static BOOL AddSizeWindowEvent(struct UndoEvent *uev, struct TagItem *TagList)
1506 BOOL Success = FALSE;
1508 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
1510 do {
1511 struct UndoSizeWindowData *uswd = &uev->uev_Data.uev_SizeWindowData;
1512 static struct Hook DisposeSizeWindowDataHook =
1514 { NULL, NULL },
1515 HOOKFUNC_DEF(UndoDisposeSizeWindowData), // h_Entry + h_SubEntry
1516 NULL, // h_Data
1518 static struct Hook UndoSizeWindowHook =
1520 { NULL, NULL },
1521 HOOKFUNC_DEF(UndoSizeWindowEvent), // h_Entry + h_SubEntry
1522 NULL, // h_Data
1524 static struct Hook RedoSizeWindowHook =
1526 { NULL, NULL },
1527 HOOKFUNC_DEF(RedoSizeWindowEvent), // h_Entry + h_SubEntry
1528 NULL, // h_Data
1531 uev->uev_DisposeHook = (struct Hook *) GetTagData(UNDOTAG_DisposeHook, (ULONG) &DisposeSizeWindowDataHook, TagList);
1532 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &UndoSizeWindowHook, TagList);
1533 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &RedoSizeWindowHook, TagList);
1535 uev->uev_DescrMsgIDSingle = MSGID_UNDO_SIZEWINDOW;
1536 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_SIZEWINDOW;
1538 uswd->uswd_WindowTask = (struct ScaWindowTask *) GetTagData(UNDOTAG_WindowTask, (ULONG) NULL, TagList);
1539 if (NULL == uswd->uswd_WindowTask)
1540 break;
1542 uswd->uswd_WindowTitle = AllocCopyString(((struct internalScaWindowTask *) uswd->uswd_WindowTask)->iwt_WinTitle);
1543 if (NULL == uswd->uswd_WindowTitle)
1544 break;
1546 uev->uev_DescrObjName = &uswd->uswd_WindowTitle;
1548 d1(kprintf("%s/%s/%ld: UNDOTAG_WindowTask=%08lx\n", __FILE__, __FUNC__, __LINE__, uswd->uswd_WindowTask));
1550 uswd->uswd_OldLeft = GetTagData(UNDOTAG_OldWindowLeft, 0, TagList);
1551 uswd->uswd_OldTop = GetTagData(UNDOTAG_OldWindowTop, 0, TagList);
1552 uswd->uswd_OldWidth = GetTagData(UNDOTAG_OldWindowWidth, 0, TagList);
1553 uswd->uswd_OldHeight = GetTagData(UNDOTAG_OldWindowHeight, 0, TagList);
1554 uswd->uswd_OldVirtX = GetTagData(UNDOTAG_OldWindowVirtX, 0, TagList);
1555 uswd->uswd_OldVirtY = GetTagData(UNDOTAG_OldWindowVirtY, 0, TagList);
1557 uswd->uswd_NewLeft = GetTagData(UNDOTAG_NewWindowLeft, uswd->uswd_OldLeft, TagList);
1558 uswd->uswd_NewTop = GetTagData(UNDOTAG_NewWindowTop, uswd->uswd_OldTop, TagList);
1559 uswd->uswd_NewWidth = GetTagData(UNDOTAG_NewWindowWidth, uswd->uswd_OldWidth, TagList);
1560 uswd->uswd_NewHeight = GetTagData(UNDOTAG_NewWindowHeight, uswd->uswd_OldHeight, TagList);
1561 uswd->uswd_NewVirtX = GetTagData(UNDOTAG_NewWindowVirtX, uswd->uswd_OldVirtX, TagList);
1562 uswd->uswd_NewVirtY = GetTagData(UNDOTAG_NewWindowVirtY, uswd->uswd_OldVirtY, TagList);
1564 d1(kprintf("%s/%s/%ld: UNDOTAG_OldWindowLeft=%ld\n", __FILE__, __FUNC__, __LINE__, uswd->uswd_OldLeft));
1565 d1(kprintf("%s/%s/%ld: UNDOTAG_OldWindowTop=%ld\n", __FILE__, __FUNC__, __LINE__, uswd->uswd_OldTop));
1566 d1(kprintf("%s/%s/%ld: UNDOTAG_OldWindowWidth=%lu\n", __FILE__, __FUNC__, __LINE__, uswd->uswd_OldWidth));
1567 d1(kprintf("%s/%s/%ld: UNDOTAG_OldWindowHeight=%lu\n", __FILE__, __FUNC__, __LINE__, uswd->uswd_OldHeight));
1568 d1(kprintf("%s/%s/%ld: UNDOTAG_OldWindowVirtX=%ld\n", __FILE__, __FUNC__, __LINE__, uswd->uswd_OldVirtX));
1569 d1(kprintf("%s/%s/%ld: UNDOTAG_OldWindowVirtY=%ld\n", __FILE__, __FUNC__, __LINE__, uswd->uswd_OldVirtY));
1570 d1(kprintf("%s/%s/%ld: UNDOTAG_NewWindowLeft=%ld\n", __FILE__, __FUNC__, __LINE__, uswd->uswd_NewLeft));
1571 d1(kprintf("%s/%s/%ld: UNDOTAG_NewWindowTop=%ld\n", __FILE__, __FUNC__, __LINE__, uswd->uswd_NewTop));
1572 d1(kprintf("%s/%s/%ld: UNDOTAG_NewWindowWidth=%lu\n", __FILE__, __FUNC__, __LINE__, uswd->uswd_NewWidth));
1573 d1(kprintf("%s/%s/%ld: UNDOTAG_NewWindowHeight=%lu\n", __FILE__, __FUNC__, __LINE__, uswd->uswd_NewHeight));
1574 d1(kprintf("%s/%s/%ld: UNDOTAG_NewWindowVirtX=%ld\n", __FILE__, __FUNC__, __LINE__, uswd->uswd_NewVirtX));
1575 d1(kprintf("%s/%s/%ld: UNDOTAG_NewWindowVirtY=%ld\n", __FILE__, __FUNC__, __LINE__, uswd->uswd_NewVirtY));
1577 Success = TRUE;
1578 } while (0);
1580 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
1582 return Success;
1585 //----------------------------------------------------------------------------
1587 static BOOL AddNewDrawerEvent(struct UndoEvent *uev, struct TagItem *TagList)
1589 BOOL Success = FALSE;
1590 STRPTR name;
1592 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
1594 do {
1595 BPTR dirLock;
1596 CONST_STRPTR fName;
1597 struct UndoNewDrawerData *und = &uev->uev_Data.uev_NewDrawerData;
1598 static struct Hook UndoDisposeNewDrawerHook =
1600 { NULL, NULL },
1601 HOOKFUNC_DEF(UndoDisposeNewDrawerData), // h_Entry + h_SubEntry
1602 NULL, // h_Data
1604 static struct Hook UndoNewDrawerHook =
1606 { NULL, NULL },
1607 HOOKFUNC_DEF(UndoNewDrawerEvent), // h_Entry + h_SubEntry
1608 NULL, // h_Data
1610 static struct Hook RedoNewDrawerHook =
1612 { NULL, NULL },
1613 HOOKFUNC_DEF(RedoNewDrawerEvent), // h_Entry + h_SubEntry
1614 NULL, // h_Data
1617 uev->uev_DisposeHook = (struct Hook *) GetTagData(UNDOTAG_DisposeHook, (ULONG) &UndoDisposeNewDrawerHook, TagList);
1619 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &UndoNewDrawerHook, TagList);
1620 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &RedoNewDrawerHook, TagList);
1622 uev->uev_DescrMsgIDSingle = MSGID_UNDO_NEWDRAWER_SINGLE;
1623 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_NEWDRAWER_MORE;
1624 uev->uev_DescrObjName = &und->und_srcName;
1626 name = AllocPathBuffer();
1627 if (NULL == name)
1628 break;
1630 d1(kprintf("%s/%s/%ld: name=%08lx\n", __FILE__, __FUNC__, __LINE__, name));
1632 dirLock = (BPTR) GetTagData(UNDOTAG_IconDirLock, 0, TagList);
1633 d1(kprintf("%s/%s/%ld: dirLock=%08lx\n", __FILE__, __FUNC__, __LINE__, dirLock));
1634 if (BNULL == dirLock)
1635 break;
1637 if (!NameFromLock(dirLock, name, Max_PathLen))
1638 break;
1640 d1(kprintf("%s/%s/%ld: UNDOTAG_IconDirLock=<%s>\n", __FILE__, __FUNC__, __LINE__, name));
1642 und->und_DirName = AllocCopyString(name);
1643 if (NULL == und->und_DirName)
1644 break;
1646 fName = (CONST_STRPTR) GetTagData(UNDOTAG_IconName, (ULONG) NULL, TagList);
1647 if (NULL == fName)
1648 break;
1650 d1(kprintf("%s/%s/%ld: UNDOTAG_IconName=<%s>\n", __FILE__, __FUNC__, __LINE__, fName));
1652 und->und_srcName = AllocCopyString(fName);
1653 if (NULL == und->und_srcName)
1654 break;
1656 und->und_CreateIcon = GetTagData(UNDOTAG_CreateIcon, TRUE, TagList);
1658 d1(kprintf("%s/%s/%ld: UNDOTAG_CreateIcon=%ld\n", __FILE__, __FUNC__, __LINE__, und->und_CreateIcon));
1660 Success = TRUE;
1661 } while (0);
1663 if (name)
1664 FreePathBuffer(name);
1666 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
1668 return Success;
1671 //----------------------------------------------------------------------------
1673 static BOOL AddLeaveOutPutAwayEvent(struct UndoEvent *uev, struct TagItem *TagList)
1675 BOOL Success = FALSE;
1676 STRPTR name;
1678 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
1680 do {
1681 struct UndoSnaphotIconData *usid = &uev->uev_Data.uev_SnapshotData;
1682 BPTR dirLock;
1683 CONST_STRPTR IconName;
1684 static struct Hook UndoDisposeLeaveOutPutAwayHook =
1686 { NULL, NULL },
1687 HOOKFUNC_DEF(UndoDisposeSnapshotData), // h_Entry + h_SubEntry
1688 NULL, // h_Data
1690 static struct Hook UndoLeaveOutHook =
1692 { NULL, NULL },
1693 HOOKFUNC_DEF(UndoLeaveOutEvent), // h_Entry + h_SubEntry
1694 NULL, // h_Data
1696 static struct Hook RedoLeaveOutHook =
1698 { NULL, NULL },
1699 HOOKFUNC_DEF(RedoLeaveOutEvent), // h_Entry + h_SubEntry
1700 NULL, // h_Data
1703 uev->uev_DisposeHook = (struct Hook *) GetTagData(UNDOTAG_DisposeHook, (ULONG) &UndoDisposeLeaveOutPutAwayHook, TagList);
1705 if (UNDO_PutAway == uev->uev_Type)
1707 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &RedoLeaveOutHook, TagList);
1708 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &UndoLeaveOutHook, TagList);
1709 uev->uev_DescrMsgIDSingle = MSGID_UNDO_PUTAWAY_SINGLE;
1710 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_PUTAWAY_MORE;
1712 else
1714 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &UndoLeaveOutHook, TagList);
1715 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &RedoLeaveOutHook, TagList);
1716 uev->uev_DescrMsgIDSingle = MSGID_UNDO_LEAVEOUT_SINGLE;
1717 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_LEAVEOUT_MORE;
1720 uev->uev_DescrObjName = &usid->usid_IconName;
1722 name = AllocPathBuffer();
1723 if (NULL == name)
1724 break;
1726 d1(kprintf("%s/%s/%ld: name=%08lx\n", __FILE__, __FUNC__, __LINE__, name));
1728 dirLock = (BPTR) GetTagData(UNDOTAG_IconDirLock, 0, TagList);
1729 debugLock_d1(dirLock);
1730 if (BNULL == dirLock)
1731 break;
1733 if (!NameFromLock(dirLock, name, Max_PathLen))
1734 break;
1736 d1(kprintf("%s/%s/%ld: UNDOTAG_IconDirLock=<%s>\n", __FILE__, __FUNC__, __LINE__, name));
1738 usid->usid_DirName = AllocCopyString(name);
1739 if (NULL == usid->usid_DirName)
1740 break;
1742 IconName = (CONST_STRPTR) GetTagData(UNDOTAG_IconName, (ULONG) NULL, TagList);
1743 if (NULL == IconName)
1744 break;
1746 usid->usid_IconName = AllocCopyString(IconName);
1747 if (NULL == usid->usid_IconName)
1748 break;
1750 d1(kprintf("%s/%s/%ld: UNDOTAG_IconName=<%s>\n", __FILE__, __FUNC__, __LINE__, usid->usid_IconName));
1752 Success = TRUE;
1753 } while (0);
1755 if (name)
1756 FreePathBuffer(name);
1758 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
1760 return Success;
1763 //----------------------------------------------------------------------------
1765 static BOOL AddSetProtectionEvent(struct UndoEvent *uev, struct TagItem *TagList)
1767 BOOL Success = FALSE;
1768 STRPTR name;
1770 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
1772 do {
1773 struct UndoSetProtectionData *uspd = &uev->uev_Data.uev_SetProtectionData;
1774 BPTR dirLock;
1775 CONST_STRPTR IconName;
1776 static struct Hook UndoDisposeSetProtectionHook =
1778 { NULL, NULL },
1779 HOOKFUNC_DEF(UndoDisposeSetProtectionData), // h_Entry + h_SubEntry
1780 NULL, // h_Data
1782 static struct Hook UndoSetProtectionHook =
1784 { NULL, NULL },
1785 HOOKFUNC_DEF(UndoSetProtectionEvent), // h_Entry + h_SubEntry
1786 NULL, // h_Data
1788 static struct Hook RedoSetProtectionHook =
1790 { NULL, NULL },
1791 HOOKFUNC_DEF(RedoSetProtectionEvent), // h_Entry + h_SubEntry
1792 NULL, // h_Data
1795 uev->uev_DisposeHook = (struct Hook *) GetTagData(UNDOTAG_DisposeHook, (ULONG) &UndoDisposeSetProtectionHook, TagList);
1797 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &UndoSetProtectionHook, TagList);
1798 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &RedoSetProtectionHook, TagList);
1799 uev->uev_DescrMsgIDSingle = MSGID_UNDO_SETPROTECTION_SINGLE;
1800 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_SETPROTECTION_MORE;
1802 uev->uev_DescrObjName = &uspd->uspd_IconName;
1804 name = AllocPathBuffer();
1805 if (NULL == name)
1806 break;
1808 d1(kprintf("%s/%s/%ld: name=%08lx\n", __FILE__, __FUNC__, __LINE__, name));
1810 dirLock = (BPTR) GetTagData(UNDOTAG_IconDirLock, 0, TagList);
1811 debugLock_d1(dirLock);
1812 if (BNULL == dirLock)
1813 break;
1815 if (!NameFromLock(dirLock, name, Max_PathLen))
1816 break;
1818 d1(kprintf("%s/%s/%ld: UNDOTAG_IconDirLock=<%s>\n", __FILE__, __FUNC__, __LINE__, name));
1820 uspd->uspd_DirName = AllocCopyString(name);
1821 if (NULL == uspd->uspd_DirName)
1822 break;
1824 IconName = (CONST_STRPTR) GetTagData(UNDOTAG_IconName, (ULONG) NULL, TagList);
1825 if (NULL == IconName)
1826 break;
1828 uspd->uspd_IconName = AllocCopyString(IconName);
1829 if (NULL == uspd->uspd_IconName)
1830 break;
1832 d1(kprintf("%s/%s/%ld: UNDOTAG_IconName=<%s>\n", __FILE__, __FUNC__, __LINE__, uspd->uspd_IconName));
1834 uspd->uspd_OldProtection = GetTagData(UNDOTAG_OldProtection, 0, TagList);
1835 uspd->uspd_NewProtection = GetTagData(UNDOTAG_NewProtection, uspd->uspd_OldProtection, TagList);
1837 d1(kprintf("%s/%s/%ld: UNDOTAG_OldProtection=%08lx\n", __FILE__, __FUNC__, __LINE__, uspd->uspd_OldProtection));
1838 d1(kprintf("%s/%s/%ld: UNDOTAG_NewProtection=%08lx\n", __FILE__, __FUNC__, __LINE__, uspd->uspd_NewProtection));
1840 Success = TRUE;
1841 } while (0);
1843 if (name)
1844 FreePathBuffer(name);
1846 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
1848 return Success;
1851 //----------------------------------------------------------------------------
1853 static BOOL AddSetCommentEvent(struct UndoEvent *uev, struct TagItem *TagList)
1855 BOOL Success = FALSE;
1856 STRPTR name;
1858 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
1860 do {
1861 struct UndoSetCommentData *uscd = &uev->uev_Data.uev_SetCommentData;
1862 BPTR dirLock;
1863 CONST_STRPTR IconName;
1864 CONST_STRPTR Comment;
1865 static struct Hook UndoDisposeSetCommentHook =
1867 { NULL, NULL },
1868 HOOKFUNC_DEF(UndoDisposeSetCommentData), // h_Entry + h_SubEntry
1869 NULL, // h_Data
1871 static struct Hook UndoSetCommentHook =
1873 { NULL, NULL },
1874 HOOKFUNC_DEF(UndoSetCommentEvent), // h_Entry + h_SubEntry
1875 NULL, // h_Data
1877 static struct Hook RedoSetCommentHook =
1879 { NULL, NULL },
1880 HOOKFUNC_DEF(RedoSetCommentEvent), // h_Entry + h_SubEntry
1881 NULL, // h_Data
1884 uev->uev_DisposeHook = (struct Hook *) GetTagData(UNDOTAG_DisposeHook, (ULONG) &UndoDisposeSetCommentHook, TagList);
1886 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &UndoSetCommentHook, TagList);
1887 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &RedoSetCommentHook, TagList);
1888 uev->uev_DescrMsgIDSingle = MSGID_UNDO_SETCOMMENT_SINGLE;
1889 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_SETCOMMENT_MORE;
1891 uev->uev_DescrObjName = &uscd->uscd_IconName;
1893 name = AllocPathBuffer();
1894 if (NULL == name)
1895 break;
1897 d1(kprintf("%s/%s/%ld: name=%08lx\n", __FILE__, __FUNC__, __LINE__, name));
1899 dirLock = (BPTR) GetTagData(UNDOTAG_IconDirLock, 0, TagList);
1900 debugLock_d1(dirLock);
1901 if (BNULL == dirLock)
1902 break;
1904 if (!NameFromLock(dirLock, name, Max_PathLen))
1905 break;
1907 d1(kprintf("%s/%s/%ld: UNDOTAG_IconDirLock=<%s>\n", __FILE__, __FUNC__, __LINE__, name));
1909 uscd->uscd_DirName = AllocCopyString(name);
1910 if (NULL == uscd->uscd_DirName)
1911 break;
1913 IconName = (CONST_STRPTR) GetTagData(UNDOTAG_IconName, (ULONG) NULL, TagList);
1914 if (NULL == IconName)
1915 break;
1917 uscd->uscd_IconName = AllocCopyString(IconName);
1918 if (NULL == uscd->uscd_IconName)
1919 break;
1921 d1(kprintf("%s/%s/%ld: UNDOTAG_IconName=<%s>\n", __FILE__, __FUNC__, __LINE__, uscd->uscd_IconName));
1923 Comment = (CONST_STRPTR) GetTagData(UNDOTAG_OldComment, (ULONG) NULL, TagList);
1924 if (NULL == Comment)
1925 break;
1927 uscd->uscd_OldComment = AllocCopyString(Comment);
1928 if (NULL == uscd->uscd_OldComment)
1929 break;
1931 d1(kprintf("%s/%s/%ld: UNDOTAG_OldComment=<%s>\n", __FILE__, __FUNC__, __LINE__, uscd->uscd_OldComment));
1933 Comment = (CONST_STRPTR) GetTagData(UNDOTAG_NewComment, (ULONG) NULL, TagList);
1934 if (NULL == Comment)
1935 break;
1937 uscd->uscd_NewComment = AllocCopyString(Comment);
1938 if (NULL == uscd->uscd_NewComment)
1939 break;
1941 d1(kprintf("%s/%s/%ld: UNDOTAG_NewComment=<%s>\n", __FILE__, __FUNC__, __LINE__, uscd->uscd_NewComment));
1943 Success = TRUE;
1944 } while (0);
1946 if (name)
1947 FreePathBuffer(name);
1949 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
1951 return Success;
1954 //----------------------------------------------------------------------------
1956 static BOOL AddSetToolTypesEvent(struct UndoEvent *uev, struct TagItem *TagList)
1958 BOOL Success = FALSE;
1959 STRPTR name;
1961 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
1963 do {
1964 struct UndoSetToolTypesData *ustd = &uev->uev_Data.uev_SetToolTypesData;
1965 BPTR dirLock;
1966 CONST_STRPTR IconName;
1967 CONST_STRPTR *ToolTypes;
1968 static struct Hook UndoDisposeSetToolTypesHook =
1970 { NULL, NULL },
1971 HOOKFUNC_DEF(UndoDisposeSetToolTypesData), // h_Entry + h_SubEntry
1972 NULL, // h_Data
1974 static struct Hook UndoSetToolTypesHook =
1976 { NULL, NULL },
1977 HOOKFUNC_DEF(UndoSetToolTypesEvent), // h_Entry + h_SubEntry
1978 NULL, // h_Data
1980 static struct Hook RedoSetToolTypesHook =
1982 { NULL, NULL },
1983 HOOKFUNC_DEF(RedoSetToolTypesEvent), // h_Entry + h_SubEntry
1984 NULL, // h_Data
1987 uev->uev_DisposeHook = (struct Hook *) GetTagData(UNDOTAG_DisposeHook, (ULONG) &UndoDisposeSetToolTypesHook, TagList);
1989 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &UndoSetToolTypesHook, TagList);
1990 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &RedoSetToolTypesHook, TagList);
1991 uev->uev_DescrMsgIDSingle = MSGID_UNDO_SETTOOLTYPES_SINGLE;
1992 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_SETTOOLTYPES_MORE;
1994 uev->uev_DescrObjName = &ustd->ustd_IconName;
1996 name = AllocPathBuffer();
1997 if (NULL == name)
1998 break;
2000 d1(kprintf("%s/%s/%ld: name=%08lx\n", __FILE__, __FUNC__, __LINE__, name));
2002 dirLock = (BPTR) GetTagData(UNDOTAG_IconDirLock, 0, TagList);
2003 debugLock_d1(dirLock);
2004 if (BNULL == dirLock)
2005 break;
2007 if (!NameFromLock(dirLock, name, Max_PathLen))
2008 break;
2010 d1(kprintf("%s/%s/%ld: UNDOTAG_IconDirLock=<%s>\n", __FILE__, __FUNC__, __LINE__, name));
2012 ustd->ustd_DirName = AllocCopyString(name);
2013 if (NULL == ustd->ustd_DirName)
2014 break;
2016 IconName = (CONST_STRPTR) GetTagData(UNDOTAG_IconName, (ULONG) NULL, TagList);
2017 if (NULL == IconName)
2018 break;
2020 ustd->ustd_IconName = AllocCopyString(IconName);
2021 if (NULL == ustd->ustd_IconName)
2022 break;
2024 d1(kprintf("%s/%s/%ld: UNDOTAG_IconName=<%s>\n", __FILE__, __FUNC__, __LINE__, ustd->ustd_IconName));
2026 ToolTypes = (CONST_STRPTR *) GetTagData(UNDOTAG_OldToolTypes, (ULONG) NULL, TagList);
2027 if (NULL == ToolTypes)
2028 break;
2030 ustd->ustd_OldToolTypes = CloneToolTypeArray(ToolTypes, 0);
2031 if (NULL == ustd->ustd_OldToolTypes)
2032 break;
2034 d1(kprintf("%s/%s/%ld: UNDOTAG_OldToolTypes=%08lx\n", __FILE__, __FUNC__, __LINE__, ustd->ustd_OldToolTypes));
2036 ToolTypes = (CONST_STRPTR *) GetTagData(UNDOTAG_NewToolTypes, (ULONG) NULL, TagList);
2037 if (NULL == ToolTypes)
2038 break;
2040 ustd->ustd_NewToolTypes = CloneToolTypeArray(ToolTypes, 0);
2041 if (NULL == ustd->ustd_NewToolTypes)
2042 break;
2044 d1(kprintf("%s/%s/%ld: UNDOTAG_NewToolTypes=%08lx\n", __FILE__, __FUNC__, __LINE__, ustd->ustd_NewToolTypes));
2046 Success = TRUE;
2047 } while (0);
2049 if (name)
2050 FreePathBuffer(name);
2052 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
2054 return Success;
2057 //----------------------------------------------------------------------------
2059 static BOOL AddChangeIconObjectEvent(struct UndoEvent *uev, struct TagItem *TagList)
2061 BOOL Success = FALSE;
2062 STRPTR name;
2064 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
2066 do {
2067 struct UndoChangeIconObjectData *uciod = &uev->uev_Data.uev_ChangeIconObjectData;
2068 BPTR dirLock;
2069 CONST_STRPTR IconName;
2070 Object *IconObj;
2071 static struct Hook UndoDisposeChangeIconObjectHook =
2073 { NULL, NULL },
2074 HOOKFUNC_DEF(UndoDisposeChangeIconObjectData), // h_Entry + h_SubEntry
2075 NULL, // h_Data
2077 static struct Hook UndoChangeIconObjectHook =
2079 { NULL, NULL },
2080 HOOKFUNC_DEF(UndoChangeIconObjectEvent), // h_Entry + h_SubEntry
2081 NULL, // h_Data
2083 static struct Hook RedoChangeIconObjectHook =
2085 { NULL, NULL },
2086 HOOKFUNC_DEF(RedoChangeIconObjectEvent), // h_Entry + h_SubEntry
2087 NULL, // h_Data
2090 uev->uev_DisposeHook = (struct Hook *) GetTagData(UNDOTAG_DisposeHook, (ULONG) &UndoDisposeChangeIconObjectHook, TagList);
2092 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &UndoChangeIconObjectHook, TagList);
2093 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &RedoChangeIconObjectHook, TagList);
2094 uev->uev_DescrMsgIDSingle = MSGID_UNDO_CHANGEICON_SINGLE;
2095 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_CHANGEICON_MORE;
2097 uev->uev_DescrObjName = &uciod->uciod_IconName;
2099 name = AllocPathBuffer();
2100 if (NULL == name)
2101 break;
2103 d1(kprintf("%s/%s/%ld: name=%08lx\n", __FILE__, __FUNC__, __LINE__, name));
2105 dirLock = (BPTR) GetTagData(UNDOTAG_IconDirLock, 0, TagList);
2106 debugLock_d1(dirLock);
2107 if (BNULL == dirLock)
2108 break;
2110 if (!NameFromLock(dirLock, name, Max_PathLen))
2111 break;
2113 d1(kprintf("%s/%s/%ld: UNDOTAG_IconDirLock=<%s>\n", __FILE__, __FUNC__, __LINE__, name));
2115 uciod->uciod_DirName = AllocCopyString(name);
2116 if (NULL == uciod->uciod_DirName)
2117 break;
2119 IconName = (CONST_STRPTR) GetTagData(UNDOTAG_IconName, (ULONG) NULL, TagList);
2120 if (NULL == IconName)
2121 break;
2123 uciod->uciod_IconName = AllocCopyString(IconName);
2124 if (NULL == uciod->uciod_IconName)
2125 break;
2127 d1(kprintf("%s/%s/%ld: UNDOTAG_IconName=<%s>\n", __FILE__, __FUNC__, __LINE__, uciod->uciod_IconName));
2129 IconObj = (Object *) GetTagData(UNDOTAG_OldIconObject, (ULONG) NULL, TagList);
2130 if (NULL == IconObj)
2131 break;
2133 uciod->uciod_OldIconObject = CloneIconObject(IconObj);
2134 if (NULL == uciod->uciod_OldIconObject)
2135 break;
2137 d1(kprintf("%s/%s/%ld: UNDOTAG_OldIconObject=%08lx\n", __FILE__, __FUNC__, __LINE__, uciod->uciod_OldIconObject));
2139 IconObj = (Object *) GetTagData(UNDOTAG_NewIconObject, (ULONG) NULL, TagList);
2140 if (NULL == IconObj)
2141 break;
2143 uciod->uciod_NewIconObject = CloneIconObject(IconObj);
2144 if (NULL == uciod->uciod_NewIconObject)
2145 break;
2147 d1(kprintf("%s/%s/%ld: UNDOTAG_NewIconObject=%08lx\n", __FILE__, __FUNC__, __LINE__, uciod->uciod_NewIconObject));
2149 Success = TRUE;
2150 } while (0);
2152 if (name)
2153 FreePathBuffer(name);
2155 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
2157 return Success;
2160 //----------------------------------------------------------------------------
2162 static BOOL AddCloseWindowEvent(struct UndoEvent *uev, struct TagItem *TagList)
2164 BOOL Success = FALSE;
2165 STRPTR name;
2167 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
2169 do {
2170 struct internalScaWindowTask *iwt;
2171 struct ScaWindowStruct *ws;
2172 struct UndoCloseWindowData *ucwd = &uev->uev_Data.uev_CloseWindowData;
2173 static struct Hook UndoDisposeCloseWindowHook =
2175 { NULL, NULL },
2176 HOOKFUNC_DEF(UndoDisposeCloseWindowData), // h_Entry + h_SubEntry
2177 NULL, // h_Data
2179 static struct Hook UndoCloseWindowHook =
2181 { NULL, NULL },
2182 HOOKFUNC_DEF(UndoCloseWindowEvent), // h_Entry + h_SubEntry
2183 NULL, // h_Data
2185 static struct Hook RedoCloseWindowHook =
2187 { NULL, NULL },
2188 HOOKFUNC_DEF(RedoCloseWindowEvent), // h_Entry + h_SubEntry
2189 NULL, // h_Data
2192 uev->uev_DisposeHook = (struct Hook *) GetTagData(UNDOTAG_DisposeHook, (ULONG) &UndoDisposeCloseWindowHook, TagList);
2194 uev->uev_UndoHook = (struct Hook *) GetTagData(UNDOTAG_UndoHook, (ULONG) &UndoCloseWindowHook, TagList);
2195 uev->uev_RedoHook = (struct Hook *) GetTagData(UNDOTAG_RedoHook, (ULONG) &RedoCloseWindowHook, TagList);
2197 uev->uev_DescrMsgIDSingle = MSGID_UNDO_CLOSEWINDOW_SINGLE;
2198 uev->uev_DescrMsgIDMultiple = MSGID_UNDO_CLOSEWINDOW_MORE;
2200 name = AllocPathBuffer();
2201 if (NULL == name)
2202 break;
2204 d1(kprintf("%s/%s/%ld: name=%08lx\n", __FILE__, __FUNC__, __LINE__, name));
2206 iwt = (struct internalScaWindowTask *) GetTagData(UNDOTAG_WindowTask, (ULONG) NULL, TagList);
2207 if (BNULL == iwt)
2208 break;
2210 ws = iwt->iwt_WindowTask.mt_WindowStruct;
2212 if (BNULL == ws->ws_Lock)
2213 break;
2215 ucwd->ucwd_WindowTitle = AllocCopyString(iwt->iwt_WinTitle);
2216 if (NULL == ucwd->ucwd_WindowTitle)
2217 break;
2219 d1(kprintf("%s/%s/%ld: ucwd_WindowTitle=%08lx\n", __FILE__, __FUNC__, __LINE__, ucwd->ucwd_WindowTitle));
2221 uev->uev_DescrObjName = &ucwd->ucwd_WindowTitle;
2223 if (!NameFromLock(ws->ws_Lock, name, Max_PathLen))
2224 break;
2226 d1(kprintf("%s/%s/%ld: ws_lock=<%s>\n", __FILE__, __FUNC__, __LINE__, name));
2228 ucwd->ucwd_DirName = AllocCopyString(name);
2229 if (NULL == ucwd->ucwd_DirName)
2230 break;
2232 ucwd->ucwd_Left = ws->ws_Left;
2233 ucwd->ucwd_Top = ws->ws_Top;
2234 ucwd->ucwd_Width = ws->ws_Width;
2235 ucwd->ucwd_Height = ws->ws_Height;
2236 ucwd->ucwd_VirtX = ws->ws_xoffset;
2237 ucwd->ucwd_VirtY = ws->ws_yoffset;
2238 ucwd->ucwd_ViewAll = ws->ws_ViewAll;
2239 ucwd->ucwd_Viewmodes = ws->ws_Viewmodes;
2241 Success = TRUE;
2242 } while (0);
2244 if (name)
2245 FreePathBuffer(name);
2247 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
2249 return Success;
2251 //----------------------------------------------------------------------------
2253 static SAVEDS(LONG) UndoCopyEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
2255 BOOL Success = FALSE;
2256 BPTR destDirLock;
2257 STRPTR iconName = NULL;
2259 (void) hook;
2260 (void) object;
2262 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
2264 do {
2265 struct UndoCopyMoveEventData *ucmed = &uev->uev_Data.uev_CopyMoveData;
2266 STRPTR destName;
2267 CONST_STRPTR iconExt = ".info";
2268 LONG Result;
2270 destDirLock = Lock(ucmed->ucmed_destDirName, ACCESS_READ);
2271 d1(kprintf("%s/%s/%ld: destDirLock=%08lx <%s>\n", __FILE__, __FUNC__, __LINE__, destDirLock, ucmed->ucmed_destDirName));
2272 if (BNULL == destDirLock)
2273 break;
2275 destName = ucmed->ucmed_destName;
2276 if (0 == strlen(destName))
2277 destName = ucmed->ucmed_srcName;
2279 Result = DoMethod(uev->uev_UndoStep->ust_FileTransObj,
2280 SCCM_FileTrans_Delete,
2281 destDirLock, destName);
2282 if (RETURN_OK != Result)
2283 break;
2285 iconName = ScalosAlloc(1 + strlen(destName) + strlen(iconExt));
2286 if (NULL == iconName)
2287 break;
2289 strcpy(iconName, destName);
2290 strcat(iconName, iconExt);
2292 /*Result =*/ DoMethod(uev->uev_UndoStep->ust_FileTransObj,
2293 SCCM_FileTrans_Delete,
2294 destDirLock, iconName);
2296 Success = TRUE;
2297 } while (0);
2299 if (BNULL != destDirLock)
2300 UnLock(destDirLock);
2301 if (iconName)
2302 ScalosFree(iconName);
2304 return Success;
2307 //----------------------------------------------------------------------------
2309 static SAVEDS(LONG) RedoCopyEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
2311 BOOL Success = FALSE;
2312 BPTR srcDirLock;
2313 BPTR destDirLock = BNULL;
2315 (void) hook;
2316 (void) object;
2318 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
2320 do {
2321 struct UndoCopyMoveEventData *ucmed = &uev->uev_Data.uev_CopyMoveData;
2322 ULONG Result;
2324 srcDirLock = Lock(ucmed->ucmed_srcDirName, ACCESS_READ);
2325 if (BNULL == srcDirLock)
2326 break;
2328 destDirLock = Lock(ucmed->ucmed_destDirName, ACCESS_READ);
2329 if (BNULL == destDirLock)
2330 break;
2332 Result = DoMethod(uev->uev_UndoStep->ust_FileTransObj, SCCM_FileTrans_Copy,
2333 srcDirLock, destDirLock,
2334 ucmed->ucmed_srcName,
2335 ucmed->ucmed_destName,
2336 uev->uev_NewPosX, uev->uev_NewPosY);
2337 if (RETURN_OK != Result)
2338 break;
2340 Success = TRUE;
2341 } while (0);
2343 if (BNULL != srcDirLock)
2344 UnLock(srcDirLock);
2345 if (BNULL != destDirLock)
2346 UnLock(destDirLock);
2348 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
2350 return Success;
2353 //----------------------------------------------------------------------------
2355 // Move moved file system object back to original position
2356 static SAVEDS(LONG) UndoMoveEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
2358 BOOL Success = FALSE;
2359 BPTR srcDirLock;
2360 BPTR destDirLock = BNULL;
2362 (void) hook;
2363 (void) object;
2365 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
2367 do {
2368 struct UndoCopyMoveEventData *ucmed = &uev->uev_Data.uev_CopyMoveData;
2369 ULONG Result;
2371 d1(kprintf("%s/%s/%ld: ucmed_srcDirName=<%s>\n", __FILE__, __FUNC__, __LINE__, ucmed->ucmed_srcDirName));
2373 srcDirLock = Lock(ucmed->ucmed_srcDirName, ACCESS_READ);
2374 if (BNULL == srcDirLock)
2375 break;
2377 debugLock_d1(srcDirLock);
2379 d1(kprintf("%s/%s/%ld: ucmed_destDirName=<%s>\n", __FILE__, __FUNC__, __LINE__, ucmed->ucmed_destDirName));
2381 destDirLock = Lock(ucmed->ucmed_destDirName, ACCESS_READ);
2382 if (BNULL == destDirLock)
2383 break;
2385 debugLock_d1(destDirLock);
2387 d1(kprintf("%s/%s/%ld: .ucmed_srcName=<%s>\n", __FILE__, __FUNC__, __LINE__, ucmed->ucmed_srcName));
2389 Result = DoMethod(uev->uev_UndoStep->ust_FileTransObj, SCCM_FileTrans_Move,
2390 destDirLock, srcDirLock,
2391 ucmed->ucmed_srcName,
2392 uev->uev_OldPosX, uev->uev_OldPosY);
2393 if (RETURN_OK != Result)
2394 break;
2396 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
2398 Success = TRUE;
2399 } while (0);
2401 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
2403 if (BNULL != srcDirLock)
2404 UnLock(srcDirLock);
2405 if (BNULL != destDirLock)
2406 UnLock(destDirLock);
2408 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
2410 return Success;
2413 //----------------------------------------------------------------------------
2415 // Repeat Move of moved file system object
2416 static SAVEDS(LONG) RedoMoveEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
2418 BOOL Success = FALSE;
2419 BPTR srcDirLock;
2420 BPTR destDirLock = BNULL;
2422 (void) hook;
2423 (void) object;
2425 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
2427 do {
2428 struct UndoCopyMoveEventData *ucmed = &uev->uev_Data.uev_CopyMoveData;
2429 ULONG Result;
2431 srcDirLock = Lock(ucmed->ucmed_srcDirName, ACCESS_READ);
2432 if (BNULL == srcDirLock)
2433 break;
2435 destDirLock = Lock(ucmed->ucmed_destDirName, ACCESS_READ);
2436 if (BNULL == destDirLock)
2437 break;
2439 Result = DoMethod(uev->uev_UndoStep->ust_FileTransObj, SCCM_FileTrans_Move,
2440 srcDirLock, destDirLock,
2441 ucmed->ucmed_srcName,
2442 uev->uev_NewPosX, uev->uev_NewPosY);
2443 if (RETURN_OK != Result)
2444 break;
2446 Success = TRUE;
2447 } while (0);
2449 if (BNULL != srcDirLock)
2450 UnLock(srcDirLock);
2451 if (BNULL != destDirLock)
2452 UnLock(destDirLock);
2454 return Success;
2457 //----------------------------------------------------------------------------
2459 static SAVEDS(LONG) RedoCreateLinkEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
2461 BOOL Success = FALSE;
2462 BPTR srcDirLock;
2463 BPTR destDirLock = BNULL;
2465 (void) hook;
2466 (void) object;
2468 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
2470 do {
2471 struct UndoCopyMoveEventData *ucmed = &uev->uev_Data.uev_CopyMoveData;
2472 ULONG Result;
2474 srcDirLock = Lock(ucmed->ucmed_srcDirName, ACCESS_READ);
2475 if (BNULL == srcDirLock)
2476 break;
2478 destDirLock = Lock(ucmed->ucmed_destDirName, ACCESS_READ);
2479 if (BNULL == destDirLock)
2480 break;
2482 Result = DoMethod(uev->uev_UndoStep->ust_FileTransObj, SCCM_FileTrans_CreateLink,
2483 srcDirLock, destDirLock,
2484 ucmed->ucmed_srcName,
2485 ucmed->ucmed_destName,
2486 uev->uev_NewPosX, uev->uev_NewPosY);
2487 if (RETURN_OK != Result)
2488 break;
2490 Success = TRUE;
2491 } while (0);
2493 if (BNULL != srcDirLock)
2494 UnLock(srcDirLock);
2495 if (BNULL != destDirLock)
2496 UnLock(destDirLock);
2498 return Success;
2501 //----------------------------------------------------------------------------
2503 static STRPTR UndoBuildIconName(CONST_STRPTR ObjName)
2505 STRPTR iconName = AllocPathBuffer();
2507 if (iconName)
2509 stccpy(iconName, ObjName, Max_PathLen);
2510 SafeStrCat(iconName, ".info", Max_PathLen);
2513 return iconName;
2516 //----------------------------------------------------------------------------
2518 static BOOL MoveIconTo(CONST_STRPTR DirName, CONST_STRPTR IconName, LONG xNew, LONG yNew)
2520 BOOL Success = FALSE;
2521 struct internalScaWindowTask *iwt;
2522 struct ScaIconNode *in = NULL;
2524 do {
2525 struct ScaIconNode *MovedIconList = NULL;
2526 LONG x0, y0;
2527 struct ExtGadget *gg;
2529 if (!UndoFindWindowAndIcon(DirName, IconName, &iwt, &in))
2530 break;
2532 SCA_MoveIconNode(&iwt->iwt_WindowTask.wt_IconList, &MovedIconList, in);
2534 RemoveIcons(iwt, &MovedIconList); // visibly remove icon from window
2536 gg = (struct ExtGadget *) in->in_Icon;
2538 // Adjust icon position
2539 x0 = gg->LeftEdge - gg->BoundsLeftEdge;
2541 gg->LeftEdge = xNew;
2542 gg->BoundsLeftEdge = gg->LeftEdge - x0;
2544 y0 = gg->TopEdge - gg->BoundsTopEdge;
2546 gg->TopEdge = yNew;
2547 gg->BoundsTopEdge = gg->TopEdge - y0;
2549 RefreshIconList(iwt, MovedIconList, NULL); // draw icon at new position in window
2551 SCA_MoveIconNode(&MovedIconList, &iwt->iwt_WindowTask.wt_IconList, in);
2553 Success = TRUE;
2554 } while (0);
2556 if (iwt)
2558 if (in)
2559 ScalosUnLockIconList(iwt);
2560 SCA_UnLockWindowList();
2563 return Success;
2566 //----------------------------------------------------------------------------
2568 static struct internalScaWindowTask *UndoFindWindowByDir(CONST_STRPTR DirName)
2570 struct internalScaWindowTask *iwt = NULL;
2571 BPTR DirLock;
2573 DirLock = Lock(DirName, ACCESS_READ);
2574 if (DirLock)
2576 struct ScaWindowStruct *ws;
2578 SCA_LockWindowList(SCA_LockWindowList_Shared);
2580 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
2581 debugLock_d1(DirLock);
2583 for (ws=winlist.wl_WindowStruct; (NULL == iwt) && ws; ws = (struct ScaWindowStruct *) ws->ws_Node.mln_Succ)
2585 if (ws->ws_Lock && (LOCK_SAME == ScaSameLock(DirLock, ws->ws_Lock)))
2587 iwt = (struct internalScaWindowTask *) ws->ws_WindowTask;
2588 d1(KPrintF("%s/%s/%ld: Found iwt=%08lx <%s>\n", __FILE__, __FUNC__, __LINE__, iwt, iwt->iwt_WinTitle));
2589 break;
2593 if (NULL == iwt)
2594 SCA_UnLockWindowList();
2596 UnLock(DirLock);
2599 d1(kprintf("%s/%s/%ld: iwt=%08lx\n", __FILE__, __FUNC__, __LINE__, iwt));
2601 return iwt;
2604 //----------------------------------------------------------------------------
2606 static struct internalScaWindowTask *UndoFindWindowByWindowTask(const struct ScaWindowTask *wt)
2608 struct ScaWindowStruct *ws;
2610 SCA_LockWindowList(SCA_LockWindowList_Shared);
2612 d1(kprintf("%s/%s/%ld: START wt=%08lx\n", __FILE__, __FUNC__, __LINE__, wt));
2614 for (ws=winlist.wl_WindowStruct; ws; ws = (struct ScaWindowStruct *) ws->ws_Node.mln_Succ)
2616 if (wt == ws->ws_WindowTask)
2618 struct internalScaWindowTask *iwt = (struct internalScaWindowTask *) ws->ws_WindowTask;
2619 d1(KPrintF("%s/%s/%ld: Found iwt=%08lx <%s>\n", __FILE__, __FUNC__, __LINE__, iwt, iwt->iwt_WinTitle));
2620 return iwt;
2624 SCA_UnLockWindowList();
2626 d1(kprintf("%s/%s/%ld: iwt=NULL\n", __FILE__, __FUNC__, __LINE__));
2628 return NULL;
2631 //----------------------------------------------------------------------------
2633 static struct ScaIconNode *UndoFindIconByName(struct internalScaWindowTask *iwt, CONST_STRPTR IconName)
2635 struct ScaIconNode *inFound = NULL;
2636 struct ScaIconNode *in;
2638 d1(KPrintF("%s/%s/%ld: START iwt=%08lx <%s>\n", __FILE__, __FUNC__, __LINE__, iwt, iwt->iwt_WinTitle));
2640 ScalosLockIconListShared(iwt);
2642 for (in=iwt->iwt_WindowTask.wt_IconList; in; in = (struct ScaIconNode *) in->in_Node.mln_Succ)
2644 if (0 == Stricmp(GetIconName(in), IconName))
2646 inFound = in;
2647 d1(kprintf("%s/%s/%ld: inFound=%08lx <%s>\n", __FILE__, __FUNC__, __LINE__, inFound, GetIconName(inFound)));
2648 break;
2652 if (NULL == inFound)
2653 ScalosUnLockIconList(iwt);
2655 d1(kprintf("%s/%s/%ld: inFound=%08lx\n", __FILE__, __FUNC__, __LINE__, inFound));
2657 return inFound;
2660 //----------------------------------------------------------------------------
2662 static SAVEDS(LONG) UndoChangeIconPosEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
2664 (void) hook;
2665 (void) object;
2667 d1(kprintf("%s/%s/%ld: uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2668 return MoveIconTo(uev->uev_Data.uev_IconData.uid_DirName,
2669 uev->uev_Data.uev_IconData.uid_IconName,
2670 uev->uev_OldPosX,
2671 uev->uev_OldPosY);
2674 //----------------------------------------------------------------------------
2676 static SAVEDS(LONG) RedoChangeIconPosEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
2678 (void) hook;
2679 (void) object;
2681 d1(kprintf("%s/%s/%ld: uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2682 return MoveIconTo(uev->uev_Data.uev_IconData.uid_DirName,
2683 uev->uev_Data.uev_IconData.uid_IconName,
2684 uev->uev_NewPosX,
2685 uev->uev_NewPosY);
2688 //----------------------------------------------------------------------------
2690 static SAVEDS(void) UndoDisposeCopyMoveData(struct Hook *hook, APTR object, struct UndoEvent *uev)
2692 (void) hook;
2693 (void) object;
2695 d1(kprintf("%s/%s/%ld: START uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2696 if (uev)
2698 struct UndoCopyMoveEventData *ucmed = &uev->uev_Data.uev_CopyMoveData;
2700 if (ucmed->ucmed_srcDirName)
2702 FreeCopyString(ucmed->ucmed_srcDirName);
2703 ucmed->ucmed_srcDirName = NULL;
2705 if (ucmed->ucmed_destDirName)
2707 FreeCopyString(ucmed->ucmed_destDirName);
2708 ucmed->ucmed_destDirName = NULL;
2710 if (ucmed->ucmed_srcName)
2712 FreeCopyString(ucmed->ucmed_srcName);
2713 ucmed->ucmed_srcName = NULL;
2715 if (ucmed->ucmed_destName)
2717 FreeCopyString(ucmed->ucmed_destName);
2718 ucmed->ucmed_destName = NULL;
2721 d1(kprintf("%s/%s/%ld: END uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2724 //----------------------------------------------------------------------------
2726 static SAVEDS(void) UndoDisposeNewDrawerData(struct Hook *hook, APTR object, struct UndoEvent *uev)
2728 (void) hook;
2729 (void) object;
2731 d1(kprintf("%s/%s/%ld: START uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2732 if (uev)
2734 struct UndoNewDrawerData *und = &uev->uev_Data.uev_NewDrawerData;
2736 if (und->und_DirName)
2738 FreeCopyString(und->und_DirName);
2739 und->und_DirName = NULL;
2741 if (und->und_srcName)
2743 FreeCopyString(und->und_srcName);
2744 und->und_srcName = NULL;
2747 d1(kprintf("%s/%s/%ld: END uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2749 //----------------------------------------------------------------------------
2751 static SAVEDS(void) UndoDisposeIconData(struct Hook *hook, APTR object, struct UndoEvent *uev)
2753 (void) hook;
2754 (void) object;
2756 d1(kprintf("%s/%s/%ld: START uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2757 if (uev)
2759 if (uev->uev_Data.uev_IconData.uid_DirName)
2761 FreeCopyString(uev->uev_Data.uev_IconData.uid_DirName);
2762 uev->uev_Data.uev_IconData.uid_DirName = NULL;
2764 if (uev->uev_Data.uev_IconData.uid_IconName)
2766 FreeCopyString(uev->uev_Data.uev_IconData.uid_IconName);
2767 uev->uev_Data.uev_IconData.uid_IconName = NULL;
2770 d1(kprintf("%s/%s/%ld: END uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2773 //----------------------------------------------------------------------------
2775 static SAVEDS(void) UndoDisposeCleanupData(struct Hook *hook, APTR object, struct UndoEvent *uev)
2777 (void) hook;
2778 (void) object;
2780 d1(kprintf("%s/%s/%ld: START uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2781 if (uev)
2783 struct UndoCleanupData *ucd = &uev->uev_Data.uev_CleanupData;
2785 if (ucd->ucd_WindowTitle)
2787 FreeCopyString(ucd->ucd_WindowTitle);
2788 ucd->ucd_WindowTitle = NULL;
2790 if (ucd->ucd_Icons)
2792 ScalosFree(ucd->ucd_Icons);
2793 ucd->ucd_Icons = NULL;
2796 d1(kprintf("%s/%s/%ld: END uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2799 //----------------------------------------------------------------------------
2801 static SAVEDS(void) UndoDisposeSnapshotData(struct Hook *hook, APTR object, struct UndoEvent *uev)
2803 (void) hook;
2804 (void) object;
2806 d1(kprintf("%s/%s/%ld: START uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2807 if (uev)
2809 struct UndoSnaphotIconData *usid = &uev->uev_Data.uev_SnapshotData;
2811 if (usid->usid_DirName)
2813 FreeCopyString(usid->usid_DirName);
2814 usid->usid_DirName = NULL;
2816 if (usid->usid_IconName)
2818 FreeCopyString(usid->usid_IconName);
2819 usid->usid_IconName = NULL;
2821 if (usid->usid_IconObj)
2823 DisposeIconObject(usid->usid_IconObj);
2824 usid->usid_IconObj = NULL;
2827 d1(kprintf("%s/%s/%ld: END uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2830 //----------------------------------------------------------------------------
2832 static SAVEDS(void) UndoDisposeSizeWindowData(struct Hook *hook, APTR object, struct UndoEvent *uev)
2834 (void) hook;
2835 (void) object;
2837 d1(kprintf("%s/%s/%ld: START uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2838 if (uev)
2840 struct UndoSizeWindowData *uswd = &uev->uev_Data.uev_SizeWindowData;
2842 if (uswd->uswd_WindowTitle)
2844 FreeCopyString(uswd->uswd_WindowTitle);
2845 uswd->uswd_WindowTitle = NULL;
2848 d1(kprintf("%s/%s/%ld: END uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2851 //----------------------------------------------------------------------------
2853 static SAVEDS(void) UndoDisposeSetProtectionData(struct Hook *hook, APTR object, struct UndoEvent *uev)
2855 (void) hook;
2856 (void) object;
2858 d1(kprintf("%s/%s/%ld: START uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2859 if (uev)
2861 struct UndoSetProtectionData *uspd = &uev->uev_Data.uev_SetProtectionData;
2863 if (uspd->uspd_DirName)
2865 FreeCopyString(uspd->uspd_DirName);
2866 uspd->uspd_DirName = NULL;
2868 if (uspd->uspd_IconName)
2870 FreeCopyString(uspd->uspd_IconName);
2871 uspd->uspd_IconName = NULL;
2874 d1(kprintf("%s/%s/%ld: END uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2877 //----------------------------------------------------------------------------
2879 static SAVEDS(void) UndoDisposeSetCommentData(struct Hook *hook, APTR object, struct UndoEvent *uev)
2881 (void) hook;
2882 (void) object;
2884 d1(kprintf("%s/%s/%ld: START uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2885 if (uev)
2887 struct UndoSetCommentData *uscd = &uev->uev_Data.uev_SetCommentData;
2889 if (uscd->uscd_DirName)
2891 FreeCopyString(uscd->uscd_DirName);
2892 uscd->uscd_DirName = NULL;
2894 if (uscd->uscd_IconName)
2896 FreeCopyString(uscd->uscd_IconName);
2897 uscd->uscd_IconName = NULL;
2899 if (uscd->uscd_OldComment)
2901 FreeCopyString(uscd->uscd_OldComment);
2902 uscd->uscd_OldComment = NULL;
2904 if (uscd->uscd_NewComment)
2906 FreeCopyString(uscd->uscd_NewComment);
2907 uscd->uscd_NewComment = NULL;
2910 d1(kprintf("%s/%s/%ld: END uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2913 //----------------------------------------------------------------------------
2915 static SAVEDS(void) UndoDisposeSetToolTypesData(struct Hook *hook, APTR object, struct UndoEvent *uev)
2917 (void) hook;
2918 (void) object;
2920 d1(kprintf("%s/%s/%ld: START uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2921 if (uev)
2923 struct UndoSetToolTypesData *ustd = &uev->uev_Data.uev_SetToolTypesData;
2925 if (ustd->ustd_DirName)
2927 FreeCopyString(ustd->ustd_DirName);
2928 ustd->ustd_DirName = NULL;
2930 if (ustd->ustd_IconName)
2932 FreeCopyString(ustd->ustd_IconName);
2933 ustd->ustd_IconName = NULL;
2935 if (ustd->ustd_OldToolTypes)
2937 ScalosFree(ustd->ustd_OldToolTypes);
2938 ustd->ustd_OldToolTypes = NULL;
2940 if (ustd->ustd_NewToolTypes)
2942 ScalosFree(ustd->ustd_NewToolTypes);
2943 ustd->ustd_NewToolTypes = NULL;
2946 d1(kprintf("%s/%s/%ld: END uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2949 //----------------------------------------------------------------------------
2951 static SAVEDS(void) UndoDisposeChangeIconObjectData(struct Hook *hook, APTR object, struct UndoEvent *uev)
2953 (void) hook;
2954 (void) object;
2956 d1(kprintf("%s/%s/%ld: START uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2957 if (uev)
2959 struct UndoChangeIconObjectData *uciod = &uev->uev_Data.uev_ChangeIconObjectData;
2961 if (uciod->uciod_DirName)
2963 FreeCopyString(uciod->uciod_DirName);
2964 uciod->uciod_DirName = NULL;
2966 if (uciod->uciod_IconName)
2968 FreeCopyString(uciod->uciod_IconName);
2969 uciod->uciod_IconName = NULL;
2971 if (uciod->uciod_OldIconObject)
2973 DisposeIconObject(uciod->uciod_OldIconObject);
2974 uciod->uciod_OldIconObject = NULL;
2976 if (uciod->uciod_NewIconObject)
2978 DisposeIconObject(uciod->uciod_NewIconObject);
2979 uciod->uciod_NewIconObject = NULL;
2982 d1(kprintf("%s/%s/%ld: END uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2985 //----------------------------------------------------------------------------
2987 static SAVEDS(void) UndoDisposeCloseWindowData(struct Hook *hook, APTR object, struct UndoEvent *uev)
2989 (void) hook;
2990 (void) object;
2992 d1(kprintf("%s/%s/%ld: START uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
2993 if (uev)
2995 struct UndoCloseWindowData *ucwd = &uev->uev_Data.uev_CloseWindowData;
2997 if (ucwd->ucwd_DirName)
2999 FreeCopyString(ucwd->ucwd_DirName);
3000 ucwd->ucwd_DirName = NULL;
3002 if (ucwd->ucwd_WindowTitle)
3004 FreeCopyString(ucwd->ucwd_WindowTitle);
3005 ucwd->ucwd_WindowTitle = NULL;
3008 d1(kprintf("%s/%s/%ld: END uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
3010 //----------------------------------------------------------------------------
3012 static SAVEDS(LONG) UndoCleanupEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
3014 struct internalScaWindowTask *iwt;
3015 BOOL Success = FALSE;
3017 (void) hook;
3018 (void) object;
3020 d1(kprintf("%s/%s/%ld: START uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
3022 do {
3023 struct ScaIconNode *in;
3025 d1(kprintf("%s/%s/%ld: ucd_IconCount=%lu\n", __FILE__, __FUNC__, __LINE__, uev->uev_Data.uev_CleanupData.ucd_IconCount));
3026 d1(kprintf("%s/%s/%ld: ucd_WindowTask=%08lx\n", __FILE__, __FUNC__, __LINE__, uev->uev_Data.uev_CleanupData.ucd_WindowTask));
3028 iwt = UndoFindWindowByWindowTask(uev->uev_Data.uev_CleanupData.ucd_WindowTask);
3029 if (NULL == iwt)
3030 break;
3032 ScalosLockIconListShared(iwt);
3034 if (iwt->iwt_WindowTask.wt_Window)
3036 EraseRect(iwt->iwt_WindowTask.wt_Window->RPort, 0, 0,
3037 iwt->iwt_WindowTask.wt_Window->Width - 1,
3038 iwt->iwt_WindowTask.wt_Window->Height -1);
3041 for (in = iwt->iwt_WindowTask.wt_IconList; in; in = (struct ScaIconNode *) in->in_Node.mln_Succ)
3043 const struct UndoCleanupIconEntry *ucie;
3045 ucie = UndoFindCleanupIconEntry(uev, in);
3046 if (ucie)
3048 LONG x0, y0;
3049 struct ExtGadget *gg = (struct ExtGadget *) in->in_Icon;
3051 d1(kprintf("%s/%s/%ld: in=%08lx <%s> Left=%ld Top=%ld\n", \
3052 __FILE__, __FUNC__, __LINE__, in, GetIconName(in), \
3053 ucie->ucin_Left, ucie->ucin_Top));
3055 // Adjust icon position
3056 x0 = gg->LeftEdge - gg->BoundsLeftEdge;
3058 gg->LeftEdge = ucie->ucin_Left;
3059 gg->BoundsLeftEdge = gg->LeftEdge - x0;
3061 y0 = gg->TopEdge - gg->BoundsTopEdge;
3063 gg->TopEdge = ucie->ucin_Top;
3064 gg->BoundsTopEdge = gg->TopEdge - y0;
3068 RefreshIconList(iwt, iwt->iwt_WindowTask.wt_IconList, NULL);
3070 DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_IconWin_SetVirtSize,
3071 SETVIRTF_AdjustBottomSlider | SETVIRTF_AdjustRightSlider);
3073 ScalosUnLockIconList(iwt);
3075 Success = TRUE;
3076 } while (0);
3078 if (iwt)
3079 SCA_UnLockWindowList();
3081 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__));
3083 return Success;
3086 //----------------------------------------------------------------------------
3088 static SAVEDS(LONG) RedoCleanupEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
3090 BOOL Success = FALSE;
3091 struct internalScaWindowTask *iwt;
3093 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3095 do {
3096 iwt = UndoFindWindowByWindowTask(uev->uev_Data.uev_CleanupData.ucd_WindowTask);
3097 if (NULL == iwt)
3098 break;
3100 switch (uev->uev_Data.uev_CleanupData.ucd_CleanupMode)
3102 case CLEANUP_ByName:
3103 DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_IconWin_CleanUpByName);
3104 break;
3105 case CLEANUP_ByDate:
3106 DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_IconWin_CleanUpByDate);
3107 break;
3108 case CLEANUP_BySize:
3109 DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_IconWin_CleanUpBySize);
3110 break;
3111 case CLEANUP_ByType:
3112 DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_IconWin_CleanUpByType);
3113 break;
3114 case CLEANUP_Default:
3115 default:
3116 //TODO
3117 break;
3119 } while (0);
3121 if (iwt)
3122 SCA_UnLockWindowList();
3124 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
3126 return Success;
3129 //----------------------------------------------------------------------------
3131 static const struct UndoCleanupIconEntry *UndoFindCleanupIconEntry(const struct UndoEvent *uev, const struct ScaIconNode *in)
3133 const struct UndoCleanupIconEntry *ucie = uev->uev_Data.uev_CleanupData.ucd_Icons;
3134 ULONG n;
3136 for (n = 0; n < uev->uev_Data.uev_CleanupData.ucd_IconCount; n++, ucie++)
3138 if (ucie->ucin_IconNode == in)
3139 return ucie;
3142 return NULL;
3145 //----------------------------------------------------------------------------
3147 static SAVEDS(LONG) UndoLeaveOutEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
3149 BOOL Success = FALSE;
3150 struct UndoSnaphotIconData *usid = &uev->uev_Data.uev_SnapshotData;
3151 struct internalScaWindowTask *iwt;
3152 BPTR oldDir = BNULL;
3153 STRPTR Path = NULL;
3155 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3157 do {
3158 BPTR iconDirLock;
3160 iwt = UndoFindWindowByDir(usid->usid_DirName);
3161 d1(kprintf("%s/%s/%ld: iwt=%08lx\n", __FILE__, __FUNC__, __LINE__, iwt));
3162 if (NULL == iwt)
3163 break;
3165 oldDir = CurrentDir(iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock);
3167 iconDirLock = DupLock(iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock);
3168 debugLock_d1(iconDirLock);
3169 if (BNULL == iconDirLock)
3170 break;
3172 // !!! side effects: UnLocks(iconDirLock) and frees <in> !!!
3173 PutAwayIcon((struct internalScaWindowTask *) iInfos.xii_iinfos.ii_MainWindowStruct->ws_WindowTask,
3174 iconDirLock, usid->usid_IconName, TRUE);
3176 // add icon to owning drawer window
3177 DoMethod(iwt->iwt_WindowTask.mt_MainObject,
3178 SCCM_IconWin_ReadIcon,
3179 usid->usid_IconName,
3180 NULL);
3182 // Special handling for "view all" textwindows.
3183 // here both object and icon are separate entries, which must be removed both!
3184 if (!IsIwtViewByIcon(iwt) && IsShowAll(iwt->iwt_WindowTask.mt_WindowStruct))
3186 Path = AllocPathBuffer();
3187 if (NULL == Path)
3188 break;
3190 stccpy(Path, usid->usid_IconName, Max_PathLen);
3191 SafeStrCat(Path, ".info", Max_PathLen);
3193 DoMethod(iwt->iwt_WindowTask.mt_MainObject,
3194 SCCM_IconWin_ReadIcon,
3195 Path,
3196 NULL);
3199 Success = TRUE;
3200 } while (0);
3202 if (oldDir)
3203 CurrentDir(oldDir);
3204 if (Path)
3205 FreePathBuffer(Path);
3206 if (iwt)
3207 SCA_UnLockWindowList();
3209 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
3211 return Success;
3214 //----------------------------------------------------------------------------
3216 static SAVEDS(LONG) RedoLeaveOutEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
3218 BOOL Success = FALSE;
3219 struct UndoSnaphotIconData *usid = &uev->uev_Data.uev_SnapshotData;
3220 struct internalScaWindowTask *iwt;
3222 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3224 do {
3225 BPTR iconDirLock;
3227 iwt = UndoFindWindowByDir(usid->usid_DirName);
3228 if (NULL == iwt)
3229 break;
3231 iconDirLock = DupLock(iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock);
3232 debugLock_d1(iconDirLock);
3233 if (BNULL == iconDirLock)
3234 break;
3236 DoLeaveOutIcon(iwt, iconDirLock, usid->usid_IconName,
3237 uev->uev_NewPosX, uev->uev_NewPosY);
3239 Success = TRUE;
3240 } while (0);
3242 if (iwt)
3243 SCA_UnLockWindowList();
3245 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
3247 return Success;
3250 //----------------------------------------------------------------------------
3252 static SAVEDS(LONG) UndoSnapshotEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
3254 struct internalScaWindowTask *iwt;
3255 struct ScaIconNode *in = NULL;
3256 BOOL Success = FALSE;
3258 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3260 do {
3261 struct UndoSnaphotIconData *usid = &uev->uev_Data.uev_SnapshotData;
3262 const struct IBox *pWinRect;
3263 ULONG IconViewMode;
3264 ULONG ddFlags;
3265 LONG WinCurrentX, WinCurrentY;
3267 if (!UndoFindWindowAndIcon(usid->usid_DirName, usid->usid_IconName, &iwt, &in))
3268 break;
3270 d1(kprintf("%s/%s/%ld: iwt=%08lx\n", __FILE__, __FUNC__, __LINE__, iwt));
3271 d1(kprintf("%s/%s/%ld: usid_IconName=<%s>\n", __FILE__, __FUNC__, __LINE__, usid->usid_IconName));
3272 d1(kprintf("%s/%s/%ld: in=%08lx <%s>\n", __FILE__, __FUNC__, __LINE__, in, GetIconName(in)));
3274 if (uev->uev_OldPosX != uev->uev_NewPosX || uev->uev_OldPosY != uev->uev_NewPosY)
3276 if (!MoveIconTo(usid->usid_DirName,
3277 usid->usid_IconName,
3278 uev->uev_OldPosX, uev->uev_OldPosY))
3279 break;
3282 GetAttr(IDTA_ViewModes, usid->usid_IconObj, &IconViewMode);
3283 GetAttr(IDTA_Flags, usid->usid_IconObj, &ddFlags);
3284 GetAttr(IDTA_WindowRect, usid->usid_IconObj, (ULONG *) &pWinRect);
3285 GetAttr(IDTA_WinCurrentX, usid->usid_IconObj, (ULONG *) &WinCurrentX);
3286 GetAttr(IDTA_WinCurrentY, usid->usid_IconObj, (ULONG *) &WinCurrentY);
3288 SetAttrs(in->in_Icon,
3289 IDTA_ViewModes, IconViewMode,
3290 IDTA_Flags, ddFlags,
3291 pWinRect ? IDTA_WindowRect : TAG_IGNORE, (ULONG) pWinRect,
3292 IDTA_WinCurrentY, WinCurrentY,
3293 IDTA_WinCurrentX, WinCurrentX,
3294 TAG_END);
3296 if (usid->usid_SaveIcon)
3298 ULONG Result;
3300 Result = SaveIconObject(usid->usid_IconObj,
3301 iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock,
3302 usid->usid_IconName,
3303 FALSE,
3304 NULL);
3306 if (RETURN_OK != Result)
3307 break;
3310 Success = TRUE;
3311 } while (0);
3313 if (iwt)
3315 if (in)
3316 ScalosUnLockIconList(iwt);
3317 SCA_UnLockWindowList();
3320 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
3322 return Success;
3325 //----------------------------------------------------------------------------
3327 static SAVEDS(LONG) RedoSnapshotPosEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
3329 struct internalScaWindowTask *iwt;
3330 struct ScaIconNode *in = NULL;
3331 BOOL Success = FALSE;
3333 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3335 do {
3336 struct UndoSnaphotIconData *usid = &uev->uev_Data.uev_SnapshotData;
3338 if (!UndoFindWindowAndIcon(usid->usid_DirName, usid->usid_IconName, &iwt, &in))
3339 break;
3341 d1(kprintf("%s/%s/%ld: iwt=%08lx\n", __FILE__, __FUNC__, __LINE__, iwt));
3342 d1(kprintf("%s/%s/%ld: usid_IconName=<%s>\n", __FILE__, __FUNC__, __LINE__, usid->usid_IconName));
3344 if (uev->uev_OldPosX != uev->uev_NewPosX || uev->uev_OldPosY != uev->uev_NewPosY)
3346 if (!MoveIconTo(usid->usid_DirName,
3347 usid->usid_IconName,
3348 uev->uev_NewPosX, uev->uev_NewPosY))
3349 break;
3352 SCA_LockWindowList(SCA_LockWindowList_Shared);
3354 if (UNDO_Snapshot == uev->uev_Type)
3355 Success = UndoSnapshotIcon(iwt, in);
3356 else
3358 struct ScaIconNode *IconList;
3360 SCA_MoveIconNode(&iwt->iwt_WindowTask.wt_IconList, &IconList, in);
3362 RemoveIcons(iwt, &IconList); // visibly remove icon from window
3364 Success = UndoUnsnapshotIcon(iwt, in, usid->usid_SaveIcon);
3366 SCA_MoveIconNode(&IconList, &iwt->iwt_WindowTask.wt_LateIconList, in);
3368 if (IsIwtViewByIcon(iwt))
3370 d1(KPrintF("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3371 DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_IconWin_CleanUp);
3372 d1(KPrintF("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3373 DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_IconWin_SetVirtSize,
3374 SETVIRTF_AdjustBottomSlider | SETVIRTF_AdjustRightSlider);
3378 SCA_UnLockWindowList();
3379 } while (0);
3381 if (iwt)
3383 if (in)
3384 ScalosUnLockIconList(iwt);
3385 SCA_UnLockWindowList();
3388 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
3390 return Success;
3393 //----------------------------------------------------------------------------
3395 static BOOL UndoSnapshotIcon(struct internalScaWindowTask *iwt, struct ScaIconNode *in)
3397 BOOL Success = FALSE;
3398 ULONG IconType = 0;
3400 d1(KPrintF("%s/%s/%ld: START iwt=%08lx in=%08lx <%s>\n", __FILE__, __FUNC__, __LINE__, iwt, in, GetIconName(in)));
3402 GetAttr(IDTA_Type, in->in_Icon, &IconType);
3404 if (0 == IconType)
3405 return Success;
3407 if (WBAPPICON == IconType)
3409 WindowSendAppIconMsg(iwt, AMCLASSICON_Snapshot, in);
3410 return TRUE;
3412 else
3414 BPTR destDirLock;
3416 SetIconWindowRect(in);
3418 if (in->in_DeviceIcon)
3420 destDirLock = DiskInfoLock(in);
3422 if (destDirLock)
3424 LONG Result;
3426 Result = ScalosPutIcon(in, destDirLock, in->in_Flags & INF_DefaultIcon);
3428 if (RETURN_OK == Result)
3429 Success = TRUE;
3431 UnLock(destDirLock);
3434 else
3436 LONG Result;
3438 if (in->in_Lock)
3439 destDirLock = in->in_Lock;
3440 else
3441 destDirLock = iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock;
3443 Result = ScalosPutIcon(in, destDirLock, in->in_Flags & INF_DefaultIcon);
3445 if (RETURN_OK == Result)
3446 Success = TRUE;
3449 in->in_Flags &= ~INF_FreeIconPosition;
3450 in->in_SupportFlags &= ~INF_SupportsSnapshot;
3451 in->in_SupportFlags |= INF_SupportsUnSnapshot;
3454 d1(KPrintF("%s/%s/%ld: END in=%08lx <%s> inFlags=%08lx Success=%ld\n", __FILE__, __FUNC__, __LINE__, in, GetIconName(in), in->in_Flags, Success));
3456 return Success;
3459 //----------------------------------------------------------------------------
3461 static BOOL UndoUnsnapshotIcon(struct internalScaWindowTask *iwt,
3462 struct ScaIconNode *in, BOOL SaveIcon)
3464 BOOL Success = FALSE;
3465 ULONG IconType = 0;
3467 d1(KPrintF("%s/%s/%ld: iwt=%08lx in=%08lx <%s>\n", __FILE__, __FUNC__, __LINE__, iwt, in, GetIconName(in)));
3469 GetAttr(IDTA_Type, in->in_Icon, &IconType);
3471 if (0 == IconType)
3472 return Success;
3474 if (WBAPPICON == IconType)
3476 WindowSendAppIconMsg(iwt, AMCLASSICON_UnSnapshot, in);
3477 return TRUE;
3479 else
3481 struct ExtGadget *gg = (struct ExtGadget *) in->in_Icon;
3482 BPTR destDirLock;
3483 WORD LeftEdge, TopEdge;
3485 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3487 SetIconWindowRect(in);
3489 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3491 LeftEdge = gg->LeftEdge;
3492 TopEdge = gg->TopEdge;
3494 if (in->in_DeviceIcon)
3496 destDirLock = DiskInfoLock(in);
3498 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3500 if (destDirLock)
3503 gg->LeftEdge = gg->TopEdge = NO_ICON_POSITION_SHORT;
3505 if (SaveIcon)
3507 LONG Result;
3509 Result = ScalosPutIcon(in, destDirLock, in->in_Flags & INF_DefaultIcon);
3511 if (RETURN_OK == Result)
3512 Success = TRUE;
3514 else
3516 Success = TRUE;
3519 UnLock(destDirLock);
3522 else
3524 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3526 if (in->in_Lock)
3527 destDirLock = in->in_Lock;
3528 else
3529 destDirLock = iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock;
3531 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3533 gg->LeftEdge = gg->TopEdge = NO_ICON_POSITION_SHORT;
3535 if (SaveIcon)
3537 LONG Result;
3539 Result = ScalosPutIcon(in, destDirLock, in->in_Flags & INF_DefaultIcon);
3541 if (RETURN_OK == Result)
3542 Success = TRUE;
3544 else
3546 Success = TRUE;
3549 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3552 gg->LeftEdge = LeftEdge;
3553 gg->TopEdge = TopEdge;
3555 in->in_Flags |= INF_FreeIconPosition;
3556 in->in_SupportFlags |= INF_SupportsSnapshot;
3557 in->in_SupportFlags &= ~INF_SupportsUnSnapshot;
3560 d1(KPrintF("%s/%s/%ld: END in=%08lx <%s> inFlags=%08lx Success=%ld\n", __FILE__, __FUNC__, __LINE__, in, GetIconName(in), in->in_Flags, Success));
3562 return Success;
3565 //----------------------------------------------------------------------------
3567 static SAVEDS(LONG) UndoRenameEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
3569 BPTR srcDirLock;
3570 BOOL Success = FALSE;
3571 STRPTR destIconName = NULL;
3572 STRPTR srcIconName = NULL;
3574 (void) hook;
3575 (void) object;
3577 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
3579 do {
3580 struct UndoCopyMoveEventData *ucmed = &uev->uev_Data.uev_CopyMoveData;
3581 BPTR oldDir;
3583 d1(kprintf("%s/%s/%ld: ucmed_srcDirName=<%s>\n", __FILE__, __FUNC__, __LINE__, ucmed->ucmed_srcDirName));
3585 srcDirLock = Lock(ucmed->ucmed_srcDirName, ACCESS_READ);
3586 if (BNULL == srcDirLock)
3587 break;
3589 debugLock_d1(srcDirLock);
3591 destIconName = UndoBuildIconName(ucmed->ucmed_destName);
3592 if (NULL == destIconName)
3593 break;
3595 srcIconName = UndoBuildIconName(ucmed->ucmed_srcName);
3596 if (NULL == srcIconName)
3597 break;
3599 d1(kprintf("%s/%s/%ld: ucmed_srcName=<%s>\n", __FILE__, __FUNC__, __LINE__, ucmed->ucmed_srcName));
3600 d1(kprintf("%s/%s/%ld: ucmed_destName=<%s>\n", __FILE__, __FUNC__, __LINE__, ucmed->ucmed_destName));
3602 oldDir = CurrentDir(srcDirLock);
3604 Success = Rename(ucmed->ucmed_destName, ucmed->ucmed_srcName);
3606 CurrentDir(oldDir);
3608 if (!Success)
3609 break;
3611 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3613 // Try to also rename icon
3614 oldDir = CurrentDir(srcDirLock);
3615 (void) Rename(destIconName, srcIconName);
3616 CurrentDir(oldDir);
3617 } while (0);
3619 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3621 if (BNULL != srcDirLock)
3622 UnLock(srcDirLock);
3623 if (srcIconName)
3624 FreePathBuffer(srcIconName);
3625 if (destIconName)
3626 FreePathBuffer(destIconName);
3628 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
3630 return Success;
3633 //----------------------------------------------------------------------------
3635 static SAVEDS(LONG) RedoRenameEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
3637 BPTR srcDirLock;
3638 BOOL Success = FALSE;
3639 STRPTR destIconName = NULL;
3640 STRPTR srcIconName = NULL;
3642 (void) hook;
3643 (void) object;
3645 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
3647 do {
3648 struct UndoCopyMoveEventData *ucmed = &uev->uev_Data.uev_CopyMoveData;
3649 BPTR oldDir;
3651 d1(kprintf("%s/%s/%ld: ucmed_srcDirName=<%s>\n", __FILE__, __FUNC__, __LINE__, ucmed->ucmed_srcDirName));
3653 srcDirLock = Lock(ucmed->ucmed_srcDirName, ACCESS_READ);
3654 if (BNULL == srcDirLock)
3655 break;
3657 debugLock_d1(srcDirLock);
3659 destIconName = UndoBuildIconName(ucmed->ucmed_destName);
3660 if (NULL == destIconName)
3661 break;
3663 srcIconName = UndoBuildIconName(ucmed->ucmed_srcName);
3664 if (NULL == srcIconName)
3665 break;
3667 d1(kprintf("%s/%s/%ld: .ucmed_srcName=<%s>\n", __FILE__, __FUNC__, __LINE__, ucmed->ucmed_srcName));
3668 d1(kprintf("%s/%s/%ld: .ucmed_destName=<%s>\n", __FILE__, __FUNC__, __LINE__, ucmed->ucmed_destName));
3670 oldDir = CurrentDir(srcDirLock);
3672 Success = Rename(ucmed->ucmed_srcName, ucmed->ucmed_destName);
3674 CurrentDir(oldDir);
3676 if (!Success)
3677 break;
3679 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3681 // Try to also rename icon
3682 oldDir = CurrentDir(srcDirLock);
3683 (void) Rename(srcIconName, destIconName);
3684 CurrentDir(oldDir);
3685 } while (0);
3687 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3689 if (BNULL != srcDirLock)
3690 UnLock(srcDirLock);
3691 if (srcIconName)
3692 FreePathBuffer(srcIconName);
3693 if (destIconName)
3694 FreePathBuffer(destIconName);
3696 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
3698 return Success;
3701 //----------------------------------------------------------------------------
3703 static SAVEDS(LONG) UndoRelabelEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
3705 BOOL Success = FALSE;
3706 STRPTR newName = NULL;
3707 STRPTR driveName;
3709 (void) hook;
3710 (void) object;
3712 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
3714 do {
3715 struct UndoCopyMoveEventData *ucmed = &uev->uev_Data.uev_CopyMoveData;
3717 driveName = AllocPathBuffer();
3718 if (NULL == driveName)
3719 break;
3721 newName = AllocPathBuffer();
3722 if (NULL == newName)
3723 break;
3725 stccpy(driveName, ucmed->ucmed_destName, Max_PathLen);
3726 SafeStrCat(driveName, ":", Max_PathLen);
3728 stccpy(newName, ucmed->ucmed_srcName, Max_PathLen);
3729 StripTrailingColon(newName);
3731 Success = Relabel(driveName, newName);
3732 } while (0);
3734 if (driveName)
3735 FreePathBuffer(driveName);
3736 if (newName)
3737 FreePathBuffer(newName);
3739 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
3741 return Success;
3744 //----------------------------------------------------------------------------
3746 static SAVEDS(LONG) RedoRelabelEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
3748 BOOL Success;
3750 (void) hook;
3751 (void) object;
3753 d1(kprintf("%s/%s/%ld: START uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
3755 do {
3756 struct UndoCopyMoveEventData *ucmed = &uev->uev_Data.uev_CopyMoveData;
3758 Success = Relabel(ucmed->ucmed_srcName, ucmed->ucmed_destName);
3759 } while (0);
3761 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
3763 return Success;
3766 //----------------------------------------------------------------------------
3768 static SAVEDS(LONG) UndoSizeWindowEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
3770 struct internalScaWindowTask *iwt;
3771 BOOL Success = FALSE;
3773 (void) hook;
3774 (void) object;
3776 d1(kprintf("%s/%s/%ld: START uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
3778 do {
3779 struct UndoSizeWindowData *uswd = &uev->uev_Data.uev_SizeWindowData;
3781 d1(kprintf("%s/%s/%ld: ucd_WindowTask=%08lx\n", __FILE__, __FUNC__, __LINE__, uev->uev_Data.uev_CleanupData.ucd_WindowTask));
3783 iwt = UndoFindWindowByWindowTask(uswd->uswd_WindowTask);
3784 if (NULL == iwt)
3785 break;
3787 ScalosObtainSemaphoreShared(iwt->iwt_WindowTask.wt_WindowSemaphore);
3789 d1(kprintf("%s/%s/%ld: XOffset=%ld YOffset=%ld\n", __FILE__, __FUNC__, __LINE__, \
3790 iwt->iwt_WindowTask.wt_XOffset, iwt->iwt_WindowTask.wt_YOffset));
3792 DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_IconWin_DeltaMove,
3793 uswd->uswd_OldVirtX - iwt->iwt_WindowTask.wt_XOffset,
3794 uswd->uswd_OldVirtY - iwt->iwt_WindowTask.wt_YOffset);
3796 d1(KPrintF("%s/%s/%ld: Left=%ld Top=%ld Width=%ld Height=%ld\n", __FILE__, __FUNC__, __LINE__, \
3797 uswd->uswd_OldLeft, uswd->uswd_OldTop, \
3798 uswd->uswd_OldWidth, uswd->uswd_OldHeight));
3800 if (iwt->iwt_WindowTask.wt_Window)
3802 ChangeWindowBox(iwt->iwt_WindowTask.wt_Window,
3803 uswd->uswd_OldLeft,
3804 uswd->uswd_OldTop,
3805 uswd->uswd_OldWidth,
3806 uswd->uswd_OldHeight);
3809 ScalosReleaseSemaphore(iwt->iwt_WindowTask.wt_WindowSemaphore);
3811 Success = TRUE;
3812 } while (0);
3814 if (iwt)
3815 SCA_UnLockWindowList();
3817 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
3819 return Success;
3822 //----------------------------------------------------------------------------
3824 static SAVEDS(LONG) RedoSizeWindowEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
3826 struct internalScaWindowTask *iwt;
3827 BOOL Success = FALSE;
3829 (void) hook;
3830 (void) object;
3832 d1(kprintf("%s/%s/%ld: START uev=%08lx\n", __FILE__, __FUNC__, __LINE__, uev));
3834 do {
3835 struct UndoSizeWindowData *uswd = &uev->uev_Data.uev_SizeWindowData;
3837 d1(kprintf("%s/%s/%ld: ucd_WindowTask=%08lx\n", __FILE__, __FUNC__, __LINE__, uev->uev_Data.uev_CleanupData.ucd_WindowTask));
3839 iwt = UndoFindWindowByWindowTask(uswd->uswd_WindowTask);
3840 if (NULL == iwt)
3841 break;
3843 ScalosObtainSemaphoreShared(iwt->iwt_WindowTask.wt_WindowSemaphore);
3845 d1(kprintf("%s/%s/%ld: XOffset=%ld YOffset=%ld\n", __FILE__, __FUNC__, __LINE__, \
3846 iwt->iwt_WindowTask.wt_XOffset, iwt->iwt_WindowTask.wt_YOffset));
3848 DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_IconWin_DeltaMove,
3849 uswd->uswd_NewVirtX - iwt->iwt_WindowTask.wt_XOffset,
3850 uswd->uswd_NewVirtY - iwt->iwt_WindowTask.wt_YOffset);
3852 d1(KPrintF("%s/%s/%ld: Left=%ld Top=%ld Width=%ld Height=%ld\n", __FILE__, __FUNC__, __LINE__, \
3853 uswd->uswd_NewLeft, uswd->uswd_NewTop, \
3854 uswd->uswd_NewWidth, uswd->uswd_NewHeight));
3856 if (iwt->iwt_WindowTask.wt_Window)
3858 ChangeWindowBox(iwt->iwt_WindowTask.wt_Window,
3859 uswd->uswd_NewLeft,
3860 uswd->uswd_NewTop,
3861 uswd->uswd_NewWidth,
3862 uswd->uswd_NewHeight);
3865 ScalosReleaseSemaphore(iwt->iwt_WindowTask.wt_WindowSemaphore);
3867 Success = TRUE;
3868 } while (0);
3870 if (iwt)
3871 SCA_UnLockWindowList();
3873 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
3875 return Success;
3878 //----------------------------------------------------------------------------
3880 static SAVEDS(LONG) UndoNewDrawerEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
3882 BOOL Success = FALSE;
3883 BPTR srcDirLock;
3884 STRPTR iconName = NULL;
3886 (void) hook;
3887 (void) object;
3889 d1(kprintf("%s/%s/%ld:\n", __FILE__, __FUNC__, __LINE__));
3891 do {
3892 struct UndoNewDrawerData *und = &uev->uev_Data.uev_NewDrawerData;
3893 LONG Result;
3895 srcDirLock = Lock(und->und_DirName, ACCESS_READ);
3896 d1(kprintf("%s/%s/%ld: srcDirLock=%08lx <%s>\n", __FILE__, __FUNC__, __LINE__, srcDirLock, und->und_DirName));
3897 if (BNULL == srcDirLock)
3898 break;
3900 if (0 == strlen(und->und_srcName))
3901 break;
3903 Result = DoMethod(uev->uev_UndoStep->ust_FileTransObj,
3904 SCCM_FileTrans_Delete,
3905 srcDirLock, und->und_srcName);
3907 if (RETURN_OK != Result)
3908 break; // SCCM_FileTrans_Delete failed
3910 if (und->und_CreateIcon)
3912 CONST_STRPTR iconExt = ".info";
3914 iconName = ScalosAlloc(1 + strlen(und->und_srcName) + strlen(iconExt));
3915 if (NULL == iconName)
3916 break;
3918 strcpy(iconName, und->und_srcName);
3919 strcat(iconName, iconExt);
3921 Result = DoMethod(uev->uev_UndoStep->ust_FileTransObj,
3922 SCCM_FileTrans_Delete,
3923 srcDirLock, iconName);
3925 if (RETURN_OK != Result)
3926 break; // SCCM_FileTrans_Delete failed
3929 Success = TRUE;
3930 } while (0);
3932 if (BNULL != srcDirLock)
3933 UnLock(srcDirLock);
3934 if (iconName)
3935 ScalosFree(iconName);
3937 return Success;
3940 //----------------------------------------------------------------------------
3942 static SAVEDS(LONG) RedoNewDrawerEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
3944 BOOL Success = FALSE;
3945 BPTR srcDirLock;
3946 BPTR newDirLock = BNULL;
3947 Object *IconObj = NULL;
3948 BPTR oldDir = BNULL;
3950 (void) hook;
3951 (void) object;
3953 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
3955 do {
3956 struct UndoNewDrawerData *und = &uev->uev_Data.uev_NewDrawerData;
3958 srcDirLock = Lock(und->und_DirName, ACCESS_READ);
3959 if (BNULL == srcDirLock)
3960 break;
3962 oldDir = CurrentDir(srcDirLock);
3964 newDirLock = CreateDir(und->und_srcName);
3965 debugLock_d1(newDirLock);
3966 if (BNULL == newDirLock)
3967 break;
3969 if (und->und_CreateIcon)
3971 LONG rc;
3972 struct ScaUpdateIcon_IW upd;
3974 IconObj = GetDefIconObject(WBDRAWER, NULL);
3976 d1(kprintf(__FILE__ "/%s/%ld: IconObj=%08lx\n", __FUNC__, __LINE__, IconObj));
3978 if (NULL == IconObj)
3979 break;
3981 upd.ui_iw_Lock = srcDirLock;
3982 upd.ui_iw_Name = und->und_srcName;
3983 upd.ui_IconType = ICONTYPE_NONE;
3985 rc = PutIconObjectTags(IconObj, und->und_srcName,
3986 TAG_END);
3987 d1(kprintf(__FILE__ "/%s/%ld: PutIconObjectTags returned rc=%ld\n", __FUNC__, __LINE__, rc));
3988 if (RETURN_OK != rc)
3989 break;
3991 SCA_UpdateIcon(WSV_Type_IconWindow, &upd, sizeof(upd));
3994 Success = TRUE;
3995 } while (0);
3997 if (oldDir)
3998 CurrentDir(oldDir);
3999 if (IconObj)
4000 DisposeIconObject(IconObj);
4001 if (BNULL != srcDirLock)
4002 UnLock(srcDirLock);
4003 if (BNULL != newDirLock)
4004 UnLock(newDirLock);
4006 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
4008 return Success;
4011 //----------------------------------------------------------------------------
4013 static SAVEDS(LONG) UndoSetProtectionEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
4015 BOOL Success = FALSE;
4016 BPTR dirLock;
4017 BPTR oldDir = BNULL;
4019 (void) hook;
4020 (void) object;
4022 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
4024 do {
4025 struct UndoSetProtectionData *uspd = &uev->uev_Data.uev_SetProtectionData;
4026 struct ScaUpdateIcon_IW upd;
4028 dirLock = Lock(uspd->uspd_DirName, ACCESS_READ);
4029 debugLock_d1(dirLock);
4030 if (BNULL == dirLock)
4031 break;
4033 oldDir = CurrentDir(dirLock);
4035 upd.ui_iw_Lock = dirLock;
4036 upd.ui_iw_Name = uspd->uspd_IconName;
4037 upd.ui_IconType = ICONTYPE_NONE;
4039 Success = SetProtection(uspd->uspd_IconName, uspd->uspd_OldProtection);
4041 if (Success)
4042 SCA_UpdateIcon(WSV_Type_IconWindow, &upd, sizeof(upd));
4043 } while (0);
4045 if (oldDir)
4046 CurrentDir(oldDir);
4047 if (BNULL != dirLock)
4048 UnLock(dirLock);
4050 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
4052 return Success;
4055 //----------------------------------------------------------------------------
4057 static SAVEDS(LONG) RedoSetProtectionEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
4059 BOOL Success = FALSE;
4060 BPTR dirLock;
4061 BPTR oldDir = BNULL;
4063 (void) hook;
4064 (void) object;
4066 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
4068 do {
4069 struct UndoSetProtectionData *uspd = &uev->uev_Data.uev_SetProtectionData;
4070 struct ScaUpdateIcon_IW upd;
4072 dirLock = Lock(uspd->uspd_DirName, ACCESS_READ);
4073 debugLock_d1(dirLock);
4074 if (BNULL == dirLock)
4075 break;
4077 oldDir = CurrentDir(dirLock);
4079 upd.ui_iw_Lock = dirLock;
4080 upd.ui_iw_Name = uspd->uspd_IconName;
4081 upd.ui_IconType = ICONTYPE_NONE;
4083 Success = SetProtection(uspd->uspd_IconName, uspd->uspd_OldProtection);
4085 if (Success)
4086 SCA_UpdateIcon(WSV_Type_IconWindow, &upd, sizeof(upd));
4087 } while (0);
4089 if (oldDir)
4090 CurrentDir(oldDir);
4091 if (BNULL != dirLock)
4092 UnLock(dirLock);
4094 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
4096 return Success;
4099 //----------------------------------------------------------------------------
4101 static SAVEDS(LONG) UndoSetCommentEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
4103 BOOL Success = FALSE;
4104 BPTR dirLock;
4105 BPTR oldDir = BNULL;
4107 (void) hook;
4108 (void) object;
4110 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
4112 do {
4113 struct UndoSetCommentData *uscd = &uev->uev_Data.uev_SetCommentData;
4114 struct ScaUpdateIcon_IW upd;
4116 dirLock = Lock(uscd->uscd_DirName, ACCESS_READ);
4117 debugLock_d1(dirLock);
4118 if (BNULL == dirLock)
4119 break;
4121 oldDir = CurrentDir(dirLock);
4123 upd.ui_iw_Lock = dirLock;
4124 upd.ui_iw_Name = uscd->uscd_IconName;
4125 upd.ui_IconType = ICONTYPE_NONE;
4127 Success = SetComment(uscd->uscd_IconName, uscd->uscd_OldComment);
4129 if (Success)
4130 SCA_UpdateIcon(WSV_Type_IconWindow, &upd, sizeof(upd));
4131 } while (0);
4133 if (oldDir)
4134 CurrentDir(oldDir);
4135 if (BNULL != dirLock)
4136 UnLock(dirLock);
4138 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
4140 return Success;
4143 //----------------------------------------------------------------------------
4145 static SAVEDS(LONG) RedoSetCommentEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
4147 BOOL Success = FALSE;
4148 BPTR dirLock;
4149 BPTR oldDir = BNULL;
4151 (void) hook;
4152 (void) object;
4154 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
4156 do {
4157 struct UndoSetCommentData *uscd = &uev->uev_Data.uev_SetCommentData;
4158 struct ScaUpdateIcon_IW upd;
4160 dirLock = Lock(uscd->uscd_DirName, ACCESS_READ);
4161 debugLock_d1(dirLock);
4162 if (BNULL == dirLock)
4163 break;
4165 oldDir = CurrentDir(dirLock);
4167 upd.ui_iw_Lock = dirLock;
4168 upd.ui_iw_Name = uscd->uscd_IconName;
4169 upd.ui_IconType = ICONTYPE_NONE;
4171 Success = SetComment(uscd->uscd_IconName, uscd->uscd_NewComment);
4173 if (Success)
4174 SCA_UpdateIcon(WSV_Type_IconWindow, &upd, sizeof(upd));
4175 } while (0);
4177 if (oldDir)
4178 CurrentDir(oldDir);
4179 if (BNULL != dirLock)
4180 UnLock(dirLock);
4182 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
4184 return Success;
4187 //----------------------------------------------------------------------------
4189 static SAVEDS(LONG) UndoSetToolTypesEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
4191 BOOL Success = FALSE;
4192 BPTR dirLock;
4193 BPTR oldDir = BNULL;
4194 struct internalScaWindowTask *iwt = NULL;
4195 struct ScaIconNode *in = NULL;
4197 (void) hook;
4198 (void) object;
4200 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
4202 do {
4203 struct UndoSetToolTypesData *ustd = &uev->uev_Data.uev_SetToolTypesData;
4204 struct ScaUpdateIcon_IW upd;
4205 LONG rc;
4207 dirLock = Lock(ustd->ustd_DirName, ACCESS_READ);
4208 debugLock_d1(dirLock);
4209 if (BNULL == dirLock)
4210 break;
4212 oldDir = CurrentDir(dirLock);
4214 if (!UndoFindWindowAndIcon(ustd->ustd_DirName, ustd->ustd_IconName, &iwt, &in))
4215 break;
4217 upd.ui_iw_Lock = dirLock;
4218 upd.ui_iw_Name = ustd->ustd_IconName;
4219 upd.ui_IconType = ICONTYPE_NONE;
4221 SetAttrs(in->in_Icon,
4222 IDTA_ToolTypes, (ULONG) ustd->ustd_OldToolTypes,
4223 TAG_END);
4225 rc = PutIconObjectTags(in->in_Icon, ustd->ustd_IconName,
4226 ICONA_NoNewImage, TRUE,
4227 TAG_END);
4228 d1(kprintf(__FILE__ "/%s/%ld: PutIconObjectTags returned rc=%ld\n", __FUNC__, __LINE__, rc));
4229 if (RETURN_OK != rc)
4230 break;
4232 SCA_UpdateIcon(WSV_Type_IconWindow, &upd, sizeof(upd));
4234 Success = TRUE;
4235 } while (0);
4237 if (iwt)
4239 if (in)
4240 ScalosUnLockIconList(iwt);
4241 SCA_UnLockWindowList();
4243 if (oldDir)
4244 CurrentDir(oldDir);
4245 if (BNULL != dirLock)
4246 UnLock(dirLock);
4248 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
4250 return Success;
4253 //----------------------------------------------------------------------------
4255 static SAVEDS(LONG) RedoSetToolTypesEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
4257 BOOL Success = FALSE;
4258 BPTR dirLock;
4259 BPTR oldDir = BNULL;
4260 struct internalScaWindowTask *iwt = NULL;
4261 struct ScaIconNode *in = NULL;
4263 (void) hook;
4264 (void) object;
4266 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
4268 do {
4269 struct UndoSetToolTypesData *ustd = &uev->uev_Data.uev_SetToolTypesData;
4270 struct ScaUpdateIcon_IW upd;
4271 LONG rc;
4273 dirLock = Lock(ustd->ustd_DirName, ACCESS_READ);
4274 debugLock_d1(dirLock);
4275 if (BNULL == dirLock)
4276 break;
4278 oldDir = CurrentDir(dirLock);
4280 if (!UndoFindWindowAndIcon(ustd->ustd_DirName, ustd->ustd_IconName, &iwt, &in))
4281 break;
4283 upd.ui_iw_Lock = dirLock;
4284 upd.ui_iw_Name = ustd->ustd_IconName;
4285 upd.ui_IconType = ICONTYPE_NONE;
4287 SetAttrs(in->in_Icon,
4288 IDTA_ToolTypes, (ULONG) ustd->ustd_OldToolTypes,
4289 TAG_END);
4291 rc = PutIconObjectTags(in->in_Icon, ustd->ustd_IconName,
4292 ICONA_NoNewImage, TRUE,
4293 TAG_END);
4294 d1(kprintf(__FILE__ "/%s/%ld: PutIconObjectTags returned rc=%ld\n", __FUNC__, __LINE__, rc));
4295 if (RETURN_OK != rc)
4296 break;
4298 SCA_UpdateIcon(WSV_Type_IconWindow, &upd, sizeof(upd));
4300 Success = TRUE;
4301 } while (0);
4303 if (iwt)
4305 if (in)
4306 ScalosUnLockIconList(iwt);
4307 SCA_UnLockWindowList();
4309 if (oldDir)
4310 CurrentDir(oldDir);
4311 if (BNULL != dirLock)
4312 UnLock(dirLock);
4314 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
4316 return Success;
4319 //----------------------------------------------------------------------------
4321 static SAVEDS(LONG) UndoChangeIconObjectEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
4323 BOOL Success = FALSE;
4324 BPTR dirLock;
4325 BPTR oldDir = BNULL;
4327 (void) hook;
4328 (void) object;
4330 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
4332 do {
4333 struct UndoChangeIconObjectData *uciod = &uev->uev_Data.uev_ChangeIconObjectData;
4334 struct ScaUpdateIcon_IW upd;
4335 LONG rc;
4337 dirLock = Lock(uciod->uciod_DirName, ACCESS_READ);
4338 debugLock_d1(dirLock);
4339 if (BNULL == dirLock)
4340 break;
4342 oldDir = CurrentDir(dirLock);
4344 upd.ui_iw_Lock = dirLock;
4345 upd.ui_iw_Name = uciod->uciod_IconName;
4346 upd.ui_IconType = ICONTYPE_NONE;
4348 rc = PutIconObjectTags(uciod->uciod_OldIconObject, uciod->uciod_IconName,
4349 TAG_END);
4350 d1(kprintf(__FILE__ "/%s/%ld: PutIconObjectTags returned rc=%ld\n", __FUNC__, __LINE__, rc));
4351 if (RETURN_OK != rc)
4352 break;
4354 SCA_UpdateIcon(WSV_Type_IconWindow, &upd, sizeof(upd));
4356 Success = TRUE;
4357 } while (0);
4359 if (oldDir)
4360 CurrentDir(oldDir);
4361 if (BNULL != dirLock)
4362 UnLock(dirLock);
4364 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
4366 return Success;
4369 //----------------------------------------------------------------------------
4371 static SAVEDS(LONG) RedoChangeIconObjectEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
4373 BOOL Success = FALSE;
4374 BPTR dirLock;
4375 BPTR oldDir = BNULL;
4377 (void) hook;
4378 (void) object;
4380 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
4382 do {
4383 struct UndoChangeIconObjectData *uciod = &uev->uev_Data.uev_ChangeIconObjectData;
4384 struct ScaUpdateIcon_IW upd;
4385 LONG rc;
4387 dirLock = Lock(uciod->uciod_DirName, ACCESS_READ);
4388 debugLock_d1(dirLock);
4389 if (BNULL == dirLock)
4390 break;
4392 oldDir = CurrentDir(dirLock);
4394 upd.ui_iw_Lock = dirLock;
4395 upd.ui_iw_Name = uciod->uciod_IconName;
4396 upd.ui_IconType = ICONTYPE_NONE;
4398 rc = PutIconObjectTags(uciod->uciod_NewIconObject, uciod->uciod_IconName,
4399 TAG_END);
4400 d1(kprintf(__FILE__ "/%s/%ld: PutIconObjectTags returned rc=%ld\n", __FUNC__, __LINE__, rc));
4401 if (RETURN_OK != rc)
4402 break;
4404 SCA_UpdateIcon(WSV_Type_IconWindow, &upd, sizeof(upd));
4406 Success = TRUE;
4407 } while (0);
4409 if (oldDir)
4410 CurrentDir(oldDir);
4411 if (BNULL != dirLock)
4412 UnLock(dirLock);
4414 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
4416 return Success;
4419 //----------------------------------------------------------------------------
4421 static SAVEDS(LONG) UndoCloseWindowEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
4423 BOOL Success;
4425 (void) hook;
4426 (void) object;
4428 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
4430 do {
4431 struct UndoCloseWindowData *ucwd = &uev->uev_Data.uev_CloseWindowData;
4432 struct IBox WindowBox;
4434 WindowBox.Left = ucwd->ucwd_Left;
4435 WindowBox.Top = ucwd->ucwd_Top;
4436 WindowBox.Width = ucwd->ucwd_Width;
4437 WindowBox.Height = ucwd->ucwd_Height;
4439 Success = SCA_OpenIconWindowTags(
4440 SCA_Path, (ULONG) ucwd->ucwd_DirName,
4441 SCA_WindowRect, (ULONG) &WindowBox,
4442 SCA_ViewModes, ucwd->ucwd_Viewmodes,
4443 SCA_ShowAllMode, ucwd->ucwd_ViewAll,
4444 SCA_XOffset, ucwd->ucwd_VirtX,
4445 SCA_YOffset, ucwd->ucwd_VirtY,
4446 TAG_END);
4447 } while (0);
4449 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
4451 return Success;
4454 //----------------------------------------------------------------------------
4456 static SAVEDS(LONG) RedoCloseWindowEvent(struct Hook *hook, APTR object, struct UndoEvent *uev)
4458 BOOL Success = FALSE;
4460 (void) hook;
4461 (void) object;
4463 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
4465 do {
4466 struct UndoCloseWindowData *ucwd = &uev->uev_Data.uev_CloseWindowData;
4467 struct internalScaWindowTask *iwt;
4469 iwt = UndoFindWindowByDir(ucwd->ucwd_DirName);
4470 if (NULL == iwt)
4471 break;
4473 iwt->iwt_CloseWindow = TRUE;
4475 SCA_UnLockWindowList();
4477 Success = TRUE;
4478 } while (0);
4480 d1(kprintf("%s/%s/%ld: END Success=%ld\n", __FILE__, __FUNC__, __LINE__, Success));
4482 return Success;
4485 //----------------------------------------------------------------------------
4487 // If window <iwt> is about to close, walk through Undo list
4488 // and remove all entries which refer to the opening window
4489 void UndoWindowSignalOpening(struct internalScaWindowTask *iwt)
4491 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
4493 if (iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock)
4495 struct UndoStep *ust;
4497 ScalosObtainSemaphore(&UndoListListSemaphore);
4499 for (ust = (struct UndoStep *) globalUndoList.lh_Head;
4500 ust != (struct UndoStep *) &globalUndoList.lh_Tail; )
4502 struct UndoStep *ustNext = (struct UndoStep *) ust->ust_Node.ln_Succ;
4503 BOOL Found = FALSE;
4504 struct UndoEvent *uev;
4506 d1(kprintf("%s/%s/%ld: ust=%08lx \n", __FILE__, __FUNC__, __LINE__, ust));
4508 for (uev = (struct UndoEvent *) ust->ust_EventList.lh_Head;
4509 uev != (struct UndoEvent *) &ust->ust_EventList.lh_Tail;
4510 uev = (struct UndoEvent *) uev->uev_Node.ln_Succ)
4512 d1(kprintf("%s/%s/%ld: uev=%08lx uev_Type=%ld uev_UndoHook=%08lx\n", __FILE__, __FUNC__, __LINE__, uev, uev->uev_Type, uev->uev_UndoHook));
4513 if (UNDO_CloseWindow == uev->uev_Type)
4515 BPTR dirLock;
4517 dirLock = Lock(uev->uev_Data.uev_CloseWindowData.ucwd_DirName, ACCESS_READ);
4518 if (dirLock)
4520 if (LOCK_SAME == SameLock(dirLock, iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock))
4521 Found = TRUE;
4523 UnLock(dirLock);
4525 if (Found)
4526 break;
4530 if (Found)
4532 UndoCount--;
4533 Remove(&ust->ust_Node);
4534 UndoDisposeStep(ust);
4537 ust = ustNext;
4538 d1(kprintf("%s/%s/%ld: ust=%08lx \n", __FILE__, __FUNC__, __LINE__, ust));
4541 ScalosReleaseSemaphore(&UndoListListSemaphore);
4543 SetMenuOnOff(iwt);
4546 d1(kprintf("%s/%s/%ld: END\n", __FILE__, __FUNC__, __LINE__));
4549 //----------------------------------------------------------------------------
4551 // If window <iwt> is about to close, walk through Undo/Redo lists
4552 // and remove all entries which refer to the disappearing window
4553 void UndoWindowSignalClosing(struct internalScaWindowTask *iwt)
4555 struct UndoStep *ust;
4557 d1(kprintf("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
4559 UndoAddEvent(iwt, UNDO_CloseWindow,
4560 UNDOTAG_WindowTask, iwt,
4561 TAG_END);
4563 ScalosObtainSemaphore(&UndoListListSemaphore);
4565 for (ust = (struct UndoStep *) globalUndoList.lh_Head;
4566 ust != (struct UndoStep *) &globalUndoList.lh_Tail; )
4568 struct UndoStep *ustNext = (struct UndoStep *) ust->ust_Node.ln_Succ;
4569 BOOL Found = FALSE;
4570 struct UndoEvent *uev;
4572 d1(kprintf("%s/%s/%ld: ust=%08lx \n", __FILE__, __FUNC__, __LINE__, ust));
4574 for (uev = (struct UndoEvent *) ust->ust_EventList.lh_Head;
4575 uev != (struct UndoEvent *) &ust->ust_EventList.lh_Tail;
4576 uev = (struct UndoEvent *) uev->uev_Node.ln_Succ)
4578 d1(kprintf("%s/%s/%ld: uev=%08lx uev_Type=%ld uev_UndoHook=%08lx\n", __FILE__, __FUNC__, __LINE__, uev, uev->uev_Type, uev->uev_UndoHook));
4579 if (UNDO_Cleanup == uev->uev_Type)
4581 if (uev->uev_Data.uev_CleanupData.ucd_WindowTask == &iwt->iwt_WindowTask)
4583 Found = TRUE;
4584 break;
4587 else if (UNDO_SizeWindow == uev->uev_Type)
4589 if (uev->uev_Data.uev_SizeWindowData.uswd_WindowTask == &iwt->iwt_WindowTask)
4591 Found = TRUE;
4592 break;
4597 if (Found)
4599 UndoCount--;
4600 Remove(&ust->ust_Node);
4601 UndoDisposeStep(ust);
4604 ust = ustNext;
4605 d1(kprintf("%s/%s/%ld: ust=%08lx \n", __FILE__, __FUNC__, __LINE__, ust));
4608 ScalosReleaseSemaphore(&UndoListListSemaphore);
4610 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
4612 ScalosObtainSemaphore(&RedoListListSemaphore);
4614 for (ust = (struct UndoStep *) globalRedoList.lh_Head;
4615 ust != (struct UndoStep *) &globalRedoList.lh_Tail; )
4617 struct UndoStep *ustNext = (struct UndoStep *) ust->ust_Node.ln_Succ;
4618 BOOL Found = FALSE;
4619 struct UndoEvent *uev;
4621 d1(kprintf("%s/%s/%ld: ust=%08lx \n", __FILE__, __FUNC__, __LINE__, ust));
4623 for (uev = (struct UndoEvent *) ust->ust_EventList.lh_Head;
4624 uev != (struct UndoEvent *) &ust->ust_EventList.lh_Tail;
4625 uev = (struct UndoEvent *) uev->uev_Node.ln_Succ)
4627 d1(kprintf("%s/%s/%ld: uev=%08lx uev_Type=%ld uev_UndoHook=%08lx\n", __FILE__, __FUNC__, __LINE__, uev, uev->uev_Type, uev->uev_UndoHook));
4628 if (UNDO_Cleanup == uev->uev_Type)
4630 if (uev->uev_Data.uev_CleanupData.ucd_WindowTask == &iwt->iwt_WindowTask)
4632 Found = TRUE;
4633 break;
4636 else if (UNDO_SizeWindow == uev->uev_Type)
4638 if (uev->uev_Data.uev_SizeWindowData.uswd_WindowTask == &iwt->iwt_WindowTask)
4640 Found = TRUE;
4641 break;
4646 if (Found)
4648 Remove(&ust->ust_Node);
4649 UndoDisposeStep(ust);
4652 ust = ustNext;
4653 d1(kprintf("%s/%s/%ld: ust=%08lx \n", __FILE__, __FUNC__, __LINE__, ust));
4656 ScalosReleaseSemaphore(&RedoListListSemaphore);
4658 SetMenuOnOff(iwt);
4660 d1(kprintf("%s/%s/%ld: END\n", __FILE__, __FUNC__, __LINE__));
4663 //----------------------------------------------------------------------------
4665 static BOOL UndoFindWindowAndIcon(CONST_STRPTR DirName, CONST_STRPTR IconName,
4666 struct internalScaWindowTask **iwt, struct ScaIconNode **in)
4668 BOOL Found = FALSE;
4669 BPTR DirLock;
4671 do {
4672 SCA_LockWindowList(SCA_LockWindowList_Shared);
4674 DirLock = Lock(DirName, ACCESS_READ);
4675 if (BNULL == DirLock)
4676 break;
4678 // First check whether icon is on desktop window (left-out)
4679 *iwt = (struct internalScaWindowTask *) iInfos.xii_iinfos.ii_MainWindowStruct->ws_WindowTask;
4681 ScalosLockIconListShared(*iwt);
4683 for ((*in)=(*iwt)->iwt_WindowTask.wt_IconList; *in; *in = (struct ScaIconNode *) (*in)->in_Node.mln_Succ)
4685 if ((*in)->in_Lock && (LOCK_SAME == SameLock((*in)->in_Lock, DirLock)) &&
4686 (0 == Stricmp(GetIconName(*in), IconName)))
4688 Found = TRUE;
4689 d1(kprintf("%s/%s/%ld: in=%08lx <%s>\n", __FILE__, __FUNC__, __LINE__, *in, GetIconName(*in)));
4690 break;
4694 if (Found)
4695 break; // icon found on desktop window
4697 // icon not found in desktop window
4698 ScalosUnLockIconList(*iwt);
4700 SCA_UnLockWindowList();
4702 *iwt = UndoFindWindowByDir(DirName);
4703 if (NULL == *iwt)
4704 break;
4706 *in = UndoFindIconByName(*iwt, IconName);
4707 if (NULL == in)
4708 break;
4710 Found = TRUE;
4711 } while (0);
4713 if (DirLock)
4714 UnLock(DirLock);
4715 if (!Found)
4717 if (*in)
4718 ScalosUnLockIconList(*iwt);
4720 if (*iwt)
4721 SCA_UnLockWindowList();
4723 *iwt = NULL;
4724 *in = NULL;
4727 return Found;
4730 //----------------------------------------------------------------------------