1 /* $TOG: ca_aux.c /main/10 1999/09/17 15:44:00 mgreess $ */
2 /******************************************************************************/
4 /* ca_aux - auxiliary functions for create action */
6 /* Functions to get/set values from/to interface. */
7 /* Callback routines for CA interface. */
9 /******************************************************************************/
14 #include <sys/signal.h>
17 #include <X11/cursorfont.h>
19 #include <X11/Xatom.h>
22 #include <Xm/RowColumnP.h>
23 #include <Xm/MessageB.h>
24 #include <Xm/FileSB.h>
29 # if defined(__osf__) || defined(linux)
32 # include <sys/dirent.h>
37 #include <Dt/IconFile.h>
43 #include "CreateActionAppShell.h"
44 #include "Confirmed.h"
46 /******************************************************************************/
48 /* External Variables */
50 /******************************************************************************/
51 extern Dimension wintypeheight, winheight, xprtheight, newheight;
53 /******************************************************************************/
57 /******************************************************************************/
58 struct _ActionData *ca_local_struct;
60 /******************************************************************************/
61 /* readCAFromGUI - loads Action data structure with data read from */
62 /* the GUI interface. */
65 /******************************************************************************/
66 void readCAFromGUI (struct _ActionData *ca_struct)
68 getCAactionName (ca_struct);
69 getCAdblClkCmd (ca_struct);
70 getCAactionHelpText (ca_struct);
71 /*getCAfileTypes (ca_struct);*/
72 getCAactionOpensText (ca_struct);
73 /*getCAwindowType (ca_struct);*/
74 /*getCAactionIcons (ca_struct);*/
75 /*getCAexpertOption (ca_struct);*/
80 /******************************************************************************/
81 /* writeCAToGUI - loads widgets with data stored in the integration */
85 /******************************************************************************/
86 void writeCAToGUI (struct _ActionData *pAD)
88 putCAactionName (pAD);
89 putCAactionIcons (pAD);
91 putCAactionHelpText (pAD);
92 putCAwindowType (pAD);
93 putCAactionOpensText (pAD);
95 putCAdropFiletypes(pAD);
100 /******************************************************************************/
101 /* getCAactionName - retrieves the action name text string and stores */
102 /* the value in the ActionData structure */
103 /* INPUT: _ActionData *ca_struct - Action data structure */
105 /******************************************************************************/
106 void getCAactionName (struct _ActionData *ca_struct)
108 GetWidgetTextString(CA_ActionNameTextField, &(AD.pszName));
112 /******************************************************************************/
113 /* getCAdblClkCmd - retrieves the double-click command text */
114 /* string and stores the value in the ActionData structure */
115 /* INPUT: _ActionData *ca_struct - Action data structure */
117 /******************************************************************************/
118 void getCAdblClkCmd (struct _ActionData *ca_struct)
120 GetWidgetTextString(CA_DblClkText, &(AD.pszCmd));
124 /******************************************************************************/
125 /* getCAactionHelpText - retrieves the help text string and stores */
126 /* the value in the ActionData structure */
127 /* INPUT: _ActionData *ca_struct - Action data structure */
129 /******************************************************************************/
130 void getCAactionHelpText (struct _ActionData *ca_struct)
132 GetWidgetTextString(CA_HelpText, &(AD.pszHelp));
135 /******************************************************************************/
136 /* getCAactionOpensText - retrieves the "action opens" text */
137 /* string and stores the value in the ActionData structure */
138 /* INPUT: _ActionData *ca_struct - Action data structure */
140 /******************************************************************************/
141 void getCAactionOpensText (struct _ActionData *ca_struct)
143 GetWidgetTextString(CA_XprtActionOpenText, &(AD.pszPrompt));
146 /******************************************************************************/
147 /* putCAactionName - sets the action name text field in the GUI */
148 /* from the value in the ActionData structure */
149 /* INPUT: _ActionData *ca_struct - Action data structure */
151 /******************************************************************************/
152 void putCAactionName (struct _ActionData *ca_struct)
154 PutWidgetTextString(CA_ActionNameTextField, CA_ActionName(ca_struct));
158 /******************************************************************************/
159 /* putCAdblClkCmd - sets the double-click command text */
160 /* string in the GUI from the value in the ActionData structure */
161 /* INPUT: _ActionData *ca_struct - Action data structure */
163 /******************************************************************************/
164 void putCAdblClkCmd (struct _ActionData *ca_struct)
166 PutWidgetTextString(CA_DblClkText, CA_DblClkAction(ca_struct));
170 /******************************************************************************/
171 /* putCAactionHelpText - sets the help text string in the GUI from */
172 /* the value in the ActionData structure */
173 /* INPUT: _ActionData *ca_struct - Action data structure */
175 /******************************************************************************/
176 void putCAactionHelpText (struct _ActionData *ca_struct)
178 PutWidgetTextString(CA_HelpText, CA_ActionHelpText(ca_struct));
182 /******************************************************************************/
183 /* putCAfileTypes - sets the list of file types in the GUI from */
184 /* the values in the ActionData structure */
185 /* INPUT: _ActionData *ca_struct - Action data structure */
187 /******************************************************************************/
188 void putCAfileTypes (struct _ActionData *pAD)
193 if (pAD->cFiletypes) {
194 for (i=0; i < pAD->cFiletypes; i++) {
195 if (!XmListItemExists(CA_FiletypesList,
196 XmStringCreateSimple((pAD->papFiletypes[i])->pszName))) {
197 XmListAddItem(CA_FiletypesList,
198 XmStringCreateSimple((pAD->papFiletypes[i])->pszName), i+1);
206 /******************************************************************************/
207 /* putCAactionOpensText - sets the "action opens" text string in */
208 /* the GUE from the value in the ActionData structure */
209 /* INPUT: _ActionData *ca_struct - Action data structure */
211 /******************************************************************************/
212 void putCAactionOpensText (struct _ActionData *ca_struct)
214 PutWidgetTextString(CA_XprtActionOpenText, CA_ActionOpensText(ca_struct));
218 /******************************************************************************/
219 /* putCAwindowType - sets the window type toggle status in the GUI */
220 /* from the value in the ActionData structure */
221 /* INPUT: _ActionData *ca_struct - Action data structure */
223 /******************************************************************************/
224 void putCAwindowType (struct _ActionData *ca_struct)
226 if (ca_struct->fsFlags & CA_WT_XWINDOWS) {
228 XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeNoOutput,NULL);
230 XtVaSetValues(CA_WindowTypeArea, XmNmenuHistory, CA_WinTypeX, NULL);
231 } else if (ca_struct->fsFlags & CA_WT_TERM) {
232 XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeAutoClose,NULL);
233 } else if (ca_struct->fsFlags & CA_WT_PERMTERM) {
234 XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeManualClose,NULL);
236 /*XtVaSetValues(CA_WindowTypeArea,XmNmenuHistory,CA_WinTypeNoOutput,NULL);*/
237 XtVaSetValues(CA_WindowTypeArea, XmNmenuHistory, CA_WinTypeX, NULL);
242 /******************************************************************************/
243 /* putCAactionIcons - */
244 /* GUI from the value in the ActionData structure */
245 /* INPUT: _ActionData *ca_struct - Action data structure */
247 /******************************************************************************/
248 void putCAactionIcons (ActionData *pAD)
250 char *pszIconFileName = (char *)NULL;
252 char *msgPtr, *fmtPtr, *errPtr;
254 /**************************************************************************/
255 /* Since we only have the base name, we must find the icon within the */
256 /* icon path, strip off the size and type extension, then set the icon */
257 /* data and gadget with this new name - base name and path. */
258 /**************************************************************************/
259 FIND_ICONGADGET_ICON(pAD->pszIcon, pszIconFileName, DtLARGE);
260 if (pszIconFileName) {
261 ptr = strstr(pszIconFileName, LARGE_EXT);
262 if (ptr) *ptr = '\0';
263 SetIconData(CA_LRG_IconGadget, pszIconFileName, Large_Icon);
264 XtFree(pszIconFileName);
266 msgPtr = GETMESSAGE(5, 95,
267 "Could not find the following icon file within the icon\n\
270 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
271 strlen(pAD->pszIcon) + 1) * sizeof(char));
272 sprintf(errPtr, fmtPtr, msgPtr, pAD->pszIcon);
273 display_error_message(CreateActionAppShell, errPtr);
277 FIND_ICONGADGET_ICON(pAD->pszIcon, pszIconFileName, DtMEDIUM);
278 if (pszIconFileName) {
279 ptr = strstr(pszIconFileName, MEDIUM_EXT);
280 if (ptr) *ptr = '\0';
281 SetIconData(CA_MED_IconGadget, pszIconFileName, Medium_Icon);
282 XtFree(pszIconFileName);
284 msgPtr = GETMESSAGE(5, 95,
285 "Could not find the following icon file within the icon\n\
288 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
289 strlen(pAD->pszIcon) + 1) * sizeof(char));
290 sprintf(errPtr, fmtPtr, msgPtr, pAD->pszIcon);
291 display_error_message(CreateActionAppShell, errPtr);
295 FIND_ICONGADGET_ICON(pAD->pszIcon, pszIconFileName, DtTINY);
296 if (pszIconFileName) {
297 ptr = strstr(pszIconFileName, TINY_EXT);
298 if (ptr) *ptr = '\0';
299 SetIconData(CA_TINY_IconGadget, pszIconFileName, Tiny_Icon);
300 XtFree(pszIconFileName);
302 msgPtr = GETMESSAGE(5, 95,
303 "Could not find the following icon file within the icon\n\
306 errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
307 strlen(pAD->pszIcon) + 1) * sizeof(char));
308 sprintf(errPtr, fmtPtr, msgPtr, pAD->pszIcon);
309 display_error_message(CreateActionAppShell, errPtr);
314 /******************************************************************************/
315 /* putCAdropFiletypes - */
317 /* INPUT: _ActionData *ca_struct - Action data structure */
319 /******************************************************************************/
320 void putCAdropFiletypes (ActionData *pAD)
324 if (pAD->fsFlags & CA_DF_ONLYFTFILES) {
327 SET_TOGGLEBUTTON(CA_FiletypesInListToggle, set);
328 SET_TOGGLEBUTTON(CA_AllFiletypesToggle, !set);
333 /******************************************************************************/
334 /* set_ca_dialog_height - adjusts height of create action dialog to exclude */
335 /* height used by expert option section. */
338 /******************************************************************************/
339 void set_ca_dialog_height (void)
341 Boolean showExpert = sessiondata.useSession && sessiondata.showExpert;
343 /* get height of window */
344 XtVaGetValues (CreateActionAppShell, XmNheight, &winheight, NULL);
345 /* get height of expert option form */
346 XtVaGetValues (XprtOptionForm, XmNheight, &xprtheight, NULL);
347 /* calculate height of window without expert option form */
348 newheight = winheight - xprtheight;
352 /* remove attachment to expert option form */
353 XtVaSetValues (CA_Expand, XmNbottomAttachment, XmATTACH_NONE, NULL);
354 XtUnmanageChild (XprtOptionForm);
356 if (!sessiondata.useSession)
358 /* give window new height */
359 XtVaSetValues (CreateActionAppShell, XmNheight, newheight, NULL);
362 XtVaSetValues (CA_Expand, XmNbottomAttachment, XmATTACH_FORM, NULL);
366 XtVaSetValues (CA_Expand, RES_CONVERT(XmNlabelString,
367 GETMESSAGE(3, 52, "Basic")),
374 /******************************************************************************/
376 /* CALLBACK FUNCTIONS */
378 /******************************************************************************/
380 /******************************************************************************/
383 /* Callbacks for Create Action 'File' menu */
386 /******************************************************************************/
388 /*****************************************************************************/
393 /*****************************************************************************/
395 initAD( ActionData *pAD )
397 memset(pAD, 0, sizeof(ActionData));
398 pAD->fsFlags |= CA_WT_XWINDOWS;
399 pAD->pszIcon = (char *)XtMalloc(strlen(ca_icon_default) + 1);
400 strcpy(pAD->pszIcon, ca_icon_default);
403 /******************************************************************************/
404 /* FreeAndClearAD - free all fields in AD, frees filetypes and array, */
405 /* and zero's out all of the fields of the structure. */
408 /******************************************************************************/
409 void FreeAndClearAD (ActionData *pAD)
414 if (pAD->pszName) XtFree(pAD->pszName);
415 if (pAD->pszIcon) XtFree(pAD->pszIcon);
416 if (pAD->pszCmd) XtFree(pAD->pszCmd);
417 if (pAD->pszHelp) XtFree(pAD->pszHelp);
418 if (pAD->pszPrompt) XtFree(pAD->pszPrompt);
420 if (pAD->papFiletypes) {
421 for (i=0; i < pAD->cFiletypes; i++) {
422 free_Filetypedata(pAD->papFiletypes[i]);
424 XtFree((char *)pAD->papFiletypes);
426 memset(pAD, 0, sizeof(ActionData));
431 /******************************************************************************/
432 /* clear_CreateActionAppShell_fields */
436 /******************************************************************************/
437 void clear_CreateActionAppShell_fields(void)
439 clear_text_field (ACTION_NAME);
440 clear_text_field (DBL_CLK_CMND);
442 XtVaSetValues(CA_WindowTypeArea, XmNmenuHistory, CA_WinTypeX, NULL);
444 clear_text_field (ACTION_OPENS_TEXT);
445 clear_text (ACTION_HELP_TXT);
446 delete_all_list_items (FILETYPES_FOR_ACTION);
448 createCB_IconGadget(CA_LRG_IconGadget, True, Large_Icon);
449 createCB_IconGadget(CA_MED_IconGadget, True, Medium_Icon);
450 createCB_IconGadget(CA_TINY_IconGadget, True, Tiny_Icon);
452 SET_TOGGLEBUTTON(CA_AllFiletypesToggle, TRUE);
453 SET_TOGGLEBUTTON(CA_FiletypesInListToggle, FALSE);
458 /******************************************************************************/
459 /* activateCB_FileNew - clears the text and list widgets on the */
460 /* create action main panel */
461 /* INPUT: Widget wid - widget id */
462 /* XtPointer cdata - client data */
463 /* XtPointer cbs - callback structur */
465 /******************************************************************************/
466 void activateCB_FileNew (Widget wid, XtPointer cdata,
469 char pszFile[MAXBUFSIZE];
471 /**************************************************************************/
472 /* Clear the fields in the gui and set fields to default. */
473 /**************************************************************************/
474 clear_CreateActionAppShell_fields();
476 /**************************************************************************/
477 /* Clear the pszFileToEdit global variable. */
478 /**************************************************************************/
479 pszFileToEdit = (char *)NULL;
481 /**************************************************************************/
482 /* Clear the fields within the ActionData structure and free any */
483 /* FiletypeData structures. */
484 /**************************************************************************/
487 /**************************************************************************/
488 /* Initialize fields within the ActionData structure. */
489 /**************************************************************************/
492 /**************************************************************************/
493 /* Get a new copy of AD. */
494 /**************************************************************************/
495 FreeAndClearAD(pMyCopyAD);
496 XtFree((char *)pMyCopyAD);
497 pMyCopyAD = copyAD(&AD);
503 /******************************************************************************/
504 /* activateCB_FileOpen - Callback for the Open menu bar option that is */
505 /* located within the File submenu. This callback */
506 /* pops up the File Selection dialog box. */
508 /* INPUT: Widget wid - widget id */
509 /* XtPointer cdata - client data */
510 /* XtPointer cbs - callback structure */
513 /******************************************************************************/
514 void activateCB_FileOpen(Widget wid, XtPointer cdata,
519 XtVaSetValues (OpenFile, RES_CONVERT(XmNdirMask, "~/.dt/types/*.dt"),
520 RES_CONVERT(XmNdirSpec, "~/.dt/types/"),
521 RES_CONVERT(XmNdirectory, "~/.dt/types/"),
524 filter = XmFileSelectionBoxGetChild (OpenFile, XmDIALOG_FILTER_TEXT);
525 /*XtVaSetValues (filter, XmNeditable, False, NULL);*/
526 UxPopupInterface (OpenFile, no_grab);
530 /******************************************************************************/
536 /******************************************************************************/
537 void FreeResources ( void )
539 /**************************************************************************/
540 /* Clear the fields within the ActionData structure and free any */
541 /* FiletypeData structures. */
542 /**************************************************************************/
545 /**************************************************************************/
546 /* Free my copy of AD. */
547 /**************************************************************************/
548 FreeAndClearAD(pMyCopyAD);
549 XtFree((char *)pMyCopyAD);
551 /********************************************************************/
552 /* Free temporary icon files */
553 /********************************************************************/
554 RemoveTmpIconFiles();
559 /******************************************************************************/
560 /* activateCB_FileQuit */
561 /* INPUT: Widget wid - widget id */
562 /* XtPointer cdata - client data */
563 /* XtPointer cbs - callback structur */
565 /******************************************************************************/
566 void activateCB_FileQuit (Widget wid, XtPointer cdata,
574 /**************************************************************************/
575 /* Get latest changes from main window. */
576 /**************************************************************************/
579 /**************************************************************************/
580 /* Check if anything has changed. If so ask if they really want to quit. */
581 /**************************************************************************/
582 if (compareAD(&AD, pMyCopyAD)) {
583 msgPtr = GETMESSAGE(5, 150, "Your current work has not been saved.");
584 msgPtr = XtNewString(msgPtr);
586 /* CDExc19439 - Save GETMESSAGE results to buffers since it can */
587 /* return an internal buffer which can be overwritten on each call. */
588 savePtr = XtNewString(GETMESSAGE(2, 25, "Save"));
589 noSavePtr = XtNewString(GETMESSAGE(5, 152, "Don't Save"));
590 cancelPtr = XtNewString(GETMESSAGE(5, 154, "Cancel Close"));
592 display_question_message(CreateActionAppShell, msgPtr,
593 savePtr, (XtCallbackProc)saveCB_QuestionDialog,
594 noSavePtr, nosaveCB_QuestionDialog,
595 cancelPtr, cancelCB_QuestionDialog);
609 /******************************************************************************/
612 /* Callbacks for Create Action 'Options' menu */
615 /* void activateCB_ExpertOption (); */
618 /******************************************************************************/
621 /******************************************************************************/
622 /* activateCB_ExpertOption - turn expert option on/off */
623 /* INPUT: Widget wid - widget id */
624 /* XtPointer client_data - client data */
625 /* XtPointer *cbs - callback data */
627 /* Global Variables Accessed: (other than widgets) */
629 /******************************************************************************/
630 void activateCB_ExpertOption (Widget wid, XtPointer client_data,
635 if (!XtIsManaged(XprtOptionForm)) {
636 /**********************************************************************/
637 /* Expand the window to show optional data. */
638 /**********************************************************************/
639 XtVaGetValues (CA_WindowTypeArea, XmNwidth, &ca_width, NULL);
640 XtVaSetValues (CA_Expand,
641 XmNbottomAttachment, XmATTACH_NONE,
643 XtVaSetValues (XprtOptionForm,
644 XmNbottomAttachment, XmATTACH_FORM,
645 XmNleftAttachment, XmATTACH_FORM,
646 XmNrightAttachment, XmATTACH_FORM,
649 XtManageChild (XprtOptionForm);
650 XtVaSetValues (CA_Expand,
651 XmNbottomAttachment, XmATTACH_WIDGET,
652 XmNbottomWidget, XprtOptionForm,
654 /*XmNlabelString, GETMESSAGE(3, 52, "Basic"),*/
655 RES_CONVERT( XmNlabelString, GETMESSAGE(3, 52, "Basic")),
657 XtVaSetValues (CA_HelpTextWindow, XmNheight, wintypeheight, NULL);
658 /*XtVaSetValues (CA_WindowTypeArea, XmNheight, wintypeheight, NULL);*/
660 /**********************************************************************/
661 /* Shrink the window to hide optional data. */
662 /**********************************************************************/
663 XtVaSetValues (CA_Expand, XmNbottomAttachment, XmATTACH_NONE, NULL);
664 XtUnmanageChild (XprtOptionForm);
665 XtVaSetValues (CA_Expand,
666 XmNbottomAttachment, XmATTACH_FORM,
668 /*XmNlabelString, GETMESSAGE(3, 50, "Advanced"),*/
669 RES_CONVERT( XmNlabelString, GETMESSAGE(3, 50, "Advanced")),
671 XtVaSetValues (CA_HelpTextWindow, XmNheight, wintypeheight, NULL);
672 XtVaSetValues (CA_WindowTypeArea, XmNheight, wintypeheight, NULL);
677 /******************************************************************************/
679 /* valueChangedCB_ColorMonoOption - turn monochrome option on/off */
681 /* INPUT: Widget wid - widget id */
682 /* XtPointer client_data - client data */
683 /* XmToggleButtonCallbackStruct *tcb - callback data */
686 /******************************************************************************/
687 void valueChangedCB_ColorMonoOption (Widget wid, XtPointer client_data,
688 XmToggleButtonCallbackStruct *tcb)
690 int toggle_set= tcb->set;
696 /***************************************************************************/
697 /* If set then change icons from pixmaps to bitmaps. */
698 /***************************************************************************/
700 bShowPixmaps = FALSE;
705 /***************************************************************************/
706 /* Change icons for CA large, med, and tiny icons */
707 /***************************************************************************/
708 widIcons[0] = CA_LRG_IconGadget;
709 widIcons[1] = CA_MED_IconGadget;
710 widIcons[2] = CA_TINY_IconGadget;
711 for (i = 0; i < 3; i++) {
712 pIconData = GetIconDataFromWid(widIcons[i]);
715 SET_ICONGADGET_ICON(widIcons[i], pIconData->pmFileName);
717 SET_ICONGADGET_ICON(widIcons[i], pIconData->bmFileName);
724 /******************************************************************************/
726 /* createCB_ColorMonoOption */
728 /* INPUT: Widget wid - widget id */
731 /******************************************************************************/
732 void createCB_ColorMonoOption (Widget wid)
736 printf("bShowPixmaps = %d\n", (int)bShowPixmaps);
741 /******************************************************************************/
744 /* Callbacks for Create Action 'Help' menu */
747 /******************************************************************************/
749 /******************************************************************************/
752 /* Callbacks for Create Action Panel Buttons */
755 /* void activateCB_action_icon (); */
758 /******************************************************************************/
760 /******************************************************************************/
762 /* activateCB_action_icon - */
764 /* INPUT: Widget wid - id of icon gadget */
765 /* XtPointer client_data - not used */
766 /* XmPushButtonCallbackStruct *cbs - not used */
769 /******************************************************************************/
770 void activateCB_action_icon (Widget wid, XtPointer client_data,
771 DtIconCallbackStruct *cbs)
774 static Time prev_lts = 0;
776 if (cbs->reason == XmCR_ACTIVATE) {
779 printf("In activate_action_icon callback.\n");
781 if (last_action_pushed && (last_action_pushed != wid)) {
782 XtVaSetValues(XtParent(last_action_pushed), XmNborderWidth, 0, NULL);
784 XtVaSetValues(XtParent(wid), XmNborderWidth, ICON_BORDER_WIDTH, NULL);
786 last_action_pushed = wid;
788 /********************************************************************/
789 /* This is the support needed to provide double-click functionality */
790 /* to the icon gadgets. When double-clicked, the icon editor will */
792 /********************************************************************/
793 XtVaSetValues(wid, XmNpushButtonClickTime, 0, NULL);
795 lts = XtLastTimestampProcessed(XtDisplay(wid));
796 mct = XtGetMultiClickTime(XtDisplay(wid));
798 if ((prev_lts + mct) > lts) {
799 prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
801 prev_lts = XtLastTimestampProcessed(XtDisplay(wid));
806 printf("DblClick icon callback.\n");
809 activateCB_edit_icon(wid, CA_ACTION_ICONS, cbs);
815 /******************************************************************************/
816 /* activateCB_add_filetype - bring up the Add Filetype dialog with correct */
818 /* INPUT: Widget wid - not used */
819 /* XtPointer client_data - not used */
820 /* XmPushButtonCallbackStruct *cbs - not used */
822 /******************************************************************************/
823 void activateCB_add_filetype (Widget wid, XtPointer client_data,
824 XmPushButtonCallbackStruct *cbs)
829 char *pre, *suf, *title;
831 if (!CreateActionAppShellCheckFields()) {
834 printf("Allocating FiletypeData structure\n"); /* debug */
837 /******************************************************************/
838 /* Allocate FiletypeData structure */
839 /******************************************************************/
840 pFtD = (FiletypeData *)XtMalloc(sizeof(FiletypeData));
841 memset(pFtD, 0, sizeof(FiletypeData));
843 /******************************************************************/
844 /* Clear dialog fields */
845 /******************************************************************/
846 clear_AddFiletype_dialog_fields();
847 clear_FileCharacteristics_dialog_fields();
849 /******************************************************************/
850 /* Create name for filetype */
851 /******************************************************************/
852 memset(tmpbuf, 0, 50);
853 sprintf(tmpbuf, "%d", (AD.cFiletypes + 1));
854 ptr = (char *)XmTextFieldGetString(CA_ActionNameTextField);
855 pFtD->pszName = (char *)XtMalloc(strlen(ptr) + strlen("_FILE_") + strlen(tmpbuf) + 1);
856 sprintf(pFtD->pszName, "%s_FILE_%d", ptr, (AD.cFiletypes + 1));
858 XmTextFieldSetString(AF_FileTypeNameTextField, pFtD->pszName);
860 pFtD->pszIcon = (char *)XtMalloc(strlen(af_icon_default) + 1);
861 strcpy(pFtD->pszIcon, af_icon_default);
863 /******************************************************************/
864 /* Set Open command string */
865 /******************************************************************/
867 pFtD->pszOpenCmd = (char *)XmTextGetString(CA_DblClkText);
869 GetWidgetTextString(CA_DblClkText, &(pFtD->pszOpenCmd));
870 XmTextSetString(AF_OpenCmdText, pFtD->pszOpenCmd);
872 pre = GETMESSAGE(3, 10, "Create Action");
873 suf = GETMESSAGE(7, 10, "Add Datatype");
874 title = XtMalloc(strlen(pre) + strlen(suf) + 2);
875 sprintf(title, "%s - %s", pre, suf);
877 XtVaSetValues (AddFiletype,
878 RES_CONVERT (XmNdialogTitle, title ),
883 UxPopupInterface (AddFiletype, no_grab);
889 /******************************************************************************/
890 /* activateCB_edit_filetype - bring up the Add Filetype dialog with correct */
892 /* INPUT: Widget wid - not used */
893 /* XtPointer client_data - not used */
894 /* XmPushButtonCallbackStruct *cbs - not used */
896 /******************************************************************************/
897 void activateCB_edit_filetype (Widget wid, XtPointer client_data,
898 XmPushButtonCallbackStruct *cbs)
901 int *poslist, poscnt;
903 char *msgPtr1, *msgPtr2, *fmtPtr, *errPtr;
904 char *pre, *suf, *title;
906 pre = GETMESSAGE(3, 10, "Create Action");
907 suf = GETMESSAGE(7, 11, "Edit Datatype");
908 title = XtMalloc(strlen(pre) + strlen(suf) + 2);
909 sprintf(title, "%s - %s", pre, suf);
911 /**************************************************************************/
912 /* Determine the selected list item. */
913 /**************************************************************************/
914 if (XmListGetSelectedPos(CA_FiletypesList, &poslist, &poscnt)) {
915 selecteditem = *poslist;
917 if (selecteditem >= 0) {
918 pFtD = AD.papFiletypes[selecteditem];
919 pFtD->fsInternal |= CA_FT_EDIT;
920 GetWidgetTextString(CA_DblClkText, &(pFtD->pszOpenCmd));
921 clear_AddFiletype_dialog_fields();
922 init_AddFiletype_dialog_fields(pFtD);
924 /********************************************************************/
925 /* Pop up the AddFiletype dialog. */
926 /********************************************************************/
927 XtVaSetValues (AddFiletype,
928 RES_CONVERT (XmNdialogTitle, title),
931 UxPopupInterface (AddFiletype, no_grab);
934 msgPtr1 = XtNewString(GETMESSAGE(5, 120,
935 "You have not selected a Datatype from the\n\
936 'Datatypes That Use This Action' list."));
937 msgPtr2 = XtNewString(GETMESSAGE(5, 130,
938 "Please select the Datatype you would like to Edit."));
940 errPtr = XtMalloc((strlen(msgPtr1) + strlen(msgPtr2) +
941 strlen(fmtPtr) + 1) * sizeof(char));
942 sprintf(errPtr, fmtPtr, msgPtr1, msgPtr2);
945 display_error_message(CreateActionAppShell, errPtr);
952 /******************************************************************************/
954 /* get_selected_action_icon - determines which action icon is currently */
958 /* OUTPUT: Widget wid - id of selected icon gadget */
960 /******************************************************************************/
961 Widget get_selected_action_icon (void)
966 if (_DtIconGetState(CA_LRG_IconGadget)) wid = CA_LRG_IconGadget;
967 else if (_DtIconGetState(CA_MED_IconGadget)) wid = CA_MED_IconGadget;
968 else if (_DtIconGetState(CA_TINY_IconGadget)) wid = CA_TINY_IconGadget;
969 else wid = CA_LRG_IconGadget;
972 if (!last_action_pushed) {
973 last_action_pushed = CA_LRG_IconGadget;
975 return (last_action_pushed);
978 /******************************************************************************/
980 /* CreateActionAppShellCheckFields */
983 /* OUTPUT: FALSE - no errors found */
984 /* TRUE - found errors */
986 /******************************************************************************/
987 Boolean CreateActionAppShellCheckFields(void)
990 char *ptr = (char *)NULL;
991 char *ptrPrompt = (char *)NULL;
992 Boolean bError = FALSE;
993 char *msgPtr, *errPtr;
995 /**************************************************************************/
996 /* Check if action name is present. */
997 /**************************************************************************/
1000 GetWidgetTextString(CA_ActionNameTextField, &ptr);
1002 printf("Action Name = '%s'\n", ptr);
1005 msgPtr = GETMESSAGE(5, 10, "The Action Name is missing.\n\
1006 Please enter a name in the 'Action Name' field.");
1007 errPtr = XtNewString(msgPtr);
1008 display_error_message(CreateActionAppShell, errPtr);
1010 XmProcessTraversal(CA_ActionNameTextField, XmTRAVERSE_CURRENT);
1017 /**************************************************************************/
1018 /* Check if execute command is present. */
1019 /**************************************************************************/
1022 GetWidgetTextString(CA_DblClkText, &ptr);
1024 printf("Exec String = '%s'\n", ptr);
1027 msgPtr = GETMESSAGE(5, 15, "The execute command is missing.\n\
1028 Please enter a command in the\n\
1029 'Command To Execute When Double-clicked' field.");
1030 errPtr = XtNewString(msgPtr);
1031 display_error_message(CreateActionAppShell, errPtr);
1033 XmProcessTraversal(CA_DblClkText, XmTRAVERSE_CURRENT);
1036 /********************************************************************/
1037 /* Now check to see if there is a prompt string. If so, make sure */
1038 /* there is an argument variable within the exec string. */
1039 /********************************************************************/
1040 GetWidgetTextString(CA_XprtActionOpenText, &ptrPrompt);
1042 if (!strchr(ptr, '$')) {
1043 msgPtr = GETMESSAGE(5, 30, "A variable name is missing in the\n\
1044 'Command To Execute When Double-clicked' field.\n\
1045 Add a variable name for the label you have entered\n\
1046 in the 'When Action Opens, Ask Users for' field.\n\
1047 Valid variable names are $*, $1, $2, ..., $9.");
1048 errPtr = XtNewString(msgPtr);
1049 display_error_message(CreateActionAppShell, errPtr);
1051 XmProcessTraversal(CA_DblClkText, XmTRAVERSE_CURRENT);
1060 /**************************************************************************/
1061 /* Check if droppable filetypes buttons are set correctly. */
1062 /**************************************************************************/
1064 if ((AD.fsFlags & CA_DF_ONLYFTFILES) && !(AD.papFiletypes)) {
1065 msgPtr = GETMESSAGE(5, 20,
1066 "The 'Datatypes That Use This Action' list is empty.\n\
1067 You have selected 'Only Above List' in the 'Dropable\n\
1068 Datatypes' field.\n\
1069 Change the Dropable Datatype choice to 'All Datatypes'\n\
1070 or add at least one datatype to the list.");
1071 errPtr = XtNewString(msgPtr);
1072 display_error_message(CreateActionAppShell, errPtr);
1074 XmProcessTraversal(CA_AllFiletypesToggle, XmTRAVERSE_CURRENT);
1082 /******************************************************************************/
1090 /******************************************************************************/
1091 char * copyString(char *string)
1096 newstring = (char *)XtMalloc(strlen(string) + 1);
1097 strcpy(newstring, string);
1099 newstring = (char *)NULL;
1104 /******************************************************************************/
1112 /******************************************************************************/
1113 FiletypeData * copyFtD(FiletypeData *pFtD)
1115 FiletypeData *pcopyFtD;
1117 pcopyFtD = (FiletypeData *)XtMalloc(sizeof(FiletypeData));
1118 memset(pcopyFtD, 0, sizeof(FiletypeData));
1120 if (pFtD->pszName) {
1121 pcopyFtD->pszName = copyString(pFtD->pszName);
1123 if (pFtD->pszIcon) {
1124 pcopyFtD->pszIcon = copyString(pFtD->pszIcon);
1126 if (pFtD->pszHelp) {
1127 pcopyFtD->pszHelp = copyString(pFtD->pszHelp);
1129 if (pFtD->pszOpenCmd) {
1130 pcopyFtD->pszOpenCmd = copyString(pFtD->pszOpenCmd);
1132 if (pFtD->pszPrintCmd) {
1133 pcopyFtD->pszPrintCmd = copyString(pFtD->pszPrintCmd);
1135 if (pFtD->pszPattern) {
1136 pcopyFtD->pszPattern = copyString(pFtD->pszPattern);
1138 if (pFtD->pszPermissions) {
1139 pcopyFtD->pszPermissions = copyString(pFtD->pszPermissions);
1141 if (pFtD->pszContents) {
1142 pcopyFtD->pszContents = copyString(pFtD->pszContents);
1145 pcopyFtD->sStart = pFtD->sStart;
1146 pcopyFtD->sEnd = pFtD->sEnd;
1147 pcopyFtD->fsFlags = pFtD->fsFlags;
1148 pcopyFtD->fsInternal = pFtD->fsInternal;
1153 /******************************************************************************/
1161 /******************************************************************************/
1162 ActionData * copyAD(ActionData *pAD)
1164 ActionData *pcopyAD;
1167 pcopyAD = (ActionData *)XtMalloc(sizeof(ActionData));
1169 return((ActionData *)NULL);
1171 memset(pcopyAD, 0, sizeof(ActionData));
1174 pcopyAD->pszName = copyString(pAD->pszName);
1177 pcopyAD->pszIcon = copyString(pAD->pszIcon);
1180 pcopyAD->pszCmd = copyString(pAD->pszCmd);
1183 pcopyAD->pszHelp = copyString(pAD->pszHelp);
1185 if (pAD->pszPrompt) {
1186 pcopyAD->pszPrompt = copyString(pAD->pszPrompt);
1188 if (pAD->papFiletypes) {
1189 pcopyAD->papFiletypes = (FiletypeData **) XtMalloc(sizeof(FiletypeData *) * (pAD->cFiletypes + 1));
1190 for (i=0; i < pAD->cFiletypes; i++) {
1191 pcopyAD->papFiletypes[i] = copyFtD(pAD->papFiletypes[i]);
1194 pcopyAD->cFiletypes = pAD->cFiletypes;
1195 pcopyAD->fsFlags = pAD->fsFlags;
1198 /******************************************************************************/
1200 /* compareStrings */
1202 /* INPUT: two pointers to char *'s */
1203 /* OUTPUT: 0 they are the same */
1204 /* 1 they are different */
1206 /******************************************************************************/
1207 Boolean compareStrings(char *pszStr1, char *pszStr2)
1209 if (pszStr1 || pszStr2) {
1212 if (!strcmp(pszStr1, pszStr2)) {
1228 /******************************************************************************/
1232 /* INPUT: two pointers to FtD structures */
1233 /* OUTPUT: 0 they are the same */
1234 /* 1 they are different */
1236 /******************************************************************************/
1237 Boolean compareFtD(FiletypeData *pFtD1, FiletypeData *pFtD2)
1239 if (compareStrings(pFtD1->pszName, pFtD2->pszName)) {
1242 if (compareStrings(pFtD1->pszIcon, pFtD2->pszIcon)) {
1245 if (compareStrings(pFtD1->pszHelp, pFtD2->pszHelp)) {
1248 if (compareStrings(pFtD1->pszOpenCmd, pFtD2->pszOpenCmd)) {
1251 if (compareStrings(pFtD1->pszPrintCmd, pFtD2->pszPrintCmd)) {
1254 if (compareStrings(pFtD1->pszPattern, pFtD2->pszPattern)) {
1257 if (compareStrings(pFtD1->pszPermissions, pFtD2->pszPermissions)) {
1260 if (compareStrings(pFtD1->pszContents, pFtD2->pszContents)) {
1263 if (pFtD1->fsFlags != pFtD2->fsFlags) {
1266 if (pFtD1->sStart != pFtD2->sStart) {
1269 if (pFtD1->sEnd != pFtD2->sEnd) {
1276 /******************************************************************************/
1280 /* INPUT: two pointers to AD structures */
1281 /* OUTPUT: 0 they are the same */
1282 /* 1 they are different */
1284 /******************************************************************************/
1285 Boolean compareAD(ActionData *pAD1, ActionData *pAD2)
1289 if (compareStrings(pAD1->pszName, pAD2->pszName)) {
1292 if (compareStrings(pAD1->pszIcon, pAD2->pszIcon)) {
1295 if (compareStrings(pAD1->pszCmd, pAD2->pszCmd)) {
1298 if (compareStrings(pAD1->pszHelp, pAD2->pszHelp)) {
1301 if (compareStrings(pAD1->pszPrompt, pAD2->pszPrompt)) {
1304 if (pAD1->fsFlags != pAD2->fsFlags) {
1307 if (pAD1->cFiletypes != pAD2->cFiletypes) {
1311 if (pAD1->papFiletypes) {
1312 for (i=0; i < pAD1->cFiletypes; i++) {
1313 if (compareFtD(pAD1->papFiletypes[i], pAD2->papFiletypes[i])) {