home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / IDEHOOK.PAK / GENVBXH.CPP < prev    next >
C/C++ Source or Header  |  1995-08-29  |  6KB  |  209 lines

  1. //----------------------------------------------------------------------------
  2. // IdeHook - (C) Copyright 1994 by Borland International
  3. //----------------------------------------------------------------------------
  4. #pragma hdrstop
  5.  
  6. #include "idehook.h"
  7. #include "pathspec.h"
  8. #include <cstring.h>
  9.  
  10. static char genVbxTransferName[]   = "VbxHeaderGen";
  11. static char genVbxViewerName[]     = "VbxHeaderNodeGen";
  12. static char genVbxTranslatorName[] = "VbxTranslator";
  13. static char genVbxPath[]           = "vbxgen.exe";
  14. static char genVbxMenuName[]       = "&Generate VBX Header";
  15. static char genVbxHelpHint[]       = "Generate header files for VBX controls";
  16.  
  17.  
  18. static char VBXFilter[]    = "VBX Controls (*.vbx)|*.vbx|"
  19.                              "All Files (*.*)|*.*|";
  20. static char DotHFilter[]   = "Header File (*.h)|*.h|"
  21.                              "All Files (*.*)|*.*|";
  22.            
  23.  
  24.  
  25. class _HOOKCLASS LocalToolClient : public ToolClient
  26. {
  27. public:
  28.     ToolReturn _HOOKEP RunVbxHeaderGen( ToolInvokeArgs * );
  29.  
  30.     void RegisterMyCallBacks( ToolServer * );
  31.  
  32. private:
  33.             int                 registered;
  34.     static  ToolRegisterPack    entryPoints[];
  35.  
  36. };
  37.  
  38. static LocalToolClient  localToolClient;
  39.  
  40. ToolRegisterPack LocalToolClient::entryPoints[] =
  41. {
  42.     { genVbxViewerName, (ToolMethod)&LocalToolClient::RunVbxHeaderGen },
  43.     { 0 }
  44. };
  45.  
  46. void
  47. LocalToolClient::RegisterMyCallBacks( ToolServer * ts )
  48. {
  49.     if( !registered )
  50.     {
  51.         registered = 1;
  52.         ts->ToolRegisterImplementor( this, entryPoints );
  53.     }
  54. }
  55.  
  56. ToolReturn _HOOKEP 
  57. LocalToolClient::RunVbxHeaderGen( ToolInvokeArgs * args )
  58. {
  59.    PathSpec    vbxPath;
  60.    PathSpec    headerPath;
  61.  
  62.    if( vbxPath.openFileDialog( VBXFilter ) )
  63.    {
  64.        headerPath.path( vbxPath.path() );
  65.        headerPath.ext( ".h" );
  66.        
  67.        if( headerPath.newFileDialog( DotHFilter ) )
  68.        {
  69.            ToolReq     ts;
  70.  
  71.            ToolObj     vbxGenner = ts->ToolFind( genVbxTransferName );
  72.                                             
  73.            string  cmdLine;
  74.  
  75.            cmdLine = vbxPath.path();
  76.            cmdLine += " ";
  77.            cmdLine += headerPath.path();
  78.  
  79.            if
  80.            (
  81.               ( ts->ToolInvoke( vbxGenner, (const char *)0, cmdLine.c_str() ) ) 
  82.                   == Success 
  83.            )
  84.            {
  85.                ProjectReq  project;
  86.  
  87.                int count = args->numNodes;
  88.     
  89.                for( int i = 0; i < count; i++ )
  90.                {
  91.                   ProjectNode   parent = args->nodeArray[i];
  92.  
  93.                   project->NodeAdd( parent, headerPath.path() );
  94.                }
  95.  
  96.                ts->ToolInvoke( ts->ToolFind( "EditText" ), headerPath.path() );
  97.                
  98.            }
  99.        }
  100.    }
  101.    
  102.    return( Success );
  103. }
  104.  
  105.  
  106. //
  107. //      Project stuff
  108. //
  109.  
  110. class _HOOKCLASS LocalProjClient : public ProjectClient
  111. {
  112. public:
  113.     LocalProjClient();
  114.    
  115.     virtual void _HOOKEP OpenNotify ( const char * name );
  116.     virtual void _HOOKEP CloseNotify() {}
  117.     virtual void _HOOKEP NodeDeleteNotify( ProjectNode ) {}
  118.     virtual void _HOOKEP DependencyQueryResponder(ProjectNode,const char *) {}
  119. };
  120.  
  121. static LocalProjClient LocalProjClient;
  122.  
  123. LocalProjClient::LocalProjClient()
  124. {
  125.    ProjectReq ps;
  126.  
  127.    ps->RegisterProjectClient(this);
  128. }
  129.  
  130.  
  131. void _HOOKEP    
  132. LocalProjClient::OpenNotify
  133. (
  134.    const char * // name 
  135. )
  136. {
  137.     ToolReq   ts;
  138.  
  139.     localToolClient.RegisterMyCallBacks( ts );
  140.  
  141.     if( !ts->ToolFind( genVbxTransferName ) )
  142.     {
  143.         ToolInfo toolInfo;
  144.  
  145.         //                                              //
  146.         // Install this as simple 'Tool' menu transfer  //
  147.         // It will run the tool 'straight'              //
  148.         //                                              //
  149.         
  150.          toolInfo.toolType        = Transfer;
  151.         toolInfo.name          = genVbxTransferName;
  152.         toolInfo.path          = genVbxPath;
  153.          toolInfo.flags         = OnToolsMenu;
  154.         toolInfo.menuName      = genVbxMenuName; 
  155.         toolInfo.helpHint      = genVbxHelpHint; 
  156.         toolInfo.defCmdLine    = "$PROMPT";
  157.          toolInfo.appliesTo     = 0;
  158.         toolInfo.defaultFor    = 0;
  159.         toolInfo.translateTo   = 0;
  160.         toolInfo.launchId      = DEFAULT_LAUNCH_ID;
  161.  
  162.         ts->ToolAdd( &toolInfo );
  163.  
  164.         //                                              //
  165.         // Install this as a Viewer on [.c] and [.cpp]  //
  166.         // We will implement the tool here (above) by   //
  167.         // putting put our own FileOpen dialogs and     //
  168.         // adding the results into tree.                //
  169.         //                                              //
  170.         
  171.          toolInfo.toolType        = Viewer;
  172.         toolInfo.name          = genVbxViewerName;
  173.         toolInfo.path          = 0;
  174.          toolInfo.flags         = OnLocalMenu;
  175.         toolInfo.menuName      = genVbxMenuName;
  176.         toolInfo.helpHint      = genVbxHelpHint;
  177.         toolInfo.defCmdLine    = 0;
  178.          toolInfo.appliesTo     = ".cpp;.c;";
  179.         toolInfo.defaultFor    = 0;
  180.         toolInfo.translateTo   = 0;
  181.         toolInfo.launchId      = CALLBACK_LAUNCH_ID;
  182.  
  183.         ts->ToolAdd( &toolInfo );
  184.         
  185.         //                                              //
  186.         // Install this as a translator on [.vbx] nodes //
  187.         // with the output being a [.h]                 //
  188.         //                                              //
  189.         
  190.          toolInfo.toolType        = Translator;
  191.         toolInfo.name          = genVbxTranslatorName;
  192.         toolInfo.path          = genVbxPath;
  193.          toolInfo.flags         = OnLocalMenu;
  194.         toolInfo.menuName      = genVbxMenuName;
  195.         toolInfo.helpHint      = genVbxHelpHint;
  196.         toolInfo.defCmdLine    = "$EDNAME $OUTNAME";
  197.          toolInfo.appliesTo     = ".vbx";
  198.         toolInfo.defaultFor    = ".vbx";
  199.         toolInfo.translateTo   = ".h";
  200.         toolInfo.launchId      = DEFAULT_LAUNCH_ID;
  201.  
  202.         ts->ToolAdd( &toolInfo );
  203.  
  204.     }
  205. }
  206.     
  207. // End of file
  208.  
  209.