home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / IDEHOOK.PAK / TRGSNPS.CPP < prev    next >
C/C++ Source or Header  |  1995-08-29  |  6KB  |  205 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 <string.h>
  9. #include <windows.h>
  10.  
  11. static char targetExeSnipName[] = "TargetExeSnippets";
  12. static char targetDllSnipName[] = "TargetDllSnippets";
  13.  
  14. #define CRLF "\n"
  15.  
  16. static char szExeWinMain[] =
  17.    "//"                                   CRLF
  18.    "//     This is the WinMain snippet"   CRLF
  19.    "//"                                   CRLF
  20.    "#include <windows.h>"                 CRLF
  21.                                           CRLF
  22.    "int WINAPI WinMain"                   CRLF
  23.    "("                                    CRLF
  24.    "   HINSTANCE /* hInstance */,"        CRLF
  25.    "   HINSTANCE /* hPrevInstance */, "   CRLF
  26.    "   LPSTR     /* lpCmdLine */,"        CRLF
  27.    "   int       /* howShow */"           CRLF
  28.    ")"                                    CRLF
  29.    "{"                                    CRLF
  30.    "   return(0);"                        CRLF
  31.    "}"                                    CRLF
  32.    ;
  33.  
  34. static char szExeOwlMain[] =
  35.    "//"                                                    CRLF
  36.    "//     This is the OwlMain snippet"                    CRLF
  37.    "//"                                                    CRLF
  38.    "#include <owl/applicat.h>"                             CRLF
  39.                                                            CRLF
  40.    "int OwlMain( int /* argc */ , char ** /* argv */ )"    CRLF
  41.    "{"                                                     CRLF
  42.    "   return( TApplication().Run() );"                    CRLF
  43.    "}"                                                     CRLF
  44.    ;
  45.  
  46. static char szExeDefSnip[] =
  47.    "EXETYPE WINDOWS"                     CRLF
  48.    "CODE PRELOAD MOVEABLE DISCARDABLE"   CRLF
  49.    "DATA PRELOAD MOVEABLE MULTIPLE"      CRLF
  50.    "HEAPSIZE 4096"                       CRLF
  51.    "STACKSIZE 8192"                      CRLF
  52.    ;
  53.  
  54. class _HOOKCLASS LocalToolClient : public ToolClient
  55. {
  56. public:
  57.     ToolReturn _HOOKEP RunTargetExeSnips( ToolInvokeArgs * );
  58.     ToolReturn _HOOKEP RunTargetDllSnips( ToolInvokeArgs * );
  59.  
  60.     void RegisterMyCallBacks( ToolServer * );
  61.  
  62. private:
  63.             int                 registered;
  64.     static  ToolRegisterPack    entryPoints[];
  65.  
  66. };
  67.  
  68. static LocalToolClient  localToolClient;
  69.  
  70. ToolRegisterPack LocalToolClient::entryPoints[] =
  71. {
  72.     { targetExeSnipName, (ToolMethod)&LocalToolClient::RunTargetExeSnips },
  73. //  { targetDllSnipName, (ToolMethod)&LocalToolClient::RunTargetDllSnips },
  74.     { 0 }
  75. };
  76.  
  77. void
  78. LocalToolClient::RegisterMyCallBacks( ToolServer * ts )
  79. {
  80.     if( !registered )
  81.     {
  82.         registered = 1;
  83.         ts->ToolRegisterImplementor( this, entryPoints );
  84.     }
  85. }
  86.  
  87. ToolReturn _HOOKEP
  88. LocalToolClient::RunTargetExeSnips( ToolInvokeArgs * args )
  89. {
  90.     ToolReq   server;
  91.  
  92.     ProjectNode node = args->numNodes ? *args->nodeArray : 0;
  93.  
  94.     if( node )
  95.     {
  96.         ProjectNodeInfo    nodeInfo;
  97.         ProjectReq         project;
  98.         PathSpec           nodePath;
  99.         EditorReq          editor;
  100.  
  101.         project->QueryNodeInfo( node, nodeInfo );
  102.  
  103.         nodePath.path( nodeInfo.outputLocation );
  104.  
  105.         //                                 //
  106.         // Do the [.cpp] main source node  //
  107.         //                                 //
  108.         
  109.         nodePath.ext( ".cpp" );
  110.  
  111.         project->NodeAdd( node, nodePath.path() );
  112.  
  113.         editor->set_buffer( editor->create_buffer( 0,
  114.                                                    (char *)nodePath.path(),
  115.                                                    0 ) );
  116.  
  117.         TargetExpertReq    targetExpert;
  118.  
  119.         const char * mainSnip;
  120.          
  121.         if( targetExpert->QuerySupports( node, 0, OWL, 0 ) )
  122.            mainSnip = szExeOwlMain;
  123.         else
  124.            mainSnip = szExeWinMain;
  125.  
  126.         editor->insert( (char *)mainSnip );
  127.  
  128.         editor->show_buffer();
  129.  
  130.         //                                 //
  131.         // Do the [.def] main source node  //
  132.         //                                 //
  133.  
  134.         nodePath.ext( ".def" );
  135.         project->NodeAdd( node, nodePath.path() );
  136.         editor->set_buffer( editor->create_buffer( 0,
  137.                                                    (char *)nodePath.path(),
  138.                                                    0 ) );
  139.         editor->insert( szExeDefSnip );
  140.     }
  141.  
  142.     return( Success );
  143.  
  144. }
  145.  
  146. //                       //
  147. //      Project stuff    //
  148. //                       //
  149.  
  150. class _HOOKCLASS LocalProjClient : public ProjectClient
  151. {
  152. public:
  153.    LocalProjClient();
  154.    
  155.  virtual void _HOOKEP OpenNotify( const char * name );
  156.  virtual void _HOOKEP CloseNotify() {}
  157.  virtual void _HOOKEP NodeDeleteNotify( ProjectNode ) {}
  158.  virtual void _HOOKEP DependencyQueryResponder(ProjectNode,const char *) {}
  159.  
  160. };
  161.  
  162. static LocalProjClient LocalProjClient;
  163.  
  164. LocalProjClient::LocalProjClient()
  165. {
  166.    ProjectReq ps;
  167.  
  168.    ps->RegisterProjectClient(this);
  169. }
  170.  
  171.  
  172. void _HOOKEP
  173. LocalProjClient::OpenNotify
  174. (
  175.    const char * // name
  176. )
  177. {
  178.     ToolReq   ts;
  179.  
  180.     localToolClient.RegisterMyCallBacks( ts );
  181.  
  182.     if( !ts->ToolFind( targetExeSnipName ) )
  183.     {
  184.         ToolInfo toolInfo;
  185.  
  186.         toolInfo.toolType      = Viewer;
  187.         toolInfo.name          = targetExeSnipName;
  188.         toolInfo.path          = 0;
  189.         toolInfo.flags         = OnLocalMenu;
  190.         toolInfo.menuName      = "&Target snippets";
  191.         toolInfo.helpHint      = "Generate a skeleton for a target";
  192.         toolInfo.defCmdLine    = 0;
  193.         toolInfo.appliesTo     = ".exe;";
  194.         toolInfo.defaultFor    = 0;
  195.         toolInfo.translateTo   = 0;
  196.         toolInfo.launchId      = CALLBACK_LAUNCH_ID;
  197.  
  198.         ts->ToolAdd( &toolInfo );
  199.     }
  200.    
  201. }
  202.  
  203. // End of file
  204.  
  205.