From b83d624eee43a6dfba50ecc4a51d32d452479e1a Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 28 Oct 2024 14:07:55 +0100 Subject: [PATCH] IDE: Custom IDE title, added preview --- ide/frames/window_options.lfm | 51 +++++++++++++++++++++++++++++++++ ide/frames/window_options.pas | 54 ++++++++++++++++++++++++++++++++--- ide/main.pp | 12 ++++---- 3 files changed, 107 insertions(+), 10 deletions(-) diff --git a/ide/frames/window_options.lfm b/ide/frames/window_options.lfm index d80aeeafdd..d857e2d85a 100644 --- a/ide/frames/window_options.lfm +++ b/ide/frames/window_options.lfm @@ -158,5 +158,56 @@ object WindowOptionsFrame: TWindowOptionsFrame ParentShowHint = False ShowHint = True TabOrder = 7 + OnChange = EdTitleBarChange + end + object lbTitlePreviewHeader: TLabel + AnchorSideLeft.Control = EdTitleBar + AnchorSideTop.Control = EdTitleBar + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = Owner + AnchorSideRight.Side = asrBottom + Left = 0 + Height = 15 + Top = 216 + Width = 573 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Top = 10 + Caption = 'lbTitlePreviewHeader' + end + object pnlTitlePreview: TPanel + AnchorSideLeft.Control = Owner + AnchorSideTop.Control = lbTitlePreviewHeader + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = Owner + AnchorSideRight.Side = asrBottom + Left = 0 + Height = 25 + Top = 231 + Width = 573 + Anchors = [akTop, akLeft, akRight] + AutoSize = True + BevelInner = bvRaised + BevelOuter = bvLowered + ClientHeight = 25 + ClientWidth = 573 + Color = clWindow + ParentBackground = False + ParentColor = False + TabOrder = 8 + object lbTitlePreview: TLabel + AnchorSideLeft.Control = pnlTitlePreview + AnchorSideTop.Control = pnlTitlePreview + AnchorSideRight.Control = pnlTitlePreview + AnchorSideRight.Side = asrBottom + Left = 5 + Height = 15 + Top = 5 + Width = 563 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Around = 3 + Caption = 'lbTitlePreview' + Transparent = False + WordWrap = True + end end end diff --git a/ide/frames/window_options.pas b/ide/frames/window_options.pas index cc29237044..c1a284cb20 100644 --- a/ide/frames/window_options.pas +++ b/ide/frames/window_options.pas @@ -27,15 +27,15 @@ interface uses SysUtils, // LCL - Forms, StdCtrls, InterfaceBase, + Forms, StdCtrls, InterfaceBase, ExtCtrls, Controls, // LazControls DividerBevel, // IdeIntf - IDEOptionsIntf, IDEOptEditorIntf, + IDEOptionsIntf, IDEOptEditorIntf, LazStringUtils, // IdeConfig - EnvironmentOpts, + EnvironmentOpts, LazConf, TransferMacros, // IDE - LazarusIDEStrConsts, EnvGuiOptions; + LazarusIDEStrConsts, EnvGuiOptions, Classes; type { TWindowOptionsFrame } @@ -44,7 +44,10 @@ type AutoAdjustIDEHeightFullCompPalCheckBox: TCheckBox; bvWindowTitle: TDividerBevel; EdTitleBar: TComboBox; + lbTitlePreviewHeader: TLabel; + lbTitlePreview: TLabel; lblTitleBar: TLabel; + pnlTitlePreview: TPanel; ProjectInspectorShowPropsCheckBox: TCheckBox; lblShowingWindows: TDividerBevel; NameForDesignedFormListCheckBox: TCheckBox; @@ -52,6 +55,7 @@ type HideIDEOnRunCheckBox: TCheckBox; SingleTaskBarButtonCheckBox: TCheckBox; TitleStartsWithProjectCheckBox: TCheckBox; + procedure EdTitleBarChange(Sender: TObject); public function GetTitle: String; override; procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override; @@ -66,6 +70,44 @@ implementation { TWindowOptionsFrame } +procedure TWindowOptionsFrame.EdTitleBarChange(Sender: TObject); + function AddToCaption(const CurrentCaption, CaptAddition: string): String; + begin + if TitleStartsWithProjectCheckBox.Checked then + Result := CaptAddition + ' - ' + CurrentCaption + else + Result := CurrentCaption + ' - ' + CaptAddition; + end; + +var + rev, NewCaption: String; + CustomCaption: TCaption; + OldMarkUnhandledMacros: Boolean; +begin + if GlobalMacroList = nil then + exit; + + rev := LazarusRevisionStr; + if IsNumber(rev) then + NewCaption := Format(lisLazarusEditorV + ' r%s', + [LazarusVersionStr, rev]) + else + NewCaption := Format(lisLazarusEditorV, [LazarusVersionStr]); + + CustomCaption := EdTitleBar.Text; + if CustomCaption <> '' then begin + OldMarkUnhandledMacros := GlobalMacroList.MarkUnhandledMacros; + GlobalMacroList.MarkUnhandledMacros := false; + GlobalMacroList.SubstituteStr(CustomCaption, 0, 0, True); + if CustomCaption <> '' then begin + NewCaption := AddToCaption(NewCaption, CustomCaption); + end; + GlobalMacroList.MarkUnhandledMacros := OldMarkUnhandledMacros; + end; + + lbTitlePreview.Caption := NewCaption; +end; + function TWindowOptionsFrame.GetTitle: String; begin Result := dlgWindow; @@ -93,6 +135,9 @@ begin AutoAdjustIDEHeightFullCompPalCheckBox.Caption:=lisAutoAdjustIDEHeightFullComponentPalette; AutoAdjustIDEHeightFullCompPalCheckBox.Hint:=lisAutoAdjustIDEHeightFullComponentPaletteHint; ProjectInspectorShowPropsCheckBox.Caption:=lisProjectInspectorShowProps; + lbTitlePreviewHeader.Caption := dlgWRDPreview; + lbTitlePreviewHeader.Visible := GlobalMacroList <> nil; + pnlTitlePreview.Visible := GlobalMacroList <> nil; EdTitleBar.AddItem('$project(TitleNew)', nil); EdTitleBar.AddItem('$project(TitleNew) $EncloseBracket($project(infodir))', nil); @@ -125,6 +170,7 @@ begin AutoAdjustIDEHeightFullCompPalCheckBox.Checked := AutoAdjustIDEHeightFullCompPal; ProjectInspectorShowPropsCheckBox.Checked := ProjectInspectorShowProps; end; + EdTitleBarChange(nil); end; procedure TWindowOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions); diff --git a/ide/main.pp b/ide/main.pp index 489be26cdc..52aeb182e0 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -9022,7 +9022,7 @@ procedure TMainIDE.UpdateCaption; end; var - rev, NewCaption, DirName, CustomnCaption: String; + rev, NewCaption, DirName, CustomCaption: String; OldMarkUnhandledMacros: boolean; begin if MainIDEBar = nil then Exit; @@ -9037,13 +9037,13 @@ begin NewCaption := AddToCaption(NewCaption, MainBarSubTitle); if (GlobalMacroList <> nil) then begin - CustomnCaption := EnvironmentGuiOpts.Desktop.IDETitleBarCustomText; - if CustomnCaption <> '' then begin + CustomCaption := EnvironmentGuiOpts.Desktop.IDETitleBarCustomText; + if CustomCaption <> '' then begin OldMarkUnhandledMacros := GlobalMacroList.MarkUnhandledMacros; GlobalMacroList.MarkUnhandledMacros := false; - GlobalMacroList.SubstituteStr(CustomnCaption, 0, 0, True); - if CustomnCaption <> '' then begin - NewCaption := AddToCaption(NewCaption, CustomnCaption); + GlobalMacroList.SubstituteStr(CustomCaption, 0, 0, True); + if CustomCaption <> '' then begin + NewCaption := AddToCaption(NewCaption, CustomCaption); end; GlobalMacroList.MarkUnhandledMacros := OldMarkUnhandledMacros; end;