From c30b81fb4841fab6c3361153b904a32ab6f2091d Mon Sep 17 00:00:00 2001 From: mattias Date: Wed, 11 Jun 2008 16:01:49 +0000 Subject: [PATCH] IDE: added jump history from Martin git-svn-id: trunk@15389 - --- .gitattributes | 3 + ide/ideoptiondefs.pas | 6 +- ide/jumphistoryview.lfm | 24 +++++ ide/jumphistoryview.lrs | 10 ++ ide/jumphistoryview.pas | 181 +++++++++++++++++++++++++++++++++++++ ide/main.pp | 94 +++++++++++-------- ide/projectdefs.pas | 44 +++++++-- ide/restrictionbrowser.pas | 2 +- ide/sourceeditor.pp | 2 +- 9 files changed, 315 insertions(+), 51 deletions(-) create mode 100644 ide/jumphistoryview.lfm create mode 100644 ide/jumphistoryview.lrs create mode 100644 ide/jumphistoryview.pas diff --git a/.gitattributes b/.gitattributes index e3f2303143..46b80e9d50 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2091,6 +2091,9 @@ ide/initialsetupdlgs.pas svneol=native#text/pascal ide/inputfiledialog.pas svneol=native#text/pascal ide/inputhistory.pas svneol=native#text/pascal ide/invertassigntool.pas svneol=native#text/pascal +ide/jumphistoryview.lfm svneol=native#text/plain +ide/jumphistoryview.lrs svneol=native#text/plain +ide/jumphistoryview.pas svneol=native#text/plain ide/keymapping.pp svneol=native#text/pascal ide/keymapschemedlg.lfm svneol=native#text/plain ide/keymapschemedlg.lrs svneol=native#text/pascal diff --git a/ide/ideoptiondefs.pas b/ide/ideoptiondefs.pas index 6c57296473..569b5ae24a 100644 --- a/ide/ideoptiondefs.pas +++ b/ide/ideoptiondefs.pas @@ -93,7 +93,8 @@ type nmiwSearchResultsViewName, nmiwAnchorEditor, nmiwCodeBrowser, - mniwIssueBrowser + nmiwIssueBrowser, + nmiwJumpHistory ); const @@ -132,7 +133,8 @@ const 'SearchResults', 'AnchorEditor', 'CodeBrowser', - 'IssueBrowser' + 'IssueBrowser', + 'JumpHistory' ); type diff --git a/ide/jumphistoryview.lfm b/ide/jumphistoryview.lfm new file mode 100644 index 0000000000..1b33e75414 --- /dev/null +++ b/ide/jumphistoryview.lfm @@ -0,0 +1,24 @@ +object JumpHistoryViewWin: TJumpHistoryViewWin + Left = 336 + Height = 426 + Top = 228 + Width = 400 + ActiveControl = listHistory + Caption = 'JumpHistoryViewWin' + ClientHeight = 426 + ClientWidth = 400 + OnCreate = FormCreate + OnDestroy = FormDestroy + ShowHint = True + LCLVersion = '0.9.25' + object listHistory: TListBox + Height = 426 + Width = 400 + Align = alClient + ClickOnSelChange = False + OnClick = listHistoryClick + OnDblClick = listHistoryDblClick + TabOrder = 0 + TopIndex = -1 + end +end diff --git a/ide/jumphistoryview.lrs b/ide/jumphistoryview.lrs new file mode 100644 index 0000000000..276b320f6c --- /dev/null +++ b/ide/jumphistoryview.lrs @@ -0,0 +1,10 @@ +LazarusResources.Add('TJumpHistoryViewWin','FORMDATA',[ + 'TPF0'#19'TJumpHistoryViewWin'#18'JumpHistoryViewWin'#4'Left'#3'P'#1#6'Height' + +#3#170#1#3'Top'#3#228#0#5'Width'#3#144#1#13'ActiveControl'#7#11'listHistory' + +#7'Caption'#6#18'JumpHistoryViewWin'#12'ClientHeight'#3#170#1#11'ClientWidth' + +#3#144#1#8'OnCreate'#7#10'FormCreate'#9'OnDestroy'#7#11'FormDestroy'#8'ShowH' + +'int'#9#10'LCLVersion'#6#6'0.9.25'#0#8'TListBox'#11'listHistory'#6'Height'#3 + +#170#1#5'Width'#3#144#1#5'Align'#7#8'alClient'#16'ClickOnSelChange'#8#7'OnCl' + +'ick'#7#16'listHistoryClick'#10'OnDblClick'#7#19'listHistoryDblClick'#8'TabO' + +'rder'#2#0#8'TopIndex'#2#255#0#0#0 +]); diff --git a/ide/jumphistoryview.pas b/ide/jumphistoryview.pas new file mode 100644 index 0000000000..e67b29357d --- /dev/null +++ b/ide/jumphistoryview.pas @@ -0,0 +1,181 @@ +{ + *************************************************************************** + * * + * This source 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 code 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. * + * * + * A copy of the GNU General Public License is available on the World * + * Wide Web at . You can also * + * obtain it by writing to the Free Software Foundation, * + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * * + *************************************************************************** +} +unit JumpHistoryView; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, LResources, Forms, Controls, StdCtrls, Menus, LCLProc, + CodeToolManager, CodeCache, + IDEOptionDefs, EnvironmentOpts, IDEProcs, LazarusIDEStrConsts, + Project, ProjectDefs; + +type + + { TJumpHistoryViewWin } + + TJumpHistoryViewWin = class(TForm) + listHistory : TListBox; + procedure FormCreate(Sender : TObject); + procedure FormDestroy(Sender : TObject); + procedure listHistoryClick(Sender : TObject); + procedure listHistoryDblClick(Sender : TObject); + procedure OnIdle(Sender : TObject; var Done: Boolean); + private + { private declarations } + fOnSelectionChanged : TNotifyEvent; + fProjectChangeStamp: integer; + function GetSelectedIndex : Integer; + function BeautifyLine(const Filename: string; X, Y: integer; + const Line: string): string; + procedure InitDisplay; + protected + procedure IndexChanged(Sender: TObject; Index: Integer); + procedure ListChanged(Sender: TObject; Index: Integer); + public + { public declarations } + property SelectedIndex : Integer read GetSelectedIndex; + property OnSelectionChanged: TNotifyEvent read fOnSelectionChanged + write fOnSelectionChanged; + end; + +var + JumpHistoryViewWin : TJumpHistoryViewWin = nil; + +implementation + +const + MaxTextLen = 80; + +{ TJumpHistoryViewWin } + +procedure TJumpHistoryViewWin.FormCreate(Sender : TObject); +var + ALayout: TIDEWindowLayout; +begin + Caption := lisMenuViewJumpHistory; + Name := NonModalIDEWindowNames[nmiwJumpHistory]; + ALayout:=EnvironmentOptions.IDEWindowLayoutList. + ItemByEnum(nmiwJumpHistory); + ALayout.Form:=TForm(Self); + ALayout.Apply; + + Application.AddOnIdleHandler(@OnIdle); + + InitDisplay; +end; + +procedure TJumpHistoryViewWin.FormDestroy(Sender : TObject); +begin + +end; + +procedure TJumpHistoryViewWin.listHistoryClick(Sender : TObject); +begin + if EnvironmentOptions.MsgViewDblClickJumps then exit; + if Assigned(fOnSelectionChanged) then fOnSelectionChanged(self); +end; + +procedure TJumpHistoryViewWin.listHistoryDblClick(Sender : TObject); +begin + if not EnvironmentOptions.MsgViewDblClickJumps then exit; + if Assigned(fOnSelectionChanged) then fOnSelectionChanged(self); +end; + +procedure TJumpHistoryViewWin.OnIdle(Sender: TObject; var Done: Boolean); +begin + if (Project1<>nil) + and (Project1.JumpHistory.ChangeStamp<>fProjectChangeStamp) then + InitDisplay; +end; + +function TJumpHistoryViewWin.GetSelectedIndex : Integer; +begin + Result := listHistory.ItemIndex; +end; + +function TJumpHistoryViewWin.BeautifyLine(const Filename : string; X, Y : integer; + const Line : string) : string; +begin + Result:=SpecialCharsToHex(Line); + if UTF8Length(Result)>MaxTextLen then + Result:=UTF8Copy(Result,1,MaxTextLen)+'...'; + Result:=Filename + +' ('+IntToStr(Y) + +','+IntToStr(X)+')' + +' '+Result; +end; + +procedure TJumpHistoryViewWin.InitDisplay; +var + i : integer; + jh_item : TProjectJumpHistoryPosition; + SrcLine: String; + CodeBuf: TCodeBuffer; + Filename: String; +begin + if (Project1<>nil) + and (fProjectChangeStamp=Project1.JumpHistory.ChangeStamp) then exit; + listHistory.Items.BeginUpdate; + listHistory.Clear; + if (Project1<>nil) then begin + fProjectChangeStamp:=Project1.JumpHistory.ChangeStamp; + for i := 0 to Project1.JumpHistory.Count -1 do begin + jh_item := Project1.JumpHistory.Items[i]; + SrcLine:=''; + CodeBuf:=CodeToolBoss.FindFile(jh_item.Filename); + if CodeBuf<>nil then + SrcLine:=CodeBuf.GetLine(jh_item.CaretXY.Y); + Filename:=jh_item.Filename; + if Project1<>nil then + Project1.ShortenFilename(Filename); + listHistory.Items.Append + (BeautifyLine(Filename, + jh_item.CaretXY.X, + jh_item.CaretXY.Y, + SrcLine + ) + ); + end; + DebugLn(['TJumpHistoryViewWin.InitDisplay Project1.JumpHistory.HistoryIndex=',Project1.JumpHistory.HistoryIndex]); + listHistory.ItemIndex := Project1.JumpHistory.HistoryIndex; + end; + listHistory.Items.EndUpdate; +end; + +procedure TJumpHistoryViewWin.IndexChanged(Sender : TObject; Index : Integer); +begin + listHistory.ItemIndex := Project1.JumpHistory.HistoryIndex; +end; + +procedure TJumpHistoryViewWin.ListChanged(Sender : TObject; Index : Integer); +begin + InitDisplay; +end; + + +initialization + {$I jumphistoryview.lrs} + +end. + diff --git a/ide/main.pp b/ide/main.pp index e98af9f085..ad51a1b3e7 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -514,6 +514,9 @@ type // SearchResultsView events procedure SearchResultsViewSelectionChanged(sender: TObject); + // JumpHistoryView events + procedure JumpHistoryViewSelectionChanged(sender: TObject); + // External Tools events procedure OnExtToolNeedsOutputFilter(var OutputFilter: TOutputFilter; var Abort: boolean); @@ -932,7 +935,7 @@ var implementation uses - Math; + Math, JumpHistoryView; var SkipAutoLoadingLastProject: boolean = false; @@ -1236,6 +1239,7 @@ begin TheControlSelection.OnSelectionFormChanged:=nil; end; + FreeAndNil(JumpHistoryViewWin); FreeAndNil(ComponentListForm); FreeThenNil(ProjInspector); FreeThenNil(CodeExplorerView); @@ -12721,6 +12725,13 @@ begin DoJumpToSearchResult(True); end; +procedure TMainIDE.JumpHistoryViewSelectionChanged(sender : TObject); +begin + SourceNotebook.HistoryJump(self, jhaViewWindow); + SourceNoteBook.ShowOnTop; + SourceNotebook.FocusEditor; +end; + Procedure TMainIDE.OnSrcNotebookEditorVisibleChanged(Sender: TObject); var ActiveUnitInfo: TUnitInfo; @@ -13288,41 +13299,40 @@ var DestIndex, UnitIndex: integer; AnUnitInfo: TUnitInfo; DestJumpPoint: TProjectJumpHistoryPosition; CursorPoint, NewJumpPoint: TProjectJumpHistoryPosition; + JumpHistory : TProjectJumpHistory; begin NewPageIndex:=-1; NewCaretXY.Y:=-1; + JumpHistory:=Project1.JumpHistory; {$IFDEF VerboseJumpHistory} writeln(''); writeln('[TMainIDE.OnSrcNotebookJumpToHistoryPoint] A Back=',JumpAction=jhaBack); - Project1.JumpHistory.WriteDebugReport; + JumpHistory.WriteDebugReport; {$ENDIF} // update jump history (e.g. delete jumps to closed editors) - Project1.JumpHistory.DeleteInvalidPositions; + JumpHistory.DeleteInvalidPositions; // get destination jump point - DestIndex:=Project1.JumpHistory.HistoryIndex; - if JumpAction=jhaForward then - inc(DestIndex); - if (DestIndex<0) or (DestIndex>=Project1.JumpHistory.Count) then exit; + DestIndex:=JumpHistory.HistoryIndex; CursorPoint:=nil; - if (SourceNoteBook<>nil) then begin - // get current cursor position - GetCurrentUnit(ASrcEdit,AnUnitInfo); - if (ASrcEdit<>nil) and (AnUnitInfo<>nil) then begin - CursorPoint:=TProjectJumpHistoryPosition.Create(AnUnitInfo.Filename, - ASrcEdit.EditorComponent.LogicalCaretXY, - ASrcEdit.EditorComponent.TopLine); - {$IFDEF VerboseJumpHistory} - writeln(' Current Position: ',CursorPoint.Filename, - ' ',CursorPoint.CaretXY.X,',',CursorPoint.CaretXY.Y); - {$ENDIF} - end; + // get current cursor position + GetCurrentUnit(ASrcEdit,AnUnitInfo); + if (ASrcEdit<>nil) and (AnUnitInfo<>nil) then begin + CursorPoint:=TProjectJumpHistoryPosition.Create + (AnUnitInfo.Filename, + ASrcEdit.EditorComponent.LogicalCaretXY, + ASrcEdit.EditorComponent.TopLine + ); + {$IFDEF VerboseJumpHistory} + writeln(' Current Position: ',CursorPoint.Filename, + ' ',CursorPoint.CaretXY.X,',',CursorPoint.CaretXY.Y-1); + {$ENDIF} end; - if (JumpAction=jhaBack) and (Project1.JumpHistory.Count=DestIndex+1) + if (JumpAction=jhaBack) and (JumpHistory.Count=DestIndex+1) and (CursorPoint<>nil) then begin // this is the first back jump // -> insert current source position into history @@ -13330,16 +13340,19 @@ begin writeln(' First back jump -> add current cursor position'); {$ENDIF} NewJumpPoint:=TProjectJumpHistoryPosition.Create(CursorPoint); - Project1.JumpHistory.InsertSmart(Project1.JumpHistory.HistoryIndex+1, - NewJumpPoint); + JumpHistory.InsertSmart(JumpHistory.HistoryIndex+1, NewJumpPoint); end; // find the next jump point that is not where the cursor is - DestIndex:=Project1.JumpHistory.HistoryIndex; - if JumpAction=jhaForward then - inc(DestIndex); - while (DestIndex>=0) and (DestIndexnil) and (JumpHistory[DestIndex].IsSimilar(CursorPoint)) +// then dec(DestIndex); + jhaViewWindow : DestIndex := JumpHistoryViewWin.SelectedIndex; + end; + + while (DestIndex>=0) and (DestIndex