home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / vide / videcmdw.cpp < prev    next >
C/C++ Source or Header  |  1999-02-22  |  32KB  |  1,143 lines

  1. //=======================================================================
  2. //    videCmdw.cpp:    Source for videCmdwindow class
  3. //=======================================================================
  4.  
  5. #include <v/vnotice.h>    // for vNoticeDialog
  6. #include <v/vkeys.h>    // to map keys
  7. #include <v/vfilesel.h>
  8. #include <v/vfontsel.h>
  9. #include <v/vutil.h>
  10. #include <v/vynreply.h>
  11. #include <v/vreply.h>
  12. #include <v/vicon.h>
  13.  
  14. #include "videapp.h"    // main header for some global defs
  15.  
  16. #include "videcmdw.h"    // our header
  17.  
  18. #include "vrundlg.h"
  19. #include "vseeci.h"    // command interp for See
  20.  
  21. //    Start defines for the main window with 100
  22.  
  23. //@V@:BeginIDs
  24.     enum {
  25.     m_FirstCmd = 100,         // Dummy Command
  26.     m_Options,            // set options
  27.         m_View,                // view a file R/O
  28.         m_SaveClose,
  29.         m_EditHelp,
  30.         m_Make,
  31.         m_MakeAll,
  32.         m_MakeClean,
  33.         m_MakeDebug,
  34.         m_MakeArgs,
  35.         m_StopMake,
  36.         m_SelectMake,
  37.  
  38.     m_Project,           // Project menu
  39.     m_ProjectNew,        // ProjectDialog menu
  40.     m_ProjectOpen,          // ProjectDialog menu
  41.     m_ProjectEdit,
  42.     m_ProjectSave,
  43.     m_ProjectClose,
  44.  
  45.         m_Tools,
  46.         m_RunVgen,
  47.         m_RunViconed,
  48.         m_RunCmd,
  49.         m_RunShell,
  50.  
  51.         lblMkFile,
  52.     lblLineCol,            // Status Bar
  53.     lblIns,
  54.     lblSBlank,
  55.     lblEMsg,
  56.         lblStatTitle,
  57.     blkLast                // Last item
  58.       };
  59. //@V@:EndIDs
  60.  
  61. //@V@:BeginPulldownMenu FileMenu
  62.     static vMenu FileMenu[] =
  63.       {
  64.     {"&New", M_New, isSens, notChk, noKeyLbl, noKey, noSub},
  65.     {"&Open...", M_Open, isSens, notChk, noKeyLbl, noKey, noSub},
  66.         {"&View...", m_View, isSens, notChk, noKeyLbl, noKey, noSub},
  67.     {"&Save", M_Save, isSens, notChk, noKeyLbl, noKey, noSub},
  68.     {"Save &as...", M_SaveAs, isSens, notChk, noKeyLbl, noKey, noSub},
  69.     {"&Close", M_CloseFile, isSens, notChk, noKeyLbl, noKey, noSub},
  70.         {"Save and Close", M_SaveClose, isSens, notChk, noKeyLbl, noKey, noSub},
  71.     {"-", M_Line, notSens, notChk, noKeyLbl, noKey, noSub},
  72.     {"E&xit", M_Exit, isSens, notChk, noKeyLbl, noKey, noSub},
  73.     {NULL}
  74.       };
  75.  
  76. //@V@:BeginPulldownMenu EditMenu
  77.     static vMenu EditMenu[] =
  78.       {
  79.     {"Cut  ", M_Cut, notSens, notChk, "^X", noKey, noSub},
  80.     {"Copy ", M_Copy, notSens, notChk, "^C", noKey, noSub},
  81.     {"Paste", M_Paste, notSens, notChk, "^V", noKey, noSub},
  82.     {"-", M_Line, notSens, notChk, noKeyLbl, noKey, noSub},
  83.     {"Find", edFind, isSens,notChk,noKeyLbl,noKey,noSub},
  84.     {"Find Next", edFindNext, isSens,notChk,noKeyLbl,noKey,noSub},
  85.     {"Find Matching Paren", edBalMatch, isSens,notChk,noKeyLbl,noKey,noSub},
  86.     {"-", M_Line, notSens, notChk, noKeyLbl, noKey, noSub},
  87.         {"Edit Help", m_EditHelp, isSens, notChk, noKeyLbl, noKey, noSub},
  88.  
  89.     {NULL}
  90.       };
  91. //@V@:EndPulldownMenu
  92.  
  93. //@V@:BeginPulldownMenu OptMenu
  94.     static vMenu OptMenu[] =
  95.       {
  96.     {"Font", M_Font,isSens,notChk,noKeyLbl,noKey,noSub},
  97.     {NULL}
  98.       };
  99. //@V@:EndPulldownMenu
  100.  
  101. //@V@:BeginPulldownMenu MakeMenu
  102.     static vMenu MakeMenu[] =
  103.       {
  104.      {"Select Makefile", m_SelectMake, isSens, notChk, noKeyLbl, noKey, noSub},
  105.         {"-", M_Line, notSens, notChk, noKeyLbl, noKey, noSub},
  106.         {"Make", m_MakeAll, isSens, notChk, noKeyLbl, noKey, noSub},
  107.         {"Make Clean", m_MakeClean, isSens, notChk, noKeyLbl, noKey, noSub},
  108.         {"Make <target>", m_MakeArgs, isSens, notChk, noKeyLbl, noKey, noSub},
  109.         {"Make Debug", m_MakeDebug, notSens, notChk, noKeyLbl, noKey, noSub},
  110.         {"-", M_Line, notSens, notChk, noKeyLbl, noKey, noSub},
  111.         {"Stop Make", m_StopMake, isSens, notChk, noKeyLbl, noKey, noSub},
  112.         {NULL}
  113.       };
  114. //@V@:EndPulldownMenu
  115.  
  116. //@V@:BeginPulldownMenu ToolsMenu
  117.     static vMenu ToolsMenu[] =
  118.       {
  119.         {"Run a program", m_RunCmd, isSens, notChk, noKeyLbl, noKey, noSub},
  120.         {"Run OS Shell", m_RunShell, isSens, notChk, noKeyLbl, noKey, noSub},
  121.         {"-", M_Line, notSens, notChk, noKeyLbl, noKey, noSub},
  122.         {"V App Gen", m_RunVgen, isSens, notChk, noKeyLbl, noKey, noSub},
  123.         {"V Icon Editor", m_RunViconed, isSens, notChk, noKeyLbl, noKey, noSub},
  124.         {NULL}
  125.       };
  126. //@V@:EndPulldownMenu
  127.  
  128. //@V@:BeginPulldownMenu ProjectMenu
  129.     static vMenu ProjectMenu[] =
  130.       {
  131.     {"&Open", m_ProjectOpen, isSens, notChk, noKeyLbl, noKey, noSub},
  132.     {"&Close", m_ProjectClose, isSens, notChk, noKeyLbl, noKey, noSub},
  133.     {"&New", m_ProjectNew, isSens, notChk, noKeyLbl, noKey, noSub},
  134.     {"&Edit", m_ProjectEdit, isSens, notChk, noKeyLbl, noKey, noSub},
  135.     {"&Save", m_ProjectSave, isSens, notChk, noKeyLbl, noKey, noSub},
  136.         {NULL}
  137.       };
  138. //@V@:EndPulldownMenu
  139.  
  140. //@V@:BeginMenu StandardMenu
  141.     static vMenu StandardMenu[] =
  142.       {
  143.     {"&File", M_File, isSens, notUsed, notUsed, noKey, &FileMenu[0]},
  144.     {"&Edit", M_Edit, isSens, notUsed, notUsed, noKey, &EditMenu[0]},
  145.     {"&Make", m_Make, isSens, notUsed, notUsed, noKey, &MakeMenu[0]},
  146.         {"&Project",m_Project,isSens,notUsed,notUsed,noKey,&ProjectMenu[0]},
  147.         {"&Tools", m_Tools, isSens, notUsed, notUsed, noKey, &ToolsMenu[0]},
  148.         {"&Options", m_Options, isSens, notUsed, notUsed, noKey, &OptMenu[0]},
  149.     {NULL}
  150.       };
  151. //@V@:EndMenu
  152.  
  153. //vbm1
  154. #define open_width 16
  155. #define open_height 16
  156. static unsigned char open_bits[] = {
  157.  0x00,0x00,0x00,0x0e,0x00,0x51,0x00,0x60,0x00,0x70,0x1c,0x00,0xe2,0x07,0x02,
  158.  0x04,0x02,0x04,0xc2,0x7f,0xa2,0x2a,0x52,0x15,0xaa,0x0a,0x56,0x05,0xfc,0x03,
  159.  0x00,0x00};
  160.     static vIcon openI(&open_bits[0],open_height,open_width);
  161.  
  162. //vbm1
  163. #define find_width 16
  164. #define find_height 16
  165. static unsigned char find_bits[] = {
  166.  0x00,0x00,0xf0,0x01,0x08,0x02,0x44,0x04,0xa2,0x08,0x12,0x09,0xf2,0x09,0x12,
  167.  0x09,0x14,0x05,0x08,0x0e,0xf0,0x1d,0x00,0x38,0x00,0x70,0x00,0x60,0x00,0x00,
  168.  0x00,0x00};
  169.     static vIcon findI(&find_bits[0],find_height,find_width);
  170.  
  171. //vbm1
  172. #define findagn_width 16
  173. #define findagn_height 16
  174. static unsigned char findagn_bits[] = {
  175.  0x00,0x00,0xf0,0x01,0x08,0x02,0x44,0x04,0xa2,0x08,0x12,0x09,0xf2,0x09,0x12,
  176.  0x09,0x14,0x05,0x08,0x0e,0xf0,0x1d,0x66,0x38,0xcc,0x70,0x98,0x61,0xcc,0x00,
  177.  0x66,0x00};
  178.     static vIcon findagnI(&findagn_bits[0],findagn_height,findagn_width);
  179.  
  180. //vbm1
  181. #define openprj_depth 1
  182. #define openprj_width 16
  183. #define openprj_height 16
  184. static unsigned char openprj_bits[] = {
  185.  0x00,0x1e,0x00,0xa3,0xbc,0xc0,0x22,0xe0,0x21,0x00,0xe1,0x7f,0x01,0x40,0xdd,
  186.  0x5d,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0xdd,0x5d,0x01,0x40,
  187.  0xff,0x7f};
  188.     static vIcon openprjI(&openprj_bits[0],openprj_height,openprj_width);
  189.  
  190. //vbm1
  191. #define selmake_depth 1
  192. #define selmake_width 16
  193. #define selmake_height 16
  194. static unsigned char selmake_bits[] = {
  195.  0xbd,0x57,0xa5,0x54,0xa5,0x54,0xa5,0x54,0xa5,0x54,0xbd,0x57,0x00,0x00,0xc0,
  196.  0x03,0x7f,0x22,0x01,0x32,0x01,0xfa,0x01,0xfa,0x01,0x32,0x01,0x22,0x01,0x02,
  197.  0xff,0x03};
  198.     static vIcon selmakeI(&selmake_bits[0],selmake_height,selmake_width);
  199.  
  200. //vbm1
  201. #define make_depth 1
  202. #define make_width 16
  203. #define make_height 16
  204. static unsigned char make_bits[] = {
  205.  0xc0,0x03,0x7f,0x12,0x01,0x32,0x01,0x22,0x01,0x22,0x01,0x32,0x01,0x12,0xff,
  206.  0x13,0x00,0x10,0x00,0x7c,0x00,0x38,0x00,0x10,0x9d,0xeb,0x95,0xaa,0x95,0xaa,
  207.  0x9d,0xeb};
  208.     static vIcon makeI(&make_bits[0],make_height,make_width);
  209.  
  210.  
  211. //vbm1
  212. #define vrun_depth 1
  213. #define vrun_width 16
  214. #define vrun_height 16
  215. static unsigned char vrun_bits[] = {
  216.  0x00,0x00,0x80,0x1f,0xc0,0x0f,0xe0,0x07,0xf0,0x03,0xf8,0x1f,0xfc,0x1f,0xc0,
  217.  0x0f,0xe0,0x07,0xf0,0x03,0xf8,0x0f,0x80,0x07,0xc0,0x03,0xe0,0x01,0x70,0x00,
  218.  0x00,0x00};
  219.     static vIcon vrunI(&vrun_bits[0],vrun_height,vrun_width);
  220.  
  221. //vbm1
  222. #define vgen_depth 1
  223. #define vgen_width 16
  224. #define vgen_height 16
  225. static unsigned char vgen_bits[] = {
  226.  0xf0,0x01,0xd8,0x03,0x80,0x1f,0xc0,0x0c,0x60,0x04,0x30,0x00,0x18,0x00,0x8c,
  227.  0xc1,0x86,0xc1,0x03,0x41,0x01,0x63,0x00,0x22,0x00,0x36,0x00,0x1c,0x00,0x1c,
  228.  0x00,0x08};
  229.     static vIcon vgenI(&vgen_bits[0],vgen_height,vgen_width);
  230.  
  231. //vbm1
  232. #define icon_width 16
  233. #define icon_height 16
  234. static unsigned char icon_bits[] = {
  235.  0x00,0x00,0x00,0x00,0x00,0x7f,0x00,0x6b,0x00,0x55,0x00,0x6b,0x80,0x57,0x50,
  236.  0x68,0x38,0x50,0x3c,0x70,0x3e,0x10,0x20,0x10,0x40,0x08,0x80,0x07,0x00,0x00,
  237.  0x00,0x00};
  238.     static vIcon iconI(&icon_bits[0],icon_height,icon_width);
  239.  
  240. //@V@:BeginCmdPane ToolBar
  241.     static CommandObject ToolBar[] =
  242.       {
  243.     {C_IconButton,M_Open,0,"Open",&openI,CA_None,isSens,NoFrame,0,0,0,"Open File"},
  244.     {C_IconButton,m_ProjectOpen,0,"OpenPrj",&openprjI,CA_None,isSens,NoFrame,0,0,0,"Open Project"},
  245.         {C_IconButton,m_SelectMake,0,"Sel Mk",&selmakeI,CA_None,isSens,NoFrame,0,0,0,
  246.            "Select Makefile"},
  247.     {C_Blank,99,0," ",NoList,CA_None,isSens,NoFrame,0,0},
  248.     {C_IconButton,m_RunVgen,0,"V Gen",&vgenI,CA_None,isSens,NoFrame,0,0,0,"V App Gen"},
  249.     {C_IconButton,m_RunViconed,0,"Icon Ed",&iconI,CA_None,isSens,NoFrame,0,0,0,"V Icon Editor"},
  250.     {C_Blank,99,0," ",NoList,CA_None,isSens,NoFrame,0,0},
  251.     {C_IconButton,edFind,0,"Find",&findI,CA_None,isSens,NoFrame,0,0,0,"Find"},
  252.     {C_IconButton,edFindNext,0,"Find Next",&findagnI,CA_None,isSens,NoFrame,0,0,0,"Find Next"},
  253.         {C_Blank,99,0," ",NoList,CA_None,isSens,NoFrame,0,0},
  254.         {C_IconButton,m_MakeAll,0,"MAKE",&makeI,CA_None,isSens,NoFrame,0,0,0,"make all"},
  255.     {C_IconButton,m_RunCmd,0,"Run a program",&vrunI,CA_None,isSens,NoFrame,0,0,0,"Run a program"},
  256.       {C_EndOfList,0,0,0,0,CA_None,0,0,0}
  257.       };
  258. //@V@:EndCmdPane
  259.  
  260. //@V@:BeginStatPane StatBar
  261.     static vStatus StatBar[] =
  262.       {
  263.         {" V IDE ", lblStatTitle, CA_NoBorder, isSens, 0},
  264.     {"1/1     ", lblLineCol, CA_None, isSens, 0},
  265.     {"    Insert   ", lblIns, CA_None, isSens, 0},
  266.     // handle messages up to 40 chars
  267.     {"                                      ", lblEMsg, /* CA_NoBorder */ CA_None, isSens, 0},
  268.     {0,0,0,0,0}
  269.       };
  270. //@V@:EndStatPane
  271.  
  272.  
  273.     static int filterIndex = 0;
  274.     static char* filter[] =
  275.       {
  276.         "*",
  277.         "*.txt",
  278.         "*.c;*.cpp;*.cxx;*.h;*.hxx",
  279.         0
  280.       };
  281.  
  282.     static char makebName[] = "make";
  283.  
  284. //====================>>> videCmdWindow::videCmdWindow <<<====================
  285.   videCmdWindow::videCmdWindow(char* name, int width, int height) :
  286.     vCmdWindow(name, width,  height)
  287.   {
  288.     UserDebug1(Constructor,"videCmdWindow::videCmdWindow(%s) Constructor\n",name)
  289.  
  290.     // local inits
  291.  
  292.     fileName[0] = 0;
  293.  
  294.     // The Menu Bar
  295.     videMenu = new vMenuPane(StandardMenu);
  296.     AddPane(videMenu);
  297.  
  298.     // The Command Pane
  299.     videCmdPane = new vCommandPane(ToolBar);
  300.     AddPane(videCmdPane);
  301.  
  302.     // The Canvas
  303.     vedCanvas = new vedTextEditor(this);
  304.     AddPane(vedCanvas);
  305.  
  306.     if (((videApp*)theApp)->GetEmulation() == See)
  307.       {
  308.         vedCI = (vTextEdCmdInterp*) new vSeeCI(vedCanvas, this); // override interp
  309.                         // ed canvas will do delete at end
  310.         vedCanvas->ChangeCmdInterp(vedCI);
  311.       }
  312.     else
  313.         vedCI = 0;
  314.  
  315.  
  316.     // The Status Bar
  317.     videStatus = new vStatusPane(StatBar);
  318.     AddPane(videStatus);
  319.  
  320.     // Associated dialogs
  321.  
  322.     // Other stuff
  323.  
  324.     ideMake = new videMake();
  325.  
  326.     // Show Window
  327.  
  328.     ShowWindow();
  329.  
  330.     vedFont = ((videApp*)theApp)->DefaultFont;
  331.  
  332. #ifdef XXXX
  333. #ifdef V_VersionX
  334.     vedFont.SetFontValues(vfFixed,12);    // use Courier rathern than default
  335. #else
  336. #ifdef DEVEL
  337.     vedFont.SetFontValues(vfFixed,10,vfNormal,vfBold);    // use Courier rathern than default
  338. #else
  339.     vedFont.SetFontValues(vfFixed,10);    // use Courier rathern than default
  340. #endif
  341. #endif
  342. #endif XXXX
  343.     vedCanvas->SetFont(vedFont);
  344.     vedCanvas->SetTextRowsCols(height,width);
  345.     (vedCanvas->GetCmdInterp())->InitCmdInterp();
  346.  
  347.   }
  348.  
  349. //====================>>> videCmdWindow::~videCmdWindow <<<====================
  350.   videCmdWindow::~videCmdWindow()
  351.   {
  352.     UserDebug(Destructor,"videCmdWindow::~videCmdWindow() destructor\n")
  353.  
  354.     // Now put a delete for each new in the constructor.
  355.  
  356.     delete videMenu;
  357.     delete vedCanvas;
  358.     delete videCmdPane;
  359.     delete videStatus;
  360.     delete ideMake;
  361.   }
  362.  
  363. //====================>>> videCmdWindow::ChangeLoc <<<====================
  364.   void videCmdWindow::ChangeLoc(long line, int col)
  365.   {
  366.     char buff[20];
  367.     char colbuff[10];
  368.     char outbuff[20];
  369.     int ll;
  370.  
  371.     LongToStr(line,buff);
  372.  
  373.     IntToStr(col,colbuff);
  374.  
  375.     // center the line/col string
  376.  
  377.     int totalLen = strlen(buff) + strlen(colbuff) + 1;
  378.  
  379.     int add = (9 - totalLen) / 2;
  380.  
  381.     for (ll = 0 ; ll < add ; ++ll)
  382.     outbuff[ll] = ' ';
  383.     outbuff[ll] = 0;
  384.     
  385.     strcat(outbuff,buff); strcat(outbuff,"/");
  386.     strcat(outbuff,colbuff);
  387.  
  388.     // pad with trailing blanks so X doesn't shift things
  389.  
  390.     for (ll = strlen(outbuff) ; ll < 9 ; ++ll)
  391.     outbuff[ll] = ' ';
  392.     outbuff[ll] = 0;
  393.     SetString(lblLineCol,outbuff);
  394.  
  395.   }
  396.  
  397. //=========================>>> videCmdWindow::FindCmdWin <<<===========================
  398.   videCmdWindow* videCmdWindow::FindCmdWin(char* fname)
  399.   {
  400.     // Find a command window by file name
  401.     videCmdWindow* clist;
  402.   
  403.     // try to match full name first
  404.     for (clist = (videCmdWindow*)GetCmdWinList() ;
  405.          clist != 0 ; clist = (videCmdWindow*)clist->GetNextCmdWin())
  406.       {
  407.         char* fp = clist->GetFileName();
  408.         if (strcmp(fname, fp) == 0)
  409.             return clist;
  410.       }
  411.  
  412.     // now just match file, not path
  413.     for (clist = (videCmdWindow*)GetCmdWinList() ;
  414.          clist != 0 ; clist = (videCmdWindow*)clist->GetNextCmdWin())
  415.       {
  416.         char* cp = strstr(clist->GetFileName(), fname);    // substring?
  417.         if (cp != 0)
  418.           {
  419.             if (strcmp(cp,fname) == 0)            // substring match
  420.                 return clist;
  421.           }
  422.       }
  423.     return 0;
  424.   }
  425.  
  426. //====================>>> videCmdWindow::GotoErrorLine <<<====================
  427.   void videCmdWindow::GotoErrorLine()
  428.   {
  429.     // Pick up the error from the selected line in the message window
  430.     // and open that file, going to the error line
  431.  
  432.     // First, get pointer to the error message window
  433.     videCmdWindow* cmdw = ((videApp*)theApp)->GetMsgWindow();
  434.  
  435.     char errLine[100];
  436.  
  437.     long curLine = (cmdw->vedCanvas)->GetCurLine();
  438.     (void)(cmdw->vedCanvas)->getLine(errLine, 99, curLine);
  439.  
  440.     // error line in format "  ! filename.cpp:###:msg"
  441.  
  442.     char fileBase[100];
  443.     char cLineNum[20];
  444.     if (errLine[2] != '!')
  445.       {
  446.         vNoticeDialog note(this);       // for user notification
  447.         note.Notice("Selected line is not a g++ error message.");
  448.         return;
  449.       }
  450.     int ix;                // get base file name
  451.     for (ix = 4 ; ix < 100 && errLine[ix] != ':' ; ++ix)
  452.         fileBase[ix-4] = errLine[ix];
  453.     fileBase[ix-4] = 0;
  454.  
  455.     char* np = &cLineNum[0];        // get the line number
  456.     for ( ++ix ; ix < 100 && errLine[ix] != ':' ; ++ix)
  457.         *np++ = errLine[ix];
  458.     *np = 0;
  459.     long lineNum = StrToLong(cLineNum);
  460.  
  461.  
  462.     // start by seeing if file is in base directory
  463.     char fullPath[maxFileNameSize];
  464.  
  465.     strcpy(fullPath,((videApp*)theApp)->GetMkFile());
  466.     ix = strlen(fullPath);
  467.     while (ix > 0)            // just that path
  468.       {
  469.         if (fullPath[ix] == '\\' || fullPath[ix] == '/')
  470.           {
  471.             fullPath[ix+1] = 0;        // keep the last /
  472.             break;
  473.           }
  474.         --ix;
  475.       }
  476.  
  477.     char* namePtr = fullPath;
  478.     strcat(fullPath,fileBase);
  479.     videCmdWindow* openw = FindCmdWin(fullPath);
  480.     if (openw == 0)        // try just base name
  481.       {
  482.         openw = FindCmdWin(fileBase);
  483.         namePtr = fileBase;    // just the base name
  484.       }
  485.  
  486.     if (openw != 0)        // EASY, already open
  487.       {
  488.         (openw->GetTextEd())->EditCommand(edLineGoto, 12);
  489.         (openw->GetTextEd())->EditCommand(edLineGoto, lineNum);
  490.         openw->RaiseWindow();
  491.         return;
  492.       }
  493.  
  494.     // Not already open, so need to open a new window.
  495.  
  496.     openw = (videCmdWindow*)
  497.                     theApp->NewAppWin(0,"V Text Editor", 90, 24);
  498.     if (!openw)
  499.         return;           // should never happen...
  500.     if (!openw->OpenFile(fullPath,0,0))
  501.       {
  502.           // hmmm - the file doesn't exist on Makefile path
  503.         // try something else
  504.         vFileSelect fsel(this);     // make an instance
  505.         strcpy(fullPath,fileBase);    // base only
  506.         if (!fsel.FileSelect("Open file",fullPath,maxFileNameSize,
  507.                      filter,filterIndex))
  508.           {
  509.             openw->CloseWin();
  510.             return;
  511.           }
  512.         if (!openw->OpenFile(fullPath,0,0))
  513.           {
  514.               openw->CloseWin();
  515.               return;
  516.           }
  517.         (openw->GetTextEd())->EditCommand(edLineGoto, 12);
  518.         (openw->GetTextEd())->EditCommand(edLineGoto, lineNum);
  519.       }
  520.     else
  521.       {
  522.         (openw->GetTextEd())->EditCommand(edLineGoto, 12);
  523.         (openw->GetTextEd())->EditCommand(edLineGoto, lineNum);
  524.         openw->RaiseWindow();
  525.       }
  526.   }
  527.  
  528. //====================>>> videCmdWindow::ChangeInsMode <<<====================
  529.   void videCmdWindow::ChangeInsMode(int IsInsMode, char* msg)
  530.   {
  531.     if (msg && *msg)
  532.         SetString(lblIns,msg);
  533.     else if ((vedCanvas->GetEdState()).readOnly)
  534.         SetString(lblIns,"  View  ");
  535.     else if (IsInsMode)
  536.     SetString(lblIns," Insert ");
  537.     else
  538.     SetString(lblIns,"Overtype");
  539.   }
  540.  
  541. //====================>>> videCmdWindow::SetRdOnly <<<====================
  542.   void videCmdWindow::SetRdOnly(int ro)
  543.   {
  544.     vedCanvas->SetRdOnly(ro);
  545.     vedCanvas->Verify();
  546.  
  547.     ChangeInsMode(1);
  548.    }
  549.  
  550. //====================>>> videCmdWindow::StatusMessage <<<====================
  551.   void videCmdWindow::StatusMessage(char *msg)
  552.   {
  553.     char lineout[42];
  554.     int ix;
  555.  
  556.     // copy up to 40 chars
  557.     for (ix = 0 ; ix < 40 && msg[ix] ; ++ix)
  558.     lineout[ix] = msg[ix];
  559.  
  560.     // pad with trailing blanks
  561.   //  for ( ; ix < 40 ; ++ix)
  562.   //    lineout[ix] = ' ';
  563.  
  564.     lineout[ix] = 0;
  565.  
  566.     SetString(lblEMsg,lineout);
  567.   }
  568.  
  569. //====================>>> videCmdWindow::ErrorMsg <<<====================
  570.   void videCmdWindow::ErrorMsg(char *str)
  571.   {
  572.       StatusMessage(str);
  573.   }
  574.  
  575. //====================>>> videCmdWindow::KeyIn <<<====================
  576.   void videCmdWindow::KeyIn(vKey keysym, unsigned int shift)
  577.   {
  578.     StatusMessage(" ");
  579.     if (!vedCanvas->EditKeyIn(keysym, shift))
  580.     vCmdWindow::KeyIn(keysym, shift);
  581.   }
  582.  
  583. //==============>>> videCmdWindow::CheckClose <<<================
  584.   int videCmdWindow::CheckClose(int ask)
  585.   {
  586.     // Checks to see if the user wants to save changes, if changes have been
  587.     // done, before it closes the application.
  588.     // Return 1 if ok to close now, 0 to abort
  589.  
  590.     if (this ==((videApp*)theApp)->GetMsgWindow())
  591.       {
  592.          // we are the main message window...
  593.          if (NumCmdWindows() > 1)
  594.              return 0;
  595.       }
  596.  
  597.     if (vedCanvas->Changed())    // changes have been made
  598.       {
  599.     if (ask)
  600.       {
  601.         vYNReplyDialog ynr(this);
  602.         int ans = ynr.AskYN("Save new or changed file?");
  603.         if (ans == 0)
  604.           {
  605.         return 1;           // don't want to save
  606.           }
  607.         if (ans == -1)          // cancel
  608.         return 0;
  609.       }
  610.  
  611.         // ok, want to save changed file
  612.         if (*fileName)                    // have a name
  613.           {
  614.             if (!vedCanvas->SaveFile(fileName))        // Save in fileName
  615.               {
  616.                 vNoticeDialog note(this);       // for user notification
  617.                 note.Notice("Unable to save file");
  618.                 return 0;
  619.               }
  620.           }
  621.         else                            // need to request name
  622.           {
  623.             vFileSelect fsel(this);     // V file select dialog
  624.  
  625.             if (!fsel.FileSelectSave("Save file as",
  626.                 fileName,99,filter,filterIndex) || !*fileName)
  627.             return 0;
  628.  
  629.             if (!vedCanvas->SaveFile(fileName))        // Save in fileName
  630.               {
  631.                 vNoticeDialog note(this);       // for user notification
  632.                 note.Notice("Unable to save file");
  633.                 return 0;
  634.               }
  635.           }
  636.       }
  637.     return 1;
  638.   }
  639.  
  640. //====================>>> videCmdWindow::WindowCommand <<<====================
  641.   void videCmdWindow::WindowCommand(ItemVal id, ItemVal val, CmdType cType)
  642.   {
  643.     // Default: route menu and toolbar commands here
  644.  
  645.     UserDebug1(CmdEvents,"videCmdWindow:WindowCommand(%d)\n",id)
  646.  
  647.     StatusMessage(" ");
  648.     switch (id)
  649.       {
  650.     //@V@:Case M_New
  651.     case M_New:
  652.       {
  653.             videCmdWindow* ncmdw = this;
  654.             ncmdw = (videCmdWindow*) theApp->NewAppWin(0,"V Text Editor", 80 , 24);
  655.             if (ncmdw)        // If a new window, raise it
  656.                 ncmdw->RaiseWindow();
  657.         break;
  658.       }    //@V@:EndCase
  659.  
  660.     //@V@:Case M_Open
  661.         case m_View:
  662.     case M_Open:             // View/Open - always open a new window!
  663.       {
  664.         char name[maxFileNameSize+2] = ""; // start out with null name
  665.         vFileSelect fsel(this);     // make an instance
  666.  
  667.         int oans = fsel.FileSelect("Open file",name,maxFileNameSize,
  668.                      filter,filterIndex);
  669.  
  670.         if (oans)
  671.           {
  672.         videCmdWindow* openw = FindCmdWin(name);
  673.         if (openw != 0)
  674.           {
  675.             vNoticeDialog note(this);       // for user notification
  676.             note.Notice("Sorry - you can only edit one copy of each file.");
  677.             return;         // @@@ not twice
  678.           }
  679.         videCmdWindow* cmdw = (videCmdWindow*)
  680.         theApp->NewAppWin(0,"V Text Editor", 80, 24);
  681.         if (!cmdw)
  682.             break;
  683.         if (!cmdw->OpenFile(name))
  684.           {
  685.             vNoticeDialog note(this);
  686.             note.Notice("Unable to open specified file.");
  687.             if (cmdw != this)        // A new window?
  688.             delete cmdw;
  689.             break;
  690.           }
  691.         else
  692.           {
  693.             if (cmdw != this)        // If a new window, raise it
  694.             cmdw->RaiseWindow();
  695.           }
  696.  
  697.         SetSyntaxType(cmdw,name,0);
  698.  
  699.         edState curState = cmdw->vedCanvas->GetEdState();
  700.         if (id == m_View)
  701.           {
  702.             curState.readOnly = 1;
  703.           }
  704.  
  705.         cmdw->vedCanvas->SetEdState(curState);
  706.         cmdw->vedCanvas->Verify();
  707.         cmdw->ChangeInsMode(1);
  708.           }
  709.  
  710.         break;
  711.       }    //@V@:EndCase
  712.  
  713.     //@V@:Case M_Save
  714.     case M_Save:
  715.       {
  716.         CheckClose(0);
  717.         break;
  718.       }    //@V@:EndCase
  719.  
  720.     //@V@:Case M_SaveAs
  721.     case M_SaveAs:
  722.       {
  723.             vFileSelect fsel(this);     // V file select dialog
  724.  
  725.             if (!fsel.FileSelectSave("Save file as",
  726.                 fileName,99,filter,filterIndex) || !*fileName)
  727.             break;
  728.  
  729.             if (!vedCanvas->SaveFile(fileName))        // Save in fileName
  730.               {
  731.                 vNoticeDialog note(this);       // for user notification
  732.                 note.Notice("Unable to save file");
  733.               }
  734.         else
  735.           {
  736.         SetTitle(fileName);
  737.         SetSyntaxType(this, fileName,0);
  738.           }
  739.         break;
  740.       }    //@V@:EndCase
  741.  
  742.     //@V@:Case M_CloseFile
  743.     case M_CloseFile:
  744.       {
  745.         if (!CheckClose(1))
  746.         break;
  747.         CloseWin();
  748.         break;
  749.       }    //@V@:EndCase
  750.  
  751.     //@V@:Case m_SaveClose
  752.     case M_SaveClose:
  753.       {
  754.         if (!CheckClose(0))
  755.         break;
  756.         CloseWin();
  757.         break;
  758.       }    //@V@:EndCase
  759.  
  760.  
  761.     //@V@:Case M_Exit
  762.     case M_Exit:
  763.       {
  764.         theApp->Exit();
  765.         break;
  766.       }    //@V@:EndCase
  767.  
  768.         //@V@:Case btnDoMake
  769.     case m_MakeAll:
  770.       {
  771.         theApp->SendWindowCommandAll(M_Save,1,C_Button);
  772.             if (ideMake->DoMake(this, makebName))
  773.           {
  774.             if (ideMake->CheckMake(makebName))
  775.             ideMake->DoMake(this, makebName);
  776.           }
  777.         break;
  778.       }    //@V@:EndCase
  779.  
  780.          //@V@:Case m_MakeArgs
  781.     case m_MakeArgs:
  782.       {
  783.             static char target[80] = "";
  784.             vReplyDialog rp(this);
  785.             if (rp.Reply("Enter make target",target,79) == M_Cancel)
  786.                 break;
  787.         char cmd[100];
  788.             strcpy(cmd,makebName); strcat(cmd," ");
  789.             strcat(cmd,target);
  790.         theApp->SendWindowCommandAll(M_Save,1,C_Button);
  791.             (void) ideMake->DoMake(this, cmd);
  792.         break;
  793.       }    //@V@:EndCase
  794.  
  795.         case m_MakeClean:
  796.           {
  797.             char cmd[100];
  798.             strcpy(cmd,makebName); strcat(cmd," clean");
  799.         theApp->SendWindowCommandAll(M_Save,1,C_Button);
  800.             (void) ideMake->DoMake(this, cmd);
  801.         break;
  802.       }    //@V@:EndCase
  803.  
  804.         case m_StopMake:
  805.           {
  806.             ideMake->StopMake();
  807.         break;
  808.       }    //@V@:EndCase
  809.  
  810.         case m_MakeDebug:
  811.           {
  812.              char cmd[100];
  813.             strcpy(cmd,makebName); strcat(cmd," debug");
  814.         theApp->SendWindowCommandAll(M_Save,1,C_Button);
  815.             if (ideMake->DoMake(this, cmd))
  816.           {
  817.             if (ideMake->CheckMake(cmd))
  818.             ideMake->DoMake(this, cmd);
  819.           }
  820.         break;
  821.       }    //@V@:EndCase
  822.  
  823.  
  824.     //**************************************************
  825.     // The Project Menu
  826.  
  827.     case m_ProjectClose:
  828.       {
  829.         if (prjName[0] != 0)
  830.           {
  831.         mm.saveProject(prjName);    // save previous
  832.           }
  833.         strcpy(prjName,"");
  834.         mm.setDefaults();
  835.             ((videApp*)theApp)->SetMkFile("");
  836.         break;
  837.       }
  838.  
  839.     case m_ProjectEdit:
  840.       {
  841.         if (prjName[0] == 0)
  842.           {
  843.         //open prj file
  844.         char MSDOSpath[256]= "";
  845.         int fi = 0;
  846.         static char* makeFilter[] = {"*.vpj", 0};
  847.         vFileSelect fsel(this);
  848.  
  849.         int ans = fsel.FileSelect("Select a project file",
  850.             MSDOSpath ,255, makeFilter,fi);
  851.         char uxfn[256]="";
  852.         if (ans && *MSDOSpath) //filename picked
  853.             Dos2UxFName(MSDOSpath, prjName, 0);
  854.         else
  855.             break;
  856.         mm.loadProject(prjName);
  857.           }
  858.         projectDialog PDlg(mm,this);
  859.         if (!PDlg.editProject())    // edit an old one
  860.         break;
  861.         mm.saveProject(prjName);
  862.  
  863.             ((videApp*)theApp)->SetMkFile(mm.makeName);
  864.  
  865.         break;
  866.       }
  867.  
  868.     case m_ProjectNew:
  869.       {
  870.         char MSDOSpath[256]= "";
  871.         ItemVal dans, oans, rval;
  872.         int fi = 0;
  873.         static char* makeFilter[] = {"*.vpj", 0};
  874.         vFileSelect fsel(this);
  875.  
  876.         if (prjName[0] != 0)
  877.           {
  878.         mm.saveProject(prjName);    // save previous
  879.           }
  880.  
  881.         //find where to save new project
  882.         oans = fsel.FileSelectSave("New Project file",
  883.         MSDOSpath , 255, makeFilter,fi);
  884.         if (oans && *MSDOSpath) //filename picked
  885.         Dos2UxFName(MSDOSpath, prjName, 0);
  886.         else
  887.         break;
  888.         mm.setDefaults();
  889.         projectDialog PDlg(mm,this);
  890.         if (!PDlg.editProject())    // edit an old one
  891.         break;
  892.         mm.saveProject(prjName);
  893.             ((videApp*)theApp)->SetMkFile(mm.makeName);
  894.         break;
  895.       }
  896.  
  897.     case m_ProjectSave:
  898.       {
  899.         char MSDOSpath[256]= "";
  900.         ItemVal dans, oans, rval;
  901.         int fi = 0;
  902.         static char* makeFilter[] = {"*.vpj", 0};
  903.         vFileSelect fsel(this);
  904.  
  905.         if (prjName[0] == 0)
  906.           {
  907.         //find where to save new project
  908.         oans = fsel.FileSelectSave("New Project file",
  909.             MSDOSpath , 255, makeFilter,fi);
  910.         if (oans && *MSDOSpath) //filename picked
  911.             Dos2UxFName(MSDOSpath, prjName, 0);
  912.         else
  913.             break;
  914.           }
  915.         mm.saveProject(prjName);
  916.             ((videApp*)theApp)->SetMkFile(mm.makeName);
  917.         break;        // done with new, edit, and save
  918.       }
  919.  
  920.  
  921.     case m_ProjectOpen:
  922.       {
  923.         if (prjName[0] != 0)
  924.           {
  925.         mm.saveProject(prjName);    // save previous
  926.           }
  927.  
  928.         //open prj file
  929.         char MSDOSpath[256]= "";
  930.         int fi = 0;
  931.         static char* makeFilter[] = {"*.vpj", 0};
  932.         vFileSelect fsel(this);
  933.  
  934.         int ans = fsel.FileSelect("Select a project file",
  935.             MSDOSpath ,255, makeFilter,fi);
  936.         char uxfn[256]="";
  937.         if (ans && *MSDOSpath) //filename picked
  938.         Dos2UxFName(MSDOSpath, prjName, 0);
  939.         else
  940.         break;
  941.         mm.loadProject(prjName);
  942.             ((videApp*)theApp)->SetMkFile(mm.makeName);
  943.         mm.saveProject(prjName);
  944.         break;
  945.       }
  946.  
  947.         case m_RunVgen:
  948.           {
  949.             vOS vos;
  950. #ifdef V_VersionX
  951.             vos.vRunProcess("vgen", 0, 0, 0);
  952. #else
  953.             vos.vRunProcess("vgen.exe", 0, 0, 0);
  954. #endif
  955.             break;
  956.           }
  957.  
  958.         case m_RunViconed:
  959.           {
  960.             vOS vos;
  961. #ifdef V_VersionX
  962.             vos.vRunProcess("viconed", 0, 0, 0);
  963. #else
  964.             vos.vRunProcess("viconed.exe", 0, 0, 0);
  965. #endif
  966.             break;
  967.           }
  968.  
  969.         case m_RunShell:
  970.           {
  971.             vOS vos;
  972. #ifdef V_VersionX
  973.             vos.vRunProcess("rxvt", 0, 0, 0);
  974. #endif
  975. #ifdef V_VersionWindows
  976.             vos.vRunProcess("command.com", 0, 0, 0);
  977. #endif
  978. #ifdef V_VersionOS2
  979.             vos.vRunProcess("cmd.exe", 0, 0, 0);
  980. #endif
  981.             break;
  982.           }
  983.  
  984.         case m_RunCmd:
  985.           {
  986.             vRunDialog run(this);      // make an instance
  987.  
  988.             (void)run.Run(mm.exeName);
  989.  
  990.             break;
  991.           }
  992.  
  993.     //@V@:Case M_Font
  994.     case M_Font:
  995.       {
  996.         vFontSelect fd(this);
  997.  
  998.         (void) fd.FontSelect(vedFont);
  999.             vedCanvas->SetFont(vedFont);
  1000.             vedCanvas->SetTextRowsCols(24,80);
  1001.         break;
  1002.       }    //@V@:EndCase
  1003.  
  1004.  
  1005.     //@V@:Case M_Cut
  1006.     case M_Cut:
  1007.       {
  1008.         vedCanvas->EditCommand(edCut,0);
  1009.         break;
  1010.       }    //@V@:EndCase
  1011.  
  1012.     //@V@:Case M_Copy
  1013.     case M_Copy:
  1014.       {
  1015.         vedCanvas->EditCommand(edCopy,0);
  1016.         break;
  1017.       }    //@V@:EndCase
  1018.  
  1019.     //@V@:Case M_Paste
  1020.     case M_Paste:
  1021.       {
  1022.         vedCanvas->EditCommand(edPaste,0);
  1023.         break;
  1024.       }    //@V@:EndCase
  1025.  
  1026.         case m_SelectMake:    // select makefile
  1027.           {
  1028.             static int filterIndex = 0;
  1029.             static char* filter[] =
  1030.               {
  1031.             "Make*;make*;Make*.*;make*.*",
  1032.             "*",
  1033.             0
  1034.               };
  1035.             char fn[maxFileNameSize+2] = "Makefile";
  1036.  
  1037.             vFileSelect fsel(this);     // V file select dialog
  1038.  
  1039.             if (!fsel.FileSelect("Select Makefile",
  1040.                 fn,maxFileNameSize,filter,filterIndex))
  1041.             break;
  1042.  
  1043.             ((videApp*)theApp)->SetMkFile(fn);
  1044.  
  1045.             break;
  1046.           }
  1047.  
  1048.         case m_updateMkFile:    // fix up the label for cwd
  1049.           {
  1050.             char *mkname = ((videApp*)theApp)->GetMkFile();
  1051.             if (*mkname != 0)
  1052.         (((videApp*)theApp)->GetMsgWindow())->
  1053.                     SetTitle(mkname);
  1054.             else
  1055.         (((videApp*)theApp)->GetMsgWindow())->
  1056.                     SetTitle("No Makefile Specified");
  1057.             break;
  1058.           }
  1059.  
  1060.     default:    // route unhandled commands through editor
  1061.       {
  1062.         if (vedCanvas->EditCommand(id, 1) < 0)
  1063.         vCmdWindow::WindowCommand(id, val, cType);
  1064.         break;
  1065.       }
  1066.       }
  1067.   }
  1068.  
  1069. //====================>>> videCmdWindow::SetSyntaxType <<<====================
  1070.   void videCmdWindow::SetSyntaxType(videCmdWindow* cmdw, char* name, int RdOnly)
  1071.   {
  1072.     // Set syntax highlighting based on file name
  1073.     char* CExts[] = {".cpp", ".CPP", ".C", ".c", ".cxx", ".CXX",
  1074.                ".h", ".H", ".hpp", ".HPP", ""};
  1075.  
  1076.     edState curState = cmdw->vedCanvas->GetEdState();
  1077.     curState.ftype = Text;            // assume Text
  1078.     curState.readOnly = RdOnly;
  1079.  
  1080.     for (int ix = 0 ; *CExts[ix] ; ++ix)    // check C extensions
  1081.       {
  1082.         if (strstr(name,CExts[ix]) != 0)    // found one!
  1083.           {                                     // @@@ .h matches .html!!!!
  1084.             curState.ftype = CPP;
  1085.             break;
  1086.           }
  1087.       }
  1088.     cmdw->vedCanvas->SetEdState(curState);
  1089.   }
  1090.  
  1091. //====================>>> videCmdWindow::OpenFile <<<====================
  1092.   int videCmdWindow::OpenFile(char* name, int RdOnly, int notify)
  1093.   {
  1094.      if (!name || !*name)
  1095.     return 0;
  1096.  
  1097.     if (!vedCanvas->ReadFile(name,0))
  1098.       {
  1099.         if (!notify)
  1100.             return 0;
  1101.     vNoticeDialog note(this);       // for user notification
  1102.     note.Notice("Unable to open specified file");
  1103.     return 0;
  1104.       }
  1105.  
  1106.     SetTitle(name);
  1107.     strcpy(fileName,name);
  1108.     SetSyntaxType(this,name,RdOnly);
  1109.     vedCanvas->Verify();
  1110.     ChangeInsMode(1);
  1111.     return 1;
  1112.   }
  1113.  
  1114. //====================>>> videCmdWindow::SetViewWindow <<<====================
  1115.   int videCmdWindow::SetViewWindow(char *name)
  1116.   {
  1117.     SetTitle(name);
  1118.     strcpy(fileName,name);
  1119.     vedCanvas->resetBuff();
  1120. #ifdef V_VersionX
  1121.     vedFont.SetFontValues(vfFixed,12);    // use Courier rathern than default
  1122. #else
  1123. #ifdef DEVEL
  1124.     vedFont.SetFontValues(vfFixed,9,vfNormal,vfBold);    // use Courier rathern than default
  1125. #else
  1126.     vedFont.SetFontValues(vfFixed,10);    // use Courier rathern than default
  1127. #endif
  1128. #endif
  1129.     vedCanvas->SetFont(vedFont);
  1130.  
  1131.     vedCanvas->Verify();
  1132.     return 1;
  1133.   }
  1134.  
  1135. //====================>>> videCmdWindow::AddLine <<<====================
  1136.   int videCmdWindow::AddLine(char* line)
  1137.   {
  1138.     if (!vedCanvas->addLine(line))
  1139.         return 0;
  1140.     vedCanvas->displayBuff(99999,1);
  1141.     return 1;
  1142.   }
  1143.