home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / online / source / c / compilers / Tickle-4.0.sit.hqx / Tickle-4.0 / src / Command.c < prev    next >
Text File  |  1993-11-18  |  11KB  |  491 lines

  1.  
  2. #ifdef MPW3
  3. #    pragma segment COMMAND
  4. #endif
  5.  
  6. /*
  7. ** This source code was written by Tim Endres
  8. ** Email: time@ice.com.
  9. ** USMail: 8840 Main Street, Whitmore Lake, MI  48189
  10. **
  11. ** Some portions of this application utilize sources
  12. ** that are copyrighted by ICE Engineering, Inc., and
  13. ** ICE Engineering retains all rights to those sources.
  14. **
  15. ** Neither ICE Engineering, Inc., nor Tim Endres, 
  16. ** warrants this source code for any reason, and neither
  17. ** party assumes any responsbility for the use of these
  18. ** sources, libraries, or applications. The user of these
  19. ** sources and binaries assumes all responsbilities for
  20. ** any resulting consequences.
  21. */
  22.  
  23. #include "tickle.h"
  24. #include "TGE.h"
  25. #include "tcl.h"
  26.  
  27. extern int tcl_feedback_output();
  28.  
  29. /*
  30. ** This is where all of the menu commands are parsed out and
  31. ** handled. MenuSelection contains the menu ID and the item
  32. ** picked in that menu. These two numbers are shorts inside
  33. ** a long integer.
  34. */
  35. do_command(MenuSelection)
  36.     long MenuSelection;
  37.     {
  38.     char             name[256];
  39.     int             refNum, doit;
  40.     WindowPtr        myWindow;
  41.     int             theMenu, theitem;
  42.     Rect            myrect;
  43.     extern Boolean    cvtNl;
  44.     extern Boolean    oldArch;
  45.  
  46.     /*
  47.     ** The menu ID is the "high" short in the long integer.
  48.     */
  49.     theMenu = (short)((MenuSelection >> 16) & 0x0000FFFF);
  50.  
  51.     /*
  52.     ** The menu item picked is the "low" short in the long integer.
  53.     */
  54.     theitem = (short)(MenuSelection & 0x0000FFFF);
  55.  
  56.     myWindow = FrontWindow();
  57.     
  58.     /*
  59.     ** Parse the menu ID and item picked into the appropriate commands.
  60.     */
  61.     switch (theMenu) {
  62.         case applemenu:
  63.             if (theitem == infoitem) {
  64.                 do_info();
  65.                 clear_notify_q(NOTIFY_ALL);
  66.                 }
  67.             else {
  68.                 GetItem(mymenus[0], theitem, name);
  69.                 refNum = OpenDeskAcc(name);
  70.                 }
  71.             break;
  72.         
  73.         case filemenu:
  74.             switch(theitem) {
  75.                 case page_setup_item:
  76.                     PageSetUp();
  77.                     break;
  78.                     
  79.                 case new_item:
  80.                     {
  81.                     Tcl_Interp            *interp;
  82.                     extern WindowPtr    MakeTextTGE();
  83.                     
  84.                     SetRect(&myrect, 10, 50, 410, 250);
  85.                     myWindow = MakeTextTGE(&myrect, "Untitled", "", 0);
  86.                     if (myWindow != NULL)
  87.                         {
  88.                         T_UNSETSTATE(TGEWPtr->state, T_TCL_STATE);
  89.                         if ( (menu_modifiers & shiftKey) != 0 && g_interp != NULL )
  90.                             {
  91.                             /* GLOBAL */
  92.                             T_SETSTATE(TGEWPtr->state, T_GLOBAL_TCL_STATE);
  93.                             interp = g_interp;
  94.                             }
  95.                         else
  96.                             {
  97.                             /* LOCAL */
  98.                             T_UNSETSTATE(TGEWPtr->state, T_GLOBAL_TCL_STATE);
  99.                             interp = Tcl_CreateTickleInterp();
  100.                             if (interp != NULL)
  101.                                 TickleInitLocalShell(interp, myWindow);
  102.                             }
  103.                         
  104.                         TGEWPtr->fobject = (void *)interp;
  105.                         if (interp != NULL)
  106.                             {
  107.                             T_SETSTATE(TGEWPtr->state, T_TCL_STATE);
  108.                             SetPort(myWindow);
  109.                             tge_inval_status_box(myWindow);
  110.                             }
  111.                         
  112.                         UInitCursor();
  113.                         }
  114.                     }
  115.                     break;
  116.                     
  117.                 case open_item:
  118.                     do_tge_file_open(NULL, (menu_modifiers & shiftKey) != 0);
  119.                     break;
  120.                 case save_item:
  121.                     if (myWindow != NULL && WPeek->windowKind == tgeWKind)
  122.                         wind_parse(myWindow, NULL, wSave);
  123.                     break;
  124.                 case save_as_item:
  125.                     if (myWindow != NULL && WPeek->windowKind == tgeWKind)
  126.                         wind_parse(myWindow, NULL, wSaveAs);
  127.                     break;
  128.                 case print_window_item:
  129.                     if (myWindow != NULL)
  130.                         wind_parse(myWindow, NULL, wPrint);
  131.                     break;
  132.                 case print_selection_item:
  133.                     if (myWindow != NULL)
  134.                         wind_parse(myWindow, NULL, wPrintSelection);
  135.                     break;
  136.                 case run_script_item:
  137.                     run_tcl_script(NULL, tcl_feedback_output);
  138.                     break;
  139.                 case new_folder_item:
  140.                     CreateDirectory();
  141.                     break;
  142.                 case open_fb_item:
  143.                     if (feedback_showing)
  144.                         HideFeedback();
  145.                     else
  146.                         ShowFeedback();
  147.                     break;
  148.                 case close_window_item:
  149.                     if (myWindow != NULL)
  150.                         wind_parse(myWindow, NULL, wClose);
  151.                     break;
  152.                 case pause_op_item:
  153.                     if (pause_op)
  154.                         {
  155.                         pause_op = 0;
  156.                         SetCursor(*GetCursor(watchCursor));
  157.                         SetItem(file_menu_hdl, pause_op_item, "\pPause");
  158.                         }
  159.                     else
  160.                         {
  161.                         pause_op = 1;
  162.                         InitCursor();
  163.                         SetItem(file_menu_hdl, pause_op_item, "\pContinue");
  164.                         }
  165.                     break;
  166.                 case cancel_op_item:
  167.                     pause_op = 0;
  168.                     cancel_current_op = 1;
  169.                     SetItem(file_menu_hdl, pause_op_item, "\pPause");
  170.                     clear_notify_q(NOTIFY_ALL);
  171.                     break;
  172.                 case stop_icons_item:
  173.                     clear_notify_q(NOTIFY_ALL);
  174.                     break;
  175.                 case quit_item:
  176.                     doit = 1;
  177.                     if (yielding_on)
  178.                         if (! AskYesNo("Sure you wanna quit?", 0))
  179.                             doit = 0;
  180.                     
  181.                     if (doit) {
  182.                         cancel_current_op = 1;
  183.                         pause_op = 0;
  184.                         app_done = true;
  185.                         clear_notify_q(NOTIFY_ALL);
  186.                         }
  187.                     break;
  188.                 case log_level_item:
  189.                     if (CheckOption()) {
  190.                         name[0] = '\0';
  191.                         if (GetInputLine("Mark String:", name)) {
  192.                             UUDEBUG(0, "LOGMARK: %s\n", name);
  193.                             }
  194.                         }
  195.                     else {
  196.                         name[0] = '\0';
  197.                         sprintf(temp_str, "Current log level = %d. Enter new level:", g_log_level);
  198.                         if (GetInputLine(temp_str, name)) {
  199.                             g_log_level = atoi(name);
  200.                             UUDEBUG(0, "Log level set to %d.\n", g_log_level);
  201.                             }
  202.                         }
  203.                     break;
  204.                 case log_item:
  205.                     if (logfile == NULL) {
  206.                         extern int errno;
  207.                         Point mypoint;
  208.                         SFReply myreply;
  209.                         
  210.                         if (CheckOption()) {
  211.                             mypoint.h = mypoint.v = 75;
  212.                             MyPutFile(mypoint, "\pLog File:", "\pLOGFILE", NULL, &myreply);
  213.                             if (myreply.good) {
  214.                                 SetVol(NULL, myreply.vRefNum);
  215.                                 p2cstr(myreply.fName);
  216.                                 logfile = fopen(myreply.fName, "a");
  217.                                 if (logfile == NULL) {
  218.                                     message_alert("Error #%d opening log file.", errno);
  219.                                     }
  220.                                 else {
  221.                                     SetItem(file_menu_hdl, log_item, "\pEnd Logging");
  222.                                     strcpy(g_log_filename, myreply.fName);
  223.                                     g_log_wdref = myreply.vRefNum;
  224.                                     }
  225.                                 }
  226.                             }
  227.                         else {
  228.                             SetVol(NULL, g_log_wdref);
  229.                             logfile = fopen(g_log_filename, "a");
  230.                             if (logfile == NULL) {
  231.                                 message_alert("Error #%d opening log file.", errno);
  232.                                 }
  233.                             else {
  234.                                 SetItem(file_menu_hdl, log_item, "\pEnd Logging");
  235.                                 }
  236.                             }
  237.                         }
  238.                     else {
  239.                         fclose(logfile);
  240.                         FlushVol(NULL, app_vrefnum);
  241.                         logfile = (FILE *)0;
  242.                         SetItem(file_menu_hdl, log_item, "\pBegin Logging");
  243.                         }
  244.                     break;
  245.                 }
  246.             break;
  247.         
  248.         case editmenu:
  249.             if (! SystemEdit(theitem)) {
  250.                 switch(theitem) {
  251.                     case cutCmd:
  252.                         wind_parse(myWindow, NULL, wCut);
  253.                         break;
  254.                     case copyCmd:
  255.                         wind_parse(myWindow, NULL, wCopy);
  256.                         break;
  257.                     case pasteCmd:
  258.                         wind_parse(myWindow, NULL, wPaste);
  259.                         break;
  260.                     case undoCmd:
  261.                         wind_parse(myWindow, NULL, wUndo);
  262.                         break;
  263.                     case clearCmd:
  264.                         wind_parse(myWindow, NULL, wDelete);
  265.                         break;
  266.                     case selectAllCmd:
  267.                         wind_parse(myWindow, NULL, wSelectAll);
  268.                         break;
  269.                     case findCmd:
  270.                         wind_parse(myWindow, NULL, wFind);
  271.                         break;
  272.                     case repeatFindCmd:
  273.                         wind_parse(myWindow, NULL, wRepeatFind);
  274.                         break;
  275.                     case replaceCmd:
  276.                         wind_parse(myWindow, NULL, wReplace);
  277.                         break;
  278.                     case repeatReplaceCmd:
  279.                         wind_parse(myWindow, NULL, wRepeatReplace);
  280.                         break;
  281.                     case shiftLeftCmd:
  282.                         if (WPeek->windowKind == tgeWKind)
  283.                             tge_left_shift_selection(myWindow, 4/*UNDONE*/);
  284.                         break;
  285.                     case shiftRightCmd:
  286.                         if (WPeek->windowKind == tgeWKind)
  287.                             tge_right_shift_selection(myWindow, 4/*UNDONE*/);
  288.                         break;
  289.                     }
  290.                 }
  291.             break;
  292.  
  293.         case tcl_menu:
  294.             scripts_menu_run(theitem);
  295.             break;
  296.         
  297.         case ttoolmenu:
  298.             clear_notify_q(NOTIFY_ALL);
  299.             switch(theitem) {
  300.                 case f_split_item:
  301.                     split_file();
  302.                     break;
  303.                 case f_join_item:
  304.                     join_files();
  305.                     break;
  306.                 case f_convert_item:
  307.                     ConvertTextFile();
  308.                     break;
  309.                 case f_texttype_item:
  310.                     FileTypeTEXT();
  311.                     break;
  312.                 case f_unixtomac_item:
  313.                     UnixToMac();
  314.                     break;
  315.                 case f_mactounix_item:
  316.                     MacToUnix();
  317.                     break;
  318.                 case f_pctomac_item:
  319.                     PCToMac();
  320.                     break;
  321.                 case f_mactopc_item:
  322.                     MacToPC();
  323.                     break;
  324.                 }
  325.             break;
  326.         
  327.         case mtoolmenu:
  328.             clear_notify_q(NOTIFY_ALL);
  329.             switch(theitem) {
  330.                 case f_macbinary_item:
  331.                     DoMacBinary(BINARY_FILE);
  332.                     break;
  333.                 case f_unmacbinary_item:
  334.                     DoMacBinary(MAC_FILE);
  335.                     break;
  336.                 case mb_info_item:
  337.                     SF_mbinfo();
  338.                     break;
  339.                 case f_binhex_item:
  340.                     SFencode_hqx();
  341.                     break;
  342.                 case f_unbinhex_item:
  343.                     SFdecode_hqx();
  344.                     break;
  345.                 case f_copyhier_item:
  346.                     copy_to_floppies();
  347.                     break;
  348.                 case f_macinfo_item:
  349.                     SFFileInfo();
  350.                     break;
  351.                 }
  352.             break;
  353.         
  354.         case hcsubmenu:
  355.             clear_notify_q(NOTIFY_ALL);
  356.             switch (theitem) {
  357.                 case hc_ftype_item:
  358.                     hfs_set_file_info(0);
  359.                     break;
  360.                 case hc_fcreator_item:
  361.                     hfs_set_file_info(1);
  362.                     break;
  363.                 case hc_folderview_item:
  364.                     set_folder_views();
  365.                     break;
  366.                 case hc_file_info_item:
  367.                     show_file_info();
  368.                     break;
  369.                 case hc_folder_info_item:
  370.                     show_folder_info();
  371.                     break;
  372.                 case hc_filefld_info_item:
  373.                     show_file_and_folder_info();
  374.                     break;
  375.                 }
  376.             break;
  377.         
  378.         case xcsubmenu:
  379.             clear_notify_q(NOTIFY_ALL);
  380.             break;
  381.  
  382.         case stoolmenu:
  383.             clear_notify_q(NOTIFY_ALL);
  384.             switch(theitem) {
  385.                 case f_stuff_file_item:
  386.                     StuffItFile();
  387.                     break;
  388.                 case f_stuff_mult_item:
  389.                     StuffItMultiple();
  390.                     break;
  391.                 case f_unstuff_item:
  392.                     UnStuffIt();
  393.                     break;
  394.                 }
  395.             break;
  396.         
  397.         case utoolmenu:
  398.             clear_notify_q(NOTIFY_ALL);
  399.             switch(theitem) {
  400.                 case f_uuencode_item:
  401.                     SFuuencode();
  402.                     break;
  403.                 case f_uudecode_item:
  404.                     SFuudecode();
  405.                     break;
  406.                 case f_decompress_item:
  407.                     SFdecompress();
  408.                     break;
  409.                 case f_compress_item:
  410.                     SFcompress();
  411.                     break;
  412.                 }
  413.             
  414.             break;
  415.  
  416.         case tarmenu:
  417.             clear_notify_q(NOTIFY_ALL);
  418.             switch(theitem) {
  419.                 case tar_create_item:
  420.                     ArCreate();
  421.                     break;
  422.                 case tar_extract_item:
  423.                     Extract();
  424.                     break;
  425.                 case tar_list_item:
  426.                     List();
  427.                     break;
  428.                 case tar_about_item:
  429.                     DoAboutBox();
  430.                     break;
  431.                 }
  432.             break;
  433.         
  434.         case ptarmenu:
  435.             clear_notify_q(NOTIFY_ALL);
  436.             switch(theitem) {
  437.                 case ptar_cnvrt_nl_item:
  438.                     cvtNl ^= true;
  439.                     CheckItem(ptar_menu_hdl, ptar_cnvrt_nl_item, cvtNl);
  440.                     break;
  441.                 case ptar_old_tar_item:
  442.                     oldArch ^= true;
  443.                     CheckItem(ptar_menu_hdl, ptar_old_tar_item, oldArch);
  444.                     break;
  445.                 case ptar_blk_size_item:
  446.                     DoBlockSize();
  447.                     break;
  448.                 case ptar_crtr_type_item:
  449.                     DoCreatorType();
  450.                     break;
  451.                 }
  452.             break;
  453.             
  454.         case asdmenu:
  455.             clear_notify_q(NOTIFY_ALL);
  456.             switch (theitem) {
  457.                 case asd_info_item:    
  458.                     SF_asd_info();
  459.                     break;
  460.                 case asd_to_mb_item:
  461.                     SF_asd_to_mb();
  462.                     break;
  463.                 case asd_to_mac_item:
  464.                     SF_asd_to_Mac();
  465.                     break;
  466.                 case mb_to_as_item:
  467.                     macbinary_to_asingle(0);
  468.                     break;
  469.                 case mb_to_ad_item:
  470.                     macbinary_to_adouble(0);
  471.                     break;
  472.                 case mac_to_as_item:
  473.                     macintosh_to_asingle(0);
  474.                     break;
  475.                 case mac_to_ad_item:
  476.                     macintosh_to_adouble(0);
  477.                     break;
  478.                 }
  479.             break;
  480.         
  481.         }
  482.     
  483.     /*
  484.     ** Since many commands can change the
  485.     ** current working directory, set it back!
  486.     */
  487.     TclMac_CWDSetVol();
  488.     
  489.     HiliteMenu(0);
  490.     }
  491.