// Add a command to DevStudio // Creates a toolbar button for the command also. // 'MethodName' is the name of the method specified in the .odl file // 'StrResId' the resource id of the descriptive string // 'GlyphIndex' the image index into the command buttons bitmap // Return true on success // bool CDSAddIn::AddCommand (IApplication* pApp, char* MethodName, char* CmdName, UINT StrResId, UINT GlyphIndex, VARIANT_BOOL bFirstTime) { CString CmdString; CString CmdText; CmdText.LoadString (StrResId); CmdString = CmdName; CmdString += CmdText; CComBSTR bszCmdString (CmdString); CComBSTR bszMethod (MethodName); CComBSTR bszCmdName (CmdName); // (see stdafx.h for the definition of VERIFY_OK) VARIANT_BOOL bRet; VERIFY_OK (pApp->AddCommand (bszCmdString, bszMethod, GlyphIndex, m_dwCookie, &bRet)); if (bRet == VARIANT_FALSE) { // AddCommand failed because a command with this name already exists. ReportInternalError ("IApplication::AddCommand"); return FALSE; } // Add toolbar buttons only if this is the first time the add-in // is being loaded. Toolbar buttons are automatically remembered // by Developer Studio from session to session, so we should only // add the toolbar buttons once. if (bFirstTime == VARIANT_TRUE) VERIFY_OK (pApp->AddCommandBarButton (dsGlyph, bszCmdName, m_dwCookie)); return TRUE; }
void CCommands::SetApplicationObject (IApplication * pApplication) { // This function assumes pApplication has already been AddRef'd // for us, which CDSAddIn did in it's QueryInterface call // just before it called us. m_pApplication = pApplication; if (! m_pApplication) return; // Create Application event handlers XApplicationEventsObj::CreateInstance (&m_pApplicationEventsObj); if (! m_pApplicationEventsObj) { ReportInternalError ("XApplicationEventsObj::CreateInstance"); return; } m_pApplicationEventsObj->AddRef (); m_pApplicationEventsObj->Connect (m_pApplication); m_pApplicationEventsObj->m_pCommands = this; #ifdef NEVER // Create Debugger event handler CComPtr < IDispatch > pDebugger; if (SUCCEEDED (m_pApplication->get_Debugger (&pDebugger)) && pDebugger != NULL) { XDebuggerEventsObj::CreateInstance (&m_pDebuggerEventsObj); m_pDebuggerEventsObj->AddRef (); m_pDebuggerEventsObj->Connect (pDebugger); m_pDebuggerEventsObj->m_pCommands = this; } #endif // Get settings from registry HKEY_CURRENT_USER\Software\Vim\VisVim HKEY hAppKey = GetAppKey ("Vim"); if (hAppKey) { HKEY hSectionKey = GetSectionKey (hAppKey, "VisVim"); if (hSectionKey) { g_bEnableVim = GetRegistryInt (hSectionKey, "EnableVim", g_bEnableVim); g_bDevStudioEditor = GetRegistryInt(hSectionKey,"DevStudioEditor", g_bDevStudioEditor); g_ChangeDir = GetRegistryInt (hSectionKey, "ChangeDir", g_ChangeDir); RegCloseKey (hSectionKey); } RegCloseKey (hAppKey); } }
// This is called when the user first loads the add-in, and on start-up // of each subsequent Developer Studio session STDMETHODIMP CDSAddIn::OnConnection (IApplication * pApp, VARIANT_BOOL bFirstTime, long dwCookie, VARIANT_BOOL * OnConnection) { AFX_MANAGE_STATE (AfxGetStaticModuleState ()); *OnConnection = VARIANT_FALSE; // Store info passed to us IApplication *pApplication = NULL; HRESULT hr; hr = pApp->QueryInterface (IID_IApplication, (void **) &pApplication); if (FAILED (hr)) { ReportLastError (hr); return E_UNEXPECTED; } if (pApplication == NULL) { ReportInternalError ("IApplication::QueryInterface"); return E_UNEXPECTED; } m_dwCookie = dwCookie; // Create command dispatch, send info back to DevStudio CCommandsObj::CreateInstance (&m_pCommands); if (! m_pCommands) { ReportInternalError ("CCommandsObj::CreateInstance"); return E_UNEXPECTED; } m_pCommands->AddRef (); // The QueryInterface above AddRef'd the Application object. It will // be Release'd in CCommand's destructor. m_pCommands->SetApplicationObject (pApplication); hr = pApplication->SetAddInInfo ((long) AfxGetInstanceHandle (), (LPDISPATCH) m_pCommands, IDR_TOOLBAR_MEDIUM, IDR_TOOLBAR_LARGE, m_dwCookie); if (FAILED (hr)) { ReportLastError (hr); return E_UNEXPECTED; } // Inform DevStudio of the commands we implement if (! AddCommand (pApplication, "VisVimDialog", "VisVimDialogCmd", IDS_CMD_DIALOG, 0, bFirstTime)) return E_UNEXPECTED; if (! AddCommand (pApplication, "VisVimEnable", "VisVimEnableCmd", IDS_CMD_ENABLE, 1, bFirstTime)) return E_UNEXPECTED; if (! AddCommand (pApplication, "VisVimDisable", "VisVimDisableCmd", IDS_CMD_DISABLE, 2, bFirstTime)) return E_UNEXPECTED; if (! AddCommand (pApplication, "VisVimToggle", "VisVimToggleCmd", IDS_CMD_TOGGLE, 3, bFirstTime)) return E_UNEXPECTED; if (! AddCommand (pApplication, "VisVimLoad", "VisVimLoadCmd", IDS_CMD_LOAD, 4, bFirstTime)) return E_UNEXPECTED; *OnConnection = VARIANT_TRUE; return S_OK; }