Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Jun 10, 2023
1 parent 4070286 commit f8f51fb
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 134 deletions.
49 changes: 18 additions & 31 deletions Source/codetools/simba.ide_codetools_insight.pas
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ interface

type
{$SCOPEDENUMS ON}
EParseExpressionFlag = (WantVarType, WantMethodResult);
EParseExpressionFlag = (
WantVarType, // if found decl is a variable, return the variables type
WantMethodResult // if found decl is a function, return the result type
);
EParseExpressionFlags = set of EParseExpressionFlag;
{$SCOPEDENUMS OFF}

Expand Down Expand Up @@ -350,6 +353,7 @@ function TCodeinsight.GetMembersOfType(Decl: TDeclaration): TDeclarationArray;
begin
Result := nil;

Decl := EnsureTypeDeclaration(Decl);
if (Decl is TDeclaration_TypeEnum) then
begin
Result := TDeclaration_TypeEnum(Decl).Elements;
Expand Down Expand Up @@ -427,36 +431,15 @@ function TCodeinsight.ParseExpression(Expr: TExpressionItems; Flags: EParseExpre
if Decl.IsName(Expr.Text) then
begin
if (Decl is TDeclaration_Var) and (TDeclaration_Var(Decl).VarType <> nil) then
begin
Result := EnsureTypeDeclaration(TDeclaration_Var(Decl).VarType);
Exit;
end;

if (Decl is TDeclaration_Method) then
begin
if Expr.IsLastItem then
begin
case (EParseExpressionFlag.WantMethodResult in Flags) of
True:
if (TDeclaration_Method(Decl).ResultType <> nil) then
begin
Result := EnsureTypeDeclaration(TDeclaration_Method(Decl).ResultType);
Exit;
end;
False:
begin
Result := Decl;
Exit;
end;
end;
end;

if (TDeclaration_Method(Decl).ResultType <> nil) then
begin
Result := EnsureTypeDeclaration(TDeclaration_Method(Decl).ResultType);
Exit;
end;
end;
Result := EnsureTypeDeclaration(TDeclaration_Var(Decl).VarType)
else
if Expr.IsLastItem then
Result := Decl
else
if (Decl is TDeclaration_Method) and Assigned(TDeclaration_Method(Decl).ResultType) then
Result := EnsureTypeDeclaration(TDeclaration_Method(Decl).ResultType);

Exit;
end;
end;

Expand Down Expand Up @@ -527,6 +510,10 @@ function TCodeinsight.ParseExpression(Expr: TExpressionItems; Flags: EParseExpre
end;

Result := Decl;

if (EParseExpressionFlag.WantMethodResult in Flags) then
if (Result is TDeclaration_Method) and Assigned(TDeclaration_Method(Result).ResultType) then
Result := EnsureTypeDeclaration(TDeclaration_Method(Result).ResultType);
end;

function TCodeinsight.ParseExpression(Expr: String; Flags: EParseExpressionFlags): TDeclaration;
Expand Down
8 changes: 5 additions & 3 deletions Source/codetools/simba.ide_codetools_parser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ procedure TCodeParser.FindLocals;

procedure CheckMethod(Decl: TDeclaration);
var
SelfDecl, ResultDecl: TDeclaration;
SelfDecl, ResultDecl, ParamListDecl: TDeclaration;
begin
if (Decl = nil) then
Exit;
Expand Down Expand Up @@ -1212,8 +1212,10 @@ procedure TCodeParser.FindLocals;
FLocals.Extend(Decl.Items.GetByClass(TDeclaration_Const, True));
FLocals.Extend(Decl.Items.GetByClass(TDeclaration_Type));
FLocals.Extend(Decl.Items.GetByClass(TDeclaration_EnumElement));
if (FItems.GetByClassEx(TDeclaration_ParamList) <> nil) then
FLocals.Extend(FItems.GetByClassEx(TDeclaration_ParamList).Items.GetByClass(TDeclaration_Parameter, False, True));

ParamListDecl := FItems.GetByClassEx(TDeclaration_ParamList, True, True);
if Assigned(ParamListDecl) then
FLocals.Extend(ParamListDecl.Items.GetByClass(TDeclaration_Parameter, False, True));

Decl := Decl.GetOwnerByClass(TDeclaration_Method);
end;
Expand Down
76 changes: 52 additions & 24 deletions Source/components/simba.component_button.pas
Original file line number Diff line number Diff line change
Expand Up @@ -19,65 +19,93 @@ TSimbaButton = class(TSpeedButton)
procedure PaintBackground(var PaintRect: TRect); override;
public
VertPadding: Integer;
Olly: Boolean;

constructor Create(AOwner: TComponent; LCLGlyphName: String); overload;
constructor Create(AOwner: TComponent); override;

procedure SetCloseGlyph;
procedure SetClearFilterGlyph;
end;

TSimbaToggleButton = class(TSimbaButton)
public
constructor Create(AOwner: TComponent); override;
end;

TSimbaTransparentButton = class(TSimbaButton)
protected
procedure PaintBackground(var PaintRect: TRect); override;
public
constructor Create(AOwner: TComponent); override;
end;

implementation

uses
simba.theme;
simba.theme,
ATCanvasPrimitives;

procedure TSimbaButton.CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean);
procedure TSimbaTransparentButton.PaintBackground(var PaintRect: TRect);
begin
inherited CalculatePreferredSize(PreferredWidth, PreferredHeight, WithThemeSpace);
if Down or MouseInClient then
Canvas.Brush.Color := SimbaTheme.ColorActive
else
Canvas.Brush.Color := Color;

PreferredWidth += VertPadding*2;
Canvas.FillRect(PaintRect);
if Down or MouseInClient then
CanvasPaintRoundedCorners(Canvas, PaintRect, [acckLeftTop, acckRightTop, acckLeftBottom, acckRightBottom], Color, Canvas.Brush.Color, Canvas.Brush.Color);
end;

procedure TSimbaButton.PaintBackground(var PaintRect: TRect);
constructor TSimbaTransparentButton.Create(AOwner: TComponent);
begin
if Olly then
begin
if Down or MouseInClient then
Canvas.Brush.Color := SimbaTheme.ColorActive
else
Canvas.Brush.Color := SimbaTheme.ColorBackground;
inherited Create(AOwner);

Canvas.FillRect(PaintRect);
ParentColor := True;
end;

Exit;
end;
procedure TSimbaButton.CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean);
begin
inherited CalculatePreferredSize(PreferredWidth, PreferredHeight, WithThemeSpace);

