Menu

[r2]: / NppWLangLexer_Plugin / src / NppPluginClass.cpp  Maximize  Restore  History

Download this file

212 lines (147 with data), 5.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// NppPluginClass.cpp
// This file is part of the Notepad++ External Lexers Plugin.
// Copyright 2008 - 2009 Thell Fowler (thell@almostautomated.com)
//
// This program is free software; you can redistribute it and/or modify it under the terms of
// the GNU General Public License as published by the Free Software Foundation; either version
// 2 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with this program;
// if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
///////////////////////////////////////////////////////////////////////////////////////////////
// Class for Plugin Object Data Storage
// for use with Notepad++ Plugins
///////////////////////////////////////////////////////////////////////////////////////////////
#include <algorithm>
#include <iterator>
#include "NppPluginClass.h"
void NppPlugin::init(const TCHAR* name, HANDLE hModule) // Initialize Plugin.
{
/*
* NppPlugin is a singleton class and should only have init() called once!
* Fail if called again.
*
*/
_ASSERT(!_isInitialized); // Assert that the class hasn't already been initialized.
_Name = name;
_hModule = hModule;
_isInitialized = true;
}
void NppPlugin::setNppData(NppData NppData) // Store Notepad++ handle details.
{
_hNpp = NppData._nppHandle;
_hScintillaMain = NppData._scintillaMainHandle;
_hScintillaSecond = NppData._scintillaSecondHandle;
}
const TCHAR* NppPlugin::Name() // Plugin module's name, for internal Notepad++ use.
{
return _Name;
}
HANDLE NppPlugin::hModule() // Plugin module's handle.
{
return _hModule;
}
HWND NppPlugin::hNpp() // Returns the main Notepad++ handle.
{
return _hNpp;
}
HWND NppPlugin::hScintillaMain() // Returns handle used in messaging the main view.
{
return _hScintillaMain;
}
HWND NppPlugin::hScintillaSecond() // Returns handle used in messaging the secondary view.
{
return _hScintillaSecond;
}
HWND NppPlugin::hCurrView() // Returns handle for the currently focused view.
{
if ( bRefreshCurrViewH || !_isReady ) {
_hCurrView = NppPlugin::updateCurrViewHandle();
}
return _hCurrView;
}
HWND NppPlugin::updateCurrViewHandle() // Updates handle pointer to the currently active view.
{
int currentEdit;
::SendMessage(_hNpp, NPPM_GETCURRENTSCINTILLA, 0, (LPARAM)&currentEdit);
bRefreshCurrViewH = false;
return ( currentEdit == 0 ) ? ( _hScintillaMain ): ( _hScintillaSecond );
};
bool NppPlugin::isReady() // Returns Notepad++ initialization state.
{
return _isReady;
}
void NppPlugin::setLexerFuncItem(const TCHAR* szName, PFUNCPLUGINCMD pFunc)
{
/*
* This function stores Function Items to the FuncItem vector.
* Using a vector instead of array to allow for easier sorting.
*
* The _cmdID values are assigned after sorting in getFunctionsArray().
*
*/
FuncItem thisFunction;
thisFunction._cmdID = NULL;
lstrcpy(thisFunction._itemName, szName);
thisFunction._pFunc = pFunc;
thisFunction._init2Check = false;
thisFunction._pShKey = NULL;
_FunctionsLexer.push_back(thisFunction);
}
void NppPlugin::setPluginFuncItem(const TCHAR* szName, PFUNCPLUGINCMD pFunc)
{
/*
* This function stores Function Items to the FuncItem vector.
* Using a vector instead of array to allow for easier sorting.
*
* The _cmdID values are assigned after sorting in getFunctionsArray().
*
*/
FuncItem thisFunction;
thisFunction._cmdID = NULL;
lstrcpy(thisFunction._itemName, szName);
thisFunction._pFunc = pFunc;
thisFunction._init2Check = false;
thisFunction._pShKey = NULL;
_FunctionsPlugin.push_back(thisFunction);
}
FuncItem * NppPlugin::getFunctionsArray() // Return this plugin's sorted FuncItem array.
{
/*
* In order to have the function items show up in the Notepad++ plugins menu with
* this plugins function items at the bottom a new vector is created and the existing
* vectors are copied into it with the lexer functions first.
*
*/
// <--- Local function for sorting criteria predicate. --->
struct sortByName
{
bool operator()(FuncItem& f1, FuncItem& f2)
{
return f1._itemName < f2._itemName;
}
};
if ( _FunctionsLexer.empty() ) {
// Doesn't look like there are any lexer function items so just send the plugin's.
ReturnVector = _FunctionsPlugin;
}
else {
// Sort the lexer function items vector.
std::sort(_FunctionsLexer.begin(), _FunctionsLexer.end(), sortByName());
// Copy it to a new vector that will be returned to Notepad++'s PluginsManager.
ReturnVector = _FunctionsLexer;
// Append the base plugin's function items (ie 'Help', 'About', etc...
std::copy(_FunctionsPlugin.begin(), _FunctionsPlugin.end(), std::back_inserter(ReturnVector));
}
return ( &ReturnVector[0] );
}
int NppPlugin::getFunctionsCount()
{
int count = _FunctionsLexer.size();
count += _FunctionsPlugin.size();
return count;
}
MongoDB Logo MongoDB