ADD: Viewer - go to line command (code viewer mode)

This commit is contained in:
Alexander Koblov 2023-04-05 22:42:00 +03:00
commit ddfb4d6559
3 changed files with 34 additions and 0 deletions

View file

@ -1307,6 +1307,9 @@ object frmViewer: TfrmViewer
object miSearchPrev: TMenuItem
Action = actFindPrev
end
object miGotoLine: TMenuItem
Action = actGotoLine
end
end
object miView: TMenuItem
Caption = '&View'
@ -1710,6 +1713,12 @@ object frmViewer: TfrmViewer
Caption = 'Find previous'
OnExecute = actExecute
end
object actGotoLine: TAction
Category = 'Edit'
Caption = 'Goto Line...'
Hint = 'Goto Line'
OnExecute = actExecute
end
object actChangeEncoding: TAction
Caption = 'Change encoding'
OnExecute = actExecute

View file

@ -75,6 +75,8 @@
{"hash":315460,"name":"tfrmviewer.actfind.caption","sourcebytes":[70,105,110,100],"value":"Find"},
{"hash":73859572,"name":"tfrmviewer.actfindnext.caption","sourcebytes":[70,105,110,100,32,110,101,120,116],"value":"Find next"},
{"hash":97034739,"name":"tfrmviewer.actfindprev.caption","sourcebytes":[70,105,110,100,32,112,114,101,118,105,111,117,115],"value":"Find previous"},
{"hash":102945374,"name":"tfrmviewer.actgotoline.caption","sourcebytes":[71,111,116,111,32,76,105,110,101,46,46,46],"value":"Goto Line..."},
{"hash":185950757,"name":"tfrmviewer.actgotoline.hint","sourcebytes":[71,111,116,111,32,76,105,110,101],"value":"Goto Line"},
{"hash":216568103,"name":"tfrmviewer.actchangeencoding.caption","sourcebytes":[67,104,97,110,103,101,32,101,110,99,111,100,105,110,103],"value":"Change encoding"},
{"hash":96796260,"name":"tfrmviewer.actautoreload.caption","sourcebytes":[65,117,116,111,32,82,101,108,111,97,100],"value":"Auto Reload"},
{"hash":216689422,"name":"tfrmviewer.actprintsetup.caption","sourcebytes":[80,114,105,110,116,32,38,115,101,116,117,112,46,46,46],"value":"Print &setup..."},

View file

@ -123,6 +123,7 @@ type
actShowAsBin: TAction;
actShowAsText: TAction;
actPreview: TAction;
actGotoLine: TAction;
actFindPrev: TAction;
actFind: TAction;
actSelectAll: TAction;
@ -178,6 +179,7 @@ type
mi270: TMenuItem;
mi180: TMenuItem;
mi90: TMenuItem;
miGotoLine: TMenuItem;
miSearchPrev: TMenuItem;
miPrint: TMenuItem;
miSearchNext: TMenuItem;
@ -465,6 +467,7 @@ type
procedure cm_Find (const Params: array of string);
procedure cm_FindNext (const Params: array of string);
procedure cm_FindPrev (const Params: array of string);
procedure cm_GotoLine (const Params: array of string);
procedure cm_Preview (const Params: array of string);
procedure cm_ShowAsText (const Params: array of string);
@ -3094,9 +3097,11 @@ begin
miStretchOnlyLarge.Visible := bImage;
end;
actGotoLine.Enabled := (Panel = pnlCode);
actShowCaret.Enabled := (Panel = pnlText);
actWrapText.Enabled := bPlugin or ((Panel = pnlText) and (ViewerControl.Mode in [vcmText, vcmWrap]));
miGotoLine.Visible := (Panel = pnlCode);
pmiSelectAll.Visible := (Panel = pnlText) or (Panel = pnlCode);
pmiCopyFormatted.Visible := (Panel = pnlText);
@ -3519,6 +3524,24 @@ begin
end;
end;
procedure TfrmViewer.cm_GotoLine(const Params: array of string);
var
P: TPoint;
Value: String;
NewTopLine: Integer;
begin
if ShowInputQuery(rsEditGotoLineTitle, rsEditGotoLineQuery, Value) then
begin
P.X := 1;
P.Y := StrToIntDef(Value, 1);
NewTopLine := P.Y - (SynEdit.LinesInWindow div 2);
if NewTopLine < 1 then NewTopLine:= 1;
SynEdit.CaretXY := P;
SynEdit.TopLine := NewTopLine;
SynEdit.SetFocus;
end;
end;
procedure TfrmViewer.cm_Preview(const Params: array of string);
begin
miPreview.Checked:= not (miPreview.Checked);