2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: actions.c /main/3 1995/10/27 10:37:37 rswiston $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company
26 * (c) Copyright 1993, 1994 International Business Machines Corp.
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
28 * (c) Copyright 1993, 1994 Novell, Inc.
33 #include <Dt/Action.h>
35 #define ApplicationClass "Dtaction"
38 static XtAppContext appContext;
39 static Widget actionText;
40 static Widget fileText;
42 static void CreateWidgets(Widget);
43 static void InvokeActionCb(Widget, XtPointer, XtPointer);
44 static void InvokeAction(char*, char*);
45 static void DbReloadProc(XtPointer);
47 void main(int argc, char **argv)
53 shell = XtAppInitialize(&appContext , ApplicationClass, NULL, 0,
54 &argc, argv, NULL, args, n);
58 if (DtInitialize(XtDisplay(shell), shell, argv[0], ApplicationClass)==False) {
59 /* DtInitialize() has already logged an appropriate error msg */
63 /* Load the filetype/action databases */
66 /* Notice changes to the database without needing to restart application */
67 DtDbReloadNotify(DbReloadProc, NULL);
69 XtRealizeWidget(shell);
70 XmProcessTraversal(actionText, XmTRAVERSE_CURRENT);
72 XtAppMainLoop(appContext);
75 static void CreateWidgets(Widget shell)
77 Widget messageBox, workArea, w;
82 labelString = XmStringCreateLocalized("Invoke");
85 XtSetArg(args[n], XmNdialogType, XmDIALOG_TEMPLATE); n++;
86 XtSetArg(args[n], XmNokLabelString, labelString); n++;
87 messageBox = XmCreateMessageBox(shell, "messageBox", args, n);
88 XtManageChild(messageBox);
89 XmStringFree(labelString);
90 XtAddCallback(messageBox, XmNokCallback, InvokeActionCb, NULL);
93 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
94 XtSetArg(args[n], XmNpacking, XmPACK_COLUMN); n++;
95 XtSetArg(args[n], XmNnumColumns, 2); n++;
96 XtSetArg(args[n], XmNentryAlignment, XmALIGNMENT_END); n++;
97 workArea = XmCreateWorkArea(messageBox, "workArea", args, n);
98 XtManageChild(workArea);
100 labelString = XmStringCreateLocalized("Invoke Action:");
102 XtSetArg(args[n], XmNlabelString, labelString); n++;
103 w = XmCreateLabel(workArea, "actionLabel", args, n);
105 XmStringFree(labelString);
107 labelString = XmStringCreateLocalized("On File:");
109 XtSetArg(args[n], XmNlabelString, labelString); n++;
110 w = XmCreateLabel(workArea, "fileLabel", args, n);
112 XmStringFree(labelString);
115 XtSetArg(args[n], XmNcolumns, 12); n++;
116 actionText = XmCreateTextField(workArea, "actionText", args, n);
117 XtManageChild(actionText);
120 XtSetArg(args[n], XmNcolumns, 12); n++;
121 fileText = XmCreateTextField(workArea, "fileText", args, n);
122 XtManageChild(fileText);
125 static void DbReloadProc(XtPointer cd)
127 /* Pick up any dynamic changes to the database files */
131 static void InvokeActionCb(Widget w, XtPointer cd, XtPointer cb)
136 action = XmTextFieldGetString(actionText);
138 if (action == NULL) return;
139 if (strlen(action) == 0) {
144 file = XmTextFieldGetString(fileText);
146 InvokeAction(action, file);
151 XmTextFieldSetString(actionText, "");
152 XmTextFieldSetString(fileText, "");
154 XmProcessTraversal(actionText, XmTRAVERSE_CURRENT);
157 static void InvokeAction(char *action, char *file)
159 DtActionArg *ap = NULL;
161 DtActionInvocationID actionId;
163 /* If a file was specified, build the file argument list */
165 printf("%s(%s)\n",action,file);
166 if (file != NULL && strlen(file) != 0) {
167 ap = (DtActionArg*) XtCalloc(1, sizeof(DtActionArg));
168 ap[0].argClass = DtACTION_FILE;
169 ap[0].u.file.name = file;
173 /* Invoke the specified action */
175 actionId = DtActionInvoke(shell,action,ap,nap,NULL,NULL,NULL,True,NULL,NULL);