From fcc0fe6d11432df824f387deb3f8fe88152bca0b Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 29 Sep 2024 21:12:41 +0200 Subject: [PATCH] IDE: SourceEditor, show selection mode indicator. Issue #40599 --- components/synedit/synedit.pp | 7 +++++++ ide/lazarusidestrconsts.pas | 3 +++ ide/sourceeditor.lfm | 6 ++++-- ide/sourceeditor.pp | 31 ++++++++++++++++++++++++++----- 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/components/synedit/synedit.pp b/components/synedit/synedit.pp index 9d05f3ae2b..6fdd05bb7e 100644 --- a/components/synedit/synedit.pp +++ b/components/synedit/synedit.pp @@ -608,6 +608,7 @@ type FPendingFoldState: String; procedure DoTopViewChanged(Sender: TObject); + function GetIsStickySelecting: Boolean; procedure SetScrollOnEditLeftOptions(AValue: TSynScrollOnEditOptions); procedure SetScrollOnEditRightOptions(AValue: TSynScrollOnEditOptions); procedure SetTabViewClass(AValue: TSynEditStringTabExpanderClass); @@ -1169,6 +1170,7 @@ type // Selection property DefaultSelectionMode: TSynSelectionMode read GetDefSelectionMode write SetDefSelectionMode default smNormal; property SelectionMode: TSynSelectionMode read GetSelectionMode write SetSelectionMode default smNormal; + property IsStickySelecting: Boolean read GetIsStickySelecting; // Cursor procedure UpdateCursorOverride; override; @@ -2173,6 +2175,11 @@ begin FTextArea.TheLinesView := FTheLinesView; end; +function TCustomSynEdit.GetIsStickySelecting: Boolean; +begin + Result := FBlockSelection.StickyAutoExtend; +end; + procedure TCustomSynEdit.SetScrollOnEditLeftOptions( AValue: TSynScrollOnEditOptions); begin diff --git a/ide/lazarusidestrconsts.pas b/ide/lazarusidestrconsts.pas index d86472c79f..2df03c10ef 100644 --- a/ide/lazarusidestrconsts.pas +++ b/ide/lazarusidestrconsts.pas @@ -2917,6 +2917,9 @@ resourcestring uepReadonly= 'Readonly'; uepIns='INS'; uepOvr='OVR'; + uepSelNorm='Def'; + uepSelLine='Line'; + uepSelCol ='Col'; lisUEFontWith = 'Font without UTF-8'; lisUETheCurre = 'The current editor font does not support UTF-8 but your system seems to use it.' +'%sThat means non ASCII characters will probably be shown incorrectly.' diff --git a/ide/sourceeditor.lfm b/ide/sourceeditor.lfm index f77259b899..dae3134079 100644 --- a/ide/sourceeditor.lfm +++ b/ide/sourceeditor.lfm @@ -7,9 +7,9 @@ object SourceNotebook: TSourceNotebook Caption = 'SourceNotebook' ClientHeight = 300 ClientWidth = 400 + LCLVersion = '3.99.0.0' OnMouseUp = FormMouseUp OnResize = FormResize - LCLVersion = '2.3.0.0' object StatusBar: TStatusBar Left = 0 Height = 23 @@ -30,7 +30,9 @@ object SourceNotebook: TSourceNotebook Width = 50 end item - Text = 'INS' + Width = 0 + end + item Width = 50 end> SimpleText = 'This is a test' diff --git a/ide/sourceeditor.pp b/ide/sourceeditor.pp index 2eff61b34a..dff61a068b 100644 --- a/ide/sourceeditor.pp +++ b/ide/sourceeditor.pp @@ -4448,6 +4448,9 @@ begin end; end; + ecStickySelection, ecStickySelectionCol, ecStickySelectionLine: + FSourceNoteBook.UpdateStatusBar; + else begin Handled:=false; @@ -8713,6 +8716,7 @@ procedure TSourceNotebook.StatusBarDrawPanel(AStatusBar: TStatusBar; APanel: TSt const ARect: TRect); var pnl: TSourceEditorStatusPanel; + cl: TColor; begin if APanel = StatusBar.Panels[1] then begin IDEImages.Images_16.ResolutionForControl[16, AStatusBar] @@ -8934,7 +8938,7 @@ end; procedure TSourceNotebook.OpenFolderMenuItemClick(Sender: TObject); begin - OpenDocument(ExtractFilePath(Statusbar.Panels[4].Text)); + OpenDocument(ExtractFilePath(Statusbar.Panels[5].Text)); end; procedure TSourceNotebook.ExecuteEditorItemClick(Sender: TObject); @@ -8964,9 +8968,9 @@ begin end; W := 0; for i := 0 to StatusBar.Panels.Count - 1 do - if i <> 4 then + if i <> 5 then w := w + StatusBar.Panels[i].Width; - StatusBar.Panels[4].Width := Max(150, StatusBar.Width - W); + StatusBar.Panels[5].Width := Max(150, StatusBar.Width - W); finally StatusBar.EndUpdate; end; @@ -9146,7 +9150,7 @@ var PanelFilename: String; PanelCharMode: string; PanelXY: string; - PanelFileMode: string; + PanelFileMode, PanelSelMode: string; CurEditor: TSynEdit; begin if FUpdateLock > 0 then begin @@ -9219,6 +9223,18 @@ begin PanelFileMode := PanelFileMode + ueLocked; end; + PanelSelMode := ''; + case CurEditor.SelectionMode of + smNormal: if CurEditor.IsStickySelecting or CurEditor.SelAvail then + PanelSelMode := uepSelNorm; + smLine: PanelSelMode := uepSelLine; + smColumn: PanelSelMode := uepSelCol; + end; + if (PanelSelMode<>'') and not CurEditor.SelAvail then + PanelSelMode := '('+PanelSelMode+')'; + if CurEditor.IsStickySelecting then + PanelSelMode := '* '+PanelSelMode; + PanelXY := Format(' %6d:%4d', [TempEditor.CurrentCursorYLine,TempEditor.CurrentCursorXLine]); @@ -9230,7 +9246,12 @@ begin Statusbar.Panels[0].Text := PanelXY; StatusBar.Panels[2].Text := PanelFileMode; Statusbar.Panels[3].Text := PanelCharMode; - Statusbar.Panels[4].Text := PanelFilename; + Statusbar.Panels[4].Text := PanelSelMode; + if PanelSelMode = '' then + Statusbar.Panels[4].Width := 0 + else + Statusbar.Panels[4].Width := 50; + Statusbar.Panels[5].Text := PanelFilename; if(EditorMacroForRecording.IsRecording(CurEditor)) then Statusbar.Panels[1].Width := IDEImages.ScaledSize(20) else