Canvas.FillRect(PaintRect);
Canvas.Pen.Color := SimbaTheme.ColorFrame;
PreferredWidth += VertPadding * 2;
end;

procedure TSimbaButton.PaintBackground(var PaintRect: TRect);
begin
if Down or MouseInClient then
Canvas.Brush.Color := SimbaTheme.ColorActive
else
Canvas.Brush.Color := SimbaTheme.ColorScrollBarActive;
Canvas.Brush.Color := SimbaTheme.ColorBackground;

Canvas.RoundRect(PaintRect, Width div 5, Width div 5);
Canvas.FillRect(PaintRect);
CanvasPaintRoundedCorners(Canvas, PaintRect, [acckLeftTop, acckRightTop, acckLeftBottom, acckRightBottom], SimbaTheme.ColorFrame, Canvas.Brush.Color, Canvas.Brush.Color);
end;

constructor TSimbaButton.Create(AOwner: TComponent; LCLGlyphName: String);
constructor TSimbaButton.Create(AOwner: TComponent);
begin
inherited Create(Owner);
inherited Create(AOwner);

AutoSize := True;

VertPadding := 5;
end;

ButtonGlyph.LCLGlyphName := LCLGlyphName;
procedure TSimbaButton.SetCloseGlyph;
begin
ButtonGlyph.LCLGlyphName := 'btn_cancel';
end;

procedure TSimbaButton.SetClearFilterGlyph;
begin
ButtonGlyph.LCLGlyphName := 'btnfiltercancel';
end;

constructor TSimbaToggleButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);

