annotate src/VisVim/Commands.cpp @ 20606:7d5bd5affd11

Added tag v8.2.0856 for changeset 503886f64d5fdb88c4518a883d37bdabe807519b
author Bram Moolenaar <Bram@vim.org>
date Sun, 31 May 2020 13:15:04 +0200
parents 1759d0ec0a6f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 #include "stdafx.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 #include <comdef.h> // For _bstr_t
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 #include "VisVim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 #include "Commands.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 #include "OleAut.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 #ifdef _DEBUG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 #define new DEBUG_NEW
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 #undef THIS_FILE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 static char THIS_FILE[] = __FILE__;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 // Change directory before opening file?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 #define CD_SOURCE 0 // Cd to source path
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 #define CD_SOURCE_PARENT 1 // Cd to parent directory of source path
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 #define CD_NONE 2 // No cd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 static BOOL g_bEnableVim = TRUE; // Vim enabled
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 static BOOL g_bDevStudioEditor = FALSE; // Open file in Dev Studio editor simultaneously
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
23 static BOOL g_bNewTabs = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 static int g_ChangeDir = CD_NONE; // CD after file open?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
26 static void VimSetEnableState(BOOL bEnableState);
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
27 static BOOL VimOpenFile(BSTR& FileName, long LineNr);
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
28 static DISPID VimGetDispatchId(COleAutomationControl& VimOle, char* Method);
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
29 static void VimErrDiag(COleAutomationControl& VimOle);
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
30 static void VimChangeDir(COleAutomationControl& VimOle, DISPID DispatchId, BSTR& FileName);
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
31 static void DebugMsg(char* Msg, char* Arg = NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 /////////////////////////////////////////////////////////////////////////////
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 // CCommands
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
37 CCommands::CCommands()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 // m_pApplication == NULL; M$ Code generation bug!!!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 m_pApplication = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 m_pApplicationEventsObj = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 m_pDebuggerEventsObj = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
45 CCommands::~CCommands()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
47 ASSERT(m_pApplication != NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 if (m_pApplication)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
50 m_pApplication->Release();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 m_pApplication = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
55 void CCommands::SetApplicationObject(IApplication * pApplication)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 // This function assumes pApplication has already been AddRef'd
16356
1759d0ec0a6f patch 8.1.1183: typos in VisVim comments
Bram Moolenaar <Bram@vim.org>
parents: 9199
diff changeset
58 // for us, which CDSAddIn did in its QueryInterface call
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 // just before it called us.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 m_pApplication = pApplication;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 if (! m_pApplication)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 // Create Application event handlers
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
65 XApplicationEventsObj::CreateInstance(&m_pApplicationEventsObj);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 if (! m_pApplicationEventsObj)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
68 ReportInternalError("XApplicationEventsObj::CreateInstance");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 }
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
71 m_pApplicationEventsObj->AddRef();
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
72 m_pApplicationEventsObj->Connect(m_pApplication);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 m_pApplicationEventsObj->m_pCommands = this;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 #ifdef NEVER
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 // Create Debugger event handler
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 CComPtr < IDispatch > pDebugger;
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
78 if (SUCCEEDED(m_pApplication->get_Debugger(&pDebugger))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 && pDebugger != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
81 XDebuggerEventsObj::CreateInstance(&m_pDebuggerEventsObj);
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
82 m_pDebuggerEventsObj->AddRef();
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
83 m_pDebuggerEventsObj->Connect(pDebugger);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 m_pDebuggerEventsObj->m_pCommands = this;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 // Get settings from registry HKEY_CURRENT_USER\Software\Vim\VisVim
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
89 HKEY hAppKey = GetAppKey("Vim");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 if (hAppKey)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
92 HKEY hSectionKey = GetSectionKey(hAppKey, "VisVim");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 if (hSectionKey)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
95 g_bEnableVim = GetRegistryInt(hSectionKey, "EnableVim",
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 g_bEnableVim);
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
97 g_bDevStudioEditor = GetRegistryInt(hSectionKey,
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
98 "DevStudioEditor", g_bDevStudioEditor);
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
99 g_bNewTabs = GetRegistryInt(hSectionKey, "NewTabs",
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
100 g_bNewTabs);
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
101 g_ChangeDir = GetRegistryInt(hSectionKey, "ChangeDir",
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 g_ChangeDir);
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
103 RegCloseKey(hSectionKey);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 }
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
105 RegCloseKey(hAppKey);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
109 void CCommands::UnadviseFromEvents()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
111 ASSERT(m_pApplicationEventsObj != NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 if (m_pApplicationEventsObj)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
114 m_pApplicationEventsObj->Disconnect(m_pApplication);
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
115 m_pApplicationEventsObj->Release();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 m_pApplicationEventsObj = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 #ifdef NEVER
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 if (m_pDebuggerEventsObj)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 // Since we were able to connect to the Debugger events, we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 // should be able to access the Debugger object again to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 // unadvise from its events (thus the VERIFY_OK below--see
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 // stdafx.h).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 CComPtr < IDispatch > pDebugger;
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
127 VERIFY_OK(m_pApplication->get_Debugger(&pDebugger));
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
128 ASSERT(pDebugger != NULL);
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
129 m_pDebuggerEventsObj->Disconnect(pDebugger);
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
130 m_pDebuggerEventsObj->Release();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 m_pDebuggerEventsObj = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 /////////////////////////////////////////////////////////////////////////////
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 // Event handlers
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 // Application events
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
142 HRESULT CCommands::XApplicationEvents::BeforeBuildStart()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
144 AFX_MANAGE_STATE(AfxGetStaticModuleState());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
148 HRESULT CCommands::XApplicationEvents::BuildFinish(long nNumErrors, long nNumWarnings)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
150 AFX_MANAGE_STATE(AfxGetStaticModuleState());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
154 HRESULT CCommands::XApplicationEvents::BeforeApplicationShutDown()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
156 AFX_MANAGE_STATE(AfxGetStaticModuleState());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 // The open document event handle is the place where the real interface work
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 // is done.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 // Vim gets called from here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 //
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
164 HRESULT CCommands::XApplicationEvents::DocumentOpen(IDispatch * theDocument)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
166 AFX_MANAGE_STATE(AfxGetStaticModuleState());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 if (! g_bEnableVim)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 // Vim not enabled or empty command line entered
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 // First get the current file name and line number
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 // Get the document object
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
175 CComQIPtr < ITextDocument, &IID_ITextDocument > pDoc(theDocument);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 if (! pDoc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 BSTR FileName;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 long LineNr = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 // Get the document name
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
183 if (FAILED(pDoc->get_FullName(&FileName)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 LPDISPATCH pDispSel;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 // Get a selection object dispatch pointer
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
189 if (SUCCEEDED(pDoc->get_Selection(&pDispSel)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 // Get the selection object
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
192 CComQIPtr < ITextSelection, &IID_ITextSelection > pSel(pDispSel);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 if (pSel)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 // Get the selection line number
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
196 pSel->get_CurrentLine(&LineNr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
198 pDispSel->Release();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 // Open the file in Vim and position to the current line
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
202 if (VimOpenFile(FileName, LineNr))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 if (! g_bDevStudioEditor)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 // Close the document in developer studio
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 CComVariant vSaveChanges = dsSaveChangesPrompt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 DsSaveStatus Saved;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
210 pDoc->Close(vSaveChanges, &Saved);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 // We're done here
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
215 SysFreeString(FileName);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
219 HRESULT CCommands::XApplicationEvents::BeforeDocumentClose(IDispatch * theDocument)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
221 AFX_MANAGE_STATE(AfxGetStaticModuleState());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
225 HRESULT CCommands::XApplicationEvents::DocumentSave(IDispatch * theDocument)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
227 AFX_MANAGE_STATE(AfxGetStaticModuleState());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
231 HRESULT CCommands::XApplicationEvents::NewDocument(IDispatch * theDocument)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
233 AFX_MANAGE_STATE(AfxGetStaticModuleState());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 if (! g_bEnableVim)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 // Vim not enabled or empty command line entered
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 // First get the current file name and line number
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
241 CComQIPtr < ITextDocument, &IID_ITextDocument > pDoc(theDocument);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 if (! pDoc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 BSTR FileName;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 HRESULT hr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
248 hr = pDoc->get_FullName(&FileName);
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
249 if (FAILED(hr))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 // Open the file in Vim and position to the current line
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
253 if (VimOpenFile(FileName, 0))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 if (! g_bDevStudioEditor)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 // Close the document in developer studio
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 CComVariant vSaveChanges = dsSaveChangesPrompt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 DsSaveStatus Saved;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
261 pDoc->Close(vSaveChanges, &Saved);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
265 SysFreeString(FileName);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
269 HRESULT CCommands::XApplicationEvents::WindowActivate(IDispatch * theWindow)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
271 AFX_MANAGE_STATE(AfxGetStaticModuleState());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
275 HRESULT CCommands::XApplicationEvents::WindowDeactivate(IDispatch * theWindow)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
277 AFX_MANAGE_STATE(AfxGetStaticModuleState());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
281 HRESULT CCommands::XApplicationEvents::WorkspaceOpen()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
283 AFX_MANAGE_STATE(AfxGetStaticModuleState());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
287 HRESULT CCommands::XApplicationEvents::WorkspaceClose()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
289 AFX_MANAGE_STATE(AfxGetStaticModuleState());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
293 HRESULT CCommands::XApplicationEvents::NewWorkspace()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
295 AFX_MANAGE_STATE(AfxGetStaticModuleState());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 // Debugger event
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
301 HRESULT CCommands::XDebuggerEvents::BreakpointHit(IDispatch * pBreakpoint)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
303 AFX_MANAGE_STATE(AfxGetStaticModuleState());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 /////////////////////////////////////////////////////////////////////////////
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 // VisVim dialog
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 class CMainDialog : public CDialog
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 public:
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
314 CMainDialog(CWnd * pParent = NULL); // Standard constructor
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 //{{AFX_DATA(CMainDialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 enum { IDD = IDD_ADDINMAIN };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 int m_ChangeDir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 BOOL m_bDevStudioEditor;
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
320 BOOL m_bNewTabs;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 //}}AFX_DATA
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 //{{AFX_VIRTUAL(CMainDialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 protected:
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
325 virtual void DoDataExchange(CDataExchange * pDX); // DDX/DDV support
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 //}}AFX_VIRTUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 protected:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 //{{AFX_MSG(CMainDialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 afx_msg void OnEnable();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 afx_msg void OnDisable();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 //}}AFX_MSG
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
333 DECLARE_MESSAGE_MAP()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
336 CMainDialog::CMainDialog(CWnd * pParent /* =NULL */ )
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
337 : CDialog(CMainDialog::IDD, pParent)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 //{{AFX_DATA_INIT(CMainDialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 m_ChangeDir = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 m_bDevStudioEditor = FALSE;
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
342 m_bNewTabs = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 //}}AFX_DATA_INIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
346 void CMainDialog::DoDataExchange(CDataExchange * pDX)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
348 CDialog::DoDataExchange(pDX);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 //{{AFX_DATA_MAP(CMainDialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 DDX_Radio(pDX, IDC_CD_SOURCE_PATH, m_ChangeDir);
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
351 DDX_Check(pDX, IDC_DEVSTUDIO_EDITOR, m_bDevStudioEditor);
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
352 DDX_Check(pDX, IDC_NEW_TABS, m_bNewTabs);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 //}}AFX_DATA_MAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
356 BEGIN_MESSAGE_MAP(CMainDialog, CDialog)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 //{{AFX_MSG_MAP(CMainDialog)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 //}}AFX_MSG_MAP
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
359 END_MESSAGE_MAP()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 /////////////////////////////////////////////////////////////////////////////
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 // CCommands methods
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
365 STDMETHODIMP CCommands::VisVimDialog()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
367 AFX_MANAGE_STATE(AfxGetStaticModuleState());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 // Use m_pApplication to access the Developer Studio Application
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 // object,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 // and VERIFY_OK to see error strings in DEBUG builds of your add-in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 // (see stdafx.h)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
374 VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 CMainDialog Dlg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 Dlg.m_bDevStudioEditor = g_bDevStudioEditor;
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
379 Dlg.m_bNewTabs = g_bNewTabs;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 Dlg.m_ChangeDir = g_ChangeDir;
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
381 if (Dlg.DoModal() == IDOK)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 g_bDevStudioEditor = Dlg.m_bDevStudioEditor;
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
384 g_bNewTabs = Dlg.m_bNewTabs;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 g_ChangeDir = Dlg.m_ChangeDir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 // Save settings to registry HKEY_CURRENT_USER\Software\Vim\VisVim
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
388 HKEY hAppKey = GetAppKey("Vim");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 if (hAppKey)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
391 HKEY hSectionKey = GetSectionKey(hAppKey, "VisVim");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 if (hSectionKey)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
394 WriteRegistryInt(hSectionKey, "DevStudioEditor",
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 g_bDevStudioEditor);
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
396 WriteRegistryInt(hSectionKey, "NewTabs",
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
397 g_bNewTabs);
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
398 WriteRegistryInt(hSectionKey, "ChangeDir", g_ChangeDir);
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
399 RegCloseKey(hSectionKey);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 }
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
401 RegCloseKey(hAppKey);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
405 VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
409 STDMETHODIMP CCommands::VisVimEnable()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
411 AFX_MANAGE_STATE(AfxGetStaticModuleState());
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
412 VimSetEnableState(true);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
416 STDMETHODIMP CCommands::VisVimDisable()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
418 AFX_MANAGE_STATE(AfxGetStaticModuleState());
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
419 VimSetEnableState(false);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
423 STDMETHODIMP CCommands::VisVimToggle()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
425 AFX_MANAGE_STATE(AfxGetStaticModuleState());
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
426 VimSetEnableState(! g_bEnableVim);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
430 STDMETHODIMP CCommands::VisVimLoad()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
432 AFX_MANAGE_STATE(AfxGetStaticModuleState());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 // Use m_pApplication to access the Developer Studio Application object,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 // and VERIFY_OK to see error strings in DEBUG builds of your add-in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 // (see stdafx.h)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 CComBSTR bStr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 // Define dispatch pointers for document and selection objects
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 CComPtr < IDispatch > pDispDoc, pDispSel;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 // Get a document object dispatch pointer
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
443 VERIFY_OK(m_pApplication->get_ActiveDocument(&pDispDoc));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 if (! pDispDoc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 BSTR FileName;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 long LineNr = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 // Get the document object
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
451 CComQIPtr < ITextDocument, &IID_ITextDocument > pDoc(pDispDoc);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 if (! pDoc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 // Get the document name
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
457 if (FAILED(pDoc->get_FullName(&FileName)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 // Get a selection object dispatch pointer
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
461 if (SUCCEEDED(pDoc->get_Selection(&pDispSel)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 // Get the selection object
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
464 CComQIPtr < ITextSelection, &IID_ITextSelection > pSel(pDispSel);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 if (pSel)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 // Get the selection line number
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
468 pSel->get_CurrentLine(&LineNr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 // Open the file in Vim
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
472 VimOpenFile(FileName, LineNr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
474 SysFreeString(FileName);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 //
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 // Here we do the actual processing and communication with Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 //
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 // Set the enable state and save to registry
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 //
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
485 static void VimSetEnableState(BOOL bEnableState)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 g_bEnableVim = bEnableState;
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
488 HKEY hAppKey = GetAppKey("Vim");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 if (hAppKey)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
491 HKEY hSectionKey = GetSectionKey(hAppKey, "VisVim");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 if (hSectionKey)
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
493 WriteRegistryInt(hSectionKey, "EnableVim", g_bEnableVim);
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
494 RegCloseKey(hAppKey);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 // Open the file 'FileName' in Vim and goto line 'LineNr'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 // 'FileName' is expected to contain an absolute DOS path including the drive
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 // letter.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 // 'LineNr' must contain a valid line number or 0, e. g. for a new file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 //
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
503 static BOOL VimOpenFile(BSTR& FileName, long LineNr)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 // OLE automation object for com. with Vim
16356
1759d0ec0a6f patch 8.1.1183: typos in VisVim comments
Bram Moolenaar <Bram@vim.org>
parents: 9199
diff changeset
507 // When the object goes out of scope, its destructor destroys the OLE
1220
97cc1e746d2c updated for version 7.1b
vimboss
parents: 7
diff changeset
508 // connection;
97cc1e746d2c updated for version 7.1b
vimboss
parents: 7
diff changeset
509 // This is important to avoid blocking the object
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 // (in this memory corruption would be likely when terminating Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 // while still running DevStudio).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 // So keep this object local!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 COleAutomationControl VimOle;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 // :cd D:/Src2/VisVim/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 //
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 // Get a dispatch id for the SendKeys method of Vim;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 // enables connection to Vim if necessary
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 DISPID DispatchId;
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
520 DispatchId = VimGetDispatchId(VimOle, "SendKeys");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 if (! DispatchId)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 // OLE error, can't obtain dispatch id
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 goto OleError;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 OLECHAR Buf[MAX_OLE_STR];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 char FileNameTmp[MAX_OLE_STR];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 char VimCmd[MAX_OLE_STR];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 char *s, *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 // Prepend CTRL-\ CTRL-N to exit insert mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 VimCmd[0] = 0x1c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 VimCmd[1] = 0x0e;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 VimCmd[2] = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 #ifdef SINGLE_WINDOW
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 // Update the current file in Vim if it has been modified.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 // Disabled, because it could write the file when you don't want to.
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
538 sprintf(VimCmd + 2, ":up\n");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 #endif
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
540 if (! VimOle.Method(DispatchId, "s", TO_OLE_STR_BUF(VimCmd, Buf)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 goto OleError;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 // Change Vim working directory to where the file is if desired
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 if (g_ChangeDir != CD_NONE)
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
545 VimChangeDir(VimOle, DispatchId, FileName);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 // Make Vim open the file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 // In the filename convert all \ to /, put a \ before a space.
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
549 if (g_bNewTabs)
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
550 {
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
551 sprintf(VimCmd, ":tab drop ");
3012
6622f28b7e87 updated for version 7.3.278
Bram Moolenaar <bram@vim.org>
parents: 1852
diff changeset
552 s = VimCmd + 10;
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
553 }
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
554 else
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
555 {
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
556 sprintf(VimCmd, ":drop ");
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
557 s = VimCmd + 6;
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
558 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 sprintf(FileNameTmp, "%S", (char *)FileName);
3012
6622f28b7e87 updated for version 7.3.278
Bram Moolenaar <bram@vim.org>
parents: 1852
diff changeset
560 for (p = FileNameTmp; *p != '\0' && s < VimCmd + MAX_OLE_STR - 4; ++p)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 if (*p == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 *s++ = '/';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 if (*p == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 *s++ = '\\';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 *s++ = *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 *s++ = '\n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 *s = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
572 if (! VimOle.Method(DispatchId, "s", TO_OLE_STR_BUF(VimCmd, Buf)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 goto OleError;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 if (LineNr > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 // Goto line
9199
665d10cb3e6b commit https://github.com/vim/vim/commit/ea0345901cc2af29f9c5dd0d9d8a818d5f96a63b
Christian Brabandt <cb@256bit.org>
parents: 3012
diff changeset
578 sprintf(VimCmd, ":%ld\n", LineNr);
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
579 if (! VimOle.Method(DispatchId, "s", TO_OLE_STR_BUF(VimCmd, Buf)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 goto OleError;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 // Make Vim come to the foreground
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
584 if (! VimOle.Method("SetForeground"))
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
585 VimOle.ErrDiag();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 // We're done
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 return true;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 OleError:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 // There was an OLE error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 // Check if it's the "unknown class string" error
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
593 VimErrDiag(VimOle);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 return false;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 // Return the dispatch id for the Vim method 'Method'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 // Create the Vim OLE object if necessary
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 // Returns a valid dispatch id or null on error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 //
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
601 static DISPID VimGetDispatchId(COleAutomationControl& VimOle, char* Method)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 // Initialize Vim OLE connection if not already done
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
604 if (! VimOle.IsCreated())
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
606 if (! VimOle.CreateObject("Vim.Application"))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 // Get the dispatch id for the SendKeys method.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 // By doing this, we are checking if Vim is still there...
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
612 DISPID DispatchId = VimOle.GetDispatchId("SendKeys");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 if (! DispatchId)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 // We can't get a dispatch id.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 // This means that probably Vim has been terminated.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 // Don't issue an error message here, instead
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 // destroy the OLE object and try to connect once more
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 //
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 // In fact, this should never happen, because the OLE aut. object
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 // should not be kept long enough to allow the user to terminate Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 // to avoid memory corruption (why the heck is there no system garbage
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 // collection for those damned OLE memory chunks???).
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
624 VimOle.DeleteObject();
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
625 if (! VimOle.CreateObject("Vim.Application"))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 // If this create fails, it's time for an error msg
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
629 if (! (DispatchId = VimOle.GetDispatchId("SendKeys")))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 // There is something wrong...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 return DispatchId;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 // Output an error message for an OLE error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 // Check on the classstring error, which probably means Vim wasn't registered.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 //
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
640 static void VimErrDiag(COleAutomationControl& VimOle)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 {
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
642 SCODE sc = GetScode(VimOle.GetResult());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 if (sc == CO_E_CLASSSTRING)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 char Buf[256];
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
646 sprintf(Buf, "There is no registered OLE automation server named "
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 "\"Vim.Application\".\n"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 "Use the OLE-enabled version of Vim with VisVim and "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 "make sure to register Vim by running \"vim -register\".");
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
650 MessageBox(NULL, Buf, "OLE Error", MB_OK);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 else
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
653 VimOle.ErrDiag();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655
16356
1759d0ec0a6f patch 8.1.1183: typos in VisVim comments
Bram Moolenaar <Bram@vim.org>
parents: 9199
diff changeset
656 // Change directory to the directory the file 'FileName' is in or its parent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 // directory according to the setting of the global 'g_ChangeDir':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 // 'FileName' is expected to contain an absolute DOS path including the drive
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 // letter.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 // CD_NONE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 // CD_SOURCE_PATH
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 // CD_SOURCE_PARENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 //
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
664 static void VimChangeDir(COleAutomationControl& VimOle, DISPID DispatchId, BSTR& FileName)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 // Do a :cd first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 // Get the path name of the file ("dir/")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 CString StrFileName = FileName;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 char Drive[_MAX_DRIVE];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 char Dir[_MAX_DIR];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 char DirUnix[_MAX_DIR * 2];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 char *s, *t;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
675 _splitpath(StrFileName, Drive, Dir, NULL, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 // Convert to Unix path name format, escape spaces.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 t = DirUnix;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 for (s = Dir; *s; ++s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 if (*s == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 *t++ = '/';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 if (*s == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 *t++ = '\\';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 *t++ = *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 *t = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 // Construct the cd command; append /.. if cd to parent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 // directory and not in root directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 OLECHAR Buf[MAX_OLE_STR];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 char VimCmd[MAX_OLE_STR];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
696 sprintf(VimCmd, ":cd %s%s%s\n", Drive, DirUnix,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 g_ChangeDir == CD_SOURCE_PARENT && DirUnix[1] ? ".." : "");
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
698 VimOle.Method(DispatchId, "s", TO_OLE_STR_BUF(VimCmd, Buf));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 #ifdef _DEBUG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 // Print out a debug message
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 //
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
704 static void DebugMsg(char* Msg, char* Arg)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706 char Buf[400];
1852
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
707 sprintf(Buf, Msg, Arg);
3af484dca921 updated for version 7.2-150
vimboss
parents: 1220
diff changeset
708 AfxMessageBox(Buf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 #endif