Link with C++ linker
[oweals/cde.git] / cde / programs / dtfile / Menu.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /* $XConsortium: Menu.c /main/4 1995/11/02 14:41:53 rswiston $ */
24 /************************************<+>*************************************
25  ****************************************************************************
26  *
27  *   FILE:           Menu.c
28  *
29  *   COMPONENT_NAME: Desktop File Manager (dtfile)
30  *
31  *   Description:    Contains the menu creation code for the file manager
32  *                   main window, and the simpler callback functions.
33  *
34  *   FUNCTIONS: ActivateMultipleSelect
35  *              ActivateNoSelect
36  *              ActivateSingleSelect
37  *              ChangeToHome
38  *              ChangeToParent
39  *              CreateMenu
40  *              GetHomeDir
41  *              GetMainMenuData
42  *              NewView
43  *              RereadDirectoryMenu
44  *              RestoreMenuSensitivity
45  *              SelectAll
46  *              SetMenuSensitivity
47  *              ShowTrash
48  *              TerminalCWD
49  *              TrashFiles
50  *              UnmanageAllActionItems
51  *              UnselectAll
52  *
53  *   (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
54  *   (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
55  *   (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
56  *   (c) Copyright 1993, 1994, 1995 Novell, Inc.
57  *
58  ****************************************************************************
59  ************************************<+>*************************************/
60
61 #include <stdio.h>
62 #include <signal.h>
63 #include <pwd.h>
64 #include <sys/stat.h>
65
66 #include <Xm/XmP.h>
67 #include <Xm/CascadeBG.h>
68 #include <Xm/PushBG.h>
69 #include <Xm/RowColumn.h>
70 #include <Xm/SeparatoG.h>
71 #include <Xm/ToggleBG.h>
72 #include <Xm/MessageB.h>
73 #include <Xm/MenuShellP.h>
74
75 #include <X11/ShellP.h>
76
77 #include <Dt/DtP.h>
78 #include <Dt/DtNlUtils.h>
79 #include <Dt/Action.h>
80 #include <Dt/ActionP.h>
81 #include <Dt/Connect.h>
82 #include <Dt/Indicator.h>
83 #include <Dt/FileM.h>
84
85 #include "Encaps.h"
86 #include "SharedProcs.h"
87 #include "MultiView.h"
88
89 #include "FileMgr.h"
90 #include "Desktop.h"
91 #include "Main.h"
92 #include "Help.h"
93 #include "SharedMsgs.h"
94
95
96 #define INDICATOR_TIME 12
97
98 #if defined(ADD_SHOW_TRASH)
99 static int menuItemCount = 52;
100 #else
101 static int menuItemCount = 51;
102 #endif
103 static MenuDesc * mainMenu = NULL;
104 static Widget * actionsPaneId = NULL;
105 static char * homeDir = NULL;
106
107 /********    Static Function Declarations    ********/
108 static void GetMainMenuData (
109                         Widget mbar,
110                         XtPointer * mainRecordPtr,
111                         MenuDesc ** menuDescPtr,
112                         int * menuItemCountPtr,
113                         unsigned int ** globalMenuStatesPtr,
114                         unsigned int ** viewMenuStatesPtr) ;
115 static void RereadDirectoryMenu(
116                         Widget w,
117                         XtPointer client_data,
118                         XtPointer call_data) ;
119 static void ShowTrash(
120                         Widget w,
121                         XtPointer client_data,
122                         XtPointer call_data) ;
123 static void NewView(
124                         Widget w,
125                         XtPointer client_data,
126                         XtPointer call_data) ;
127 static void SetMenuSensitivity(
128                         Widget w,
129                         XtPointer client_data,
130                         XtPointer call_data) ;
131 static void RestoreMenuSensitivity(
132                         Widget w,
133                         XtPointer client_data,
134                         XtPointer call_data) ;
135 static void TerminalCWD (
136                         Widget w,
137                         XtPointer client_data,
138                         XtPointer call_data) ;
139
140 /********    End Static Function Declarations    ********/
141
142
143 /************************************************************************
144  *
145  *  CreateMenu
146  *      Create the pull down menuing system for the program.
147  *
148  ************************************************************************/ 
149
150 Widget
151 CreateMenu(
152         Widget main,
153         FileMgrRec *file_mgr_rec )
154 {
155    static Boolean createSharedComponents = True;
156    static Widget * actionsId;
157    static Widget * directoryBarBtn;
158    int i, j;
159    Widget menu_bar;
160    Arg args[5];
161
162    if (createSharedComponents)
163    {
164       mainMenu = (MenuDesc *)XtCalloc(sizeof(MenuDesc) * menuItemCount, 1);
165       j = 0;
166
167       for (i = 0; i < menuItemCount; i++)
168       {
169          mainMenu[i].helpCallback = HelpRequestCB;
170          mainMenu[i].helpData = NULL;
171          mainMenu[i].activateCallback = NULL;
172          mainMenu[i].activateData = NULL;
173          mainMenu[i].maskBit = NULL;
174          mainMenu[i].isHelpBtn = False;
175          mainMenu[i].label = NULL;
176          mainMenu[i].mnemonic = NULL;
177       }
178
179
180       /*************************************/
181       /* Create the 'File' menu components */
182       /*************************************/
183
184       mainMenu[j].type = MENU_PULLDOWN_BUTTON;
185       mainMenu[j].label = GETMESSAGE(20, 1, "File");
186       mainMenu[j].label = XtNewString(mainMenu[j].label);
187       mainMenu[j].mnemonic = GETMESSAGE(20, 2, "F");
188       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
189       mainMenu[j].name = "file";
190       mainMenu[j++].helpData = HELP_FILE_MENU_STR;
191
192       mainMenu[j].type = SHARED_MENU_PANE;
193       mainMenu[j].name = "fileMenu";
194       mainMenu[j++].helpData = HELP_FILE_MENU_STR;
195
196       create_directoryBtn = &(mainMenu[j].widget);
197       mainMenu[j].type = MENU_BUTTON;
198       mainMenu[j].maskBit = CREATE_DIR;
199       mainMenu[j].label = GETMESSAGE(20, 130, "New Folder...");
200       mainMenu[j].label = XtNewString(mainMenu[j].label);
201       mainMenu[j].mnemonic = GETMESSAGE(20, 131, "N");
202       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
203       mainMenu[j].helpData = HELP_FILE_MENU_STR;
204       mainMenu[j].name = "newFolder";
205       mainMenu[j++].activateCallback = ShowMakeFileDialog;
206
207       create_dataBtn = &(mainMenu[j].widget);
208       mainMenu[j].maskBit = CREATE_FILE;
209       mainMenu[j].type = MENU_BUTTON;
210       mainMenu[j].label = GETMESSAGE(20, 132, "New File...");
211       mainMenu[j].label = XtNewString(mainMenu[j].label);
212       mainMenu[j].mnemonic = GETMESSAGE(20, 133, "w");
213       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
214       mainMenu[j].helpData = HELP_FILE_MENU_STR;
215       mainMenu[j].name = "newFile";
216       mainMenu[j++].activateCallback = ShowMakeFileDialog;
217
218       mainMenu[j].type = MENU_SEPARATOR;
219       mainMenu[j].name = "separator";
220       mainMenu[j++].helpCallback = NULL;
221
222       homeBarBtn = &(mainMenu[j].widget);
223       mainMenu[j].type = MENU_BUTTON;
224       mainMenu[j].label = GETMESSAGE(20, 38, "Go Home");
225       mainMenu[j].label = XtNewString(mainMenu[j].label);
226       mainMenu[j].mnemonic = GETMESSAGE(20, 41, "H");
227       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
228       mainMenu[j].helpData = HELP_FILE_MENU_STR;
229       mainMenu[j].name = "goHome";
230       mainMenu[j++].activateCallback = ChangeToHome;
231
232       upBarBtn = &(mainMenu[j].widget);
233       mainMenu[j].type = MENU_BUTTON;
234       mainMenu[j].maskBit = MOVE_UP;
235       mainMenu[j].label = GETMESSAGE(20, 155, "Go Up");
236       mainMenu[j].label = XtNewString(mainMenu[j].label);
237       mainMenu[j].mnemonic = GETMESSAGE(20,94, "U");
238       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
239       mainMenu[j].helpData = HELP_FILE_MENU_STR;
240       mainMenu[j].name = "goUp";
241       mainMenu[j++].activateCallback = ChangeToParent;
242
243       change_directoryBtn = &(mainMenu[j].widget);
244       mainMenu[j].maskBit = CHANGEDIR;
245       mainMenu[j].type = MENU_BUTTON;
246       mainMenu[j].label = GETMESSAGE(20, 134, "Go To...");
247       mainMenu[j].label = XtNewString(mainMenu[j].label);
248       mainMenu[j].mnemonic = GETMESSAGE(20, 135, "G");
249       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
250       mainMenu[j].helpData = HELP_FILE_MENU_STR;
251       mainMenu[j].name = "changeTo";
252       mainMenu[j++].activateCallback = ShowChangeDirDialog;
253
254       findBtn = &(mainMenu[j].widget);
255       mainMenu[j].type = MENU_BUTTON;
256       mainMenu[j].maskBit = FIND;
257       mainMenu[j].label = GETMESSAGE(20, 18, "Find...");
258       mainMenu[j].label = XtNewString(mainMenu[j].label);
259       mainMenu[j].mnemonic = GETMESSAGE(20, 19, "F");
260       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
261       mainMenu[j].helpData = HELP_FILE_MENU_STR;
262       mainMenu[j].name = "find";
263       mainMenu[j++].activateCallback = ShowFindDialog;
264
265       mainMenu[j].type = MENU_SEPARATOR;
266       mainMenu[j].name = "separator";
267       mainMenu[j++].helpCallback = NULL;
268
269 #if defined(ADD_SHOW_TRASH)
270       mainMenu[j].type = MENU_BUTTON;
271       mainMenu[j].label = GETMESSAGE(20, 136, "Open Trash");
272       mainMenu[j].label = XtNewString(mainMenu[j].label);
273       mainMenu[j].mnemonic = GETMESSAGE(20, 112, "O");
274       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
275       mainMenu[j].helpData = HELP_FILE_MENU_STR;
276       mainMenu[j].name = "openTrash";
277       mainMenu[j++].activateCallback = ShowTrash;
278 #endif
279       if (!restrictMode)
280       {
281          terminalBtn = &(mainMenu[j].widget);
282          mainMenu[j].type = MENU_BUTTON;
283          mainMenu[j].label = GETMESSAGE(20,146, "Open Terminal");
284          mainMenu[j].label = XtNewString(mainMenu[j].label);
285          mainMenu[j].mnemonic = GETMESSAGE(20,147, "O");
286          mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
287          mainMenu[j].helpData = HELP_FILE_MENU_STR;
288          mainMenu[j].name = "openTerminal";
289          mainMenu[j++].activateCallback = TerminalCWD;
290       }
291       else 
292          --menuItemCount;
293
294       mainMenu[j].type = MENU_SEPARATOR;
295       mainMenu[j].name = "separator";
296       mainMenu[j++].helpCallback = NULL;
297
298       mainMenu[j].type = MENU_BUTTON;
299       mainMenu[j].label = GETMESSAGE(20, 117, "Close");
300       mainMenu[j].label = XtNewString(mainMenu[j].label);
301       mainMenu[j].mnemonic = GETMESSAGE(20, 118, "C");
302       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
303       mainMenu[j].helpData = HELP_FILE_MENU_STR;
304       mainMenu[j].name = "close";
305       mainMenu[j++].activateCallback = Close;
306
307       /***************************************/
308       /* Create the 'Action' menu components */
309       /***************************************/
310
311       actionsId = &(mainMenu[j].widget);
312       mainMenu[j].type = MENU_PULLDOWN_BUTTON;
313       mainMenu[j].label = GETMESSAGE(20, 7, "Selected");
314       mainMenu[j].label = XtNewString(mainMenu[j].label);
315       mainMenu[j].mnemonic = GETMESSAGE(20, 8, "S");
316       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
317       mainMenu[j].name = "actions";
318       mainMenu[j++].helpData = HELP_SELECTED_MENU_STR;
319
320       actionsPaneId = &(mainMenu[j].widget);
321       mainMenu[j].type = SHARED_MENU_PANE;
322       mainMenu[j].name = "actionMenu";
323       mainMenu[j++].helpData = HELP_SELECTED_MENU_STR;
324
325       moveBtn = &(mainMenu[j].widget);
326       mainMenu[j].type = MENU_BUTTON;
327       mainMenu[j].maskBit = MOVE;
328       mainMenu[j].label = GETMESSAGE(20, 152, "Move to...");
329       mainMenu[j].label = XtNewString(mainMenu[j].label);
330       mainMenu[j].mnemonic = GETMESSAGE(20, 125, "M");
331       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
332       mainMenu[j].helpData = HELP_MOVE_AS_COMMAND_STR;
333       mainMenu[j].name = "move";
334       mainMenu[j++].activateCallback = ShowMoveFileDialog;
335
336       duplicateBtn = &(mainMenu[j].widget);
337       mainMenu[j].type = MENU_BUTTON;
338       mainMenu[j].maskBit = DUPLICATE;
339       mainMenu[j].label = GETMESSAGE(20, 153, "Copy to...");
340       mainMenu[j].label = XtNewString(mainMenu[j].label);
341       mainMenu[j].mnemonic = GETMESSAGE(20, 145, "C");
342       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
343       mainMenu[j].helpData = HELP_COPY_AS_COMMAND_STR;
344       mainMenu[j].name = "copy";
345       mainMenu[j++].activateCallback = ShowCopyFileDialog;
346
347       linkBtn = &(mainMenu[j].widget);
348       mainMenu[j].type = MENU_BUTTON;
349       mainMenu[j].maskBit = LINK;
350       mainMenu[j].label = GETMESSAGE(20, 154, "Copy As Link...");
351       mainMenu[j].label = XtNewString(mainMenu[j].label);
352       mainMenu[j].mnemonic = GETMESSAGE(20, 127, "L");
353       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
354       mainMenu[j].helpData = HELP_LINK_AS_COMMAND_STR;
355       mainMenu[j].name = "link";
356       mainMenu[j++].activateCallback = ShowLinkFileDialog;
357
358       mainMenu[j].type = MENU_SEPARATOR;
359       mainMenu[j].name = "separator";
360       mainMenu[j++].helpCallback = NULL;
361
362       mainMenu[j].maskBit = PUT_ON_DESKTOP;
363       mainMenu[j].type = MENU_BUTTON;
364       mainMenu[j].label = GETMESSAGE(20,84, "Put in Workspace");
365       mainMenu[j].label = XtNewString(mainMenu[j].label);
366       mainMenu[j].mnemonic = GETMESSAGE(20,85, "W");
367       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
368       mainMenu[j].helpData = HELP_PUT_ON_DT_COMMAND_STR;
369       mainMenu[j].name = "putInWorkspace";
370       mainMenu[j++].activateCallback = PutOnDTCB;
371
372       mainMenu[j].type = MENU_BUTTON;
373       mainMenu[j].maskBit = TRASH;
374       mainMenu[j].label = GETMESSAGE(20,151, "Put in Trash");
375       mainMenu[j].label = XtNewString(mainMenu[j].label);
376       mainMenu[j].mnemonic = GETMESSAGE(20, 91, "T");
377       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
378       mainMenu[j].helpData = HELP_TRASH_FILES_COMMAND_STR;
379       mainMenu[j].name = "putInTrash";
380       mainMenu[j++].activateCallback = TrashFiles;
381
382       renameBtn = &(mainMenu[j].widget);
383       mainMenu[j].type = MENU_BUTTON;
384       mainMenu[j].maskBit = RENAME;
385       mainMenu[j].label = GETMESSAGE(20, 137, "Rename...");
386       mainMenu[j].label = XtNewString(mainMenu[j].label);
387       mainMenu[j].mnemonic = GETMESSAGE(20, 110, "R");
388       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
389       mainMenu[j].helpData = HELP_RENAME_COMMAND_STR;
390       mainMenu[j].name = "rename";
391       mainMenu[j++].activateCallback = ShowRenameFileDialog;
392
393       mainMenu[j].type = MENU_BUTTON;
394       mainMenu[j].maskBit = MODIFY;
395       mainMenu[j].label = GETMESSAGE(20, 150, "Change Permissions...");
396       mainMenu[j].label = XtNewString(mainMenu[j].label);
397       mainMenu[j].mnemonic = GETMESSAGE(20, 17, "P");
398       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
399       mainMenu[j].helpData = HELP_PROPERTIES_COMMAND_STR;
400       mainMenu[j].name = "permissions";
401       mainMenu[j++].activateCallback = ShowModAttrDialog;
402
403       mainMenu[j].type = MENU_SEPARATOR;
404       mainMenu[j].name = "separator";
405       mainMenu[j++].helpCallback = NULL;
406
407       mainMenu[j].type = MENU_BUTTON;
408       mainMenu[j].label = GETMESSAGE(20, 48, "Select All");
409       mainMenu[j].label = XtNewString(mainMenu[j].label);
410       mainMenu[j].mnemonic = GETMESSAGE(20, 51, "S");
411       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
412       mainMenu[j].helpData = HELP_SELECT_ALL_COMMAND_STR;
413       mainMenu[j].name = "selectAll";
414       mainMenu[j++].activateCallback = SelectAll;
415
416       mainMenu[j].type = MENU_BUTTON;
417       mainMenu[j].label = GETMESSAGE(20, 52, "Deselect All");
418       mainMenu[j].label = XtNewString(mainMenu[j].label);
419       mainMenu[j].mnemonic = GETMESSAGE(20, 55, "D");
420       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
421       mainMenu[j].helpData = HELP_UNSELECT_ALL_COMMAND_STR;
422       mainMenu[j].name = "deselectAll";
423       mainMenu[j++].activateCallback = UnselectAll;
424
425       mainMenu[j].type = MENU_SEPARATOR;
426       mainMenu[j].name = "separator";
427       mainMenu[j++].helpCallback = NULL;
428
429       /*************************************/
430       /* Create the 'View' menu components */
431       /*************************************/
432
433       directoryBarBtn = &(mainMenu[j].widget);
434       mainMenu[j].type = MENU_PULLDOWN_BUTTON;
435       mainMenu[j].label = GETMESSAGE(20, 5, "View");
436       mainMenu[j].label = XtNewString(mainMenu[j].label);
437       mainMenu[j].mnemonic = GETMESSAGE(20, 6, "V");
438       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
439       mainMenu[j].name = "view";
440       mainMenu[j++].helpData = HELP_VIEW_MENU_STR;
441
442       mainMenu[j].type = SHARED_MENU_PANE;
443       mainMenu[j].name = "viewMenu";
444       mainMenu[j++].helpData = HELP_VIEW_MENU_STR;
445
446       if(openDirType == CURRENT)
447       {
448          newViewBtn = &(mainMenu[j].widget);
449          mainMenu[j].type = MENU_BUTTON;
450          mainMenu[j].label = GETMESSAGE(20, 138, "Open New View");
451          mainMenu[j].label = XtNewString(mainMenu[j].label);
452          mainMenu[j].mnemonic = GETMESSAGE(20, 139, "O");
453          mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
454          mainMenu[j].helpData = HELP_NEW_VIEW_COMMAND_STR;
455          mainMenu[j].name = "new";
456          mainMenu[j++].activateCallback = NewView;
457       }
458       else 
459          menuItemCount--;
460
461       mainMenu[j].type = MENU_SEPARATOR;
462       mainMenu[j].name = "separator";
463       mainMenu[j++].helpCallback = NULL;
464
465       preferencesBtn = &(mainMenu[j].widget);
466       mainMenu[j].type = MENU_BUTTON;
467       mainMenu[j].maskBit = PREFERENCES;
468       mainMenu[j].label = GETMESSAGE(20, 141, "Set View Options...");
469       mainMenu[j].label = XtNewString(mainMenu[j].label);
470       mainMenu[j].mnemonic = GETMESSAGE(20, 6, "V");
471       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
472       mainMenu[j].helpData = HELP_PREFERENCES_COMMAND_STR;
473       mainMenu[j].name = "setViewOptions";
474       mainMenu[j++].activateCallback = ShowPreferencesDialog;
475
476       defaultEnvBtn = &(mainMenu[j].widget);
477       mainMenu[j].type = MENU_BUTTON;
478       mainMenu[j].maskBit = SETTINGS;
479       mainMenu[j].label = GETMESSAGE(20, 142, "Save As Default Options...");
480       mainMenu[j].label = XtNewString(mainMenu[j].label);
481       mainMenu[j].mnemonic = GETMESSAGE(20, 143, "S");
482       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
483       mainMenu[j].helpData = HELP_SAVE_SETTINGS_COMMAND_STR;
484       mainMenu[j].name = "saveViewOptions";
485       mainMenu[j++].activateCallback = SaveSettingsCB;
486
487       showHiddenMenu = &(mainMenu[j].widget);
488       mainMenu[j].type = MENU_TOGGLE_BUTTON;
489       mainMenu[j].label = GETMESSAGE(20,156, "Show Hidden Objects");
490       mainMenu[j].label = XtNewString(mainMenu[j].label);
491       mainMenu[j].mnemonic = GETMESSAGE(20,102, "H");
492       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
493       mainMenu[j].helpData = HELP_SHOW_HIDDEN_COMMAND_STR;
494       mainMenu[j].name = "showHiddenObjects";
495       mainMenu[j++].activateCallback = ShowHiddenFiles;
496
497       filterBtn = &(mainMenu[j].widget);
498       mainMenu[j].type = MENU_BUTTON;
499       mainMenu[j].maskBit = FILTER;
500       mainMenu[j].label = GETMESSAGE(20,144, "Set Filter Options...");
501       mainMenu[j].label = XtNewString(mainMenu[j].label);
502       mainMenu[j].mnemonic = GETMESSAGE(20, 104, "F");
503       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
504       mainMenu[j].helpData = HELP_FILTER_COMMAND_STR;
505       mainMenu[j].name = "setFilterOptions";
506       mainMenu[j++].activateCallback = ShowFilterDialog;
507
508       mainMenu[j].type = MENU_SEPARATOR;
509       mainMenu[j].name = "separator";
510       mainMenu[j++].helpCallback = NULL;
511
512       cleanUpBtn = &(mainMenu[j].widget);
513       mainMenu[j].type = MENU_BUTTON;
514       mainMenu[j].maskBit = CLEAN_UP;
515       mainMenu[j].label = GETMESSAGE(20,99, "Clean Up");
516       mainMenu[j].label = XtNewString(mainMenu[j].label);
517       mainMenu[j].mnemonic = GETMESSAGE(20,100, "C");
518       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
519       mainMenu[j].helpData = HELP_CLEAN_UP_COMMAND_STR;
520       mainMenu[j].name = "cleanUp";
521       mainMenu[j++].activateCallback = CleanUp;
522
523       mainMenu[j].type = MENU_BUTTON;
524       mainMenu[j].label = GETMESSAGE(20, 30, "Update");
525       mainMenu[j].label = XtNewString(mainMenu[j].label);
526       mainMenu[j].mnemonic = GETMESSAGE(20, 33, "U");
527       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
528       mainMenu[j].helpData = HELP_REREAD_COMMAND_STR;
529       mainMenu[j].name = "refresh";
530       mainMenu[j++].activateCallback = RereadDirectoryMenu;
531
532       /*************************************/
533       /* Create the 'Help' menu components */
534       /*************************************/
535
536       mainMenu[j].type = MENU_PULLDOWN_BUTTON;
537       mainMenu[j].isHelpBtn = True;
538       mainMenu[j].label = GETMESSAGE(20, 123, "Help");
539       mainMenu[j].label = XtNewString(mainMenu[j].label);
540       mainMenu[j].mnemonic = GETMESSAGE(20, 9, "H");
541       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
542       mainMenu[j].name = "help";
543       mainMenu[j++].helpData = HELP_HELP_MENU_STR;
544
545       mainMenu[j].type = SHARED_MENU_PANE;
546       mainMenu[j].name = "helpMenu";
547       mainMenu[j++].helpData = HELP_HELP_MENU_STR;
548
549       mainMenu[j].type = MENU_BUTTON;
550       mainMenu[j].label = GETMESSAGE(20, 105, "Overview");
551       mainMenu[j].label = XtNewString(mainMenu[j].label);
552       mainMenu[j].mnemonic = GETMESSAGE(20, 106, "v");
553       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
554       mainMenu[j].helpData = HELP_HELP_MENU_STR;
555       mainMenu[j].activateCallback = HelpRequestCB;
556       mainMenu[j].name = "introduction";
557       mainMenu[j++].activateData = HELP_HOME_TOPIC;
558
559       mainMenu[j].type = MENU_SEPARATOR;
560       mainMenu[j].name = "separator";
561       mainMenu[j++].helpCallback = NULL;
562
563       mainMenu[j].type = MENU_BUTTON;
564       mainMenu[j].label = GETMESSAGE(20, 148, "Table Of Contents");
565       mainMenu[j].label = XtNewString(mainMenu[j].label);
566       mainMenu[j].mnemonic = GETMESSAGE(20, 149, "C");
567       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
568       mainMenu[j].helpData = HELP_HELP_MENU_STR;
569       mainMenu[j].activateCallback = HelpRequestCB;
570       mainMenu[j].name = "toc";
571       mainMenu[j++].activateData = HELP_TOC_STR;
572
573       mainMenu[j].type = MENU_BUTTON;
574       mainMenu[j].label = GETMESSAGE(20, 107, "Tasks");
575       mainMenu[j].label = XtNewString(mainMenu[j].label);
576       mainMenu[j].mnemonic = GETMESSAGE(20, 108, "T");
577       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
578       mainMenu[j].helpData = HELP_HELP_MENU_STR;
579       mainMenu[j].activateCallback = HelpRequestCB;
580       mainMenu[j].name = "tasks";
581       mainMenu[j++].activateData = HELP_TASKS_STR;
582
583       mainMenu[j].type = MENU_BUTTON;
584       mainMenu[j].label = GETMESSAGE(20,109, "Reference");
585       mainMenu[j].label = XtNewString(mainMenu[j].label);
586       mainMenu[j].mnemonic = GETMESSAGE(20,110, "R");
587       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
588       mainMenu[j].helpData = HELP_HELP_MENU_STR;
589       mainMenu[j].activateCallback = HelpRequestCB;
590       mainMenu[j].name = "reference";
591       mainMenu[j++].activateData = HELP_REFERENCE_STR;
592
593       mainMenu[j].type = MENU_BUTTON;
594       mainMenu[j].label = GETMESSAGE(20,111, "On Item");
595       mainMenu[j].label = XtNewString(mainMenu[j].label);
596       mainMenu[j].mnemonic = GETMESSAGE(20,112, "O");
597       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
598       mainMenu[j].helpData = HELP_HELP_MENU_STR;
599       mainMenu[j].activateCallback = HelpRequestCB;
600       mainMenu[j].name = "onItem";
601       mainMenu[j++].activateData = HELP_HELP_MODE_STR;
602
603       mainMenu[j].type = MENU_SEPARATOR;
604       mainMenu[j].name = "separator";
605       mainMenu[j++].helpCallback = NULL;
606
607       usingHelp = &(mainMenu[j].widget);
608       mainMenu[j].type = MENU_BUTTON;
609       mainMenu[j].label = GETMESSAGE(20,113, "Using Help");
610       mainMenu[j].label = XtNewString(mainMenu[j].label);
611       mainMenu[j].mnemonic = GETMESSAGE(20,114, "U");
612       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
613       mainMenu[j].helpData = HELP_HELP_MENU_STR;
614       mainMenu[j].activateCallback = HelpRequestCB;
615       mainMenu[j].name = "usingHelp";
616       mainMenu[j++].activateData = HELP_HOME_TOPIC;
617    
618       mainMenu[j].type = MENU_SEPARATOR;
619       mainMenu[j].name = "separator";
620       mainMenu[j++].helpCallback = NULL;
621
622       fileManagerHelp = &(mainMenu[j].widget);
623       mainMenu[j].type = MENU_BUTTON;
624       mainMenu[j].label = GETMESSAGE(20,115, "About File Manager");
625       mainMenu[j].label = XtNewString(mainMenu[j].label);
626       mainMenu[j].mnemonic = GETMESSAGE(20,116, "A");
627       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
628       mainMenu[j].helpData = HELP_HELP_MENU_STR;
629       mainMenu[j].activateCallback = HelpRequestCB;
630       mainMenu[j].name = "version";
631       mainMenu[j++].activateData = HELP_ABOUT_STR;
632
633       applicationManagerHelp = &(mainMenu[j].widget);
634       mainMenu[j].type = MENU_BUTTON;
635       mainMenu[j].label = GETMESSAGE(20,157, "About Application Manager");
636       mainMenu[j].label = XtNewString(mainMenu[j].label);
637       mainMenu[j].mnemonic = GETMESSAGE(20,116, "A");
638       mainMenu[j].mnemonic = XtNewString(mainMenu[j].mnemonic);
639       mainMenu[j].helpData = HELP_HELP_MENU_STR;
640       mainMenu[j].activateCallback = HelpRequestCB;
641       mainMenu[j].name = "version";
642       mainMenu[j++].activateData = HELP_ABOUT_STR;
643    }
644
645    menu_bar = _DtCreateMenuSystem(main, "mainMenu", HelpRequestCB, 
646                                HELP_HELP_MENU_STR, createSharedComponents, 
647                                mainMenu, menuItemCount, GetMainMenuData,
648                                SetMenuSensitivity, RestoreMenuSensitivity);
649
650    /* Fine tune the menubar */
651    XtSetArg(args[0], XmNmarginWidth, 2);
652    XtSetArg(args[1], XmNmarginHeight, 2);
653    XtSetValues(menu_bar, args, 2);
654
655    file_mgr_rec->actions = *actionsId;
656    file_mgr_rec->action_pane = *actionsPaneId;
657    file_mgr_rec->directoryBarBtn = *directoryBarBtn;
658
659    file_mgr_rec->create_directoryBtn_child= NULL;
660    file_mgr_rec->create_dataBtn_child= NULL;
661
662    ActivateNoSelect (file_mgr_rec);
663
664    createSharedComponents = False;
665
666    return (menu_bar);
667 }
668
669
670 static void 
671 GetMainMenuData (
672    Widget mbar,
673    XtPointer * mainRecordPtr,
674    MenuDesc ** menuDescPtr,
675    int * menuItemCountPtr,
676    unsigned int ** globalMenuStatesPtr,
677    unsigned int ** viewMenuStatesPtr )
678
679 {
680    Arg args[1];
681    FileMgrRec * fileMgrRec;
682
683    XtSetArg(args[0], XmNuserData, &fileMgrRec);
684    XtGetValues(mbar, args, 1);
685    *mainRecordPtr = (XtPointer) fileMgrRec;
686    *menuDescPtr = mainMenu;
687    *menuItemCountPtr = menuItemCount;
688    *globalMenuStatesPtr = &currentMenuStates;
689    *viewMenuStatesPtr = &fileMgrRec->menuStates;
690    *actionsPaneId = fileMgrRec->action_pane;
691 }
692
693
694 void
695 GetHomeDir( )
696 {
697   struct passwd * pwInfo;
698
699   if( homeDir == NULL )
700   {
701     if ((homeDir = getenv("HOME_CLIENT")) == NULL)
702     {
703       if ((homeDir = getenv("HOME")) == NULL)
704       {
705         pwInfo = getpwuid (getuid());
706         homeDir = pwInfo->pw_dir;
707       }
708     }
709   }
710 }
711
712
713 /************************************************************************
714  *
715  *  ActivateSingleSelect
716  *      Activate the menu items that are to be active upon a
717  *      single selection.
718  *
719  ************************************************************************/
720
721 void
722 ActivateSingleSelect(
723         FileMgrRec *file_mgr_rec,
724         char *file_type )
725 {
726    DialogData * dialog_data;
727    FileMgrData * file_mgr_data;
728
729    if ((dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec)) == NULL)
730       return;
731    file_mgr_data = (FileMgrData *) dialog_data->data;
732
733    if ((strcmp(file_mgr_data->selection_list[0]->file_data->file_name, ".." ) == 0 )
734        || (strcmp(file_mgr_data->selection_list[0]->file_data->file_name, "." ) == 0 ) )
735    {
736      file_mgr_rec->menuStates |= TRASH | MODIFY | PUT_ON_DESKTOP;
737      file_mgr_rec->menuStates &= (~RENAME);
738    }
739    else
740      file_mgr_rec->menuStates |= RENAME | TRASH | MODIFY | PUT_ON_DESKTOP;
741
742    if ((strcmp(file_type, LT_BROKEN_LINK) != 0)
743        && (strcmp(file_type, LT_RECURSIVE_LINK) != 0)
744 /*
745        && (file_mgr_data->selection_list[0]->file_data->physical_type !=
746         DtDIRECTORY)
747 */
748        )
749    {
750       file_mgr_rec->menuStates |= MOVE | DUPLICATE | LINK;
751    }
752    else
753       file_mgr_rec->menuStates &= ~(MOVE | DUPLICATE | LINK);
754
755    /*  Update the action menu pane defined for the file type  */
756    /*  of the selected file.                                  */
757
758    UpdateActionMenuPane ((XtPointer)file_mgr_data, file_mgr_rec, file_type, 
759                    NOT_DESKTOP, 0, (Widget)NULL, 
760                    file_mgr_data->selection_list[0]->file_data->physical_type);
761 }
762
763
764
765 static void
766 UnmanageAllActionItems(
767         FileMgrRec *file_mgr_rec )
768 {
769   register int i, children;
770   XmManagerWidget action_pane;
771
772   action_pane = (XmManagerWidget) file_mgr_rec->action_pane;
773
774   for (i = SELECTED_MENU_MAX; i < action_pane->composite.num_children; ++i)
775   {
776     XtUnmanageChild (action_pane->composite.children[i]);
777   }
778 }
779
780 /************************************************************************
781  *
782  *  ActivateMultipleSelect
783  *      Activate (deactivate) the appropriate menu items when multiple
784  *      files are selected.
785  *
786  *
787  ************************************************************************/
788
789 void
790 ActivateMultipleSelect(
791         FileMgrRec *file_mgr_rec )
792 {
793    file_mgr_rec->menuStates |= TRASH | PUT_ON_DESKTOP;
794    file_mgr_rec->menuStates &= ~(RENAME | MOVE | DUPLICATE | LINK |
795                                  MODIFY);
796
797    UnmanageAllActionItems (file_mgr_rec);
798 }
799
800
801
802
803 /************************************************************************
804  *
805  *  ActivateNoSelect
806  *      Activate (deactivate) the appropriate menu items when no
807  *      files are selected.
808  *
809  ************************************************************************/
810
811 void
812 ActivateNoSelect(
813         FileMgrRec *file_mgr_rec )
814 {
815    file_mgr_rec->menuStates &= ~(RENAME | MOVE | DUPLICATE | LINK | TRASH |
816                                  MODIFY | PUT_ON_DESKTOP);
817
818    UnmanageAllActionItems (file_mgr_rec);
819 }
820
821
822
823 /************************************************************************
824  *
825  *  UnselectAll
826  *      Unselect all of the selected files.
827  *
828  ************************************************************************/
829
830 void
831 UnselectAll(
832         Widget w,
833         XtPointer client_data,
834         XtPointer call_data )
835 {
836    FileMgrRec * file_mgr_rec;
837    DialogData * dialog_data;
838    FileMgrData * file_mgr_data;
839    Arg args[1];
840    Widget mbar;
841
842    if ((int)client_data == FM_POPUP)
843      mbar = XtParent(w);
844    else
845      mbar = XmGetPostedFromWidget(XtParent(w));
846
847    XmUpdateDisplay (w);
848    XtSetArg(args[0], XmNuserData, &file_mgr_rec);
849    XtGetValues(mbar, args, 1);
850
851    /* Ignore accelerators received after we're unposted */
852    if ((dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec)) == NULL)
853       return;
854    file_mgr_data = (FileMgrData *) dialog_data->data;
855
856    DeselectAllFiles (file_mgr_data);
857    ActivateNoSelect (file_mgr_rec);
858
859    if( file_mgr_data == trashFileMgrData )
860      SensitizeTrashBtns();
861 }
862
863
864
865
866 /************************************************************************
867  *
868  *  SelectAll
869  *      Select all of file displayed.
870  *
871  ************************************************************************/
872
873 void
874 SelectAll(
875         Widget w,
876         XtPointer client_data,
877         XtPointer call_data )
878 {
879    FileMgrRec * file_mgr_rec;
880    DialogData * dialog_data;
881    FileMgrData * file_mgr_data;
882    Arg args[1];
883    Widget mbar;
884
885    if ((int)client_data == FM_POPUP)
886      mbar = XtParent(w);
887    else
888      mbar = XmGetPostedFromWidget(XtParent(w));
889
890    XmUpdateDisplay (w);
891    XtSetArg(args[0], XmNuserData, &file_mgr_rec);
892    XtGetValues(mbar, args, 1);
893
894    /* Ignore accelerators received after we're unposted */
895    if ((dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec)) == NULL)
896       return;
897    file_mgr_data = (FileMgrData *) dialog_data->data;
898
899    SelectAllFiles (file_mgr_data);
900
901    if( file_mgr_data == trashFileMgrData )
902      SensitizeTrashBtns();
903 }
904
905
906
907
908 /************************************************************************
909  *
910  *  RereadDirectoryMenu
911  *      Callback function invoked from the Reread Directory
912  *      menu item.  This function calls the file manager functions
913  *      which rereads and processes the directory.
914  *
915  ************************************************************************/
916
917 static void
918 RereadDirectoryMenu(
919         Widget w,
920         XtPointer client_data,
921         XtPointer call_data )
922 {
923    Arg args[1];
924    Widget mbar = XmGetPostedFromWidget(XtParent(w));
925    FileMgrRec * file_mgr_rec;
926    DialogData * dialog_data;
927
928    XmUpdateDisplay (w);
929
930    XtSetArg(args[0], XmNuserData, &file_mgr_rec);
931    XtGetValues(mbar, args, 1);
932
933    /* Ignore accelerators received after we're unposted */
934    if ((dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec)) == NULL)
935       return;
936
937    UnpostTextPath( (FileMgrData *) dialog_data->data );
938
939    /* force this directory to be updated */
940    FileMgrReread (file_mgr_rec);
941 }
942
943
944 /************************************************************************
945  *
946  *  ShowTrash
947  *      Display the Trash can.
948  *
949  ************************************************************************/ 
950 #if defined(ADD_SHOW_TRASH)
951
952 static void
953 ShowTrash(
954         Widget w,
955         XtPointer client_data,
956         XtPointer call_data )
957 {
958    XmUpdateDisplay (w);
959
960    TrashDisplayHandler (NULL, NULL, NULL, NULL, 0);
961 }
962 #endif
963
964
965 /************************************************************************
966  *
967  *  TrashFiles
968  *      Send the selected set of files to the trash.
969  *
970  ************************************************************************/ 
971
972 void
973 TrashFiles(
974         Widget w,
975         XtPointer client_data,
976         XtPointer call_data )
977 {
978    FileMgrRec * file_mgr_rec;
979    DialogData * dialog_data;
980    FileMgrData * file_mgr_data;
981    FileViewData * file_view_data;
982    Arg args[1];
983    Widget mbar;
984    DtActionArg * action_args;
985    int arg_count;
986    register int i;
987
988    if (!TrashIsInitialized())
989    {
990      char *title, *msg;
991
992      title = XtNewString(GetSharedMessage(TRASH_ERROR_TITLE));
993
994      msg = XtMalloc( strlen( GETMESSAGE(27,95, "Unable to access the Trash directory:\n   %s\n   All trash operations will not be performed.\n   The most common causes are:\n     - Network authentication.\n     - Insufficient disk space.\n     - Wrong permissions.") )
995                      + strlen( trash_dir )
996                      + 1 );
997
998      sprintf( msg, GETMESSAGE(27, 95, "Unable to access the Trash directory:\n   %s\n   All trash operations will not be performed.\n   The most common causes are:\n     - Network authentication.\n     - Insufficient disk space.\n     - Wrong permissions."), trash_dir );
999
1000      _DtMessage(toplevel, title, msg, NULL, HelpRequestCB);
1001      XtFree(title);
1002      XtFree(msg);
1003      return;
1004    }
1005
1006    XmUpdateDisplay (w);
1007
1008    if((int)client_data == NULL)
1009       mbar = XmGetPostedFromWidget(XtParent(w));
1010    else
1011       mbar =  XtParent(w);
1012
1013    XtSetArg(args[0], XmNuserData, &file_mgr_rec);
1014    XtGetValues(mbar, args, 1);
1015
1016    /* Ignore accelerators when we're insensitive */
1017    if(client_data == NULL)
1018       if ((file_mgr_rec->menuStates & TRASH) == 0)
1019          return;
1020
1021    /* Ignore accelerators received after we're unposted */
1022    if ((dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec)) == NULL)
1023       return;
1024    file_mgr_data = (FileMgrData *) dialog_data->data;
1025
1026    /* 'widget_dragged' is set in InitiateIconDrag() and
1027       is never set to NULL.  Because of this, after doing a desktop drag
1028       if you do a 'PutInTrash' on the File Manager window object, in
1029       TrashRemoveHandler() in Trash.c, it displays an incorrect message,
1030       So set it to NULL here. */
1031
1032    widget_dragged = NULL;
1033
1034    /* get the file_view_data object from which the menu was invoked */
1035    if (client_data == NULL)
1036      file_view_data = NULL;
1037    else
1038    {
1039      file_view_data = file_mgr_data->popup_menu_icon;
1040      /* The following test makes sure that the it is not the case of 
1041         multiple selected files */
1042      if (!file_mgr_data->selected_file_count && file_view_data == NULL)
1043        /* the object has gone away (probably deleted) */
1044        return;
1045
1046      file_mgr_data->popup_menu_icon = NULL;
1047
1048      if(file_view_data)
1049      {
1050        for(i = 0; i < file_mgr_data->selected_file_count; i++)
1051        {
1052           if(file_mgr_data->selection_list[i] == file_view_data)
1053           {
1054              file_view_data = NULL;
1055              break;
1056           }
1057        }
1058      }
1059    }
1060
1061    if(file_view_data)
1062       _DtBuildActionArgsWithSelectedFiles(&file_view_data, 1,
1063                                           &action_args, &arg_count);
1064    else
1065       _DtBuildActionArgsWithSelectedFiles(file_mgr_data->selection_list,
1066                                           file_mgr_data->selected_file_count,
1067                                           &action_args, &arg_count);
1068
1069    DtActionInvoke(file_mgr_rec->shell, TRASH_ACTION,
1070                   action_args, arg_count, NULL, NULL,
1071                   trash_dir, True, NULL, NULL);
1072
1073    _DtFreeActionArgs(action_args, arg_count);
1074 }
1075
1076
1077
1078
1079 /************************************************************************
1080  *
1081  *  NewView
1082  *      Create a new view of the currently display directory
1083  *
1084  ************************************************************************/ 
1085
1086 static void
1087 NewView(
1088         Widget w,
1089         XtPointer client_data,
1090         XtPointer call_data )
1091 {
1092    FileMgrRec * file_mgr_rec;
1093    DialogData * dialog_data;
1094    FileMgrData * file_mgr_data;
1095    Arg args[1];
1096    Widget mbar = XmGetPostedFromWidget(XtParent(w));
1097
1098
1099    XmUpdateDisplay (w);
1100    XtSetArg(args[0], XmNuserData, &file_mgr_rec);
1101    XtGetValues(mbar, args, 1);
1102
1103    /* Ignore accelerators received after we're unposted */
1104    if ((dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec)) == NULL)
1105       return;
1106    file_mgr_data = (FileMgrData *) dialog_data->data;
1107
1108    initiating_view = (XtPointer) file_mgr_data;
1109    if(file_mgr_data->restricted_directory != NULL)
1110    {
1111       special_view = True;
1112       special_treeType = file_mgr_data->show_type;
1113       special_viewType = file_mgr_data->view;
1114       special_orderType = file_mgr_data->order;
1115       special_directionType = file_mgr_data->direction;
1116       special_randomType = file_mgr_data->positionEnabled;
1117       special_restricted = XtNewString(file_mgr_data->restricted_directory);
1118       if(file_mgr_data->title == NULL)
1119          special_title = NULL;
1120       else
1121          special_title = XtNewString(file_mgr_data->title);
1122       special_helpVol = XtNewString(file_mgr_data->helpVol);
1123
1124       if(file_mgr_data->toolbox)
1125          GetNewView (file_mgr_data->host, file_mgr_data->current_directory,
1126                      file_mgr_data->restricted_directory, NULL, 0);
1127       else
1128          GetNewView (file_mgr_data->host, file_mgr_data->current_directory,
1129                      NULL, NULL, 0);
1130    }
1131    else
1132       GetNewView (file_mgr_data->host, file_mgr_data->current_directory, NULL,
1133                   NULL, 0);
1134    initiating_view = (XtPointer) NULL;
1135 }
1136
1137
1138
1139
1140 /************************************************************************
1141  *
1142  *  ChangeToHome
1143  *      Update the current view to show the home directory.
1144  *
1145  ************************************************************************/ 
1146
1147 void
1148 ChangeToHome(
1149         Widget w,
1150         XtPointer client_data,
1151         XtPointer call_data )
1152 {
1153    FileMgrRec * file_mgr_rec;
1154    DialogData * dialog_data;
1155    FileMgrData * file_mgr_data;
1156    char *host;
1157    char *ptr, *ptr1;
1158    Arg args[1];
1159    Widget mbar = XmGetPostedFromWidget(XtParent(w));
1160    Boolean found;
1161
1162    XmUpdateDisplay (w);
1163    if((int)client_data == FM_POPUP)
1164       mbar = XtParent(w);
1165    else
1166       mbar = XmGetPostedFromWidget(XtParent(w));
1167
1168    XtSetArg(args[0], XmNuserData, &file_mgr_rec);
1169    XtGetValues(mbar, args, 1);
1170
1171   /* Ignore accelerators when we're insensitive */
1172    if ((file_mgr_rec->menuStates & HOME) == 0)
1173       return;
1174
1175    /* Ignore accelerators received after we're unposted */
1176    if ((dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec)) == NULL)
1177       return;
1178    file_mgr_data = (FileMgrData *) dialog_data->data;
1179
1180    found = False;
1181
1182    if( homeDir == NULL )
1183      GetHomeDir( );
1184
1185    if((ptr = DtStrchr(homeDir, ':')) != NULL)
1186    {
1187       ptr1 = DtStrchr(homeDir, '/');
1188       if(strlen(ptr) > strlen(ptr1))
1189       {
1190          *ptr = '\0';
1191          host = XtNewString(homeDir);
1192          ptr1 = ptr;
1193          ptr++;
1194          homeDir = ptr;
1195          *ptr1 = ':';
1196          found = True;
1197       }
1198       else
1199          host = home_host_name;
1200    }
1201    else
1202       host = home_host_name;
1203
1204    if (file_mgr_data->cd_select != NULL)
1205    {
1206       XtFree (file_mgr_data->cd_select);
1207       file_mgr_data->cd_select = NULL;
1208    }
1209
1210    ShowNewDirectory( file_mgr_data, host, homeDir );
1211
1212    if( found )
1213       XtFree(host);
1214 }
1215
1216
1217
1218
1219 /************************************************************************
1220  *
1221  *  ChangeToParent
1222  *      Update the current view to show the parent directory.
1223  *
1224  ************************************************************************/ 
1225
1226 void
1227 ChangeToParent(
1228         Widget w,
1229         XtPointer client_data,
1230         XtPointer call_data )
1231 {
1232    FileMgrRec * file_mgr_rec;
1233    DialogData * dialog_data;
1234    FileMgrData * file_mgr_data;
1235    Arg args[1];
1236    Widget mbar = XmGetPostedFromWidget(XtParent(w));
1237    char host_name[MAX_PATH];
1238    Widget focus_widget;
1239
1240    XmUpdateDisplay (w);
1241    if((int)client_data == FM_POPUP)
1242       mbar = XtParent(w);
1243    else
1244       mbar = XmGetPostedFromWidget(XtParent(w));
1245
1246    XtSetArg(args[0], XmNuserData, &file_mgr_rec);
1247    XtGetValues(mbar, args, 1);
1248
1249   /* Ignore accelerators when we're insensitive */
1250    if ((file_mgr_rec->menuStates & MOVE_UP) == 0)
1251       return;
1252
1253    /* Ignore accelerators received after we're unposted */
1254    if ((dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec)) == NULL)
1255       return;
1256
1257    focus_widget = XmGetFocusWidget(file_mgr_rec->file_window);
1258    if (focus_widget)
1259    {
1260       if (focus_widget == file_mgr_rec->current_directory_text)
1261       {
1262          XmTextFieldReplace(focus_widget,
1263                             (XmTextPosition) 0,
1264                             XmTextFieldGetInsertionPosition(focus_widget),
1265                             "");
1266          return;
1267       }
1268       else if (strcmp(focus_widget->core.name, "nameChangeT") == 0)
1269       {
1270          XmTextReplace(focus_widget,
1271                        (XmTextPosition) 0,
1272                        XmTextFieldGetInsertionPosition(focus_widget),
1273                        "");
1274          return;
1275       }
1276    }
1277
1278    file_mgr_data = (FileMgrData *) dialog_data->data;
1279
1280    if (strcmp (file_mgr_data->current_directory, "/") == 0)
1281       return;
1282
1283    strcpy(host_name, file_mgr_data->host);
1284
1285    if (file_mgr_data->cd_select != NULL)
1286    {
1287       XtFree (file_mgr_data->cd_select);
1288       file_mgr_data->cd_select = NULL;
1289    }
1290
1291    ShowNewDirectory (file_mgr_data, host_name,
1292                      _DtPName (file_mgr_data->current_directory));
1293
1294    if(strcmp(file_mgr_data->current_directory,
1295                    file_mgr_data->restricted_directory) == 0)
1296    {
1297       _DtGlobalUpdateMenuItemState(*upBarBtn, MOVE_UP, False, &currentMenuStates);
1298       file_mgr_rec->menuStates &= ~(MOVE_UP);
1299    }
1300    else
1301    {
1302       file_mgr_rec->menuStates |= MOVE_UP;
1303       _DtGlobalUpdateMenuItemState(*upBarBtn, MOVE_UP, True, &currentMenuStates);
1304    }
1305 }
1306
1307
1308
1309
1310 /************************************************************************
1311  *
1312  *  SetMenuSensitivity
1313  *      Called before each menupane is posted; it will correctly set
1314  *      the menu button sensitivity for the view from which the menu
1315  *      is being posted; this is necessary because the menupanes are
1316  *      shared.  Only those buttons whose state is different than that
1317  *      of the current menu will be changed.
1318  *
1319  ************************************************************************/ 
1320
1321 static void
1322 SetMenuSensitivity(
1323         Widget w,
1324         XtPointer client_data,
1325         XtPointer call_data )
1326 {
1327    Arg args[1];
1328    Widget mbar;
1329    FileMgrRec * file_mgr_rec;
1330    XmMenuShellWidget mshell = (XmMenuShellWidget) w;
1331    DialogData * dialog_data;
1332    FileMgrData * file_mgr_data;
1333
1334    _XmGetActiveTopLevelMenu(mshell->composite.children[0], &mbar);
1335    XtSetArg(args[0], XmNuserData, &file_mgr_rec);
1336    XtGetValues(mbar, args, 1);
1337
1338    /* Enable the appropriate menu widgets based on the view type */
1339    if ((dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec)) != NULL)
1340    {
1341       struct stat file_info;
1342
1343       file_mgr_data = (FileMgrData *) dialog_data->data;
1344
1345       if( stat( file_mgr_data->current_directory, &file_info ) == 0 )
1346       {
1347         if( ! (file_info.st_mode & S_IXUSR)
1348             || ! (file_info.st_mode & S_IWUSR) )
1349         {
1350           file_mgr_rec->menuStates &= ~(CREATE_DIR) & ~(CREATE_FILE);
1351           _DtGlobalUpdateMenuItemState(*create_dataBtn, CREATE_FILE, False, &currentMenuStates);
1352           _DtGlobalUpdateMenuItemState(*create_directoryBtn, CREATE_DIR, False, &currentMenuStates);
1353         }
1354         else if( ! ( file_mgr_data->toolbox ) ||
1355                    ( file_mgr_data->toolbox && geteuid() == root_user ) )
1356         {
1357           file_mgr_rec->menuStates |= CREATE_DIR | CREATE_FILE;
1358           _DtGlobalUpdateMenuItemState(*create_dataBtn, CREATE_FILE, True, &currentMenuStates);
1359           _DtGlobalUpdateMenuItemState(*create_directoryBtn, CREATE_DIR, True, &currentMenuStates);
1360         }
1361       }
1362
1363       if (!PositioningEnabledInView(file_mgr_data))
1364          file_mgr_rec->menuStates &= ~(CLEAN_UP);
1365       else
1366          file_mgr_rec->menuStates |= CLEAN_UP;
1367
1368       XtManageChild(*defaultEnvBtn);
1369       if(file_mgr_data->restricted_directory == NULL)
1370       {
1371         if(strcmp(file_mgr_data->current_directory, "/") == 0)
1372         {
1373           file_mgr_rec->menuStates &= ~(MOVE_UP);
1374           _DtGlobalUpdateMenuItemState( *upBarBtn, MOVE_UP,
1375                                         False,&currentMenuStates);
1376         }
1377         else
1378         {
1379           file_mgr_rec->menuStates |= MOVE_UP;
1380           _DtGlobalUpdateMenuItemState(*upBarBtn, MOVE_UP, True,&currentMenuStates);
1381         }
1382
1383         if( homeDir == NULL )
1384           GetHomeDir( );
1385
1386         if( homeDir != NULL
1387             && strcmp( homeDir, file_mgr_data->current_directory ) != 0 )
1388         {
1389           file_mgr_rec->menuStates |= HOME;
1390           _DtGlobalUpdateMenuItemState(*homeBarBtn, HOME, True,
1391                                        &currentMenuStates);
1392         }
1393         else
1394         {
1395           file_mgr_rec->menuStates &= ~(HOME);
1396           _DtGlobalUpdateMenuItemState(*homeBarBtn, HOME, False,
1397                                        &currentMenuStates);
1398         }
1399
1400         file_mgr_rec->menuStates |= CHANGE_DIR;
1401         _DtGlobalUpdateMenuItemState(*change_directoryBtn, CHANGE_DIR, True, 
1402                                      &currentMenuStates);
1403         XtManageChild(*change_directoryBtn);
1404       }
1405       else
1406       {
1407          if(strcmp(file_mgr_data->current_directory, 
1408                          file_mgr_data->restricted_directory) == 0)
1409          {
1410             _DtGlobalUpdateMenuItemState(*upBarBtn, MOVE_UP, False, 
1411                                       &currentMenuStates);
1412             file_mgr_rec->menuStates &= ~(MOVE_UP);
1413          }
1414          else
1415          {
1416             file_mgr_rec->menuStates |= MOVE_UP;
1417             _DtGlobalUpdateMenuItemState(*upBarBtn, MOVE_UP, True,
1418                                       &currentMenuStates);
1419          }
1420          _DtGlobalUpdateMenuItemState(*homeBarBtn, HOME, False,&currentMenuStates);
1421          file_mgr_rec->menuStates &= ~(HOME);
1422          _DtGlobalUpdateMenuItemState(*change_directoryBtn, CHANGE_DIR, False, 
1423                                    &currentMenuStates);
1424          file_mgr_rec->menuStates &= ~(CHANGE_DIR);
1425       }
1426
1427       if(!restrictMode)
1428       {
1429 /*
1430          if(file_mgr_data->restricted_directory == NULL)
1431          {
1432 */
1433             _DtGlobalUpdateMenuItemState(*terminalBtn, TERMINAL, True,
1434                                       &currentMenuStates);
1435             file_mgr_rec->menuStates |= TERMINAL;
1436 /*
1437          }
1438          else
1439          {
1440             _DtGlobalUpdateMenuItemState(*terminalBtn, TERMINAL, False,
1441                                       &currentMenuStates);
1442             file_mgr_rec->menuStates &= ~(TERMINAL);
1443          }
1444 */
1445          XtManageChild(*terminalBtn);
1446       }
1447
1448       XtManageChild(*preferencesBtn);
1449       XtManageChild(*filterBtn);
1450       if(openDirType == CURRENT)
1451          XtManageChild(*newViewBtn);
1452       XtManageChild(*showHiddenMenu);
1453
1454 /*    Obsolete code.
1455       if(restrictMode)
1456       {
1457          char *ptr;
1458
1459          ptr = strrchr(users_home_dir, '/');
1460          *ptr = '\0';
1461          if(strcmp(file_mgr_data->current_directory, users_home_dir) == 0)
1462             file_mgr_rec->menuStates &= ~(MOVE_UP);
1463          else
1464             file_mgr_rec->menuStates |= MOVE_UP;
1465          *ptr = '/';
1466       }
1467 */
1468
1469       XtManageChild(*findBtn);
1470
1471       /* The problem is when users have 2 views
1472          and selected one file on one view and popup the
1473          'Selected' menu on the other view.
1474          The 'Selected' menu still show the other view action items.
1475       */
1476       if( file_mgr_data->selected_file_count == 0 )
1477         ActivateNoSelect( file_mgr_rec );
1478       else if( file_mgr_data->selected_file_count == 1 )
1479         ActivateSingleSelect( file_mgr_rec,
1480           file_mgr_data->selection_list[0]->file_data->logical_type );
1481       else
1482         ActivateMultipleSelect( file_mgr_rec );
1483
1484       if( file_mgr_data->toolbox )
1485       {
1486         if( geteuid() == root_user || access(file_mgr_data->current_directory,
1487                                         W_OK|X_OK) == 0)
1488         {
1489           file_mgr_rec->menuStates |= CREATE_DIR
1490                                       | CREATE_FILE;
1491           _DtGlobalUpdateMenuItemState(*create_dataBtn, CREATE_FILE, True,
1492                                        &currentMenuStates);
1493           _DtGlobalUpdateMenuItemState(*create_directoryBtn, CREATE_DIR, True,
1494                                        &currentMenuStates);
1495         }
1496         else
1497         {
1498           file_mgr_rec->menuStates &= ~(CREATE_DIR
1499                                         | CREATE_FILE
1500                                         | MOVE
1501                                         | LINK
1502                                         | RENAME
1503                                         | TRASH);
1504           _DtGlobalUpdateMenuItemState(*create_dataBtn, CREATE_FILE, False,
1505                                        &currentMenuStates);
1506           _DtGlobalUpdateMenuItemState(*create_directoryBtn, CREATE_DIR, False,
1507                                        &currentMenuStates);
1508           _DtGlobalUpdateMenuItemState(*moveBtn, MOVE, False,
1509                                        &currentMenuStates);
1510           _DtGlobalUpdateMenuItemState(*linkBtn, LINK, False,
1511                                        &currentMenuStates);
1512           _DtGlobalUpdateMenuItemState(*renameBtn, RENAME, False,
1513                                        &currentMenuStates);
1514         }
1515       }
1516    }
1517
1518    if(showFilesystem )
1519    {
1520       if (file_mgr_data->show_hid_enabled)
1521          XmToggleButtonGadgetSetState(*showHiddenMenu, True, False);
1522       else
1523          XmToggleButtonGadgetSetState(*showHiddenMenu, False, False);
1524    }
1525
1526    if( file_mgr_data->toolbox )
1527    {
1528      if( ! XtIsManaged( *applicationManagerHelp ) )
1529        XtManageChild( *applicationManagerHelp );
1530      if( XtIsManaged( *fileManagerHelp ) )
1531        XtUnmanageChild( *fileManagerHelp );
1532    }
1533    else
1534    {
1535      if( ! XtIsManaged( *fileManagerHelp ) )
1536        XtManageChild( *fileManagerHelp );
1537      if( XtIsManaged( *applicationManagerHelp ) )
1538        XtUnmanageChild( *applicationManagerHelp );
1539    }
1540
1541    _DtGlobalSetMenuSensitivity(w, client_data, call_data);
1542 }
1543
1544
1545
1546
1547 /************************************************************************
1548  *
1549  *  RestoreMenuSensitivity
1550  *      Called after each menupane is unposted; it will restore the
1551  *      sensitivity state of each menubutton to 'TRUE'; this is so that
1552  *      accelerators will work correctly.
1553  *
1554  ************************************************************************/ 
1555
1556 static void
1557 RestoreMenuSensitivity(
1558         Widget w,
1559         XtPointer client_data,
1560         XtPointer call_data )
1561 {
1562    Arg args[1];
1563    Widget mbar;
1564    FileMgrRec * file_mgr_rec;
1565    XmMenuShellWidget mshell = (XmMenuShellWidget) w;
1566    DialogData * dialog_data;
1567    FileMgrData * file_mgr_data;
1568
1569
1570    _XmGetActiveTopLevelMenu(mshell->composite.children[0], &mbar);
1571    XtSetArg(args[0], XmNuserData, &file_mgr_rec);
1572    XtGetValues(mbar, args, 1);
1573
1574    /* Enable the appropriate menu widgets based on the view type */
1575    dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
1576    file_mgr_data = (FileMgrData *) dialog_data->data;
1577
1578    _DtGlobalRestoreMenuSensitivity(w, client_data, call_data);
1579
1580    if(restrictMode) 
1581    {
1582       char *ptr;
1583
1584       ptr = strrchr(users_home_dir, '/');
1585       *ptr = '\0';
1586       if(strcmp(file_mgr_data->current_directory, users_home_dir) == 0)
1587       {
1588          _DtGlobalUpdateMenuItemState(*upBarBtn, MOVE_UP, False,
1589                                       &currentMenuStates);
1590       }
1591       else
1592       {
1593          _DtGlobalUpdateMenuItemState(*upBarBtn, MOVE_UP, True,
1594                                       &currentMenuStates);
1595       }
1596       *ptr = '/';
1597    }
1598    else
1599      if ((currentMenuStates & MOVE_UP) == 0)
1600          _DtGlobalUpdateMenuItemState(*upBarBtn, MOVE_UP, True,&currentMenuStates);
1601
1602    if ((currentMenuStates & CLEAN_UP) == 0)
1603       _DtGlobalUpdateMenuItemState(*cleanUpBtn, CLEAN_UP, True,&currentMenuStates);
1604
1605 }
1606
1607
1608
1609 /************************************************************************
1610  *
1611  *  TerminalCWD
1612  *      Bring up a terminal with the current working directory the directory
1613  *      of the dtfile view.
1614  *
1615  ************************************************************************/ 
1616
1617 static void 
1618 TerminalCWD (
1619      Widget w,
1620      XtPointer client_data,
1621      XtPointer call_data)
1622 {
1623    FileMgrRec * file_mgr_rec;
1624    DialogData * dialog_data;
1625    FileMgrData * file_mgr_data;
1626    Arg args[1];
1627    Widget mbar = XmGetPostedFromWidget(XtParent(w));
1628    char * pwd_host = NULL;
1629    char * pwd_dir = NULL;
1630
1631    XmUpdateDisplay (w);
1632    XtSetArg(args[0], XmNuserData, &file_mgr_rec);
1633    XtGetValues(mbar, args, 1);
1634
1635    /* Ignore accelerators received after we're unposted */
1636    if ((dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec)) == NULL)
1637       return;
1638    file_mgr_data = (FileMgrData *) dialog_data->data;
1639
1640    pwd_host = XtNewString(file_mgr_data->host);
1641    pwd_dir = XtNewString(file_mgr_data->current_directory);
1642
1643    DtActionInvoke(file_mgr_rec->shell, "Terminal", NULL, 0, NULL,
1644                   NULL, pwd_dir, True, NULL, NULL);
1645
1646    XtFree(pwd_host);
1647    XtFree(pwd_dir);
1648
1649 }