AllowAllUp := True;
GroupIndex := 1+AOwner.ComponentCount;
GroupIndex := 1 + AOwner.ComponentCount;

Font.Color := SimbaTheme.ColorFont;
end;
Expand Down
19 changes: 15 additions & 4 deletions Source/components/simba.component_edit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ TSimbaEdit = class(TCustomControl)
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;

procedure ParentFontChanged; override;

procedure FontChanged(Sender: TObject); override;
procedure TextChanged; override;
procedure Paint; override;
Expand Down Expand Up @@ -368,6 +370,19 @@ procedure TSimbaEdit.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Int
FSelectingEndX := CharIndexAtXY(X, Y);
end;

procedure TSimbaEdit.ParentFontChanged;
begin
inherited ParentFontChanged;

if Assigned(Parent) then
begin
Font.BeginUpdate();
Font := Parent.Font;
Font.Color := SimbaTheme.ColorFont;
Font.EndUpdate();
end;
end;

procedure TSimbaEdit.SetCaretPos(Pos: Integer);
begin
if (Pos < 0) then
Expand All @@ -387,8 +402,6 @@ procedure TSimbaEdit.FontChanged(Sender: TObject);
begin
inherited FontChanged(Sender);

Font.Color := SimbaTheme.ColorFont;

NewHeight := CalculateHeight();

Constraints.MinHeight := NewHeight;
Expand Down Expand Up @@ -644,8 +657,6 @@ constructor TSimbaEdit.Create(AOwner: TComponent);
HintTextStyle := [fsItalic];
HintTextColor := cl3DDkShadow;

Font.Color := SimbaTheme.ColorFont;

Color := SimbaTheme.ColorBackground;
ColorSelection := SimbaTheme.ColorActive;
ColorBorder := SimbaTheme.ColorFrame;
Expand Down
14 changes: 3 additions & 11 deletions Source/components/simba.component_treeview.pas
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ TSimbaTreeView = class(TCustomControl)

procedure ScrollHorzChange(Sender: TObject);
procedure ScrollVertChange(Sender: TObject);
procedure DoScrollBarVertResize(Sender: TObject);
public
constructor Create(AOwner: TComponent; NodeClass: TTreeNodeClass = nil); reintroduce;

Expand Down Expand Up @@ -123,7 +122,7 @@ TSimbaTreeView = class(TCustomControl)
implementation

uses
Math, EditBtn, simba.theme;
Math, simba.theme;

constructor TSimbaTreeView.Create(AOwner: TComponent; NodeClass: TTreeNodeClass);
var
Expand All @@ -145,7 +144,6 @@ constructor TSimbaTreeView.Create(AOwner: TComponent; NodeClass: TTreeNodeClass)
FScrollbarVert.Align := alRight;
FScrollbarVert.OnChange := @ScrollVertChange;
FScrollbarVert.Visible := True;
FScrollbarVert.OnResize := @DoScrollBarVertResize;

FScrollbarHorz := TSimbaScrollBar.Create(Self);
FScrollbarHorz.Parent := test;
Expand Down Expand Up @@ -196,15 +194,14 @@ constructor TSimbaTreeView.Create(AOwner: TComponent; NodeClass: TTreeNodeClass)
FFilterEdit.HintTextColor := clLtGray;
FFilterEdit.HintText := '(search)';

FFilterClearButton := TSimbaButton.Create(Self, ResBtnListFilter);
FFilterClearButton := TSimbaTransparentButton.Create(Self);
FFilterClearButton.Parent := FFilterPanel;
FFilterClearButton.Align := alRight;
FFilterClearButton.AutoSize := True;
FFilterClearButton.VertPadding := 4;
FFilterClearButton.Olly := True;
FFilterClearButton.OnClick := @DoClearFilterClick;
FFilterClearButton.Hint := 'Clear Filter';
FFilterClearButton.ShowHint := True;
FFilterClearButton.SetClearFilterGlyph();
end;

procedure TSimbaTreeView.FullCollapse;
Expand Down Expand Up @@ -456,11 +453,6 @@ procedure TSimbaTreeView.ScrollVertChange(Sender: TObject);
FTree.ScrolledTop := FScrollbarVert.Position;
end;

