annotate src/VisVim/DSAddIn.cpp @ 19481:c27837cbe922 v8.2.0298

patch 8.2.0298: Vim9 script: cannot start command with a string constant Commit: https://github.com/vim/vim/commit/0c6ceaf90389b41545d803458c4813013811c756 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Feb 22 18:36:32 2020 +0100 patch 8.2.0298: Vim9 script: cannot start command with a string constant Problem: Vim9 script: cannot start command with a string constant. Solution: Recognize expression starting with '('.
author Bram Moolenaar <Bram@vim.org>
date Sat, 22 Feb 2020 18:45:04 +0100
parents a3c21128b246
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 "VisVim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 #include "DSAddIn.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
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 #ifdef _DEBUG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 #define new DEBUG_NEW
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 #undef THIS_FILE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 static char THIS_FILE[] = __FILE__;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 // This is called when the user first loads the add-in, and on start-up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 // of each subsequent Developer Studio session
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 STDMETHODIMP CDSAddIn::OnConnection (IApplication * pApp, VARIANT_BOOL bFirstTime,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 long dwCookie, VARIANT_BOOL * OnConnection)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 AFX_MANAGE_STATE (AfxGetStaticModuleState ());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 *OnConnection = VARIANT_FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 // Store info passed to us
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 IApplication *pApplication = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 HRESULT hr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 hr = pApp->QueryInterface (IID_IApplication, (void **) &pApplication);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 if (FAILED (hr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 ReportLastError (hr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 return E_UNEXPECTED;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 if (pApplication == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 ReportInternalError ("IApplication::QueryInterface");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 return E_UNEXPECTED;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 m_dwCookie = dwCookie;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 // Create command dispatch, send info back to DevStudio
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 CCommandsObj::CreateInstance (&m_pCommands);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 if (! m_pCommands)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 ReportInternalError ("CCommandsObj::CreateInstance");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 return E_UNEXPECTED;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 m_pCommands->AddRef ();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 // The QueryInterface above AddRef'd the Application object. It will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 // be Release'd in CCommand's destructor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 m_pCommands->SetApplicationObject (pApplication);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 hr = pApplication->SetAddInInfo ((long) AfxGetInstanceHandle (),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 (LPDISPATCH) m_pCommands, IDR_TOOLBAR_MEDIUM, IDR_TOOLBAR_LARGE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 m_dwCookie);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 if (FAILED (hr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 ReportLastError (hr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 return E_UNEXPECTED;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 // Inform DevStudio of the commands we implement
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 if (! AddCommand (pApplication, "VisVimDialog", "VisVimDialogCmd",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 IDS_CMD_DIALOG, 0, bFirstTime))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 return E_UNEXPECTED;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 if (! AddCommand (pApplication, "VisVimEnable", "VisVimEnableCmd",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 IDS_CMD_ENABLE, 1, bFirstTime))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 return E_UNEXPECTED;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 if (! AddCommand (pApplication, "VisVimDisable", "VisVimDisableCmd",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 IDS_CMD_DISABLE, 2, bFirstTime))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 return E_UNEXPECTED;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 if (! AddCommand (pApplication, "VisVimToggle", "VisVimToggleCmd",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 IDS_CMD_TOGGLE, 3, bFirstTime))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 return E_UNEXPECTED;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 if (! AddCommand (pApplication, "VisVimLoad", "VisVimLoadCmd",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 IDS_CMD_LOAD, 4, bFirstTime))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 return E_UNEXPECTED;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 *OnConnection = VARIANT_TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 // This is called on shut-down, and also when the user unloads the add-in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 STDMETHODIMP CDSAddIn::OnDisconnection (VARIANT_BOOL bLastTime)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 AFX_MANAGE_STATE (AfxGetStaticModuleState ());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 m_pCommands->UnadviseFromEvents ();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 m_pCommands->Release ();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 m_pCommands = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 return S_OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 // Add a command to DevStudio
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 // Creates a toolbar button for the command also.
1204
a3c21128b246 updated for version 7.1b
vimboss
parents: 7
diff changeset
96 // 'MethodName' is the name of the method specified in the .odl file
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 // 'StrResId' the resource id of the descriptive string
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 // 'GlyphIndex' the image index into the command buttons bitmap
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 // Return true on success
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 //
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 bool CDSAddIn::AddCommand (IApplication* pApp, char* MethodName, char* CmdName,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 UINT StrResId, UINT GlyphIndex, VARIANT_BOOL bFirstTime)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 CString CmdString;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 CString CmdText;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 CmdText.LoadString (StrResId);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 CmdString = CmdName;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 CmdString += CmdText;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 CComBSTR bszCmdString (CmdString);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 CComBSTR bszMethod (MethodName);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 CComBSTR bszCmdName (CmdName);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 // (see stdafx.h for the definition of VERIFY_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 VARIANT_BOOL bRet;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 VERIFY_OK (pApp->AddCommand (bszCmdString, bszMethod, GlyphIndex,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 m_dwCookie, &bRet));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 if (bRet == VARIANT_FALSE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 // AddCommand failed because a command with this name already exists.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 ReportInternalError ("IApplication::AddCommand");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 // Add toolbar buttons only if this is the first time the add-in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 // is being loaded. Toolbar buttons are automatically remembered
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 // by Developer Studio from session to session, so we should only
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 // add the toolbar buttons once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 if (bFirstTime == VARIANT_TRUE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 VERIFY_OK (pApp->AddCommandBarButton (dsGlyph, bszCmdName, m_dwCookie));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 return TRUE;
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 void ReportLastError (HRESULT Err)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 char *Buf = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 char Msg[512];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 NULL, Err,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 Buf, 400, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 sprintf (Msg, "Unexpected error (Error code: %lx)\n%s", Err, Buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 ::MessageBox (NULL, Msg, "VisVim", MB_OK | MB_ICONSTOP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 if (Buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 LocalFree (Buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 void ReportInternalError (char* Fct)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 char Msg[512];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 sprintf (Msg, "Unexpected error\n%s failed", Fct);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 ::MessageBox (NULL, Msg, "VisVim", MB_OK | MB_ICONSTOP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160