Skip to content

Commit b47f439

Browse files
committed
Added hotkeys for bookmarks
1 parent 4748bab commit b47f439

File tree

4 files changed

+56
-12
lines changed

4 files changed

+56
-12
lines changed

src/VBACHAddin.pas

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ TVBACHAddin = class(TAutoObject, IVBACodeHelper, IDTExtensibility2)
2222
FHotKeyWindowHandle: HWND;
2323
FHotKeyCommentLine: Cardinal;
2424
FHotKeyUnCommentLine: Cardinal;
25+
FHotKeyToggleBookmark: Cardinal;
26+
FHotKeyNextBookmark: Cardinal;
27+
FHotKeyPrevBookmark: Cardinal;
2528
procedure InitButtons;
2629
procedure DestroyButtons;
2730
procedure WndProc(var Msg: TMessage);
@@ -111,6 +114,15 @@ procedure TVBACHAddin.InitHotKeys;
111114
{ UnComment lines }
112115
FHotKeyUnCommentLine := GlobalAddAtom(StrFmt(AtomText, 'UnCommentHotVBE%.8X%.8X', [HInstance, GetCurrentThreadID]));
113116
RegisterHotKey(FHotKeyWindowHandle, FHotKeyUnCommentLine, MOD_ALT + MOD_CONTROL, VK_SUBTRACT);
117+
{ Toggle bookmark }
118+
FHotKeyToggleBookmark := GlobalAddAtom(StrFmt(AtomText, 'TgBmarkHotVBE%.8X%.8X', [HInstance, GetCurrentThreadID]));
119+
RegisterHotKey(FHotKeyWindowHandle, FHotKeyToggleBookmark, MOD_ALT + MOD_CONTROL, VK_MULTIPLY);
120+
{ Next bookmark }
121+
FHotKeyNextBookmark := GlobalAddAtom(StrFmt(AtomText, 'NxBkmarkVBE%.8X%.8X', [HInstance, GetCurrentThreadID]));
122+
RegisterHotKey(FHotKeyWindowHandle, FHotKeyNextBookmark, MOD_CONTROL, VK_OEM_3);
123+
{ Previous bookmark }
124+
FHotKeyPrevBookmark := GlobalAddAtom(StrFmt(AtomText, 'PvBkmarkVBE%.8X%.8X', [HInstance, GetCurrentThreadID]));
125+
RegisterHotKey(FHotKeyWindowHandle, FHotKeyPrevBookmark, MOD_SHIFT + MOD_CONTROL, VK_OEM_3);
114126
end;
115127
end;
116128

@@ -244,6 +256,12 @@ procedure TVBACHAddin.DestroyHotKeys;
244256
GlobalDeleteAtom(FHotKeyCommentLine);
245257
UnRegisterHotKey(FHotKeyWindowHandle, FHotKeyUnCommentLine);
246258
GlobalDeleteAtom(FHotKeyUnCommentLine);
259+
UnRegisterHotKey(FHotKeyWindowHandle, FHotKeyToggleBookmark);
260+
GlobalDeleteAtom(FHotKeyToggleBookmark);
261+
UnRegisterHotKey(FHotKeyWindowHandle, FHotKeyNextBookmark);
262+
GlobalDeleteAtom(FHotKeyNextBookmark);
263+
UnRegisterHotKey(FHotKeyWindowHandle, FHotKeyPrevBookmark);
264+
GlobalDeleteAtom(FHotKeyPrevBookmark);
247265
DeallocateHWnd(FHotKeyWindowHandle);
248266
FHotKeyWindowHandle := 0;
249267
end;
@@ -282,16 +300,35 @@ procedure TVBACHAddin.WndProc(var Msg: TMessage);
282300
if Msg.Msg = WM_HOTKEY then
283301
begin
284302
fgWnd := GetForegroundWindow;
285-
if (fgWnd = FVBEWindowHandle) and ((Msg.WParam = FHotKeyCommentLine) or
286-
(Msg.WParam = FHotKeyUnCommentLine)) then
303+
if (fgWnd = FVBEWindowHandle) and
304+
((Msg.WParam = FHotKeyCommentLine) or
305+
(Msg.WParam = FHotKeyUnCommentLine) or
306+
(Msg.WParam = FHotKeyToggleBookmark) or
307+
(Msg.WParam = FHotKeyNextBookmark) or
308+
(Msg.WParam = FHotKeyPrevBookmark)) then
287309
begin
288310
if Assigned(FVBEApp) then
289311
begin
290312
cmBars := (FVBEApp as VBE).CommandBars;
291313
if Msg.WParam = FHotKeyCommentLine then
292-
cmBars.Item['Edit'].Controls.Item['Comment Block'].Execute
314+
cmBars.Item[sVBE_EditBar].Controls.Item[sVBE_CommentLines].Execute
293315
else if Msg.WParam = FHotKeyUnCommentLine then
294-
cmBars.Item['Edit'].Controls.Item['UnComment Block'].Execute;
316+
cmBars.Item[sVBE_EditBar].Controls.Item[sVBE_UnCommentLines].Execute
317+
else if Msg.WParam = FHotKeyToggleBookmark then
318+
begin
319+
if cmBars.Item[sVBE_EditBar].Controls.Item[sVBE_ToggleBookmark].Enabled then
320+
cmBars.Item[sVBE_EditBar].Controls.Item[sVBE_ToggleBookmark].Execute;
321+
end
322+
else if Msg.WParam = FHotKeyNextBookmark then
323+
begin
324+
if cmBars.Item[sVBE_EditBar].Controls.Item[sVBE_NextBookmark].Enabled then
325+
cmBars.Item[sVBE_EditBar].Controls.Item[sVBE_NextBookmark].Execute
326+
end
327+
else if Msg.WParam = FHotKeyPrevBookmark then
328+
begin
329+
if cmBars.Item[sVBE_EditBar].Controls.Item[sVBE_PreviousBookmark].Enabled then
330+
cmBars.Item[sVBE_EditBar].Controls.Item[sVBE_PreviousBookmark].Execute;
331+
end;
295332
end;
296333
end;
297334
end

