home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume2 / xbrowser / part02 / xfilebrowser.c < prev   
Encoding:
C/C++ Source or Header  |  1989-01-03  |  8.0 KB  |  267 lines

  1. /* Systems Sciences Laboratory, Webster Research Center */
  2.  
  3. static char *PROGRAM_information[] =
  4. {
  5.     "Copyright (c) 1988 Xerox Corporation.  All rights reserved.",
  6.     "$Header$",
  7.     "$Locker$"
  8. }
  9. ;
  10.  
  11. /*
  12.  * Copyright protection claimed includes all forms and matters of copyrightable
  13.  * material and information now allowed by statutory or judicial lay or
  14.  * herinafter granted, including without limitation, material generated from
  15.  * the software programs which are displayed on the screen such as icons,
  16.  * screen display looks, etc.
  17.  */
  18.  
  19. #include "xfilebrowser.h"
  20. #include "xbrowser.icon"
  21.  
  22.  
  23. char *filepattern;
  24. char *searchpattern;
  25. char *curdirectory;
  26. char *oldpattern;
  27. char *cmdline;
  28.  
  29. struct afile **files = NULL;
  30. SearchElement **hitfiles = NULL;
  31. int numfiles = 0;
  32. int numhitfiles = 0;
  33. int allowedit = 0;
  34.  
  35. Widget toplevel;
  36. Widget outer;
  37. Widget Row1;
  38. Widget Row2;
  39. Widget Row3;
  40.  
  41. Widget messwidget;    /* text widget for displaying messages */
  42. Widget dirwidget;    /* label widget for current directory */
  43. Widget listwidget;    /* text widget for directory listing */
  44. Widget grepwidget;    /* text widget for searched files */
  45.  
  46. Widget quitbutton;    /* command button for quit */
  47. Widget listbutton;    /* command button for list */
  48. Widget editbutton;    /* command button for edit file selected
  49.             in directory listing */
  50. Widget parentdirbutton;    /* command button for selecting
  51.                 parent directory */
  52. Widget shellbutton;    /* command button for invoking shell */
  53. Widget copybutton;    /* command button for invoking copy */
  54. Widget renamebutton;    /* command button for invoking rename */
  55. Widget deletebutton;    /* command button for invoking delete on files */
  56.  
  57. Widget fpatwindow;    /* string box for providing the file pattern
  58.             used to list directories */
  59.  
  60. Widget grepbutton;    /* command button for invoking grep on files */
  61. Widget grepwindow;    /* string box to specify the grep search pattern */
  62. Widget grepeditbutton;    /* command button for edit file selected
  63.             in list of searched files */
  64.  
  65. Display *curdisplay;
  66. XtTextSource messsource, listsource, grepsource;
  67.  
  68. int viewEdit;
  69.  
  70. static XtResource resources[] = {
  71.    {"viewEdit", "ViewEdit", XtRBoolean, sizeof(int),
  72.          (Cardinal)&viewEdit, XtRString, "False"}
  73. };
  74.  
  75. makeButtonsAndBoxes()
  76. {
  77.     Cursor hand;
  78.     static XtTextSelectType listselect[] = {
  79.         XtselectLine, XtselectAll, XtselectNull, XtselectNull};
  80.  
  81.     static Arg paneargs[] = {
  82.        { XtNallowResize, (XtArgVal)True },
  83.     };
  84.     static Arg ListArgs[] = {
  85.        { XtNtextSource, NULL },
  86.        { XtNtextSink, NULL },
  87.          { XtNcursor, NULL },
  88.        { XtNtextOptions , 
  89.         (XtArgVal)(scrollVertical | scrollHorizontal | resizeWidth) },
  90.        { XtNselectTypes, (XtArgVal)listselect }, 
  91.     };
  92.     static Arg MessArgs[] = {
  93.        { XtNtextSource, NULL },
  94.        { XtNtextSink, NULL },
  95.        { XtNtextOptions, (XtArgVal)(scrollVertical | wordBreak) },
  96.     };
  97.     static Arg labelArgs[] = {
  98.        { XtNjustify, (XtArgVal)XtJustifyCenter },
  99.        { XtNlabel,     NULL },
  100.     };
  101.     static Arg grepArgs[] = {
  102.        { XtNtextSource, NULL },
  103.        { XtNtextSink, NULL },
  104.          { XtNcursor, NULL },
  105.        { XtNtextOptions , 
  106.         (XtArgVal)(scrollVertical | scrollHorizontal | resizeWidth) },
  107.        { XtNselectTypes, (XtArgVal)listselect }, 
  108.     }; 
  109.  
  110.  
  111.     outer = XtCreateManagedWidget( "vpaned", vPanedWidgetClass, toplevel,
  112.                                   paneargs , XtNumber(paneargs) );
  113.     XtPanedSetRefigureMode(outer, FALSE);
  114.  
  115.     /* create first row */
  116.     Row1 = XtCreateManagedWidget("row1", boxWidgetClass, outer, NULL,0);
  117.     quitbutton     = makeCommandButton(Row1, "Quit", DoQuit);
  118.     listbutton     = makeCommandButton(Row1, "List", DoList);
  119.     ModCommand_Init(listbutton);
  120.  
  121.     editbutton     = makeCommandButton(Row1, "View/Edit", DoEdit);
  122.     ModCommand_Init(editbutton);
  123.     parentdirbutton = makeCommandButton(Row1, "Parent", DoParent);
  124.     ModCommand_Init(parentdirbutton);
  125.     shellbutton     = makeCommandButton(Row1, "Shell", DoShell);
  126.     ModCommand_Init(shellbutton);
  127.  
  128.     copybutton     = makeCommandButton(Row1, "Copy", DoCopy);
  129.     renamebutton     = makeCommandButton(Row1, "Move", DoRename);
  130.     deletebutton     = makeCommandButton(Row1, "Delete", DoDelete);
  131.  
  132.     /* create second row */
  133.     Row2 = XtCreateManagedWidget("row2", boxWidgetClass, outer, NULL,0);
  134.     fpatwindow = makeStringBox(Row2, filepattern, 254);
  135.  
  136.     /* create label for current directory */
  137.     labelArgs[1].value = (XtArgVal)curdirectory;
  138.     dirwidget = XtCreateManagedWidget("labelWindow",labelWidgetClass, 
  139.         outer, labelArgs, XtNumber(labelArgs)); 
  140.     XtPanedSetMinMax((Widget)dirwidget, 14, 14);
  141.  
  142.     /* create message window */
  143.     messsource = TCreateApAsSource();
  144.     MessArgs[0].value = (XtArgVal)messsource;
  145.     MessArgs[1].value = (XtArgVal)XtAsciiSinkCreate(outer, NULL, 0);
  146.     messwidget =  XtCreateManagedWidget("messageWindow",
  147.         textWidgetClass, outer, MessArgs, XtNumber(MessArgs));
  148.     XtPanedSetMinMax((Widget) messwidget, 40, 40);
  149.  
  150.         /* create cursor hand */
  151.     hand = XCreateFontCursor(curdisplay, XC_hand1);
  152.  
  153.     /* create text for displaying directory listings */
  154.     listsource = TCreateApAsSource();
  155.     ListArgs[0].value = (XtArgVal)listsource;
  156.     ListArgs[1].value = (XtArgVal)XtAsciiSinkCreate(outer, NULL, 0);
  157.     ListArgs[2].value = (XtArgVal)hand;
  158.     listwidget =  XtCreateManagedWidget("listWindow", 
  159.         textWidgetClass, outer, ListArgs, XtNumber(ListArgs));
  160.     XtPanedSetMinMax((Widget) listwidget, 250, 65535);
  161.     Modtext_Init(listwidget);
  162.  
  163.     /* create third row */
  164.     Row3 = XtCreateManagedWidget("row3", boxWidgetClass, outer, NULL,0);
  165.     grepeditbutton     = makeCommandButton(Row3, "View/Edit", DoGrepEdit);
  166.     ModCommand_Init(grepeditbutton);
  167.     grepbutton     = makeCommandButton(Row3, "Grep", DoGrep);
  168.     ModCommand_Init(grepbutton);
  169.     grepwindow     = makeStringBox(Row3, searchpattern, 120);
  170.  
  171.     /* create text for displaying directory listings */
  172.     grepsource = TCreateApAsSource();
  173.     grepArgs[0].value = (XtArgVal)grepsource;
  174.     grepArgs[1].value = (XtArgVal)XtAsciiSinkCreate(outer, NULL, 0);
  175.     grepArgs[2].value = (XtArgVal)hand;
  176.     grepwidget =  XtCreateManagedWidget("grepWindow", 
  177.         textWidgetClass, outer, grepArgs, XtNumber(grepArgs));
  178.     XtPanedSetMinMax((Widget) grepwidget, 150, 65535);
  179.     Modtext_Init(grepwidget);
  180.  
  181.     {
  182.        static Dimension boxHeight;
  183.        static Arg getargs[] = {
  184.         { XtNheight, (XtArgVal)&boxHeight }
  185.        };
  186.  
  187.     XtGetValues(quitbutton, getargs, XtNumber(getargs));
  188.     boxHeight += 8;
  189.     XtPanedSetMinMax((Widget) Row1, boxHeight, 65535);
  190.     XtPanedSetMinMax((Widget) Row2, boxHeight, 65535);
  191.     XtPanedSetMinMax((Widget) Row3, boxHeight, 65535);
  192.     }
  193.  
  194.     XtPanedSetRefigureMode(outer, TRUE); 
  195. }
  196.  
  197.  
  198. main(argc, argv)
  199. int argc;
  200. char **argv;
  201. {
  202.     char *cwd;
  203.     Pixmap icon;
  204.     Arg iconargs[1];
  205.    
  206.     static Dimension width, height;
  207.      static Arg args[]={
  208.        {XtNwidth, (XtArgVal) &width},
  209.        {XtNheight, (XtArgVal)&height} };
  210.     static Arg setargs[]={
  211.          {XtNwidth, 500},
  212.          {XtNheight,700} };
  213.  
  214.     filepattern = XtMalloc(255);
  215.     searchpattern = XtMalloc(255);
  216.     curdirectory = XtMalloc(255);
  217.     oldpattern = XtMalloc(64);
  218.     cmdline = XtCalloc(1024, 1);
  219.  
  220.     toplevel = XtInitialize( "xbrowser", "XBrowser", 
  221.         NULL, 0, &argc, argv);
  222.     XtGetValues(toplevel, args, XtNumber(args));
  223.     if(!width || !height){
  224.        XtSetValues(toplevel, setargs, XtNumber(setargs));
  225.     }
  226.  
  227.     XtGetApplicationResources(toplevel, 0, resources,
  228.                                   XtNumber(resources),NULL, 0);
  229.     curdisplay = XtDisplay(toplevel);
  230.  
  231.     if ( (cwd = getcwd((char *)NULL, 255)) == (char *)NULL)
  232.          XtError("\nxbrowser: cannot get current directory");
  233.  
  234.     if (argv[1]) {
  235.        strcpy(curdirectory, cwd);
  236.        get_dirpat(argv[1], curdirectory, filepattern);
  237.     }
  238.       else get_dirpat(cwd, curdirectory, filepattern);
  239.  
  240.     strcpy(oldpattern, filepattern);
  241.     reset_ownercache();
  242.  
  243.     makeButtonsAndBoxes();
  244.  
  245.     XtRealizeWidget(toplevel);
  246.     XDefineCursor( XtDisplay(toplevel), XtWindow(toplevel),
  247.         XCreateFontCursor(XtDisplay(toplevel), XC_left_ptr) );
  248.     setup_iconname();
  249.  
  250.     /* define icon pixmap */
  251.     icon = XCreateBitmapFromData(curdisplay, 
  252.             DefaultRootWindow(curdisplay),
  253.             xbrowser_bits,
  254.             xbrowser_width,
  255.             xbrowser_height);
  256.     XtSetArg(iconargs[0], XtNiconPixmap, (XtArgVal)icon);
  257.     XtSetValues(toplevel, iconargs, XtNumber(iconargs));
  258.  
  259.     create_log(); /* create log window; it must be created before
  260.             the popup window for the list options; otherwise
  261.             it does not create the scrollbar correctly;
  262.             I have no idea why */
  263.  
  264.     XtMainLoop();
  265. }
  266.  
  267.