Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions client/source/DelphiLint.Context.pas
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ TLinePaintContext = record
procedure OnLineChanged(OldLine: Integer; NewLine: Integer; Data: Integer);
end;

IIDEThemeChangeHandler = interface(IIDEHandler)
['{677285CF-D165-4CA1-9565-FECA44CF9748}']
procedure OnThemeChanged;
end;

IIDEEditLineTracker = interface
['{0E41ADA7-FE27-42BD-8153-EBBF96260385}']
function GetFileName: string;
Expand All @@ -211,6 +216,8 @@ TLinePaintContext = record
procedure RegisterFormClass(FormClass: TCustomFormClass);
function GetStyleColor(Color: TStyleColor): TColor;
function GetSystemColor(Color: TColor): TColor;
function AddThemeChangeNotifier(Notifier: IIDEThemeChangeHandler): Integer;
procedure RemoveThemeChangeNotifier(const Index: Integer);

// From IOTAServices
function GetRootDirectory: string;
Expand Down
27 changes: 27 additions & 0 deletions client/source/DelphiLint.Handlers.pas
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ TEditLineHandler = class(THandler, IIDEEditLineHandler)
procedure OnLineChanged(OldLine: Integer; NewLine: Integer; Data: Integer);
end;

//______________________________________________________________________________________________________________________

TOnThemeChanged = reference to procedure;

TThemeChangeHandler = class(THandler, IIDEThemeChangeHandler)
private
FOnThemeChanged: TOnThemeChanged;
public
constructor Create(OnThemeChanged: TOnThemeChanged);
procedure OnThemeChanged;
end;

//______________________________________________________________________________________________________________________

