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

@ -181,6 +181,10 @@ const
ecGotoEditor8 = ecGotoEditor7 + 1;
ecGotoEditor9 = ecGotoEditor8 + 1;
ecGotoEditor0 = ecGotoEditor9 + 1;
// marker
ecPrevBookmark = ecUserFirst + 381;
ecNextBookmark = ecUserFirst + 382;
// compile menu
ecBuild = ecUserFirst + 400;
@ -550,6 +554,8 @@ begin
ecOpenFileAtCursor: SetResult(VK_RETURN,[ssCtrl],VK_UNKNOWN,[]);
// marker
ecPrevBookmark: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecNextBookmark: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecGotoMarker0: SetResult(VK_0,[ssCtrl],VK_UNKNOWN,[]);
ecGotoMarker1: SetResult(VK_1,[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,[]);
// marker
ecPrevBookmark: SetResult(VK_UNKNOWN,[],VK_UNKNOWN,[]);
ecNextBookmark: SetResult(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,[]);
ecGotoMarker2: SetResult(VK_Q,[ssCtrl],VK_2,[],VK_UNKNOWN,[],VK_UNKNOWN,[]);
@ -1390,7 +1398,8 @@ begin
ecColumnSelect : Result:= srkmecColumnSelect;
ecLineSelect : Result:= srkmecLineSelect;
ecAutoCompletion : Result:= srkmecAutoCompletion;
ecUserFirst : Result:= srkmecUserFirst;
ecUserFirst : Result:= srkmecPrevBookmark;
ecPrevBookmark : Result:= srkmecNextBookmark;
ecGotoMarker0 ..
ecGotoMarker9 : Result:= Format(srkmecGotoMarker,[cmd-ecGotoMarker0]);
ecSetMarker0 ..
@ -2313,6 +2322,8 @@ begin
// marker - without menu items in the IDE bar
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 1',ecGotoMarker1);
AddDefault(C,'Go to marker 2',ecGotoMarker2);

View File

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

View File

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

View File

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

View File

@ -350,6 +350,8 @@ type
CopyMenuItem: TMenuItem;
PasteMenuItem: TMenuItem;
GotoBookmarkMenuItem: TMenuItem;
NextBookmarkMenuItem: TMenuItem;
PrevBookmarkMenuItem: TMenuItem;
MoveEditorLeftMenuItem: TMenuItem;
MoveEditorRightMenuItem: TMenuItem;
OpenFileAtCursorMenuItem: TMenuItem;
@ -366,9 +368,9 @@ type
SrcPopUpMenu: TPopupMenu;
StatusBar: TStatusBar;
Notebook: TNotebook;
Procedure AddBreakpointClicked(Sender: TObject);
procedure AddBreakpointClicked(Sender: TObject);
procedure CompleteCodeMenuItemClick(Sender: TObject);
Procedure DeleteBreakpointClicked(Sender: TObject);
procedure DeleteBreakpointClicked(Sender: TObject);
procedure EncloseSelectionMenuItemClick(Sender: TObject);
procedure ExtractProcMenuItemClick(Sender: TObject);
procedure InvertAssignmentMenuItemClick(Sender: TObject);
@ -376,27 +378,30 @@ type
procedure RenameIdentifierMenuItemClick(Sender: TObject);
procedure RunToClicked(Sender: TObject);
procedure ViewCallStackClick(Sender: TObject);
Procedure AddWatchAtCursor(Sender: TObject);
Procedure BookmarkGoTo(Index: Integer);
Procedure BookMarkGotoClicked(Sender: TObject);
Procedure BookMarkSet(Value: Integer);
Procedure BookMarkSetClicked(Sender: TObject);
Procedure BookMarkToggle(Value: Integer);
procedure AddWatchAtCursor(Sender: TObject);
procedure BookmarkGoTo(Index: Integer);
procedure BookmarkGotoNext(GoForward: boolean);
procedure BookMarkNextClicked(Sender: TObject);
procedure BookMarkPrevClicked(Sender: TObject);
procedure BookMarkGotoClicked(Sender: TObject);
procedure BookMarkSet(Value: Integer);
procedure BookMarkSetClicked(Sender: TObject);
procedure BookMarkToggle(Value: Integer);
procedure EditorPropertiesClicked(Sender: TObject);
Procedure FindDeclarationClicked(Sender: TObject);
procedure FindDeclarationClicked(Sender: TObject);
procedure MoveEditorLeftClicked(Sender: TObject);
procedure MoveEditorRightClicked(Sender: TObject);
Procedure NotebookPageChanged(Sender: TObject);
procedure NotebookPageChanged(Sender: TObject);
procedure NotebookShowTabHint(Sender: TObject; HintInfo: PHintInfo);
Procedure OpenAtCursorClicked(Sender: TObject);
Procedure ReadOnlyClicked(Sender: TObject);
procedure OpenAtCursorClicked(Sender: TObject);
procedure ReadOnlyClicked(Sender: TObject);
procedure OnPopupMenuOpenPasFile(Sender: TObject);
procedure OnPopupMenuOpenPPFile(Sender: TObject);
procedure OnPopupMenuOpenLFMFile(Sender: TObject);
procedure OnPopupMenuOpenLRSFile(Sender: TObject);
Procedure ShowUnitInfo(Sender: TObject);
procedure ShowUnitInfo(Sender: TObject);
procedure SrcPopUpMenuPopup(Sender: TObject);
Procedure ToggleLineNumbersClicked(Sender: TObject);
procedure ToggleLineNumbersClicked(Sender: TObject);
private
fAutoFocusLock: integer;
FCodeTemplateModul: TSynEditAutoComplete;
@ -3303,6 +3308,8 @@ begin
SrcEditSubMenuSetBookmarks.FindByName('SetBookmark'+IntToStr(i))
.OnClickMethod:=@BookMarkSetClicked;
end;
SrcEditMenuNextBookmark.OnClickMethod:=@NextBookmarkClicked;
SrcEditMenuPrevBookmark.OnClickMethod:=@PrevBookmarkClicked;
SrcEditMenuAddBreakpoint.OnClickMethod:=@AddBreakpointClicked;
SrcEditMenuAddWatchAtCursor.OnClickMethod:=@AddWatchAtCursor;
@ -3408,7 +3415,8 @@ Begin
end;
SrcPopupMenu.Items.Add(GotoBookmarkMenuItem);
for I := 0 to 9 do
begin
for I := 0 to 9 do
Begin
SubMenuItem := TMenuItem.Create(Self);
with SubmenuItem do begin
@ -3419,6 +3427,23 @@ Begin
GotoBookmarkMenuItem.Add(SubMenuItem);
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);
with SetBookmarkMenuItem do begin
Name:='SetBookmarkMenuItem';
@ -4581,12 +4606,101 @@ Begin
end;
{This is called from outside to set a bookmark}
Procedure TSourceNotebook.SetBookmark(Value: Integer);
procedure TSourceNotebook.SetBookmark(Value: Integer);
Begin
BookMarkSet(Value);
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
AnEditor:TSourceEditor;
begin
@ -4599,6 +4713,16 @@ begin
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}
Procedure TSourceNotebook.GoToBookmark(Value: Integer);
begin
@ -4946,12 +5070,18 @@ begin
ecToggleObjectInsp:
ToggleObjectInspClicked(Self);
ecPrevBookmark:
BookmarkGotoNext(false);
ecNextBookmark:
BookmarkGotoNext(true);
ecGotoMarker0..ecGotoMarker9:
BookMarkGoto(Command - ecGotoMarker0);
BookmarkGoto(Command - ecGotoMarker0);
ecSetMarker0..ecSetMarker9:
BookMarkSet(Command - ecSetMarker0);
BookmarkSet(Command - ecSetMarker0);
ecJumpBack:
HistoryJump(Self,jhaBack);