From 5ec7988f47c558b747a11a14f776b215e805d006 Mon Sep 17 00:00:00 2001 From: ondrej Date: Fri, 23 Oct 2015 17:04:26 +0000 Subject: [PATCH] IDE: IDECommand update events refactored: delete timer, use checks for command updates, add TIDESpecialCommand.OnRequestCaptionHint git-svn-id: trunk@50152 - --- components/ideintf/idecommands.pas | 114 +++++-- components/ideintf/menuintf.pas | 1 + components/ideintf/toolbarintf.pas | 11 +- ide/main.pp | 506 +++++++++++++++++++++-------- ide/sourceeditor.pp | 306 ++++------------- ide/sourcesyneditor.pas | 6 + packager/packagesystem.pas | 17 + 7 files changed, 559 insertions(+), 402 deletions(-) diff --git a/components/ideintf/idecommands.pas b/components/ideintf/idecommands.pas index 85b8fac5ec..04d2c69f95 100644 --- a/components/ideintf/idecommands.pas +++ b/components/ideintf/idecommands.pas @@ -548,6 +548,9 @@ type function GetUserCount: Integer; procedure SetOnExecute(const aOnExecute: TNotifyEvent); procedure SetOnExecuteProc(const aOnExecuteProc: TNotifyProcedure); + procedure SetEnabled(const AEnabled: Boolean); + procedure SetVisible(const AVisible: Boolean); + procedure SetCaption(const ACaption: string); protected function GetLocalizedName: string; virtual; procedure SetLocalizedName(const AValue: string); virtual; @@ -579,6 +582,10 @@ type procedure UserRemoved(const aUser: TIDESpecialCommand); procedure DoOnUpdate; overload; procedure DoOnUpdate(Sender: TObject); overload; + public + property Enabled: Boolean write SetEnabled; + property Visible: Boolean write SetVisible; + property Caption: string write SetCaption; public property Name: String read FName; property Command: word read FCommand;// see the ecXXX constants above @@ -601,9 +608,9 @@ type TIDECommands = class private FCustomUpdateEvents: TMethodList; - FUpdateTimer: TTimer; + FDontExecuteUpdateEventsUntil: Integer; - procedure UpdateTimerTimer(Sender: TObject); + procedure ApplicationOnIdle({%H-}Sender: TObject; var {%H-}Done: Boolean); protected function GetCategory(Index: integer): TIDECommandCategory; virtual; abstract; public @@ -626,10 +633,11 @@ type IDEWindowClass: TCustomFormClass = nil): TFPList; virtual; abstract; // list of TIDECommand function CategoryCount: integer; virtual; abstract; public - procedure StartUpdateTimer; - procedure StopUpdateTimer; + procedure StartUpdateEvents; + procedure StopUpdateEvents; procedure ExecuteUpdateEvents; + procedure CancelPostponeUpdateEvents; procedure PostponeUpdateEvents; procedure AddCustomUpdateEvent(const aEvent: TNotifyEvent); @@ -640,6 +648,8 @@ type // MenuItem and ButtonCommand inherit from SpecialCommand. + TGetHintCaptionEvent = procedure(Sender: TObject; var ACaption, AHint: string) of object; + TIDESpecialCommand = class(TPersistent) private FCommand: TIDECommand; @@ -651,6 +661,7 @@ type FImageIndex: Integer; FOnClickMethod: TNotifyEvent; FOnClickProc: TNotifyProcedure; + FOnRequestCaption: TGetHintCaptionEvent; FVisible: Boolean; protected function GetCaption: string; virtual; @@ -664,6 +675,8 @@ type procedure SetVisible(const aVisible: Boolean); virtual; procedure SetOnClickMethod(const aOnClick: TNotifyEvent); virtual; procedure SetOnClickProc(const aOnClickProc: TNotifyProcedure); virtual; + procedure SetOnRequestCaption( + const aOnRequestCaptionHint: TGetHintCaptionEvent); virtual; procedure SetResourceName(const aResourceName: string); virtual; procedure ShortCutsUpdated(const {%H-}aShortCut, {%H-}aShortCutKey2: TShortCut); virtual; public @@ -672,6 +685,7 @@ type public procedure DoOnClick; overload; procedure DoOnClick(Sender: TObject); virtual; overload; + function DoOnRequestCaption(Sender: TObject): Boolean; virtual; public function GetCaptionWithShortCut: String; virtual; function GetHintOrCaptionWithShortCut: String; virtual; @@ -689,6 +703,7 @@ type property OnClick: TNotifyEvent read FOnClickMethod write SetOnClickMethod; property OnClickProc: TNotifyProcedure read FOnClickProc write SetOnClickProc; + property OnRequestCaptionHint: TGetHintCaptionEvent read FOnRequestCaption write SetOnRequestCaption; end; TIDESpecialCommandEnumerator = class @@ -1208,6 +1223,14 @@ begin Change; end; +procedure TIDECommand.SetVisible(const AVisible: Boolean); +var + xUser: TIDESpecialCommand; +begin + for xUser in FUsers do + xUser.Visible := AVisible; +end; + procedure TIDECommand.UserAdded(const aUser: TIDESpecialCommand); begin FUsers.Add(aUser); @@ -1294,6 +1317,14 @@ begin Change; end; +procedure TIDECommand.SetEnabled(const AEnabled: Boolean); +var + xUser: TIDESpecialCommand; +begin + for xUser in FUsers do + xUser.Enabled := AEnabled; +end; + function TIDECommand.AsShortCut: TShortCut; var CurKey: TIDEShortCut; @@ -1381,6 +1412,14 @@ begin and (CompareIDEShortCuts(@FShortcutB,@ACommand.FShortcutB)=0); end; +procedure TIDECommand.SetCaption(const ACaption: string); +var + xUser: TIDESpecialCommand; +begin + for xUser in FUsers do + xUser.Caption := ACaption; +end; + procedure TIDECommand.ClearShortcutA; begin ShortcutA:=CleanIDEShortCut; @@ -1418,23 +1457,24 @@ begin FCustomUpdateEvents.Add(TMethod(aEvent)); end; +procedure TIDECommands.ApplicationOnIdle(Sender: TObject; var Done: Boolean); +begin + if (FDontExecuteUpdateEventsUntil > 0) and (GetTickCount64 < FDontExecuteUpdateEventsUntil) then + Exit; + + ExecuteUpdateEvents; + FDontExecuteUpdateEventsUntil := 0; +end; + constructor TIDECommands.Create; begin inherited Create; FCustomUpdateEvents := TMethodList.Create; - - //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 - FUpdateTimer.Free; FCustomUpdateEvents.Free; inherited Destroy; end; @@ -1455,18 +1495,14 @@ begin Categories[i].DoOnUpdate; end; -procedure TIDECommands.UpdateTimerTimer(Sender: TObject); +procedure TIDECommands.CancelPostponeUpdateEvents; begin - ExecuteUpdateEvents; + FDontExecuteUpdateEventsUntil := 0; end; procedure TIDECommands.PostponeUpdateEvents; begin - if FUpdateTimer.Enabled then - begin - FUpdateTimer.Enabled := False; - FUpdateTimer.Enabled := True; - end; + FDontExecuteUpdateEventsUntil := GetTickCount64 + 500; end; procedure TIDECommands.RemoveCustomUpdateEvent(const aEvent: TNotifyEvent); @@ -1474,14 +1510,14 @@ begin FCustomUpdateEvents.Remove(TMethod(aEvent)); end; -procedure TIDECommands.StartUpdateTimer; +procedure TIDECommands.StartUpdateEvents; begin - FUpdateTimer.Enabled := True; + Application.AddOnIdleHandler(@ApplicationOnIdle, False); end; -procedure TIDECommands.StopUpdateTimer; +procedure TIDECommands.StopUpdateEvents; begin - FUpdateTimer.Enabled := False; + Application.RemoveOnIdleHandler(@ApplicationOnIdle); end; { TIDESpecialCommand } @@ -1506,10 +1542,10 @@ end; procedure TIDESpecialCommand.DoOnClick(Sender: TObject); begin if Assigned(FOnClickProc) then - FOnClickProc(Self) + FOnClickProc(Sender) else if Assigned(FOnClickMethod) then - FOnClickMethod(Self); + FOnClickMethod(Sender); end; procedure TIDESpecialCommand.DoOnClick; @@ -1517,6 +1553,21 @@ begin DoOnClick(Self); end; +function TIDESpecialCommand.DoOnRequestCaption(Sender: TObject): Boolean; +var + xCaption, xHint: string; +begin + Result := Assigned(FOnRequestCaption); + if Result then + begin + xCaption := Caption; + xHint := Hint; + FOnRequestCaption(Sender, xCaption, xHint); + Caption := xCaption; + Hint := xHint; + end; +end; + function TIDESpecialCommand.GetCaption: string; begin if FCaption<>'' then @@ -1657,6 +1708,19 @@ begin FCommand.OnExecuteProc:=aOnClickProc; end; +procedure TIDESpecialCommand.SetOnRequestCaption( + const aOnRequestCaptionHint: TGetHintCaptionEvent); +var + xUser: TIDESpecialCommand; +begin + if FOnRequestCaption = aOnRequestCaptionHint then Exit; + FOnRequestCaption := aOnRequestCaptionHint; + if FCommand<> nil then + for xUser in FCommand.FUsers do + if xUser <> Self then + xUser.OnRequestCaptionHint:=aOnRequestCaptionHint; +end; + procedure TIDESpecialCommand.SetResourceName(const aResourceName: string); begin if aResourceName <> '' then diff --git a/components/ideintf/menuintf.pas b/components/ideintf/menuintf.pas index e549bda8af..9f280a9fec 100644 --- a/components/ideintf/menuintf.pas +++ b/components/ideintf/menuintf.pas @@ -1218,6 +1218,7 @@ begin i:=0; while inil then @@ -2490,7 +2650,6 @@ end; procedure TMainIDE.SetupFileMenu; begin inherited SetupFileMenu; - mnuFile.OnClick:=@UpdateFileMenu; with MainIDEBar do begin itmFileNewUnit.OnClick := @mnuNewUnitClicked; itmFileNewForm.OnClick := @mnuNewFormClicked; @@ -2515,7 +2674,6 @@ end; procedure TMainIDE.SetupEditMenu; begin inherited SetupEditMenu; - mnuEdit.OnClick:=@UpdateEditMenu; with MainIDEBar do begin itmEditUndo.OnClick:=@mnuEditUndoClicked; itmEditRedo.OnClick:=@mnuEditRedoClicked; @@ -2579,7 +2737,6 @@ end; procedure TMainIDE.SetupSourceMenu; begin inherited SetupSourceMenu; - mnuSource.OnClick:=@UpdateSourceMenu; with MainIDEBar do begin itmSourceCommentBlock.OnClick:=@mnuSourceCommentBlockClicked; itmSourceUncommentBlock.OnClick:=@mnuSourceUncommentBlockClicked; @@ -2637,7 +2794,6 @@ end; procedure TMainIDE.SetupProjectMenu; begin inherited SetupProjectMenu; - mnuProject.OnClick:=@UpdateProjectMenu; with MainIDEBar do begin itmProjectNew.OnClick := @mnuNewProjectClicked; itmProjectNewFromFile.OnClick := @mnuNewProjectFromFileClicked; @@ -2661,7 +2817,6 @@ end; procedure TMainIDE.SetupRunMenu; begin inherited SetupRunMenu; - mnuRun.OnClick:=@UpdateRunMenu; with MainIDEBar do begin itmRunMenuCompile.OnClick := @mnuCompileProjectClicked; itmRunMenuBuild.OnClick := @mnuBuildProjectClicked; @@ -2689,7 +2844,6 @@ end; procedure TMainIDE.SetupPackageMenu; begin inherited SetupPackageMenu; - mnuPackage.OnClick:=@UpdatePackageMenu; end; procedure TMainIDE.SetupToolsMenu; @@ -3543,95 +3697,58 @@ end; {------------------------------------------------------------------------------} -procedure TMainIDE.UpdateFileMenu(Sender: TObject); +procedure TMainIDE.UpdateFileCommands(Sender: TObject); var ASrcEdit: TSourceEditor; AnUnitInfo: TUnitInfo; begin GetCurrentUnit(ASrcEdit,AnUnitInfo); - with MainIDEBar do begin - itmFileClose.Enabled := ASrcEdit<>nil; - itmFileCloseAll.Enabled := ASrcEdit<>nil; - end; + if not UpdateFileCommandsStamp.Changed(ASrcEdit) then + Exit; + + IDECommandList.FindIDECommand(ecClose).Enabled := ASrcEdit<>nil; + IDECommandList.FindIDECommand(ecCloseAll).Enabled := ASrcEdit<>nil; end; procedure TMainIDE.UpdateMainIDECommands(Sender: TObject); begin - UpdateFileMenu(Sender); - UpdateEditMenu(Sender); - UpdateSourceMenu(Sender); - UpdateProjectMenu(Sender); - UpdateRunMenu(Sender); - UpdatePackageMenu(Sender); + UpdateFileCommands(Sender); + UpdateEditorCommands(Sender); + UpdateBookmarkCommands(Sender); + UpdateEditorTabCommands(Sender); + UpdateProjectCommands(Sender); + UpdatePackageCommands(Sender); end; -procedure TMainIDE.UpdateEditMenu(Sender: TObject); +procedure TMainIDE.UpdateEditorCommands(Sender: TObject); var ASrcEdit: TSourceEditor; AnUnitInfo: TUnitInfo; Editable: Boolean; SelAvail: Boolean; SelEditable: Boolean; - SrcEditorActive, DsgEditorActive: Boolean; + SrcEditorActive, DsgEditorActive, StringFound, IdentFound: Boolean; ActiveDesigner: TComponentEditorDesigner; + xAttr: TSynHighlighterAttributes; + xToken, CurWordAtCursor: string; begin GetCurrentUnit(ASrcEdit, AnUnitInfo); + if not UpdateEditorCommandsStamp.Changed(ASrcEdit, DisplayState) then + Exit; + Editable := Assigned(ASrcEdit) and not ASrcEdit.ReadOnly; SelAvail := Assigned(ASrcEdit) and ASrcEdit.SelectionAvailable; SelEditable := Editable and SelAvail; SrcEditorActive := DisplayState = dsSource; DsgEditorActive := DisplayState = dsForm; ActiveDesigner := GetActiveDesignerSkipMainBar; - with MainIDEBar do - begin - if Assigned(ActiveDesigner) then - begin - // activate them when Designer start to support Undo/Redo - itmEditUndo.Enabled := DsgEditorActive and ActiveDesigner.CanUndo; {and not ActiveDesigner.ReadOnly} - itmEditRedo.Enabled := DsgEditorActive and ActiveDesigner.CanRedo; {and not ActiveDesigner.ReadOnly} - itmEditCut.Enabled := ActiveDesigner.CanCopy; - itmEditCopy.Enabled := itmEditCut.Enabled; - itmEditPaste.Enabled := ActiveDesigner.CanPaste; - end - else - begin - itmEditUndo.Enabled := Editable and SrcEditorActive and ASrcEdit.EditorComponent.CanUndo; - itmEditRedo.Enabled := Editable and SrcEditorActive and ASrcEdit.EditorComponent.CanRedo; - itmEditCut.Enabled := SelEditable; - itmEditCopy.Enabled := SelAvail; - itmEditPaste.Enabled := Editable; - end; - //itmEditSelect: TIDEMenuSection; [...] - //itmEditBlockActions: TIDEMenuSection; - itmEditIndentBlock.Enabled := Editable; - itmEditUnindentBlock.Enabled := Editable; - itmEditUpperCaseBlock.Enabled := SelEditable; - itmEditLowerCaseBlock.Enabled := SelEditable; - itmEditSwapCaseBlock.Enabled := SelEditable; - itmEditSortBlock.Enabled := SelEditable; - itmEditTabsToSpacesBlock.Enabled := SelEditable; - itmEditSelectionBreakLines.Enabled := SelEditable; - itmEditInsertCharacter.Enabled := Editable; - end; -end; -procedure TMainIDE.UpdateSourceMenu(Sender: TObject); -var - ASrcEdit: TSourceEditor; - AnUnitInfo: TUnitInfo; - Editable, SelEditable, SelAvail, IdentFound, StringFound: Boolean; - xToken: string; - xAttr: TSynHighlighterAttributes; -begin - Editable:=False; - SelAvail:=False; - StringFound:=False; - IdentFound:=False; - GetCurrentUnit(ASrcEdit,AnUnitInfo); + StringFound := False; + IdentFound := False; + CurWordAtCursor := ''; if ASrcEdit<>nil then begin - Editable:=not ASrcEdit.ReadOnly; - SelAvail:=ASrcEdit.SelectionAvailable; + CurWordAtCursor := ASrcEdit.GetWordAtCurrentCaret; //it is faster to get information from SynEdit than from CodeTools if ASrcEdit.EditorComponent.GetHighlighterAttriAtRowCol(ASrcEdit.EditorComponent.CaretXY, xToken, xAttr) then begin @@ -3639,70 +3756,153 @@ begin IdentFound := xAttr = ASrcEdit.EditorComponent.Highlighter.IdentifierAttribute; end; end; - SelEditable:=Editable and SelAvail; - with MainIDEBar do begin - //itmSourceBlockActions - itmSourceCommentBlock.Enabled:=SelEditable; - itmSourceUncommentBlock.Enabled:=SelEditable; - itmSourceEncloseBlock.Enabled:=SelEditable; - itmSourceEncloseInIFDEF.Enabled:=SelEditable; - itmSourceCompleteCode.Enabled:=Editable; - itmSourceUseUnit.Enabled:=Editable; - //itmSourceInsertions - //itmSourceInsertCVSKeyWord - itmSourceInsertCVSAuthor.Enabled:=Editable; - itmSourceInsertCVSDate.Enabled:=Editable; - itmSourceInsertCVSHeader.Enabled:=Editable; - itmSourceInsertCVSID.Enabled:=Editable; - itmSourceInsertCVSLog.Enabled:=Editable; - itmSourceInsertCVSName.Enabled:=Editable; - itmSourceInsertCVSRevision.Enabled:=Editable; - itmSourceInsertCVSSource.Enabled:=Editable; - //itmSourceInsertGeneral - itmSourceInsertGPLNotice.Enabled:=Editable; - itmSourceInsertGPLNoticeTranslated.Visible:= - Editable and (EnglishGPLNotice<>lisGPLNotice); - itmSourceInsertLGPLNotice.Enabled:=Editable; - itmSourceInsertLGPLNoticeTranslated.Visible:= - Editable and (EnglishLGPLNotice<>lisLGPLNotice); - itmSourceInsertModifiedLGPLNotice.Enabled:=Editable; - itmSourceInsertModifiedLGPLNoticeTranslated.Visible:= - Editable and (EnglishModifiedLGPLNotice<>lisModifiedLGPLNotice); - itmSourceInsertMITNotice.Enabled:=Editable; - itmSourceInsertMITNoticeTranslated.Visible:= - Editable and (EnglishMITNotice<>lisMITNotice); - itmSourceInsertUsername.Enabled:=Editable; - itmSourceInsertDateTime.Enabled:=Editable; - itmSourceInsertChangeLogEntry.Enabled:=Editable; - //itmSourceRefactor - //itmRefactorCodeTools - itmRefactorRenameIdentifier.Enabled:=Editable and IdentFound; - itmRefactorExtractProc.Enabled:=Editable and SelAvail; - itmRefactorInvertAssignment.Enabled:=Editable and SelAvail; - //itmRefactorAdvanced - itmRefactorMakeResourceString.Enabled:=Editable and StringFound; + + if Assigned(ActiveDesigner) then + begin + IDECommandList.FindIDECommand(ecUndo).Enabled := DsgEditorActive and ActiveDesigner.CanUndo; {and not ActiveDesigner.ReadOnly} + IDECommandList.FindIDECommand(ecRedo).Enabled := DsgEditorActive and ActiveDesigner.CanRedo; {and not ActiveDesigner.ReadOnly} + IDECommandList.FindIDECommand(ecCut).Enabled := ActiveDesigner.CanCopy; + IDECommandList.FindIDECommand(ecCopy).Enabled := ActiveDesigner.CanCopy; + IDECommandList.FindIDECommand(ecPaste).Enabled := ActiveDesigner.CanPaste; + IDECommandList.FindIDECommand(ecSelectAll).Enabled := Assigned(ActiveDesigner.Form) and (ActiveDesigner.Form.ComponentCount>0); + end + else + begin + IDECommandList.FindIDECommand(ecUndo).Enabled := Editable and SrcEditorActive and Assigned(ASrcEdit) and ASrcEdit.EditorComponent.CanUndo; + IDECommandList.FindIDECommand(ecRedo).Enabled := Editable and SrcEditorActive and Assigned(ASrcEdit) and ASrcEdit.EditorComponent.CanRedo; + IDECommandList.FindIDECommand(ecCut).Enabled := SelEditable; + IDECommandList.FindIDECommand(ecCopy).Enabled := SelAvail; + IDECommandList.FindIDECommand(ecPaste).Enabled := Editable; + IDECommandList.FindIDECommand(ecSelectAll).Enabled := Assigned(ASrcEdit) and (ASrcEdit.SourceText<>''); end; + + IDECommandList.FindIDECommand(ecBlockIndent).Enabled := Editable; + IDECommandList.FindIDECommand(ecBlockUnindent).Enabled := Editable; + IDECommandList.FindIDECommand(ecSelectionUpperCase).Enabled := SelEditable; + IDECommandList.FindIDECommand(ecSelectionLowerCase).Enabled := SelEditable; + IDECommandList.FindIDECommand(ecSelectionSwapCase).Enabled := SelEditable; + IDECommandList.FindIDECommand(ecSelectionSort).Enabled := SelEditable; + IDECommandList.FindIDECommand(ecSelectionTabs2Spaces).Enabled := SelEditable; + IDECommandList.FindIDECommand(ecSelectionBreakLines).Enabled := SelEditable; + IDECommandList.FindIDECommand(ecSelectionComment).Enabled := SelEditable; + IDECommandList.FindIDECommand(ecSelectionUnComment).Enabled := SelEditable; + IDECommandList.FindIDECommand(ecSelectionEnclose).Enabled := SelEditable; + IDECommandList.FindIDECommand(ecSelectionEncloseIFDEF).Enabled := SelEditable; + + IDECommandList.FindIDECommand(ecInsertCharacter).Enabled := Editable; + IDECommandList.FindIDECommand(ecCompleteCode).Enabled := Editable; + IDECommandList.FindIDECommand(ecUseUnit).Enabled := Editable; + + IDECommandList.FindIDECommand(ecInsertCVSAuthor).Enabled := Editable; + IDECommandList.FindIDECommand(ecInsertCVSDate).Enabled := Editable; + IDECommandList.FindIDECommand(ecInsertCVSHeader).Enabled := Editable; + IDECommandList.FindIDECommand(ecInsertCVSID).Enabled := Editable; + IDECommandList.FindIDECommand(ecInsertCVSLog).Enabled := Editable; + IDECommandList.FindIDECommand(ecInsertCVSName).Enabled := Editable; + IDECommandList.FindIDECommand(ecInsertCVSRevision).Enabled := Editable; + IDECommandList.FindIDECommand(ecInsertCVSSource).Enabled := Editable; + IDECommandList.FindIDECommand(ecInsertGPLNotice).Enabled := Editable; + IDECommandList.FindIDECommand(ecInsertGPLNoticeTranslated).Visible := Editable and (EnglishGPLNotice<>lisGPLNotice); + IDECommandList.FindIDECommand(ecInsertLGPLNotice).Enabled := Editable; + IDECommandList.FindIDECommand(ecInsertLGPLNoticeTranslated).Visible := Editable and (EnglishLGPLNotice<>lisLGPLNotice); + IDECommandList.FindIDECommand(ecInsertModifiedLGPLNotice).Enabled := Editable; + IDECommandList.FindIDECommand(ecInsertModifiedLGPLNoticeTranslated).Visible := Editable and (EnglishModifiedLGPLNotice<>lisModifiedLGPLNotice); + IDECommandList.FindIDECommand(ecInsertMITNotice).Enabled := Editable; + IDECommandList.FindIDECommand(ecInsertMITNoticeTranslated).Visible := Editable and (EnglishMITNotice<>lisMITNotice); + IDECommandList.FindIDECommand(ecInsertUserName).Enabled := Editable; + IDECommandList.FindIDECommand(ecInsertDateTime).Enabled := Editable; + IDECommandList.FindIDECommand(ecInsertChangeLogEntry).Enabled := Editable; + + IDECommandList.FindIDECommand(ecRenameIdentifier).Enabled := Editable and IdentFound; + IDECommandList.FindIDECommand(ecExtractProc).Enabled := SelEditable; + IDECommandList.FindIDECommand(ecInvertAssignment).Enabled := SelEditable; + IDECommandList.FindIDECommand(ecMakeResourceString).Enabled := Editable and StringFound; + IDECommandList.FindIDECommand(ecFindIdentifierRefs).Enabled := IdentFound; + IDECommandList.FindIDECommand(ecFindUsedUnitRefs).Enabled := IdentFound; + IDECommandList.FindIDECommand(ecFindOverloads).Enabled := IdentFound; + IDECommandList.FindIDECommand(ecShowAbstractMethods).Enabled := Editable; + IDECommandList.FindIDECommand(ecRemoveEmptyMethods).Enabled := Editable; + + IDECommandList.FindIDECommand(ecFindDeclaration).Enabled := CurWordAtCursor<>''; + if CurWordAtCursor<>'' then + IDECommandList.FindIDECommand(ecFindDeclaration).Caption := + Format(lisFindDeclarationOf, [CurWordAtCursor]) + else + IDECommandList.FindIDECommand(ecFindDeclaration).Caption := + uemFindDeclaration; end; -procedure TMainIDE.UpdateProjectMenu(Sender: TObject); +procedure TMainIDE.UpdateEditorTabCommands(Sender: TObject); +var + ASrcEdit: TSourceEditor; + AnUnitInfo: TUnitInfo; + + {$IFnDEF SingleSrcWindow} + function ToWindow(WinForFind: Boolean = False): Boolean; + var + i, ThisWin, SharedEditor: Integer; + nb: TSourceNotebook; + begin + Result := False; + ThisWin := SourceEditorManager.IndexOfSourceWindow(ASrcEdit.SourceNotebook); + for i := 0 to SourceEditorManager.SourceWindowCount - 1 do begin + nb:=SourceEditorManager.SourceWindows[i]; + SharedEditor:=nb.IndexOfEditorInShareWith(ASrcEdit); + if (i <> ThisWin) and ((SharedEditor < 0) <> WinForFind) then begin + Result := True; + Break; + end; + end; + end; + {$ENDIF} + +var + NBAvail: Boolean; + PageIndex, PageCount: Integer; +begin + GetCurrentUnit(ASrcEdit, AnUnitInfo); + if not UpdateEditorTabCommandsStamp.Changed(ASrcEdit) then + Exit; + + PageIndex := ASrcEdit.SourceNotebook.PageIndex; + PageCount := ASrcEdit.SourceNotebook.PageCount; + + {$IFnDEF SingleSrcWindow} + SrcEditMenuEditorLock.Checked := ASrcEdit.IsLocked; // Editor locks + // Multi win + NBAvail := ToWindow(); + SrcEditMenuMoveToNewWindow.Visible := not NBAvail; + SrcEditMenuMoveToNewWindow.Enabled := PageCount > 1; + SrcEditMenuMoveToOtherWindow.Visible := NBAvail; + SrcEditMenuMoveToOtherWindowNew.Enabled := PageCount > 1; + + SrcEditMenuCopyToNewWindow.Visible := not NBAvail; + SrcEditMenuCopyToOtherWindow.Visible := NBAvail; + + SrcEditMenuFindInOtherWindow.Enabled := NBAvail; + {$ENDIF} + + // editor layout + SrcEditMenuMoveEditorLeft.Enabled:= (PageCount>1); + SrcEditMenuMoveEditorRight.Enabled:= (PageCount>1); + SrcEditMenuMoveEditorFirst.Enabled:= (PageCount>1) and (PageIndex>0); + SrcEditMenuMoveEditorLast.Enabled:= (PageCount>1) and (PageIndex<(PageCount-1)); +end; + +procedure TMainIDE.UpdateProjectCommands(Sender: TObject); var ASrcEdit: TSourceEditor; AUnitInfo: TUnitInfo; - NotPartOfProj: Boolean; begin GetCurrentUnit(ASrcEdit,AUnitInfo); - NotPartOfProj:=Assigned(AUnitInfo) and not AUnitInfo.IsPartOfProject; - MainIDEBar.itmProjectAddTo.Enabled:=NotPartOfProj; + if not UpdateProjectCommandsStamp.Changed(AUnitInfo) then + Exit; + + IDECommandList.FindIDECommand(ecAddCurUnitToProj).Enabled:=Assigned(AUnitInfo) and not AUnitInfo.IsPartOfProject; + IDECommandList.FindIDECommand(ecBuildManyModes).Enabled:=Project1.BuildModes.Count>1; end; -procedure TMainIDE.UpdateRunMenu(Sender: TObject); -begin - with MainIDEBar do begin - itmRunMenuBuildManyModes.Enabled:=Project1.BuildModes.Count>1; - end; -end; - -procedure TMainIDE.UpdatePackageMenu(Sender: TObject); +procedure TMainIDE.UpdatePackageCommands(Sender: TObject); var ASrcEdit: TSourceEditor; AUnitInfo: TUnitInfo; @@ -3710,6 +3910,13 @@ var CanOpenPkgOfFile, CanAddCurFile: Boolean; begin GetCurrentUnit(ASrcEdit,AUnitInfo); + if Assigned(AUnitInfo) then + else + PkgFile := nil; + + if not UpdatePackageCommandsStamp.Changed(AUnitInfo) then + Exit; + if Assigned(AUnitInfo) then begin PkgFile:=PackageGraph.FindFileInAllPackages(AUnitInfo.Filename,true, @@ -7895,6 +8102,42 @@ begin Application.BringToFront; end; +procedure TMainIDE.UpdateBookmarkCommands(Sender: TObject); +var + se: TSourceEditor; + MarkDesc: string; + MarkComand: TIDECommand; + BookMarkID, i, BookMarkX, BookMarkY: Integer; + BookmarkAvail: Boolean; +begin + if not UpdateBookmarkCommandsStamp.Changed then + Exit; + + for BookMarkID:=0 to 9 do begin + MarkDesc:=' '+IntToStr(BookMarkID); + BookmarkAvail:=False; + i := 0; + while i < SourceEditorManager.SourceEditorCount do begin + se:=SourceEditorManager.SourceEditors[i]; + BookMarkX:=0; BookMarkY:=0; + if se.EditorComponent.GetBookMark(BookMarkID,BookMarkX,BookMarkY) then + begin + MarkDesc:=MarkDesc+': '+se.PageName+' ('+IntToStr(BookMarkY)+','+IntToStr(BookMarkX)+')'; + BookmarkAvail:=True; + break; + end; + inc(i); + end; + // goto book mark item + MarkComand:=IDECommandList.FindIDECommand(ecGotoMarker0+BookMarkID); + MarkComand.Caption:=uemBookmarkN+MarkDesc; + MarkComand.Enabled:=BookmarkAvail; + // set book mark item + MarkComand:=IDECommandList.FindIDECommand(ecToggleMarker0+BookMarkID); + MarkComand.Caption:=uemToggleBookmark+MarkDesc; + end; +end; + procedure TMainIDE.SaveIncludeLinks; var AFilename: string; @@ -10167,7 +10410,6 @@ end; procedure TMainIDE.OnSrcNotebookEditorDoSetBookmark(Sender: TObject; ID: Integer; Toggle: Boolean); var ActEdit, OldEdit: TSourceEditor; - Cmd: TIDEMenuCommand; OldX, OldY: integer; NewXY: TPoint; SetMark: Boolean; @@ -10197,8 +10439,8 @@ Begin end; if SetMark then ActEdit.EditorComponent.SetBookMark(ID,NewXY.X,NewXY.Y); - Cmd:=SrcEditSubMenuToggleBookmarks[ID] as TIDEMenuCommand; - Cmd.Checked := SetMark; + + UpdateBookmarkCommandsStamp.BookmarkChanged := True; end; procedure TMainIDE.OnSrcNotebookEditorDoGotoBookmark(Sender: TObject; ID: Integer; Backward: Boolean); diff --git a/ide/sourceeditor.pp b/ide/sourceeditor.pp index 3a87efe7ae..ab3a0b1b61 100644 --- a/ide/sourceeditor.pp +++ b/ide/sourceeditor.pp @@ -252,8 +252,6 @@ type procedure EditorMouseMoved(Sender: TObject; Shift: TShiftState; X,Y:Integer); procedure EditorMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,Y: Integer); - procedure EditorMouseUp(Sender: TObject; {%H-}Button: TMouseButton; - {%H-}Shift: TShiftState; {%H-}X,{%H-}Y: Integer); procedure EditorMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); procedure EditorKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); @@ -581,14 +579,6 @@ type TBrowseEditorTabHistoryDialog = class; - TSrcPopupMenuItemsStamp = record - SrcEdit: TSourceEditor; - EditorComponentStamp: int64; - FileStateStamp: int64; - SourceCacheStamp: int64; - DefinesStep: integer; - end; - { TSourceNotebook } TSourceNotebook = class(TSourceEditorWindowInterface) @@ -622,19 +612,16 @@ type procedure SrcEditMenuFindInWindowClicked(Sender: TObject); procedure SrcEditMenuMoveToExistingWindowClicked(Sender: TObject); procedure SrcPopUpMenuPopup(Sender: TObject); - procedure UpdateSrcPopUpMenu(SrcEdit: TSourceEditor); procedure StatusBarClick(Sender: TObject); procedure StatusBarDblClick(Sender: TObject); procedure StatusBarDrawPanel({%H-}AStatusBar: TStatusBar; APanel: TStatusPanel; const ARect: TRect); - procedure UpdateTabPopUpMenu(ASrcEdit: TSourceEditor); procedure TabPopUpMenuPopup(Sender: TObject); private FNotebook: TExtendedNotebook; FBaseCaption: String; FIsClosing: Boolean; FSrcEditsSortedForFilenames: TAvgLvlTree; // TSourceEditorInterface sorted for Filename - FSrcPopupMenuItemsStamp: TSrcPopupMenuItemsStamp; TabPopUpMenu, SrcPopUpMenu, DbgPopUpMenu: TPopupMenu; procedure ApplyPageIndex; procedure ExecuteEditorItemClick(Sender: TObject); @@ -1032,8 +1019,8 @@ type procedure SetActiveSourceNotebook(const AValue: TSourceNotebook); function GetSourceNotebook(Index: integer): TSourceNotebook; procedure SetActiveSrcEditor(const AValue: TSourceEditor); - - procedure UpdatePopUpMenus(Sender: TObject); + procedure SrcEditMenuProcedureJumpGetCaption(Sender: TObject; var ACaption, + {%H-}AHint: string); public // Windows function SourceWindowWithEditor(const AEditor: TSourceEditorInterface): TSourceNotebook; @@ -4052,6 +4039,8 @@ Begin If Assigned(OnEditorChange) then OnEditorChange(Sender); UpdatePageName; + if Changes * [scCaretX, scCaretY, scSelection] <> [] then + IDECommandList.PostponeUpdateEvents; end; function TSourceEditor.SelectionAvailable: boolean; @@ -4985,7 +4974,6 @@ Begin OnMouseMove := @EditorMouseMoved; OnMouseWheel := @EditorMouseWheel; OnMouseDown := @EditorMouseDown; - OnMouseUp := @EditorMouseUp; OnClickLink := Manager.OnClickLink; OnMouseLink := Manager.OnMouseLink; OnKeyDown := @EditorKeyDown; @@ -5430,8 +5418,6 @@ begin // Navigating with mousebuttons between editors (eg jump history on btn 4/5) // can trigger the old editor to be refocused (while not visible) end; - - IDECommandList.ExecuteUpdateEvents; end; procedure TSourceEditor.EditorActivateSyncro(Sender: TObject); @@ -5518,15 +5504,6 @@ 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 - if Button=mbLeft then - IDECommandList.ExecuteUpdateEvents; end; procedure TSourceEditor.EditorMouseWheel(Sender: TObject; Shift: TShiftState; @@ -6516,8 +6493,6 @@ begin end; ASrcEdit:=Editors[PageIndex]; - UpdateTabPopUpMenu(ASrcEdit); - {$IFnDEF SingleSrcWindow} // Multi win ToWindow(SrcEditMenuMoveToOtherWindowList, 'MoveToWindow', @@ -6651,7 +6626,13 @@ begin Assert((ASrcEdit=GetActiveSE), 'TSourceNotebook.SrcPopUpMenuPopup: ASrcEdit<>GetActiveSE'); EditorComp:=ASrcEdit.EditorComponent; - UpdateSrcPopUpMenu(ASrcEdit); + SrcEditMenuReadOnly.Checked:=ASrcEdit.ReadOnly; + SrcEditMenuShowLineNumbers.Checked := ASrcEdit.EditorComponent.Gutter.LineNumberPart.Visible; + SrcEditMenuDisableI18NForLFM.Visible:=false; + + UpdateHighlightMenuItems(ASrcEdit); + UpdateEncodingMenuItems(ASrcEdit); + UpdateLineEndingMenuItems(ASrcEdit); // ask Codetools CurFilename:=ASrcEdit.FileName; @@ -6928,144 +6909,6 @@ begin Editors[i].UpdateProjectFile; end; -procedure TSourceNotebook.UpdateSrcPopUpMenu(SrcEdit: TSourceEditor); -var - se: TSourceEditor; - BookMarkID, BookMarkX, BookMarkY: integer; - MarkDesc, ShortFileName, CurFilename: String; - MarkMenuItem: TIDEMenuItem; - MainCodeBuf: TCodeBuffer; - i: integer; - SelAvail, SelAvailAndWritable, StringFound, IdentFound: Boolean; - CurWordAtCursor: String; - CodeTool: TCodeTool; - CaretXY: TCodeXYPosition; - CleanPos: integer; - CodeNode: TCodeTreeNode; - ProcNode: TCodeTreeNode; - ProcName, xToken: String; - xAttr: TSynHighlighterAttributes; -begin - if (FSrcPopupMenuItemsStamp.SrcEdit = SrcEdit) - and (FSrcPopupMenuItemsStamp.EditorComponentStamp = SrcEdit.EditorComponent.ChangeStamp) - and (FSrcPopupMenuItemsStamp.FileStateStamp = FileStateCache.TimeStamp) - and (FSrcPopupMenuItemsStamp.SourceCacheStamp = CodeToolBoss.SourceCache.ChangeStamp) - and (FSrcPopupMenuItemsStamp.DefinesStep = CodeToolBoss.DefineTree.ChangeStep) - then exit; - FSrcPopupMenuItemsStamp.SrcEdit := SrcEdit; - FSrcPopupMenuItemsStamp.EditorComponentStamp := SrcEdit.EditorComponent.ChangeStamp; - FSrcPopupMenuItemsStamp.FileStateStamp := FileStateCache.TimeStamp; - FSrcPopupMenuItemsStamp.SourceCacheStamp := CodeToolBoss.SourceCache.ChangeStamp; - FSrcPopupMenuItemsStamp.DefinesStep := CodeToolBoss.DefineTree.ChangeStep; - - // Clipboard section: - SrcEditMenuCut.Enabled := SrcEdit.SelectionAvailable and not SrcEdit.ReadOnly; - SrcEditMenuCopy.Enabled := SrcEdit.SelectionAvailable; - SrcEditMenuPaste.Enabled := not SrcEdit.ReadOnly; - SrcEditMenuSelectAll.Enabled:= SrcEdit.SourceText<>''; - - // Files section: Readonly, ShowLineNumbers - SrcEditMenuReadOnly.Checked:=SrcEdit.ReadOnly; - SrcEditMenuShowLineNumbers.Checked := SrcEdit.EditorComponent.Gutter.LineNumberPart.Visible; - SrcEditMenuDisableI18NForLFM.Visible:=false; - - UpdateHighlightMenuItems(SrcEdit); - UpdateEncodingMenuItems(SrcEdit); - UpdateLineEndingMenuItems(SrcEdit); - - // add context specific menu items - CurFilename:=SrcEdit.FileName; - ShortFileName:=ExtractFileName(CurFilename); - SelAvail:=SrcEdit.EditorComponent.SelAvail; - SelAvailAndWritable:=SelAvail and (not SrcEdit.ReadOnly); - CurWordAtCursor:=SrcEdit.GetWordAtCurrentCaret; - - // ask Codetools - MainCodeBuf:=nil; - if FilenameIsPascalUnit(ShortFileName) - or (CompareFileExt(ShortFileName,'.inc',true)=0) then - MainCodeBuf:=CodeToolBoss.GetMainCode(SrcEdit.CodeBuffer) - else if FilenameIsPascalSource(ShortFileName) then - MainCodeBuf:=SrcEdit.CodeBuffer; - CodeTool:=nil; - CaretXY:=CleanCodeXYPosition; - CaretXY.Code:=SrcEdit.CodeBuffer; - CaretXY.X:=SrcEdit.CursorTextXY.X; - CaretXY.Y:=SrcEdit.CursorTextXY.Y; - CodeNode:=nil; - if MainCodeBuf<>nil then begin - CodeToolBoss.Explore(MainCodeBuf,CodeTool,true); - if CodeTool<>nil then begin - CodeTool.CaretToCleanPos(CaretXY,CleanPos); - CodeNode:=CodeTool.FindDeepestNodeAtPos(CleanPos,false); - end; - end; - - StringFound:=False; - IdentFound:=False; - //it is faster to get information from SynEdit than from CodeTools - if SrcEdit.EditorComponent.GetHighlighterAttriAtRowCol(SrcEdit.EditorComponent.CaretXY, xToken, xAttr) then - begin - StringFound := xAttr = SrcEdit.EditorComponent.Highlighter.StringAttribute; - IdentFound := xAttr = SrcEdit.EditorComponent.Highlighter.IdentifierAttribute; - end; - - // bookmarks - for BookMarkID:=0 to 9 do begin - MarkDesc:=' '+IntToStr(BookMarkID); - SelAvail:=False; - i := 0; - while i < Manager.SourceEditorCount do begin - se:=Manager.SourceEditors[i]; - BookMarkX:=0; BookMarkY:=0; - if se.EditorComponent.GetBookMark(BookMarkID,BookMarkX,BookMarkY) then - begin - MarkDesc:=MarkDesc+': '+se.PageName+' ('+IntToStr(BookMarkY)+','+IntToStr(BookMarkX)+')'; - SelAvail:=True; - break; - end; - inc(i); - end; - // goto book mark item - MarkMenuItem:=SrcEditSubMenuGotoBookmarks[BookMarkID]; - MarkMenuItem.Caption:=uemBookmarkN+MarkDesc; - MarkMenuItem.Enabled:=SelAvail; - // set book mark item - MarkMenuItem:=SrcEditSubMenuToggleBookmarks[BookMarkID]; - MarkMenuItem.Caption:=uemToggleBookmark+MarkDesc; - end; - - SrcEditMenuFindDeclaration.Enabled:=CurWordAtCursor<>''; - if CurWordAtCursor<>'' then - SrcEditMenuFindDeclaration.Caption:=Format(lisFindDeclarationOf, [ - CurWordAtCursor]) - else - SrcEditMenuFindDeclaration.Caption:=uemFindDeclaration; - SrcEditMenuFindIdentifierReferences.Enabled:=IdentFound; - SrcEditMenuFindUsedUnitReferences.Enabled:=IdentFound; - SrcEditMenuFindOverloads.Enabled:=IdentFound; - ProcName:=''; - if CodeNode<>nil then begin - ProcNode:=CodeNode.GetNodeOfType(ctnProcedure); - if ProcNode<>nil then - ProcName:=CodeTool.ExtractProcName(ProcNode,[]); - end; - SrcEditMenuProcedureJump.Enabled:=(ProcName<>''); - if ProcName<>'' then - SrcEditMenuProcedureJump.Caption:=Format(lisJumpToProcedure, [ProcName]) - else - SrcEditMenuProcedureJump.Caption:=uemProcedureJump; - // enable refactoring menu items - SrcEditMenuEncloseSelection.Enabled := SelAvailAndWritable; - SrcEditMenuEncloseInIFDEF.Enabled := SelAvailAndWritable; - SrcEditMenuExtractProc.Enabled := SelAvailAndWritable; - SrcEditMenuInvertAssignment.Enabled := SelAvailAndWritable; - SrcEditMenuRenameIdentifier.Enabled:=IdentFound and (not SrcEdit.ReadOnly); - SrcEditMenuShowAbstractMethods.Enabled:=not SrcEdit.ReadOnly; - SrcEditMenuShowEmptyMethods.Enabled:=not SrcEdit.ReadOnly; - SrcEditMenuMakeResourceString.Enabled:=not SrcEdit.ReadOnly and StringFound; -end; - procedure TSourceNotebook.UpdateEncodingMenuItems(SrcEdit: TSourceEditor); var List: TStringList; @@ -8403,51 +8246,6 @@ begin CheckCurrentCodeBufferChanged; End; -procedure TSourceNotebook.UpdateTabPopUpMenu(ASrcEdit: TSourceEditor); - {$IFnDEF SingleSrcWindow} - function ToWindow(WinForFind: Boolean = False): Boolean; - var - i, ThisWin, SharedEditor: Integer; - nb: TSourceNotebook; - begin - Result := False; - ThisWin := Manager.IndexOfSourceWindow(self); - for i := 0 to Manager.SourceWindowCount - 1 do begin - nb:=Manager.SourceWindows[i]; - SharedEditor:=nb.IndexOfEditorInShareWith(ASrcEdit); - if (i <> ThisWin) and ((SharedEditor < 0) <> WinForFind) then begin - Result := True; - Break; - end; - end; - end; - {$ENDIF} - -var - NBAvail: Boolean; -begin - {$IFnDEF SingleSrcWindow} - SrcEditMenuEditorLock.Checked := ASrcEdit.IsLocked; // Editor locks - // Multi win - NBAvail := ToWindow(); - SrcEditMenuMoveToNewWindow.Visible := not NBAvail; - SrcEditMenuMoveToNewWindow.Enabled := PageCount > 1; - SrcEditMenuMoveToOtherWindow.Visible := NBAvail; - SrcEditMenuMoveToOtherWindowNew.Enabled := PageCount > 1; - - SrcEditMenuCopyToNewWindow.Visible := not NBAvail; - SrcEditMenuCopyToOtherWindow.Visible := NBAvail; - - SrcEditMenuFindInOtherWindow.Enabled := NBAvail; - {$ENDIF} - - // editor layout - SrcEditMenuMoveEditorLeft.Enabled:= (PageCount>1); - SrcEditMenuMoveEditorRight.Enabled:= (PageCount>1); - SrcEditMenuMoveEditorFirst.Enabled:= (PageCount>1) and (PageIndex>0); - SrcEditMenuMoveEditorLast.Enabled:= (PageCount>1) and (PageIndex<(PageCount-1)); -end; - function TSourceNotebook.FindPageWithEditor( ASourceEditor: TSourceEditor):integer; var @@ -9915,6 +9713,56 @@ begin end; end; +procedure TSourceEditorManager.SrcEditMenuProcedureJumpGetCaption( + Sender: TObject; var ACaption, AHint: string); +var + ShortFileName, CurFilename: String; + MainCodeBuf: TCodeBuffer; + CodeTool: TCodeTool; + CaretXY: TCodeXYPosition; + CleanPos: integer; + CodeNode: TCodeTreeNode; + ProcNode: TCodeTreeNode; + ProcName: String; + SrcEdit: TSourceEditor; +begin + // ask Codetools + SrcEdit:=GetActiveSE; + if not Assigned(SrcEdit) then Exit; + CurFilename:=SrcEdit.FileName; + ShortFileName:=ExtractFileName(CurFilename); + MainCodeBuf:=nil; + if FilenameIsPascalUnit(ShortFileName) + or (CompareFileExt(ShortFileName,'.inc',true)=0) then + MainCodeBuf:=CodeToolBoss.GetMainCode(SrcEdit.CodeBuffer) + else if FilenameIsPascalSource(ShortFileName) then + MainCodeBuf:=SrcEdit.CodeBuffer; + CodeTool:=nil; + CaretXY:=CleanCodeXYPosition; + CaretXY.Code:=SrcEdit.CodeBuffer; + CaretXY.X:=SrcEdit.CursorTextXY.X; + CaretXY.Y:=SrcEdit.CursorTextXY.Y; + CodeNode:=nil; + if MainCodeBuf<>nil then begin + CodeToolBoss.Explore(MainCodeBuf,CodeTool,true); + if CodeTool<>nil then begin + CodeTool.CaretToCleanPos(CaretXY,CleanPos); + CodeNode:=CodeTool.FindDeepestNodeAtPos(CleanPos,false); + end; + end; + + ProcName:=''; + if CodeNode<>nil then begin + ProcNode:=CodeNode.GetNodeOfType(ctnProcedure); + if ProcNode<>nil then + ProcName:=CodeTool.ExtractProcName(ProcNode,[]); + end; + if ProcName<>'' then + ACaption:=Format(lisJumpToProcedure, [ProcName]) + else + ACaption:=uemProcedureJump; +end; + function TSourceEditorManager.IndexOfSourceWindowWithID(const AnID: Integer): Integer; begin Result := SourceWindowCount - 1; @@ -10450,6 +10298,7 @@ begin SrcEditMenuFindDeclaration.Command := GetCommand(ecFindDeclaration); {%region *** Submenu: Find Section *** } SrcEditMenuProcedureJump.Command := GetCommand(ecFindProcedureDefinition); + SrcEditMenuProcedureJump.OnRequestCaptionHint := @SrcEditMenuProcedureJumpGetCaption; SrcEditMenuFindNextWordOccurrence.Command := GetCommand(ecFindNextWordOccurrence); SrcEditMenuFindPrevWordOccurrence.Command := GetCommand(ecFindPrevWordOccurrence); SrcEditMenuFindInFiles.Command := GetCommand(ecFindInFiles); @@ -10680,34 +10529,6 @@ begin end; end; -procedure TSourceEditorManager.UpdatePopUpMenus(Sender: TObject); -var - ASrcNB: TSourceNotebook; - I: Integer; -begin - if Screen.ActiveCustomForm is TSourceNotebook then - begin - ASrcNB:=TSourceNotebook(Screen.ActiveCustomForm); - end else - begin - ASrcNB:=nil; - for I := 0 to Screen.CustomFormZOrderCount-1 do - if Screen.CustomFormsZOrdered[I] is TSourceNotebook then - begin - ASrcNB:=TSourceNotebook(Screen.CustomFormsZOrdered[I]); - Break; - end; - end; - if (ASrcNB=nil) and (SourceWindowCount > 0) then - ASrcNB:=SourceWindows[0]; - - if (ASrcNB<>nil) and (ASrcNB.GetActiveSE<>nil) then - begin - ASrcNB.UpdateSrcPopUpMenu(ASrcNB.GetActiveSE); - ASrcNB.UpdateTabPopUpMenu(ASrcNB.GetActiveSE); - end; -end; - procedure TSourceEditorManager.BeginGlobalUpdate; var i: integer; @@ -11046,13 +10867,10 @@ begin Application.AddOnIdleHandler(@OnIdle); Application.AddOnUserInputHandler(@OnUserInput); - - IDECommandList.AddCustomUpdateEvent(@UpdatePopUpMenus); end; destructor TSourceEditorManager.Destroy; begin - IDECommandList.RemoveCustomUpdateEvent(@UpdatePopUpMenus); FreeAndNil(FHints); SourceEditorMarks.OnAction := nil; Application.RemoveAllHandlersOfObject(Self); diff --git a/ide/sourcesyneditor.pas b/ide/sourcesyneditor.pas index 4e11c062b0..0729362b13 100644 --- a/ide/sourcesyneditor.pas +++ b/ide/sourcesyneditor.pas @@ -213,6 +213,7 @@ type TIDESynEditor = class(TSynEdit) private + FCaretStamp: Int64; FShowTopInfo: boolean; FSyncroEdit: TSynPluginSyncroEdit; FTemplateEdit: TSynPluginTemplateEdit; @@ -278,6 +279,7 @@ type property IsInMultiCaretMainExecution: Boolean read GetIsInMultiCaretMainExecution; property IsInMultiCaretRepeatExecution: Boolean read GetIsInMultiCaretRepeatExecution; property OnMultiCaretBeforeCommand: TSynMultiCaretBeforeCommand read GetOnMultiCaretBeforeCommand write SetOnMultiCaretBeforeCommand; + property CaretStamp: Int64 read FCaretStamp; end; TIDESynHighlighterPasRangeList = class(TSynHighlighterPasRangeList) @@ -1484,6 +1486,10 @@ begin inherited DoOnStatusChange(Changes); if Changes * [scTopLine, scLinesInWindow] <> []then SrcSynCaretChanged(nil); + {$push}{$R-} // range check off + if Changes * [scCaretX, scCaretY, scSelection] <> []then + Inc(FCaretStamp); + {$pop} end; procedure TIDESynEditor.GetTopInfoMarkupForLine(Sender: TObject; Line: integer; diff --git a/packager/packagesystem.pas b/packager/packagesystem.pas index 25483f025a..a81036454d 100644 --- a/packager/packagesystem.pas +++ b/packager/packagesystem.pas @@ -214,6 +214,7 @@ type function GetCount: Integer; function GetPackages(Index: integer): TLazPackage; procedure DoDependencyChanged(Dependency: TPkgDependency); + function GetPackagesChangeStamp: Int64; procedure SetRegistrationPackage(const AValue: TLazPackage); procedure UpdateBrokenDependenciesToPackage(APackage: TLazPackage); function OpenDependencyWithPackageLink(Dependency: TPkgDependency; @@ -442,6 +443,7 @@ type property Packages[Index: integer]: TLazPackage read GetPackages; default; // see Count for the number property UpdateLock: integer read FUpdateLock; property Verbosity: TPkgVerbosityFlags read FVerbosity write FVerbosity; + property PackagesChangeStamp: Int64 read GetPackagesChangeStamp; // base packages property FCLPackage: TLazPackage read FFCLPackage; @@ -5157,6 +5159,21 @@ begin end; end; +function TLazPackageGraph.GetPackagesChangeStamp: Int64; +var + I: Integer; + xPck: TLazPackage; +begin + {$push}{$R-} // range check off + Result := 0; + for I := 0 to Count-1 do + begin + xPck := Packages[I]; + Inc(Result, xPck.ChangeStamp); + end; + {$pop} +end; + procedure TLazPackageGraph.SortDependencyListTopologicallyOld( var FirstDependency: TPkgDependency; TopLevelFirst: boolean); // Sort dependency list topologically.