procedure TSimbaTreeView.DoScrollBarVertResize(Sender: TObject);
begin
FFilterClearButton.BorderSpacing.Right := FScrollbarVert.Width;
end;

procedure TSimbaTreeView.ScrollHorzChange(Sender: TObject);
begin
FTree.ScrolledLeft := FScrollbarHorz.Position;
Expand Down
11 changes: 6 additions & 5 deletions Source/editor/simba.editor_autocomplete.pas
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
interface

uses
Classes, SysUtils, Graphics, StdCtrls, Controls, Forms, LCLType, Types, ATScrollBar,
Classes, SysUtils, Graphics, StdCtrls, Controls, Forms, LCLType, Types,
SynEdit, SynEditTypes, SynCompletion, SynEditKeyCmds, SynEditHighlighter,
simba.mufasatypes, simba.ide_codetools_parser, simba.ide_codetools_insight;
simba.mufasatypes, simba.ide_codetools_parser, simba.ide_codetools_insight,
simba.component_scrollbar;

type
TSimbaAutoCompleteSizeDrag = class(TSynBaseCompletionFormSizeDrag)
Expand All @@ -24,7 +25,7 @@ TSimbaAutoCompleteSizeDrag = class(TSynBaseCompletionFormSizeDrag)
TSimbaAutoComplete = class;
TSimbaAutoComplete_Form = class(TSynCompletionForm)
protected
RealScroll: TATScrollbar;
RealScroll: TSimbaScrollBar;

procedure DoPaintSizeDrag(Sender: TObject);
procedure DoScrollChange(Sender: TObject);
Expand Down Expand Up @@ -286,12 +287,12 @@ constructor TSimbaAutoComplete_Form.Create(AOwner: TComponent);

Scroll.Width := 0;

RealScroll := TATScrollbar.Create(Self);
RealScroll := TSimbaScrollBar.Create(Self);
RealScroll.Parent := Self;
RealScroll.Kind := sbVertical;
RealScroll.OnEnter := @ScrollGetFocus;
RealScroll.OnChange := @DoScrollChange;
RealScroll.Anchors := [akTop,akRight, akBottom];
RealScroll.Anchors := [akTop, akRight, akBottom];
RealScroll.AnchorSide[akTop].Side := asrTop;
RealScroll.AnchorSide[akTop].Control := self;
RealScroll.AnchorSide[akRight].Side := asrBottom;
Expand Down
8 changes: 7 additions & 1 deletion Source/forms/simba.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,11 @@ procedure TSimbaForm.Setup(Data: PtrInt);
SimbaSettingChanged(SimbaSettings.General.LockLayout);
SimbaSettingChanged(SimbaSettings.General.TrayIconVisible);
SimbaSettingChanged(SimbaSettings.General.ConsoleVisible);

// Finally, give the editor focus as default.
if Assigned(SimbaScriptTabsForm.CurrentEditor) then
if SimbaScriptTabsForm.CurrentEditor.CanSetFocus() then
SimbaScriptTabsForm.CurrentEditor.SetFocus();
end;

procedure TSimbaForm.FormCreate(Sender: TObject);
Expand Down Expand Up @@ -684,7 +689,8 @@ procedure TSimbaForm.FormShortCut(var Msg: TLMKey; var Handled: Boolean);
begin
Handled := MainMenuFile.IsShortcut(Msg) or MainMenuView.IsShortcut(Msg) or
MainMenuEdit.IsShortcut(Msg) or MainMenuScript.IsShortcut(Msg) or
MainMenuTools.IsShortcut(Msg) or MainMenuHelp.IsShortcut(Msg);
MainMenuTools.IsShortcut(Msg) or MainMenuHelp.IsShortcut(Msg) or
(KeyDataToShiftState(Msg.KeyData) = [ssAlt]); // Suppress windows freaking out
end;

procedure TSimbaForm.MenuItemDocumentationClick(Sender: TObject);
Expand Down

0 comments on commit f8f51fb

Please sign in to comment.