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

  1. //----------------------------------------------------------------------------
  2. // IdeHook - (C) Copyright 1994 by Borland International
  3. //----------------------------------------------------------------------------
  4. #pragma hdrstop
  5.  
  6. #include "idehook.h"
  7. #include <string.h>
  8. #include <windows.h>
  9.  
  10. static char realCppPreprocess[]  = "CppPreprocessor";
  11. static char myPreprocessorName[] = "CppPreprocessAndSee";
  12.  
  13.  
  14. class _HOOKCLASS LocalToolClient : public ToolClient
  15. {
  16. public:
  17.     ToolReturn _HOOKEP RunPreprocessor( ToolInvokeArgs * );
  18.  
  19.     void RegisterMyCallBacks( ToolServer * );
  20.  
  21. private:
  22.  
  23.             int                 registered;
  24.     static  ToolRegisterPack    entryPoints[];
  25.  
  26. };
  27.  
  28. static LocalToolClient  localToolClient;
  29.  
  30. ToolRegisterPack LocalToolClient::entryPoints[] =
  31. {
  32.     { myPreprocessorName, (ToolMethod)&LocalToolClient::RunPreprocessor },
  33.     { 0 }
  34. };
  35.  
  36. void
  37. LocalToolClient::RegisterMyCallBacks( ToolServer * ts )
  38. {
  39.     if( !registered )
  40.     {
  41.         registered = 1;
  42.         ts->ToolRegisterImplementor( this, entryPoints );
  43.     }
  44. }
  45.  
  46. ToolReturn _HOOKEP 
  47. LocalToolClient::RunPreprocessor( ToolInvokeArgs * args )
  48. {
  49.     ToolReq   server;
  50.  
  51.     ProjectNode node = args->numNodes ? *args->nodeArray : 0;
  52.  
  53.     ToolObj preprocessor = server->ToolFind( realCppPreprocess );
  54.     ToolObj editTool = 0;
  55.     
  56.     if( preprocessor )
  57.     {
  58.         if( server->ToolInvoke( preprocessor, node, 0 ) == Success )
  59.         {
  60.            if( (editTool = server->ToolFind( "EditText" )) == 0 )
  61.            {
  62.                ::MessageBox( ::GetActiveWindow(), 
  63.                                "Can't find editor!",
  64.                                "Error!", 
  65.                                MB_ICONEXCLAMATION | MB_OK );
  66.            }
  67.         }
  68.         else
  69.         {
  70.            ::MessageBox( ::GetActiveWindow(), 
  71.                            "CppPreprocess did not complete ok!",
  72.                            "Error!", 
  73.                            MB_ICONEXCLAMATION | MB_OK );
  74.         }
  75.     }
  76.  
  77.     if( editTool )
  78.     {
  79.         ProjectNodeInfo     nodeInfo;
  80.         ProjectReq          projectServer;
  81.  
  82.         projectServer->QueryNodeInfo( node, nodeInfo );
  83.  
  84.         char * str = new char [ strlen( nodeInfo.outputLocation ) + 3 ];
  85.  
  86.         strcpy( str, nodeInfo.outputLocation );
  87.  
  88.         char * pdot = strrchr( str, '.' );
  89.  
  90.         if( pdot )
  91.             *pdot = 0;
  92.  
  93.         strcat( str, ".i" );
  94.  
  95.         return( server->ToolInvoke( editTool, str ) );
  96.     }
  97.  
  98.     return( Errors );
  99.  
  100. }
  101.  
  102. //
  103. //      Project stuff
  104. //
  105. class _HOOKCLASS LocalProjClient : public ProjectClient
  106. {
  107. public:
  108.    LocalProjClient();
  109.    
  110.     virtual void _HOOKEP    OpenNotify
  111.                                     (
  112.                                         const char * name 
  113.                                     );
  114.     
  115.     virtual void _HOOKEP    CloseNotify();
  116.  
  117.     virtual void _HOOKEP NodeDeleteNotify
  118.                                     (
  119.                                         ProjectNode
  120.                                     );
  121.                                 
  122.     virtual void _HOOKEP  DependencyQueryResponder
  123.                                     (
  124.                                         ProjectNode , 
  125.                                         const char * 
  126.                                     );
  127.  
  128. };
  129.  
  130. static LocalProjClient LocalProjClient;
  131.  
  132. LocalProjClient::LocalProjClient()
  133. {
  134.    ProjectReq ps;
  135.  
  136.    ps->RegisterProjectClient(this);
  137. }
  138.  
  139.  
  140. void _HOOKEP    
  141. LocalProjClient::OpenNotify
  142. (
  143.    const char * // name 
  144. )
  145. {
  146.     ToolReq   ts;
  147.  
  148.     localToolClient.RegisterMyCallBacks( ts );
  149.  
  150.     if( !ts->ToolFind( myPreprocessorName ) )
  151.     {
  152.         ToolObj realPreProcessor;
  153.  
  154.         if( (realPreProcessor = ts->ToolFind( realCppPreprocess )) != 0 )
  155.         {
  156.             ToolInfo toolInfo;
  157.  
  158.             ts->QueryToolInfo( realPreProcessor, toolInfo );
  159.  
  160.             toolInfo.toolType       = Viewer;
  161.             toolInfo.name           = myPreprocessorName;
  162.             toolInfo.menuName       = "&Preprocess and see";
  163.             toolInfo.defCmdLine     = 0;
  164.             toolInfo.helpHint       = "Preprocess a c/c++ file and dump"
  165.                                       " into editor";
  166.             toolInfo.launchId       = CALLBACK_LAUNCH_ID;
  167.  
  168.             ts->ToolAdd( &toolInfo );
  169.         }
  170.     }
  171.    
  172. }
  173.     
  174. void _HOOKEP    
  175. LocalProjClient::CloseNotify()
  176. {
  177. }
  178.  
  179. void _HOOKEP 
  180. LocalProjClient::NodeDeleteNotify
  181. (
  182.    ProjectNode
  183. )
  184. {
  185. }
  186.                                                 
  187. void _HOOKEP  
  188. LocalProjClient::DependencyQueryResponder
  189. (
  190.    ProjectNode , 
  191.    const char * 
  192. )
  193. {
  194. }
  195.     
  196.  
  197. // End of file
  198.  
  199.