home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / x / volume13 / xdtm / part09 < prev    next >
Text File  |  1991-05-18  |  48KB  |  1,464 lines

  1. Path: uunet!olivea!apple!sun-barr!newstop!exodus!cogs.sussex.ac.uk
  2. From: eddyg@cogs.sussex.ac.uk (EdwardJ. Groenendaal)
  3. Newsgroups: comp.sources.x
  4. Subject: v13i014: xdtm - X Desktop Manager for the X Window System, Part09/11
  5. Message-ID: <13578@exodus.Eng.Sun.COM>
  6. Date: 19 May 91 00:03:55 GMT
  7. References: <csx-13i006:xdtm@uunet.UU.NET>
  8. Sender: news@exodus.Eng.Sun.COM
  9. Lines: 1452
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: Edward "J." Groenendaal <eddyg@cogs.sussex.ac.uk>
  13. Posting-number: Volume 13, Issue 14
  14. Archive-name: xdtm/part09
  15.  
  16. Submitted-by: eddyg@cste
  17. Archive-name: xdtm/part09
  18.  
  19. ---- Cut Here and feed the following to sh ----
  20. #!/bin/sh
  21. # This is part 09 of xdtm
  22. # ============= xdtm/main.c ==============
  23. if test ! -d 'xdtm'; then
  24.     echo 'x - creating directory xdtm'
  25.     mkdir 'xdtm'
  26. fi
  27. if test -f 'xdtm/main.c' -a X"$1" != X"-c"; then
  28.     echo 'x - skipping xdtm/main.c (File already exists)'
  29. else
  30. echo 'x - extracting xdtm/main.c (Text)'
  31. sed 's/^X//' << 'SHAR_EOF' > 'xdtm/main.c' &&
  32. X/*****************************************************************************
  33. X ** File          : main.c                                                  **
  34. X ** Purpose       : Initialise and Realise xdtm                             **
  35. X ** Author        : Edward Groenendaal                                      **
  36. X ** Date          : 18th Feb 1991                                           **
  37. X ** Documentation : Xdtm Design Folder                                      **
  38. X ** Related Files : All other xdtm files                                    **
  39. X *****************************************************************************/
  40. X
  41. X#include "xdtm.h"
  42. X#include "menus.h"
  43. X
  44. X/* local headers */
  45. X
  46. X#include <X11/Shell.h>
  47. X#include "Xedw/XedwForm.h"
  48. X
  49. X#include "bitmaps/xdtm.xbm"
  50. X
  51. Xpublic Widget topLevel;
  52. Xpublic String home;
  53. Xpublic AppData app_data;
  54. X
  55. Xstatic XtResource resources[] = {
  56. X  {   
  57. X    XtNviewWidth, 
  58. X    XtCViewWidth,
  59. X    XtRInt,
  60. X    sizeof(int),
  61. X    XtOffset(AppDataPtr, view_width),
  62. X    XtRImmediate,
  63. X    (caddr_t) 85,
  64. X  },
  65. X  { 
  66. X    XtNviewHeight,
  67. X    XtCViewHeight,
  68. X    XtRInt,
  69. X    sizeof(int),
  70. X    XtOffset(AppDataPtr, view_height),
  71. X    XtRImmediate,
  72. X    (caddr_t) 25,
  73. X  },
  74. X  {
  75. X    XtNmode,
  76. X    XtCMode,
  77. X    XtRString,
  78. X    sizeof(String),
  79. X    XtOffset(AppDataPtr, mode),
  80. X    XtRImmediate,
  81. X    (caddr_t) "icons",
  82. X  },
  83. X  {
  84. X    XtNdelay,
  85. X    XtCDelay,
  86. X    XtRInt,
  87. X    sizeof(int),
  88. X    XtOffset(AppDataPtr, delay),
  89. X    XtRImmediate,
  90. X    (caddr_t) 0,
  91. X  },
  92. X  {
  93. X    XtNdirOnExit,
  94. X    XtCDirOnExit,
  95. X    XtRBoolean,
  96. X    sizeof(Boolean),
  97. X    XtOffset(AppDataPtr, dironexit),
  98. X    XtRImmediate,
  99. X    (caddr_t) False,
  100. X  },
  101. X  {
  102. X    XtNconfigFile,
  103. X    XtCConfigFile,
  104. X    XtRString,
  105. X    sizeof(String),
  106. X    XtOffset(AppDataPtr, cffile),
  107. X    XtRImmediate,
  108. X    (caddr_t) NULL,
  109. X  },
  110. X  {
  111. X    XtNviewFont,
  112. X    XtCFont,
  113. X    XtRFontStruct,
  114. X    sizeof(XFontStruct*),
  115. X    XtOffset(AppDataPtr, view_font),
  116. X    XtRString,
  117. X    (caddr_t) "6x10",
  118. X  },
  119. X  {
  120. X    XtNdmFont,
  121. X    XtCFont,
  122. X    XtRFontStruct,
  123. X    sizeof(XFontStruct*),
  124. X    XtOffset(AppDataPtr, dm_font),
  125. X    XtRString,
  126. X    (caddr_t) "*-courier-bold-r-*-120-*",
  127. X  },
  128. X};
  129. X      
  130. X/*****************************************************************************
  131. X *                                main                                       *
  132. X *****************************************************************************/
  133. Xpublic void main(int argc, char *argv[])
  134. X{
  135. X  /* Parse the command line arguments, initialise the toplevel form, call
  136. X   * other initialising procedures, enter the X Main Loop.
  137. X   */
  138. X
  139. X  private void initialiseXdtm(void);
  140. X  extern void createMenuWidgets(Widget);          /* menus.c */
  141. X  extern void createAppManagerWidgets(Widget);    /* appman.c */
  142. X  extern void createFileManagerWidgets(Widget);   /* fileman.c */
  143. X  extern void createDialogWidgets(Widget);        /* dialogs.c */
  144. X
  145. X  extern Icon_mode current_mode;
  146. X  Widget topForm;
  147. X  Arg arglist[6];
  148. X  Cardinal i;
  149. X  static String Title = "X DeskTop Manager";
  150. X
  151. X  /* Command Line Arguments */
  152. X
  153. X  static XrmOptionDescRec options[] = {
  154. X    {"-dmfont",    "*directoryManager.font", XrmoptionSepArg, NULL},
  155. X    {"-cf",        ".configFile",            XrmoptionSepArg, NULL},
  156. X    {"-delay",     ".delay",                 XrmoptionSepArg, NULL}
  157. X  };
  158. X
  159. X  /* Initialise Program */
  160. X  if ((home = (String) getenv("HOME")) == NULL) {
  161. X    fprintf(stderr, "Warning: can't get environment variable HOME\n");
  162. X    home = XtNewString("/");
  163. X  } else 
  164. X    home = XtNewString(home);
  165. X
  166. X  /* Initialise the user interface */
  167. X
  168. X  topLevel = XtInitialize(argv[0], 
  169. X              "Xdtm", 
  170. X              options, 
  171. X              XtNumber(options),
  172. X              &argc, argv);
  173. X
  174. X  /* Check left over command line arguments */
  175. X  if (argc > 1) {
  176. X    /* incorrect command line arguments */
  177. X    int i;
  178. X    static int errs = False;
  179. X    
  180. X    for (i = 1; i < argc; i++) {
  181. X      if (!errs++)
  182. X    fprintf(stderr, "%s: command line option unknown:\n", argv[0]);
  183. X      fprintf(stderr, "option: %s\n\n", argv[i]);
  184. X    }
  185. X    fprintf(stderr, "%s understands all standard Xt "
  186. X        "command-line options.\n", argv[0]);
  187. X    fprintf(stderr, "Additional options are as follows:\n");
  188. X    fprintf(stderr, "Option              Valid Range\n");
  189. X    fprintf(stderr, "-dmfont             Any font, should be fixed width\n");
  190. X    fprintf(stderr, "-cf                 config filename\n");
  191. X    fprintf(stderr, "-delay              delay after copying, for NFS\n");
  192. X    exit(2);
  193. X  }
  194. X    
  195. X  /* get application resources */
  196. X  XtGetApplicationResources(topLevel,
  197. X                &app_data,
  198. X                resources,
  199. X                XtNumber(resources),
  200. X                NULL, 0);
  201. X
  202. X  /* check values of application resources */
  203. X  if (app_data.view_width < 1 || app_data.view_height < 1) {
  204. X    fprintf(stderr, "%s: error in resource settings:\n"
  205. X        "view window must be greater than 1x1 characters\n",
  206. X        argv[0]);
  207. X    exit(2);
  208. X  }
  209. X  
  210. X  if (strcmp(app_data.mode, "icons") == 0) 
  211. X    current_mode.mode = Icons;
  212. X  else if (strcmp(app_data.mode, "short") == 0)
  213. X    current_mode.mode = Short;
  214. X  else if (strcmp(app_data.mode,  "long") == 0)
  215. X    current_mode.mode = Long;
  216. X  else {
  217. X    fprintf(stderr, "%s: error in resource settings:\n"
  218. X        "mode must be one of either:\n"
  219. X        "'icons'     Show icons\n"
  220. X        "'short'     Just display file names\n"
  221. X        "'long'      Display file names with additional data.\n",
  222. X        argv[0]);
  223. X    exit(2);
  224. X  }
  225. X
  226. X  if (app_data.delay < 0 || app_data.delay > 5) {
  227. X    fprintf(stderr, "%s: error in resource settings:\n"
  228. X        "delay must be between 0 and 5\n", argv[0]);
  229. X    exit(2);
  230. X  }
  231. X
  232. X  i = 0;
  233. X  XtSetArg(arglist[i], XtNbottom, XtChainBottom); i++;
  234. X  XtSetArg(arglist[i], XtNtop,       XtChainTop); i++;
  235. X  XtSetArg(arglist[i], XtNleft,     XtChainLeft); i++;
  236. X  XtSetArg(arglist[i], XtNright,   XtChainRight); i++;
  237. X  XtSetArg(arglist[i], XtNhorizDistance,      5); i++;
  238. X  XtSetArg(arglist[i], XtNvertDistance,       5); i++;
  239. X  topForm = XtCreateManagedWidget("topForm",
  240. X                  xedwFormWidgetClass,
  241. X                  topLevel,
  242. X                  arglist, i);
  243. X
  244. X  /* Create Widgets in rest of program.
  245. X   * These must be called in this order, top left -> bottom right 
  246. X   */
  247. X  createMenuWidgets        (topForm);
  248. X  createAppManagerWidgets  (topForm);
  249. X  createFileManagerWidgets (topForm);
  250. X  createDialogWidgets      (topForm); 
  251. X
  252. X  i = 0;
  253. X  XtSetArg(arglist[i], XtNiconPixmap,
  254. X       XCreateBitmapFromData(XtDisplay(topLevel),       /* jcc */
  255. X                 XtScreen(topLevel)->root,
  256. X                 xdtm_bits, xdtm_width,
  257. X                 xdtm_height)); i++;
  258. X  XtSetArg(arglist[i], XtNtitle,   Title); i++;
  259. X  XtSetArg(arglist[i], XtNminWidth,  400); i++;
  260. X  XtSetArg(arglist[i], XtNminHeight, 200); i++;
  261. X  XtSetValues(topLevel, arglist, i);
  262. X
  263. X  tzset(); /* Make sure we have the time zone info so that the date 
  264. X        * functions work, probably don't *need* this.. */
  265. X
  266. X  /* Realize the widgets, (display program) then loop waiting for events */
  267. X
  268. X  XtRealizeWidget(topLevel);
  269. X
  270. X  initialiseXdtm();
  271. X
  272. X  XtMainLoop();
  273. X
  274. X}
  275. X
  276. X/*****************************************************************************
  277. X *                              quitQueryResult                              *
  278. X *****************************************************************************/
  279. Xpublic void quitQueryResult(Widget w, Boolean quit, caddr_t call_data)
  280. X{
  281. X  /* Action procedure called when a button is pressed in a quit dialog,
  282. X   *
  283. X   * - Takes a widget, quit - whether to quit, call_data - ignored.
  284. X   */
  285. X
  286. X  extern void destroy_quit_dialog(void);
  287. X
  288. X  /* Quit selected */
  289. X  if (quit == True)
  290. X    exit(0);
  291. X
  292. X  /* Cancel selected */
  293. X  destroy_quit_dialog();
  294. X}
  295. X
  296. X/*****************************************************************************
  297. X *                              initialiseXdtm                               *
  298. X *****************************************************************************/
  299. Xprivate void initialiseXdtm(void)
  300. X{
  301. X  /* initialise the program */
  302. X
  303. X  extern void initAppManager(Widget);               /* appman.c */
  304. X  extern void initFileManager(Widget);              /* fileman.c */
  305. X  extern void parsePreferences(Widget);           /* parse.c */
  306. X
  307. X  parsePreferences(topLevel);
  308. X  initAppManager(topLevel);
  309. X  initFileManager(topLevel);
  310. X}
  311. SHAR_EOF
  312. chmod 0644 xdtm/main.c ||
  313. echo 'restore of xdtm/main.c failed'
  314. Wc_c="`wc -c < 'xdtm/main.c'`"
  315. test 8048 -eq "$Wc_c" ||
  316.     echo 'xdtm/main.c: original size 8048, current size' "$Wc_c"
  317. fi
  318. # ============= xdtm/map.c ==============
  319. if test -f 'xdtm/map.c' -a X"$1" != X"-c"; then
  320.     echo 'x - skipping xdtm/map.c (File already exists)'
  321. else
  322. echo 'x - extracting xdtm/map.c (Text)'
  323. sed 's/^X//' << 'SHAR_EOF' > 'xdtm/map.c' &&
  324. X/*****************************************************************************
  325. X ** File          : map.c                                                   **
  326. X ** Purpose       : Initialise and Realise map dialog                       **
  327. X ** Author        : Edward Groenendaal                                      **
  328. X ** Date          : April 1991                                              **
  329. X ** Documentation : Xdtm Design Folder                                      **
  330. X ** Related Files :                                                         **
  331. X *****************************************************************************/
  332. X
  333. X#include "xdtm.h"
  334. X#include "parse.h"        /* For SelOptions, ESIZE */
  335. X#include <X11/Shell.h>
  336. X#include <X11/Xaw/Label.h>
  337. X#include <X11/Xaw/Command.h>
  338. X#include <X11/Xaw/AsciiText.h>
  339. X#include "Xedw/XedwForm.h"
  340. X#include "Xedw/XedwList.h"
  341. X
  342. Xextern void realize_dialog(Widget);
  343. X
  344. X/* Widgets */
  345. X
  346. Xprivate Widget mappopup;        /* For mapping prog over files */
  347. Xprivate Widget mapform;
  348. Xprivate Widget maplabel;
  349. Xprivate Widget mappromptlabel;
  350. Xprivate Widget maptext;
  351. Xprivate Widget mapCancel;
  352. Xprivate Widget mapOK;
  353. X
  354. X/*****************************************************************************
  355. X *                                init_map                                   *
  356. X *****************************************************************************/
  357. Xpublic void init_map(Widget top)
  358. X{
  359. X  /* Initialise the map and select dialog Widgets, they actually shar the
  360. X   * same ones.
  361. X   */
  362. X
  363. X  Arg arglist[7];
  364. X  Cardinal i;
  365. X  XtTranslations mapTranslations;
  366. X
  367. X  /* Translations for the text widget */
  368. X  static char defaultTranslations[] = 
  369. X    "Ctrl<Key>A:        beginning-of-line() \n\
  370. X     Ctrl<Key>E:        end-of-line() \n\
  371. X     <Key>Escape:       beginning-of-line() kill-to-end-of-line() \n\
  372. X     <Key>Right:     forward-character() \n\
  373. X     <Key>Left:         backward-character() \n\
  374. X     <Key>Delete:       delete-previous-character() \n\
  375. X     <Key>BackSpace:    delete-previous-character() \n\
  376. X     <Key>:             insert-char() \n\
  377. X     <FocusIn>:         focus-in() \n\
  378. X     <FocusOut>:        focus-out() \n\
  379. X     <BtnDown>:         select-start()";
  380. X
  381. X
  382. X  mappopup       = XtCreatePopupShell("mappopup",
  383. X                      transientShellWidgetClass,
  384. X                      top,
  385. X                      NULL, 0);
  386. X
  387. X  mapform        = XtCreateManagedWidget("mapform",
  388. X                     xedwFormWidgetClass,
  389. X                     mappopup,
  390. X                     NULL, 0);
  391. X
  392. X  i = 0;
  393. X  XtSetArg(arglist[i], XtNborderWidth,           0); i++;
  394. X  XtSetArg(arglist[i], XtNfullWidth,          True); i++;
  395. X  XtSetArg(arglist[i], XtNjustify, XtJustifyCenter); i++;
  396. X  maplabel       = XtCreateManagedWidget("maplabel",
  397. X                     labelWidgetClass,
  398. X                     mapform,
  399. X                     arglist, i);
  400. X
  401. X  i = 1;
  402. X  XtSetArg(arglist[i], XtNfromVert, maplabel); i++;
  403. X  mappromptlabel = XtCreateManagedWidget("mappromptlabel",
  404. X                     labelWidgetClass,
  405. X                     mapform,
  406. X                     arglist, i);
  407. X  
  408. X  i = 2;
  409. X  XtSetArg(arglist[i], XtNfromHoriz, mappromptlabel); i++;
  410. X  XtSetArg(arglist[i], XtNfullWidth,           True); i++;
  411. X  XtSetArg(arglist[i], XtNeditType,     XawtextEdit); i++;
  412. X  maptext        = XtCreateManagedWidget("maptext",
  413. X                     asciiTextWidgetClass,
  414. X                     mapform,
  415. X                     arglist, i);
  416. X  
  417. X  i = 0;
  418. X  XtSetArg(arglist[i], XtNjustify, XtJustifyCenter); i++;
  419. X  XtSetArg(arglist[i], XtNfromVert,        maptext); i++;
  420. X  XtSetArg(arglist[i], XtNlabel,          "Cancel"); i++;
  421. X  mapCancel      = XtCreateManagedWidget("mapCancel",
  422. X                     commandWidgetClass,
  423. X                     mapform,
  424. X                     arglist, i);
  425. X
  426. X  i = 2;
  427. X  XtSetArg(arglist[i], XtNfromHoriz,   mapCancel); i++;
  428. X  XtSetArg(arglist[i], XtNwidthLinked, mapCancel); i++;
  429. X  XtSetArg(arglist[i], XtNlabel,            "OK"); i++;
  430. X  mapOK          = XtCreateManagedWidget("mapOK",
  431. X                     commandWidgetClass,
  432. X                     mapform,
  433. X                     arglist, i);
  434. X
  435. X
  436. X  XtUninstallTranslations(maptext);
  437. X  mapTranslations = XtParseTranslationTable(defaultTranslations);
  438. X  XtOverrideTranslations(maptext, mapTranslations);
  439. X
  440. X}
  441. X
  442. X/*****************************************************************************
  443. X *                                 map_dialog                                *
  444. X *****************************************************************************/
  445. Xpublic void map_dialog(Boolean map)
  446. X{
  447. X  /* if map is true then put map dialog up, otherwise use the 
  448. X   * select dialog.
  449. X   */
  450. X
  451. X  private void mapQueryResult(Widget, Boolean, caddr_t);
  452. X  private void selectQueryResult(Widget, Boolean, caddr_t);
  453. X  Arg arglist[1];
  454. X
  455. X  XtSetArg(arglist[0], XtNstring, "");
  456. X  XtSetValues(maptext, arglist, 1);
  457. X
  458. X  if (map == True) {
  459. X    XtSetArg(arglist[0], XtNlabel, " Map Program over Selected Files ");
  460. X    XtSetValues(maplabel, arglist, 1);
  461. X
  462. X    XtSetArg(arglist[0], XtNlabel, "Program:");
  463. X    XtSetValues(mappromptlabel, arglist, 1);
  464. X
  465. X    XtAddCallback(mapCancel, XtNcallback, mapQueryResult, False);
  466. X    XtAddCallback(mapOK,     XtNcallback, mapQueryResult, True);
  467. X  } else {
  468. X    XtSetArg(arglist[0], XtNlabel, "Select Files by Regular Expression"); 
  469. X    XtSetValues(maplabel, arglist, 1);
  470. X
  471. X    XtSetArg(arglist[0], XtNlabel, "RegExp: ");
  472. X    XtSetValues(mappromptlabel, arglist, 1);
  473. X
  474. X    XtAddCallback(mapCancel, XtNcallback, selectQueryResult, False);
  475. X    XtAddCallback(mapOK,     XtNcallback, selectQueryResult, True);
  476. X  }
  477. X
  478. X  realize_dialog(mappopup);
  479. X}
  480. X
  481. X/*****************************************************************************
  482. X *                         destroy_map_dialog                                *
  483. X *****************************************************************************/
  484. Xprivate void destroy_map_dialog(void)
  485. X{
  486. X  /* Popdown the map dialog, remove the callbacks on the buttons so that
  487. X   * they can be reset next time map_dialog is called, in case the select
  488. X   * dialog is required.
  489. X   */
  490. X
  491. X  Arg arglist[1];
  492. X
  493. X  XtPopdown(mappopup);
  494. X
  495. X  XtRemoveAllCallbacks(mapCancel, XtNcallback);
  496. X  XtRemoveAllCallbacks(mapOK,     XtNcallback);
  497. X}
  498. X
  499. X/*****************************************************************************
  500. X *                             mapQueryResult                                *
  501. X *****************************************************************************/
  502. Xprivate void mapQueryResult(Widget w, Boolean ok, caddr_t call_data)
  503. X{
  504. X  /* Either map a program over the selected files if OK was pressed,
  505. X   * otherwise do nothing.
  506. X   */
  507. X
  508. X  extern String build_arguments(String, SelOptions);
  509. X  extern int execute(String, String, String, Boolean);
  510. X  extern void setCursor(Cursor);
  511. X  extern Cursor busy;
  512. X  String mapprogram, program, filename;
  513. X  Arg arglist[1];
  514. X
  515. X  destroy_map_dialog();
  516. X
  517. X  if (ok == True) {
  518. X    setCursor(busy);
  519. X    /* get program name from text widget */
  520. X    XtSetArg(arglist[0], XtNstring, &mapprogram);
  521. X    XtGetValues(maptext, arglist, 1);
  522. X
  523. X    program = XtNewString(mapprogram);
  524. X
  525. X    /* extract filename from program */
  526. X    filename = XtNewString(program);
  527. X    filename = strtok(filename, " ");
  528. X    
  529. X    /* Get list of files */
  530. X    if ((program = build_arguments(program, M_SEL)) == NULL) 
  531. X      fprintf(stderr, "Programmer Error: map was selected without files\n");
  532. X    else
  533. X      execute(NULL, filename, program, False);
  534. X
  535. X    setCursor(NULL);
  536. X  }
  537. X}
  538. X
  539. X/*****************************************************************************
  540. X *                             selectQueryResult                             *
  541. X *****************************************************************************/
  542. Xprivate void selectQueryResult(Widget w, Boolean ok, caddr_t call_data)
  543. X{
  544. X  /* If Ok was pressed then select files using the regular expression
  545. X   * contained within the text widget.
  546. X   */
  547. X
  548. X  extern void highlight_by_re(String);
  549. X  extern void setCursor(Cursor);
  550. X  extern Cursor busy;
  551. X  String re;
  552. X  Arg arglist[1];
  553. X
  554. X  destroy_map_dialog();
  555. X
  556. X  if (ok == True) {
  557. X    /* Get regular expression */
  558. X    setCursor(busy);
  559. X    XtSetArg(arglist[0], XtNstring, &re);
  560. X    XtGetValues(maptext, arglist, 1);
  561. X    
  562. X    highlight_by_re(re);
  563. X
  564. X    setCursor(NULL);
  565. X  }
  566. X}
  567. SHAR_EOF
  568. chmod 0644 xdtm/map.c ||
  569. echo 'restore of xdtm/map.c failed'
  570. Wc_c="`wc -c < 'xdtm/map.c'`"
  571. test 7904 -eq "$Wc_c" ||
  572.     echo 'xdtm/map.c: original size 7904, current size' "$Wc_c"
  573. fi
  574. # ============= xdtm/menus.c ==============
  575. if test -f 'xdtm/menus.c' -a X"$1" != X"-c"; then
  576.     echo 'x - skipping xdtm/menus.c (File already exists)'
  577. else
  578. echo 'x - extracting xdtm/menus.c (Text)'
  579. sed 's/^X//' << 'SHAR_EOF' > 'xdtm/menus.c' &&
  580. X/*****************************************************************************
  581. X ** File          : menus.c                                                 **
  582. X ** Purpose       : Create, and handle the pull down menus                  **
  583. X ** Author        : Edward Groenendaal                                      **
  584. X ** Date          : 18th Feb 1991                                           **
  585. X ** Documentation : Xdtm Design Folder                                      **
  586. X ** Related Files :                                                         **
  587. X *****************************************************************************/
  588. X
  589. X#include "xdtm.h"
  590. X#include "menus.h"
  591. X#include <sys/stat.h>
  592. X#include <X11/Xaw/MenuButton.h>
  593. X#include <X11/Xaw/SimpleMenu.h>
  594. X#include <X11/Xaw/SmeBSB.h>
  595. X#include <X11/Xaw/SmeLine.h>
  596. X
  597. X#include "Xedw/XedwList.h"
  598. X#include "Xedw/XedwForm.h"
  599. X#include "bitmaps/Tick"
  600. X#include "bitmaps/EmptyTick"
  601. X
  602. Xstatic MenuContents fileMenuStrings[] = {
  603. X  { "about",     "About Xdtm...",  About,     noflag },
  604. X  { "help",      "Help",           Help,      noflag },
  605. X  {  LINE,        NULL,            0,         noflag },
  606. X  { "new",       "New File",       New,       noflag },
  607. X  { "duplicate", "Duplicate File", Duplicate, noflag },
  608. X  {  LINE,        NULL,            0,         noflag },
  609. X  { "copy",      "Copy files",     Copy,      noflag },
  610. X  { "move",      "Move files",     Move,      noflag },
  611. X  { "trash",     "Delete files",   Trash,     noflag },
  612. X  {  LINE,        NULL,            0,         noflag },
  613. X  { "quit",      "Quit Program",   Quit,      noflag },
  614. X};
  615. X
  616. Xstatic MenuContents optionMenuStrings[] = {
  617. X  { "map",      "Map Program over Files",     Map,    noflag },
  618. X  { "select",   "Select Files by Template",   Select, noflag },
  619. X};
  620. X
  621. Xstatic MenuContents viewMenuStrings[] = {
  622. X  { "icons",    "Show Icons",     Icons,   flagged },
  623. X  { "short",    "No Icons",       Short,   flagged },
  624. X  {  LINE,       NULL,            0,       flagged },
  625. X  { "long",     "Long Listing",   Long,    flagged },
  626. X  { "options",  "Options",        Options, flagged },
  627. X};
  628. X
  629. XCardinal fileMenuSize   = sizeof(fileMenuStrings)   /
  630. X                                sizeof(fileMenuStrings[0]);
  631. XCardinal optionMenuSize = sizeof(optionMenuStrings) /
  632. X                                sizeof(optionMenuStrings[0]);
  633. XCardinal viewMenuSize   = sizeof(viewMenuStrings)   /
  634. X                                sizeof(viewMenuStrings[0]);
  635. X
  636. Xpublic Arg chain_position[] = {  XtNtop,     XtChainTop,
  637. X                 XtNbottom,  XtChainBottom,
  638. X                 XtNleft,    XtChainLeft,
  639. X                 XtNright,   XtChainRight,
  640. X                 NULL,       NULL
  641. X                  };
  642. X
  643. XCardinal chain_size = sizeof(chain_position)/sizeof(chain_position[0]);
  644. X
  645. Xpublic Pixmap tick, emptytick;
  646. Xpublic Widget menuBar;
  647. X
  648. Xpublic Icon_mode current_mode;
  649. X
  650. X/*****************************************************************************
  651. X *                        createManuWidgets                                  *
  652. X *****************************************************************************/
  653. Xpublic void createMenuWidgets(Widget w)
  654. X{
  655. X  /* This procedure creates the widgets for the menu bar. 
  656. X   * It's 4:41 in the morning, I'm tired, but the work must go on..
  657. X   * so it's time to smile :-) Always look on the bright side of life... 
  658. X   */
  659. X   
  660. X  private void menuSelect(Widget, Cardinal, caddr_t);
  661. X  public  void createMenu(Widget, MenuContents[], Cardinal, 
  662. X              void (*)(Widget, Cardinal, caddr_t) );
  663. X
  664. X  Widget fileMenuButton, optionMenuButton, viewMenuButton, selectionMenuButton;
  665. X  Widget fileMenu, optionMenu, viewMenu;
  666. X  Arg arglist[7], *newlist;
  667. X  Cardinal i;
  668. X
  669. X  i = 0;
  670. X  XtSetArg(arglist[i], XtNrubberWidth,  False);    i++;
  671. X  XtSetArg(arglist[i], XtNrubberHeight, False);    i++;
  672. X  XtSetArg(arglist[i], XtNborderWidth,      0);    i++;
  673. X  newlist = XtMergeArgLists(arglist, i, chain_position, chain_size);
  674. X  menuBar          =   XtCreateManagedWidget("menuBar",
  675. X                         xedwFormWidgetClass,
  676. X                         w,
  677. X                         newlist, i + chain_size);
  678. X  XtFree(newlist);
  679. X
  680. X  i = 0;
  681. X  XtSetArg(arglist[i], XtNhighlightThickness, 0); i++;
  682. X  XtSetArg(arglist[i], XtNborderWidth,        0); i++;
  683. X  XtSetArg(arglist[i], XtNmenuName,  "fileMenu"); i++;
  684. X  XtSetArg(arglist[i], XtNlabel,         "File"); i++;
  685. X  XtSetArg(arglist[i], XtNvertDistance,       0); i++;
  686. X  fileMenuButton   =   XtCreateManagedWidget("fileMenuButton",
  687. X                         menuButtonWidgetClass,
  688. X                         menuBar,
  689. X                         arglist, i);
  690. X
  691. X  i = 2;
  692. X  XtSetArg(arglist[i], XtNmenuName,         "optionMenu"); i++;
  693. X  XtSetArg(arglist[i], XtNlabel,               "Options"); i++;
  694. X  XtSetArg(arglist[i], XtNfromHoriz,      fileMenuButton); i++;
  695. X  XtSetArg(arglist[i], XtNvertDistance,                0); i++;
  696. X  optionMenuButton =   XtCreateManagedWidget("optionMenuButton",
  697. X                         menuButtonWidgetClass,
  698. X                         menuBar,
  699. X                         arglist, i);
  700. X
  701. X  i = 2;
  702. X  XtSetArg(arglist[i], XtNmenuName,        "viewMenu"); i++;
  703. X  XtSetArg(arglist[i], XtNlabel,               "View"); i++;
  704. X  XtSetArg(arglist[i], XtNfromHoriz, optionMenuButton); i++;
  705. X  XtSetArg(arglist[i], XtNvertDistance,       0); i++;
  706. X  viewMenuButton   =   XtCreateManagedWidget("viewMenuButton",
  707. X                         menuButtonWidgetClass,
  708. X                         menuBar,
  709. X                         arglist, i);
  710. X
  711. X  fileMenu         =   XtCreatePopupShell("fileMenu",
  712. X                      simpleMenuWidgetClass,
  713. X                      fileMenuButton,
  714. X                      NULL, 0);
  715. X  
  716. X  optionMenu       =   XtCreatePopupShell("optionMenu",
  717. X                      simpleMenuWidgetClass,
  718. X                      optionMenuButton,
  719. X                      NULL, 0);
  720. X  
  721. X  viewMenu         =   XtCreatePopupShell("viewMenu",
  722. X                      simpleMenuWidgetClass,
  723. X                      viewMenuButton,
  724. X                      NULL, 0);
  725. X
  726. X  tick             =   XCreateBitmapFromData(XtDisplay(w), 
  727. X                         RootWindowOfScreen(XtScreen(w)),
  728. X                         tick_bits, tick_width, 
  729. X                         tick_height);
  730. X
  731. X  emptytick        =   XCreateBitmapFromData(XtDisplay(w), 
  732. X                         RootWindowOfScreen(XtScreen(w)),
  733. X                         EmptyTick_bits, 
  734. X                         EmptyTick_width, 
  735. X                         EmptyTick_height);
  736. X
  737. X  /* create the menu panes from the arrays defined at the top of this 
  738. X   * file. 
  739. X   */
  740. X  createMenu(fileMenu, fileMenuStrings, fileMenuSize, menuSelect);
  741. X  
  742. X  createMenu(optionMenu, optionMenuStrings, optionMenuSize, menuSelect);
  743. X  
  744. X  createMenu(viewMenu, viewMenuStrings, viewMenuSize, menuSelect);
  745. X
  746. X  /* Default long listing options */
  747. X  current_mode.options = (PERMS | NLINKS | OWNER | GROUP | SIZE);
  748. X  
  749. X}
  750. X
  751. X
  752. X/*****************************************************************************
  753. X *                                createMenu                                 *
  754. X *****************************************************************************/
  755. Xpublic void createMenu(Widget menu, MenuContents menuStrings[], 
  756. X               Cardinal menuSize, void (*function)())
  757. X{
  758. X  /* Given a MenuContents stucture, the number of entries and a function
  759. X   * that should be called when that pane is pressed, this procedure
  760. X   * creates the menu panes for the menu widget 'menu'
  761. X   */
  762. X
  763. X  Widget menuEntry;
  764. X  Cardinal i, n;
  765. X  Arg arglist[3];
  766. X
  767. X  for(n=0; n < menuSize; n++) {
  768. X    MenuContents entry = menuStrings[n];
  769. X    String widgetname = entry.paneName;
  770. X    if (!strcmp(LINE, widgetname))
  771. X      menuEntry = XtCreateManagedWidget(widgetname, smeLineObjectClass,
  772. X                    menu, NULL, 0);
  773. X    else {
  774. X      i = 0;
  775. X      XtSetArg(arglist[i], XtNlabel, entry.paneLabel); i++;
  776. X      if (entry.set == flagged) {
  777. X    XtSetArg(arglist[i], XtNleftMargin, (tick_width*1.5)); i++;
  778. X    if (entry.paneNumber == current_mode.mode) {
  779. X      XtSetArg(arglist[i], XtNleftBitmap, tick); i++; 
  780. X    } else {
  781. X      XtSetArg(arglist[i], XtNleftBitmap,           None); i++; 
  782. X    }
  783. X      }
  784. X      
  785. X      menuEntry = XtCreateManagedWidget(widgetname, smeBSBObjectClass,
  786. X                    menu, arglist, i);
  787. X      if (entry.paneNumber == current_mode.mode && entry.set == flagged) 
  788. X    current_mode.w = menuEntry;
  789. X
  790. X      XtAddCallback(menuEntry, XtNcallback, function,
  791. X            (caddr_t) entry.paneNumber);
  792. X    }
  793. X  }
  794. X}
  795. X
  796. X/*****************************************************************************
  797. X *                              menuSelect                                   *
  798. X *****************************************************************************/
  799. Xprivate void menuSelect(Widget w, Cardinal paneNumber, caddr_t rubbish)
  800. X{
  801. X  /* This procedure is called when a pane is pressed in any of the main
  802. X   * three pull down menus.
  803. X   *
  804. X   * - Takes the paneNumber of the pane selected. Rest is discarded.
  805. X   */
  806. X
  807. X  extern void map_dialog(Boolean);
  808. X  extern void quit_dialog(void);
  809. X  extern void query_dialog(String, Boolean);
  810. X  extern void displayfile(String);
  811. X  extern void newfile_dialog(Boolean, String, Boolean);
  812. X  extern void button_selected(Widget, Cardinal, caddr_t);
  813. X  extern void listoption_dialog(void);
  814. X  extern Boolean directoryManagerNewDirectory(String);
  815. X  extern String getfilename(String);
  816. X  extern void setCursor(Cursor);
  817. X  extern Cursor busy;
  818. X  extern String cwd;
  819. X  extern Widget directoryManager;
  820. X  XedwListReturnStruct *highlighted;
  821. X  String filename, fullname, level;
  822. X  struct stat filestatus;
  823. X  Arg arglist[6];
  824. X  Cardinal i;
  825. X
  826. X  /* Which pane was selected */
  827. X  switch (paneNumber) {
  828. X  case About:
  829. X    /* display about dialog */
  830. X
  831. X    level = XtMalloc (sizeof(char) * 25);
  832. X    sprintf(level, "   Xdtm v%d.%d   ", RELEASE, PATCHLEVEL);
  833. X    query_dialog(level, False);
  834. X    break;
  835. X  case Help:
  836. X    /* If help file is readable show it */
  837. X
  838. X    if (access(SYSTEM_HELP, R_OK) == 0) 
  839. X      displayfile(SYSTEM_HELP);
  840. X    else
  841. X      query_dialog("Help not found!", False); /* Error dialog */
  842. X    break;
  843. X
  844. X  case New:
  845. X    /* Create a newfile */
  846. X
  847. X    newfile_dialog(False, NULL, False);
  848. X    break;
  849. X
  850. X  case Duplicate:
  851. X    /* Find out whether highlighted file is a regular file or a directory */
  852. X
  853. X    highlighted = XedwListShowCurrent(directoryManager);
  854. X    if (highlighted->xedwList_index != XDTM_LIST_NONE) {
  855. X      if (highlighted->next != NULL) 
  856. X    query_dialog("Only one file!", False);
  857. X      else {
  858. X    filename = getfilename(highlighted->string);
  859. X    fullname=(String) XtMalloc((strlen(filename)+strlen(cwd)+3) * 
  860. X                   sizeof(char));
  861. X    strcpy(fullname, cwd);
  862. X    if (strcmp(cwd, "/") != 0)
  863. X      strcat(fullname, "/");
  864. X    strcat(fullname, filename);
  865. X    if (stat(fullname, &filestatus) == -1) {
  866. X      fprintf(stderr,"xdtm: ARRRGGHHH stat error\n");
  867. X    } else {
  868. X      if ((filestatus.st_mode & S_IFMT) == S_IFDIR) 
  869. X        /* Is a directory */
  870. X        newfile_dialog(True, filename, True);
  871. X      else if ((filestatus.st_mode & S_IFMT) == S_IFREG) 
  872. X        newfile_dialog(True, filename, False);
  873. X      else 
  874. X        query_dialog("Wrong file type!", False);
  875. X    }
  876. X    XtFree(fullname);
  877. X      }
  878. X    } else
  879. X      fprintf(stderr, "Error: Duplicate selected when should have been"
  880. X          " disabled\n");
  881. X    break;
  882. X
  883. X  case Getinfo:
  884. X    /* Maybe I'll get round to doing this one sometime, it should display
  885. X     * a popup with the filename and permissions in, then allow you to
  886. X     * change them. 
  887. X     */
  888. X    query_dialog("Not implemented!", False);
  889. X    break;
  890. X
  891. X  case Copy:
  892. X  case Move:
  893. X  case Trash:
  894. X    /* Call button press with it */
  895. X    button_selected(w, paneNumber, 0);
  896. X    break;
  897. X
  898. X  case Quit:
  899. X    /* Quit the program.. maybe */
  900. X    quit_dialog();
  901. X    break;
  902. X
  903. X  case Map:
  904. X    /* Map program over files */
  905. X    map_dialog(True);
  906. X    break;
  907. X
  908. X  case Select:
  909. X    /* Select files via RE template, uses same dilaog as map, except 
  910. X     * with different resources.
  911. X     */
  912. X    map_dialog(False);
  913. X    break;
  914. X
  915. X  case Icons:
  916. X    /* Change to icon mode */
  917. X    if (current_mode.mode != Icons) {
  918. X      i = 0;
  919. X      XtSetArg(arglist[i], XtNleftBitmap, None); i++;
  920. X      XtSetValues(current_mode.w, arglist, i);
  921. X      i = 0;
  922. X      XtSetArg(arglist[i], XtNleftBitmap, tick); i++;
  923. X      XtSetValues(w, arglist, i);
  924. X      current_mode.w = w;
  925. X      current_mode.mode = Icons;
  926. X      XtSetArg(arglist[i], XtNshowIcons,     True); i++;
  927. X      XtSetArg(arglist[i], XtNrowSpacing,      10); i++; 
  928. X      XtSetArg(arglist[i], XtNforceColumns, False); i++;
  929. X      XtSetArg(arglist[i], XtNdefaultColumns,   2); i++;
  930. X      XtSetValues(directoryManager, arglist, i);
  931. X      directoryManagerNewDirectory(cwd);
  932. X    } 
  933. X    break;
  934. X
  935. X  case Short:
  936. X    /* Change to short listing mode */
  937. X    if (current_mode.mode != Short) {
  938. X      i = 0;
  939. X      XtSetArg(arglist[i], XtNleftBitmap, None); i++;
  940. X      XtSetValues(current_mode.w, arglist, i);
  941. X      i = 0;
  942. X      XtSetArg(arglist[i], XtNleftBitmap, tick); i++;
  943. X      XtSetValues(w, arglist, i);
  944. X      current_mode.w = w;
  945. X      current_mode.mode = Short;
  946. X      i = 0;
  947. X      XtSetArg(arglist[i], XtNshowIcons,    False); i++;
  948. X      XtSetArg(arglist[i], XtNrowSpacing,       5); i++;
  949. X      XtSetArg(arglist[i], XtNforceColumns, False); i++;
  950. X      XtSetArg(arglist[i], XtNdefaultColumns,   2); i++;
  951. X      XtSetValues(directoryManager, arglist, i);
  952. X      directoryManagerNewDirectory(cwd);    /* To be consistent */
  953. X    } 
  954. X    break;
  955. X
  956. X  case Long:
  957. X    /* change to long listing mode */
  958. X    if (current_mode.mode != Long) {
  959. X      i = 0;
  960. X      XtSetArg(arglist[i], XtNleftBitmap, None); i++;
  961. X      XtSetValues(current_mode.w, arglist, i);
  962. X      i = 0;
  963. X      XtSetArg(arglist[i], XtNleftBitmap, tick); i++;
  964. X      XtSetValues(w, arglist, i);
  965. X      current_mode.w = w;
  966. X      current_mode.mode = Long;
  967. X      i = 0;
  968. X      XtSetArg(arglist[i], XtNshowIcons,   False); i++;
  969. X      XtSetArg(arglist[i], XtNrowSpacing,      5); i++;
  970. X      XtSetArg(arglist[i], XtNforceColumns, True); i++;
  971. X      XtSetArg(arglist[i], XtNdefaultColumns,  1); i++;
  972. X      XtSetValues(directoryManager, arglist, i);
  973. X      directoryManagerNewDirectory(cwd);       /* To be consistent */
  974. X    }
  975. X    break;
  976. X
  977. X  case Options:
  978. X    /* allow changes to long listing format. */
  979. X    listoption_dialog();
  980. X    break;
  981. X
  982. X  default:
  983. X    fprintf(stderr, "Menu option number %d not supported\n", paneNumber);
  984. X    break;
  985. X  }
  986. X    
  987. X  
  988. X}
  989. X
  990. SHAR_EOF
  991. chmod 0644 xdtm/menus.c ||
  992. echo 'restore of xdtm/menus.c failed'
  993. Wc_c="`wc -c < 'xdtm/menus.c'`"
  994. test 13682 -eq "$Wc_c" ||
  995.     echo 'xdtm/menus.c: original size 13682, current size' "$Wc_c"
  996. fi
  997. # ============= xdtm/menus.h ==============
  998. if test -f 'xdtm/menus.h' -a X"$1" != X"-c"; then
  999.     echo 'x - skipping xdtm/menus.h (File already exists)'
  1000. else
  1001. echo 'x - extracting xdtm/menus.h (Text)'
  1002. sed 's/^X//' << 'SHAR_EOF' > 'xdtm/menus.h' &&
  1003. X/***********************************************************************************
  1004. X ** File          : menus.h                                                       **
  1005. X ** Purpose       :                                                               **
  1006. X ** Author        : Edward Groenendaal                                            **
  1007. X ** Date          : 18th Feb 1990                                                 **
  1008. X ** Documentation : Xedw Design Folder                                            **
  1009. X ** Related Files : menus.c                                                       **
  1010. X ***********************************************************************************/
  1011. X
  1012. X#ifndef _EG_menus_h
  1013. X#define _EG_menus_h
  1014. X
  1015. X#include <X11/Intrinsic.h>
  1016. X
  1017. X#define LINE    "line"
  1018. X
  1019. X#define PERMS   (1 << 1)
  1020. X#define NLINKS  (1 << 2)
  1021. X#define OWNER   (1 << 3)
  1022. X#define GROUP   (1 << 4)
  1023. X#define SIZE    (1 << 5)
  1024. X#define MODTM   (1 << 6)
  1025. X#define ACCTM   (1 << 7)
  1026. X
  1027. Xtypedef enum {flagged, noflag} Flags;
  1028. X
  1029. Xtypedef enum {
  1030. X  About,
  1031. X  Help,
  1032. X  New,
  1033. X  Duplicate,
  1034. X  Getinfo,
  1035. X  Copy,
  1036. X  Move,
  1037. X  Trash,
  1038. X  Quit,
  1039. X  Map,
  1040. X  Select,
  1041. X  Icons,
  1042. X  Short,
  1043. X  Long,
  1044. X  Options
  1045. X} MenuValue;
  1046. X
  1047. Xtypedef struct {
  1048. X  String paneName;
  1049. X  String paneLabel;
  1050. X  MenuValue paneNumber;
  1051. X  Flags set;
  1052. X} MenuContents;
  1053. X
  1054. Xtypedef struct {
  1055. X  Widget w;
  1056. X  MenuValue mode;
  1057. X  /* long listing options */
  1058. X  Cardinal length;
  1059. X  char options;
  1060. X} Icon_mode;
  1061. X
  1062. Xextern Widget menuBar;
  1063. Xextern Icon_mode current_mode;
  1064. Xextern Pixmap tick;
  1065. Xextern Pixmap emptytick;
  1066. X
  1067. X#endif /* _EG_menus_h */
  1068. SHAR_EOF
  1069. chmod 0644 xdtm/menus.h ||
  1070. echo 'restore of xdtm/menus.h failed'
  1071. Wc_c="`wc -c < 'xdtm/menus.h'`"
  1072. test 1513 -eq "$Wc_c" ||
  1073.     echo 'xdtm/menus.h: original size 1513, current size' "$Wc_c"
  1074. fi
  1075. # ============= xdtm/mystrstr.c ==============
  1076. if test -f 'xdtm/mystrstr.c' -a X"$1" != X"-c"; then
  1077.     echo 'x - skipping xdtm/mystrstr.c (File already exists)'
  1078. else
  1079. echo 'x - extracting xdtm/mystrstr.c (Text)'
  1080. sed 's/^X//' << 'SHAR_EOF' > 'xdtm/mystrstr.c' &&
  1081. X/*****************************************************************************
  1082. X ** File          : mystrstr.c                                              **
  1083. X ** Purpose       : Return pointer to first occurence of second string in   **
  1084. X **                 first string, else NULL                                 **
  1085. X ** Author        : Edward Groenendaal                                      **
  1086. X ** Date          : 11th April 1991                                         **
  1087. X ** Documentation : Xdtm Design Folder                                      **
  1088. X ** Related Files : appman.c                                                **
  1089. X *****************************************************************************/
  1090. X
  1091. X#ifndef HAS_STRSTR
  1092. X
  1093. X#include <stdio.h>  /* For NULL */
  1094. X
  1095. Xchar *mystrstr(char *cs, char *ct)
  1096. X{
  1097. X  char *csi, *cti, *result;
  1098. X  
  1099. X  result = NULL;
  1100. X  cti = ct;
  1101. X  csi = cs;
  1102. X  
  1103. X  /* search for first letter, on finding it set result to that point */
  1104. X
  1105. X  while (*csi != '\0' && *cti != '\0') {
  1106. X    if (result == NULL) {
  1107. X      /* searching for start of substring */
  1108. X      if (*csi == *cti) {
  1109. X    result = csi;
  1110. X    cti++;
  1111. X      }
  1112. X    } else 
  1113. X      /* trying to match rest */
  1114. X      if (*csi == *cti) 
  1115. X    cti++;
  1116. X      else {
  1117. X    cti = ct;
  1118. X    csi = result;
  1119. X    result = NULL;
  1120. X      }
  1121. X    csi++;
  1122. X  }
  1123. X
  1124. X  if (*cti == '\0')
  1125. X    return(result);
  1126. X  else 
  1127. X    return((char*) NULL);
  1128. X}
  1129. X
  1130. X#endif /* HAS_STRSTR */
  1131. X
  1132. X
  1133. X
  1134. X
  1135. SHAR_EOF
  1136. chmod 0644 xdtm/mystrstr.c ||
  1137. echo 'restore of xdtm/mystrstr.c failed'
  1138. Wc_c="`wc -c < 'xdtm/mystrstr.c'`"
  1139. test 1385 -eq "$Wc_c" ||
  1140.     echo 'xdtm/mystrstr.c: original size 1385, current size' "$Wc_c"
  1141. fi
  1142. # ============= xdtm/newfile.c ==============
  1143. if test -f 'xdtm/newfile.c' -a X"$1" != X"-c"; then
  1144.     echo 'x - skipping xdtm/newfile.c (File already exists)'
  1145. else
  1146. echo 'x - extracting xdtm/newfile.c (Text)'
  1147. sed 's/^X//' << 'SHAR_EOF' > 'xdtm/newfile.c' &&
  1148. X/*****************************************************************************
  1149. X ** File          : newfile.c                                               **
  1150. X ** Purpose       : Initialise and Realise newfile dialog                   **
  1151. X ** Author        : Edward Groenendaal                                      **
  1152. X ** Date          : April 1991                                              **
  1153. X ** Documentation : Xdtm Design Folder                                      **
  1154. X ** Related Files :                                                         **
  1155. X *****************************************************************************/
  1156. X
  1157. X#include "xdtm.h"
  1158. X
  1159. X#include <X11/Shell.h>
  1160. X#include <X11/Xaw/Label.h>
  1161. X#include <X11/Xaw/Command.h>
  1162. X#include <X11/Xaw/AsciiText.h>
  1163. X#include "Xedw/XedwForm.h"
  1164. X
  1165. Xextern void realize_dialog(Widget);
  1166. X
  1167. X/* Widgets */
  1168. X
  1169. Xprivate Widget newfilepopup;
  1170. Xprivate Widget newfileform;
  1171. Xprivate Widget newfilelabel;
  1172. Xprivate Widget newfiletext;
  1173. Xprivate Widget newfilefile;
  1174. Xprivate Widget newfiledir;
  1175. Xprivate Widget newfilecancel;
  1176. X
  1177. Xtypedef struct {
  1178. X  String filename;
  1179. X  Boolean isdir;
  1180. X} Filetype;
  1181. X
  1182. X/*****************************************************************************
  1183. X *                             init_newfile                                  *
  1184. X *****************************************************************************/
  1185. Xpublic void init_newfile(Widget top)
  1186. X{
  1187. X  /* Create Widgets for newfile dialog */
  1188. X
  1189. X  private void destroy_newfile_dialog(Widget, caddr_t, caddr_t);
  1190. X
  1191. X  Arg arglist[5];
  1192. X  Cardinal i;
  1193. X  XtTranslations newfileTranslations;
  1194. X
  1195. X  /* Translations for text widget */
  1196. X  static char defaultTranslations[] = 
  1197. X    "Ctrl<Key>A:        beginning-of-line() \n\
  1198. X     Ctrl<Key>E:        end-of-line() \n\
  1199. X     <Key>Escape:       beginning-of-line() kill-to-end-of-line() \n\
  1200. X     <Key>Right:     forward-character() \n\
  1201. X     <Key>Left:         backward-character() \n\
  1202. X     <Key>Delete:       delete-previous-character() \n\
  1203. X     <Key>BackSpace:    delete-previous-character() \n\
  1204. X     <Key>:             insert-char() \n\
  1205. X     <FocusIn>:         focus-in() \n\
  1206. X     <FocusOut>:        focus-out() \n\
  1207. X     <BtnDown>:         select-start()";
  1208. X    
  1209. X
  1210. X  newfilepopup  = XtCreatePopupShell("newfilepopup",
  1211. X                     transientShellWidgetClass,
  1212. X                     top,
  1213. X                     NULL, 0);
  1214. X
  1215. X  newfileform   = XtCreateManagedWidget("newfileform",
  1216. X                    xedwFormWidgetClass,
  1217. X                    newfilepopup,
  1218. X                    NULL, 0);
  1219. X
  1220. X  /* label widget to prompt for new filename */
  1221. X
  1222. X  i = 0;
  1223. X  XtSetArg(arglist[i], XtNfullWidth,          True); i++;
  1224. X  XtSetArg(arglist[i], XtNborderWidth,           0); i++;
  1225. X  XtSetArg(arglist[i], XtNjustify, XtJustifyCenter); i++;
  1226. X  newfilelabel  = XtCreateManagedWidget("newfilelabel",
  1227. X                    labelWidgetClass,
  1228. X                    newfileform,
  1229. X                    arglist, i);
  1230. X  
  1231. X  /* new filename text input widget */
  1232. X
  1233. X  i = 1;
  1234. X  XtSetArg(arglist[i], XtNfromVert, newfilelabel); i++;
  1235. X  XtSetArg(arglist[i], XtNeditType, XawtextEdit); i++;
  1236. X  newfiletext   = XtCreateManagedWidget("newfiletext",
  1237. X                    asciiTextWidgetClass,
  1238. X                    newfileform,
  1239. X                    arglist, i);
  1240. X
  1241. X  i = 0;
  1242. X  XtSetArg(arglist[i], XtNfromVert, newfiletext); i++;
  1243. X  XtSetArg(arglist[i], XtNlabel,    "Directory"); i++;
  1244. X  newfiledir    = XtCreateManagedWidget("newfiledir",
  1245. X                    commandWidgetClass,
  1246. X                    newfileform,
  1247. X                    arglist, i);
  1248. X  i = 1;
  1249. X  XtSetArg(arglist[i], XtNfromHoriz,   newfiledir); i++;
  1250. X  XtSetArg(arglist[i], XtNwidthLinked, newfiledir); i++;
  1251. X  XtSetArg(arglist[i], XtNlabel,           "File"); i++;
  1252. X  newfilefile   = XtCreateManagedWidget("newfilefile",
  1253. X                    commandWidgetClass,
  1254. X                    newfileform,
  1255. X                    arglist, i);
  1256. X
  1257. X  i = 1;
  1258. X  XtSetArg(arglist[i], XtNfromHoriz,   newfilefile); i++;
  1259. X  XtSetArg(arglist[i], XtNwidthLinked, newfilefile); i++;
  1260. X  XtSetArg(arglist[i], XtNlabel,          "Cancel"); i++;
  1261. X  newfilecancel = XtCreateManagedWidget("newfilecancel",
  1262. X                    commandWidgetClass,
  1263. X                    newfileform,
  1264. X                    arglist, i);
  1265. X
  1266. X  /* Add callbacks for buttons */
  1267. X  XtAddCallback(newfilecancel, XtNcallback,  destroy_newfile_dialog, 0); 
  1268. X
  1269. X  /* Do the translations on the text widget */
  1270. X  XtUninstallTranslations(newfiletext);
  1271. X  newfileTranslations = XtParseTranslationTable(defaultTranslations);
  1272. X  XtOverrideTranslations(newfiletext, newfileTranslations);
  1273. X}
  1274. X
  1275. X/*****************************************************************************
  1276. X *                             newfile_dialog                                *
  1277. X *****************************************************************************/
  1278. Xpublic void newfile_dialog(Boolean rename, String newname, Boolean isdir)
  1279. X{
  1280. X  /* Popup the newfile dialog on screen with the correct data 
  1281. X   *
  1282. X   * - Takes a flag saying whether this is a duplication of a file, or the
  1283. X   *   creation of a new file or directory.
  1284. X   *   newname - The name of the file to be duplicated.
  1285. X   *   isdir   - Whether the file is a directory 
  1286. X   */
  1287. X
  1288. X  private void newfileQueryReturn(Widget, Boolean, caddr_t);
  1289. X  private void duplicateQueryReturn(Widget, Filetype*, caddr_t);
  1290. X  Arg arglist[1];
  1291. X  String filename;
  1292. X  Filetype *filetype;
  1293. X
  1294. X  static String defaultfilename = "untitled";
  1295. X
  1296. X  filetype = (Filetype*) XtMalloc (sizeof(Filetype));
  1297. X
  1298. X  if (newname == NULL) 
  1299. X    filename = defaultfilename;
  1300. X  else
  1301. X    filename = newname;
  1302. X
  1303. X  if (rename == False) {
  1304. X    /* Create a new file */
  1305. X
  1306. X    XtSetArg(arglist[0], XtNlabel, "Create a new file"); 
  1307. X    XtSetValues(newfilelabel, arglist, 1);
  1308. X
  1309. X    XtSetArg(arglist[0], XtNstring, filename);
  1310. X    XtSetValues(newfiletext, arglist, 1);
  1311. X
  1312. X    /* Add callbacks for buttons */
  1313. X    XtAddCallback(newfiledir,    XtNcallback,  newfileQueryReturn,  True);
  1314. X    XtAddCallback(newfilefile,   XtNcallback,  newfileQueryReturn, False);
  1315. X  } else {
  1316. X    /* rename an existing file */
  1317. X    filetype->filename = filename;
  1318. X    filetype->isdir    = isdir;
  1319. X
  1320. X    XtSetArg(arglist[0], XtNlabel, "Duplicate file"); 
  1321. X    XtSetValues(newfilelabel, arglist, 1);
  1322. X
  1323. X    XtSetArg(arglist[0], XtNstring, filename);
  1324. X    XtSetValues(newfiletext, arglist, 1);
  1325. X
  1326. X    if (isdir == True) 
  1327. X      XtSetSensitive(newfilefile, False);
  1328. X    else
  1329. X      XtSetSensitive(newfiledir, False);
  1330. X    XtAddCallback(newfiledir,  XtNcallback, duplicateQueryReturn, filetype);
  1331. X    XtAddCallback(newfilefile, XtNcallback, duplicateQueryReturn, filetype);
  1332. X  }
  1333. X
  1334. X  realize_dialog(newfilepopup);
  1335. X
  1336. X}
  1337. X
  1338. X/*****************************************************************************
  1339. X *                        destroy_newfile_dialog                             *
  1340. X *****************************************************************************/
  1341. Xprivate void destroy_newfile_dialog(Widget w, caddr_t dummy1, caddr_t dummy2)
  1342. X{
  1343. X  /* Popdown and destroy callbacks for the newfile dialog. Also back sure
  1344. X   * that both buttons are sensitive.
  1345. X   */
  1346. X
  1347. X  XtPopdown(newfilepopup);
  1348. X  
  1349. X  XtSetSensitive(newfilefile, True);
  1350. X  XtSetSensitive(newfiledir,  True);
  1351. X  XtRemoveAllCallbacks(newfilefile, XtNcallback);
  1352. X  XtRemoveAllCallbacks(newfiledir,  XtNcallback);
  1353. X}
  1354. X
  1355. X/*****************************************************************************
  1356. X *                            newfileQueryReturn                             *
  1357. X *****************************************************************************/
  1358. Xprivate void newfileQueryReturn(Widget w, Boolean isdir, caddr_t dummy)
  1359. X{
  1360. X  /* This procedure creates a new empty directory or file with the filename
  1361. X   * in the text widget newfiletext.
  1362. X   *
  1363. X   * - Takes a flag isdir, is the new file a directory?
  1364. X   */
  1365. X
  1366. X  extern void query_dialog(String, Boolean);
  1367. X  extern String cwd;
  1368. X  String filename, fullname;
  1369. X  Arg arglist[1];
  1370. X  int fd;
  1371. X  
  1372. X  destroy_newfile_dialog(w, 0, 0);
  1373. X  
  1374. X  XtSetArg(arglist[0], XtNstring, &filename);
  1375. X  XtGetValues(newfiletext, arglist, 1);
  1376. X
  1377. X  fullname = (String) XtMalloc (sizeof(char) * (strlen(cwd) + 
  1378. X                        strlen(filename) + 4));
  1379. X  sprintf(fullname, "%s/%s", cwd, filename);
  1380. X
  1381. X  if (isdir == True) {
  1382. X    /* Create a directory with the name 'filename' */
  1383. X    if ((fd = mkdir(fullname, 0777)) == -1) 
  1384. X      query_dialog("Can't create dir", False);
  1385. X    else
  1386. X      directoryManagerNewDirectory(cwd);
  1387. X  } else {
  1388. X    /* Create a file with the name 'filename' */
  1389. X    if ((fd = creat(fullname, 0666)) == -1) {
  1390. X      /* Can't create fullname, maybe should look in errno to see why? */
  1391. X      query_dialog("Can't create file", False);
  1392. X    } else {
  1393. X      close(fd);
  1394. X      directoryManagerNewDirectory(cwd);
  1395. X    }
  1396. X  }
  1397. X
  1398. X  XtFree(fullname);
  1399. X}
  1400. X
  1401. X/*****************************************************************************
  1402. X *                            duplicateQueryReturn                           *
  1403. X *****************************************************************************/
  1404. Xprivate void duplicateQueryReturn(Widget w, Filetype *filetype, caddr_t dummy)
  1405. X{
  1406. X  /* This procedure copies a file in the current directory to a file with
  1407. X   * the name as specified within the text widget newfiletext. The orignal
  1408. X   * filename and type are passed as arguments to this procedure in the
  1409. X   * structure filetype.
  1410. X   */
  1411. X
  1412. X  extern void query_dialog(String, Boolean);
  1413. X  extern String cwd;
  1414. X  String filename, command;
  1415. X  Arg arglist[1];
  1416. X  int fd;
  1417. X  
  1418. X  destroy_newfile_dialog(w, 0, 0);
  1419. X  
  1420. X  XtSetArg(arglist[0], XtNstring, &filename);
  1421. X  XtGetValues(newfiletext, arglist, 1);
  1422. X
  1423. X  command = XtMalloc (sizeof(char) * (strlen(filetype->filename) + 
  1424. X                      strlen(filename) + 24));
  1425. X
  1426. X  if (filetype->isdir == True) {
  1427. X    /* make new directory, copy contents of old one into it */
  1428. X    if ((fd = mkdir(filename, 0777)) == -1) 
  1429. X      query_dialog("Can't create dir", False);
  1430. X    sprintf(command, "sh -c 'cp -r \"%s\"/ \"%s\"'", filetype->filename, 
  1431. X        filename);
  1432. X
  1433. X    if (execute(NULL, "sh", command, True) != 0) 
  1434. X      query_dialog("Can't copy files!", False);
  1435. X    else
  1436. X      directoryManagerNewDirectory(cwd);
  1437. X  } else {
  1438. X    sprintf(command, "cp '%s' '%s'", filetype->filename, filename);
  1439. X
  1440. X    if (execute(NULL, "cp", command, True) != 0) 
  1441. X      query_dialog("Can't create file!", False);
  1442. X    else
  1443. X      directoryManagerNewDirectory(cwd);
  1444. X  }
  1445. X
  1446. X  XtFree(command);
  1447. X}
  1448. SHAR_EOF
  1449. chmod 0644 xdtm/newfile.c ||
  1450. echo 'restore of xdtm/newfile.c failed'
  1451. Wc_c="`wc -c < 'xdtm/newfile.c'`"
  1452. test 9922 -eq "$Wc_c" ||
  1453.     echo 'xdtm/newfile.c: original size 9922, current size' "$Wc_c"
  1454. fi
  1455. true || echo 'restore of xdtm/parse.c failed'
  1456. echo End of part 9, continue with part 10
  1457. exit 0
  1458.  
  1459. --
  1460. Dan Heller
  1461. O'Reilly && Associates       Z-Code Software    Comp-sources-x:
  1462. Senior Writer                President          comp-sources-x@uunet.uu.net
  1463. argv@ora.com                 argv@zipcode.com
  1464.