src/VBACHConst.pas

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ interface
88
sCHBT_IndentModule = 'CHBT_IndentModule';
99
sCHBT_IndentSubProgram = 'CHBT_IndentSubProgram';
1010
sCHBT_IndentLines = 'CHBT_IndentLines';
11+
{ VBE bar's items }
12+
sVBE_EditBar = 'Edit';
13+
sVBE_CommentLines = 'Comment Block';
14+
sVBE_UnCommentLines = 'UnComment Block';
15+
sVBE_ToggleBookmark = 'Toggle Bookmark';
16+
sVBE_NextBookmark = 'Next Bookmark';
17+
sVBE_PreviousBookmark = 'Previous Bookmark';
1118

1219
resourcestring
1320
{$IFDEF WIN32}

src/VBACodeHelper.dproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@
9999
<VerInfo_Locale>1033</VerInfo_Locale>
100100
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
101101
<DCC_RemoteDebug>false</DCC_RemoteDebug>
102-
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.1.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=;ProductName=$(MSBuildProjectName);ProductVersion=1.0.1.0;Comments=</VerInfo_Keys>
103-
<VerInfo_Release>1</VerInfo_Release>
102+
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.2.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=;ProductName=$(MSBuildProjectName);ProductVersion=1.0.2.0;Comments=</VerInfo_Keys>
103+
<VerInfo_Release>2</VerInfo_Release>
104104
</PropertyGroup>
105105
<PropertyGroup Condition="'$(Cfg_1_Win64)'!=''">
106-
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.1.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=;ProductName=$(MSBuildProjectName);ProductVersion=1.0.1.0;Comments=</VerInfo_Keys>
107-
<VerInfo_Release>1</VerInfo_Release>
106+
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.2.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=;ProductName=$(MSBuildProjectName);ProductVersion=1.0.2.0;Comments=</VerInfo_Keys>
107+
<VerInfo_Release>2</VerInfo_Release>
108108
<VerInfo_Locale>1033</VerInfo_Locale>
109109
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
110110
<Debugger_HostApplication>C:\Program Files\Microsoft Office\Office15\WINWORD.EXE</Debugger_HostApplication>
@@ -118,15 +118,15 @@
118118
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
119119
<VerInfo_Locale>1033</VerInfo_Locale>
120120
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
121-
<VerInfo_Release>1</VerInfo_Release>
122-
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.1.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=;ProductName=$(MSBuildProjectName);ProductVersion=1.0.1.0;Comments=</VerInfo_Keys>
121+
<VerInfo_Release>2</VerInfo_Release>
122+
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.2.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=;ProductName=$(MSBuildProjectName);ProductVersion=1.0.2.0;Comments=</VerInfo_Keys>
123123
</PropertyGroup>
124124
<PropertyGroup Condition="'$(Cfg_2_Win64)'!=''">
125125
<VerInfo_Locale>1033</VerInfo_Locale>
126126
<Debugger_HostApplication>C:\Program Files\Microsoft Office\Office15\WINWORD.EXE</Debugger_HostApplication>
127127
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
128-
<VerInfo_Release>1</VerInfo_Release>
129-
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.1.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=;ProductName=$(MSBuildProjectName);ProductVersion=1.0.1.0;Comments=</VerInfo_Keys>
128+
<VerInfo_Release>2</VerInfo_Release>
129+
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.2.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=;ProductName=$(MSBuildProjectName);ProductVersion=1.0.2.0;Comments=</VerInfo_Keys>
130130
</PropertyGroup>
131131
<ItemGroup>
132132
<DelphiCompile Include="$(MainSource)">

src/VBACodeHelper.res

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)