62
62
Math, Classes, SysUtils, Process, AsyncProcess, TypInfo, types, AVL_Tree,
64
LazUTF8, Laz2_XMLCfg, AvgLvlTree,
64
66
LCLProc, LCLMemManager, LCLType, LCLIntf, LConvEncoding, LMessages, ComCtrls,
65
67
FileUtil, LResources, StdCtrls, Forms, Buttons, Menus, Controls, GraphType,
66
HelpIntfs, Graphics, ExtCtrls, Dialogs, InterfaceBase, UTF8Process,
68
HelpIntfs, Graphics, ExtCtrls, Dialogs, InterfaceBase, UTF8Process, LazLogger,
68
71
FileProcs, CodeBeautifier, FindDeclarationTool, LinkScanner, BasicCodeTools,
69
Laz_XMLCfg, CodeToolsStructs, CodeToolManager, CodeCache, DefineTemplates,
72
CodeToolsStructs, CodeToolManager, CodeCache, DefineTemplates,
73
KeywordFuncLists, CodeTree,
72
SynEditKeyCmds, SynBeautifier, SynEditMarks,
75
AllSynEdit, SynEditKeyCmds, SynBeautifier, SynEditMarks,
74
AllIDEIntf, BaseIDEIntf, ObjectInspector, PropEdits, PropEditUtils,
75
MacroIntf, IDECommands, IDEWindowIntf,
77
IDEIntf, BaseIDEIntf, ObjectInspector, PropEdits, PropEditUtils,
78
MacroIntf, IDECommands, IDEWindowIntf, ComponentReg, FormEditingIntf,
76
79
SrcEditorIntf, NewItemIntf, IDEExternToolIntf, IDEMsgIntf,
77
PackageIntf, ProjectIntf, MenuIntf, LazIDEIntf, IDEDialogs,
78
IDEOptionsIntf, IDEImagesIntf,
80
PackageIntf, ProjectIntf, CompOptsIntf, MenuIntf, LazIDEIntf, IDEDialogs,
81
IDEOptionsIntf, IDEImagesIntf, ComponentEditors,
82
Compiler, CompilerOptions, CompilerOptionsDlg, CheckCompilerOpts,
85
Compiler, CompilerOptions, CheckCompilerOpts, BuildProjectDlg,
83
86
ApplicationBundle, ImExportCompilerOpts, InfoBuild,
85
88
ProjectResources, Project, ProjectDefs, NewProjectDlg,
86
89
PublishProjectDlg, ProjectInspector, PackageDefs,
88
IDEContextHelpEdit, IDEHelpIntf, HelpManager, CodeHelp, HelpOptions,
91
IDEContextHelpEdit, IDEHelpIntf, IDEHelpManager, CodeHelp, HelpOptions,
90
JITForms, ComponentPalette, ComponentList, ComponentReg, FormEditingIntf,
93
JITForms, ComponentPalette, ComponentList,
91
94
ObjInspExt, Designer, FormEditor, CustomFormEditor,
92
ControlSelection, AnchorEditor,
95
ControlSelection, AnchorEditor, TabOrderDlg, MenuEditorForm,
129
132
compiler_path_options, compiler_parsing_options, compiler_codegen_options,
130
133
compiler_linking_options, compiler_verbosity_options, compiler_messages_options,
131
134
compiler_other_options, compiler_inherited_options, compiler_compilation_options,
135
BuildModesEditor, compiler_buildmacro_options,
136
// package option frames
137
package_usage_options, package_description_options, package_integration_options,
138
package_provides_options, package_i18n_options,
134
140
// rest of the ide
135
141
Splash, IDEDefs, LazarusIDEStrConsts, LazConf, MsgView, SearchResultView,
136
CodeTemplatesDlg, CodeBrowser, FindUnitDlg, IdeOptionsDlg, EditDefineTree,
137
PublishModule, EnvironmentOpts, TransferMacros, KeyMapping, IDETranslations,
138
IDEProcs, ExtToolDialog, ExtToolEditDlg, OutputFilter, JumpHistoryView,
142
CodeTemplatesDlg, CodeBrowser, FindUnitDlg, InspectChksumChangedDlg,
143
IdeOptionsDlg, EditDefineTree, PublishModule, EnvironmentOpts, TransferMacros,
144
KeyMapping, IDETranslations, IDEProcs, ExtToolDialog, ExtToolEditDlg,
145
OutputFilter, JumpHistoryView, ManageExamples,
139
146
BuildLazDialog, BuildProfileManager, BuildManager, CheckCompOptsForNewUnitDlg,
140
147
MiscOptions, InputHistory, UnitDependencies, ClipBoardHistory,
141
IDEFPCInfo, IDEInfoDlg, ProcessList, InitialSetupDlgs, NewDialog,
142
MakeResStrDlg, DialogProcs, FindReplaceDialog, FindInFilesDlg, CodeExplorer,
143
BuildFileDlg, ProcedureList, ExtractProcDlg, FindRenameIdentifier,
144
AbstractsMethodsDlg, EmptyMethodsDlg, UnusedUnitsDlg, FindOverloadsDlg,
148
IDEFPCInfo, IDEInfoDlg, IDEInfoNeedBuild, ProcessList, InitialSetupDlgs,
149
NewDialog, MakeResStrDlg, DialogProcs, FindReplaceDialog, FindInFilesDlg,
150
CodeExplorer, BuildFileDlg, ProcedureList, ExtractProcDlg,
151
FindRenameIdentifier, AbstractsMethodsDlg, EmptyMethodsDlg, UnusedUnitsDlg,
152
UseUnitDlg, FindOverloadsDlg, EditorFileManager,
145
153
CleanDirDlg, CodeContextForm, AboutFrm, CompatibilityRestrictions,
146
RestrictionBrowser, ProjectWizardDlg, IDECmdLine, CodeExplOpts,
154
RestrictionBrowser, ProjectWizardDlg, IDECmdLine, IDEGuiCmdLine, CodeExplOpts,
148
156
MainBar, MainIntf, MainBase;
158
159
TIDECodetoolsDefines = (
202
209
procedure mnuEditCutClicked(Sender: TObject);
203
210
procedure mnuEditCopyClicked(Sender: TObject);
204
211
procedure mnuEditPasteClicked(Sender: TObject);
205
procedure mnuEditIndentBlockClicked(Sender: TObject);
206
procedure mnuEditUnindentBlockClicked(Sender: TObject);
207
procedure mnuEditEncloseBlockClicked(Sender: TObject);
208
procedure mnuEditUpperCaseBlockClicked(Sender: TObject);
209
procedure mnuEditLowerCaseBlockClicked(Sender: TObject);
210
procedure mnuEditTabsToSpacesBlockClicked(Sender: TObject);
211
procedure mnuEditCommentBlockClicked(Sender: TObject);
212
procedure mnuEditUncommentBlockClicked(Sender: TObject);
213
procedure mnuEditToggleCommentClicked(Sender: TObject);
214
procedure mnuEditConditionalBlockClicked(Sender: TObject);
215
procedure mnuEditSortBlockClicked(Sender: TObject);
216
procedure mnuEditSelectionBreakLinesClicked(Sender: TObject);
217
212
procedure mnuEditSelectAllClick(Sender: TObject);
218
213
procedure mnuEditSelectCodeBlockClick(Sender: TObject);
219
214
procedure mnuEditSelectToBraceClick(Sender: TObject);
215
procedure mnuEditSelectWordClick(Sender: TObject);
220
216
procedure mnuEditSelectLineClick(Sender: TObject);
221
217
procedure mnuEditSelectParagraphClick(Sender: TObject);
222
procedure mnuEditCompleteCodeClicked(Sender: TObject);
223
procedure mnuEditExtractProcClicked(Sender: TObject);
218
procedure mnuEditUpperCaseBlockClicked(Sender: TObject);
219
procedure mnuEditLowerCaseBlockClicked(Sender: TObject);
220
procedure mnuEditSwapCaseBlockClicked(Sender: TObject);
221
procedure mnuEditIndentBlockClicked(Sender: TObject);
222
procedure mnuEditUnindentBlockClicked(Sender: TObject);
223
procedure mnuEditSortBlockClicked(Sender: TObject);
224
procedure mnuEditTabsToSpacesBlockClicked(Sender: TObject);
225
procedure mnuEditSelectionBreakLinesClicked(Sender: TObject);
224
226
procedure mnuEditInsertCharacterClicked(Sender: TObject);
226
// edit->insert text->CVS keyword
227
procedure mnuEditInsertCVSAuthorClick(Sender: TObject);
228
procedure mnuEditInsertCVSDateClick(Sender: TObject);
229
procedure mnuEditInsertCVSHeaderClick(Sender: TObject);
230
procedure mnuEditInsertCVSIDClick(Sender: TObject);
231
procedure mnuEditInsertCVSLogClick(Sender: TObject);
232
procedure mnuEditInsertCVSNameClick(Sender: TObject);
233
procedure mnuEditInsertCVSRevisionClick(Sender: TObject);
234
procedure mnuEditInsertCVSSourceClick(Sender: TObject);
236
// edit->insert text->general
237
procedure mnuEditInsertGPLNoticeClick(Sender: TObject);
238
procedure mnuEditInsertLGPLNoticeClick(Sender: TObject);
239
procedure mnuEditInsertModifiedLGPLNoticeClick(Sender: TObject);
240
procedure mnuEditInsertUsernameClick(Sender: TObject);
241
procedure mnuEditInsertDateTimeClick(Sender: TObject);
242
procedure mnuEditInsertChangeLogEntryClick(Sender: TObject);
243
procedure mnuEditInsertGUID(Sender: TObject);
246
229
procedure mnuSearchFindInFiles(Sender: TObject);
247
230
procedure mnuSearchFindIdentifierRefsClicked(Sender: TObject);
248
procedure mnuSearchRenameIdentifierClicked(Sender: TObject);
249
231
procedure mnuSearchFindBlockOtherEnd(Sender: TObject);
250
232
procedure mnuSearchFindBlockStart(Sender: TObject);
251
233
procedure mnuSearchFindDeclaration(Sender: TObject);
271
249
procedure mnuViewSearchResultsClick(Sender: TObject);
272
250
procedure mnuToggleFormUnitClicked(Sender: TObject);
273
251
procedure mnuViewAnchorEditorClicked(Sender: TObject);
252
procedure mnuViewTabOrderClicked(Sender: TObject);
274
253
procedure mnuViewComponentPaletteClicked(Sender: TObject);
275
254
procedure mnuViewIDESpeedButtonsClicked(Sender: TObject);
276
255
procedure mnuViewFPCInfoClicked(Sender: TObject);
277
256
procedure mnuViewIDEInfoClicked(Sender: TObject);
257
procedure mnuViewNeedBuildClicked(Sender: TObject);
260
procedure mnuSourceClicked(Sender: TObject);
261
procedure mnuSourceCommentBlockClicked(Sender: TObject);
262
procedure mnuSourceUncommentBlockClicked(Sender: TObject);
263
procedure mnuSourceToggleCommentClicked(Sender: TObject);
264
procedure mnuSourceEncloseBlockClicked(Sender: TObject);
265
procedure mnuSourceEncloseInIFDEFClicked(Sender: TObject);
266
procedure mnuSourceCompleteCodeClicked(Sender: TObject);
267
procedure mnuSourceUseUnitClicked(Sender: TObject);
268
procedure mnuSourceSyntaxCheckClicked(Sender: TObject);
269
procedure mnuSourceGuessUnclosedBlockClicked(Sender: TObject);
270
procedure mnuSourceGuessMisplacedIFDEFClicked(Sender: TObject);
271
// source->insert CVS keyword
272
procedure mnuSourceInsertCVSAuthorClick(Sender: TObject);
273
procedure mnuSourceInsertCVSDateClick(Sender: TObject);
274
procedure mnuSourceInsertCVSHeaderClick(Sender: TObject);
275
procedure mnuSourceInsertCVSIDClick(Sender: TObject);
276
procedure mnuSourceInsertCVSLogClick(Sender: TObject);
277
procedure mnuSourceInsertCVSNameClick(Sender: TObject);
278
procedure mnuSourceInsertCVSRevisionClick(Sender: TObject);
279
procedure mnuSourceInsertCVSSourceClick(Sender: TObject);
280
// source->insert general
281
procedure mnuSourceInsertGPLNoticeClick(Sender: TObject);
282
procedure mnuSourceInsertLGPLNoticeClick(Sender: TObject);
283
procedure mnuSourceInsertModifiedLGPLNoticeClick(Sender: TObject);
284
procedure mnuSourceInsertMITNoticeClick(Sender: TObject);
285
procedure mnuSourceInsertUsernameClick(Sender: TObject);
286
procedure mnuSourceInsertDateTimeClick(Sender: TObject);
287
procedure mnuSourceInsertChangeLogEntryClick(Sender: TObject);
288
procedure mnuSourceInsertGUID(Sender: TObject);
289
// source->insert full Filename
290
procedure mnuSourceInsertFilename(Sender: TObject);
292
procedure mnuSourceUnitInfoClicked(Sender: TObject);
293
procedure mnuSourceUnitDependenciesClicked(Sender: TObject);
296
procedure mnuRefactorRenameIdentifierClicked(Sender: TObject);
297
procedure mnuRefactorExtractProcClicked(Sender: TObject);
298
procedure mnuRefactorInvertAssignmentClicked(Sender: TObject);
299
procedure mnuRefactorShowAbstractMethodsClicked(Sender: TObject);
300
procedure mnuRefactorShowEmptyMethodsClicked(Sender: TObject);
301
procedure mnuRefactorShowUnusedUnitsClicked(Sender: TObject);
302
procedure mnuRefactorFindOverloadsClicked(Sender: TObject);
303
procedure mnuRefactorMakeResourceStringClicked(Sender: TObject);
280
306
procedure mnuNewProjectClicked(Sender: TObject);
1231
1328
Application.BidiMode := Application.Direction(EnvironmentOptions.LanguageID);
1233
TranslateResourceStrings(EnvironmentOptions.LazarusDirectory,
1330
TranslateResourceStrings(EnvironmentOptions.GetParsedLazarusDirectory,
1234
1331
EnvironmentOptions.LanguageID);
1332
MainBuildBoss.TranslateMacros;
1236
ExternalTools.OnNeedsOutputFilter := @OnExtToolNeedsOutputFilter;
1237
ExternalTools.OnFreeOutputFilter := @OnExtToolFreeOutputFilter;
1238
1334
Application.ShowButtonGlyphs := ShowButtonGlyphs;
1239
1335
Application.ShowMenuGlyphs := ShowMenuGlyphs;
1241
IDEWindowCreators.OnShowForm:=@IDEWindowCreators.SimpleLayoutStorage.ApplyAndShow;
1338
OldVer:=EnvironmentOptions.OldLazarusVersion;
1339
NowVer:=GetLazarusVersionString;
1340
//debugln(['TMainIDE.LoadGlobalOptions ',EnvOptsCfgExisted,' diff=',OldVer<>NowVer,' Now=',NowVer,' Old=',OldVer,' Comp=',CompareLazarusVersion(NowVer,OldVer)]);
1341
if EnvOptsCfgExisted and (OldVer<>NowVer) then
1343
IsUpgrade:=CompareLazarusVersion(NowVer,OldVer)>0;
1345
OldVer:=Format(lisPrior, [GetLazarusVersionString]);
1346
s:=Format(lisWelcomeToLazarusThereIsAlreadyAConfigurationFromVe, [
1347
GetLazarusVersionString, #13, #13, OldVer, #13, GetPrimaryConfigPath, #13]
1350
s+=lisTheOldConfigurationWillBeUpgraded
1352
s+=lisTheConfigurationWillBeDowngradedConverted;
1355
s+=Format(lisIfYouWantToUseTwoDifferentLazarusVersionsYouMustSt, [#13, #13,
1357
StartFile:=Application.ExeName;
1358
if StartedByStartLazarus then
1359
StartFile:=ExtractFilePath(StartFile)+'startlazarus'+GetExeExt;
1361
s+=StartFile+' --pcp=C:\test_lazarus\configs';
1364
s+='open '+StartFile+' --pcp=~/.lazarus_test';
1366
s+=StartFile+' --pcp=~/.lazarus_test';
1370
MsgResult:=IDEQuestionDialog(lisUpgradeConfiguration, s, mtConfirmation, [
1371
mrOK, lisUpgrade, mrAbort])
1373
MsgResult:=IDEQuestionDialog(lisDowngradeConfiguration, s, mtWarning, [
1374
mrOK, lisDowngrade, mrAbort]);
1375
if MsgResult<>mrOk then begin
1376
Application.Terminate;
1381
ExternalTools.OnNeedsOutputFilter := @OnExtToolNeedsOutputFilter;
1382
ExternalTools.OnFreeOutputFilter := @OnExtToolFreeOutputFilter;
1242
1383
UpdateDefaultPascalFileExtensions;
1384
LoadFileDialogFilter;
1244
1386
EditorOpts := TEditorOptions.Create;
1245
1387
EditorOpts.OnBeforeRead := @DoEditorOptionsBeforeRead;
1854
procedure TMainIDE.OnPropHookGetCompatibleMethods(InstProp: PInstProp;
1855
const Proc: TGetStrProc);
1857
ActiveSrcEdit: TSourceEditor;
1858
ActiveUnitInfo: TUnitInfo;
1860
if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[ctfSwitchToFormSource])
1864
DebugLn('[TMainIDE.OnPropHookGetCompatibleMethods] ************');
1866
if not CodeToolBoss.GetCompatiblePublishedMethods(ActiveUnitInfo.Source,
1867
ActiveUnitInfo.Component.ClassName,
1868
InstProp^.Instance,InstProp^.PropInfo^.Name,Proc) then
1870
DoJumpToCodeToolBossError;
1874
function TMainIDE.OnPropHookCompatibleMethodExists(const AMethodName: String;
1875
InstProp: PInstProp; var MethodIsCompatible, MethodIsPublished,
1876
IdentIsMethod: boolean): boolean;
1878
ActiveSrcEdit: TSourceEditor;
1879
ActiveUnitInfo: TUnitInfo;
1881
if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[ctfSwitchToFormSource]) then
1885
WriteLn('[TMainIDE.OnPropHookCompatibleMethodExists] ************ ',AMethodName);
1887
Result := CodeToolBoss.PublishedMethodExists(ActiveUnitInfo.Source,
1888
ActiveUnitInfo.Component.ClassName, AMethodName,
1889
InstProp^.Instance, InstProp^.PropInfo^.Name,
1890
MethodIsCompatible, MethodIsPublished, IdentIsMethod);
1891
if CodeToolBoss.ErrorMessage <> '' then
1893
DoJumpToCodeToolBossError;
1894
raise Exception.Create(lisUnableToFindMethod+' '+lisPleaseFixTheErrorInTheMessageWindow);
1676
1898
{------------------------------------------------------------------------------}
1677
1899
procedure TMainIDE.MainIDEFormClose(Sender: TObject;
1678
1900
var CloseAction: TCloseAction);
1680
1902
DoCallNotifyHandler(lihtIDEClose);
1903
SaveEnvironment(true);
1682
1904
if IDEDockMaster<>nil then
1683
1905
IDEDockMaster.CloseAll
1798
1999
MainIDEBar.tbStandard := CreateToolBar('tbStandard');
1800
2001
MainIDEBar.NewUnitSpeedBtn := CreateButton(MainIDEBar.tbStandard , 'NewUnitSpeedBtn' , 'item_unit' , @mnuNewUnitClicked, lisMenuNewUnit);
2002
MainIDEBar.NewFormSpeedBtn := CreateButton(MainIDEBar.tbStandard , 'NewFormSpeedBtn' , 'item_form' , @mnuNewFormClicked, lisMenuNewForm);
1801
2003
MainIDEBar.tbDivider1 := CreateDivider(MainIDEBar.tbStandard);
1802
MainIDEBar.OpenFileSpeedBtn := CreateButton(MainIDEBar.tbStandard , 'OpenFileSpeedBtn' , 'laz_open' , @mnuOpenClicked, lisHintOpen);
1803
MainIDEBar.SaveSpeedBtn := CreateButton(MainIDEBar.tbStandard , 'SaveSpeedBtn' , 'laz_save' , @mnuSaveClicked, lisHintSave);
2004
MainIDEBar.OpenFileSpeedBtn := CreateButton(MainIDEBar.tbStandard , 'OpenFileSpeedBtn' , 'laz_open' , @mnuOpenClicked, lisOpen);
2005
MainIDEBar.SaveSpeedBtn := CreateButton(MainIDEBar.tbStandard , 'SaveSpeedBtn' , 'laz_save' , @mnuSaveClicked, lisSave);
1804
2006
MainIDEBar.SaveAllSpeedBtn := CreateButton(MainIDEBar.tbStandard , 'SaveAllSpeedBtn' , 'menu_save_all' , @mnuSaveAllClicked, lisHintSaveAll);
1805
2007
MainIDEBar.tbDivider2 := CreateDivider(MainIDEBar.tbStandard);
1806
MainIDEBar.NewFormSpeedBtn := CreateButton(MainIDEBar.tbStandard , 'NewFormSpeedBtn' , 'item_form' , @mnuNewFormClicked, lisMenuNewForm);
1807
2008
MainIDEBar.ToggleFormSpeedBtn := CreateButton(MainIDEBar.tbStandard , 'ToggleFormSpeedBtn' , 'menu_view_toggle_form_unit', @mnuToggleFormUnitCLicked, lisHintToggleFormUnit);
1809
2010
MainIDEBar.ViewUnitsSpeedBtn := CreateButton(MainIDEBar.tbViewDebug, 'ViewUnitsSpeedBtn' , 'menu_view_units' , @mnuViewUnitsClicked, lisHintViewUnits);
1810
2011
MainIDEBar.ViewFormsSpeedBtn := CreateButton(MainIDEBar.tbViewDebug, 'ViewFormsSpeedBtn' , 'menu_view_forms' , @mnuViewFormsClicked, lisHintViewForms);
1811
2012
MainIDEBar.tbDivider3 := CreateDivider(MainIDEBar.tbViewDebug);
1812
2013
MainIDEBar.BuildModeSpeedButton:= CreateButton(MainIDEBar.tbViewDebug, 'BuildModeSpeedButton', 'menu_compiler_options' , @mnuChgBuildModeClicked, lisChangeBuildMode);
1813
MainIDEBar.RunSpeedButton := CreateButton(MainIDEBar.tbViewDebug, 'RunSpeedButton' , 'menu_run' , @mnuRunProjectClicked, lisHintRun);
1814
MainIDEBar.PauseSpeedButton := CreateButton(MainIDEBar.tbViewDebug, 'PauseSpeedButton' , 'menu_pause' , @mnuPauseProjectClicked, lisHintPause);
1815
MainIDEBar.StopSpeedButton := CreateButton(MainIDEBar.tbViewDebug, 'StopSpeedButton' , 'menu_stop' , @mnuStopProjectClicked, lisHintStop);
2014
MainIDEBar.RunSpeedButton := CreateButton(MainIDEBar.tbViewDebug, 'RunSpeedButton' , 'menu_run' , @mnuRunProjectClicked, lisRunButtonHint);
2015
MainIDEBar.PauseSpeedButton := CreateButton(MainIDEBar.tbViewDebug, 'PauseSpeedButton' , 'menu_pause' , @mnuPauseProjectClicked, lisPause);
2016
MainIDEBar.StopSpeedButton := CreateButton(MainIDEBar.tbViewDebug, 'StopSpeedButton' , 'menu_stop' , @mnuStopProjectClicked, lisStop);
1816
2017
MainIDEBar.StepIntoSpeedButton := CreateButton(MainIDEBar.tbViewDebug, 'StepIntoSpeedButton', 'menu_stepinto' , @mnuStepIntoProjectClicked, lisHintStepInto);
1817
2018
MainIDEBar.StepOverSpeedButton := CreateButton(MainIDEBar.tbViewDebug, 'StepOverpeedButton' , 'menu_stepover' , @mnuStepOverProjectClicked, lisHintStepOver);
1818
2019
MainIDEBar.StepOutSpeedButton := CreateButton(MainIDEBar.tbViewDebug, 'StepOutSpeedButton' , 'menu_stepout' , @mnuStepOutProjectClicked, lisHintStepOut);
1904
2107
IDECmdScopeObjectInspectorOnly.AddWindowClass(TObjectInspectorDlg);
1906
ObjectInspector1 := TObjectInspectorDlg.Create(OwningComponent);
1907
ObjectInspector1.Name:=DefaultObjectInspectorName;
1908
ObjectInspector1.ShowFavorites:=True;
1909
ObjectInspector1.ShowRestricted:=True;
1910
ObjectInspector1.Favourites:=LoadOIFavouriteProperties;
1911
ObjectInspector1.FindDeclarationPopupmenuItem.Visible:=true;
1912
ObjectInspector1.OnAddToFavourites:=@OIOnAddToFavourites;
1913
ObjectInspector1.OnFindDeclarationOfProperty:=@OIOnFindDeclarationOfProperty;
1914
ObjectInspector1.OnUpdateRestricted := @OIOnUpdateRestricted;
1915
ObjectInspector1.OnRemainingKeyDown:=@OIRemainingKeyDown;
1916
ObjectInspector1.OnRemoveFromFavourites:=@OIOnRemoveFromFavourites;
1917
ObjectInspector1.OnSelectPersistentsInOI:=@OIOnSelectPersistents;
1918
ObjectInspector1.OnShowOptions:=@OIOnShowOptions;
1919
ObjectInspector1.OnViewRestricted:=@OIOnViewRestricted;
1920
ObjectInspector1.OnSelectionChange:=@OIOnSelectionChange;
1921
ObjectInspector1.OnPropertyHint:=@OIOnPropertyHint;
1922
ObjectInspector1.OnDestroy:=@OIOnDestroy;
1923
ObjectInspector1.OnAutoShow:=@OIOnAutoShow;
1924
ObjectInspector1.PropertyEditorHook:=GlobalDesignHook;
1926
// after OI changes the hints needs to be updated
1927
// do that after some idle time
1928
OIChangedTimer:=TIdleTimer.Create(OwningComponent);
1929
with OIChangedTimer do begin
1930
Name:='OIChangedTimer';
1932
OnTimer:=@OIChangedTimerTimer;
1935
IDEWindowCreators.Add(ObjectInspector1.Name,nil,@CreateIDEWindow,
2109
IDEWindowCreators.Add(DefaultObjectInspectorName,nil,@CreateIDEWindow,
1936
2110
'0','120','+230','-120','',alNone,false,@OnGetLayout);
1938
EnvironmentOptions.ObjectInspectorOptions.AssignTo(ObjectInspector1);
1940
2112
ShowAnchorDesigner:=@mnuViewAnchorEditorClicked;
2113
ShowTabOrderEditor:=@mnuViewTabOrderClicked;
1943
2116
procedure TMainIDE.SetupFormEditor;
2352
2543
procedure TMainIDE.SetupEditMenu;
2354
2545
inherited SetupEditMenu;
2546
mnuEdit.OnClick:=@mnuEditClicked;
2355
2547
with MainIDEBar do begin
2356
mnuEdit.OnClick:=@mnuEditClicked;
2357
2548
itmEditUndo.OnClick:=@mnuEditUndoClicked;
2358
2549
itmEditRedo.OnClick:=@mnuEditRedoClicked;
2359
2550
itmEditCut.OnClick:=@mnuEditCutClicked;
2360
2551
itmEditCopy.OnClick:=@mnuEditCopyClicked;
2361
2552
itmEditPaste.OnClick:=@mnuEditPasteClicked;
2553
itmEditSelectAll.OnClick:=@mnuEditSelectAllClick;
2554
itmEditSelectToBrace.OnClick:=@mnuEditSelectToBraceClick;
2555
itmEditSelectCodeBlock.OnClick:=@mnuEditSelectCodeBlockClick;
2556
itmEditSelectWord.OnClick:=@mnuEditSelectWordClick;
2557
itmEditSelectLine.OnClick:=@mnuEditSelectLineClick;
2558
itmEditSelectParagraph.OnClick:=@mnuEditSelectParagraphClick;
2362
2559
itmEditIndentBlock.OnClick:=@mnuEditIndentBlockClicked;
2363
2560
itmEditUnindentBlock.OnClick:=@mnuEditUnindentBlockClicked;
2364
itmEditEncloseBlock.OnClick:=@mnuEditEncloseBlockClicked;
2365
2561
itmEditUpperCaseBlock.OnClick:=@mnuEditUpperCaseBlockClicked;
2366
2562
itmEditLowerCaseBlock.OnClick:=@mnuEditLowerCaseBlockClicked;
2563
itmEditSwapCaseBlock.OnClick:=@mnuEditSwapCaseBlockClicked;
2564
itmEditSortBlock.OnClick:=@mnuEditSortBlockClicked;
2367
2565
itmEditTabsToSpacesBlock.OnClick:=@mnuEditTabsToSpacesBlockClicked;
2368
itmEditCommentBlock.OnClick:=@mnuEditCommentBlockClicked;
2369
itmEditUncommentBlock.OnClick:=@mnuEditUncommentBlockClicked;
2370
itmEditToggleComment.OnClick:=@mnuEditToggleCommentClicked;
2371
itmEditConditionalBlock.OnClick:=@mnuEditConditionalBlockClicked;
2372
itmEditSortBlock.OnClick:=@mnuEditSortBlockClicked;
2373
2566
itmEditSelectionBreakLines.OnClick:=@mnuEditSelectionBreakLinesClicked;
2374
itmEditSelectAll.OnClick:=@mnuEditSelectAllClick;
2375
itmEditSelectToBrace.OnClick:=@mnuEditSelectToBraceClick;
2376
itmEditSelectCodeBlock.OnClick:=@mnuEditSelectCodeBlockClick;
2377
itmEditSelectLine.OnClick:=@mnuEditSelectLineClick;
2378
itmEditSelectParagraph.OnClick:=@mnuEditSelectParagraphClick;
2379
itmEditCompleteCode.OnClick:=@mnuEditCompleteCodeClicked;
2380
itmEditExtractProc.OnClick:=@mnuEditExtractProcClicked;
2381
2567
itmEditInsertCharacter.OnClick:=@mnuEditInsertCharacterClicked;
2383
// insert text->CVS keyword
2384
itmEditInsertCVSAuthor.OnClick:=@mnuEditInsertCVSAuthorClick;
2385
itmEditInsertCVSDate.OnClick:=@mnuEditInsertCVSDateClick;
2386
itmEditInsertCVSHeader.OnClick:=@mnuEditInsertCVSHeaderClick;
2387
itmEditInsertCVSID.OnClick:=@mnuEditInsertCVSIDClick;
2388
itmEditInsertCVSLog.OnClick:=@mnuEditInsertCVSLogClick;
2389
itmEditInsertCVSName.OnClick:=@mnuEditInsertCVSNameClick;
2390
itmEditInsertCVSRevision.OnClick:=@mnuEditInsertCVSRevisionClick;
2391
itmEditInsertCVSSource.OnClick:=@mnuEditInsertCVSSourceClick;
2393
// insert text->general
2394
itmEditInsertGPLNotice.OnClick:=@mnuEditInsertGPLNoticeClick;
2395
itmEditInsertLGPLNotice.OnClick:=@mnuEditInsertLGPLNoticeClick;
2396
itmEditInsertModifiedLGPLNotice.OnClick:=@mnuEditInsertModifiedLGPLNoticeClick;
2397
itmEditInsertUsername.OnClick:=@mnuEditInsertUsernameClick;
2398
itmEditInsertDateTime.OnClick:=@mnuEditInsertDateTimeClick;
2399
itmEditInsertChangeLogEntry.OnClick:=@mnuEditInsertChangeLogEntryClick;
2400
itmEditInsertGUID.OnClick:=@mnuEditInsertGUID;
2404
2571
procedure TMainIDE.SetupSearchMenu;
2406
2573
inherited SetupSearchMenu;
2574
// mnuSearch.OnClick:=@mnuSearchClicked;
2407
2575
with MainIDEBar do begin
2408
2576
itmSearchFindIdentifierRefs.OnClick:=@mnuSearchFindIdentifierRefsClicked;
2409
itmSearchRenameIdentifier.OnClick:=@mnuSearchRenameIdentifierClicked;
2410
2577
itmGotoIncludeDirective.OnClick:=@mnuGotoIncludeDirectiveClicked;
2411
2578
itmSearchProcedureList.OnClick := @mnuSearchProcedureList;
2412
2579
itmSetFreeBookmark.OnClick := @mnuSetFreeBookmark;
2424
2592
itmViewRestrictionBrowser.OnClick := @mnuViewRestrictionBrowserClick;
2425
2593
itmViewComponents.OnClick := @mnuViewComponentsClick;
2426
2594
itmViewFPDocEditor.OnClick := @mnuViewFPDocEditorClicked;
2427
itmViewUnits.OnClick := @mnuViewUnitsClicked;
2428
itmViewForms.OnClick := @mnuViewFormsClicked;
2429
itmViewUnitDependencies.OnClick := @mnuViewUnitDependenciesClicked;
2430
itmViewUnitInfo.OnClick := @mnuViewUnitInfoClicked;
2431
itmViewToggleFormUnit.OnClick := @mnuToggleFormUnitClicked;
2432
2595
itmViewMessage.OnClick := @mnuViewMessagesClick;
2433
2596
itmViewSearchResults.OnClick := @mnuViewSearchResultsClick;
2434
2597
itmViewAnchorEditor.OnClick := @mnuViewAnchorEditorClicked;
2598
itmViewTabOrder.OnClick := @mnuViewTabOrderClicked;
2435
2599
itmViewComponentPalette.OnClick := @mnuViewComponentPaletteClicked;
2436
2600
itmViewIDESpeedButtons.OnClick := @mnuViewIDESpeedButtonsClicked;
2438
2602
itmViewFPCInfo.OnClick:=@mnuViewFPCInfoClicked;
2439
2603
itmViewIDEInfo.OnClick:=@mnuViewIDEInfoClicked;
2604
itmViewNeedBuild.OnClick:=@mnuViewNeedBuildClicked;
2608
procedure TMainIDE.SetupSourceMenu;
2610
inherited SetupSourceMenu;
2611
mnuSource.OnClick:=@mnuSourceClicked;
2612
with MainIDEBar do begin
2613
itmSourceCommentBlock.OnClick:=@mnuSourceCommentBlockClicked;
2614
itmSourceUncommentBlock.OnClick:=@mnuSourceUncommentBlockClicked;
2615
itmSourceToggleComment.OnClick:=@mnuSourceToggleCommentClicked;
2616
itmSourceEncloseBlock.OnClick:=@mnuSourceEncloseBlockClicked;
2617
itmSourceEncloseInIFDEF.OnClick:=@mnuSourceEncloseInIFDEFClicked;
2618
itmSourceCompleteCode.OnClick:=@mnuSourceCompleteCodeClicked;
2619
itmSourceUseUnit.OnClick:=@mnuSourceUseUnitClicked;
2621
itmSourceSyntaxCheck.OnClick := @mnuSourceSyntaxCheckClicked;
2622
itmSourceGuessUnclosedBlock.OnClick := @mnuSourceGuessUnclosedBlockClicked;
2623
itmSourceGuessMisplacedIFDEF.OnClick := @mnuSourceGuessMisplacedIFDEFClicked;
2625
itmRefactorRenameIdentifier.OnClick:=@mnuRefactorRenameIdentifierClicked;
2626
itmRefactorExtractProc.OnClick:=@mnuRefactorExtractProcClicked;
2627
itmRefactorInvertAssignment.OnClick:=@mnuRefactorInvertAssignmentClicked;
2628
// itmRefactorAdvanced
2629
itmRefactorShowAbstractMethods.OnClick:=@mnuRefactorShowAbstractMethodsClicked;
2630
itmRefactorShowEmptyMethods.OnClick:=@mnuRefactorShowEmptyMethodsClicked;
2631
itmRefactorShowUnusedUnits.OnClick:=@mnuRefactorShowUnusedUnitsClicked;
2632
{$IFDEF EnableFindOverloads}
2633
itmRefactorFindOverloads.OnClick:=@mnuRefactorFindOverloadsClicked;
2636
itmRefactorMakeResourceString.OnClick := @mnuRefactorMakeResourceStringClicked;
2637
// insert CVS keyword
2638
itmSourceInsertCVSAuthor.OnClick:=@mnuSourceInsertCVSAuthorClick;
2639
itmSourceInsertCVSDate.OnClick:=@mnuSourceInsertCVSDateClick;
2640
itmSourceInsertCVSHeader.OnClick:=@mnuSourceInsertCVSHeaderClick;
2641
itmSourceInsertCVSID.OnClick:=@mnuSourceInsertCVSIDClick;
2642
itmSourceInsertCVSLog.OnClick:=@mnuSourceInsertCVSLogClick;
2643
itmSourceInsertCVSName.OnClick:=@mnuSourceInsertCVSNameClick;
2644
itmSourceInsertCVSRevision.OnClick:=@mnuSourceInsertCVSRevisionClick;
2645
itmSourceInsertCVSSource.OnClick:=@mnuSourceInsertCVSSourceClick;
2647
itmSourceInsertGPLNotice.OnClick:=@mnuSourceInsertGPLNoticeClick;
2648
itmSourceInsertLGPLNotice.OnClick:=@mnuSourceInsertLGPLNoticeClick;
2649
itmSourceInsertModifiedLGPLNotice.OnClick:=@mnuSourceInsertModifiedLGPLNoticeClick;
2650
itmSourceInsertMITNotice.OnClick:=@mnuSourceInsertMITNoticeClick;
2651
itmSourceInsertUsername.OnClick:=@mnuSourceInsertUsernameClick;
2652
itmSourceInsertDateTime.OnClick:=@mnuSourceInsertDateTimeClick;
2653
itmSourceInsertChangeLogEntry.OnClick:=@mnuSourceInsertChangeLogEntryClick;
2654
itmSourceInsertGUID.OnClick:=@mnuSourceInsertGUID;
2655
itmSourceInsertFilename.OnClick:=@mnuSourceInsertFilename;
2657
itmSourceUnitInfo.OnClick := @mnuSourceUnitInfoClicked;
2658
itmSourceUnitDependencies.OnClick := @mnuSourceUnitDependenciesClicked;
2443
2662
procedure TMainIDE.SetupProjectMenu;
2445
2664
inherited SetupProjectMenu;
2665
mnuProject.OnClick:=@mnuProjectClicked;
2446
2666
with MainIDEBar do begin
2447
2667
itmProjectNew.OnClick := @mnuNewProjectClicked;
2448
2668
itmProjectNewFromFile.OnClick := @mnuNewProjectFromFileClicked;
2665
2893
AFilename: string;
2667
2895
OpenFlags: TOpenFlags;
2897
AllEditorMask: String;
2899
ASrcEdit: TSourceEditor;
2900
AnUnitInfo: TUnitInfo;
2669
2902
OpenDialog:=TOpenDialog.Create(nil);
2671
2904
InputHistories.ApplyFileDialogSettings(OpenDialog);
2672
2905
OpenDialog.Title:=lisOpenFile;
2673
2906
OpenDialog.Options:=OpenDialog.Options+[ofAllowMultiSelect];
2674
OpenDialog.Filter := lisLazarusFile + ' (*.lpi;*.lpr;*.lpk;*.pas;*.pp;*.inc;*.lfm;*.dfm)|' +
2675
'*.lpi;*.lpr;*.lpk;*.pas;*.pp;*.inc;*.lfm;*.dfm'
2676
+ '|' + lisLazarusUnit + ' (*.pas;*.pp)|*.pas;*.pp'
2677
+ '|' + lisLazarusProject + ' (*.lpi)|*.lpi'
2678
+ '|' + lisLazarusForm + ' (*.lfm;*.dfm)|*.lfm;*.dfm'
2679
+ '|' + lisLazarusPackage + ' (*.lpk)|*.lpk'
2680
+ '|' + lisLazarusProjectSource + ' (*.lpr)|*.lpr'
2681
+ '|' + dlgAllFiles + ' (' + GetAllFilesMask + ')|' + GetAllFilesMask;
2908
// set InitialDir to
2909
GetCurrentUnit(ASrcEdit,AnUnitInfo);
2910
if Assigned(AnUnitInfo) and (not AnUnitInfo.IsVirtual) then
2911
OpenDialog.InitialDir:=ExtractFilePath(AnUnitInfo.Filename);
2913
Filter := EnvironmentOptions.FileDialogFilter;
2915
// append a filter for all file types of the open files in the source editor
2916
CreateFileDialogFilterForSourceEditorFiles(Filter,AllEditorMask,AllMask);
2917
if (AllEditorMask<>'') then
2918
Filter:=Filter+ '|' + lisEditorFileTypes + ' (' + AllEditorMask + ')|' +
2921
// prepend an all normal files filter
2922
Filter:=lisLazarusFile + ' ('+AllMask+')|' + AllMask + '|' + Filter;
2924
// append an any files filter
2925
if TFileDialog.FindMaskInFilter(Filter,GetAllFilesMask)<1 then
2926
Filter:=Filter+ '|' + dlgAllFiles + ' (' + GetAllFilesMask + ')|' + GetAllFilesMask;
2928
OpenDialog.Filter := Filter;
2682
2930
if OpenDialog.Execute and (OpenDialog.Files.Count>0) then begin
2683
2931
OpenFlags:=[ofAddToRecent];
2684
2932
//debugln('TMainIDE.mnuOpenClicked OpenDialog.Files.Count=',dbgs(OpenDialog.Files.Count));
2685
2933
if OpenDialog.Files.Count>1 then
2686
2934
Include(OpenFlags,ofRegularFile);
2687
For I := 0 to OpenDialog.Files.Count-1 do
2689
AFilename:=CleanAndExpandFilename(OpenDialog.Files.Strings[i]);
2690
if i<OpenDialog.Files.Count-1 then
2691
Include(OpenFlags,ofMultiOpen)
2693
Exclude(OpenFlags,ofMultiOpen);
2694
if DoOpenEditorFile(AFilename,-1,-1,OpenFlags)=mrAbort then begin
2936
SourceEditorManager.IncUpdateLock;
2937
For I := 0 to OpenDialog.Files.Count-1 do
2939
AFilename:=CleanAndExpandFilename(OpenDialog.Files.Strings[i]);
2940
if i<OpenDialog.Files.Count-1 then
2941
Include(OpenFlags,ofMultiOpen)
2943
Exclude(OpenFlags,ofMultiOpen);
2944
if DoOpenEditorFile(AFilename,-1,-1,OpenFlags)=mrAbort then begin
2949
SourceEditorManager.DecUpdateLock;
2698
2951
UpdateEnvironment;
3644
3963
Editable: Boolean;
3645
3964
SelAvail: Boolean;
3646
3965
SelEditable: Boolean;
3648
GetCurrentUnit(ASrcEdit,AnUnitInfo);
3649
Editable:=(ASrcEdit<>nil) and (not ASrcEdit.ReadOnly);
3650
SelAvail:=(ASrcEdit<>nil) and (ASrcEdit.SelectionAvailable);
3966
SrcEditorActive: Boolean;
3967
ActiveDesigner: TComponentEditorDesigner;
3969
GetCurrentUnit(ASrcEdit, AnUnitInfo);
3970
Editable := Assigned(ASrcEdit) and not ASrcEdit.ReadOnly;
3971
SelAvail := Assigned(ASrcEdit) and ASrcEdit.SelectionAvailable;
3972
SelEditable := Editable and SelAvail;
3973
SrcEditorActive := FDisplayState = dsSource;
3974
ActiveDesigner := GetActiveDesignerSkipMainBar;
3977
if Assigned(ActiveDesigner) then
3979
// activate them when Designer start to support Undo/Redo
3980
itmEditUndo.Enabled := False;
3981
itmEditRedo.Enabled := False;
3982
itmEditCut.Enabled := ActiveDesigner.CanCopy;
3983
itmEditCopy.Enabled := itmEditCut.Enabled;
3984
itmEditPaste.Enabled := ActiveDesigner.CanPaste;
3988
itmEditUndo.Enabled := Editable and SrcEditorActive;
3989
itmEditRedo.Enabled := itmEditUndo.Enabled;
3990
itmEditCut.Enabled := SelEditable;
3991
itmEditCopy.Enabled := SelAvail;
3992
itmEditPaste.Enabled := Editable;
3994
//itmEditSelect: TIDEMenuSection; [...]
3995
//itmEditBlockActions: TIDEMenuSection;
3996
itmEditIndentBlock.Enabled := Editable;
3997
itmEditUnindentBlock.Enabled := Editable;
3998
itmEditUpperCaseBlock.Enabled := SelEditable;
3999
itmEditLowerCaseBlock.Enabled := SelEditable;
4000
itmEditSwapCaseBlock.Enabled := SelEditable;
4001
itmEditSortBlock.Enabled := SelEditable;
4002
itmEditTabsToSpacesBlock.Enabled := SelEditable;
4003
itmEditSelectionBreakLines.Enabled := SelEditable;
4004
itmEditInsertCharacter.Enabled := Editable;
4008
{------------------------------------------------------------------------------}
4010
procedure TMainIDE.mnuSourceClicked(Sender: TObject);
4012
ASrcEdit: TSourceEditor;
4013
AnUnitInfo: TUnitInfo;
4014
Editable, SelEditable, SelAvail, IdentFound, StringFound: Boolean;
4015
StartCode, EndCode: TCodeBuffer;
4016
StartPos, EndPos: TPoint;
4017
NewX, NewY, NewTopLine: integer;
4024
if BeginCodeTool(ASrcEdit,AnUnitInfo,[]) then begin
4025
Assert(Assigned(ASrcEdit));
4026
Editable:=not ASrcEdit.ReadOnly;
4027
SelAvail:=ASrcEdit.SelectionAvailable;
4029
// Try to find main identifier declaration to enable rename feature.
4030
CursorXY:=ASrcEdit.EditorComponent.LogicalCaretXY;
4031
IdentFound:=CodeToolBoss.FindMainDeclaration(AnUnitInfo.Source,
4032
CursorXY.X,CursorXY.Y,StartCode,NewX,NewY,NewTopLine);
4034
// Calculate start and end of string expr to enable ResourceString feature.
4035
if ASrcEdit.EditorComponent.SelAvail then
4036
CursorXY:=ASrcEdit.EditorComponent.BlockBegin;
4037
if CodeToolBoss.GetStringConstBounds(AnUnitInfo.Source,CursorXY.X,CursorXY.Y,
4038
StartCode,StartPos.X,StartPos.Y,
4039
EndCode,EndPos.X,EndPos.Y,true) then
4040
StringFound:=(StartCode<>EndCode) or (CompareCaret(StartPos,EndPos)<>0);
3651
4042
SelEditable:=Editable and SelAvail;
3652
4043
with MainIDEBar do begin
3653
itmEditUndo.Enabled:=Editable;
3654
itmEditRedo.Enabled:=Editable;
3655
//itmEditClipboard: TIDEMenuSection;
3656
itmEditCut.Enabled:=SelEditable;
3657
itmEditCopy.Enabled:=SelAvail;
3658
itmEditPaste.Enabled:=Editable;
3659
//itmEditBlockIndentation: TIDEMenuSection;
3660
itmEditIndentBlock.Enabled:=SelEditable;
3661
itmEditUnindentBlock.Enabled:=SelEditable;
3662
itmEditEncloseBlock.Enabled:=SelEditable;
3663
itmEditCommentBlock.Enabled:=SelEditable;
3664
itmEditUncommentBlock.Enabled:=SelEditable;
3665
itmEditConditionalBlock.Enabled:=SelEditable;
3666
itmEditSortBlock.Enabled:=SelEditable;
3667
//itmEditBlockCharConversion: TIDEMenuSection;
3668
itmEditUpperCaseBlock.Enabled:=SelEditable;
3669
itmEditLowerCaseBlock.Enabled:=SelEditable;
3670
itmEditTabsToSpacesBlock.Enabled:=SelEditable;
3671
itmEditSelectionBreakLines.Enabled:=SelEditable;
3672
//itmEditSelect: TIDEMenuSection;
3673
//itmEditSelectAll: TIDEMenuCommand;
3674
//itmEditSelectToBrace: TIDEMenuCommand;
3675
//itmEditSelectCodeBlock: TIDEMenuCommand;
3676
//itmEditSelectLine: TIDEMenuCommand;
3677
//itmEditSelectParagraph: TIDEMenuCommand;
3678
//itmEditInsertions: TIDEMenuSection;
3679
itmEditInsertCharacter.Enabled:=Editable;
3680
//itmEditInsertText: TIDEMenuSection;
3681
//itmEditInsertCVSKeyWord: TIDEMenuSection;
3682
itmEditInsertCVSAuthor.Enabled:=Editable;
3683
itmEditInsertCVSDate.Enabled:=Editable;
3684
itmEditInsertCVSHeader.Enabled:=Editable;
3685
itmEditInsertCVSID.Enabled:=Editable;
3686
itmEditInsertCVSLog.Enabled:=Editable;
3687
itmEditInsertCVSName.Enabled:=Editable;
3688
itmEditInsertCVSRevision.Enabled:=Editable;
3689
itmEditInsertCVSSource.Enabled:=Editable;
3690
//itmEditInsertGeneral: TIDEMenuSection;
3691
itmEditInsertGPLNotice.Enabled:=Editable;
3692
itmEditInsertLGPLNotice.Enabled:=Editable;
3693
itmEditInsertModifiedLGPLNotice.Enabled:=Editable;
3694
itmEditInsertUsername.Enabled:=Editable;
3695
itmEditInsertDateTime.Enabled:=Editable;
3696
itmEditInsertChangeLogEntry.Enabled:=Editable;
3697
//itmEditMenuCodeTools: TIDEMenuSection;
3698
itmEditCompleteCode.Enabled:=Editable;
3699
itmEditExtractProc.Enabled:=SelEditable;
4044
//itmSourceBlockActions
4045
itmSourceCommentBlock.Enabled:=SelEditable;
4046
itmSourceUncommentBlock.Enabled:=SelEditable;
4047
itmSourceEncloseBlock.Enabled:=SelEditable;
4048
itmSourceEncloseInIFDEF.Enabled:=SelEditable;
4049
itmSourceCompleteCode.Enabled:=Editable;
4050
itmSourceUseUnit.Enabled:=Editable;
4051
//itmSourceInsertions
4052
//itmSourceInsertCVSKeyWord
4053
itmSourceInsertCVSAuthor.Enabled:=Editable;
4054
itmSourceInsertCVSDate.Enabled:=Editable;
4055
itmSourceInsertCVSHeader.Enabled:=Editable;
4056
itmSourceInsertCVSID.Enabled:=Editable;
4057
itmSourceInsertCVSLog.Enabled:=Editable;
4058
itmSourceInsertCVSName.Enabled:=Editable;
4059
itmSourceInsertCVSRevision.Enabled:=Editable;
4060
itmSourceInsertCVSSource.Enabled:=Editable;
4061
//itmSourceInsertGeneral
4062
itmSourceInsertGPLNotice.Enabled:=Editable;
4063
itmSourceInsertLGPLNotice.Enabled:=Editable;
4064
itmSourceInsertModifiedLGPLNotice.Enabled:=Editable;
4065
itmSourceInsertMITNotice.Enabled:=Editable;
4066
itmSourceInsertUsername.Enabled:=Editable;
4067
itmSourceInsertDateTime.Enabled:=Editable;
4068
itmSourceInsertChangeLogEntry.Enabled:=Editable;
4070
//itmRefactorCodeTools
4071
itmRefactorRenameIdentifier.Enabled:=Editable and IdentFound;
4072
itmRefactorExtractProc.Enabled:=Editable and SelAvail;
4073
itmRefactorInvertAssignment.Enabled:=Editable and SelAvail;
4074
//itmRefactorAdvanced
4075
itmRefactorMakeResourceString.Enabled:=Editable and StringFound;
4079
procedure TMainIDE.mnuProjectClicked(Sender: TObject);
4081
ASrcEdit: TSourceEditor;
4082
AUnitInfo: TUnitInfo;
4083
NotPartOfProj: Boolean;
4085
GetCurrentUnit(ASrcEdit,AUnitInfo);
4086
NotPartOfProj:=Assigned(AUnitInfo) and not AUnitInfo.IsPartOfProject;
4087
MainIDEBar.itmProjectAddTo.Enabled:=NotPartOfProj;
4090
procedure TMainIDE.mnuPackageClicked(Sender: TObject);
4092
ASrcEdit: TSourceEditor;
4093
AUnitInfo: TUnitInfo;
4095
CanOpenPkgOfFile, CanAddCurFile: Boolean;
4097
CanOpenPkgOfFile:=False;
4098
CanAddCurFile:=False;
4099
GetCurrentUnit(ASrcEdit,AUnitInfo);
4100
if Assigned(ASrcEdit) then begin
4101
PkgFile:=PackageGraph.FindFileInAllPackages(AUnitInfo.Filename,true,
4102
not AUnitInfo.IsPartOfProject);
4103
CanOpenPkgOfFile:=Assigned(PkgFile);
4104
CanAddCurFile:=(not AUnitInfo.IsVirtual) and FileExistsUTF8(AUnitInfo.Filename)
4105
and not AUnitInfo.IsPartOfProject;
4107
MainIDEBar.itmPkgOpenPackageOfCurUnit.Enabled:=CanOpenPkgOfFile;
4108
MainIDEBar.itmPkgAddCurFileToPkg.Enabled:=CanAddCurFile;
3703
4111
{------------------------------------------------------------------------------}
4030
4449
//DebugLn(['TMainIDE.UpdateProjectPOFile Updating POFilename="',POFilename,'"']);
4032
Files := TStringList.Create;
4451
Files := TFilenameToPointerTree.Create(false);
4452
FileList:=TStringList.Create;
4034
4454
AnUnitInfo:=AProject.FirstPartOfProject;
4035
4455
while AnUnitInfo<>nil do begin
4036
4456
CurFilename:=AnUnitInfo.Filename;
4037
if (not AnUnitInfo.IsVirtual) and FilenameIsPascalSource(CurFilename) then
4457
AnUnitInfo:=AnUnitInfo.NextPartOfProject;
4458
if not FilenameIsAbsolute(CurFilename) then continue;
4459
if (AProject.MainFilename<>CurFilename)
4460
and (not FilenameIsPascalUnit(CurFilename)) then
4463
LRTFilename:=ChangeFileExt(CurFilename,'.lrt');
4464
if FileExistsCached(LRTFilename)
4465
and ((not POFileAgeValid) or (FileAgeCached(LRTFilename)>POFileAge)) then
4466
Files[LRTFilename]:=nil;
4468
RSTFilename:=ChangeFileExt(CurFilename,'.rst');
4469
// the compiler puts the .rst in the unit output directory if -FU is given
4470
if AProject.CompilerOptions.UnitOutputDirectory<>'' then
4040
LRTFilename:=ChangeFileExt(CurFilename,'.lrt');
4041
if FileExistsCached(LRTFilename)
4042
and ((not POFileAgeValid) or (FileAgeCached(LRTFilename)>POFileAge)) then
4043
Files.Add(LRTFilename);
4045
RSTFilename:=ExtractFileName(ChangeFileExt(CurFilename,'.rst'));
4047
// the compiler puts the .rst in the unit output directory
4048
4472
UnitOutputDir:=AProject.GetOutputDirectory;
4049
if UnitOutputDir='' then
4050
UnitOutputDir:=AProject.ProjectDirectory;
4052
RSTFilename:=TrimFilename(AppendPathDelim(UnitOutputDir)+RSTFilename);
4054
//DebugLn(['TMainIDE.UpdateProjectPOFile Looking for .rst file ="',RSTFilename,'"']);
4056
if FileExistsCached(RSTFilename)
4057
and ((not POFileAgeValid) or (FileAgeCached(RSTFilename)>POFileAge)) then
4058
Files.Add(RSTFilename);
4473
if UnitOutputDir<>'' then
4474
RSTFilename:=TrimFilename(AppendPathDelim(UnitOutputDir)+ExtractFilename(RSTFilename));
4060
AnUnitInfo:=AnUnitInfo.NextPartOfProject;
4476
//DebugLn(['TMainIDE.UpdateProjectPOFile Looking for .rst file ="',RSTFilename,'"']);
4477
if FileExistsCached(RSTFilename)
4478
and ((not POFileAgeValid) or (FileAgeCached(RSTFilename)>POFileAge)) then
4479
Files[RSTFilename]:=nil;
4483
if Files.Tree.Count=0 then exit(mrOk);
4484
Files.GetNames(FileList);
4064
UpdatePoFile(Files, POFilename);
4486
UpdatePoFileAndTranslations(FileList, POFilename);
4065
4487
Result := mrOk;
4067
4489
on E:EPOFileError do begin
4507
4954
SaveDesktopSettings(AOptions as TEnvironmentOptions);
4510
procedure TMainIDE.DoOpenIDEOptions(AEditor: TAbstractIDEOptionsEditorClass = nil;
4511
ACaption: String = ''; AOptionsFilter: TAbstractIDEOptionsClass = nil);
4957
procedure TMainIDE.DoOpenIDEOptions(AEditor: TAbstractIDEOptionsEditorClass;
4958
ACaption: String; AOptionsFilter: array of TAbstractIDEOptionsClass;
4959
ASettings: TIDEOptionsEditorSettings);
4513
4961
IDEOptionsDialog: TIDEOptionsDialog;
4962
OptionsFilter: TIDEOptionsEditorFilter;
4515
4965
IDEOptionsDialog := TIDEOptionsDialog.Create(nil);
4518
4967
if ACaption <> '' then
4519
4968
IDEOptionsDialog.Caption := ACaption;
4520
if AOptionsFilter = nil then
4969
if Length(AOptionsFilter) = 0 then
4971
SetLength(OptionsFilter, 1);
4521
4972
if AEditor <> nil then
4522
AOptionsFilter := AEditor.SupportedOptionsClass
4973
OptionsFilter[0] := AEditor.SupportedOptionsClass
4524
AOptionsFilter := TAbstractIDEEnvironmentOptions;
4525
IDEOptionsDialog.OptionsFilter := AOptionsFilter;
4526
//DebugLn(['TMainIDE.DoOpenIDEOptions ',DbgSName(IDEOptionsDialog.OptionsFilter)]);
4975
OptionsFilter[0] := TAbstractIDEEnvironmentOptions;
4979
SetLength(OptionsFilter, Length(AOptionsFilter));
4980
for i := 0 to Length(AOptionsFilter) - 1 do
4981
OptionsFilter[i] := AOptionsFilter[i];
4983
IDEOptionsDialog.OptionsFilter := OptionsFilter;
4984
IDEOptionsDialog.Settings := ASettings;
4527
4985
IDEOptionsDialog.OpenEditor(AEditor);
4529
with IDEOptionsDialog do
4531
OnLoadIDEOptions:=@Self.OnLoadIDEOptions;
4532
OnSaveIDEOptions:=@Self.OnSaveIDEOptions;
4986
IDEOptionsDialog.OnLoadIDEOptions:=@Self.OnLoadIDEOptions;
4987
IDEOptionsDialog.OnSaveIDEOptions:=@Self.OnSaveIDEOptions;
4988
IDEOptionsDialog.ReadAll;
4535
4989
if IDEOptionsDialog.ShowModal = mrOk then begin
4536
4990
IDEOptionsDialog.WriteAll(false);
4537
4991
UpdateHighlighters(True);
5459
function TMainIDE.NewUniqueComponentName(Prefix: string): string;
5461
function SearchProject(AProject: TProject; const Identifier: string): boolean;
5464
AnUnitInfo: TUnitInfo;
5466
if AProject=nil then exit(false);
5468
for i:=0 to AProject.UnitCount-1 do
5470
AnUnitInfo:=AProject.Units[i];
5471
if (AnUnitInfo.Component<>nil) then begin
5472
if CompareText(AnUnitInfo.Component.Name,Identifier)=0 then exit;
5473
if CompareText(AnUnitInfo.Component.ClassName,Identifier)=0 then exit;
5474
end else if (AnUnitInfo.ComponentName<>'')
5475
and ((AnUnitInfo.IsPartOfProject) or AnUnitInfo.Loaded) then begin
5476
if SysUtils.CompareText(AnUnitInfo.Unit_Name,Identifier)=0 then exit;
5477
if SysUtils.CompareText(AnUnitInfo.ComponentName,Identifier)=0 then exit;
5483
function SearchPackage(APackage: TLazPackage; const Identifier: string): boolean;
5488
if APackage=nil then exit(false);
5490
if SysUtils.CompareText(APackage.Name,Identifier)=0 then exit;
5491
for i:=0 to APackage.FileCount-1 do
5493
PkgFile:=APackage.Files[i];
5494
if SysUtils.CompareText(PkgFile.Unit_Name,Identifier)=0 then exit;
5499
function IdentifierExists(Identifier: string): boolean;
5504
if GetClass(Identifier)<>nil then exit;
5505
if SearchProject(Project1,Identifier) then exit;
5506
for i:=0 to PackageGraph.Count-1 do
5507
if SearchPackage(PackageGraph[i],Identifier) then exit;
5511
function IdentifierIsOk(Identifier: string): boolean;
5514
if (Identifier='') or not IsValidIdent(Identifier) then exit;
5515
if AllKeyWords.DoIdentifier(PChar(Identifier)) then exit;
5516
if IdentifierExists(Identifier) then exit;
5517
if IdentifierExists('T'+Identifier) then exit;
5524
if IdentifierIsOk(Prefix) then
5526
while (Prefix<>'') and (Prefix[length(Prefix)] in ['0'..'9']) do
5527
System.Delete(Prefix,length(Prefix),1);
5528
if (Prefix='') or (not IsValidIdent(Prefix)) then
5533
Result:=Prefix+IntToStr(i);
5534
until IdentifierIsOk(Result);
4978
5537
function TMainIDE.DoLoadResourceFile(AnUnitInfo: TUnitInfo;
4979
var LFMCode, ResourceCode: TCodeBuffer;
5538
var LFMCode, LRSCode: TCodeBuffer;
4980
5539
IgnoreSourceErrors, AutoCreateResourceCode, ShowAbort: boolean): TModalResult;
5541
LfmSuffices: array[0..1] of string = ('.lfm', '.dfm');
4982
5543
LFMFilename: string;
4983
5544
LRSFilename: String;
4984
5545
ResType: TResourceType;
4988
5550
//DebugLn(['TMainIDE.DoLoadResourceFile ',AnUnitInfo.Filename,' HasResources=',AnUnitInfo.HasResources,' IgnoreSourceErrors=',IgnoreSourceErrors,' AutoCreateResourceCode=',AutoCreateResourceCode]);
5551
// Load the lfm file (without parsing)
5552
if not AnUnitInfo.IsVirtual then begin // and (AnUnitInfo.Component<>nil)
5553
for i := Low(LfmSuffices) to High(LfmSuffices) do begin
5554
LFMFilename:=ChangeFileExt(AnUnitInfo.Filename,LfmSuffices[i]);
5555
if (FileExistsUTF8(LFMFilename)) then begin
5556
Result:=LoadCodeBuffer(LFMCode,LFMFilename,[lbfCheckIfText],ShowAbort);
5557
if not (Result in [mrOk,mrIgnore]) then
4989
5563
if AnUnitInfo.HasResources then begin
4990
5564
//writeln('TMainIDE.DoLoadResourceFile A "',AnUnitInfo.Filename,'" "',AnUnitInfo.ResourceFileName,'"');
4992
5565
ResType:=MainBuildBoss.GetResourceType(AnUnitInfo);
4993
5566
if ResType=rtLRS then begin
4994
5567
LRSFilename:=MainBuildBoss.FindLRSFilename(AnUnitInfo,false);
4995
5568
if LRSFilename<>'' then begin
4996
Result:=LoadCodeBuffer(ResourceCode,LRSFilename,[lbfUpdateFromDisk],ShowAbort);
5569
Result:=LoadCodeBuffer(LRSCode,LRSFilename,[lbfUpdateFromDisk],ShowAbort);
4997
5570
if Result<>mrOk then exit;
4999
5572
LRSFilename:=MainBuildBoss.GetDefaultLRSFilename(AnUnitInfo);
5000
5573
if AutoCreateResourceCode then begin
5001
ResourceCode:=CodeToolBoss.CreateFile(LRSFilename);
5574
LRSCode:=CodeToolBoss.CreateFile(LRSFilename);
5003
5576
DebugLn(['TMainIDE.DoLoadResourceFile .lrs file not found of unit ',AnUnitInfo.Filename]);
5004
5577
exit(mrCancel);
5476
6084
// if resource name has changed, delete old resource
5477
6085
if (AnUnitInfo.ComponentName<>AnUnitInfo.ComponentResourceName)
5478
6086
and (AnUnitInfo.ComponentResourceName<>'') then begin
5479
CodeToolBoss.RemoveLazarusResource(ResourceCode,
6087
CodeToolBoss.RemoveLazarusResource(LRSCode,
5480
6088
'T'+AnUnitInfo.ComponentResourceName);
5482
6090
// add comment to resource file (if not already exists)
5483
if (not CodeToolBoss.AddLazarusResourceHeaderComment(ResourceCode,
6091
if (not CodeToolBoss.AddLazarusResourceHeaderComment(LRSCode,LRSComment)) then
5486
6093
ACaption:=lisResourceSaveError;
5487
6094
AText:=Format(lisUnableToAddResourceHeaderCommentToResourceFile, [
5488
#13, '"', ResourceCode.FileName, '"', #13]);
5489
Result:=MessageDlg(ACaption,AText,mtError,[mbIgnore,mbAbort],0);
6095
#13, '"', LRSCode.FileName, '"', #13]);
6096
Result:=IDEMessageDialog(ACaption,AText,mtError,[mbIgnore,mbAbort]);
5490
6097
if Result<>mrIgnore then exit;
5492
6099
// add resource to resource file
5493
if (not CodeToolBoss.AddLazarusResource(ResourceCode,
6100
if (not CodeToolBoss.AddLazarusResource(LRSCode,
5494
6101
'T'+AnUnitInfo.ComponentName,CompResourceCode)) then
5496
6103
ACaption:=lisResourceSaveError;
5498
6105
lisUnableToAddResourceTFORMDATAToResourceFileProbably, [
5499
6106
AnUnitInfo.ComponentName,
5500
#13, '"', ResourceCode.FileName, '"', #13]
6107
#13, '"', LRSCode.FileName, '"', #13]
5502
Result:=MessageDlg(ACaption, AText, mtError, [mbIgnore, mbAbort],0);
6109
Result:=IDEMessageDialog(ACaption, AText, mtError, [mbIgnore, mbAbort]);
5503
6110
if Result<>mrIgnore then exit;
5505
6112
AnUnitInfo.ComponentResourceName:=AnUnitInfo.ComponentName;
5508
ResourceCode.Source:=CompResourceCode;
6115
LRSCode.Source:=CompResourceCode;
5614
6221
writeln('TMainIDE.SaveFileResources F ',ResourceCode.Modified);
5616
6223
// save binary stream (.lrs)
5617
if ResourceCode<>nil then begin
6224
if LRSCode<>nil then begin
5618
6225
if (not (sfSaveToTestDir in Flags)) then
5620
if (ResourceCode.Modified) then begin
5621
if FilenameIsAbsolute(ResourceCode.Filename) then
5622
LRSFilename:=ResourceCode.Filename
6227
if (LRSCode.Modified) then begin
6228
if FilenameIsAbsolute(LRSCode.Filename) then
6229
LRSFilename:=LRSCode.Filename
5623
6230
else if LRSFilename='' then
5624
6231
LRSFilename:=MainBuildBoss.FindLRSFilename(AnUnitInfo,true);
5625
Result:=ForceDirectoryInteractive(ExtractFilePath(LRSFilename),[mbRetry]);
5626
if not Result=mrOk then exit;
5627
Result:=SaveCodeBufferToFile(ResourceCode,LRSFilename);
5628
if not Result=mrOk then exit;
6232
if (LRSFilename<>'') and FilenameIsAbsolute(LRSFilename) then
6234
Result:=ForceDirectoryInteractive(ExtractFilePath(LRSFilename),[mbRetry]);
6235
if not Result=mrOk then exit;
6236
Result:=SaveCodeBufferToFile(LRSCode,LRSFilename);
6237
if not Result=mrOk then exit;
5631
6241
TestFilename:=MainBuildBoss.GetTestUnitFilename(AnUnitInfo);
5632
Result:=SaveCodeBufferToFile(ResourceCode,
5633
ChangeFileExt(TestFilename,
5634
ExtractFileExt(ResourceCode.Filename)));
6242
LRSFilename:=ChangeFileExt(TestFilename,ExtractFileExt(LRSCode.Filename));
6243
Result:=SaveCodeBufferToFile(LRSCode,LRSFilename);
5635
6244
if not Result=mrOk then exit;
5699
6310
OldPPUFilename: String;
5700
6311
OutDir: string;
5701
6312
Owners: TFPList;
5702
LFMBuf: TCodeBuffer;
6313
OldFileExisted: Boolean;
6314
ConvTool: TConvDelphiCodeTool;
5704
6316
Project1.BeginUpdate(false);
5706
6318
OldFilename:=AnUnitInfo.Filename;
5707
6319
OldFilePath:=ExtractFilePath(OldFilename);
5708
OldLFMFilename:=ChangeFileExt(OldFilename,'.lfm');
5709
if not FileExistsUTF8(OldLFMFilename) then
5710
OldLFMFilename:=ChangeFileExt(OldFilename,'.dfm');
6321
if FilenameIsPascalUnit(OldFilename) then begin
6322
OldLFMFilename:=ChangeFileExt(OldFilename,'.lfm');
6323
if not FileExistsUTF8(OldLFMFilename) then
6324
OldLFMFilename:=ChangeFileExt(OldFilename,'.dfm');
5711
6326
if NewUnitName='' then
5712
6327
NewUnitName:=AnUnitInfo.Unit_Name;
5713
debugln(['TMainIDE.DoRenameUnit ',AnUnitInfo.Filename,' NewUnitName=',NewUnitName,' OldUnitName=',AnUnitInfo.Unit_Name,' ResourceCode=',ResourceCode<>nil,' NewFilename="',NewFilename,'"']);
6328
debugln(['TMainIDE.DoRenameUnit ',AnUnitInfo.Filename,' NewUnitName=',NewUnitName,' OldUnitName=',AnUnitInfo.Unit_Name,' LFMCode=',LFMCode<>nil,' LRSCode=',LRSCode<>nil,' NewFilename="',NewFilename,'"']);
5715
6330
// check new resource file
5716
NewLFMFilename:=ChangeFileExt(NewFilename,'.lfm');
6332
if FilenameIsPascalUnit(NewFilename) then
6333
NewLFMFilename:=ChangeFileExt(NewFilename,'.lfm');
5717
6334
if AnUnitInfo.ComponentName='' then begin
5718
6335
// unit has no component
5719
6336
// -> remove lfm file, so that it will not be auto loaded on next open
5720
6337
if (FileExistsUTF8(NewLFMFilename))
5721
6338
and (not DeleteFileUTF8(NewLFMFilename))
5722
and (MessageDlg(lisPkgMangDeleteFailed, Format(lisDeletingOfFileFailed, [
5723
'"', NewLFMFilename, '"']), mtError, [mbIgnore, mbCancel], 0)=mrCancel)
6339
and (IDEMessageDialog(lisPkgMangDeleteFailed, Format(lisDeletingOfFileFailed, [
6340
'"', NewLFMFilename, '"']), mtError, [mbIgnore, mbCancel])=mrCancel)
5726
6343
Result:=mrCancel;
6387
if FilenameIsAbsolute(NewLFMFilename) then begin
6389
and (OldLFMFilename<>'')
6390
and FilenameIsAbsolute(OldLFMFilename) and FileExistsUTF8(OldLFMFilename) then
6391
LFMCode:=CodeToolBoss.LoadFile(OldLFMFilename,false,false);
6392
if (LFMCode<>nil) then begin
6393
Result:=SaveCodeBufferToFile(LFMCode,NewLFMFilename,true);
6394
if not (Result in [mrOk,mrIgnore]) then begin
6395
DebugLn(['TMainIDE.DoRenameUnit SaveCodeBufferToFile failed for "',NewLFMFilename,'"']);
6398
LFMCode:=CodeToolBoss.LoadFile(NewLFMFilename,true,false);
6399
if LFMCode<>nil then
6400
NewLFMFilename:=LFMCode.Filename;
6401
ConvTool:=TConvDelphiCodeTool.Create(NewSource);
6403
if not ConvTool.RenameResourceDirectives then
6404
debugln(['TMainIDE.DoRenameUnit WARNING: unable to rename resource directive in "',NewSource.Filename,'"']);
5769
6411
// rename Resource file (.lrs)
5770
if (ResourceCode<>nil) then begin
6412
if (LRSCode<>nil) then begin
5771
6413
// the resource include line in the code will be changed later after
5772
6414
// changing the unitname
5773
6415
if AnUnitInfo.IsPartOfProject
5774
6416
and (not Project1.IsVirtual)
5775
6417
and (pfLRSFilesInOutputDirectory in Project1.Flags) then begin
5776
NewResFilename:=MainBuildBoss.GetDefaultLRSFilename(AnUnitInfo);
5777
NewResFilename:=AppendPathDelim(ExtractFilePath(NewResFilename))
6418
NewLRSFilename:=MainBuildBoss.GetDefaultLRSFilename(AnUnitInfo);
6419
NewLRSFilename:=AppendPathDelim(ExtractFilePath(NewLRSFilename))
5778
6420
+ExtractFileNameOnly(NewFilename)+ResourceFileExt;
5780
OldResFilePath:=ExtractFilePath(ResourceCode.Filename);
5781
NewResFilePath:=OldResFilePath;
6422
OldLRSFilePath:=ExtractFilePath(LRSCode.Filename);
6423
NewLRSFilePath:=OldLRSFilePath;
5782
6424
if FilenameIsAbsolute(OldFilePath)
5783
and FileIsInPath(OldResFilePath,OldFilePath) then begin
6425
and FileIsInPath(OldLRSFilePath,OldFilePath) then begin
5784
6426
// resource code was in the same or in a sub directory of source
5785
6427
// -> try to keep this relationship
5786
NewResFilePath:=NewFilePath
5787
+copy(ResourceCode.Filename,length(OldFilePath)+1,
5788
length(ResourceCode.Filename));
5789
if not DirPathExists(NewResFilePath) then
5790
NewResFilePath:=NewFilePath;
6428
NewLRSFilePath:=NewFilePath
6429
+copy(LRSCode.Filename,length(OldFilePath)+1,
6430
length(LRSCode.Filename));
6431
if not DirPathExists(NewLRSFilePath) then
6432
NewLRSFilePath:=NewFilePath;
5792
6434
// resource code was not in the same or in a sub directory of source
5793
6435
// copy resource into the same directory as the source
5794
NewResFilePath:=NewFilePath;
6436
NewLRSFilePath:=NewFilePath;
5796
NewResFilename:=NewResFilePath
6438
NewLRSFilename:=NewLRSFilePath
5797
6439
+ExtractFileNameOnly(NewFilename)+ResourceFileExt;
5799
Result:=ForceDirectoryInteractive(ExtractFilePath(NewResFilename),[mbRetry,mbIgnore]);
6441
Result:=ForceDirectoryInteractive(ExtractFilePath(NewLRSFilename),[mbRetry,mbIgnore]);
5800
6442
if Result=mrCancel then exit;
5801
6443
if Result=mrOk then begin
5802
if not CodeToolBoss.SaveBufferAs(ResourceCode,NewResFilename,ResourceCode)
6444
if not CodeToolBoss.SaveBufferAs(LRSCode,NewLRSFilename,LRSCode)
5804
DebugLn(['TMainIDE.DoRenameUnit CodeToolBoss.SaveBufferAs failed: NewResFilename="',NewResFilename,'"']);
6446
DebugLn(['TMainIDE.DoRenameUnit CodeToolBoss.SaveBufferAs failed: NewResFilename="',NewLRSFilename,'"']);
5807
6449
{$IFDEF IDE_DEBUG}
7336
7983
//DebugLn(['TMainIDE.UnitComponentIsUsed ',AnUnitInfo.Filename,' ',dbgs(AnUnitInfo.Flags)]);
7986
function TMainIDE.RemoveFilesFromProject(AProject: TProject; UnitInfos: TFPList
7990
AnUnitInfo: TUnitInfo;
7991
ShortUnitName: String;
7993
ObsoleteUnitPaths: String;
7994
ObsoleteIncPaths: String;
7996
ProjUnitPaths: String;
7998
ResolvedDir: String;
8000
ProjIncPaths: String;
8003
if UnitInfos=nil then exit;
8004
// check if something will change
8005
i:=UnitInfos.Count-1;
8006
while (i>=0) and (not TUnitInfo(UnitInfos[i]).IsPartOfProject) do dec(i);
8007
if i<0 then exit(mrOk);
8009
if (ToolStatus in [itCodeTools,itCodeToolAborting]) then begin
8010
debugln('TMainIDE.RemoveUnitsFromProject wrong ToolStatus ',dbgs(ord(ToolStatus)));
8013
// commit changes from source editor to codetools
8014
SaveSourceEditorChangesToCodeCache(nil);
8016
ObsoleteUnitPaths:='';
8017
ObsoleteIncPaths:='';
8018
AProject.BeginUpdate(true);
8020
for i:=0 to UnitInfos.Count-1 do begin
8021
AnUnitInfo:=TUnitInfo(UnitInfos[i]);
8022
//debugln(['TMainIDE.RemoveUnitsFromProject Unit ',AnUnitInfo.Filename]);
8023
if not AnUnitInfo.IsPartOfProject then continue;
8024
AnUnitInfo.IsPartOfProject:=false;
8025
AProject.Modified:=true;
8026
if FilenameIsPascalUnit(AnUnitInfo.Filename) then begin
8027
if FilenameIsAbsolute(AnUnitInfo.Filename) then
8028
ObsoleteUnitPaths:=MergeSearchPaths(ObsoleteUnitPaths,
8029
ChompPathDelim(ExtractFilePath(AnUnitInfo.Filename)));
8030
// remove from project's unit section
8031
if (AProject.MainUnitID>=0)
8032
and (pfMainUnitHasUsesSectionForAllUnits in AProject.Flags)
8034
ShortUnitName:=ExtractFileNameOnly(AnUnitInfo.Filename);
8035
//debugln(['TMainIDE.RemoveUnitsFromProject UnitName=',ShortUnitName]);
8036
if (ShortUnitName<>'') then begin
8037
Dummy:=CodeToolBoss.RemoveUnitFromAllUsesSections(
8038
AProject.MainUnitInfo.Source,ShortUnitName);
8039
if not Dummy then begin
8040
DoJumpToCodeToolBossError;
8046
// remove CreateForm statement from project
8047
if (AProject.MainUnitID>=0)
8048
and (pfMainUnitHasCreateFormStatements in AProject.Flags)
8049
and (AnUnitInfo.ComponentName<>'') then begin
8050
Dummy:=AProject.RemoveCreateFormFromProjectFile(
8051
'T'+AnUnitInfo.ComponentName,AnUnitInfo.ComponentName);
8052
if not Dummy then begin
8053
DoJumpToCodeToolBossError;
8059
if CompareFileExt(AnUnitInfo.Filename,'.inc',false)=0 then begin
8061
if FilenameIsAbsolute(AnUnitInfo.Filename) then
8062
ObsoleteIncPaths:=MergeSearchPaths(ObsoleteIncPaths,
8063
ChompPathDelim(ExtractFilePath(AnUnitInfo.Filename)));
8067
// removed directories still used fomr ObsoleteUnitPaths, ObsoleteIncPaths
8068
AnUnitInfo:=AProject.FirstPartOfProject;
8069
while AnUnitInfo<>nil do begin
8070
if FilenameIsAbsolute(AnUnitInfo.Filename) then begin
8071
if FilenameIsPascalUnit(AnUnitInfo.Filename) then
8072
ObsoleteUnitPaths:=RemoveSearchPaths(ObsoleteUnitPaths,
8073
ChompPathDelim(ExtractFilePath(AnUnitInfo.Filename)));
8074
if CompareFileExt(AnUnitInfo.Filename,'.inc',false)=0 then
8075
ObsoleteIncPaths:=RemoveSearchPaths(ObsoleteIncPaths,
8076
ChompPathDelim(ExtractFilePath(AnUnitInfo.Filename)));
8078
AnUnitInfo:=AnUnitInfo.NextPartOfProject;
8081
// check if compiler options contain paths of ObsoleteUnitPaths
8082
if ObsoleteUnitPaths<>'' then begin
8083
ProjUnitPaths:=AProject.CompilerOptions.OtherUnitFiles;
8087
CurDir:=GetNextDirectoryInSearchPath(ProjUnitPaths,p);
8088
if CurDir='' then break;
8089
ResolvedDir:=AProject.CompilerOptions.ParsedOpts.DoParseOption(CurDir,
8090
pcosUnitPath,false);
8091
if (ResolvedDir<>'')
8092
and (SearchDirectoryInSearchPath(ObsoleteUnitPaths,ResolvedDir)>0) then begin
8093
if IDEQuestionDialog(lisRemoveUnitPath,
8094
Format(lisTheDirectoryContainsNoProjectUnitsAnyMoreRemoveThi, [CurDir]),
8095
mtConfirmation, [mrYes, lisRemove, mrNo, lisKeep2], '')=mrYes
8098
ProjUnitPaths:=RemoveSearchPaths(ProjUnitPaths,CurDir);
8103
AProject.CompilerOptions.OtherUnitFiles:=ProjUnitPaths;
8106
// check if compiler options contain paths of ObsoleteIncPaths
8107
if ObsoleteIncPaths<>'' then begin
8108
ProjIncPaths:=AProject.CompilerOptions.IncludePath;
8112
CurDir:=GetNextDirectoryInSearchPath(ProjIncPaths,p);
8113
if CurDir='' then break;
8114
ResolvedDir:=AProject.CompilerOptions.ParsedOpts.DoParseOption(CurDir,
8115
pcosIncludePath,false);
8116
if (ResolvedDir<>'')
8117
and (SearchDirectoryInSearchPath(ObsoleteIncPaths,ResolvedDir)>0) then begin
8118
if IDEQuestionDialog(lisRemoveIncludePath,
8119
Format(lisTheDirectoryContainsNoProjectIncludeFilesAnyMoreRe, [CurDir]),
8120
mtConfirmation, [mrYes, lisRemove, mrNo, lisKeep2], '')=mrYes
8123
ProjIncPaths:=RemoveSearchPaths(ProjIncPaths,CurDir);
8128
AProject.CompilerOptions.IncludePath:=ProjIncPaths;
8132
ApplyCodeToolChanges;
7339
8137
function TMainIDE.GetAncestorUnit(AnUnitInfo: TUnitInfo): TUnitInfo;
7341
8139
if (AnUnitInfo=nil) or (AnUnitInfo.Component=nil) then
7839
8633
//DebugLn(['TMainIDE.DoShowSaveProjectAsDialog END OK']);
8636
function TMainIDE.AskSaveProject(const ContinueText, ContinueBtn: string): TModalResult;
8638
DataModified: Boolean;
8639
SrcModified: Boolean;
8641
if Project1=nil then exit(mrOk);
8642
//debugln(['TMainIDE.AskSaveProject SomethingOfProjectIsModified=',SomethingOfProjectIsModified,' Project1.SomeDataModified(false)=',Project1.SomeDataModified(false)]);
8643
if not SomethingOfProjectIsModified then exit(mrOk);
8645
DataModified:=Project1.SomeDataModified(false);
8646
SrcModified:=SourceEditorManager.SomethingModified(false);
8648
if Project1.IsVirtual
8649
and (not DataModified)
8650
and (not SrcModified) then begin
8651
// only session changed of a new project => ignore
8655
if (Project1.SessionStorage=pssInProjectInfo)
8658
// lpi file will change => ask
8659
Result:=IDEQuestionDialog(lisProjectChanged,
8660
Format(lisSaveChangesToProject, [Project1.GetTitleOrName]),
8661
mtConfirmation, [mrYes, mrNoToAll, lisNo, mbCancel], '');
8662
if Result=mrNoToAll then exit(mrOk);
8663
if Result<>mrYes then exit(mrCancel);
8665
else if SrcModified then
8667
// some non project files were changes in the source editor
8668
Result:=IDEQuestionDialog(lisSaveChangedFiles,lisSaveChangedFiles,
8669
mtConfirmation, [mrYes, mrNoToAll, lisNo, mbCancel], '');
8670
if Result=mrNoToAll then exit(mrOk);
8671
if Result<>mrYes then exit(mrCancel);
8674
// only session data changed
8675
if Project1.SessionStorage=pssNone then
8676
// session is not saved => skip
8678
else if not SomethingOfProjectIsModified then
8682
// session is saved separately
8683
if EnvironmentOptions.AskSaveSessionOnly then begin
8684
Result:=IDEQuestionDialog(lisProjectSessionChanged,
8685
Format(lisSaveSessionChangesToProject, [Project1.GetTitleOrName]),
8686
mtConfirmation, [mrYes, mrNoToAll, lisNo, mbCancel], '');
8687
if Result=mrNoToAll then exit(mrOk);
8688
if Result<>mrYes then exit(mrCancel);
8692
Result:=DoSaveProject([sfCanAbort]);
8693
if Result=mrAbort then exit;
8694
if Result<>mrOk then begin
8695
Result:=IDEQuestionDialog(lisChangesWereNotSaved,
8697
mtConfirmation, [mrOk, ContinueBtn, mrAbort]);
8698
if Result<>mrOk then exit(mrCancel);
7842
8702
function TMainIDE.DoCompleteLoadingProjectInfo: TModalResult;
7845
8705
EnvironmentOptions.LastSavedProjectFile:=Project1.ProjectInfoFile;
7846
EnvironmentOptions.Save(false);
7848
MainBuildBoss.RescanCompilerDefines(true,false,false);
8708
MainBuildBoss.SetBuildTargetProject1(false);
7850
8710
// load required packages
7851
8711
PkgBoss.OpenProjectDependencies(Project1,true);
8904
Result:=NewFileDescriptor.Init(NewFilename,NewOwner,NewSource,nfQuiet in NewFlags);
8905
if Result<>mrOk then exit;
8907
if FilenameIsAbsolute(NewFilename) and DirectoryExistsUTF8(NewFilename) then
8909
IDEMessageDialog(lisFileIsDirectory,
8910
lisUnableToCreateNewFileBecauseThereIsAlreadyADirecto,
8911
mtError,[mbCancel]);
8042
8915
if NewOwner is TProject then
8043
8916
AProject:=TProject(NewOwner)
8045
8918
AProject:=Project1;
8919
if NewOwner is TLazPackage then
8920
APackage:=TLazPackage(NewOwner)
8924
OldUnitIndex:=AProject.IndexOfFilename(NewFilename);
8925
if OldUnitIndex>=0 then begin
8926
// the file is not really new
8928
Result:=CloseUnitComponent(AProject.Units[OldUnitIndex],
8929
[cfCloseDependencies,cfSaveDependencies]);
8930
if Result<>mrOk then
8932
debugln(['TMainIDE.DoNewFile CloseUnitComponent failed']);
8937
IsPartOfProject:=(nfIsPartOfProject in NewFlags)
8938
or (NewOwner is TProject)
8939
or (AProject.FileIsInProjectDir(NewFilename)
8940
and (not (nfIsNotPartOfProject in NewFlags)));
8942
// add required packages
8943
//debugln(['TMainIDE.DoNewFile NewFileDescriptor.RequiredPackages="',NewFileDescriptor.RequiredPackages,'" ',DbgSName(NewFileDescriptor)]);
8944
RequiredPackages:=NewFileDescriptor.RequiredPackages;
8945
if (RequiredPackages='') and (NewFileDescriptor.ResourceClass<>nil) then
8947
if (NewFileDescriptor.ResourceClass.InheritsFrom(TForm))
8948
or (NewFileDescriptor.ResourceClass.InheritsFrom(TFrame)) then
8949
RequiredPackages:='LCL';
8951
if RequiredPackages<>'' then
8953
if IsPartOfProject then begin
8954
Result:=PkgBoss.AddProjectDependencies(Project1,RequiredPackages);
8955
if Result<>mrOk then
8957
debugln(['TMainIDE.DoNewFile PkgBoss.AddProjectDependencies failed RequiredPackages="',RequiredPackages,'"']);
8961
if APackage<>nil then
8963
Result:=PkgBoss.AddPackageDependency(APackage,RequiredPackages);
8964
if Result<>mrOk then
8966
debugln(['TMainIDE.DoNewFile PkgBoss.AddPackageDependency failed RequiredPackages="',RequiredPackages,'"']);
8972
// check if the new file fits
8973
Result:=NewFileDescriptor.CheckOwner(nfQuiet in NewFlags);
8974
if Result<>mrOk then
8976
debugln(['TMainIDE.DoNewFile NewFileDescriptor.CheckOwner failed NewFilename="',NewFilename,'"']);
8047
8980
// create new codebuffer and apply naming conventions
8048
8983
Result:=CreateNewCodeBuffer(NewFileDescriptor,NewOwner,NewFilename,NewBuffer,
8050
if Result<>mrOk then exit;
8985
if Result<>mrOk then
8987
debugln(['TMainIDE.DoNewFile CreateNewCodeBuffer failed NewFilename="',NewFilename,'"']);
8052
8990
NewFilename:=NewBuffer.Filename;
8053
OldUnitIndex:=AProject.IndexOfFilename(NewFilename);
8054
8992
if OldUnitIndex>=0 then begin
8055
8993
// the file is not really new
8056
8994
NewUnitInfo:=AProject.Units[OldUnitIndex];
8058
Result:=CloseUnitComponent(NewUnitInfo,
8059
[cfCloseDependencies,cfSaveDependencies]);
8060
if Result<>mrOk then exit;
8061
8995
// assign source
8062
8996
NewUnitInfo.Source:=NewBuffer;
8244
9181
PkgBoss.DoNewPackage;
8246
MessageDlg(ueNotImplCap,
9183
IDEMessageDialog(ueNotImplCap,
8247
9184
lisSorryThisTypeIsNotYetImplemented,
8248
mtInformation,[mbOk],0);
8252
function TMainIDE.DoSaveEditorFile(PageIndex:integer;
8253
Flags: TSaveFlags):TModalResult;
9185
mtInformation,[mbOk]);
9189
procedure TMainIDE.CreateFileDialogFilterForSourceEditorFiles(Filter: string;
9190
out AllEditorMask, AllMask: string);
9191
// Filter: a TFileDialog filter, e.g. Pascal|*.pas;*.pp|Text|*.txt
9192
// AllEditorExt: a mask for all open files in the source editor, that are not
9193
// in Filter, e.g. '*.txt;*.xml'
9194
// AllFilter: all masks of Filter and AllEditorExt, e.g. '*.pas;*.pp;*.inc'
9197
SrcEdit: TSourceEditor;
9200
AllMask:='|'+TFileDialog.ExtractAllFilterMasks(Filter);
9202
for i:=0 to SourceEditorManager.SourceEditorCount-1 do begin
9203
SrcEdit:=SourceEditorManager.SourceEditors[i];
9204
Ext:=ExtractFileExt(SrcEdit.FileName);
9205
if Ext<>'' then begin
9207
if (TFileDialog.FindMaskInFilter(AllMask,Ext)>0)
9208
or (TFileDialog.FindMaskInFilter(AllEditorMask,Ext)>0) then continue;
9209
if AllEditorMask<>'|' then
9210
AllEditorMask:=AllEditorMask+';';
9211
AllEditorMask:=AllEditorMask+Ext;
9214
System.Delete(AllMask,1,1);
9215
System.Delete(AllEditorMask,1,1);
9216
if AllEditorMask<>'' then begin
9218
AllMask:=AllMask+';';
9219
AllMask:=AllMask+AllEditorMask;
9223
function TMainIDE.DoSaveEditorFile(PageIndex:integer; Flags: TSaveFlags):TModalResult;
8255
9225
Result := DoSaveEditorFile(
8256
9226
SourceEditorManager.ActiveSourceWindow.FindSourceEditorWithPageIndex(PageIndex),
8795
9753
// check if the project knows this file
8796
if (not (ofRevert in Flags)) then begin
8797
UnitIndex:=Project1.IndexOfFilename(AFilename);
8798
ReOpen:=(UnitIndex>=0);
8799
if ReOpen then begin
8800
NewUnitInfo:=Project1.Units[UnitIndex];
8801
if AEditorInfo <> nil then
8802
NewEditorInfo := AEditorInfo
8803
else if (ofProjectLoading in Flags) then
8804
NewEditorInfo := NewUnitInfo.GetClosedOrNewEditorInfo
8806
NewEditorInfo := NewUnitInfo.EditorInfo[0];
8807
if (ofAddToProject in Flags) and (not NewUnitInfo.IsPartOfProject) then
8809
NewUnitInfo.IsPartOfProject:=true;
8810
Project1.Modified:=true;
8812
if (not (ofProjectLoading in Flags)) and (NewEditorInfo.EditorComponent <> nil) then
8814
//DebugLn(['TMainIDE.DoOpenEditorFile file already open ',NewUnitInfo.Filename,' WindowIndex=',NewEditorInfo.WindowIndex,' PageIndex=',NewEditorInfo.PageIndex]);
8815
// file already open -> change source notebook page
8816
SourceEditorManager.ActiveSourceWindowIndex := NewEditorInfo.WindowIndex;
8817
SourceEditorManager.ActiveSourceWindow.PageIndex:= NewEditorInfo.PageIndex;
8818
if ofDoLoadResource in Flags then
8819
Result:=OpenResource
9754
if (ofRevert in Flags) then begin
9756
UnknownFile := False;
8827
9757
NewEditorInfo := Project1.EditorInfoWithEditorComponent(
8828
9758
SourceEditorManager.SourceEditorsByPage[WindowIndex, PageIndex]);
8829
9759
NewUnitInfo := NewEditorInfo.UnitInfo;
8830
9760
UnitIndex:=Project1.IndexOf(NewUnitInfo);
8831
9761
AFilename:=NewUnitInfo.Filename;
9762
if CompareFilenames(AFileName,DiskFilename)=0 then
9763
AFileName:=DiskFilename;
8832
9764
if NewUnitInfo.IsVirtual then begin
8833
9765
if (not (ofQuiet in Flags)) then begin
8834
MessageDlg(lisRevertFailed, Format(lisFileIsVirtual, ['"', AFilename,
9766
IDEMessageDialog(lisRevertFailed, Format(lisFileIsVirtual, ['"', AFilename,
8836
mtInformation,[mbCancel],0);
9768
mtInformation,[mbCancel]);
8838
9770
Result:=mrCancel;
8842
if (ofAddToProject in Flags) and (not NewUnitInfo.IsPartOfProject) then
8844
NewUnitInfo.IsPartOfProject:=true;
8845
Project1.Modified:=true;
9774
UnitIndex:=Project1.IndexOfFilename(AFilename);
9775
UnknownFile := (UnitIndex < 0);
9776
NewEditorInfo := nil;
9777
if not UnknownFile then begin
9778
NewUnitInfo:=Project1.Units[UnitIndex];
9779
if AEditorInfo <> nil then
9780
NewEditorInfo := AEditorInfo
9781
else if (ofProjectLoading in Flags) then
9782
NewEditorInfo := NewUnitInfo.GetClosedOrNewEditorInfo
9784
NewEditorInfo := NewUnitInfo.EditorInfo[0];
9788
if (NewEditorInfo <> nil) and (ofAddToProject in Flags) and (not NewUnitInfo.IsPartOfProject) then
9790
NewUnitInfo.IsPartOfProject:=true;
9791
Project1.Modified:=true;
9794
if (NewEditorInfo <> nil) and (Flags * [ofProjectLoading, ofRevert] = []) and (NewEditorInfo.EditorComponent <> nil) then
9796
//DebugLn(['TMainIDE.DoOpenEditorFile file already open ',NewUnitInfo.Filename,' WindowIndex=',NewEditorInfo.WindowIndex,' PageIndex=',NewEditorInfo.PageIndex]);
9797
// file already open -> change source notebook page
9798
SourceEditorManager.ActiveSourceWindowIndex := NewEditorInfo.WindowIndex;
9799
SourceEditorManager.ActiveSourceWindow.PageIndex:= NewEditorInfo.PageIndex;
9800
if ofDoLoadResource in Flags then
9801
Result:=OpenResource
8849
9807
Reverting:=false;
8850
9808
if ofRevert in Flags then begin
8851
9809
Reverting:=true;
9070
10028
case ItemType of
9071
piUnit: DlgCaption := dlgMainViewUnits;
10029
piUnit: DlgCaption := dlgMainViewUnits;
9072
10030
piComponent: DlgCaption := dlgMainViewForms;
9073
piFrame: DlgCaption := dlgMainViewFrames;
9075
Result := ShowViewUnitsDlg(ItemList, MultiSelect, MultiSelectCheckedState, DlgCaption);
10031
piFrame: DlgCaption := dlgMainViewFrames;
10033
Result := ShowViewUnitsDlg(ItemList, MultiSelect, MultiSelectCheckedState, DlgCaption, ItemType);
10036
function TMainIDE.SelectUnitComponents(DlgCaption: string;
10037
ItemType: TIDEProjectItem; Files: TStringList; MultiSelect: boolean;
10038
var MultiSelectCheckedState: Boolean): TModalResult;
10040
ActiveSourceEditor: TSourceEditor;
10041
ActiveUnitInfo: TUnitInfo;
10042
UnitToFilename: TStringToStringTree;
10045
function ResourceFits(ResourceBaseClass: TPFComponentBaseClass): boolean;
10048
piUnit: Result:=true;
10049
piComponent: Result:=ResourceBaseClass<>pfcbcNone;
10050
piFrame: Result:=ResourceBaseClass=pfcbcFrame;
10051
else Result:=false;
10055
function CheckLFMBaseClass(aFilename: string): TPFComponentBaseClass;
10057
LFMFilename: String;
10059
LFMComponentName: String;
10060
LFMClassName: String;
10063
ClassNode: TCodeTreeNode;
10064
ListOfPFindContext: TFPList;
10066
Context: PFindContext;
10067
AClassName: String;
10070
if not FilenameIsPascalUnit(aFilename) then exit;
10071
if not FilenameIsAbsolute(aFilename) then exit;
10072
LFMFilename:=ChangeFileExt(aFilename,'.lfm');
10073
if not FileExistsCached(LFMFilename) then exit;
10074
if not FileExistsCached(aFilename) then exit;
10075
if not ReadLFMHeaderFromFile(LFMFilename,LFMType,LFMComponentName,LFMClassName)
10077
Code:=CodeToolBoss.LoadFile(aFilename,true,false);
10078
if Code=nil then exit;
10079
if not CodeToolBoss.Explore(Code,Tool,false,true) then exit;
10081
ClassNode:=Tool.FindClassNodeInInterface(LFMClassName,true,false,false);
10082
if ClassNode=nil then exit;
10083
ListOfPFindContext:=nil;
10085
Tool.FindClassAndAncestors(ClassNode,ListOfPFindContext,false);
10086
if ListOfPFindContext=nil then exit;
10087
for i:=0 to ListOfPFindContext.Count-1 do begin
10088
Context:=PFindContext(ListOfPFindContext[i]);
10089
AClassName:=Context^.Tool.ExtractClassName(Context^.Node,false);
10090
//debugln(['CheckLFMBaseClass ',AClassName]);
10091
if CompareText(AClassName,'TFrame')=0 then
10093
else if CompareText(AClassName,'TForm')=0 then
10095
else if CompareText(AClassName,'TDataModule')=0 then
10096
exit(pfcbcDataModule);
10099
FreeListOfPFindContext(ListOfPFindContext);
10105
procedure AddUnit(AnUnitName,AFilename: string);
10107
LFMFilename: String;
10109
//debugln(['AddUnit ',AFilename]);
10110
if not FilenameIsPascalUnit(AFilename) then exit;
10111
if CompareFilenames(AFilename,ActiveUnitInfo.Filename)=0 then exit;
10112
if (AnUnitName='') then
10113
AnUnitName:=ExtractFileNameOnly(AFilename);
10114
if (not FilenameIsAbsolute(AFilename)) then begin
10115
if (not ActiveUnitInfo.IsVirtual) then
10116
exit; // virtual UnitToFilename can not be accessed from disk UnitToFilename
10118
//debugln(['AddUnit unitpath=',UnitPath]);
10119
if SearchDirectoryInSearchPath(UnitPath,ExtractFilePath(AFilename))<1 then
10120
exit; // not reachable
10122
if UnitToFilename.Contains(AnUnitName) then exit; // duplicate unit
10123
if not FileExistsCached(AFilename) then exit;
10124
LFMFilename:=ChangeFileExt(aFilename,'.lfm');
10125
if not FileExistsCached(LFMFilename) then exit;
10126
UnitToFilename[AnUnitName]:=AFilename;
10129
procedure AddPackage(Pkg: TLazPackage);
10134
//debugln(['AddPackage ',pkg.Name]);
10135
for i:=0 to Pkg.FileCount-1 do begin
10136
PkgFile:=TPkgFile(Pkg.Files[i]);
10137
if not (PkgFile.FileType in PkgFileRealUnitTypes) then continue;
10138
if not FilenameIsAbsolute(PkgFile.Filename) then continue;
10139
if not ResourceFits(PkgFile.ResourceBaseClass) then begin
10140
if PkgFile.ResourceBaseClass<>pfcbcNone then continue;
10141
// unknown resource class => check file
10142
PkgFile.ResourceBaseClass:=CheckLFMBaseClass(PkgFile.Filename);
10143
if not ResourceFits(PkgFile.ResourceBaseClass) then continue;
10145
AddUnit(PkgFile.Unit_Name,PkgFile.Filename);
10151
APackage: TLazPackage;
10152
AProject: TProject;
10153
AnUnitInfo: TUnitInfo;
10154
FirstDependency: TPkgDependency;
10157
S2SItem: PStringToStringTreeItem;
10158
AnUnitName: String;
10160
UnitList: TStringList;
10163
GetCurrentUnit(ActiveSourceEditor, ActiveUnitInfo);
10164
if ActiveUnitInfo=nil then exit;
10165
Owners:=PkgBoss.GetPossibleOwnersOfUnit(ActiveUnitInfo.Filename,[]);
10166
UnitPath:=CodeToolBoss.GetCompleteSrcPathForDirectory(ExtractFilePath(ActiveUnitInfo.Filename));
10168
UnitToFilename:=TStringToStringTree.Create(false);
10169
UnitList:=TStringList.Create;
10171
// fetch owner of active unit
10174
if (Owners<>nil) then begin
10175
for i:=0 to Owners.Count-1 do begin
10176
if TObject(Owners[i]) is TProject then begin
10177
AProject:=TProject(Owners[i]);
10179
end else if TObject(Owners[i]) is TLazPackage then begin
10180
APackage:=TLazPackage(Owners[i]);
10184
if AProject<>nil then begin
10185
// add project units
10186
//debugln(['TMainIDE.SelectUnitComponents Project=',AProject.ProjectInfoFile]);
10187
FirstDependency:=AProject.FirstRequiredDependency;
10188
for i:=0 to AProject.UnitCount-1 do begin
10189
AnUnitInfo:=AProject.Units[i];
10190
if (not AnUnitInfo.IsPartOfProject)
10191
or (AnUnitInfo.ComponentName='')
10193
if not ResourceFits(AnUnitInfo.ResourceBaseClass) then begin
10194
if AnUnitInfo.ResourceBaseClass<>pfcbcNone then continue;
10195
// unknown resource class => check file
10196
AnUnitInfo.ResourceBaseClass:=CheckLFMBaseClass(AnUnitInfo.Filename);
10197
if not ResourceFits(AnUnitInfo.ResourceBaseClass) then continue;
10199
AddUnit(AnUnitInfo.Unit_Name,AnUnitInfo.Filename);
10201
end else if APackage<>nil then begin
10202
// add package units
10203
FirstDependency:=APackage.FirstRequiredDependency;
10204
AddPackage(APackage);
10206
// add all units of all used packages
10207
PackageGraph.GetAllRequiredPackages(FirstDependency,PkgList);
10208
if PkgList<>nil then
10209
for i:=0 to PkgList.Count-1 do
10210
AddPackage(TLazPackage(PkgList[i]));
10214
for S2SItem in UnitToFilename do begin
10215
AnUnitName:=S2SItem^.Name;
10216
UnitList.AddObject(AnUnitName,TViewUnitsEntry.Create(AnUnitName,i,false));
10220
Result := ShowViewUnitsDlg(UnitList, MultiSelect, MultiSelectCheckedState, DlgCaption, ItemType);
10222
// create list of selected files
10224
for S2SItem in UnitToFilename do begin
10225
AFilename:=S2SItem^.Value;
10226
if TViewUnitsEntry(UnitList.Objects[i]).Selected then
10227
Files.Add(AFilename);
10232
for i := 0 to UnitList.Count-1 do
10233
TViewUnitsEntry(UnitList.Objects[i]).Free;
10237
UnitToFilename.Free;
9078
10241
function TMainIDE.DoSelectFrame: TComponentClass;
9080
10243
UnitList: TStringList;
9082
AnUnitInfo: TUnitInfo;
9083
LFMCode: TCodeBuffer;
9084
LFMFilename: String;
9085
TheModalResult: TModalResult;
9086
10244
dummy: Boolean;
10247
AComponent: TComponent;
9088
10249
Result := nil;
9089
10250
UnitList := TStringList.Create;
9090
UnitList.Sorted := True;
9092
10252
dummy := false;
9093
if SelectProjectItems(UnitList, piFrame, false, dummy) = mrOk then
10253
if SelectUnitComponents('Select Frame',piFrame,UnitList, false, dummy) <> mrOk
10256
for i := 0 to UnitList.Count-1 do
9095
{ This is where we check what the user selected. }
9097
for i := 0 to UnitList.Count-1 do
9099
if TViewUnitsEntry(UnitList.Objects[i]).Selected then
9101
AnUnitInfo := Project1.Units[TViewUnitsEntry(UnitList.Objects[i]).ID];
9102
if (AnUnitInfo.Component=nil) then begin
9104
LFMFilename:=ChangeFileExt(AnUnitInfo.Filename,'.lfm');
9105
if not FileExistsUTF8(LFMFilename) then begin
9106
DebugLn(['TMainIDE.DoSelectFrame file not found: ',LFMFilename]);
9109
// load the lfm file
9110
TheModalResult:=LoadCodeBuffer(LFMCode,LFMFilename,[lbfCheckIfText],false);
9111
if TheModalResult<>mrOk then begin
9112
debugln('TMainIDE.DoSelectFrame Failed loading ',LFMFilename);
9115
TheModalResult:=DoLoadLFM(AnUnitInfo,LFMCode,
9116
[ofQuiet,ofOnlyIfExists,ofLoadHiddenResource],[]);
9117
if TheModalResult<>mrOk then begin
9118
debugln('TMainIDE.DoSelectFrame Failed streaming ',LFMFilename);
9122
if (AnUnitInfo.Component<>nil) then
9124
Result := TComponentClass(AnUnitInfo.Component.ClassType);
9125
//DebugLn(AnUnitInfo.ComponentName + ' has been selected');
9130
end; { if ShowViewUnitDlg... }
10258
aFilename:=UnitList[i];
10259
if not FileExistsUTF8(aFilename) then continue;
10260
debugln(['TMainIDE.DoSelectFrame Filename="',aFilename,'"']);
10261
if DoOpenComponent(aFilename,
10262
[ofOnlyIfExists,ofLoadHiddenResource,ofUseCache],[],AComponent)<>mrOk
10264
debugln(['TMainIDE.DoSelectFrame AncestorComponent=',DbgSName(AComponent)]);
10265
Result := TComponentClass(AComponent.ClassType);
9132
for i := 0 to UnitList.Count-1 do
9133
TViewUnitsEntry(UnitList.Objects[i]).Free;
9134
10269
UnitList.Free;
10062
11248
Include(SaveFileFlags,sfSaveToTestDir);
10064
11250
Result:=DoSaveEditorFile(AnUnitInfo.OpenEditorInfo[0].EditorComponent, SaveFileFlags);
10065
if (Result=mrAbort) or (Result=mrCancel) then exit;
11251
if Result in [mrCancel,mrAbort] then exit;
10070
11256
Result:=SaveProjectInfo(Flags);
10071
if Result<>mrOk then exit;
11257
if Result in [mrCancel,mrAbort] then exit;
10073
11259
// save all editor files
10074
11260
for i:=0 to SourceEditorManager.SourceEditorCount-1 do begin
10075
11261
AnUnitInfo:=Project1.UnitWithEditorComponent(SourceEditorManager.SourceEditors[i]);
10076
if (Project1.MainUnitID<0) or (Project1.MainUnitInfo <> AnUnitInfo) then begin
10077
SaveFileFlags:=[sfProjectSaving]
10078
+Flags*[sfCheckAmbiguousFiles];
10079
if AnUnitInfo = nil
11262
if (Project1.MainUnitID>=0) and (Project1.MainUnitInfo = AnUnitInfo) then
11264
SaveFileFlags:=[sfProjectSaving]
11265
+Flags*[sfCheckAmbiguousFiles];
11266
if AnUnitInfo = nil
11268
// consistency check
11269
DebugLn('TMainIDE.DoSaveProject - unit not found for page %d', [i]);
11272
if AnUnitInfo.IsVirtual
10081
DebugLn('TMainIDE.DoSaveProject - unit not found for page %d', [i]);
10084
if AnUnitInfo.IsVirtual
10086
if (sfSaveToTestDir in Flags) then
10087
Include(SaveFileFlags,sfSaveToTestDir)
11274
if (sfSaveToTestDir in Flags) then
11275
Include(SaveFileFlags,sfSaveToTestDir)
10092
Result:=DoSaveEditorFile(SourceEditorManager.SourceEditors[i], SaveFileFlags);
10093
if Result=mrAbort then exit;
11280
Result:=DoSaveEditorFile(SourceEditorManager.SourceEditors[i], SaveFileFlags);
11281
if Result=mrAbort then exit;
11282
// mrCancel: continue saving other files
10097
11285
// update all lrs files
10098
11286
if sfSaveToTestDir in Flags then
10099
MainBuildBoss.UpdateProjectAutomaticFiles(EnvironmentOptions.TestBuildDirectory)
11287
MainBuildBoss.UpdateProjectAutomaticFiles(EnvironmentOptions.GetParsedTestBuildDirectory)
10101
11289
MainBuildBoss.UpdateProjectAutomaticFiles('');
10218
11400
ACaption:=lisFileNotText;
10219
11401
AText:=Format(lisFileDoesNotLookLikeATextFileOpenItAnyway, ['"', AFilename,
10220
11402
'"', #13, #13]);
10221
Result:=MessageDlg(ACaption, AText, mtConfirmation, [mbYes, mbAbort], 0);
11403
Result:=IDEMessageDialog(ACaption, AText, mtConfirmation, [mbYes, mbAbort]);
10222
11404
if Result=mrAbort then exit;
10224
11406
if not FileReadable then begin
10225
Result:=QuestionDlg(lisUnableToReadFile,
11407
Result:=IDEQuestionDialog(lisUnableToReadFile,
10226
11408
Format(lisUnableToReadFilename, ['"', AFilename, '"']),
10227
mtError, [mrCancel, lisSkipFile, mrAbort, lisAbortAllLoading], 0);
11409
mtError, [mrCancel, lisSkipFile, mrAbort, lisAbortAllLoading]);
10231
11413
if ofAddToRecent in Flags then
10232
11414
AddRecentProjectFileToEnvironment(AFileName);
11416
if not DoResetToolStatus([rfInteractive, rfSuccessOnTrigger]) then exit;
11418
// save old project
11419
if AskSaveProject(lisDoYouStillWantToOpenAnotherProject,
11420
lisDiscardChangesAndOpenProject)<>mrOk then exit;
10234
11422
Result:=DoCloseProject;
10235
11423
if Result=mrAbort then exit;
10237
11425
// create a new project
10238
11426
{$IFDEF IDE_VERBOSE}
10239
writeln('TMainIDE.DoOpenProjectFile B');
11427
debugln('TMainIDE.DoOpenProjectFile B');
10241
11429
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.DoOpenProjectFile B');{$ENDIF}
10242
11430
Project1:=CreateProjectObject(ProjectDescriptorProgram,
10671
11850
if (AnUnitInfo.IsPartOfProject) and (i<>Project1.MainUnitID) then
10673
11852
AName := Project1.RemoveProjectPathFromFilename(AnUnitInfo.FileName);
10674
UnitList.AddObject(AName, TViewUnitsEntry.Create(AName,i,false));
11853
ViewUnitEntries.AddObject(AName, TViewUnitsEntry.Create(AName,i,false));
10677
if ShowViewUnitsDlg(UnitList, true, MultiSelectCheckedState, lisRemoveFromProject) = mrOk then
11856
if ShowViewUnitsDlg(ViewUnitEntries, true, MultiSelectCheckedState,
11857
lisRemoveFromProject, IDEImages.LoadImage(16, 'item_unit')) <> mrOk then
11859
{ This is where we check what the user selected. }
11860
UnitInfos:=TFPList.Create;
11861
for i:=0 to ViewUnitEntries.Count-1 do
10679
{ This is where we check what the user selected. }
10680
for i:=0 to UnitList.Count-1 do
11863
if TViewUnitsEntry(ViewUnitEntries.Objects[i]).Selected then
10682
if TViewUnitsEntry(UnitList.Objects[i]).Selected then
10684
AnUnitInfo:=Project1.Units[TViewUnitsEntry(UnitList.Objects[i]).ID];
10685
AnUnitInfo.IsPartOfProject := false;
10686
if (Project1.MainUnitID >= 0) and
10687
(pfMainUnitHasUsesSectionForAllUnits in Project1.Flags) then
10689
if (AnUnitInfo.Unit_Name <> '') then
10691
if CodeToolBoss.RemoveUnitFromAllUsesSections(
10692
Project1.MainUnitInfo.Source, AnUnitInfo.Unit_Name)
10694
Project1.MainUnitInfo.Modified := true;
10696
if (AnUnitInfo.ComponentName <> '') then
10698
Project1.RemoveCreateFormFromProjectFile(
10699
'T' + AnUnitInfo.ComponentName, AnUnitInfo.ComponentName);
10704
end; { if ShowViewUnitsDlg.. }
11865
AnUnitInfo:=Project1.Units[TViewUnitsEntry(ViewUnitEntries.Objects[i]).ID];
11866
if AnUnitInfo.IsPartOfProject then
11867
UnitInfos.Add(AnUnitInfo);
11870
if UnitInfos.Count>0 then
11871
Result:=RemoveFilesFromProject(Project1,UnitInfos)
10706
for i := 0 to UnitList.Count-1 do
10707
TViewUnitsEntry(UnitList.Objects[i]).Free;
11876
for i := 0 to ViewUnitEntries.Count-1 do
11877
TViewUnitsEntry(ViewUnitEntries.Objects[i]).Free;
11878
ViewUnitEntries.Free;
10713
11882
function TMainIDE.DoWarnAmbiguousFiles: TModalResult;
10782
11951
Result:=PkgBoss.DoSaveAllPackages([]);
10785
function TMainIDE.DoCheckIfProjectNeedsCompilation(AProject: TProject;
10786
const CompilerFilename, CompilerParams, SrcFilename: string;
10787
out NeedBuildAllFlag: boolean): TModalResult;
10789
StateFilename: String;
10790
StateFileAge: LongInt;
10791
AnUnitInfo: TUnitInfo;
10793
NeedBuildAllFlag:=false;
10794
if (AProject.LastCompilerFilename<>CompilerFilename)
10795
or (AProject.LastCompilerParams<>CompilerParams)
10796
or ((AProject.LastCompilerFileDate>0)
10797
and FileExistsCached(CompilerFilename)
10798
and (FileAgeCached(CompilerFilename)<>AProject.LastCompilerFileDate))
10800
NeedBuildAllFlag:=true;
10802
// check state file
10803
StateFilename:=AProject.GetStateFilename;
10804
Result:=AProject.LoadStateFile(false);
10805
if Result<>mrOk then exit;
10806
if not (lpsfStateFileLoaded in AProject.StateFlags) then begin
10807
DebugLn('TMainIDE.CheckIfPackageNeedsCompilation No state file for ',AProject.IDAsString);
10811
StateFileAge:=FileAgeCached(StateFilename);
10813
// check main source file
10814
if FileExistsCached(SrcFilename) and (StateFileAge<FileAgeCached(SrcFilename)) then
10816
DebugLn('TMainIDE.CheckIfProjectNeedsCompilation SrcFile outdated ',AProject.IDAsString);
10820
// check compiler and params
10821
if CompilerFilename<>AProject.LastCompilerFilename then begin
10822
DebugLn('TMainIDE.CheckIfProjectNeedsCompilation Compiler filename changed for ',AProject.IDAsString);
10823
DebugLn(' Old="',AProject.LastCompilerFilename,'"');
10824
DebugLn(' Now="',CompilerFilename,'"');
10827
if not FileExistsUTF8(CompilerFilename) then begin
10828
DebugLn('TMainIDE.CheckIfProjectNeedsCompilation Compiler filename not found for ',AProject.IDAsString);
10829
DebugLn(' File="',CompilerFilename,'"');
10832
if FileAgeCached(CompilerFilename)<>AProject.LastCompilerFileDate then begin
10833
DebugLn('TMainIDE.CheckIfProjectNeedsCompilation Compiler file changed for ',AProject.IDAsString);
10834
DebugLn(' File="',CompilerFilename,'"');
10837
if CompilerParams<>AProject.LastCompilerParams then begin
10838
DebugLn('TMainIDE.CheckIfProjectNeedsCompilation Compiler params changed for ',AProject.IDAsString);
10839
DebugLn(' Old="',AProject.LastCompilerParams,'"');
10840
DebugLn(' Now="',CompilerParams,'"');
10844
// compiler and parameters are the same
10845
// quick compile is possible
10846
NeedBuildAllFlag:=false;
10848
// check all required packages
10849
Result:=PackageGraph.CheckCompileNeedDueToDependencies(
10850
AProject.FirstRequiredDependency,StateFileAge);
10851
if Result<>mrNo then exit;
10853
// check project files
10854
AnUnitInfo:=AProject.FirstPartOfProject;
10855
while AnUnitInfo<>nil do begin
10856
if FileExistsCached(AnUnitInfo.Filename)
10857
and (StateFileAge<FileAgeCached(AnUnitInfo.Filename)) then begin
10858
DebugLn('TMainIDE.CheckIfProjectNeedsCompilation Src has changed ',AProject.IDAsString,' ',AnUnitInfo.Filename);
10861
AnUnitInfo:=AnUnitInfo.NextPartOfProject;
10864
// check all open editor files (maybe the user forgot to add them to the project)
10865
AnUnitInfo:=AProject.FirstUnitWithEditorIndex;
10866
while AnUnitInfo<>nil do begin
10867
if (not AnUnitInfo.IsPartOfProject)
10868
and FileExistsCached(AnUnitInfo.Filename)
10869
and (StateFileAge<FileAgeCached(AnUnitInfo.Filename)) then begin
10870
DebugLn('TMainIDE.CheckIfProjectNeedsCompilation Editor Src has changed ',AProject.IDAsString,' ',AnUnitInfo.Filename);
10873
AnUnitInfo:=AnUnitInfo.NextUnitWithEditorIndex;
10879
11954
function TMainIDE.DoSaveProjectToTestDirectory(Flags: TSaveFlags): TModalResult;
10881
11958
Result:=mrCancel;
10882
if (EnvironmentOptions.TestBuildDirectory='')
10883
or (not DirPathExists(EnvironmentOptions.TestBuildDirectory)) then begin
10884
if (EnvironmentOptions.TestBuildDirectory<>'') then begin
10885
MessageDlg(Format(lisTheTestDirectoryCouldNotBeFoundSeeEnvironmentOpt, [
11959
TestDir:=GetTestBuildDirectory;
11961
or (not DirPathExists(TestDir)) then begin
11962
if (TestDir<>'') then begin
11963
IDEMessageDialog(lisCCOErrorCaption, Format(
11964
lisTheTestDirectoryCouldNotBeFoundSeeIDEOpt, [
10886
11965
#13, '"', EnvironmentOptions.TestBuildDirectory, '"', #13]), mtError, [
10888
11967
Result:=mrCancel;
10891
Result:=MessageDlg(lisBuildNewProject,
11970
Result:=IDEMessageDialog(lisBuildNewProject,
10892
11971
Format(lisTheProjectMustBeSavedBeforeBuildingIfYouSetTheTest, [#13, #13,
10893
#13]), mtInformation, [mbYes, mbNo], 0);
11972
#13]), mtInformation, [mbYes, mbNo]);
10894
11973
if Result<>mrYes then exit;
10895
11974
Result:=DoSaveAll([sfCheckAmbiguousFiles]);
11476
12607
Filename: String;
12608
List: TStringListUTF8;
11478
12609
Files: TStrings;
11481
12613
Filename:=GetRemoteControlFilename;
11482
if FileExistsUTF8(Filename) then begin
11483
// the control file exists
11484
if FRemoteControlFileValid then begin
11485
List:=TStringList.Create;
12614
if FileExistsUTF8(Filename) and (FRemoteControlFileAge<>FileAgeUTF8(Filename))
12616
// the control file exists and has changed
12617
List:=TStringListUTF8.Create;
12620
// load and delete the file
11488
// load and delete the file
11490
List.LoadFromFile(UTF8ToSys(Filename));
11492
DebugLn(['TMainIDE.DoExecuteRemoteControl reading file failed: ',Filename]);
11494
DeleteFileUTF8(Filename);
11495
FRemoteControlFileValid:=not FileExistsUTF8(Filename);
11497
Files:=TStringList.Create;
11498
for i:=0 to List.Count-1 do begin
11499
if SysUtils.CompareText(copy(List[i],1,5),'open ')=0 then
11500
Files.Add(copy(List[i],6,length(List[i])));
11502
if Files.Count>0 then begin
11510
// the last time there was an error (e.g. read/delete failed)
11511
// do not waste time again
12622
List.LoadFromFile(Filename);
12624
DebugLn(['TMainIDE.DoExecuteRemoteControl reading file failed: ',Filename]);
12626
DeleteFileUTF8(Filename);
12627
FRemoteControlFileAge:=-1;
12629
Files:=TStringList.Create;
12631
for i:=0 to List.Count-1 do begin
12632
if SysUtils.CompareText(List[i],'show')=0 then
12634
if SysUtils.CompareText(copy(List[i],1,5),'open ')=0 then
12635
Files.Add(copy(List[i],6,length(List[i])));
12637
if CmdShow then begin
12638
// if minimized then restore, bring IDE to front
12639
Application.MainForm.ShowOnTop;
12641
if Files.Count>0 then begin
11513
12648
end else begin
11514
12649
// the control file does not exist
11515
// => remember the good state
11516
FRemoteControlFileValid:=true;
12650
FRemoteControlFileAge:=-1;
11520
12654
//-----------------------------------------------------------------------------
11522
function TMainIDE.DoRunExternalTool(Index: integer; ShowAbort: Boolean
12656
function TMainIDE.DoRunExternalTool(Index: integer; ShowAbort: Boolean): TModalResult;
11525
12658
SourceEditorManager.ClearErrorLines;
11526
Result:=EnvironmentOptions.ExternalTools.Run(Index,GlobalMacroList,ShowAbort);
12659
Result:=ExternalTools.Run(Index,GlobalMacroList,ShowAbort);
11527
12660
DoCheckFilesOnDisk;
11541
12673
// prepare static auto install packages
11542
12674
PkgOptions:='';
11543
if (blfWithStaticPackages in Flags)
11544
or MiscellaneousOptions.BuildLazOpts.WithStaticPackages then begin
11545
// create inherited compiler options
11546
PkgOptions:=PackageGraph.GetIDEInstallPackageOptions(
11547
PackageGraph.FirstAutoInstallDependency,InheritedOptionStrings);
12675
// create inherited compiler options
12676
PkgOptions:=PackageGraph.GetIDEInstallPackageOptions(
12677
PackageGraph.FirstAutoInstallDependency,InheritedOptionStrings);
11549
// check ambiguous units
11550
CodeToolBoss.GetFPCVersionForDirectory(
11551
EnvironmentOptions.LazarusDirectory,
11552
FPCVersion,FPCRelease,FPCPatch);
11553
if (FPCVersion=0) or (FPCRelease=0) or (FPCPatch=0) then ;
12679
// check ambiguous units
12680
CodeToolBoss.GetFPCVersionForDirectory(
12681
EnvironmentOptions.GetParsedLazarusDirectory,
12682
FPCVersion,FPCRelease,FPCPatch);
12683
if (FPCVersion=0) or (FPCRelease=0) or (FPCPatch=0) then ;
11556
12685
// save extra options
11557
IDEBuildFlags:=Flags+[blfOnlyIDE];
11558
Result:=SaveIDEMakeOptions(MiscellaneousOptions.BuildLazProfiles,
11559
GlobalMacroList,PkgOptions,IDEBuildFlags);
12686
Result:=SaveIDEMakeOptions(MiscellaneousOptions.BuildLazProfiles.Current,
12687
GlobalMacroList,PkgOptions,Flags+[blfOnlyIDE]);
11560
12688
if Result<>mrOk then exit;
12691
function TMainIDE.DoManageExamples: TModalResult;
12693
Result:=ShowManageExamplesDlg;
11563
12696
function TMainIDE.DoBuildLazarusSub(Flags: TBuildLazarusFlags): TModalResult;
11565
12698
PkgOptions: string;
11586
12720
MessagesView.BeginBlock;
12721
ProfileChanged:=false;
12722
with MiscellaneousOptions do
11588
12724
MainBuildBoss.SetBuildTargetIDE;
11590
// first compile all lazarus components (LCL, SynEdit, CodeTools, ...)
11592
SourceEditorManager.ClearErrorLines;
11593
CompileProgress.CreateDialog(OwningComponent, 'Lazarus...', '');
11594
Result:=BuildLazarus(MiscellaneousOptions.BuildLazProfiles,
11595
EnvironmentOptions.ExternalTools,GlobalMacroList,
11596
'',EnvironmentOptions.GetCompilerFilename,
11597
EnvironmentOptions.MakeFilename,
11598
Flags+[blfWithoutCompilingIDE,blfWithoutLinkingIDE]);
11599
if Result<>mrOk then begin
11600
DebugLn('TMainIDE.DoBuildLazarus: Building standard components (LCL, SynEdit, CodeTools) failed.');
11605
// then compile the 'installed' packages
11606
if (not (blfOnlyIDE in Flags))
11607
and (MiscellaneousOptions.BuildLazProfiles.CurrentIdeMode=mmNone) then begin
11608
CompileProgress.Ready;
11613
OnlyBase:=not ((blfWithStaticPackages in Flags)
11614
or MiscellaneousOptions.BuildLazOpts.WithStaticPackages);
11616
// prepare static auto install packages
12727
PkgCompileFlags:=[];
12728
if (not (blfDontClean in Flags))
12729
and (BuildLazProfiles.Current.IdeBuildMode<>bmBuild) then begin
12730
PkgCompileFlags:=PkgCompileFlags+[pcfCompileDependenciesClean];
12731
if BuildLazProfiles.Current.IdeBuildMode=bmCleanAllBuild then begin
12732
SourceEditorManager.ClearErrorLines;
12733
Result:=MakeLazarus(BuildLazProfiles.Current,ExternalTools,GlobalMacroList,
12734
'',EnvironmentOptions.GetParsedCompilerFilename,
12735
EnvironmentOptions.GetParsedMakeFilename, [blfDontBuild],
12737
if Result<>mrOk then begin
12738
DebugLn('TMainIDE.DoBuildLazarus: Clean all failed.');
11618
12744
// compile auto install static packages
11619
Result:=PkgBoss.DoCompileAutoInstallPackages([],OnlyBase);
12745
Result:=PkgBoss.DoCompileAutoInstallPackages(PkgCompileFlags,false);
11620
12746
if Result<>mrOk then begin
11621
12747
DebugLn('TMainIDE.DoBuildLazarus: Compile AutoInstall Packages failed.');
11625
12751
// create uses section addition for lazarus.pp
11626
if not OnlyBase then begin
11627
Result:=PkgBoss.DoSaveAutoInstallConfig;
11628
if Result<>mrOk then begin
11629
DebugLn('TMainIDE.DoBuildLazarus: Save AutoInstall Config failed.');
12752
Result:=PkgBoss.DoSaveAutoInstallConfig;
12753
if Result<>mrOk then begin
12754
DebugLn('TMainIDE.DoBuildLazarus: Save AutoInstall Config failed.');
11634
12758
// create inherited compiler options
11638
PkgOptions:=PackageGraph.GetIDEInstallPackageOptions(
12759
PkgOptions:=PackageGraph.GetIDEInstallPackageOptions(
11639
12760
PackageGraph.FirstAutoInstallDependency,InheritedOptionStrings);
11641
12762
// check ambiguous units
11642
CodeToolBoss.GetFPCVersionForDirectory(
11643
EnvironmentOptions.LazarusDirectory,
11644
FPCVersion,FPCRelease,FPCPatch);
12763
CodeToolBoss.GetFPCVersionForDirectory(EnvironmentOptions.GetParsedLazarusDirectory,
12764
FPCVersion,FPCRelease,FPCPatch);
11645
12765
if FPCPatch=0 then ;
11646
12766
CompiledUnitExt:=GetDefaultCompiledUnitExt(FPCVersion,FPCRelease);
11647
12767
Result:=MainBuildBoss.CheckUnitPathForAmbiguousPascalFiles(
11648
EnvironmentOptions.LazarusDirectory+PathDelim+'ide',
12768
EnvironmentOptions.GetParsedLazarusDirectory+PathDelim+'ide',
11649
12769
InheritedOptionStrings[icoUnitPath],
11650
12770
CompiledUnitExt,'IDE');
11651
12771
if Result<>mrOk then begin
11656
12776
// save extra options
11657
IDEBuildFlags:=Flags+[blfOnlyIDE];
11658
if not OnlyBase then
11660
Result:=SaveIDEMakeOptions(MiscellaneousOptions.BuildLazProfiles,
11661
GlobalMacroList,PkgOptions,IDEBuildFlags);
11662
if Result<>mrOk then begin
11663
DebugLn('TMainIDE.DoBuildLazarus: Save IDEMake options failed.');
12777
IDEBuildFlags:=Flags;
12778
Result:=SaveIDEMakeOptions(BuildLazProfiles.Current,GlobalMacroList,PkgOptions,
12779
IDEBuildFlags-[blfUseMakeIDECfg,blfDontClean]+[blfBackupOldExe]);
12780
if Result<>mrOk then begin
12781
DebugLn('TMainIDE.DoBuildLazarus: Save IDEMake options failed.');
12785
// make lazarus ide
11669
12786
SourceEditorManager.ClearErrorLines;
11670
Result:=BuildLazarus(MiscellaneousOptions.BuildLazProfiles,
11671
EnvironmentOptions.ExternalTools,GlobalMacroList,
11672
PkgOptions,EnvironmentOptions.GetCompilerFilename,
11673
EnvironmentOptions.MakeFilename,
11674
IDEBuildFlags+[blfUseMakeIDECfg]
12787
IDEBuildFlags:=IDEBuildFlags+[blfUseMakeIDECfg,blfDontClean];
12788
Result:=MakeLazarus(BuildLazProfiles.Current,ExternalTools,GlobalMacroList,
12789
PkgOptions,EnvironmentOptions.GetParsedCompilerFilename,
12790
EnvironmentOptions.GetParsedMakeFilename,IDEBuildFlags,
11676
12792
if Result<>mrOk then exit;
12794
if ProfileChanged then
12795
MiscellaneousOptions.Save;
11679
MainBuildBoss.SetBuildTarget('','','',bmsfsBackground);
12797
MainBuildBoss.SetBuildTargetProject1(true);
11681
12799
DoCheckFilesOnDisk;
11682
12800
MessagesView.EndBlock;
12791
13956
procedure TMainIDE.UnhideIDE;
12793
13958
AForm: TCustomForm;
13960
AActiveForm: TCustomForm;
13962
{$IFDEF DEBUGHIDEIDEWINDOWSONRUN}
13963
DebugLn('TMainIDE.UnhideIDE Active=',dbgsName(WindowMenuActiveForm));
13965
AActiveForm := WindowMenuActiveForm;
12795
13966
// unminimize IDE
12796
13967
MainIDEBar.UnhideIDE;
12798
// show other windows
12799
while HiddenWindowsOnRun.Count>0 do begin
12800
AForm:=TCustomForm(HiddenWindowsOnRun[0]);
12801
if (csDesigning in ComponentState) then
12802
ShowDesignerForm(AForm)
13969
// show other windows but keep order as it was before hiding.
13970
for i := HiddenWindowsOnRun.Count - 1 downto 0 do
13972
AForm:=TCustomForm(HiddenWindowsOnRun[i]);
13973
if (csDesigning in AForm.ComponentState) or (AForm.Designer <> nil) then
13975
{$IFDEF DEBUGHIDEIDEWINDOWSONRUN}
13976
DebugLn('TMainIDE.UnhideIDE: Showing LCLIntf AForm ',dbgsName(AForm),
13977
' WindowState ',dbgs(AForm.WindowState),' LCLIntf.IsIconic ',
13978
dbgs(LCLIntf.IsIconic(AForm.Handle)));
13980
if LCLIntf.IsIconic(AForm.Handle) then
13981
LCLIntf.ShowWindow(AForm.Handle, SW_SHOWMINIMIZED)
13983
LCLIntf.ShowWindow(AForm.Handle, SW_SHOWNORMAL);
13984
// ShowDesignerForm(AForm)
13987
{$IFDEF DEBUGHIDEIDEWINDOWSONRUN}
13988
DebugLn('TMainIDE.UnhideIDE: Showing AForm ',dbgsName(AForm));
12805
HiddenWindowsOnRun.Delete(0);
13993
HiddenWindowsOnRun.Clear;
13994
{$IFDEF DEBUGHIDEIDEWINDOWSONRUN}
13995
DebugLn('TMainIDE.UnhideIDE: activating form ',dbgsName(AActiveForm));
13997
{activate form or app, must be so because of debugmanager !}
13998
if Assigned(AActiveForm) then
13999
AActiveForm.BringToFront
14001
Application.BringToFront;
12809
14004
procedure TMainIDE.DoBringToFrontFormOrUnit;
13862
15064
'PROJECT',nil,@CTMacroFunctionProject);
13864
15066
CodeToolsOpts.AssignTo(CodeToolBoss);
13865
if (not FileExistsCached(EnvironmentOptions.GetCompilerFilename)) then begin
13867
DebugLn('NOTE: Compiler filename not set! (see Environment / Options ... / Environment / Files)');
13870
if (EnvironmentOptions.LazarusDirectory='')
13871
or not DirPathExists(EnvironmentOptions.LazarusDirectory) then begin
13874
'NOTE: Lazarus source directory not set! (see Environment / Options ... / Environment / Files)');
13876
if (EnvironmentOptions.FPCSourceDirectory='') then begin
13877
// Note: the FPCSourceDirectory can contain the macro FPCVer, which depend
13878
// on the compiler. Do not check if file exists here.
13880
DebugLn('NOTE: FPC source directory not set! (see Environment / Options ... / Environment / Files)');
15068
if not InteractiveSetup then begin
15069
if (not FileExistsCached(EnvironmentOptions.GetParsedCompilerFilename)) then begin
15071
DebugLn('NOTE: invalid compiler filename! (see Tools / Options ... / Environment / Files)');
15073
if not DirPathExists(EnvironmentOptions.GetParsedLazarusDirectory) then begin
15075
DebugLn('NOTE: Lazarus source directory not set! (see Tools / Options ... / Environment / Files)');
15077
if (EnvironmentOptions.GetParsedFPCSourceDirectory='') then begin
15079
DebugLn('NOTE: FPC source directory not set! (see Tools / Options ... / Environment / Files)');
13883
15083
// create a test unit needed to get from the compiler all macros and search paths
13884
15084
CodeToolBoss.FPCDefinesCache.TestFilename:=CreateCompilerTestPascalFilename;
15085
MainBuildBoss.UpdateEnglishErrorMsgFilename;
15087
if InteractiveSetup then
15089
if (not ShowSetupDialog)
15090
and (CheckLazarusDirectoryQuality(EnvironmentOptions.GetParsedLazarusDirectory,Note)<>sddqCompatible)
15092
debugln(['Warning: incompatible Lazarus directory: ',EnvironmentOptions.GetParsedLazarusDirectory]);
15093
ShowSetupDialog:=true;
15095
if (not ShowSetupDialog)
15096
and (CheckCompilerQuality(EnvironmentOptions.GetParsedCompilerFilename,Note,
15097
CodeToolBoss.FPCDefinesCache.TestFilename)=sddqInvalid)
15099
debugln(['Warning: invalid compiler: ',EnvironmentOptions.GetParsedCompilerFilename]);
15100
ShowSetupDialog:=true;
15102
if (not ShowSetupDialog) then
15104
CfgCache:=CodeToolBoss.FPCDefinesCache.ConfigCaches.Find(
15105
EnvironmentOptions.GetParsedCompilerFilename,'','','',true);
15106
if CheckFPCSrcDirQuality(EnvironmentOptions.GetParsedFPCSourceDirectory,Note,
15107
CfgCache.GetFPCVer)=sddqInvalid
15109
debugln(['Warning: invalid fpc source directory: ',EnvironmentOptions.GetParsedFPCSourceDirectory]);
15110
ShowSetupDialog:=true;
15113
if ShowSetupDialog then begin
15114
OldLazDir:=EnvironmentOptions.LazarusDirectory;
15115
if ShowInitialSetupDialog<>mrOk then
15117
if OldLazDir<>EnvironmentOptions.LazarusDirectory then begin
15118
CollectTranslations(EnvironmentOptions.GetParsedLazarusDirectory);
15119
TranslateResourceStrings(EnvironmentOptions.GetParsedLazarusDirectory,
15120
EnvironmentOptions.LanguageID);
13886
15125
// set global macros
13887
15126
with CodeToolBoss.GlobalValues do begin
13888
Variables[ExternalMacroStart+'LazarusDir']:=
13889
EnvironmentOptions.LazarusDirectory;
15127
Variables[ExternalMacroStart+'LazarusDir']:=EnvironmentOptions.GetParsedLazarusDirectory;
13890
15128
Variables[ExternalMacroStart+'ProjPath']:=VirtualDirectory;
13891
Variables[ExternalMacroStart+'LCLWidgetType']:=
13892
LCLPlatformDirNames[GetDefaultLCLWidgetType];
15129
Variables[ExternalMacroStart+'LCLWidgetType']:=LCLPlatformDirNames[GetDefaultLCLWidgetType];
15130
Variables[ExternalMacroStart+'FPCSrcDir']:=EnvironmentOptions.GetParsedFPCSourceDirectory;
13895
// find the compiler executable
13896
SetupCompilerFilename(InteractiveSetup);
13897
// find the FPC source directory
13898
SetupFPCSourceDirectory(InteractiveSetup);
13899
CodeToolBoss.GlobalValues.Variables[ExternalMacroStart+'FPCSrcDir']:=
13900
EnvironmentOptions.GetFPCSourceDirectory;
13902
15133
// the first template is the "use default" flag
13903
15134
CreateUseDefaultsFlagTemplate;
13905
// create defines for the lazarus sources
13906
SetupLazarusDirectory(InteractiveSetup);
13908
MainBuildBoss.RescanCompilerDefines(true,false,false);
15136
MainBuildBoss.SetBuildTargetProject1(false);
13910
15138
// load include file relationships
13911
15139
AFilename:=AppendPathDelim(GetPrimaryConfigPath)+CodeToolsIncludeLinkFile;
14353
15585
function TMainIDE.DoJumpToSourcePosition(const Filename: string; NewX, NewY,
14354
NewTopLine: integer; AddJumpPoint: boolean; MarkLine: Boolean): TModalResult;
15586
NewTopLine: integer; Flags: TJumpToCodePosFlags = [jfFocusEditor]): TModalResult;
14356
15588
CodeBuffer: TCodeBuffer;
14358
15591
Result:=mrCancel;
14359
CodeBuffer:=CodeToolBoss.LoadFile(CleanAndExpandFilename(Filename),true,false);
15592
aFilename:=Filename;
15593
if not (jfDoNotExpandFilename in Flags) then
15594
aFilename:=TrimAndExpandFilename(aFilename);
15595
CodeBuffer:=CodeToolBoss.LoadFile(aFilename,true,false);
14360
15596
if CodeBuffer=nil then exit;
14361
Result:=DoJumpToCodePos(nil,nil,CodeBuffer,NewX,NewY,NewTopLine,AddJumpPoint, True, MarkLine);
15597
Result:=DoJumpToCodePosition(nil,nil,CodeBuffer,NewX,NewY,NewTopLine, Flags);
14364
function TMainIDE.DoJumpToCodePos(
14365
ActiveSrcEdit: TSourceEditor; ActiveUnitInfo: TUnitInfo;
14366
NewSource: TCodeBuffer; NewX, NewY, NewTopLine: integer;
14367
AddJumpPoint: boolean; FocusEditor: boolean; MarkLine: Boolean): TModalResult;
15600
function TMainIDE.DoJumpToCodePosition(ActiveSrcEdit: TSourceEditorInterface;
15601
ActiveUnitInfo: TUnitInfo; NewSource: TCodeBuffer; NewX, NewY, NewTopLine: integer;
15602
Flags: TJumpToCodePosFlags): TModalResult;
14369
NewSrcEdit: TSourceEditor;
15604
SrcEdit, NewSrcEdit: TSourceEditor;
14370
15605
AnEditorInfo: TUnitEditorInfo;
14372
15608
Result:=mrCancel;
14373
15609
if NewSource=nil then begin
14374
DebugLn(['TMainIDE.DoJumpToCodePos ERROR: missing NewSource']);
15610
DebugLn(['TMainIDE.DoJumpToCodePosition ERROR: missing NewSource']);
15615
if ActiveSrcEdit = nil then
15618
SrcEdit := ActiveSrcEdit as TSourceEditor;
14379
15620
SourceEditorManager.BeginAutoFocusLock;
14381
if (ActiveSrcEdit=nil) or (ActiveUnitInfo=nil) then
14382
GetCurrentUnit(ActiveSrcEdit,ActiveUnitInfo);
15622
if (SrcEdit=nil) or (ActiveUnitInfo=nil) then
15623
GetCurrentUnit(SrcEdit,ActiveUnitInfo);
14384
if AddJumpPoint and (ActiveUnitInfo <> nil) and (ActiveSrcEdit <> nil)
15625
if (jfAddJumpPoint in Flags) and (ActiveUnitInfo <> nil) and (SrcEdit <> nil)
14386
15627
if (NewSource<>ActiveUnitInfo.Source)
14387
or (ActiveSrcEdit.EditorComponent.CaretX<>NewX)
14388
or (ActiveSrcEdit.EditorComponent.CaretY<>NewY) then
15628
or (SrcEdit.EditorComponent.CaretX<>NewX)
15629
or (SrcEdit.EditorComponent.CaretY<>NewY) then
14389
15630
SourceEditorManager.AddJumpPointClicked(Self);
15610
16933
writeln('[TMainIDE.OnSrcNotebookShowHintForSource] ************ ',ActiveUnitInfo.Source.Filename,' X=',CaretPos.X,' Y=',CaretPos.Y);
15612
16936
if EditorOpts.AutoToolTipSymbTools then begin
15613
16937
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.OnSrcNotebookShowHintForSource A');{$ENDIF}
15614
TIDEHelpManager(HelpBoss).GetHintForSourcePosition(ActiveUnitInfo.Filename,
15615
CaretPos,BaseURL,SmartHintStr);
16938
if TIDEHelpManager(HelpBoss).GetHintForSourcePosition(ActiveUnitInfo.Filename,
16939
CaretPos,BaseURL,SmartHintStr,
16940
[{$IFDEF EnableFocusHint}ihmchAddFocusHint{$ENDIF}])=shrSuccess
15616
16943
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.OnSrcNotebookShowHintForSource B');{$ENDIF}
15618
16945
case ToolStatus of
15619
16946
itDebugger: begin
15620
16947
if EditorOpts.AutoToolTipExprEval then begin
15621
if SrcEdit.SelectionAvailable and SrcEdit.CaretInSelection(CaretPos) then
15622
Expression := SrcEdit.GetText(True)
16948
if SrcEdit.SelectionAvailable and SrcEdit.CaretInSelection(CaretPos) then begin
16949
Expression := SrcEdit.GetText(True);
16950
if not CheckExpressionIsValid(Expression) then
15624
16954
Expression := SrcEdit.GetOperandFromCaret(CaretPos);
15625
16955
if Expression='' then exit;
15626
16956
//DebugLn(['TMainIDE.OnSrcNotebookShowHintForSource Expression="',Expression,'"']);
15627
16957
DBGType:=nil;
15628
16958
DBGTypeDerefer:=nil;
15629
if not DebugBoss.Evaluate(Expression, DebugEval, DBGType) or (DebugEval = '') then
16960
if EditorOpts.DbgHintAutoTypeCastClass
16961
then Opts := [defClassAutoCast];
16962
if not DebugBoss.Evaluate(Expression, DebugEval, DBGType, Opts) or (DebugEval = '') then
15630
16963
DebugEval := '???';
15631
16964
// deference a pointer - maybe it is a class
15632
16965
if Assigned(DBGType) and (DBGType.Kind in [skPointer]) and
17684
procedure TMainIDE.CreateObjectInspector;
17686
if ObjectInspector1<>nil then exit;
17687
ObjectInspector1 := TObjectInspectorDlg.Create(OwningComponent);
17688
ObjectInspector1.Name:=DefaultObjectInspectorName;
17689
ObjectInspector1.ShowFavorites:=True;
17690
ObjectInspector1.ShowRestricted:=True;
17691
ObjectInspector1.Favourites:=LoadOIFavouriteProperties;
17692
ObjectInspector1.FindDeclarationPopupmenuItem.Visible:=true;
17693
ObjectInspector1.OnAddToFavourites:=@OIOnAddToFavourites;
17694
ObjectInspector1.OnFindDeclarationOfProperty:=@OIOnFindDeclarationOfProperty;
17695
ObjectInspector1.OnUpdateRestricted := @OIOnUpdateRestricted;
17696
ObjectInspector1.OnRemainingKeyDown:=@OIRemainingKeyDown;
17697
ObjectInspector1.OnRemoveFromFavourites:=@OIOnRemoveFromFavourites;
17698
ObjectInspector1.OnSelectPersistentsInOI:=@OIOnSelectPersistents;
17699
ObjectInspector1.OnShowOptions:=@OIOnShowOptions;
17700
ObjectInspector1.OnViewRestricted:=@OIOnViewRestricted;
17701
ObjectInspector1.OnSelectionChange:=@OIOnSelectionChange;
17702
ObjectInspector1.OnPropertyHint:=@OIOnPropertyHint;
17703
ObjectInspector1.OnDestroy:=@OIOnDestroy;
17704
ObjectInspector1.OnAutoShow:=@OIOnAutoShow;
17705
ObjectInspector1.EnableHookGetSelection:=false; // the selection is stored in TheControlSelection
17707
// after OI changes the hints need to be updated
17708
// do that after some idle time
17709
OIChangedTimer:=TIdleTimer.Create(OwningComponent);
17710
with OIChangedTimer do begin
17711
Name:='OIChangedTimer';
17713
OnTimer:=@OIChangedTimerTimer;
17715
EnvironmentOptions.ObjectInspectorOptions.AssignTo(ObjectInspector1);
17717
// connect to designers
17718
ObjectInspector1.PropertyEditorHook:=GlobalDesignHook;
17719
if FormEditor1<>nil then
17720
FormEditor1.Obj_Inspector := ObjectInspector1;
16330
17723
procedure TMainIDE.OnApplicationUserInput(Sender: TObject; Msg: Cardinal);
16332
17725
fUserInputSinceLastIdle:=true;
16373
17784
HasResources:=true
16374
17785
else if FilenameIsAbsolute(AnUnitInfo.Filename)
16375
17786
and FilenameIsPascalSource(AnUnitInfo.Filename)
16376
and FileExistsCached(ChangeFileExt(AnUnitInfo.Filename,'.lfm'))
17787
and ( FileExistsCached(ChangeFileExt(AnUnitInfo.Filename,'.lfm'))
17788
or FileExistsCached(ChangeFileExt(AnUnitInfo.Filename,'.dfm')) )
16378
17790
HasResources:=true;
16380
17792
MainIDEBar.itmViewToggleFormUnit.Enabled := HasResources;
16382
17794
MainIDEBar.ToggleFormSpeedBtn.Enabled := MainIDEBar.itmViewToggleFormUnit.Enabled;
16384
17795
DebugBoss.UpdateButtonsAndMenuItems;
16388
if FCheckFilesOnDiskNeeded then
17798
if FCheckFilesOnDiskNeeded then begin
17799
{$IFDEF VerboseIdle}
17800
debugln(['TMainIDE.OnApplicationIdle FCheckFilesOnDiskNeeded']);
16389
17802
DoCheckFilesOnDisk(true);
16391
if (FRemoteControlTimer=nil) and EnableRemoteControl then
17804
if (FRemoteControlTimer=nil) and EnableRemoteControl then begin
17805
{$IFDEF VerboseIdle}
17806
debugln(['TMainIDE.OnApplicationIdle EnableRemoteControl']);
16392
17808
SetupRemoteControl;
16394
if Screen.GetCurrentModalForm=nil then
17810
if Screen.GetCurrentModalForm=nil then begin
17811
{$IFDEF VerboseIdle}
17812
debugln(['TMainIDE.OnApplicationIdle Screen.GetCurrentModalForm']);
16395
17814
PkgBoss.OpenHiddenModifiedPackages;
17818
procedure TMainIDE.OnApplicationDeActivate(Sender: TObject);
17821
AForm: TCustomForm;
17823
if EnvironmentOptions.SingleTaskBarButton and FApplicationIsActivate
17824
and (MainIDEBar.WindowState=wsNormal) then
17826
for i:=Screen.CustomFormCount-1 downto 0 do
17828
AForm:=Screen.CustomFormsZOrdered[i];
17829
if (AForm.Parent=nil) and (AForm<>MainIDEBar) and (AForm.IsVisible)
17830
and (AForm.Designer=nil) and (not (csDesigning in AForm.ComponentState))
17831
and not (fsModal in AForm.FormState) then
17832
LastActivatedWindows.Add(AForm);
17834
FApplicationIsActivate:=false;
17838
procedure TMainIDE.OnMainBarActive(Sender: TObject);
17840
i, FormCount: integer;
17841
AForm: TCustomForm;
17843
if EnvironmentOptions.SingleTaskBarButton and not FApplicationIsActivate
17844
and (MainIDEBar.WindowState=wsNormal) then
17846
FApplicationIsActivate:=true;
17848
for i:=Screen.CustomFormCount-1 downto 0 do
17850
AForm:=Screen.CustomForms[i];
17851
if (AForm.Parent=nil) and (AForm<>MainIDEBar) and (AForm.IsVisible)
17852
and (AForm.Designer=nil) and (not (csDesigning in AForm.ComponentState))
17853
and not (fsModal in AForm.FormState) then
17856
if FormCount<>LastActivatedWindows.Count then
17857
LastActivatedWindows.Clear;
17858
while LastActivatedWindows.Count>0 do
17860
AForm:=TCustomForm(LastActivatedWindows[0]);
17861
if Assigned(AForm) and (not (CsDestroying in AForm.ComponentState)) and
17862
AForm.IsVisible then
17863
AForm.BringToFront;
17864
LastActivatedWindows.Delete(0);
17866
MainIDEBar.BringToFront;
16398
17870
procedure TMainIDE.OnApplicationActivate(Sender: TObject);
16645
18141
BeginCodeTool(ActiveSourceEditor,ActiveUnitInfo,[]);
16646
18142
AnUnitInfo.IsPartOfProject:=true;
16647
18143
DependencyAdded:=false;
16648
if FilenameIsPascalUnit(AnUnitInfo.Filename) then
16649
CheckDirIsInUnitSearchPath(AnUnitInfo,false,DependencyAdded)
18144
if FilenameIsPascalUnit(AnUnitInfo.Filename) then begin
18145
CheckDirIsInUnitSearchPath(AnUnitInfo,false,DependencyAdded);
18146
if (pfMainUnitHasUsesSectionForAllUnits in Project1.Flags) then begin
18147
AnUnitInfo.ReadUnitNameFromSource(false);
18148
ShortUnitName:=AnUnitInfo.Unit_Name;
18149
if (ShortUnitName<>'') then begin
18150
if CodeToolBoss.AddUnitToMainUsesSectionIfNeeded(
18151
Project1.MainUnitInfo.Source,ShortUnitName,'') then begin
18152
ApplyCodeToolChanges;
18153
Project1.MainUnitInfo.Modified:=true;
18155
DoJumpToCodeToolBossError;
16650
18161
else if CompareFileExt(AnUnitInfo.Filename,'inc',false)=0 then
16651
18162
CheckDirIsInIncludeSearchPath(AnUnitInfo,false,DependencyAdded);
16652
if FilenameIsPascalUnit(AnUnitInfo.Filename)
16653
and (pfMainUnitHasUsesSectionForAllUnits in Project1.Flags)
16655
AnUnitInfo.ReadUnitNameFromSource(false);
16656
ShortUnitName:=AnUnitInfo.Unit_Name;
16657
if (ShortUnitName<>'') then begin
16658
Dummy:=CodeToolBoss.AddUnitToMainUsesSection(
16659
Project1.MainUnitInfo.Source,ShortUnitName,'');
16660
ApplyCodeToolChanges;
16661
if Dummy then begin
16662
Project1.MainUnitInfo.Modified:=true;
16664
DoJumpToCodeToolBossError;
16669
18163
Project1.Modified:=true;
16672
18166
function TMainIDE.ProjInspectorRemoveFile(Sender: TObject; AnUnitInfo: TUnitInfo
16673
18167
): TModalresult;
16675
ActiveSourceEditor: TSourceEditor;
16676
ActiveUnitInfo: TUnitInfo;
16677
ShortUnitName: String;
18169
UnitInfos: TFPList;
16681
if not AnUnitInfo.IsPartOfProject then exit;
16682
Project1.BeginUpdate(true);
18171
if not AnUnitInfo.IsPartOfProject then exit(mrOk);
18172
UnitInfos:=TFPList.Create;
16684
AnUnitInfo.IsPartOfProject:=false;
16685
if (Project1.MainUnitID>=0)
16686
and (pfMainUnitHasUsesSectionForAllUnits in Project1.Flags)
16688
BeginCodeTool(ActiveSourceEditor,ActiveUnitInfo,[]);
16689
ShortUnitName:=AnUnitInfo.Unit_Name;
16690
if (ShortUnitName<>'') then begin
16691
Dummy:=CodeToolBoss.RemoveUnitFromAllUsesSections(
16692
Project1.MainUnitInfo.Source,ShortUnitName);
16694
Project1.MainUnitInfo.Modified:=true
16696
ApplyCodeToolChanges;
16697
DoJumpToCodeToolBossError;
16702
if (AnUnitInfo.ComponentName<>'') then begin
16703
Dummy:=Project1.RemoveCreateFormFromProjectFile(
16704
'T'+AnUnitInfo.ComponentName,AnUnitInfo.ComponentName);
16705
if not Dummy then begin
16706
ApplyCodeToolChanges;
16707
DoJumpToCodeToolBossError;
16712
ApplyCodeToolChanges;
16714
Project1.Modified:=true;
18174
UnitInfos.Add(AnUnitInfo);
18175
Result:=RemoveFilesFromProject(Project1,UnitInfos);
16716
Project1.EndUpdate;
16934
18399
WriteLn('[TMainIDE.OnPropHookMethodExists] ************ ',AMethodName);
16936
//D := GetTickCount;
16937
18401
Result := CodeToolBoss.PublishedMethodExists(ActiveUnitInfo.Source,
16938
18402
ActiveUnitInfo.Component.ClassName, AMethodName, TypeData,
16939
18403
MethodIsCompatible, MethodIsPublished, IdentIsMethod);
16940
//D := GetTickCount - D;
16941
//WriteLn('CodeToolBoss.PublishedMethodExists takes ', D, ' ms');
16942
18404
if CodeToolBoss.ErrorMessage <> '' then
16944
18406
DoJumpToCodeToolBossError;
16945
raise Exception.Create(lisUnableToFindMethodPleaseFixTheErrorShownInTheMessage);
18407
raise Exception.Create(lisUnableToFindMethod+' '+lisPleaseFixTheErrorInTheMessageWindow);
16949
18411
function TMainIDE.OnPropHookCreateMethod(const AMethodName: ShortString;
16950
18412
ATypeInfo: PTypeInfo;
16951
18413
APersistent: TPersistent; const APropertyPath: string): TMethod;
18414
{ APersistent is the intance that gets the new method, not the lookuproot.
18415
For example assign 'Button1Click' to Form1.Button1.OnClick:
18416
APersistent = APersistent
18417
AMethodName = 'Button1Click'
18418
APropertyPath = Form1.Button1.OnClick
18419
ATypeInfo = the typeinfo of the event property
18421
{ $DEFINE VerboseOnPropHookCreateMethod}
16953
18423
ActiveSrcEdit: TSourceEditor;
16954
18424
ActiveUnitInfo: TUnitInfo;
18426
function GetInheritedMethodPath: string;
18428
OldJITMethod: TJITMethod;
18429
OldMethod: TMethod;
18432
OldMethodOwner: TComponent;
18435
{$IFDEF VerboseOnPropHookCreateMethod}
18436
debugln([' GetInheritedMethodPath APersistent=',DbgSName(APersistent),' APropertyPath="',APropertyPath,'" AMethodName="',AMethodName,'"']);
18440
p:=length(APropertyPath);
18441
while (p>0) and (APropertyPath[p]<>'.') do dec(p);
18443
APropName:=copy(APropertyPath,p+1,length(APropertyPath));
18444
OldMethod:=GetMethodProp(APersistent,APropName);
18445
if not GetJITMethod(OldMethod,OldJITMethod) then begin
18446
{$IFDEF VerboseOnPropHookCreateMethod}
18447
debugln([' GetInheritedMethodPath old method is not a jitmethod']);
18452
{$IFDEF VerboseOnPropHookCreateMethod}
18453
debugln([' GetInheritedMethodPath OldJITMethod=',DbgSName(OldJITMethod.TheClass),'.',OldJITMethod.TheMethodName]);
18456
// there is an old method
18457
if OldJITMethod.TheClass=ActiveUnitInfo.Component.ClassType then begin
18458
// old method belongs to same lookup root
18459
// => do not call the old method
18460
{$IFDEF VerboseOnPropHookCreateMethod}
18461
debugln([' GetInheritedMethodPath old method belongs to same lookuproot (',DbgSName(ActiveUnitInfo.Component),')']);
18465
// the old method is from another lookup root (e.g. not the current form)
18467
if ActiveUnitInfo.Component.InheritsFrom(OldJITMethod.TheClass) then
18469
// the old method is from an ancestor
18470
// => add a statement 'inherited OldMethodName;'
18471
Result:='inherited';
18472
{$IFDEF VerboseOnPropHookCreateMethod}
18473
debugln([' GetInheritedMethodPath old method is from an ancestor. Result="',Result,'"']);
18478
// check for nested components
18479
// to call a method the instance is needed
18480
// => create a path from the current component (e.g. the form) to the nested OldMethodOwner
18481
if APersistent is TComponent then
18482
OldMethodOwner:=TComponent(APersistent)
18484
{$IFDEF VerboseOnPropHookCreateMethod}
18485
debugln([' GetInheritedMethodPath there is no simple way to get the owner of a TPersistent. Not calling old method.']);
18489
while (OldMethodOwner<>nil)
18490
and (not OldMethodOwner.ClassType.InheritsFrom(OldJITMethod.TheClass)) do
18491
OldMethodOwner:=OldMethodOwner.Owner;
18492
if OldMethodOwner=nil then begin
18493
{$IFDEF VerboseOnPropHookCreateMethod}
18494
debugln([' GetInheritedMethodPath owner of oldmethod not found.']);
18499
{$IFDEF VerboseOnPropHookCreateMethod}
18500
DebugLn([' GetInheritedMethodPath OldMethodOwner=',dbgsName(OldMethodOwner)]);
18502
// create a path to the nested component
18503
while (OldMethodOwner<>nil) and (OldMethodOwner<>ActiveUnitInfo.Component) do
18506
Result:='.'+Result;
18507
Result:=OldMethodOwner.Name+Result;
18508
OldMethodOwner:=OldMethodOwner.Owner;
18510
if (OldMethodOwner=ActiveUnitInfo.Component)
18511
and (Result<>'') then begin
18512
Result:=Result+'.'+OldJITMethod.TheMethodName;
18513
{$IFDEF VerboseOnPropHookCreateMethod}
18514
DebugLn([' GetInheritedMethodPath call to nested override: OverrideMethodName=',Result]);
16956
18522
OldChange: Boolean;
16959
OldMethod: TMethod;
16960
JITMethod: TJITMethod;
16961
OverrideMethodName: String;
16962
AComponent: TComponent;
18523
InheritedMethodPath: String;
16964
18525
Result.Code:=nil;
16965
18526
Result.Data:=nil;
16966
18527
if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[ctfSwitchToFormSource])
18529
{$IFDEF VerboseOnPropHookCreateMethod}
16970
18531
debugln('[TMainIDE.OnPropHookCreateMethod] ************ ',AMethodName);
16971
DebugLn(['[TMainIDE.OnPropHookCreateMethod] Persistent=',dbgsName(APersistent),' Unit=',GetClassUnitName(APersistent.ClassType),' Path=',APropertyPath]);
18532
DebugLn([' Persistent=',dbgsName(APersistent),' Unit=',GetClassUnitName(APersistent.ClassType),' Path=',APropertyPath]);
16974
OverrideMethodName:='';
16975
if APersistent is TComponent then begin
16976
AComponent:=TComponent(APersistent);
16977
p:=length(APropertyPath);
16978
while (p>0) and (APropertyPath[p]<>'.') do dec(p);
16980
APropName:=copy(APropertyPath,p+1,length(APropertyPath));
16981
OldMethod:=GetMethodProp(APersistent,APropName);
16982
if IsJITMethod(OldMethod) then begin
16983
// there is an old method
16984
JITMethod:=TJITMethod(OldMethod.Data);
16985
if JITMethod.ClassType<>ActiveUnitInfo.Component.ClassType then begin
16986
// the old method is inherited
16987
// => search the component that has the method
16988
//DebugLn(['TMainIDE.OnPropHookCreateMethod ',dbgsName(JITMethod.TheClass),' ',dbgsName(APersistent.ClassType),' ',dbgsName(APersistent)]);
16989
while (AComponent<>nil)
16990
and (not JITMethod.TheClass.InheritsFrom(AComponent.ClassType)) do
16991
AComponent:=AComponent.Owner;
16992
// create a path to the component
16993
while (AComponent<>nil) and (AComponent<>ActiveUnitInfo.Component) do
16995
if OverrideMethodName<>'' then
16996
OverrideMethodName:='.'+OverrideMethodName;
16997
OverrideMethodName:=AComponent.Name+OverrideMethodName;
16998
AComponent:=AComponent.Owner;
17000
if (AComponent=ActiveUnitInfo.Component)
17001
and (OverrideMethodName<>'') then begin
17002
// the old value does not belong to this main component, but to
17003
// a nested/inline component
17004
OverrideMethodName:=OverrideMethodName+'.'+JITMethod.TheMethodName;
17005
DebugLn(['TMainIDE.OnPropHookCreateMethod OverrideMethodName=',OverrideMethodName]);
18534
if ActiveUnitInfo.Component=nil then begin
18535
{$IFDEF VerboseOnPropHookCreateMethod}
18536
debugln(['TMainIDE.OnPropHookCreateMethod failed ActiveUnitInfo.Component=nil']);
18540
InheritedMethodPath:=GetInheritedMethodPath;
17012
18541
OldChange:=OpenEditorsOnCodeToolChange;
17013
18542
OpenEditorsOnCodeToolChange:=true;
17015
18544
// create published method
18545
{$IFDEF VerboseOnPropHookCreateMethod}
18546
debugln(['TMainIDE.OnPropHookCreateMethod CreatePublishedMethod ',ActiveUnitInfo.Source.Filename,' LookupRoot=',ActiveUnitInfo.Component.ClassName,' AMethodName="',AMethodName,'" PropertyUnit=',GetClassUnitName(APersistent.ClassType),' APropertyPath="',APropertyPath,'" CallInherited=',InheritedMethodPath]);
17016
18548
r:=CodeToolBoss.CreatePublishedMethod(ActiveUnitInfo.Source,
17017
18549
ActiveUnitInfo.Component.ClassName,AMethodName,
17018
18550
ATypeInfo,false,GetClassUnitName(APersistent.ClassType),APropertyPath,
17019
OverrideMethodName);
17022
debugln('[TMainIDE.OnPropHookCreateMethod] ************2 ',r,' ',AMethodName);
18551
InheritedMethodPath);
18552
{$IFDEF VerboseOnPropHookCreateMethod}
18553
debugln(['[TMainIDE.OnPropHookCreateMethod] ************ ',dbgs(r),' AMethodName="',AMethodName,'"']);
17024
18555
ApplyCodeToolChanges;
17025
18556
if r then begin
17026
18557
Result:=FormEditor1.CreateNewJITMethod(ActiveUnitInfo.Component,
17027
18558
AMethodName);
17028
18559
end else begin
17029
DebugLn(['TMainIDE.OnPropHookCreateMethod failed adding method to source']);
18560
DebugLn(['TMainIDE.OnPropHookCreateMethod failed adding method "'+AMethodName+'" to source']);
17030
18561
DoJumpToCodeToolBossError;
17031
raise Exception.Create(lisUnableToCreateNewMethodPleaseFixTheErrorShownIn);
18562
raise Exception.Create(lisUnableToCreateNewMethod+' '+lisPleaseFixTheErrorInTheMessageWindow);
17034
18565
OpenEditorsOnCodeToolChange:=OldChange;
17502
19073
DoFindRenameIdentifier(false);
17505
procedure TMainIDE.mnuSearchRenameIdentifierClicked(Sender: TObject);
17507
DoFindRenameIdentifier(true);
17510
procedure TMainIDE.mnuEditCompleteCodeClicked(Sender: TObject);
17512
DoCompleteCodeAtCursor;
17515
procedure TMainIDE.mnuEditExtractProcClicked(Sender: TObject);
17517
DoExtractProcFromSelection;
17520
19076
procedure TMainIDE.mnuEditInsertCharacterClicked(Sender: TObject);
17522
19078
DoSourceEditorCommand(ecInsertCharacter);
17525
procedure TMainIDE.mnuEditInsertCVSAuthorClick(Sender: TObject);
19081
procedure TMainIDE.mnuSourceInsertCVSAuthorClick(Sender: TObject);
17527
19083
DoSourceEditorCommand(ecInsertCVSAuthor);
17530
procedure TMainIDE.mnuEditInsertCVSDateClick(Sender: TObject);
19086
procedure TMainIDE.mnuSourceInsertCVSDateClick(Sender: TObject);
17532
19088
DoSourceEditorCommand(ecInsertCVSDate);
17535
procedure TMainIDE.mnuEditInsertCVSHeaderClick(Sender: TObject);
19091
procedure TMainIDE.mnuSourceInsertCVSHeaderClick(Sender: TObject);
17537
19093
DoSourceEditorCommand(ecInsertCVSHeader);
17540
procedure TMainIDE.mnuEditInsertCVSIDClick(Sender: TObject);
19096
procedure TMainIDE.mnuSourceInsertCVSIDClick(Sender: TObject);
17542
19098
DoSourceEditorCommand(ecInsertCVSID);
17545
procedure TMainIDE.mnuEditInsertCVSLogClick(Sender: TObject);
19101
procedure TMainIDE.mnuSourceInsertCVSLogClick(Sender: TObject);
17547
19103
DoSourceEditorCommand(ecInsertCVSLog);
17550
procedure TMainIDE.mnuEditInsertCVSNameClick(Sender: TObject);
19106
procedure TMainIDE.mnuSourceInsertCVSNameClick(Sender: TObject);
17552
19108
DoSourceEditorCommand(ecInsertCVSName);
17555
procedure TMainIDE.mnuEditInsertCVSRevisionClick(Sender: TObject);
19111
procedure TMainIDE.mnuSourceInsertCVSRevisionClick(Sender: TObject);
17557
19113
DoSourceEditorCommand(ecInsertCVSRevision);
17560
procedure TMainIDE.mnuEditInsertCVSSourceClick(Sender: TObject);
19116
procedure TMainIDE.mnuSourceInsertCVSSourceClick(Sender: TObject);
17562
19118
DoSourceEditorCommand(ecInsertCVSSource);
19121
procedure TMainIDE.mnuSourceCompleteCodeClicked(Sender: TObject);
19123
DoCompleteCodeAtCursor;
19126
procedure TMainIDE.mnuSourceUseUnitClicked(Sender: TObject);
19128
DoSourceEditorCommand(ecUseUnit);
19131
procedure TMainIDE.mnuRefactorRenameIdentifierClicked(Sender: TObject);
19133
DoFindRenameIdentifier(true);
19136
procedure TMainIDE.mnuRefactorExtractProcClicked(Sender: TObject);
19138
DoExtractProcFromSelection;
19141
procedure TMainIDE.mnuRefactorInvertAssignmentClicked(Sender: TObject);
19143
DoSourceEditorCommand(ecInvertAssignment);
19146
procedure TMainIDE.mnuRefactorShowAbstractMethodsClicked(Sender: TObject);
19148
DoSourceEditorCommand(ecShowAbstractMethods);
19151
procedure TMainIDE.mnuRefactorShowEmptyMethodsClicked(Sender: TObject);
19153
DoSourceEditorCommand(ecRemoveEmptyMethods);
19156
procedure TMainIDE.mnuRefactorShowUnusedUnitsClicked(Sender: TObject);
19158
DoSourceEditorCommand(ecRemoveUnusedUnits);
19161
procedure TMainIDE.mnuRefactorFindOverloadsClicked(Sender: TObject);
19163
DoSourceEditorCommand(ecFindOverloads);
17565
19166
procedure TMainIDE.DoCommand(ACommand: integer);
17567
19168
ActiveSourceEditor: TSourceEditor;