implemented goto next/previous bookmark

git-svn-id: trunk@7570 -
This commit is contained in:
mattias 2005-08-25 21:48:07 +00:00
parent bd65ed9642
commit 401d21c00f
5 changed files with 175 additions and 22 deletions

View File

@ -182,6 +182,10 @@ const
ecGotoEditor9 = ecGotoEditor8 + 1; ecGotoEditor9 = ecGotoEditor8 + 1;
ecGotoEditor0 = ecGotoEditor9 + 1; ecGotoEditor0 = ecGotoEditor9 + 1;
// marker
ecPrevBookmark = ecUserFirst + 381;
ecNextBookmark = ecUserFirst + 382;
// compile menu // compile menu
ecBuild = ecUserFirst + 400; ecBuild = ecUserFirst + 400;
ecBuildAll = ecUserFirst + 401; ecBuildAll = ecUserFirst + 401;
@ -550,6 +554,8 @@ begin
ecOpenFileAtCursor: SetResult(VK_RETURN,[ssCtrl],VK_UNKNOWN,[]); ecOpenFileAtCursor: SetResult(VK_RETURN,[ssCtrl],VK_UNKNOWN,[]);
// marker // marker
ecPrevBookmark: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecNextBookmark: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecGotoMarker0: SetResult(VK_0,[ssCtrl],VK_UNKNOWN,[]); ecGotoMarker0: SetResult(VK_0,[ssCtrl],VK_UNKNOWN,[]);
ecGotoMarker1: SetResult(VK_1,[ssCtrl],VK_UNKNOWN,[]); ecGotoMarker1: SetResult(VK_1,[ssCtrl],VK_UNKNOWN,[]);
ecGotoMarker2: SetResult(VK_2,[ssCtrl],VK_UNKNOWN,[]); ecGotoMarker2: SetResult(VK_2,[ssCtrl],VK_UNKNOWN,[]);
@ -853,6 +859,8 @@ begin
ecOpenFileAtCursor: SetResult(VK_RETURN,[ssCtrl],VK_UNKNOWN,[],VK_UNKNOWN,[],VK_UNKNOWN,[]); ecOpenFileAtCursor: SetResult(VK_RETURN,[ssCtrl],VK_UNKNOWN,[],VK_UNKNOWN,[],VK_UNKNOWN,[]);
// marker // marker
ecPrevBookmark: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecNextBookmark: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecGotoMarker0: SetResult(VK_Q,[ssCtrl],VK_0,[],VK_UNKNOWN,[],VK_UNKNOWN,[]); ecGotoMarker0: SetResult(VK_Q,[ssCtrl],VK_0,[],VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecGotoMarker1: SetResult(VK_Q,[ssCtrl],VK_1,[],VK_UNKNOWN,[],VK_UNKNOWN,[]); ecGotoMarker1: SetResult(VK_Q,[ssCtrl],VK_1,[],VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecGotoMarker2: SetResult(VK_Q,[ssCtrl],VK_2,[],VK_UNKNOWN,[],VK_UNKNOWN,[]); ecGotoMarker2: SetResult(VK_Q,[ssCtrl],VK_2,[],VK_UNKNOWN,[],VK_UNKNOWN,[]);
@ -1390,7 +1398,8 @@ begin
ecColumnSelect : Result:= srkmecColumnSelect; ecColumnSelect : Result:= srkmecColumnSelect;
ecLineSelect : Result:= srkmecLineSelect; ecLineSelect : Result:= srkmecLineSelect;
ecAutoCompletion : Result:= srkmecAutoCompletion; ecAutoCompletion : Result:= srkmecAutoCompletion;
ecUserFirst : Result:= srkmecUserFirst; ecUserFirst : Result:= srkmecPrevBookmark;
ecPrevBookmark : Result:= srkmecNextBookmark;
ecGotoMarker0 .. ecGotoMarker0 ..
ecGotoMarker9 : Result:= Format(srkmecGotoMarker,[cmd-ecGotoMarker0]); ecGotoMarker9 : Result:= Format(srkmecGotoMarker,[cmd-ecGotoMarker0]);
ecSetMarker0 .. ecSetMarker0 ..
@ -2313,6 +2322,8 @@ begin
// marker - without menu items in the IDE bar // marker - without menu items in the IDE bar
C:=Categories[AddCategory('Marker',srkmCatMarker,caSrcEditOnly)]; C:=Categories[AddCategory('Marker',srkmCatMarker,caSrcEditOnly)];
AddDefault(C,'Previous Bookmark',ecPrevBookmark);
AddDefault(C,'Next Bookmark',ecNextBookmark);
AddDefault(C,'Go to marker 0',ecGotoMarker0); AddDefault(C,'Go to marker 0',ecGotoMarker0);
AddDefault(C,'Go to marker 1',ecGotoMarker1); AddDefault(C,'Go to marker 1',ecGotoMarker1);
AddDefault(C,'Go to marker 2',ecGotoMarker2); AddDefault(C,'Go to marker 2',ecGotoMarker2);

View File

@ -184,6 +184,8 @@ resourcestring
lisMenuGotoIncludeDirective = 'Goto include directive'; lisMenuGotoIncludeDirective = 'Goto include directive';
lisMenuJumpToNextError = 'Jump to next error'; lisMenuJumpToNextError = 'Jump to next error';
lisMenuJumpToPrevError = 'Jump to previous error'; lisMenuJumpToPrevError = 'Jump to previous error';
lisMenuJumpToNextBookmark = 'Jump to next bookmark';
lisMenuJumpToPrevBookmark = 'Jump to previous bookmark';
lisMenuViewObjectInspector = 'Object Inspector'; lisMenuViewObjectInspector = 'Object Inspector';
lisMenuViewSourceEditor = 'Source Editor'; lisMenuViewSourceEditor = 'Source Editor';
@ -1160,6 +1162,8 @@ resourcestring
uemCopy = 'Copy'; uemCopy = 'Copy';
uemPaste = 'Paste'; uemPaste = 'Paste';
uemGotoBookmark = '&Goto Bookmark'; uemGotoBookmark = '&Goto Bookmark';
uemNextBookmark = 'Goto next Bookmark';
uemPrevBookmark = 'Goto previous Bookmark';
uemBookmarkN = 'Bookmark'; uemBookmarkN = 'Bookmark';
lisOpenLfm = 'Open %s'; lisOpenLfm = 'Open %s';
uemSetBookmark = '&Set Bookmark'; uemSetBookmark = '&Set Bookmark';
@ -1314,6 +1318,8 @@ resourcestring
srkmecLineSelect = 'Line selection mode'; srkmecLineSelect = 'Line selection mode';
srkmecAutoCompletion = 'Code template completion'; srkmecAutoCompletion = 'Code template completion';
srkmecUserFirst = 'User First'; srkmecUserFirst = 'User First';
srkmecPrevBookmark = 'Previous Bookmark';
srkmecNextBookmark = 'Next Bookmark';
srkmecGotoMarker = 'Go to Marker %d'; srkmecGotoMarker = 'Go to Marker %d';
srkmecSetMarker = 'Set Marker %d'; srkmecSetMarker = 'Set Marker %d';

View File

@ -157,6 +157,8 @@ type
itmJumpHistory: TMenuItem; itmJumpHistory: TMenuItem;
itmJumpToNextError: TMenuItem; itmJumpToNextError: TMenuItem;
itmJumpToPrevError: TMenuItem; itmJumpToPrevError: TMenuItem;
itmJumpToNextBookmark: TMenuItem;
itmJumpToPrevBookmark: TMenuItem;
itmFindBlockOtherEnd: TMenuItem; itmFindBlockOtherEnd: TMenuItem;
itmFindBlockStart: TMenuItem; itmFindBlockStart: TMenuItem;
itmFindDeclaration: TMenuItem; itmFindDeclaration: TMenuItem;

View File

@ -479,8 +479,10 @@ begin
CreateMenuItem(ParentMI,itmJumpForward,'itmJumpForward',lisMenuJumpForward); CreateMenuItem(ParentMI,itmJumpForward,'itmJumpForward',lisMenuJumpForward);
CreateMenuItem(ParentMI,itmAddJumpPoint,'itmAddJumpPoint',lisMenuAddJumpPointToHistory); CreateMenuItem(ParentMI,itmAddJumpPoint,'itmAddJumpPoint',lisMenuAddJumpPointToHistory);
CreateMenuItem(ParentMI,itmJumpHistory,'itmJumpHistory',lisMenuViewJumpHistory); CreateMenuItem(ParentMI,itmJumpHistory,'itmJumpHistory',lisMenuViewJumpHistory);
CreateMenuItem(ParentMI,itmJumpHistory,'itmJumpToNextError',lisMenuJumpToNextError); CreateMenuItem(ParentMI,itmJumpToNextError,'itmJumpToNextError',lisMenuJumpToNextError);
CreateMenuItem(ParentMI,itmJumpHistory,'itmJumpToPrevError',lisMenuJumpToPrevError); CreateMenuItem(ParentMI,itmJumpToPrevError,'itmJumpToPrevError',lisMenuJumpToPrevError);
CreateMenuItem(ParentMI,itmJumpToNextBookmark,'itmJumpToNextBookmark',lisMenuJumpToNextBookmark);
CreateMenuItem(ParentMI,itmJumpToPrevBookmark,'itmJumpToPrevBookmark',lisMenuJumpToNextBookmark);
ParentMI.Add(CreateMenuSeparator); ParentMI.Add(CreateMenuSeparator);
@ -779,6 +781,8 @@ begin
itmJumpHistory.ShortCut:=CommandToShortCut(ecViewJumpHistory); itmJumpHistory.ShortCut:=CommandToShortCut(ecViewJumpHistory);
itmJumpToNextError.ShortCut:=CommandToShortCut(ecJumpToNextError); itmJumpToNextError.ShortCut:=CommandToShortCut(ecJumpToNextError);
itmJumpToPrevError.ShortCut:=CommandToShortCut(ecJumpToPrevError); itmJumpToPrevError.ShortCut:=CommandToShortCut(ecJumpToPrevError);
itmJumpToNextBookmark.ShortCut:=CommandToShortCut(ecNextBookmark);
itmJumpToPrevBookmark.ShortCut:=CommandToShortCut(ecPrevBookmark);
itmFindBlockOtherEnd.ShortCut:=CommandToShortCut(ecFindBlockOtherEnd); itmFindBlockOtherEnd.ShortCut:=CommandToShortCut(ecFindBlockOtherEnd);
itmFindBlockStart.ShortCut:=CommandToShortCut(ecFindBlockStart); itmFindBlockStart.ShortCut:=CommandToShortCut(ecFindBlockStart);
itmFindDeclaration.ShortCut:=CommandToShortCut(ecFindDeclaration); itmFindDeclaration.ShortCut:=CommandToShortCut(ecFindDeclaration);

View File

@ -350,6 +350,8 @@ type
CopyMenuItem: TMenuItem; CopyMenuItem: TMenuItem;
PasteMenuItem: TMenuItem; PasteMenuItem: TMenuItem;
GotoBookmarkMenuItem: TMenuItem; GotoBookmarkMenuItem: TMenuItem;
NextBookmarkMenuItem: TMenuItem;
PrevBookmarkMenuItem: TMenuItem;
MoveEditorLeftMenuItem: TMenuItem; MoveEditorLeftMenuItem: TMenuItem;
MoveEditorRightMenuItem: TMenuItem; MoveEditorRightMenuItem: TMenuItem;
OpenFileAtCursorMenuItem: TMenuItem; OpenFileAtCursorMenuItem: TMenuItem;
@ -366,9 +368,9 @@ type
SrcPopUpMenu: TPopupMenu; SrcPopUpMenu: TPopupMenu;
StatusBar: TStatusBar; StatusBar: TStatusBar;
Notebook: TNotebook; Notebook: TNotebook;
Procedure AddBreakpointClicked(Sender: TObject); procedure AddBreakpointClicked(Sender: TObject);
procedure CompleteCodeMenuItemClick(Sender: TObject); procedure CompleteCodeMenuItemClick(Sender: TObject);
Procedure DeleteBreakpointClicked(Sender: TObject); procedure DeleteBreakpointClicked(Sender: TObject);
procedure EncloseSelectionMenuItemClick(Sender: TObject); procedure EncloseSelectionMenuItemClick(Sender: TObject);
procedure ExtractProcMenuItemClick(Sender: TObject); procedure ExtractProcMenuItemClick(Sender: TObject);
procedure InvertAssignmentMenuItemClick(Sender: TObject); procedure InvertAssignmentMenuItemClick(Sender: TObject);
@ -376,27 +378,30 @@ type
procedure RenameIdentifierMenuItemClick(Sender: TObject); procedure RenameIdentifierMenuItemClick(Sender: TObject);
procedure RunToClicked(Sender: TObject); procedure RunToClicked(Sender: TObject);
procedure ViewCallStackClick(Sender: TObject); procedure ViewCallStackClick(Sender: TObject);
Procedure AddWatchAtCursor(Sender: TObject); procedure AddWatchAtCursor(Sender: TObject);
Procedure BookmarkGoTo(Index: Integer); procedure BookmarkGoTo(Index: Integer);
Procedure BookMarkGotoClicked(Sender: TObject); procedure BookmarkGotoNext(GoForward: boolean);
Procedure BookMarkSet(Value: Integer); procedure BookMarkNextClicked(Sender: TObject);
Procedure BookMarkSetClicked(Sender: TObject); procedure BookMarkPrevClicked(Sender: TObject);
Procedure BookMarkToggle(Value: Integer); procedure BookMarkGotoClicked(Sender: TObject);
procedure BookMarkSet(Value: Integer);
procedure BookMarkSetClicked(Sender: TObject);
procedure BookMarkToggle(Value: Integer);
procedure EditorPropertiesClicked(Sender: TObject); procedure EditorPropertiesClicked(Sender: TObject);
Procedure FindDeclarationClicked(Sender: TObject); procedure FindDeclarationClicked(Sender: TObject);
procedure MoveEditorLeftClicked(Sender: TObject); procedure MoveEditorLeftClicked(Sender: TObject);
procedure MoveEditorRightClicked(Sender: TObject); procedure MoveEditorRightClicked(Sender: TObject);
Procedure NotebookPageChanged(Sender: TObject); procedure NotebookPageChanged(Sender: TObject);
procedure NotebookShowTabHint(Sender: TObject; HintInfo: PHintInfo); procedure NotebookShowTabHint(Sender: TObject; HintInfo: PHintInfo);
Procedure OpenAtCursorClicked(Sender: TObject); procedure OpenAtCursorClicked(Sender: TObject);
Procedure ReadOnlyClicked(Sender: TObject); procedure ReadOnlyClicked(Sender: TObject);
procedure OnPopupMenuOpenPasFile(Sender: TObject); procedure OnPopupMenuOpenPasFile(Sender: TObject);
procedure OnPopupMenuOpenPPFile(Sender: TObject); procedure OnPopupMenuOpenPPFile(Sender: TObject);
procedure OnPopupMenuOpenLFMFile(Sender: TObject); procedure OnPopupMenuOpenLFMFile(Sender: TObject);
procedure OnPopupMenuOpenLRSFile(Sender: TObject); procedure OnPopupMenuOpenLRSFile(Sender: TObject);
Procedure ShowUnitInfo(Sender: TObject); procedure ShowUnitInfo(Sender: TObject);
procedure SrcPopUpMenuPopup(Sender: TObject); procedure SrcPopUpMenuPopup(Sender: TObject);
Procedure ToggleLineNumbersClicked(Sender: TObject); procedure ToggleLineNumbersClicked(Sender: TObject);
private private
fAutoFocusLock: integer; fAutoFocusLock: integer;
FCodeTemplateModul: TSynEditAutoComplete; FCodeTemplateModul: TSynEditAutoComplete;
@ -3303,6 +3308,8 @@ begin
SrcEditSubMenuSetBookmarks.FindByName('SetBookmark'+IntToStr(i)) SrcEditSubMenuSetBookmarks.FindByName('SetBookmark'+IntToStr(i))
.OnClickMethod:=@BookMarkSetClicked; .OnClickMethod:=@BookMarkSetClicked;
end; end;
SrcEditMenuNextBookmark.OnClickMethod:=@NextBookmarkClicked;
SrcEditMenuPrevBookmark.OnClickMethod:=@PrevBookmarkClicked;
SrcEditMenuAddBreakpoint.OnClickMethod:=@AddBreakpointClicked; SrcEditMenuAddBreakpoint.OnClickMethod:=@AddBreakpointClicked;
SrcEditMenuAddWatchAtCursor.OnClickMethod:=@AddWatchAtCursor; SrcEditMenuAddWatchAtCursor.OnClickMethod:=@AddWatchAtCursor;
@ -3408,6 +3415,7 @@ Begin
end; end;
SrcPopupMenu.Items.Add(GotoBookmarkMenuItem); SrcPopupMenu.Items.Add(GotoBookmarkMenuItem);
begin
for I := 0 to 9 do for I := 0 to 9 do
Begin Begin
SubMenuItem := TMenuItem.Create(Self); SubMenuItem := TMenuItem.Create(Self);
@ -3419,6 +3427,23 @@ Begin
GotoBookmarkMenuItem.Add(SubMenuItem); GotoBookmarkMenuItem.Add(SubMenuItem);
end; end;
NextBookmarkMenuItem := TMenuItem.Create(Self);
with NextBookmarkMenuItem do begin
Name:='NextBookmarkMenuItem';
Caption := uemNextBookmark;
OnClick := @BookmarkNextClicked;
end;
GotoBookmarkMenuItem.Add(NextBookmarkMenuItem);
PrevBookmarkMenuItem := TMenuItem.Create(Self);
with PrevBookmarkMenuItem do begin
Name:='PrevBookmarkMenuItem';
Caption := uemPrevBookmark;
OnClick := @BookmarkPrevClicked;
end;
GotoBookmarkMenuItem.Add(PrevBookmarkMenuItem);
end;
SetBookmarkMenuItem := TMenuItem.Create(Self); SetBookmarkMenuItem := TMenuItem.Create(Self);
with SetBookmarkMenuItem do begin with SetBookmarkMenuItem do begin
Name:='SetBookmarkMenuItem'; Name:='SetBookmarkMenuItem';
@ -4581,12 +4606,101 @@ Begin
end; end;
{This is called from outside to set a bookmark} {This is called from outside to set a bookmark}
Procedure TSourceNotebook.SetBookmark(Value: Integer); procedure TSourceNotebook.SetBookmark(Value: Integer);
Begin Begin
BookMarkSet(Value); BookMarkSet(Value);
End; End;
Procedure TSourceNotebook.BookMarkGoto(Index: Integer); procedure TSourceNotebook.BookmarkGotoNext(GoForward: boolean);
var
CurBookmarkID: Integer;
x: Integer;
y: Integer;
SrcEdit: TSourceEditor;
StartY: LongInt;
CurEditorComponent: TSynEdit;
StartEditorComponent: TSynEdit;
BestBookmarkID: Integer;
BestY: Integer;
CurPageIndex: Integer;
CurSrcEdit: TSourceEditor;
StartPageIndex: LongInt;
BetterFound: Boolean;
PageDistance: Integer;
BestPageDistance: Integer;
begin
if Notebook=nil then exit;
SrcEdit:=GetActiveSE;
if SrcEdit=nil then exit;
// init best bookmark
BestBookmarkID:=-1;
BestY:=-1;
BestPageDistance:=-1;
// where is the cursor
StartPageIndex:=Notebook.PageIndex;
StartEditorComponent:=SrcEdit.EditorComponent;
StartY:=StartEditorComponent.CaretY;
// go through all bookmarks
for CurPageIndex:=0 to Notebook.PageCount-1 do begin
CurSrcEdit:=FindSourceEditorWithPageIndex(CurPageIndex);
CurEditorComponent:=CurSrcEdit.EditorComponent;
for CurBookmarkID:=0 to 9 do begin
if CurEditorComponent.GetBookmark(CurBookmarkID,x,y) then begin
if (CurPageIndex=StartPageIndex) and (y=StartY) then
continue;
// for GoForward=true we are searching the nearest bookmark down the
// current page, then the pages from left to right, starting at the
// current page. That means the lines above the cursor are the most
// far away.
// calculate the distance of pages between the current bookmark
// and the current page
PageDistance:=(StartPageIndex-CurPageIndex);
if GoForward then PageDistance:=-PageDistance;
if PageDistance<0 then
// for GoForward=true the pages on the left are farer than the pages
// on the right (and vice versus)
inc(PageDistance,Notebook.PageCount);
if (PageDistance=0) then begin
// for GoForward=true the lines in front are farer than the pages
// on the left side
if (GoForward and (y<StartY))
or ((not GoForward) and (y>StartY)) then
inc(PageDistance,Notebook.PageCount);
end;
BetterFound:=false;
if BestBookmarkID<0 then
BetterFound:=true
else if PageDistance<BestPageDistance then begin
BetterFound:=true;
end else if PageDistance=BestPageDistance then begin
if (GoForward and (y<BestY))
or ((not GoForward) and (y>BestY)) then
BetterFound:=true;
end;
//debugln('TSourceNotebook.BookmarkGotoNext GoForward=',dbgs(GoForward),
// ' CurBookmarkID=',dbgs(CurBookmarkID),
// ' PageDistance=',dbgs(PageDistance),' BestPageDistance='+dbgs(BestPageDistance),
// ' y='+dbgs(y),' BestY='+dbgs(BestY),' StartY=',dbgs(StartY),
// ' StartPageIndex='+dbgs(StartPageIndex),' CurPageIndex='+dbgs(CurPageIndex),
// ' BetterFound='+dbgs(BetterFound));
if BetterFound then begin
// nearer bookmark found
BestBookmarkID:=CurBookmarkID;
BestY:=y;
BestPageDistance:=PageDistance;
end;
end;
end;
end;
if BestBookmarkID>=0 then
BookMarkGoto(BestBookmarkID);
end;
procedure TSourceNotebook.BookMarkGoto(Index: Integer);
var var
AnEditor:TSourceEditor; AnEditor:TSourceEditor;
begin begin
@ -4599,6 +4713,16 @@ begin
end; end;
end; end;
procedure TSourceNotebook.BookMarkNextClicked(Sender: TObject);
begin
BookmarkGotoNext(true);
end;
procedure TSourceNotebook.BookMarkPrevClicked(Sender: TObject);
begin
BookmarkGotoNext(false);
end;
{This is called from outside to Go to a bookmark} {This is called from outside to Go to a bookmark}
Procedure TSourceNotebook.GoToBookmark(Value: Integer); Procedure TSourceNotebook.GoToBookmark(Value: Integer);
begin begin
@ -4947,11 +5071,17 @@ begin
ecToggleObjectInsp: ecToggleObjectInsp:
ToggleObjectInspClicked(Self); ToggleObjectInspClicked(Self);
ecPrevBookmark:
BookmarkGotoNext(false);
ecNextBookmark:
BookmarkGotoNext(true);
ecGotoMarker0..ecGotoMarker9: ecGotoMarker0..ecGotoMarker9:
BookMarkGoto(Command - ecGotoMarker0); BookmarkGoto(Command - ecGotoMarker0);
ecSetMarker0..ecSetMarker9: ecSetMarker0..ecSetMarker9:
BookMarkSet(Command - ecSetMarker0); BookmarkSet(Command - ecSetMarker0);
ecJumpBack: ecJumpBack:
HistoryJump(Self,jhaBack); HistoryJump(Self,jhaBack);