From: Erik B. <eb...@us...> - 2006-09-06 07:53:36
|
Update of /cvsroot/gexperts/gexperts/unstable/Src In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv504/Src Modified Files: GX_IdeShortCuts.pas Log Message: Reinit the shortcuts on process debug state and active project change notifications This seems to fix most missed IDE shortcut changes except for manual desktop changes Index: GX_IdeShortCuts.pas =================================================================== RCS file: /cvsroot/gexperts/gexperts/unstable/Src/GX_IdeShortCuts.pas,v retrieving revision 1.41 retrieving revision 1.42 diff -u -d -r1.41 -r1.42 --- GX_IdeShortCuts.pas 10 Jul 2006 21:20:37 -0000 1.41 +++ GX_IdeShortCuts.pas 6 Sep 2006 07:53:34 -0000 1.42 @@ -47,13 +47,18 @@ private FOldShortCuts: TStringList; FPackageNotifier: TBaseIdeNotifier; + FUpdateTimer: TTimer; + FUpdateCount: Integer; + FProcessNotifier: TBaseDebuggerNotifier; + procedure OnUpdateTimer(Sender: TObject); procedure ReadFromRegistryIDE; procedure ResetShortCuts; procedure InitializeShortCutExpert; procedure FinalizeShortCutExpert; protected procedure SetActive(New: Boolean); override; + procedure QueueReinitializeShortcuts; public destructor Destroy; override; function GetActionCaption: string; override; @@ -75,9 +80,6 @@ TPackageLoadingNotifier = class(TBaseIdeNotifier) private FShortCutExpert: TShortCutExpert; - FUpdateTimer: TTimer; - FUpdateCount: Integer; - procedure OnUpdateTimer(Sender: TObject); public procedure FileNotification(NotifyCode: TOTAFileNotification; const FileName: string; var Cancel: Boolean); override; @@ -85,6 +87,16 @@ destructor Destroy; override; end; + TProcessNotifier = class(TBaseDebuggerNotifier) + private + FShortCutExpert: TShortCutExpert; + public + constructor Create(const AClient: TShortCutExpert); + procedure ProcessCreated({$IFDEF GX_VER170_up} const {$ENDIF} Process: IOTAProcess); override; + procedure ProcessDestroyed({$IFDEF GX_VER170_up} const {$ENDIF} Process: IOTAProcess); override; + destructor Destroy; override; + end; + function FindMenuByName(AMenuItem: TMenuItem; const Name: string): TMenuItem; var j: Integer; @@ -421,15 +433,22 @@ begin FinalizeShortCutExpert; - inherited Destroy; + inherited; end; procedure TShortCutExpert.FinalizeShortCutExpert; begin + if Assigned(FUpdateTimer) then + FUpdateTimer.Enabled := False; + FreeAndNil(FUpdateTimer); if Assigned(FPackageNotifier) then FPackageNotifier.RemoveNotifierFromIDE; + if Assigned(FProcessNotifier) then + FProcessNotifier.RemoveNotifierFromIDE; + // The IDE destroys the notifier for us (tested in D5/D7) FPackageNotifier := nil; + FProcessNotifier := nil; // Restore old shortcut settings ResetShortCuts; @@ -465,6 +484,23 @@ FPackageNotifier := TPackageLoadingNotifier.Create(Self); FPackageNotifier.AddNotifierToIDE; + + FProcessNotifier := TProcessNotifier.Create(Self); + FProcessNotifier.AddNotifierToIDE; + + FUpdateTimer := TTimer.Create(nil); + FUpdateTimer.Enabled := False; + FUpdateTimer.Interval := 5000; + FUpdateTimer.OnTimer := OnUpdateTimer; +end; + +procedure TShortCutExpert.QueueReinitializeShortcuts; +begin + // Restart the timer delay before updating the shortcuts. + // This prevents us from updating constantly during startup, etc. + FUpdateTimer.Enabled := False; + FUpdateCount := 0; + FUpdateTimer.Enabled := True; end; // Read shortcut settings from the registry and apply to the menu @@ -574,6 +610,18 @@ end; end; +procedure TShortCutExpert.OnUpdateTimer(Sender: TObject); +begin + Inc(FUpdateCount); + {$IFOPT D+} SendDebug('IDE shortcut update timer expired, calling ReadFromRegistryIDE. Update Count: ' + IntToStr(FUpdateCount)); {$ENDIF} + if FUpdateCount >= 3 then + FUpdateTimer.Enabled := False; + if Application.Terminated then + Exit; + ReadFromRegistryIDE; + {$IFOPT D+} SendDebug('Done processing IDE shortcut updates'); {$ENDIF} +end; + { TPackageLoadingNotifier } constructor TPackageLoadingNotifier.Create(const AClient: TShortCutExpert); @@ -582,47 +630,22 @@ Assert(Assigned(AClient)); FShortCutExpert := AClient; - FUpdateTimer := TTimer.Create(nil); - FUpdateTimer.Enabled := False; - FUpdateTimer.Interval := 5000; - FUpdateTimer.OnTimer := OnUpdateTimer; end; destructor TPackageLoadingNotifier.Destroy; begin - if Assigned(FUpdateTimer) then - FUpdateTimer.Enabled := False; - FreeAndNil(FUpdateTimer); FShortCutExpert.FPackageNotifier := nil; - inherited Destroy; + inherited; end; procedure TPackageLoadingNotifier.FileNotification(NotifyCode: TOTAFileNotification; const FileName: string; var Cancel: Boolean); begin // Re-assign shortcuts if a package (which may contain - // experts with hotkeys) has been loaded. - // No need to detect unload - we are not interested in what's vanishing - if NotifyCode = ofnPackageInstalled then - begin - // Restart the timer delay before updating the shortcuts. - // This prevents us from updating constantly during startup, etc. - FUpdateTimer.Enabled := False; - FUpdateCount := 0; - FUpdateTimer.Enabled := True; - end; -end; - -procedure TPackageLoadingNotifier.OnUpdateTimer(Sender: TObject); -begin - Inc(FUpdateCount); - {$IFOPT D+} SendDebug('IDE shortcut update timer expired, calling ReadFromRegistryIDE. Update Count: ' + IntToStr(FUpdateCount)); {$ENDIF} - if FUpdateCount >= 3 then - FUpdateTimer.Enabled := False; - if Application.Terminated then - Exit; - FShortCutExpert.ReadFromRegistryIDE; - {$IFOPT D+} SendDebug('Done processing IDE shortcut updates'); {$ENDIF} + // experts with hotkeys) or project has been loaded. BDS 2006 resets shortcuts + // in lots of situations, but this detects most of them. + if NotifyCode in [ofnPackageInstalled, ofnActiveProjectChanged] then + FShortCutExpert.QueueReinitializeShortcuts; end; procedure TfmIdeShortCuts.FormCreate(Sender: TObject); @@ -639,6 +662,33 @@ lblShortCut.FocusControl := hkShortCut; end; +{ TProcessNotifier } + +constructor TProcessNotifier.Create(const AClient: TShortCutExpert); +begin + inherited Create; + Assert(Assigned(AClient)); + FShortCutExpert := AClient; +end; + +destructor TProcessNotifier.Destroy; +begin + FShortCutExpert.FProcessNotifier := nil; + inherited; +end; + +procedure TProcessNotifier.ProcessCreated({$IFDEF GX_VER170_up} const {$ENDIF} Process: IOTAProcess); +begin + inherited; + FShortCutExpert.QueueReinitializeShortcuts; +end; + +procedure TProcessNotifier.ProcessDestroyed({$IFDEF GX_VER170_up} const {$ENDIF} Process: IOTAProcess); +begin + inherited; + FShortCutExpert.QueueReinitializeShortcuts; +end; + initialization RegisterGX_Expert(TShortCutExpert); |