-
Notifications
You must be signed in to change notification settings - Fork 9
/
plugin.pas
139 lines (106 loc) · 2.98 KB
/
plugin.pas
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
unit plugin;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils,
System.Classes, Vcl.ComCtrls, SciSupport, Vcl.Forms,
Vcl.Controls, NppPlugin;
type
TModalResultArray = array[False..True] of TModalResult;
TBdType = (bdMSSQL, bdSybase, bdODBC);
TBdTypeStringArray = array [TBdType] of string;
TItemType = (itServerMS,itServerSYB,itODBC,itBase,itBaseRTI,itLogin);
TMenuItemCheck = (miHidden,miShown);
TdsPlugin = class(TNppPlugin)
private
{ Private declarations }
FForm: TForm;
public
constructor Create;
procedure DoNppnToolbarModification; override;
procedure FuncLog;
procedure FuncExecSQL;
end;
const
WM_USER_MESSAGE_FROM_THREAD = WM_USER + 1;
cnstSqlWaitResults = 'Waiting........';
cnstSqlNoResults = 'Command executed';
cnstSqlExec = 'Results: %s\%s (%s)';
cnstModalResultArray: TModalResultArray = (mrCancel,mrOk);
cnstShowPlan_ON = 'set showplan on';
cnstShowPlan_OFF = 'set showplan off';
cnstAseOleDB = '[ASEOLEDB]';
cnstShowPlan = 'PLAN:';
cnstShowIndx = 'INDX:';
cnstSqlplanExt = '.sqlplan';
cnstGo = 'go';
constLoginBDCaption = 'Connect to ';
constLoginBDCaptionArray: TBdTypeStringArray = ('MSSQL','Sybase','ODBC');
constDSBDCaptionArray: TBdTypeStringArray = ('Server','Server','DataSource');
cnstErroCaption = 'Error';
cnstNoBaseSelected = 'You must select Server and Base before executing SQL!';
cnstMainDlgId = 0;
var
NPlugin: TdsPlugin;
implementation
uses connectionFormUnit;
procedure _FuncLog; cdecl;
begin
NPlugin.FuncLog;
end;
procedure _FuncExecSQL; cdecl;
begin
NPlugin.FuncExecSQL;
end;
{ TdsPlugin }
constructor TdsPlugin.Create;
var
sk: TShortcutKey;
begin
inherited;
PluginName := 'npp.Connections';
AddFuncItem('Show result panel', _FuncLog);
sk.IsCtrl := true; sk.IsAlt := false; sk.IsShift := false;
sk.Key := 69; // 'E'
AddFuncItem('Execute SQL', _FuncExecSQL, sk);
Sci_Send(SCI_SETMODEVENTMASK,SC_MOD_INSERTTEXT or SC_MOD_DELETETEXT,0);
end;
procedure TdsPlugin.DoNppnToolbarModification;
var
tb: TToolbarIcons;
begin
tb.ToolbarIcon := 0;
tb.ToolbarBmp := LoadImage(Hinstance, 'TREE', IMAGE_BITMAP, 0, 0, (LR_DEFAULTSIZE));
Npp_Send(NPPM_ADDTOOLBARICON, WPARAM(self.CmdIdFromDlgId(cnstMainDlgId)), LPARAM(@tb));
tb.ToolbarBmp := LoadImage(Hinstance, 'SQL', IMAGE_BITMAP, 0, 0, (LR_DEFAULTSIZE));
Npp_Send(NPPM_ADDTOOLBARICON, WPARAM(self.CmdIdFromDlgId(cnstMainDlgId+1)), LPARAM(@tb));
end;
procedure TdsPlugin.FuncExecSQL;
var S: string;
N: integer;
begin
if not Assigned(FForm) then
begin
FuncLog;
TconnectionForm(FForm).DoConnect;
end
else
begin
S := SelectedText;
N := Length(S);
if N < 1 then
begin
S := GetText;
N := Length(S);
end;
if N > 1 then
begin
TconnectionForm(FForm).DoSql(S);
end;
end;
end;
procedure TdsPlugin.FuncLog;
begin
if not Assigned(FForm) then FForm := TconnectionForm.Create(self, cnstMainDlgId);
(FForm as TconnectionForm).Carousel;
end;
end.