~ubuntu-branches/ubuntu/utopic/cccc/utopic

« back to all changes in this revision

Viewing changes to vcaddin/DSAddIn.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2003-08-23 04:34:05 UTC
  • Revision ID: james.westby@ubuntu.com-20030823043405-xnzd3mn3hwtvi6dr
Tags: upstream-3.pre81
ImportĀ upstreamĀ versionĀ 3.pre81

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// AddInMod.cpp : implementation file
 
2
//
 
3
 
 
4
 
 
5
#include "stdafx.h"
 
6
 
 
7
// Turn off warnings due to long names arising out of STL use
 
8
#pragma warning ( disable : 4786 4503 )
 
9
 
 
10
#include "CcccDevStudioAddIn.h"
 
11
#include "DSAddIn.h"
 
12
#include "Commands.h"
 
13
 
 
14
#ifdef _DEBUG
 
15
#define new DEBUG_NEW
 
16
#undef THIS_FILE
 
17
static char THIS_FILE[] = __FILE__;
 
18
#endif
 
19
 
 
20
// This is called when the user first loads the add-in, and on start-up
 
21
//  of each subsequent Developer Studio session
 
22
STDMETHODIMP CDSAddIn::OnConnection(IApplication* pApp, VARIANT_BOOL bFirstTime,
 
23
                long dwCookie, VARIANT_BOOL* OnConnection)
 
24
{
 
25
        AFX_MANAGE_STATE(AfxGetStaticModuleState());
 
26
        
 
27
        // Store info passed to us
 
28
        IApplication* pApplication = NULL;
 
29
        if (FAILED(pApp->QueryInterface(IID_IApplication, (void**) &pApplication))
 
30
                || pApplication == NULL)
 
31
        {
 
32
                *OnConnection = VARIANT_FALSE;
 
33
                return S_OK;
 
34
        }
 
35
 
 
36
        m_dwCookie = dwCookie;
 
37
 
 
38
        // Create command dispatch, send info back to DevStudio
 
39
        CCommandsObj::CreateInstance(&m_pCommands);
 
40
        m_pCommands->AddRef();
 
41
 
 
42
        // The QueryInterface above AddRef'd the Application object.  It will
 
43
        //  be Release'd in CCommand's destructor.
 
44
        m_pCommands->SetApplicationObject(pApplication);
 
45
 
 
46
        // (see stdafx.h for the definition of VERIFY_OK)
 
47
 
 
48
        VERIFY_OK(pApplication->SetAddInInfo((long) AfxGetInstanceHandle(),
 
49
                (LPDISPATCH) m_pCommands, IDR_TOOLBAR_MEDIUM, IDR_TOOLBAR_LARGE, m_dwCookie));
 
50
 
 
51
        // Inform DevStudio of the commands we implement
 
52
 
 
53
        // TODO: Replace the AddCommand call below with a series of calls,
 
54
        //  one for each command your add-in will add.
 
55
 
 
56
        // The command name should not be localized to other languages.  The 
 
57
        //  tooltip, command description, and other strings related to this
 
58
        //  command are stored in the string table (IDS_CMD_STRING) and should
 
59
        //  be localized.
 
60
        addCommand(pApplication,
 
61
                "runCCCCOnActiveFile","run CCCC on the active file", 
 
62
                0,bFirstTime);
 
63
        addCommand(pApplication,
 
64
                "runCCCCOnProjectFiles","run CCCC on all files in the active project",
 
65
                1,bFirstTime);
 
66
        addCommand(pApplication,
 
67
                "runCCCCOnWorkspaceFiles","run CCCC on all files in the active workspace", 
 
68
                2,bFirstTime);
 
69
        addCommand(pApplication,
 
70
                "configureCCCCDevStudioAddIn","configure the add-in", 
 
71
                3,bFirstTime);
 
72
 
 
73
        int i;
 
74
        for (i=0; i<6; i++)
 
75
        {
 
76
                char userCommandName[1024], userCommandTip[1024];
 
77
                sprintf(userCommandName,"UserCommand%d",i+1);
 
78
                sprintf(userCommandTip,"User defined command #%d",i+1);
 
79
                addCommand(pApplication,
 
80
                        userCommandName,userCommandTip,i+4,bFirstTime);
 
81
        }
 
82
 
 
83
 
 
84
        *OnConnection = VARIANT_TRUE;
 
85
        return S_OK;
 
86
}
 
87
 
 
88
// This is called on shut-down, and also when the user unloads the add-in
 
89
STDMETHODIMP CDSAddIn::OnDisconnection(VARIANT_BOOL bLastTime)
 
90
{
 
91
        AFX_MANAGE_STATE(AfxGetStaticModuleState());
 
92
 
 
93
        m_pCommands->Release();
 
94
        m_pCommands = NULL;
 
95
 
 
96
        // TODO: Perform any cleanup work here
 
97
 
 
98
        return S_OK;
 
99
}
 
100
 
 
101
void CDSAddIn::addCommand(IApplication* pApp, LPCSTR methodName, LPCSTR methodTip, long imageIndex, VARIANT_BOOL bFirstTime)
 
102
{
 
103
        VARIANT_BOOL bRet;
 
104
 
 
105
        // We can simplify on the MS boilerplate code
 
106
        // for this activity by deciding that the command name
 
107
        // and the method name will always be the same.
 
108
        CComBSTR bszMethodName(methodName);
 
109
        CComBSTR bszCmdName(methodName);
 
110
 
 
111
        // We still have to build up the command string
 
112
        CString strMethodName(methodName);
 
113
        CString strCmdString;
 
114
        strCmdString=
 
115
                strMethodName + "\n" + 
 
116
                strMethodName + "\n" +
 
117
                methodTip + "\n" + 
 
118
                methodTip
 
119
        ;
 
120
        CComBSTR bszCmdString(strCmdString);
 
121
 
 
122
        VERIFY_OK(pApp->AddCommand(bszCmdString, bszMethodName, imageIndex, m_dwCookie, &bRet));
 
123
        if (bRet == VARIANT_FALSE)
 
124
        {
 
125
                AfxMessageBox("Failed to load command");
 
126
                
 
127
        }
 
128
        else
 
129
        {
 
130
                // Add toolbar buttons only if this is the first time the add-in
 
131
                //  is being loaded.  Toolbar buttons are automatically remembered
 
132
                //  by Developer Studio from session to session, so we should only
 
133
                //  add the toolbar buttons once.
 
134
                if (bFirstTime == VARIANT_TRUE)
 
135
                {
 
136
                        VERIFY_OK(pApp->
 
137
                                AddCommandBarButton(dsGlyph, bszCmdName, m_dwCookie));
 
138
                }
 
139
        }
 
140
}