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