diff --git a/src/ce_main.lfm b/src/ce_main.lfm index eef47708..2974acfc 100644 --- a/src/ce_main.lfm +++ b/src/ce_main.lfm @@ -2074,6 +2074,7 @@ object CEMainForm: TCEMainForm Caption = 'Copy' ImageIndex = 4 OnExecute = actEdCopyExecute + OnUpdate = updateDocumentBasedAction ShortCut = 16451 end object actEdCut: TAction @@ -2081,6 +2082,7 @@ object CEMainForm: TCEMainForm Caption = 'Cut' ImageIndex = 6 OnExecute = actEdCutExecute + OnUpdate = updateDocumentBasedAction ShortCut = 16472 end object actEdPaste: TAction @@ -2088,6 +2090,7 @@ object CEMainForm: TCEMainForm Caption = 'Paste' ImageIndex = 5 OnExecute = actEdPasteExecute + OnUpdate = updateDocumentBasedAction ShortCut = 16470 end object actEdUndo: TAction @@ -2095,6 +2098,7 @@ object CEMainForm: TCEMainForm Caption = 'Undo' ImageIndex = 0 OnExecute = actEdUndoExecute + OnUpdate = updateDocumentBasedAction ShortCut = 16474 end object actEdRedo: TAction @@ -2102,6 +2106,7 @@ object CEMainForm: TCEMainForm Caption = 'Redo' ImageIndex = 1 OnExecute = actEdRedoExecute + OnUpdate = updateDocumentBasedAction ShortCut = 24666 end object actEdMacStartStop: TAction @@ -2109,6 +2114,7 @@ object CEMainForm: TCEMainForm Caption = 'Start/stop macro recording' ImageIndex = 10 OnExecute = actEdMacStartStopExecute + OnUpdate = updateDocumentBasedAction ShortCut = 24658 end object actEdMacPlay: TAction @@ -2116,6 +2122,7 @@ object CEMainForm: TCEMainForm Caption = 'Play macro' ImageIndex = 11 OnExecute = actEdMacPlayExecute + OnUpdate = updateDocumentBasedAction ShortCut = 24656 end object actFileSave: TAction @@ -2123,6 +2130,7 @@ object CEMainForm: TCEMainForm Caption = 'Save file' ImageIndex = 3 OnExecute = actFileSaveExecute + OnUpdate = updateDocumentBasedAction ShortCut = 16467 end object actFileSaveAs: TAction @@ -2130,6 +2138,7 @@ object CEMainForm: TCEMainForm Caption = 'Save file as...' ImageIndex = 2 OnExecute = actFileSaveAsExecute + OnUpdate = updateDocumentBasedAction ShortCut = 49235 end object actFileOpen: TAction @@ -2158,12 +2167,14 @@ object CEMainForm: TCEMainForm Caption = 'Add file to project' ImageIndex = 7 OnExecute = actFileAddToProjExecute + OnUpdate = updateDocumentBasedAction end object actFileCompAndRun: TAction Category = 'File' Caption = 'Compile file and run' ImageIndex = 22 OnExecute = actFileCompAndRunExecute + OnUpdate = updateDocumentBasedAction ShortCut = 16503 end object actProjSave: TAction @@ -2171,12 +2182,14 @@ object CEMainForm: TCEMainForm Caption = 'Save project' ImageIndex = 3 OnExecute = actProjSaveExecute + OnUpdate = updateProjectBasedAction end object actProjSaveAs: TAction Category = 'Project' Caption = 'Save project as...' ImageIndex = 2 OnExecute = actProjSaveAsExecute + OnUpdate = updateProjectBasedAction end object actProjOpen: TAction Category = 'Project' @@ -2195,24 +2208,28 @@ object CEMainForm: TCEMainForm Caption = 'Close project' ImageIndex = 27 OnExecute = actProjCloseExecute + OnUpdate = updateProjectBasedAction end object actProjOpts: TAction Category = 'Project' Caption = 'Project configuration' ImageIndex = 24 OnExecute = actProjOptsExecute + OnUpdate = updateProjectBasedAction end object actProjSource: TAction Category = 'Project' Caption = 'View project source' ImageIndex = 12 OnExecute = actProjSourceExecute + OnUpdate = updateProjectBasedAction end object actEdIndent: TAction Category = 'Edit' Caption = 'Indent' ImageIndex = 16 OnExecute = actEdIndentExecute + OnUpdate = updateDocumentBasedAction ShortCut = 24649 end object actEdUnIndent: TAction @@ -2220,6 +2237,7 @@ object CEMainForm: TCEMainForm Caption = 'Unindent' ImageIndex = 17 OnExecute = actEdUnIndentExecute + OnUpdate = updateDocumentBasedAction ShortCut = 24661 end object actProjOptView: TAction @@ -2227,12 +2245,14 @@ object CEMainForm: TCEMainForm Caption = 'View project command line' ImageIndex = 12 OnExecute = actProjOptViewExecute + OnUpdate = updateProjectBasedAction end object actProjCompile: TAction Category = 'Project' Caption = 'Compile project' ImageIndex = 21 OnExecute = actProjCompileExecute + OnUpdate = updateProjectBasedAction ShortCut = 16504 end object actProjCompileAndRun: TAction @@ -2240,6 +2260,7 @@ object CEMainForm: TCEMainForm Caption = 'Compile project and run' ImageIndex = 21 OnExecute = actProjCompileAndRunExecute + OnUpdate = updateProjectBasedAction ShortCut = 24696 end object actProjCompAndRunWithArgs: TAction @@ -2247,12 +2268,14 @@ object CEMainForm: TCEMainForm Caption = 'Compile project and run...' ImageIndex = 21 OnExecute = actProjCompAndRunWithArgsExecute + OnUpdate = updateProjectBasedAction end object actProjRun: TAction Category = 'Project' Caption = 'Run project' ImageIndex = 21 OnExecute = actProjRunExecute + OnUpdate = updateProjectBasedAction ShortCut = 120 end object actProjRunWithArgs: TAction @@ -2260,12 +2283,14 @@ object CEMainForm: TCEMainForm Caption = 'Run project...' ImageIndex = 21 OnExecute = actProjRunWithArgsExecute + OnUpdate = updateProjectBasedAction end object actEdFind: TAction Category = 'Edit' Caption = 'Find...' ImageIndex = 28 OnExecute = actEdFindExecute + OnUpdate = updateDocumentBasedAction ShortCut = 16454 end object actEdFindNext: TAction @@ -2273,6 +2298,7 @@ object CEMainForm: TCEMainForm Caption = 'Find next' ImageIndex = 28 OnExecute = actEdFindNextExecute + OnUpdate = updateDocumentBasedAction ShortCut = 114 end object actProjOpenContFold: TAction @@ -2280,6 +2306,7 @@ object CEMainForm: TCEMainForm Caption = 'View in mini explorer' ImageIndex = 29 OnExecute = actProjOpenContFoldExecute + OnUpdate = updateProjectBasedAction end object actLayoutSave: TAction Category = 'Misc' @@ -2292,12 +2319,14 @@ object CEMainForm: TCEMainForm Caption = 'Compile file and run outside' ImageIndex = 22 OnExecute = actFileCompileAndRunOutExecute + OnUpdate = updateDocumentBasedAction end object ActFileCompAndRunWithArgs: TAction Category = 'File' Caption = 'Compile file and run...' ImageIndex = 22 OnExecute = ActFileCompAndRunWithArgsExecute + OnUpdate = updateDocumentBasedAction ShortCut = 24695 end object actFileSaveAll: TAction @@ -2305,12 +2334,14 @@ object CEMainForm: TCEMainForm Caption = 'Save all' ImageIndex = 26 OnExecute = actFileSaveAllExecute + OnUpdate = updateDocumentBasedAction end object actFileClose: TAction Category = 'File' Caption = 'Close file' ImageIndex = 27 OnExecute = actFileCloseExecute + OnUpdate = updateDocumentBasedAction ShortCut = 16471 end object actFileOpenContFold: TAction @@ -2318,18 +2349,21 @@ object CEMainForm: TCEMainForm Caption = 'View in mini explorer' ImageIndex = 29 OnExecute = actFileOpenContFoldExecute + OnUpdate = updateDocumentBasedAction end object actFileHtmlExport: TAction Category = 'File' Caption = 'Export to html...' ImageIndex = 33 OnExecute = actFileHtmlExportExecute + OnUpdate = updateDocumentBasedAction end object actFileUnittest: TAction Category = 'File' Caption = 'Run file unittests' ImageIndex = 22 OnExecute = actFileUnittestExecute + OnUpdate = updateDocumentBasedAction end end object imgList: TImageList diff --git a/src/ce_main.pas b/src/ce_main.pas index ffe1d16a..8d625061 100644 --- a/src/ce_main.pas +++ b/src/ce_main.pas @@ -135,6 +135,8 @@ type MenuItem7: TMenuItem; MenuItem8: TMenuItem; MenuItem9: TMenuItem; + procedure updateDocumentBasedAction(sender: TObject); + procedure updateProjectBasedAction(sender: TObject); procedure actFileCompileAndRunOutExecute(Sender: TObject); procedure actEdFindExecute(Sender: TObject); procedure actEdFindNextExecute(Sender: TObject); @@ -706,95 +708,28 @@ begin SaveDocking; end; -procedure TCEMainForm.ActionsUpdate(AAction: TBasicAction; var Handled: Boolean); -var - hasEd: boolean; - hasProj: boolean; +procedure TCEMainForm.updateDocumentBasedAction(sender: TObject); begin - Handled := true; - {$IFDEF LINUX} - // TODO-cbugfix-linux: AV when closing document, current workaround may have other side effects. - // fixes some issues with property inspectors. - // option editor: IdleTimer seems to be used to refresh values after editing (e.g TColorPropertyEditor) - If not Focused then exit; - // fixes the error raised when the update is called after docClosing () - // looks like a syncro error, needs more investigation. - Application.DisableIdleHandler; - {$ENDIF} + TAction(sender).Enabled := fDoc <> nil; +end; + +procedure TCEMainForm.updateProjectBasedAction(sender: TObject); +begin + TAction(sender).Enabled := fProject <> nil; +end; + +procedure TCEMainForm.ActionsUpdate(AAction: TBasicAction; var Handled: Boolean); +begin + // TODO-cTest: linux, confirm close doc AV & TCOlorPropertyEditor conv err are fixed + Handled := false; if fUpdateCount > 0 then exit; Inc(fUpdateCount); - - - clearActProviderEntries; - collectedActProviderEntries; - try - HasEd := fDoc <> nil; - if hasEd then - begin - actEdCopy.Enabled := fDoc.SelAvail and fDoc.Focused; - actEdCut.Enabled := fDoc.SelAvail and fDoc.Focused; - actEdPaste.Enabled := fDoc.CanPaste and fDoc.Focused; - actEdUndo.Enabled := fDoc.CanUndo; - actEdRedo.Enabled := fDoc.CanRedo; - // - actFileCompAndRun.Enabled := fDoc.isDSource; - actFileCompAndRunWithArgs.Enabled := fDoc.isDSource; - actFileCompileAndRunOut.Enabled := fDoc.isDSource; - actFileUnittest.Enabled := fDoc.isDSource; - // - actEdMacPlay.Enabled := true; - actEdMacStartStop.Enabled := true; - actEdIndent.Enabled := true; - actEdUnIndent.Enabled := true; - // - actFileSave.Enabled := true; - actFileSaveAs.Enabled := true; - actFileClose.Enabled := true; - actFileSaveAll.Enabled := true; - actFileOpenContFold.Enabled := true; - actFileHtmlExport.Enabled := true; - end - else begin - actEdCopy.Enabled := false; - actEdCut.Enabled := false ; - actEdPaste.Enabled := false; - actEdUndo.Enabled := false; - actEdRedo.Enabled := false; - actEdMacPlay.Enabled := false; - actEdMacStartStop.Enabled := false; - actEdIndent.Enabled := false; - actEdUnIndent.Enabled := false; - // - actFileCompAndRun.Enabled := false; - actFileCompAndRunWithArgs.Enabled := false; - actFileCompileAndRunOut.Enabled := false; - actFileUnittest.Enabled := false; - actFileSave.Enabled := false; - actFileSaveAs.Enabled := false; - actFileClose.Enabled := false; - actFileSaveAll.Enabled := false; - actFileOpenContFold.Enabled := false; - actFileHtmlExport.Enabled := false; - end; - hasProj := fProject <> nil; - actProjSave.Enabled := hasProj; - actProjSaveAs.Enabled := hasProj; - actProjOpts.Enabled := hasProj; - actProjClose.Enabled := hasProj; - actProjCompile.Enabled := hasProj; - actProjCompileAndRun.Enabled := hasProj; - actProjCompAndRunWithArgs.Enabled := hasProj; - actProjOptView.Enabled := hasProj; - actProjOpenContFold.Enabled := hasProj; - if hasProj then - begin - actProjSource.Enabled := fileExists(fProject.Filename); - actProjRun.Enabled := fProject.canBeRun; - actProjRunWithArgs.Enabled := fProject.canBeRun; - end; - actFileAddToProj.Enabled := hasEd and hasProj; - // + clearActProviderEntries; + collectedActProviderEntries; + if (AAction <> nil ) then + if not AAction.Update then + TAction(AAction).enabled := true; updateMainMenuProviders; finally Dec(fUpdateCount);