// The open document event handle is the place where the real interface work // is done. // Vim gets called from here. // HRESULT CCommands::XApplicationEvents::DocumentOpen (IDispatch * theDocument) { AFX_MANAGE_STATE (AfxGetStaticModuleState ()); if (! g_bEnableVim) // Vim not enabled or empty command line entered return S_OK; // First get the current file name and line number // Get the document object CComQIPtr < ITextDocument, &IID_ITextDocument > pDoc (theDocument); if (! pDoc) return S_OK; BSTR FileName; long LineNr = -1; // Get the document name if (FAILED (pDoc->get_FullName (&FileName))) return S_OK; LPDISPATCH pDispSel; // Get a selection object dispatch pointer if (SUCCEEDED (pDoc->get_Selection (&pDispSel))) { // Get the selection object CComQIPtr < ITextSelection, &IID_ITextSelection > pSel (pDispSel); if (pSel) // Get the selection line number pSel->get_CurrentLine (&LineNr); pDispSel->Release (); } // Open the file in Vim and position to the current line if (VimOpenFile (FileName, LineNr)) { if (! g_bDevStudioEditor) { // Close the document in developer studio CComVariant vSaveChanges = dsSaveChangesPrompt; DsSaveStatus Saved; pDoc->Close (vSaveChanges, &Saved); } } // We're done here SysFreeString (FileName); return S_OK; }
virtual STDMETHODIMP OnButtonClicked(IFileDialogCustomize* pfdc, DWORD dwIDCtl) { if (dwIDCtl == 101) { CComQIPtr<IFileOpenDialog> pDlg = pfdc; if (pDlg) { pDlg->Close(S_OK); } } return S_OK; }
HRESULT CCommands::XApplicationEvents::NewDocument (IDispatch * theDocument) { AFX_MANAGE_STATE (AfxGetStaticModuleState ()); if (! g_bEnableVim) // Vim not enabled or empty command line entered return S_OK; // First get the current file name and line number CComQIPtr < ITextDocument, &IID_ITextDocument > pDoc (theDocument); if (! pDoc) return S_OK; BSTR FileName; HRESULT hr; hr = pDoc->get_FullName (&FileName); if (FAILED (hr)) return S_OK; // Open the file in Vim and position to the current line if (VimOpenFile (FileName, 0)) { if (! g_bDevStudioEditor) { // Close the document in developer studio CComVariant vSaveChanges = dsSaveChangesPrompt; DsSaveStatus Saved; pDoc->Close (vSaveChanges, &Saved); } } SysFreeString (FileName); return S_OK; }