diff --git a/components/ideintf/idecommands.pas b/components/ideintf/idecommands.pas index dc03bc0aae..510dd6ed2c 100644 --- a/components/ideintf/idecommands.pas +++ b/components/ideintf/idecommands.pas @@ -598,9 +598,9 @@ type TIDECommands = class private FCustomUpdateEvents: TMethodList; - FLateUpdateTimer: TTimer; + FUpdateTimer: TTimer; - procedure FLateUpdateTimerTimer(Sender: TObject); + procedure UpdateTimerTimer(Sender: TObject); protected function GetCategory(Index: integer): TIDECommandCategory; virtual; abstract; public @@ -623,10 +623,11 @@ type IDEWindowClass: TCustomFormClass = nil): TFPList; virtual; abstract; // list of TIDECommand function CategoryCount: integer; virtual; abstract; public - procedure StartUpdateHandler; + procedure StartUpdateTimer; + procedure StopUpdateTimer; procedure ExecuteUpdateEvents; - procedure LateExecuteUpdateEvents; + procedure PostponeUpdateEvents; procedure AddCustomUpdateEvent(const aEvent: TNotifyEvent); procedure RemoveCustomUpdateEvent(const aEvent: TNotifyEvent); @@ -1420,16 +1421,17 @@ begin FCustomUpdateEvents := TMethodList.Create; - //Updating the events needs a lot of CPU power, use TTimer for late updating - FLateUpdateTimer := TTimer.Create(nil); - FLateUpdateTimer.Interval := 800; - FLateUpdateTimer.OnTimer := @FLateUpdateTimerTimer; - FLateUpdateTimer.Enabled := False; + //Updating the commands needs time and CPU power (codetools are called for some commands) + // -> use TTimer with a reasonable interval and not Application.OnIdle + FUpdateTimer := TTimer.Create(nil); + FUpdateTimer.Interval := 500; + FUpdateTimer.OnTimer := @UpdateTimerTimer; + FUpdateTimer.Enabled := False; end; destructor TIDECommands.Destroy; begin - FLateUpdateTimer.Free; + FUpdateTimer.Free; FCustomUpdateEvents.Free; inherited Destroy; end; @@ -1450,16 +1452,18 @@ begin Categories[i].DoOnUpdate; end; -procedure TIDECommands.FLateUpdateTimerTimer(Sender: TObject); +procedure TIDECommands.UpdateTimerTimer(Sender: TObject); begin ExecuteUpdateEvents; - FLateUpdateTimer.Enabled := False; end; -procedure TIDECommands.LateExecuteUpdateEvents; +procedure TIDECommands.PostponeUpdateEvents; begin - FLateUpdateTimer.Enabled := False; - FLateUpdateTimer.Enabled := True; + if FUpdateTimer.Enabled then + begin + FUpdateTimer.Enabled := False; + FUpdateTimer.Enabled := True; + end; end; procedure TIDECommands.RemoveCustomUpdateEvent(const aEvent: TNotifyEvent); @@ -1467,9 +1471,14 @@ begin FCustomUpdateEvents.Remove(TMethod(aEvent)); end; -procedure TIDECommands.StartUpdateHandler; +procedure TIDECommands.StartUpdateTimer; begin - FLateUpdateTimer.Enabled := True; + FUpdateTimer.Enabled := True; +end; + +procedure TIDECommands.StopUpdateTimer; +begin + FUpdateTimer.Enabled := False; end; { TIDESpecialCommand } diff --git a/ide/main.pp b/ide/main.pp index f0ef60c765..ec87fec926 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -1577,7 +1577,7 @@ begin MainIDEBar.ApplicationIsActivate:=true; IDECommandList.AddCustomUpdateEvent(@UpdateMainIDECommands); LazIDEInstances.StartListening(@LazInstancesStartNewInstance); - IDECommandList.StartUpdateHandler; + IDECommandList.StartUpdateTimer; FIDEStarted:=true; {$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.StartIDE END');{$ENDIF} end; @@ -1973,6 +1973,7 @@ procedure TMainIDE.MainIDEFormClose(Sender: TObject; var CloseAction: TCloseAction); begin LazIDEInstances.StopServer; + IDECommandList.StopUpdateTimer; DoCallNotifyHandler(lihtIDEClose); SaveEnvironment(true); if IDEDockMaster<>nil then diff --git a/ide/sourceeditor.pp b/ide/sourceeditor.pp index 20982f8fab..5ab3b3d6f4 100644 --- a/ide/sourceeditor.pp +++ b/ide/sourceeditor.pp @@ -5247,7 +5247,7 @@ begin // can trigger the old editor to be refocused (while not visible) end; - IDECommandList.LateExecuteUpdateEvents; + IDECommandList.ExecuteUpdateEvents; end; procedure TSourceEditor.EditorActivateSyncro(Sender: TObject); @@ -5334,12 +5334,15 @@ begin // debugln('MouseMove in Editor',X,',',Y); if Assigned(OnMouseMove) then OnMouseMove(Self,Shift,X,Y); + if Shift*[ssLeft,ssRight]<>[] then + IDECommandList.PostponeUpdateEvents; end; procedure TSourceEditor.EditorMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin - IDECommandList.LateExecuteUpdateEvents; + if Button=mbLeft then + IDECommandList.ExecuteUpdateEvents; end; procedure TSourceEditor.EditorMouseWheel(Sender: TObject; Shift: TShiftState; @@ -5366,7 +5369,7 @@ begin if Assigned(OnKeyDown) then OnKeyDown(Sender, Key, Shift); - IDECommandList.LateExecuteUpdateEvents; + IDECommandList.PostponeUpdateEvents; end; procedure TSourceEditor.EditorKeyUp(Sender: TObject; var Key: Word; @@ -5376,7 +5379,7 @@ begin if Assigned(OnKeyUp) then OnKeyUp(Sender, Key, Shift); - IDECommandList.LateExecuteUpdateEvents; + IDECommandList.PostponeUpdateEvents; end; {-------------------------------------------------------------------------------