TLineTracker = class;
Expand Down Expand Up @@ -290,6 +302,21 @@ procedure TEditLineHandler.OnLineChanged(OldLine: Integer; NewLine: Integer; Dat

//______________________________________________________________________________________________________________________

constructor TThemeChangeHandler.Create(OnThemeChanged: TOnThemeChanged);
begin
inherited Create;
FOnThemeChanged := OnThemeChanged;
end;

//______________________________________________________________________________________________________________________

procedure TThemeChangeHandler.OnThemeChanged;
begin
FOnThemeChanged;
end;

//______________________________________________________________________________________________________________________

constructor TEditorHandler.Create;
begin
inherited;
Expand Down
35 changes: 35 additions & 0 deletions client/source/DelphiLint.IDEContext.pas
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ TToolsApiServices = class(TInterfacedObject, IIDEServices)
procedure RegisterFormClass(FormClass: TCustomFormClass);
function GetStyleColor(Color: TStyleColor): TColor;
function GetSystemColor(Color: TColor): TColor;
function AddThemeChangeNotifier(Notifier: IIDEThemeChangeHandler): Integer;
procedure RemoveThemeChangeNotifier(const Index: Integer);

// From IOTAServices
function GetRootDirectory: string;
Expand Down Expand Up @@ -240,6 +242,11 @@ TToolsApiEditLineNotifier = class(TToolsApiNotifier<IIDEEditLineHandler>, IOTA
procedure LineChanged(OldLine: Integer; NewLine: Integer; Data: Integer);
end;

TToolsApiThemeNotifier = class(TToolsApiNotifier<IIDEThemeChangeHandler>, INTAIDEThemingServicesNotifier)
procedure ChangingTheme;
procedure ChangedTheme;
end;

//______________________________________________________________________________________________________________________

procedure Register;
Expand Down Expand Up @@ -378,6 +385,20 @@ function TToolsApiServices.GetSystemColor(Color: TColor): TColor;

//______________________________________________________________________________________________________________________

function TToolsApiServices.AddThemeChangeNotifier(Notifier: IIDEThemeChangeHandler): Integer;
begin
Result := (BorlandIDEServices as IOTAIDEThemingServices).AddNotifier(TToolsApiThemeNotifier.Create(Notifier));
end;

//______________________________________________________________________________________________________________________

procedure TToolsApiServices.RemoveThemeChangeNotifier(const Index: Integer);
begin
(BorlandIDEServices as IOTAIDEThemingServices).RemoveNotifier(Index);
end;

//______________________________________________________________________________________________________________________

function TToolsApiServices.GetRootDirectory: string;
begin
Result := (BorlandIDEServices as IOTAServices).GetRootDirectory;
Expand Down Expand Up @@ -968,6 +989,20 @@ procedure TToolsApiEditLineNotifier.LineChanged(OldLine: Integer; NewLine: Integ
FHandler.OnLineChanged(OldLine, NewLine, Data);
end;

//______________________________________________________________________________________________________________________

procedure TToolsApiThemeNotifier.ChangingTheme;
begin
// Only theme changes that have completed are relevant
end;

//______________________________________________________________________________________________________________________

procedure TToolsApiThemeNotifier.ChangedTheme;
begin
FHandler.OnThemeChanged;
end;

initialization
SetLogger(BuildDelphiLintFileLogger);
SetLintContext(TIDELintContext.Create);
Expand Down
15 changes: 15 additions & 0 deletions client/source/DelphiLint.Plugin.pas
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ TPluginCore = class(TDataModule)
private
FEditor: TEditorHandler;
FEditorNotifier: Integer;
FThemeNotifier: Integer;
FActionListIndex: Integer;
FMainMenu: TMenuItem;
FAnalysisActionsEnabled: Boolean;
Expand All @@ -75,6 +76,7 @@ TPluginCore = class(TDataModule)

procedure OnAnalysisStateChanged(const StateChange: TAnalysisStateChangeContext);
procedure OnActiveFileChanged(const Path: string);
procedure OnThemeChanged;

procedure SetAnalysisActionsEnabled(Value: Boolean);

Expand Down Expand Up @@ -321,6 +323,9 @@ procedure TPluginCore.OnRegister;
FEditorNotifier := LintContext.IDEServices.AddEditorNotifier(FEditor);
FEditor.OnActiveFileChanged.AddListener(OnActiveFileChanged);

// Theme change notifier
FThemeNotifier := LintContext.IDEServices.AddThemeChangeNotifier(TThemeChangeHandler.Create(OnThemeChanged));

// Main menu
FActionListIndex := LintContext.IDEServices.AddActionListToIDEInsight(LintActions);
CreateMainMenu;
Expand Down Expand Up @@ -360,6 +365,7 @@ procedure TPluginCore.OnDeregister(IDEServices: IIDEServices);
RemoveToolbarActions(IDEServices);
FreeAndNil(FMainMenu);
IDEServices.RemoveEditorNotifier(FEditorNotifier);
IDEServices.RemoveThemeChangeNotifier(FThemeNotifier);
IDEServices.UnregisterDockableForm(FToolFormInfo);
IDEServices.RemovePluginInfo(FInfoIndex);
IDEServices.UnregisterAddInOptions(FAddInOptions);
Expand All @@ -375,6 +381,15 @@ procedure TPluginCore.OnAnalysisStateChanged(const StateChange: TAnalysisStateCh

//______________________________________________________________________________________________________________________

procedure TPluginCore.OnThemeChanged;
begin
if Assigned(FToolForm) then begin
LintContext.IDEServices.ApplyTheme(FToolForm);
end;
end;

//______________________________________________________________________________________________________________________

procedure TPluginCore.CreateMainMenu;

procedure AddItem(Action: TAction);
Expand Down
23 changes: 23 additions & 0 deletions client/test/DelphiLintTest.MockContext.pas
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ TMockIDE = class(TObject)
FActions: TList<TCustomAction>;
FIDEInsightActions: TList<TCustomActionList>;
FEditorNotifiers: TDictionary<Integer, IIDEEditorHandler>;
FThemeChangeNotifiers: TDictionary<Integer, IIDEThemeChangeHandler>;
FMenus: TDictionary<string, TMenuItem>;
FPluginInfos: TObjectDictionary<Integer, TMockPluginInfo>;
FPluginTitle: string;
Expand All @@ -264,6 +265,7 @@ TMockIDE = class(TObject)
property Actions: TList<TCustomAction> read FActions;
property IDEInsightActions: TList<TCustomActionList> read FIDEInsightActions;
property EditorNotifiers: TDictionary<Integer, IIDEEditorHandler> read FEditorNotifiers;
property ThemeChangeNotifiers: TDictionary<Integer, IIDEThemeChangeHandler> read FThemeChangeNotifiers;
property Menus: TDictionary<string, TMenuItem> read FMenus;
property PluginInfos: TObjectDictionary<Integer, TMockPluginInfo> read FPluginInfos;

Expand Down Expand Up @@ -307,6 +309,8 @@ TMockIDEServices = class(THookedObject<TIDEServicesCallType>, IIDEServices)
procedure RegisterFormClass(FormClass: TCustomFormClass);
function GetStyleColor(Color: TStyleColor): TColor;
function GetSystemColor(Color: TColor): TColor;
function AddThemeChangeNotifier(Notifier: IIDEThemeChangeHandler): Integer;
procedure RemoveThemeChangeNotifier(const Index: Integer);

// From IOTAServices
function GetRootDirectory: string;
Expand Down Expand Up @@ -928,6 +932,23 @@ function TMockIDEServices.AddEditorNotifier(Notifier: IIDEEditorHandler): Intege

//______________________________________________________________________________________________________________________

function TMockIDEServices.AddThemeChangeNotifier(Notifier: IIDEThemeChangeHandler): Integer;
begin
Result := FNextId;
Inc(FNextId);

FIDE.ThemeChangeNotifiers.Add(Result, Notifier);
end;

//______________________________________________________________________________________________________________________

procedure TMockIDEServices.RemoveThemeChangeNotifier(const Index: Integer);
begin
FIDE.ThemeChangeNotifiers.Remove(Index);
end;

//______________________________________________________________________________________________________________________

function TMockIDEServices.AddImages(const ImageList: TImageList): Integer;
begin
// TODO apply image list to mock IDE
Expand Down Expand Up @@ -1160,6 +1181,7 @@ constructor TMockIDE.Create;
FActions := TList<TCustomAction>.Create;
FIDEInsightActions := TList<TCustomActionList>.Create;
FEditorNotifiers := TDictionary<Integer, IIDEEditorHandler>.Create;
FThemeChangeNotifiers := TDictionary<Integer, IIDEThemeChangeHandler>.Create;
FMenus := TDictionary<string, TMenuItem>.Create;
FPluginInfos := TObjectDictionary<Integer, TMockPluginInfo>.Create([doOwnsValues]);
end;
Expand All @@ -1171,6 +1193,7 @@ destructor TMockIDE.Destroy;
FreeAndNil(FActions);
FreeAndNil(FIDEInsightActions);
FreeAndNil(FEditorNotifiers);
FreeAndNil(FThemeChangeNotifiers);
FreeAndNil(FMenus);
FreeAndNil(FPluginInfos);
FreeAndNil(FPluginIcon);
Expand Down