~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to ide/main.pp

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
{$ENDIF}
61
61
  // fpc packages
62
62
  Math, Classes, SysUtils, Process, AsyncProcess, TypInfo, types, AVL_Tree,
 
63
  // lazutils
 
64
  LazUTF8, Laz2_XMLCfg, AvgLvlTree,
63
65
  // lcl
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,
 
69
  lazutf8classes,
67
70
  // codetools
68
71
  FileProcs, CodeBeautifier, FindDeclarationTool, LinkScanner, BasicCodeTools,
69
 
  Laz_XMLCfg, CodeToolsStructs, CodeToolManager, CodeCache, DefineTemplates,
70
 
  KeywordFuncLists,
 
72
  CodeToolsStructs, CodeToolManager, CodeCache, DefineTemplates,
 
73
  KeywordFuncLists, CodeTree,
71
74
  // synedit
72
 
  SynEditKeyCmds, SynBeautifier, SynEditMarks,
 
75
  AllSynEdit, SynEditKeyCmds, SynBeautifier, SynEditMarks,
73
76
  // IDE interface
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,
79
82
  // protocol
80
83
  IDEProtocol,
81
84
  // compile
82
 
  Compiler, CompilerOptions, CompilerOptionsDlg, CheckCompilerOpts,
 
85
  Compiler, CompilerOptions, CheckCompilerOpts, BuildProjectDlg,
83
86
  ApplicationBundle, ImExportCompilerOpts, InfoBuild,
84
87
  // projects
85
88
  ProjectResources, Project, ProjectDefs, NewProjectDlg, 
86
89
  PublishProjectDlg, ProjectInspector, PackageDefs,
87
90
  // help manager
88
 
  IDEContextHelpEdit, IDEHelpIntf, HelpManager, CodeHelp, HelpOptions,
 
91
  IDEContextHelpEdit, IDEHelpIntf, IDEHelpManager, CodeHelp, HelpOptions,
89
92
  // designer
90
 
  JITForms, ComponentPalette, ComponentList, ComponentReg, FormEditingIntf,
 
93
  JITForms, ComponentPalette, ComponentList,
91
94
  ObjInspExt, Designer, FormEditor, CustomFormEditor,
92
 
  ControlSelection, AnchorEditor,
93
 
  MenuEditorForm,
 
95
  ControlSelection, AnchorEditor, TabOrderDlg, MenuEditorForm,
94
96
  // LRT stuff
95
97
  Translations,
96
98
  // debugger
102
104
  CodeToolsDefines, DiffDialog, DiskDiffsDialog, UnitInfoDlg, EditorOptions,
103
105
  SourceEditProcs, MsgQuickFixes, ViewUnit_dlg, FPDocEditWindow,
104
106
  // converter
105
 
  ChgEncodingDlg, ConvertDelphi, MissingPropertiesDlg, LazXMLForms,
 
107
  ChgEncodingDlg, ConvertDelphi, ConvCodeTool, MissingPropertiesDlg, LazXMLForms,
106
108
  // environment option frames
107
109
  editor_general_options, formed_options, OI_options,
108
110
  files_options, desktop_options, window_options,
121
123
  codeexplorer_update_options, codeexplorer_categories_options,
122
124
  codeobserver_options,
123
125
  help_general_options,
 
126
  env_file_filters,
124
127
  // project option frames
125
128
  project_application_options, project_forms_options, project_lazdoc_options,
126
129
  project_save_options, project_versioninfo_options, project_i18n_options,
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,
132
 
  BuildModesEditor,
 
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,
133
139
 
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,
147
155
  // main ide
148
156
  MainBar, MainIntf, MainBase;
149
157
 
150
158
type
151
 
  TIDEProjectItem =
152
 
  (
153
 
    piUnit,
154
 
    piComponent,
155
 
    piFrame
156
 
  );
157
 
 
158
159
  TIDECodetoolsDefines = (
159
160
    ctdReady,
160
161
    ctdNeedUpdate,
170
171
    procedure OnApplicationUserInput(Sender: TObject; Msg: Cardinal);
171
172
    procedure OnApplicationIdle(Sender: TObject; var Done: Boolean);
172
173
    procedure OnApplicationActivate(Sender: TObject);
 
174
    procedure OnApplicationDeActivate(Sender: TObject);
173
175
    procedure OnApplicationKeyDown(Sender: TObject;
174
176
                                   var Key: Word; Shift: TShiftState);
175
177
    procedure OnApplicationDropFiles(Sender: TObject; const FileNames: array of String);
 
178
    procedure OnApplicationQueryEndSession(var Cancel: Boolean);
 
179
    procedure OnApplicationEndSession(Sender: TObject);
 
180
    procedure OnScreenChangedForm(Sender: TObject; Form: TCustomForm);
176
181
    procedure OnScreenRemoveForm(Sender: TObject; AForm: TCustomForm);
177
182
    procedure OnRemoteControlTimer(Sender: TObject);
178
183
    procedure OnSelectFrame(Sender: TObject; var AComponentClass: TComponentClass);
179
184
    procedure OIChangedTimerTimer(Sender: TObject);
 
185
    procedure OnMainBarActive(Sender: TObject);
180
186
 
181
187
    // file menu
182
188
    procedure mnuFileClicked(Sender: TObject);
189
195
    procedure mnuSaveClicked(Sender: TObject);
190
196
    procedure mnuSaveAsClicked(Sender: TObject);
191
197
    procedure mnuSaveAllClicked(Sender: TObject);
 
198
    procedure mnuExportHtml(Sender: TObject);
192
199
    procedure mnuCloseClicked(Sender: TObject);
193
200
    procedure mnuCloseAllClicked(Sender: TObject);
194
201
    procedure mnuCleanDirectoryClicked(Sender: TObject);
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);
225
227
 
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);
235
 
 
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);
244
 
 
245
228
    // search menu
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);
258
240
    // view menu
259
241
    procedure mnuViewInspectorClicked(Sender: TObject);
260
242
    procedure mnuViewSourceEditorClicked(Sender: TObject);
261
 
    procedure mnuViewUnitsClicked(Sender: TObject);
262
 
    procedure mnuViewFormsClicked(Sender: TObject);
263
 
    procedure mnuViewUnitDependenciesClicked(Sender: TObject);
264
 
    procedure mnuViewUnitInfoClicked(Sender: TObject);
265
243
    procedure mnuViewFPDocEditorClicked(Sender: TObject);
266
244
    procedure mnuViewCodeExplorerClick(Sender: TObject);
267
245
    procedure mnuViewCodeBrowserClick(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);
 
258
 
 
259
    // source menu
 
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);
 
291
    // source->Tools
 
292
    procedure mnuSourceUnitInfoClicked(Sender: TObject);
 
293
    procedure mnuSourceUnitDependenciesClicked(Sender: TObject);
 
294
 
 
295
    // refactor menu
 
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);
278
304
 
279
305
    // project menu
280
306
    procedure mnuNewProjectClicked(Sender: TObject);
287
313
    procedure mnuProjectInspectorClicked(Sender: TObject);
288
314
    procedure mnuAddToProjectClicked(Sender: TObject);
289
315
    procedure mnuRemoveFromProjectClicked(Sender: TObject);
 
316
    procedure mnuViewUnitsClicked(Sender: TObject);
 
317
    procedure mnuViewFormsClicked(Sender: TObject);
290
318
    procedure mnuViewProjectSourceClicked(Sender: TObject);
291
319
    procedure mnuProjectOptionsClicked(Sender: TObject);
292
320
 
293
321
    // run menu
 
322
    procedure mnuCompileProjectClicked(Sender: TObject);
294
323
    procedure mnuBuildProjectClicked(Sender: TObject);
295
 
    procedure mnuBuildAllProjectClicked(Sender: TObject);
296
324
    procedure mnuQuickCompileProjectClicked(Sender: TObject);
 
325
    procedure mnuCleanUpCompiledProjectClicked(Sender: TObject);
297
326
    procedure mnuAbortBuildProjectClicked(Sender: TObject);
298
327
    procedure mnuRunProjectClicked(Sender: TObject);
299
328
    procedure mnuPauseProjectClicked(Sender: TObject);
310
339
    procedure mnuRunFileClicked(Sender: TObject);
311
340
    procedure mnuConfigBuildFileClicked(Sender: TObject);
312
341
 
313
 
    // components menu
 
342
    // project menu
 
343
    procedure mnuProjectClicked(Sender: TObject);
 
344
 
 
345
    // package menu
 
346
    procedure mnuPackageClicked(Sender: TObject);
314
347
    // see pkgmanager.pas
315
348
 
316
349
    // tools menu
317
350
    procedure mnuToolConfigureClicked(Sender: TObject);
318
 
    procedure mnuToolSyntaxCheckClicked(Sender: TObject);
319
 
    procedure mnuToolGuessUnclosedBlockClicked(Sender: TObject);
320
 
    procedure mnuToolGuessMisplacedIFDEFClicked(Sender: TObject);
321
 
    procedure mnuToolMakeResourceStringClicked(Sender: TObject);
322
351
    procedure mnuToolDiffClicked(Sender: TObject);
323
352
    procedure mnuToolConvertDFMtoLFMClicked(Sender: TObject);
324
353
    procedure mnuToolCheckLFMClicked(Sender: TObject);
326
355
    procedure mnuToolConvertDelphiProjectClicked(Sender: TObject);
327
356
    procedure mnuToolConvertDelphiPackageClicked(Sender: TObject);
328
357
    procedure mnuToolConvertEncodingClicked(Sender: TObject);
 
358
    procedure mnuToolManageExamplesClicked(Sender: TObject);
329
359
    procedure mnuToolBuildLazarusClicked(Sender: TObject);
330
360
    procedure mnuToolBuildAdvancedLazarusClicked(Sender: TObject);
331
361
    procedure mnuToolConfigBuildLazClicked(Sender: TObject);
332
362
    procedure mnuCustomExtToolClick(Sender: TObject);
333
363
 
334
 
    // environment menu
 
364
    // options menu
335
365
    procedure mnuEnvGeneralOptionsClicked(Sender: TObject);
336
366
    procedure mnuEnvEditorOptionsClicked(Sender: TObject);
337
367
    procedure mnuEnvCodeTemplatesClicked(Sender: TObject);
339
369
    procedure mnuEnvRescanFPCSrcDirClicked(Sender: TObject);
340
370
 
341
371
    // windows menu
 
372
    procedure mnuWindowManagerClicked(Sender: TObject);
342
373
 
343
374
    // help menu
344
375
    // see helpmanager.pas
350
381
    procedure mnuSetBuildModeClick(Sender: TObject); // event for drop down items
351
382
  private
352
383
    function DoBuildLazarusSub(Flags: TBuildLazarusFlags): TModalResult;
 
384
    function ExternalTools: TExternalToolList;
353
385
  public
354
386
    // Global IDE events
355
387
    procedure OnProcessIDECommand(Sender: TObject; Command: word;
371
403
    // Environment options dialog events
372
404
    procedure OnLoadIDEOptions(Sender: TObject; AOptions: TAbstractIDEOptions);
373
405
    procedure OnSaveIDEOptions(Sender: TObject; AOptions: TAbstractIDEOptions);
374
 
    procedure DoOpenIDEOptions(AEditor: TAbstractIDEOptionsEditorClass = nil;
375
 
      ACaption: String = '';
376
 
      AOptionsFilter: TAbstractIDEOptionsClass = nil); override;
 
406
    procedure DoOpenIDEOptions(AEditor: TAbstractIDEOptionsEditorClass;
 
407
      ACaption: String;
 
408
      AOptionsFilter: array of TAbstractIDEOptionsClass;
 
409
      ASettings: TIDEOptionsEditorSettings); override;
377
410
 
378
411
    procedure DoEnvironmentOptionsBeforeRead(Sender: TObject);
379
412
    procedure DoEnvironmentOptionsBeforeWrite(Sender: TObject; Restore: boolean);
384
417
    procedure DoCodeExplorerOptionsAfterWrite(Sender: TObject; Restore: boolean);
385
418
    procedure DoProjectOptionsBeforeRead(Sender: TObject);
386
419
    procedure DoProjectOptionsAfterWrite(Sender: TObject; Restore: boolean);
 
420
    procedure OnCompilerOptionsDialogTest(Sender: TObject);
 
421
    function DoTestCompilerSettings(
 
422
                            TheCompilerOptions: TCompilerOptions): TModalResult;
 
423
    function OnCheckCompOptsAndMainSrcForNewUnit(CompOpts: TLazCompilerOptions
 
424
        ): TModalResult;
 
425
 
 
426
    // ComponentPalette events
 
427
    procedure ComponentPaletteClassSelected(Sender: TObject);
387
428
 
388
429
    // SourceNotebook events
389
430
    procedure OnSrcNoteBookActivated(Sender: TObject);
431
472
    procedure OnSrcNoteBookCloseQuery(Sender: TObject; var CloseAction: TCloseAction);
432
473
 
433
474
    // ObjectInspector + PropertyEditorHook events
 
475
    procedure CreateObjectInspector;
434
476
    procedure OIOnSelectPersistents(Sender: TObject);
435
477
    procedure OIOnShowOptions(Sender: TObject);
436
478
    procedure OIOnViewRestricted(Sender: TObject);
449
491
    function OnPropHookGetMethodName(const Method: TMethod;
450
492
                                     PropOwner: TObject): String;
451
493
    procedure OnPropHookGetMethods(TypeData: PTypeData; Proc:TGetStrProc);
 
494
    procedure OnPropHookGetCompatibleMethods(InstProp: PInstProp;
 
495
                                             const Proc:TGetStrProc);
 
496
    function OnPropHookCompatibleMethodExists(const AMethodName: String;
 
497
                                    InstProp: PInstProp;
 
498
                                    var MethodIsCompatible, MethodIsPublished,
 
499
                                    IdentIsMethod: boolean): boolean;
452
500
    function OnPropHookMethodExists(const AMethodName: String;
453
501
                                    TypeData: PTypeData;
454
502
                                    var MethodIsCompatible, MethodIsPublished,
483
531
    procedure OnDesignerSetDesigning(Sender: TObject; Component: TComponent;
484
532
                                     Value: boolean);
485
533
    procedure OnDesignerShowOptions(Sender: TObject);
486
 
    procedure OnDesignerPasteComponent(Sender: TObject; LookupRoot: TComponent;
 
534
    procedure OnDesignerPasteComponents(Sender: TObject; LookupRoot: TComponent;
487
535
                            TxtCompStream: TStream; ParentControl: TWinControl;
488
 
                            var NewComponent: TComponent);
 
536
                            var NewComponents: TFPList);
 
537
    procedure OnDesignerPastedComponents(Sender: TObject; LookupRoot: TComponent);
489
538
    procedure OnDesignerPropertiesChanged(Sender: TObject);
490
539
    procedure OnDesignerPersistentDeleted(Sender: TObject;
491
540
                                          APersistent: TPersistent);
497
546
    procedure OnDesignerViewLFM(Sender: TObject);
498
547
    procedure OnDesignerSaveAsXML(Sender: TObject);
499
548
    procedure OnDesignerShowObjectInspector(Sender: TObject);
 
549
    procedure OnDesignerShowAnchorEditor(Sender: TObject);
 
550
    procedure OnDesignerShowTabOrderEditor(Sender: TObject);
500
551
 
501
552
    // control selection
502
553
    procedure OnControlSelectionChanged(Sender: TObject; ForceUpdate: Boolean);
503
554
    procedure OnControlSelectionPropsChanged(Sender: TObject);
504
555
    procedure OnControlSelectionFormChanged(Sender: TObject; OldForm,
505
556
                                            NewForm: TCustomForm);
 
557
    procedure OnGetDesignerSelection(const ASelection: TPersistentSelectionList);
506
558
 
507
559
    // project inspector
508
560
    procedure ProjInspectorOpen(Sender: TObject);
519
571
    procedure CheckDirIsInIncludeSearchPath(UnitInfo: TUnitInfo;
520
572
        AllowAddingDependencies: boolean; out DependencyAdded: boolean);
521
573
 
522
 
    // compiler options dialog events
523
 
    procedure OnCompilerOptionsDialogTest(Sender: TObject);
524
 
    procedure OnCheckCompOptsAndMainSrcForNewUnit(CompOpts: TLazCompilerOptions);
525
 
 
526
574
    // unit dependencies events
527
575
    procedure UnitDependenciesViewAccessingSources(Sender: TObject);
528
 
    function UnitDependenciesViewGetProjectMainFilename(
529
 
        Sender: TObject): string;
530
 
    procedure UnitDependenciesViewOpenFile(Sender: TObject;
531
 
        const Filename: string);
 
576
    function UnitDependenciesViewGetProjectMainFilename(Sender: TObject): string;
 
577
    procedure UnitDependenciesViewOpenFile(Sender: TObject; const Filename: string);
532
578
 
533
579
    // code explorer events
534
580
    procedure OnCodeExplorerGetDirectivesTree(Sender: TObject;
558
604
    procedure OnCodeBufferEncodeSaving(Code: TCodeBuffer;
559
605
                                    const Filename: string; var Source: string);
560
606
    function OnCodeToolBossGetMethodName(const Method: TMethod;
561
 
                                       PropOwner: TObject): String;
 
607
                                         PropOwner: TObject): String;
562
608
    procedure CodeToolBossPrepareTree(Sender: TObject);
563
609
    procedure CodeToolBossProgress(Sender: TObject; Index, MaxIndex: integer;
564
610
                                   const Msg: string; var Abort: boolean);
589
635
            out aBounds: TRect; out DockSibling: string; out DockAlign: TAlign);
590
636
  private
591
637
    FUserInputSinceLastIdle: boolean;
 
638
    FDesignerToBeFreed: TFilenameToStringTree; // form file names to be freed OnIdle.
592
639
    FDisplayState: TDisplayState;
593
640
    FLastFormActivated: TCustomForm;// used to find the last form so you can
594
641
                                    // display the correct tab
 
642
    FApplicationIsActivate: boolean;
595
643
    FCheckingFilesOnDisk: boolean;
596
644
    FCheckFilesOnDiskNeeded: boolean;
 
645
    fNeedSaveEnvironment: boolean;
597
646
    FRemoteControlTimer: TTimer;
598
 
    FRemoteControlFileValid: boolean;
 
647
    FRemoteControlFileAge: integer;
599
648
 
600
649
    FIDECodeToolsDefines: TIDECodetoolsDefines;
601
650
 
628
677
    procedure SetupEditMenu; override;
629
678
    procedure SetupSearchMenu; override;
630
679
    procedure SetupViewMenu; override;
 
680
    procedure SetupSourceMenu; override;
631
681
    procedure SetupProjectMenu; override;
632
682
    procedure SetupRunMenu; override;
633
 
    procedure SetupComponentsMenu; override;
 
683
    procedure SetupPackageMenu; override;
634
684
    procedure SetupToolsMenu; override;
635
 
    procedure SetupEnvironmentMenu; override;
636
685
    procedure SetupWindowsMenu; override;
637
686
    procedure SetupHelpMenu; override;
638
687
    procedure LoadMenuShortCuts; override;
645
694
    procedure SetupObjectInspector;
646
695
    procedure SetupFormEditor;
647
696
    procedure SetupSourceNotebook;
648
 
    procedure SetupTransferMacros;
649
697
    procedure SetupCodeMacros;
650
698
    procedure SetupControlSelection;
651
699
    procedure SetupIDECommands;
657
705
    procedure FreeIDEWindows;
658
706
    function CloseQueryIDEWindows: boolean;
659
707
 
 
708
    function GetActiveDesignerSkipMainBar: TComponentEditorDesigner;
660
709
    procedure ReloadMenuShortCuts;
661
710
 
662
711
    // methods for 'new unit'
666
715
    function CreateNewForm(NewUnitInfo: TUnitInfo;
667
716
        AncestorType: TPersistentClass; ResourceCode: TCodeBuffer;
668
717
        UseCreateFormStatements, DisableAutoSize: Boolean): TModalResult;
 
718
    function NewUniqueComponentName(Prefix: string): string;
669
719
 
670
720
    // methods for 'save unit'
671
721
    function DoShowSaveFileAsDialog(var AFilename: string; AnUnitInfo: TUnitInfo;
672
 
        var ResourceCode: TCodeBuffer; CanAbort: boolean): TModalResult;
 
722
        var LFMCode, LRSCode: TCodeBuffer; CanAbort: boolean): TModalResult;
673
723
    function DoSaveUnitComponent(AnUnitInfo: TUnitInfo;
674
 
        ResourceCode, LFMCode: TCodeBuffer; Flags: TSaveFlags): TModalResult;
 
724
        LRSCode, LFMCode: TCodeBuffer; Flags: TSaveFlags): TModalResult;
675
725
    function DoRemoveDanglingEvents(AnUnitInfo: TUnitInfo;
676
726
        OkOnCodeErrors: boolean): TModalResult;
677
727
    function DoRenameUnit(AnUnitInfo: TUnitInfo; NewFilename, NewUnitName: string;
678
 
        var ResourceCode: TCodeBuffer): TModalresult;
 
728
        var LFMCode, LRSCode: TCodeBuffer): TModalResult;
679
729
 
680
730
    // methods for 'open unit' and 'open main unit'
681
731
    function DoOpenNotExistingFile(const AFileName:string;
685
735
    function DoOpenFileInSourceEditor(AnEditorInfo: TUnitEditorInfo;
686
736
        PageIndex, WindowIndex: integer; Flags: TOpenFlags): TModalResult;
687
737
    function DoLoadResourceFile(AnUnitInfo: TUnitInfo;
688
 
        var LFMCode, ResourceCode: TCodeBuffer;
 
738
        var LFMCode, LRSCode: TCodeBuffer;
689
739
        IgnoreSourceErrors, AutoCreateResourceCode, ShowAbort: boolean): TModalResult;
690
740
    function DoLoadLFM(AnUnitInfo: TUnitInfo; OpenFlags: TOpenFlags;
691
741
                       CloseFlags: TCloseFlags): TModalResult;
707
757
                           var ComponentUnitInfo: TUnitInfo): TModalResult;
708
758
 
709
759
    // methods for 'close unit'
 
760
    procedure FreeDesigner(AnUnitInfo: TUnitInfo; ADesigner: TDesigner;
 
761
                           AFreeComponent: boolean);
710
762
    function CloseUnitComponent(AnUnitInfo: TUnitInfo; Flags: TCloseFlags
711
763
                                ): TModalResult;
712
764
    function CloseDependingUnitComponents(AnUnitInfo: TUnitInfo;
713
765
                                          Flags: TCloseFlags): TModalResult;
714
766
    function UnitComponentIsUsed(AnUnitInfo: TUnitInfo;
715
767
                                 CheckHasDesigner: boolean): boolean;
 
768
    function RemoveFilesFromProject(AProject: TProject; UnitInfos: TFPList): TModalResult;
716
769
 
717
770
    // methods for creating a project
718
771
    function CreateProjectObject(ProjectDesc,
734
787
    procedure SaveSrcEditorProjectSpecificSettings(AnEditorInfo: TUnitEditorInfo);
735
788
    procedure SaveSourceEditorProjectSpecificSettings;
736
789
    function DoShowSaveProjectAsDialog(UseMainSourceFile: boolean): TModalResult;
 
790
    function AskSaveProject(const ContinueText, ContinueBtn: string): TModalResult;
737
791
 
738
792
    // methods for open project, create project from source
739
793
    function DoCompleteLoadingProjectInfo: TModalResult;
740
794
 
741
795
    // methods for publish project
742
 
    procedure OnCopyFile(const Filename: string; var Copy: boolean;
743
 
        Data: TObject);
 
796
    procedure OnCopyFile(const Filename: string; var Copy: boolean; Data: TObject);
744
797
    procedure OnCopyError(const ErrorData: TCopyErrorData;
745
798
        var Handled: boolean; Data: TObject);
746
799
  public
755
808
 
756
809
    // files/units
757
810
    function DoNewFile(NewFileDescriptor: TProjectFileDescriptor;
758
 
        var NewFilename: string; const NewSource: string;
 
811
        var NewFilename: string; NewSource: string;
759
812
        NewFlags: TNewFlags; NewOwner: TObject): TModalResult; override;
760
813
    function DoNewOther: TModalResult;
 
814
    procedure CreateFileDialogFilterForSourceEditorFiles(Filter: string;
 
815
         out AllEditorMask, AllMask: string);
761
816
 
762
817
    function DoSaveEditorFile(PageIndex:integer;
763
818
                              Flags: TSaveFlags): TModalResult; override;
805
860
                           OpenFlags: TOpenFlags): TModalResult; override;
806
861
    procedure BeginFixupComponentReferences;
807
862
    procedure EndFixupComponentReferences;
808
 
    function DoSaveAll(Flags: TSaveFlags): TModalResult;
 
863
    function DoSaveAll(Flags: TSaveFlags): TModalResult; override;
809
864
    procedure DoRestart;
810
865
    procedure DoExecuteRemoteControl;
811
866
    function DoOpenMainUnit(PageIndex, WindowIndex: integer; Flags: TOpenFlags): TModalResult;
818
873
    procedure DoShowCodeExplorer(Show: boolean);
819
874
    procedure DoShowCodeBrowser(Show: boolean);
820
875
    procedure DoShowRestrictionBrowser(Show: boolean; const RestrictedName: String = '');
821
 
    procedure DoShowComponentList(Show: boolean);
 
876
    procedure DoShowComponentList(Show: boolean); override;
 
877
    procedure DoShowInspector(Show: boolean);
822
878
    procedure CreateIDEWindow(Sender: TObject; aFormName: string;
823
879
                          var AForm: TCustomForm; DoDisableAutoSizing: boolean);
824
880
    function CreateNewUniqueFilename(const Prefix, Ext: string;
830
886
      ACaretPoint: TPoint; WantedTopLine: integer = -1): TUnitEditorInfo;
831
887
 
832
888
    // project(s)
833
 
    procedure DoLoadDefaultCompilerOptions(AProject: TProject);
 
889
    procedure DoMergeDefaultProjectOptions(AProject: TProject);
834
890
    function DoNewProject(ProjectDesc: TProjectDescriptor): TModalResult; override;
835
891
    function DoSaveProject(Flags: TSaveFlags): TModalResult; override;
836
892
    function DoCloseProject: TModalResult; override;
845
901
    function DoWarnAmbiguousFiles: TModalResult;
846
902
    procedure DoUpdateProjectResourceInfo;
847
903
    function DoSaveForBuild(AReason: TCompileReason): TModalResult; override;
848
 
    function DoCheckIfProjectNeedsCompilation(AProject: TProject;
849
 
                    const CompilerFilename, CompilerParams, SrcFilename: string;
850
 
                    out NeedBuildAllFlag: boolean): TModalResult;
851
904
    function DoBuildProject(const AReason: TCompileReason;
852
905
                            Flags: TProjectBuildFlags): TModalResult; override;
853
906
    function UpdateProjectPOFile(AProject: TProject): TModalResult;
859
912
    function DoCreateProjectForProgram(ProgramBuf: TCodeBuffer): TModalResult;
860
913
    function DoSaveProjectIfChanged: TModalResult;
861
914
    function DoSaveProjectToTestDirectory(Flags: TSaveFlags): TModalResult;
862
 
    function DoTestCompilerSettings(
863
 
                            TheCompilerOptions: TCompilerOptions): TModalResult;
864
915
    function CheckMainSrcLCLInterfaces(Silent: boolean): TModalResult;
865
916
    function QuitIDE: boolean;
866
917
 
867
918
    // edit menu
868
919
    procedure DoCommand(ACommand: integer); override;
869
 
    procedure DoSourceEditorCommand(EditorCommand: integer);
 
920
    procedure DoSourceEditorCommand(EditorCommand: integer; CheckFocus: boolean = true);
870
921
    procedure UpdateCustomToolsInMenu;
871
922
 
872
923
    // external tools
874
925
    function OnRunExternalTool(Tool: TIDEExternalToolOptions): TModalResult;
875
926
    function DoRunExternalTool(Index: integer; ShowAbort: Boolean): TModalResult;
876
927
    function DoSaveBuildIDEConfigs(Flags: TBuildLazarusFlags): TModalResult; override;
 
928
    function DoManageExamples(): TModalResult; override;
877
929
    function DoBuildLazarus(Flags: TBuildLazarusFlags): TModalResult; override;
878
930
    function DoBuildAdvancedLazarus(ProfileNames: TStringList): TModalResult;
879
931
    function DoBuildFile(ShowAbort: Boolean): TModalResult;
929
981
    function DoPublishModule(Options: TPublishModuleOptions;
930
982
                             const SrcDirectory, DestDirectory: string
931
983
                             ): TModalResult; override;
 
984
    procedure PrepareBuildTarget(Quiet: boolean;
 
985
                               ScanFPCSrc: TScanModeFPCSources = smsfsBackground); override;
932
986
    procedure AbortBuild; override;
933
987
 
934
988
    // useful frontend methods
942
996
    procedure UnhideIDE; override;
943
997
 
944
998
    // methods for codetools
945
 
    procedure InitCodeToolBoss;
 
999
    function InitCodeToolBoss: boolean;
946
1000
    procedure ActivateCodeToolAbortableMode;
947
1001
    function BeginCodeTools: boolean; override;
948
1002
    function BeginCodeTool(var ActiveSrcEdit: TSourceEditor;
954
1008
                           Flags: TCodeToolsFlags): boolean;
955
1009
    function DoJumpToSourcePosition(const Filename: string;
956
1010
                               NewX, NewY, NewTopLine: integer;
957
 
                               AddJumpPoint: boolean; MarkLine: Boolean = False): TModalResult; override;
958
 
    function DoJumpToCodePos(
959
 
                        ActiveSrcEdit: TSourceEditor;
 
1011
                               Flags: TJumpToCodePosFlags = [jfFocusEditor]): TModalResult; override;
 
1012
    function DoJumpToCodePosition(
 
1013
                        ActiveSrcEdit: TSourceEditorInterface;
960
1014
                        ActiveUnitInfo: TUnitInfo;
961
1015
                        NewSource: TCodeBuffer; NewX, NewY, NewTopLine: integer;
962
 
                        AddJumpPoint: boolean; FocusEditor: Boolean = True; MarkLine: Boolean = False): TModalResult; override;
 
1016
                        Flags: TJumpToCodePosFlags = [jfFocusEditor]): TModalResult; override;
963
1017
    procedure DoJumpToCodeToolBossError; override;
964
1018
    procedure UpdateSourceNames;
965
1019
    function NeedSaveSourceEditorChangesToCodeCache(PageIndex: integer): boolean; override;
969
1023
        deprecated {$IFDEF VER2_5}'use method with EditorObject'{$ENDIF};   // deprecated in 0.9.29 March 2010
970
1024
    function SaveSourceEditorChangesToCodeCache(AEditor: TSourceEditorInterface): boolean; override;
971
1025
    procedure ApplyCodeToolChanges;
972
 
    procedure DoJumpToProcedureSection;
 
1026
    procedure DoJumpToOtherProcedureSection;
973
1027
    procedure DoFindDeclarationAtCursor;
974
1028
    procedure DoFindDeclarationAtCaret(const LogCaretXY: TPoint);
975
1029
    function DoFindRenameIdentifier(Rename: boolean): TModalResult;
979
1033
    function DoShowAbstractMethods: TModalResult;
980
1034
    function DoRemoveEmptyMethods: TModalResult;
981
1035
    function DoRemoveUnusedUnits: TModalResult;
 
1036
    function DoUseUnit: TModalResult;
982
1037
    function DoFindOverloads: TModalResult;
983
1038
    function DoInitIdentCompletion(JumpToError: boolean): boolean;
984
1039
    function DoShowCodeContext(JumpToError: boolean): boolean;
996
1051
                                ItemType: TIDEProjectItem;
997
1052
                                MultiSelect: boolean;
998
1053
                                var MultiSelectCheckedState: Boolean): TModalResult;
 
1054
    function SelectUnitComponents(DlgCaption: string; ItemType: TIDEProjectItem;
 
1055
      Files: TStringList;
 
1056
      MultiSelect: boolean; var MultiSelectCheckedState: Boolean): TModalResult;
999
1057
 
1000
1058
    // tools
1001
1059
    function DoMakeResourceString: TModalResult;
1002
1060
    function DoDiff: TModalResult;
1003
1061
    function DoFindInFiles: TModalResult;
1004
1062
    procedure DoInsertGUID;
 
1063
    procedure DoInsertFilename;
1005
1064
 
1006
1065
    // conversion
1007
1066
    function DoConvertDFMtoLFM: TModalResult;
1019
1078
 
1020
1079
    // methods for debugging, compiling and external tools
1021
1080
    function GetTestBuildDirectory: string; override;
1022
 
    procedure OnMacroSubstitution(TheMacro: TTransferMacro;
1023
 
                               const MacroName: string; var s: string;
1024
 
                               const Data: PtrInt; var Handled, Abort: boolean;
1025
 
                               Depth: integer);
1026
1081
    procedure GetIDEFileState(Sender: TObject; const AFilename: string;
1027
1082
      NeededFlags: TIDEFileStateFlags; out ResultFlags: TIDEFileStateFlags); override;
1028
1083
 
1029
1084
    // search results
1030
1085
    function DoJumpToSearchResult(FocusEditor: boolean): boolean;
1031
 
    procedure DoShowSearchResultsView(Show, BringToFront: boolean);
 
1086
    procedure DoShowSearchResultsView(Show: boolean); override;
1032
1087
 
1033
1088
    // form editor and designer
1034
1089
    procedure DoBringToFrontFormOrUnit;
1043
1098
    procedure UpdateIDEComponentPalette;
1044
1099
    procedure ShowDesignerForm(AForm: TCustomForm);
1045
1100
    procedure DoViewAnchorEditor(Show: boolean);
 
1101
    procedure DoViewTabOrderEditor(Show: boolean);
1046
1102
    procedure DoToggleViewComponentPalette;
1047
1103
    procedure DoToggleViewIDESpeedButtons;
1048
1104
 
1049
1105
    // editor and environment options
1050
 
    procedure SaveEnvironment; override;
 
1106
    procedure SaveEnvironment(Immediately: boolean = false); override;
1051
1107
    procedure LoadDesktopSettings(TheEnvironmentOptions: TEnvironmentOptions);
1052
1108
    procedure SaveDesktopSettings(TheEnvironmentOptions: TEnvironmentOptions);
1053
1109
  end;
1061
1117
 
1062
1118
implementation
1063
1119
 
 
1120
 
1064
1121
var
 
1122
  ParamBaseDirectory: string = '';
1065
1123
  SkipAutoLoadingLastProject: boolean = false;
1066
1124
  StartedByStartLazarus: boolean = false;
1067
 
  EnableRemoteControl: boolean = false;
 
1125
  ShowSetupDialog: boolean = false;
1068
1126
 
1069
1127
function FindDesignComponent(const aName: string): TComponent;
1070
1128
var
1096
1154
  space = '                      ';
1097
1155
var
1098
1156
  AHelp: TStringList;
 
1157
  HelpLang: string;
1099
1158
 
1100
1159
  procedure AddHelp(Args: array of const);
1101
1160
  var
1121
1180
        vtChar: AHelp.Add(Args[i].VChar);
1122
1181
        vtPChar: AHelp.Add(Args[i].VPChar);
1123
1182
        vtPWideChar: AHelp.Add(Args[i].VPWideChar);
1124
 
        vtWideChar: AHelp.Add(Args[i].VWideChar);
1125
 
        vtWidestring: AHelp.Add(WideString(Args[i].VWideString));
 
1183
        vtWideChar: AHelp.Add(Args[i].VWideChar{%H-});
 
1184
        vtWidestring: AHelp.Add(WideString(Args[i].VWideString){%H-});
1126
1185
        vtObject: AHelp.Add(DbgSName(Args[i].VObject));
1127
1186
        vtClass: AHelp.Add(DbgSName(Args[i].VClass));
1128
1187
        vtPointer: AHelp.Add(Dbgs(Args[i].VPointer));
1133
1192
  procedure WriteHelp(const AText: string);
1134
1193
  begin
1135
1194
    if TextRec(Output).Mode = fmClosed then
1136
 
      MessageDlg(AText, mtInformation, [mbOk], 0)
 
1195
      // Note: do not use IDEMessageDialog here:
 
1196
      MessageDlg(lisInformation, AText, mtInformation, [mbOk],0)
1137
1197
    else
1138
1198
      WriteLn(UTF8ToConsole(AText));
1139
1199
    Application.Terminate;
1140
1200
  end;
1141
1201
 
 
1202
var
 
1203
  i: integer;
 
1204
  ConfFileName: String;
 
1205
  Cfg: TXMLConfig;
1142
1206
begin
 
1207
  ParamBaseDirectory:=GetCurrentDirUTF8;
1143
1208
  StartedByStartLazarus:=false;
1144
1209
  SkipAutoLoadingLastProject:=false;
1145
1210
  EnableRemoteControl:=false;
1146
1211
  if IsHelpRequested then
1147
1212
  begin
1148
 
    TranslateResourceStrings(ProgramDirectory(true),'');
 
1213
    HelpLang := GetLanguageSpecified;
 
1214
    if HelpLang = '' then
 
1215
    begin
 
1216
      ConfFileName:=TrimFilename(SetDirSeparators(GetPrimaryConfigPath+'/'+EnvOptsConfFileName));
 
1217
      try
 
1218
        Cfg:=TXMLConfig.Create(ConfFileName);
 
1219
        try
 
1220
          HelpLang:=Cfg.GetValue('EnvironmentOptions/Language/ID','');
 
1221
        finally
 
1222
          Cfg.Free;
 
1223
        end;
 
1224
      except
 
1225
      end;
 
1226
    end;
 
1227
    if HelpLang<>'' then
 
1228
      TranslateResourceStrings(ProgramDirectory(true), HelpLang);
1149
1229
 
1150
1230
    AHelp := TStringList.Create;
1151
1231
    AddHelp([lislazarusOptionsProjectFilename]);
1156
1236
    AddHelp(['']);
1157
1237
    AddHelp(['-v or --version          ', lisShowVersionAndExit]);
1158
1238
    AddHelp(['']);
 
1239
    AddHelp([ShowSetupDialogOptLong]);
 
1240
    AddHelp([BreakString(space+lisShowSetupDialogForMostImportantSettings, 75, 22)]);
 
1241
    AddHelp(['']);
1159
1242
    AddHelp([PrimaryConfPathOptLong, ' <path>']);
1160
1243
    AddHelp(['or ', PrimaryConfPathOptShort, ' <path>']);
1161
1244
    AddHelp([BreakString(space+lisprimaryConfigDirectoryWhereLazarusStoresItsConfig,
1169
1252
    AddHelp([DebugLogOpt,' <file>']);
1170
1253
    AddHelp([BreakString(space+lisFileWhereDebugOutputIsWritten, 75, 22)]);
1171
1254
    AddHelp(['']);
 
1255
    AddHelp([DebugLogOptEnable,' [[-]OptName][,[-]OptName][...]']);
 
1256
    AddHelp([BreakString(space+lisGroupsForDebugOutput, 75, 22)]);
 
1257
    for i := 0 to DebugLogger.LogGroupList.Count - 1 do
 
1258
      AddHelp([space + DebugLogger.LogGroupList[i]^.ConfigName]);
 
1259
    AddHelp(['']);
1172
1260
    AddHelp([NoSplashScreenOptLong]);
1173
1261
    AddHelp(['or ',NoSplashScreenOptShort]);
1174
1262
    AddHelp([BreakString(space+lisDoNotShowSplashScreen,75, 22)]);
1197
1285
    exit;
1198
1286
  end;
1199
1287
 
1200
 
  SetParamOptions(SkipAutoLoadingLastProject, StartedByStartLazarus, EnableRemoteControl, ShowSplashScreen);
 
1288
  ParseGuiCmdLineParams(SkipAutoLoadingLastProject, StartedByStartLazarus,
 
1289
    EnableRemoteControl, ShowSplashScreen, ShowSetupDialog);
1201
1290
 
1202
1291
  DebugLn('TMainIDE.ParseCmdLineOptions:');
1203
1292
  Debugln('  PrimaryConfigPath="',UTF8ToConsole(GetPrimaryConfigPath),'"');
1206
1295
 
1207
1296
procedure TMainIDE.LoadGlobalOptions;
1208
1297
// load environment, miscellaneous, editor and codetools options
 
1298
var
 
1299
  EnvOptsCfgExisted: boolean;
 
1300
  s: String;
 
1301
  StartFile: String;
 
1302
  OldVer: String;
 
1303
  NowVer: String;
 
1304
  IsUpgrade: boolean;
 
1305
  MsgResult: TModalResult;
1209
1306
begin
1210
 
  EnvironmentOptions := TEnvironmentOptions.Create;
1211
1307
  with EnvironmentOptions do
1212
1308
  begin
 
1309
    EnvOptsCfgExisted := FileExistsCached(GetDefaultConfigFilename);
1213
1310
    OnBeforeRead := @DoEnvironmentOptionsBeforeRead;
1214
1311
    OnBeforeWrite := @DoEnvironmentOptionsBeforeWrite;
1215
1312
    OnAfterWrite := @DoEnvironmentOptionsAfterWrite;
1216
 
    SetLazarusDefaultFilename;
 
1313
    CreateConfig;
1217
1314
    Load(false);
1218
1315
    if Application.HasOption('language') then
1219
1316
    begin
1230
1327
 
1231
1328
    Application.BidiMode := Application.Direction(EnvironmentOptions.LanguageID);
1232
1329
 
1233
 
    TranslateResourceStrings(EnvironmentOptions.LazarusDirectory,
 
1330
    TranslateResourceStrings(EnvironmentOptions.GetParsedLazarusDirectory,
1234
1331
                             EnvironmentOptions.LanguageID);
 
1332
    MainBuildBoss.TranslateMacros;
1235
1333
 
1236
 
    ExternalTools.OnNeedsOutputFilter := @OnExtToolNeedsOutputFilter;
1237
 
    ExternalTools.OnFreeOutputFilter := @OnExtToolFreeOutputFilter;
1238
1334
    Application.ShowButtonGlyphs := ShowButtonGlyphs;
1239
1335
    Application.ShowMenuGlyphs := ShowMenuGlyphs;
1240
1336
  end;
1241
 
  IDEWindowCreators.OnShowForm:=@IDEWindowCreators.SimpleLayoutStorage.ApplyAndShow;
 
1337
 
 
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
 
1342
  begin
 
1343
    IsUpgrade:=CompareLazarusVersion(NowVer,OldVer)>0;
 
1344
    if OldVer='' then
 
1345
      OldVer:=Format(lisPrior, [GetLazarusVersionString]);
 
1346
    s:=Format(lisWelcomeToLazarusThereIsAlreadyAConfigurationFromVe, [
 
1347
      GetLazarusVersionString, #13, #13, OldVer, #13, GetPrimaryConfigPath, #13]
 
1348
      );
 
1349
    if IsUpgrade then
 
1350
      s+=lisTheOldConfigurationWillBeUpgraded
 
1351
    else
 
1352
      s+=lisTheConfigurationWillBeDowngradedConverted;
 
1353
    s+=#13
 
1354
      +#13;
 
1355
    s+=Format(lisIfYouWantToUseTwoDifferentLazarusVersionsYouMustSt, [#13, #13,
 
1356
      #13]);
 
1357
    StartFile:=Application.ExeName;
 
1358
    if StartedByStartLazarus then
 
1359
      StartFile:=ExtractFilePath(StartFile)+'startlazarus'+GetExeExt;
 
1360
    {$IFDEF Windows}
 
1361
      s+=StartFile+' --pcp=C:\test_lazarus\configs';
 
1362
    {$ELSE}
 
1363
      {$IFDEF darwin}
 
1364
      s+='open '+StartFile+' --pcp=~/.lazarus_test';
 
1365
      {$ELSE}
 
1366
      s+=StartFile+' --pcp=~/.lazarus_test';
 
1367
      {$ENDIF}
 
1368
    {$ENDIF}
 
1369
    if IsUpgrade then
 
1370
      MsgResult:=IDEQuestionDialog(lisUpgradeConfiguration, s, mtConfirmation, [
 
1371
        mrOK, lisUpgrade, mrAbort])
 
1372
    else
 
1373
      MsgResult:=IDEQuestionDialog(lisDowngradeConfiguration, s, mtWarning, [
 
1374
        mrOK, lisDowngrade, mrAbort]);
 
1375
    if MsgResult<>mrOk then begin
 
1376
      Application.Terminate;
 
1377
      exit;
 
1378
    end;
 
1379
  end;
 
1380
 
 
1381
  ExternalTools.OnNeedsOutputFilter := @OnExtToolNeedsOutputFilter;
 
1382
  ExternalTools.OnFreeOutputFilter := @OnExtToolFreeOutputFilter;
1242
1383
  UpdateDefaultPascalFileExtensions;
 
1384
  LoadFileDialogFilter;
1243
1385
 
1244
1386
  EditorOpts := TEditorOptions.Create;
1245
1387
  EditorOpts.OnBeforeRead := @DoEditorOptionsBeforeRead;
1248
1390
  SetupIDEMsgQuickFixItems;
1249
1391
  EditorOpts.Load;
1250
1392
 
1251
 
  EnvironmentOptions.ExternalTools.LoadShortCuts(EditorOpts.KeyMap);
 
1393
  ExternalTools.LoadShortCuts(EditorOpts.KeyMap);
1252
1394
 
1253
1395
  MiscellaneousOptions := TMiscellaneousOptions.Create;
1254
1396
  MiscellaneousOptions.Load;
1265
1407
  CodeExplorerOptions.OnAfterWrite := @DoCodeExplorerOptionsAfterWrite;
1266
1408
  CodeExplorerOptions.Load;
1267
1409
 
 
1410
  DebuggerOptions := TDebuggerOptions.Create;
 
1411
 
1268
1412
  MainBuildBoss.SetupInputHistories;
1269
1413
  CompileProgress.SetEnabled(EnvironmentOptions.ShowCompileDialog);
1270
1414
 
1275
1419
var
1276
1420
  Layout: TSimpleWindowLayout;
1277
1421
  FormCreator: TIDEWindowCreator;
 
1422
  AMenuHeight: Integer;
1278
1423
begin
1279
1424
  {$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.Create START');{$ENDIF}
1280
1425
  inherited Create(TheOwner);
1296
1441
  MainBuildBoss:=TBuildManager.Create(nil);
1297
1442
  MainBuildBoss.HasGUI:=true;
1298
1443
  {$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.Create BUILD MANAGER');{$ENDIF}
 
1444
  // setup macros before loading options
 
1445
  MainBuildBoss.SetupTransferMacros;
1299
1446
 
1300
1447
  // load options
1301
1448
  CreatePrimaryConfigPath;
1302
1449
  StartProtocol;
1303
1450
  LoadGlobalOptions;
 
1451
  if Application.Terminated then exit;
 
1452
 
1304
1453
  if EnvironmentOptions.SingleTaskBarButton then
1305
1454
    Application.TaskBarBehavior := tbSingleButton;
1306
1455
 
1307
1456
  // set the IDE mode to none (= editing mode)
1308
1457
  ToolStatus:=itNone;
1309
1458
 
1310
 
  // setup macros
1311
 
  SetupTransferMacros;
 
1459
  // setup code templates
1312
1460
  SetupCodeMacros;
1313
1461
 
1314
1462
  // setup the code tools
1315
 
  InitCodeToolBoss;
 
1463
  if not InitCodeToolBoss then begin
 
1464
    Application.Terminate;
 
1465
    exit;
 
1466
  end;
1316
1467
  {$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.Create CODETOOLS');{$ENDIF}
1317
1468
 
1318
1469
  // build and position the MainIDE form
1319
1470
  Application.CreateForm(TMainIDEBar,MainIDEBar);
1320
1471
  MainIDEBar.OnDestroy:=@OnMainBarDestroy;
1321
 
 
1322
 
  MainIDEBar.Constraints.MaxHeight:=110;
 
1472
  MainIDEBar.OnActive:=@OnMainBarActive;
 
1473
 
 
1474
  AMenuHeight := LCLIntf.GetSystemMetrics(SM_CYMENU);
 
1475
  if AMenuHeight > 0 then
 
1476
  begin
 
1477
    // what we know:
 
1478
    // 1. cmd speedbuttons height = 22
 
1479
    // 2. components palette buttons = 32
 
1480
    // 3. menu height provided by widgetset (varies , depends on theme)
 
1481
    // so we set 22 + 32 + (borders * 2).
 
1482
    MainIDEBar.Constraints.MaxHeight := AMenuHeight +
 
1483
      22 {cmd speedbtns} + 32 {component buttons} +
 
1484
      LCLIntf.GetSystemMetrics(SM_CYSIZEFRAME) +
 
1485
      (LCLIntf.GetSystemMetrics(SM_CYBORDER) * 2) {borders};
 
1486
  end else
 
1487
    MainIDEBar.Constraints.MaxHeight:=85;
 
1488
 
1323
1489
  MainIDEBar.Name := NonModalIDEWindowNames[nmiwMainIDEName];
1324
1490
  FormCreator:=IDEWindowCreators.Add(MainIDEBar.Name);
1325
1491
  FormCreator.Right:='100%';
1332
1498
 
1333
1499
  HiddenWindowsOnRun:=TList.Create;
1334
1500
 
 
1501
  LastActivatedWindows:=TList.Create;
1335
1502
  // menu
1336
1503
  MainIDEBar.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TMainIDE.Create'){$ENDIF};
1337
1504
  try
1390
1557
  Application.AddOnUserInputHandler(@OnApplicationUserInput);
1391
1558
  Application.AddOnIdleHandler(@OnApplicationIdle);
1392
1559
  Application.AddOnActivateHandler(@OnApplicationActivate);
 
1560
  Application.AddOnDeActivateHandler(@OnApplicationDeActivate);
1393
1561
  Application.AddOnKeyDownHandler(@OnApplicationKeyDown);
1394
1562
  Application.AddOnDropFilesHandler(@OnApplicationDropFiles);
 
1563
  Application.AddOnQueryEndSessionHandler(@OnApplicationQueryEndSession);
 
1564
  Application.AddOnEndSessionHandler(@OnApplicationEndSession);
1395
1565
  Screen.AddHandlerRemoveForm(@OnScreenRemoveForm);
 
1566
  Screen.AddHandlerActiveFormChanged(@OnScreenChangedForm);
1396
1567
  SetupHints;
1397
 
 
1398
1568
  SetupIDEWindowsLayout;
1399
1569
  RestoreIDEWindows;
1400
1570
  // make sure the main IDE bar is always shown
1401
1571
  IDEWindowCreators.ShowForm(MainIDEBar,false);
1402
 
 
1403
 
  // Now load a project
1404
 
  SetupStartProject;
1405
 
 
1406
 
  // reopen extra windows
1407
 
  DoShowMessagesView(false);
 
1572
  DebugBoss.UpdateButtonsAndMenuItems; // Disable Stop-button (and some others).
 
1573
  SetupStartProject;                   // Now load a project
 
1574
  DoShowMessagesView(false);           // reopen extra windows
 
1575
  fUserInputSinceLastIdle:=true; // Idle work gets done initially before user action.
 
1576
  FApplicationIsActivate:=true;
1408
1577
  {$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.StartIDE END');{$ENDIF}
1409
1578
end;
1410
1579
 
1415
1584
  DebugLn('[TMainIDE.Destroy] A ');
1416
1585
 
1417
1586
  {$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.Destroy A ');{$ENDIF}
1418
 
  MainIDEBar.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TMainIDE.Destroy'){$ENDIF};
 
1587
  if Assigned(MainIDEBar) then
 
1588
    MainIDEBar.DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TMainIDE.Destroy'){$ENDIF};
1419
1589
 
1420
1590
  if DebugBoss<>nil then DebugBoss.EndDebugging;
1421
1591
 
1424
1594
    TheControlSelection.OnSelectionFormChanged:=nil;
1425
1595
  end;
1426
1596
 
 
1597
  FreeAndNil(FDesignerToBeFreed);
1427
1598
  FreeAndNil(JumpHistoryViewWin);
1428
1599
  FreeAndNil(ComponentListForm);
1429
1600
  FreeThenNil(ProjInspector);
1432
1603
  FreeAndNil(LazFindReplaceDialog);
1433
1604
  FreeAndNil(MessagesView);
1434
1605
  FreeThenNil(AnchorDesigner);
 
1606
  FreeThenNil(SearchResultsView);
1435
1607
  FreeThenNil(ObjectInspector1);
1436
1608
  FreeThenNil(SourceEditorManagerIntf);
1437
1609
 
1454
1626
  FreeThenNil(DebugBoss);
1455
1627
  FreeThenNil(TheCompiler);
1456
1628
  FreeThenNil(HiddenWindowsOnRun);
 
1629
  FreeThenNil(LastActivatedWindows);
1457
1630
  FreeThenNil(IDEMsgScanners);
1458
1631
  FreeThenNil(TheOutputFilter);
1459
1632
  FreeThenNil(GlobalMacroList);
1468
1641
  FreeThenNil(CodeExplorerOptions);
1469
1642
  FreeThenNil(MiscellaneousOptions);
1470
1643
  FreeThenNil(EditorOpts);
1471
 
  IDEWindowCreators.OnShowForm:=nil;
 
1644
  FreeThenNil(DebuggerOptions);
1472
1645
  FreeThenNil(EnvironmentOptions);
1473
1646
  FreeThenNil(IDECommandScopes);
1474
1647
 
1496
1669
 
1497
1670
procedure TMainIDE.OIOnSelectPersistents(Sender: TObject);
1498
1671
begin
 
1672
  if ObjectInspector1=nil then exit;
1499
1673
  TheControlSelection.AssignSelection(ObjectInspector1.Selection);
1500
1674
  GlobalDesignHook.SetSelection(ObjectInspector1.Selection);
1501
1675
end;
1509
1683
var
1510
1684
  C: TClass;
1511
1685
begin
 
1686
  if ObjectInspector1=nil then exit;
1512
1687
  C := nil;
1513
1688
  if (ObjectInspector1.Selection <> nil) and
1514
1689
      (ObjectInspector1.Selection.Count > 0) then
1515
1690
  begin
1516
1691
    C := ObjectInspector1.Selection[0].ClassType;
1517
 
    if C.InheritsFrom(TForm) then C := TForm
1518
 
    else
1519
 
      if C.InheritsFrom(TCustomForm) then C := TCustomForm
1520
 
        else
1521
 
          if C.InheritsFrom(TDataModule) then C := TDataModule
1522
 
            else
1523
 
              if C.InheritsFrom(TFrame) then C := TFrame;
 
1692
    if C.InheritsFrom(TForm) then
 
1693
      C := TForm
 
1694
    else if C.InheritsFrom(TCustomForm) then
 
1695
      C := TCustomForm
 
1696
    else if C.InheritsFrom(TDataModule) then
 
1697
      C := TDataModule
 
1698
    else if C.InheritsFrom(TFrame) then
 
1699
      C := TFrame;
1524
1700
  end;
1525
1701
 
1526
 
 
1527
1702
  if ObjectInspector1.GetActivePropertyRow = nil then
1528
1703
  begin
1529
1704
    if C <> nil then
1559
1734
 
1560
1735
procedure TMainIDE.OIOnAddToFavourites(Sender: TObject);
1561
1736
begin
 
1737
  if ObjectInspector1=nil then exit;
1562
1738
  ShowAddRemoveFavouriteDialog(ObjectInspector1,true);
1563
1739
end;
1564
1740
 
1565
1741
procedure TMainIDE.OIOnRemoveFromFavourites(Sender: TObject);
1566
1742
begin
 
1743
  if ObjectInspector1=nil then exit;
1567
1744
  ShowAddRemoveFavouriteDialog(ObjectInspector1,false);
1568
1745
end;
1569
1746
 
1603
1780
  AHint:='';
1604
1781
  HintWinRect:=Rect(0,0,0,0);
1605
1782
  if not BeginCodeTools then exit;
 
1783
  if ObjectInspector1=nil then exit;
1606
1784
  if FindDeclarationOfOIProperty(ObjectInspector1,PointedRow,Code,Caret,NewTopLine)
1607
1785
  then begin
1608
1786
    if TIDEHelpManager(HelpBoss).GetHintForSourcePosition(Code.Filename,
1673
1851
  end;
1674
1852
end;
1675
1853
 
 
1854
procedure TMainIDE.OnPropHookGetCompatibleMethods(InstProp: PInstProp;
 
1855
  const Proc: TGetStrProc);
 
1856
var
 
1857
  ActiveSrcEdit: TSourceEditor;
 
1858
  ActiveUnitInfo: TUnitInfo;
 
1859
begin
 
1860
  if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[ctfSwitchToFormSource])
 
1861
  then exit;
 
1862
  {$IFDEF IDE_DEBUG}
 
1863
  DebugLn('');
 
1864
  DebugLn('[TMainIDE.OnPropHookGetCompatibleMethods] ************');
 
1865
  {$ENDIF}
 
1866
  if not CodeToolBoss.GetCompatiblePublishedMethods(ActiveUnitInfo.Source,
 
1867
    ActiveUnitInfo.Component.ClassName,
 
1868
    InstProp^.Instance,InstProp^.PropInfo^.Name,Proc) then
 
1869
  begin
 
1870
    DoJumpToCodeToolBossError;
 
1871
  end;
 
1872
end;
 
1873
 
 
1874
function TMainIDE.OnPropHookCompatibleMethodExists(const AMethodName: String;
 
1875
  InstProp: PInstProp; var MethodIsCompatible, MethodIsPublished,
 
1876
  IdentIsMethod: boolean): boolean;
 
1877
var
 
1878
  ActiveSrcEdit: TSourceEditor;
 
1879
  ActiveUnitInfo: TUnitInfo;
 
1880
begin
 
1881
  if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[ctfSwitchToFormSource]) then
 
1882
    Exit;
 
1883
  {$IFDEF IDE_DEBUG}
 
1884
  WriteLn('');
 
1885
  WriteLn('[TMainIDE.OnPropHookCompatibleMethodExists] ************ ',AMethodName);
 
1886
  {$ENDIF}
 
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
 
1892
  begin
 
1893
    DoJumpToCodeToolBossError;
 
1894
    raise Exception.Create(lisUnableToFindMethod+' '+lisPleaseFixTheErrorInTheMessageWindow);
 
1895
  end;
 
1896
end;
 
1897
 
1676
1898
{------------------------------------------------------------------------------}
1677
1899
procedure TMainIDE.MainIDEFormClose(Sender: TObject;
1678
1900
  var CloseAction: TCloseAction);
1679
1901
begin
1680
1902
  DoCallNotifyHandler(lihtIDEClose);
1681
 
  SaveEnvironment;
 
1903
  SaveEnvironment(true);
1682
1904
  if IDEDockMaster<>nil then
1683
1905
    IDEDockMaster.CloseAll
1684
1906
  else
1686
1908
  SaveIncludeLinks;
1687
1909
  InputHistories.Save;
1688
1910
  PkgBoss.SaveSettings;
1689
 
  if TheControlSelection<>nil then TheControlSelection.Clear;
 
1911
  if TheControlSelection<>nil then
 
1912
    TheControlSelection.Clear;
1690
1913
  FreeIDEWindows;
1691
1914
end;
1692
1915
 
1693
 
procedure TMainIDE.MainIDEFormCloseQuery(Sender: TObject;
1694
 
  var CanClose: boolean);
1695
 
var
1696
 
  MsgResult: integer;
 
1916
procedure TMainIDE.MainIDEFormCloseQuery(Sender: TObject; var CanClose: boolean);
1697
1917
const IsClosing: Boolean = False;
1698
1918
begin
1699
1919
  CanClose := True;
1708
1928
    // check foreign windows
1709
1929
    if not CloseQueryIDEWindows then exit;
1710
1930
 
1711
 
    // check packages
1712
 
    if (PkgBoss.DoSaveAllPackages([psfAskBeforeSaving])<>mrOk)
1713
 
    or (PkgBoss.DoCloseAllPackageEditors<>mrOk) then exit;
1714
 
 
1715
 
    // check project
1716
 
    if SomethingOfProjectIsModified then begin
1717
 
      MsgResult:=QuestionDlg(lisProjectChanged,
1718
 
        Format(lisSaveChangesToProject, [Project1.Title]), mtConfirmation,
1719
 
        [mrYes, lisMenuSave, mrNoToAll, lisDiscardChanges,
1720
 
         mrAbort, lisDoNotCloseTheIDE],
1721
 
        0);
1722
 
      case MsgResult of
1723
 
 
1724
 
      mrYes:
1725
 
        begin
1726
 
          CanClose := DoSaveProject([]) <> mrAbort;
1727
 
          if not CanClose then exit;
1728
 
        end;
1729
 
 
1730
 
      mrCancel, mrAbort:
1731
 
        begin
1732
 
          Exit;
1733
 
        end;
1734
 
      end;
1735
 
    end;
 
1931
    // save packages
 
1932
    if PkgBoss.DoCloseAllPackageEditors<>mrOk then exit;
 
1933
 
 
1934
    // save project
 
1935
    if AskSaveProject(lisDoYouStillWantToQuit,lisDiscardChangesAndQuit)<>mrOk then
 
1936
      exit;
1736
1937
 
1737
1938
    CanClose:=(DoCloseProject <> mrAbort);
1738
1939
  finally
1746
1947
{------------------------------------------------------------------------------}
1747
1948
procedure TMainIDE.SetupSpeedButtons;
1748
1949
 
1749
 
  function CreateButton(AToolBar: TToolBar; const AName, APixName: String;     
 
1950
  function CreateButton(AToolBar: TToolBar; const AName, APixName: String;
1750
1951
    const AOnClick: TNotifyEvent; const AHint: String): TToolButton;
1751
1952
  begin
1752
1953
    Result := TToolButton.Create(OwningComponent);
1798
1999
  MainIDEBar.tbStandard := CreateToolBar('tbStandard');
1799
2000
 
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);
1808
2009
 
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);
1886
2087
  GlobalDesignHook:=TPropertyEditorHook.Create;
1887
2088
  GlobalDesignHook.GetPrivateDirectory:=AppendPathDelim(GetPrimaryConfigPath);
1888
2089
  GlobalDesignHook.AddHandlerGetMethodName(@OnPropHookGetMethodName);
 
2090
  GlobalDesignHook.AddHandlerGetCompatibleMethods(@OnPropHookGetCompatibleMethods);
1889
2091
  GlobalDesignHook.AddHandlerGetMethods(@OnPropHookGetMethods);
 
2092
  GlobalDesignHook.AddHandlerCompatibleMethodExists(@OnPropHookCompatibleMethodExists);
1890
2093
  GlobalDesignHook.AddHandlerMethodExists(@OnPropHookMethodExists);
1891
2094
  GlobalDesignHook.AddHandlerCreateMethod(@OnPropHookCreateMethod);
1892
2095
  GlobalDesignHook.AddHandlerShowMethod(@OnPropHookShowMethod);
1903
2106
 
1904
2107
  IDECmdScopeObjectInspectorOnly.AddWindowClass(TObjectInspectorDlg);
1905
2108
 
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;
1925
 
 
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';
1931
 
    Interval:=400;
1932
 
    OnTimer:=@OIChangedTimerTimer;
1933
 
  end;
1934
 
 
1935
 
  IDEWindowCreators.Add(ObjectInspector1.Name,nil,@CreateIDEWindow,
 
2109
  IDEWindowCreators.Add(DefaultObjectInspectorName,nil,@CreateIDEWindow,
1936
2110
   '0','120','+230','-120','',alNone,false,@OnGetLayout);
1937
2111
 
1938
 
  EnvironmentOptions.ObjectInspectorOptions.AssignTo(ObjectInspector1);
1939
 
 
1940
2112
  ShowAnchorDesigner:=@mnuViewAnchorEditorClicked;
 
2113
  ShowTabOrderEditor:=@mnuViewTabOrderClicked;
1941
2114
end;
1942
2115
 
1943
2116
procedure TMainIDE.SetupFormEditor;
1981
2154
  SourceEditorManager.OnViewJumpHistory := @OnSrcNotebookViewJumpHistory;
1982
2155
  SourceEditorManager.OnPopupMenu := @OnSrcNoteBookPopupMenu;
1983
2156
  SourceEditorManager.OnNoteBookCloseQuery := @OnSrcNoteBookCloseQuery;
 
2157
  SourceEditorManager.OnPackageForSourceEditor := @PkgBoss.GetPackageOfSourceEditor;
1984
2158
  DebugBoss.ConnectSourceNotebookEvents;
1985
2159
 
1986
2160
  OnSearchResultsViewSelectionChanged := @SearchResultsViewSelectionChanged;
2008
2182
  SourceEditorManager.InitMacros(GlobalMacroList);
2009
2183
end;
2010
2184
 
2011
 
procedure TMainIDE.SetupTransferMacros;
2012
 
begin
2013
 
  MainBuildBoss.SetupTransferMacros;
2014
 
  GlobalMacroList.OnSubstitution:=@OnMacroSubstitution;
2015
 
 
2016
 
  // source editor
2017
 
  GlobalMacroList.Add(TTransferMacro.Create('Save','',
2018
 
                      lisSaveCurrentEditorFile,nil,[tmfInteractive]));
2019
 
  GlobalMacroList.Add(TTransferMacro.Create('SaveAll','',
2020
 
                      lisSaveAllModified,nil,[tmfInteractive]));
2021
 
end;
2022
 
 
2023
2185
procedure TMainIDE.SetupCodeMacros;
2024
2186
begin
2025
2187
  CreateStandardCodeMacros;
2031
2193
  TheControlSelection.OnChange:=@OnControlSelectionChanged;
2032
2194
  TheControlSelection.OnPropertiesChanged:=@OnControlSelectionPropsChanged;
2033
2195
  TheControlSelection.OnSelectionFormChanged:=@OnControlSelectionFormChanged;
 
2196
  GlobalDesignHook.AddHandlerGetSelection(@OnGetDesignerSelection);
2034
2197
end;
2035
2198
 
2036
2199
procedure TMainIDE.SetupIDECommands;
2050
2213
  IDECmdScopeSrcEditOnlySyncroEdit.AddWindowClass(TLazSynPluginSyncroEditForm);
2051
2214
  IDECmdScopeSrcEditOnlySyncroEditOff.AddWindowClass(TLazSynPluginSyncroEditFormOff);
2052
2215
 
2053
 
  EditorOpts.KeyMap.CreateDefaultMapping;
 
2216
  EditorOpts.KeyMap.DefineCommandCategories;
2054
2217
end;
2055
2218
 
2056
2219
procedure TMainIDE.SetupIDEMsgQuickFixItems;
2058
2221
  InitStandardIDEQuickFixItems;
2059
2222
  InitCodeBrowserQuickFixItems;
2060
2223
  InitFindUnitQuickFixItems;
 
2224
  InitInspectChecksumChangedQuickFixItems;
2061
2225
end;
2062
2226
 
2063
2227
procedure TMainIDE.SetupStartProject;
2065
2229
  function AskIfLoadLastFailingProject: boolean;
2066
2230
  begin
2067
2231
    debugln(['AskIfLoadLastFailingProject START']);
2068
 
    Result:=QuestionDlg(lisOpenProject2,
 
2232
    Result:=IDEQuestionDialog(lisOpenProject2,
2069
2233
      Format(lisAnErrorOccuredAtLastStartupWhileLoadingLoadThisPro, [
2070
2234
        EnvironmentOptions.LastSavedProjectFile, #13, #13]), mtWarning,
2071
 
        [mrYes, lisOpenProjectAgain, mrNoToAll, lisStartWithANewProject], 0)=
 
2235
        [mrYes, lisOpenProjectAgain, mrNoToAll, lisStartWithANewProject])=
2072
2236
          mrYes;
2073
2237
    debugln(['AskIfLoadLastFailingProject END ',dbgs(Result)]);
2074
2238
  end;
2169
2333
var
2170
2334
  Filename: String;
2171
2335
begin
2172
 
  // delete old remote control file
 
2336
  debugln(['TMainIDE.SetupRemoteControl ']);
 
2337
  // delete old remote commands
2173
2338
  Filename:=GetRemoteControlFilename;
2174
2339
  if FileExistsUTF8(Filename) then
2175
2340
    DeleteFileUTF8(Filename);
2183
2348
procedure TMainIDE.SetupIDEWindowsLayout;
2184
2349
begin
2185
2350
  IDEWindowCreators.Add(NonModalIDEWindowNames[nmiwMessagesViewName],
2186
 
    nil,@CreateIDEWindow,
2187
 
    '250','75%','+70%','+100',NonModalIDEWindowNames[nmiwSourceNoteBookName],alBottom,
2188
 
    false,@OnGetLayout);
 
2351
    nil,@CreateIDEWindow,'250','75%','+70%','+100',
 
2352
    NonModalIDEWindowNames[nmiwSourceNoteBookName],alBottom,false,@OnGetLayout);
2189
2353
  IDEWindowCreators.Add(NonModalIDEWindowNames[nmiwCodeExplorerName],
2190
 
    nil,@CreateIDEWindow,
2191
 
    '72%','120','+170','-200',NonModalIDEWindowNames[nmiwSourceNoteBookName],alRight);
 
2354
    nil,@CreateIDEWindow,'72%','120','+170','-200',
 
2355
    NonModalIDEWindowNames[nmiwSourceNoteBookName],alRight);
2192
2356
 
2193
2357
  IDEWindowCreators.Add(NonModalIDEWindowNames[nmiwUnitDependenciesName],
2194
2358
    nil,@CreateIDEWindow,'200','200','','');
2202
2366
    nil,@CreateIDEWindow,'250','250','+70%','+300');
2203
2367
  IDEWindowCreators.Add(NonModalIDEWindowNames[nmiwAnchorEditor],
2204
2368
    nil,@CreateIDEWindow,'250','250','','');
 
2369
  IDEWindowCreators.Add(NonModalIDEWindowNames[nmiwTabOrderEditor],
 
2370
    nil,@CreateIDEWindow,'270','270','','');
2205
2371
  IDEWindowCreators.Add(NonModalIDEWindowNames[nmiwCodeBrowser],
2206
2372
    nil,@CreateIDEWindow,'200','200','+650','+500');
2207
2373
  IDEWindowCreators.Add(NonModalIDEWindowNames[nmiwIssueBrowser],
2208
2374
    nil,@CreateIDEWindow,'250','250','','');
2209
2375
  IDEWindowCreators.Add(NonModalIDEWindowNames[nmiwJumpHistory],
2210
2376
    nil,@CreateIDEWindow,'250','250','','');
2211
 
  IDEWindowCreators.Add(ComponentListFormName,
 
2377
  IDEWindowCreators.Add(NonModalIDEWindowNames[nmiwComponentList],
2212
2378
    nil,@CreateIDEWindow,'250','250','','');
2213
2379
end;
2214
2380
 
2243
2409
begin
2244
2410
  for i:=0 to Screen.CustomFormCount-1 do begin
2245
2411
    AForm:=Screen.CustomForms[i];
2246
 
    if AForm<>MainIDEBar then begin
2247
 
      if not AForm.CloseQuery then exit(false);
2248
 
    end;
 
2412
    if AForm=MainIDEBar then continue;
 
2413
    if AForm.Designer<>nil then continue;
 
2414
    if AForm.Parent<>nil then continue;
 
2415
    if not AForm.CloseQuery then exit(false);
2249
2416
  end;
2250
2417
  Result:=true;
2251
2418
end;
2252
2419
 
 
2420
function TMainIDE.GetActiveDesignerSkipMainBar: TComponentEditorDesigner;
 
2421
// returns the designer that is currently active
 
2422
// the MainIDEBar is ignored
 
2423
var
 
2424
  ActForm: TCustomForm;
 
2425
  ActControl: TWinControl;
 
2426
begin
 
2427
  ActForm:=Screen.ActiveCustomForm;
 
2428
  if ActForm=MainIDEBar then
 
2429
  begin
 
2430
    ActControl:=ActForm.ActiveControl;
 
2431
    if (ActControl<>nil) and (GetFirstParentForm(ActControl)<>MainIDEBar) then
 
2432
      exit(nil); // a docked form has focus
 
2433
    if Screen.CustomFormZOrderCount < 2 then exit(nil);
 
2434
    ActForm:=Screen.CustomFormsZOrdered[1];
 
2435
  end;
 
2436
  if (ActForm<>nil) and (ActForm.Designer is TComponentEditorDesigner) then
 
2437
    Result := TComponentEditorDesigner(ActForm.Designer)
 
2438
  else
 
2439
    Result := nil;
 
2440
end;
 
2441
 
2253
2442
procedure TMainIDE.ReloadMenuShortCuts;
2254
2443
begin
2255
2444
  //LoadMenuShortCuts;
2264
2453
  SetupEditMenu;
2265
2454
  SetupSearchMenu;
2266
2455
  SetupViewMenu;
 
2456
  SetupSourceMenu;
2267
2457
  SetupProjectMenu;
2268
2458
  SetupRunMenu;
2269
 
  SetupComponentsMenu;
 
2459
  SetupPackageMenu;
2270
2460
  SetupToolsMenu;
2271
 
  SetupEnvironmentMenu;
2272
2461
  SetupWindowsMenu;
2273
2462
  SetupHelpMenu;
2274
2463
end;
2276
2465
procedure TMainIDE.SetupStandardIDEMenuItems;
2277
2466
begin
2278
2467
  IDEMenuRoots:=TIDEMenuRoots.Create;
 
2468
  RegisterStandardSourceTabMenuItems;
2279
2469
  RegisterStandardSourceEditorMenuItems;
2280
2470
  RegisterStandardMessagesViewMenuItems;
2281
2471
  RegisterStandardCodeExplorerMenuItems;
2328
2518
procedure TMainIDE.SetupFileMenu;
2329
2519
begin
2330
2520
  inherited SetupFileMenu;
 
2521
  mnuFile.OnClick:=@mnuFileClicked;
2331
2522
  with MainIDEBar do begin
2332
 
    mnuFile.OnClick:=@mnuFileClicked;
2333
2523
    itmFileNewUnit.OnClick := @mnuNewUnitClicked;
2334
2524
    itmFileNewForm.OnClick := @mnuNewFormClicked;
2335
2525
    itmFileNewOther.OnClick := @mnuNewOtherClicked;
2339
2529
    itmFileSave.OnClick := @mnuSaveClicked;
2340
2530
    itmFileSaveAs.OnClick := @mnuSaveAsClicked;
2341
2531
    itmFileSaveAll.OnClick := @mnuSaveAllClicked;
 
2532
    itmFileExportHtml.OnClick  := @mnuExportHtml;
2342
2533
    itmFileClose.Enabled := False;
2343
2534
    itmFileClose.OnClick := @mnuCloseClicked;
2344
2535
    itmFileCloseAll.Enabled := False;
2352
2543
procedure TMainIDE.SetupEditMenu;
2353
2544
begin
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;
2382
 
 
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;
2392
 
 
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;
2401
2568
  end;
2402
2569
end;
2403
2570
 
2404
2571
procedure TMainIDE.SetupSearchMenu;
2405
2572
begin
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;
2417
2584
begin
2418
2585
  inherited SetupViewMenu;
2419
2586
  with MainIDEBar do begin
 
2587
    itmViewToggleFormUnit.OnClick := @mnuToggleFormUnitClicked;
2420
2588
    itmViewInspector.OnClick := @mnuViewInspectorClicked;
2421
2589
    itmViewSourceEditor.OnClick := @mnuViewSourceEditorClicked;
2422
2590
    itmViewCodeExplorer.OnClick := @mnuViewCodeExplorerClick;
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;
2437
2601
 
2438
2602
    itmViewFPCInfo.OnClick:=@mnuViewFPCInfoClicked;
2439
2603
    itmViewIDEInfo.OnClick:=@mnuViewIDEInfoClicked;
 
2604
    itmViewNeedBuild.OnClick:=@mnuViewNeedBuildClicked;
 
2605
  end;
 
2606
end;
 
2607
 
 
2608
procedure TMainIDE.SetupSourceMenu;
 
2609
begin
 
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;
 
2620
    // CodeTool Checks
 
2621
    itmSourceSyntaxCheck.OnClick := @mnuSourceSyntaxCheckClicked;
 
2622
    itmSourceGuessUnclosedBlock.OnClick := @mnuSourceGuessUnclosedBlockClicked;
 
2623
    itmSourceGuessMisplacedIFDEF.OnClick := @mnuSourceGuessMisplacedIFDEFClicked;
 
2624
    // Refactor
 
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;
 
2634
    {$ENDIF}
 
2635
    // itmRefactorTools
 
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;
 
2646
    // insert general
 
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;
 
2656
    // Tools
 
2657
    itmSourceUnitInfo.OnClick := @mnuSourceUnitInfoClicked;
 
2658
    itmSourceUnitDependencies.OnClick := @mnuSourceUnitDependenciesClicked;
2440
2659
  end;
2441
2660
end;
2442
2661
 
2443
2662
procedure TMainIDE.SetupProjectMenu;
2444
2663
begin
2445
2664
  inherited SetupProjectMenu;
 
2665
  mnuProject.OnClick:=@mnuProjectClicked;
2446
2666
  with MainIDEBar do begin
2447
2667
    itmProjectNew.OnClick := @mnuNewProjectClicked;
2448
2668
    itmProjectNewFromFile.OnClick := @mnuNewProjectFromFileClicked;
2456
2676
    itmProjectOptions.OnClick := @mnuProjectOptionsClicked;
2457
2677
    itmProjectAddTo.OnClick := @mnuAddToProjectClicked;
2458
2678
    itmProjectRemoveFrom.OnClick := @mnuRemoveFromProjectClicked;
 
2679
    itmProjectViewUnits.OnClick := @mnuViewUnitsClicked;
 
2680
    itmProjectViewForms.OnClick := @mnuViewFormsClicked;
2459
2681
    itmProjectViewSource.OnClick := @mnuViewProjectSourceClicked;
2460
2682
  end;
2461
2683
end;
2464
2686
begin
2465
2687
  inherited SetupRunMenu;
2466
2688
  with MainIDEBar do begin
 
2689
    itmRunMenuCompile.OnClick := @mnuCompileProjectClicked;
2467
2690
    itmRunMenuBuild.OnClick := @mnuBuildProjectClicked;
2468
 
    itmRunMenuBuildAll.OnClick := @mnuBuildAllProjectClicked;
2469
2691
    itmRunMenuQuickCompile.OnClick := @mnuQuickCompileProjectClicked;
 
2692
    itmRunMenuCleanUpCompiled.OnClick := @mnuCleanUpCompiledProjectClicked;
2470
2693
    itmRunMenuAbortBuild.OnClick := @mnuAbortBuildProjectClicked;
2471
2694
    itmRunMenuRun.OnClick := @mnuRunProjectClicked;
2472
2695
    itmRunMenuPause.OnClick := @mnuPauseProjectClicked;
2483
2706
  end;
2484
2707
end;
2485
2708
 
2486
 
procedure TMainIDE.SetupComponentsMenu;
 
2709
procedure TMainIDE.SetupPackageMenu;
2487
2710
begin
2488
 
  inherited SetupComponentsMenu;
 
2711
  inherited SetupPackageMenu;
 
2712
  mnuPackage.OnClick:=@mnuPackageClicked;
2489
2713
end;
2490
2714
 
2491
2715
procedure TMainIDE.SetupToolsMenu;
2492
2716
begin
2493
2717
  inherited SetupToolsMenu;
2494
2718
  with MainIDEBar do begin
 
2719
    itmEnvGeneralOptions.OnClick := @mnuEnvGeneralOptionsClicked;
 
2720
    itmToolRescanFPCSrcDir.OnClick := @mnuEnvRescanFPCSrcDirClicked;
 
2721
    itmEnvCodeTemplates.OnClick := @mnuEnvCodeTemplatesClicked;
 
2722
    itmEnvCodeToolsDefinesEditor.OnClick := @mnuEnvCodeToolsDefinesEditorClicked;
 
2723
 
2495
2724
    itmToolConfigure.OnClick := @mnuToolConfigureClicked;
2496
 
    itmToolSyntaxCheck.OnClick := @mnuToolSyntaxCheckClicked;
2497
 
    itmToolGuessUnclosedBlock.OnClick := @mnuToolGuessUnclosedBlockClicked;
2498
 
    itmToolGuessMisplacedIFDEF.OnClick := @mnuToolGuessMisplacedIFDEFClicked;
2499
 
    itmToolMakeResourceString.OnClick := @mnuToolMakeResourceStringClicked;
2500
2725
    itmToolDiff.OnClick := @mnuToolDiffClicked;
 
2726
 
2501
2727
    itmToolCheckLFM.OnClick := @mnuToolCheckLFMClicked;
2502
2728
    itmToolConvertDFMtoLFM.OnClick := @mnuToolConvertDFMtoLFMClicked;
2503
2729
    itmToolConvertDelphiUnit.OnClick := @mnuToolConvertDelphiUnitClicked;
2504
2730
    itmToolConvertDelphiProject.OnClick := @mnuToolConvertDelphiProjectClicked;
2505
2731
    itmToolConvertDelphiPackage.OnClick := @mnuToolConvertDelphiPackageClicked;
2506
2732
    itmToolConvertEncoding.OnClick := @mnuToolConvertEncodingClicked;
 
2733
    itmToolManageExamples.OnClick := @mnuToolManageExamplesClicked;
2507
2734
    itmToolBuildLazarus.OnClick := @mnuToolBuildLazarusClicked;
2508
2735
    itmToolConfigureBuildLazarus.OnClick := @mnuToolConfigBuildLazClicked;
2509
2736
    // Set initial caption for Build Lazarus item. Will be changed in BuildLazDialog.
2514
2741
  UpdateCustomToolsInMenu;
2515
2742
end;
2516
2743
 
2517
 
procedure TMainIDE.SetupEnvironmentMenu;
2518
 
begin
2519
 
  inherited SetupEnvironmentMenu;
2520
 
  with MainIDEBar do
2521
 
  begin
2522
 
    itmEnvGeneralOptions.OnClick := @mnuEnvGeneralOptionsClicked;
2523
 
    itmEnvCodeTemplates.OnClick := @mnuEnvCodeTemplatesClicked;
2524
 
    itmEnvCodeToolsDefinesEditor.OnClick := @mnuEnvCodeToolsDefinesEditorClicked;
2525
 
    itmEnvRescanFPCSrcDir.OnClick := @mnuEnvRescanFPCSrcDirClicked;
2526
 
  end;
2527
 
end;
2528
 
 
2529
2744
procedure TMainIDE.SetupWindowsMenu;
2530
2745
begin
2531
2746
  inherited SetupWindowsMenu;
 
2747
  with MainIDEBar do begin
 
2748
    itmWindowManager.OnClick := @mnuWindowManagerClicked;
 
2749
  end;
2532
2750
end;
2533
2751
 
2534
2752
procedure TMainIDE.SetupHelpMenu;
2561
2779
  DoViewAnchorEditor(true);
2562
2780
end;
2563
2781
 
 
2782
procedure TMainIDE.mnuViewTabOrderClicked(Sender: TObject);
 
2783
begin
 
2784
  DoViewTabOrderEditor(true);
 
2785
end;
 
2786
 
2564
2787
procedure TMainIDE.mnuViewComponentPaletteClicked(Sender: TObject);
2565
2788
begin
2566
2789
  DoToggleViewComponentPalette;
2581
2804
  ShowIDEInfo;
2582
2805
end;
2583
2806
 
 
2807
procedure TMainIDE.mnuViewNeedBuildClicked(Sender: TObject);
 
2808
begin
 
2809
  ShowNeedBuildDialog;
 
2810
end;
 
2811
 
2584
2812
procedure TMainIDE.SetDesigning(AComponent: TComponent; Value: Boolean);
2585
2813
begin
2586
2814
  SetComponentDesignMode(AComponent, Value);
2665
2893
  AFilename: string;
2666
2894
  I: Integer;
2667
2895
  OpenFlags: TOpenFlags;
 
2896
  Filter: String;
 
2897
  AllEditorMask: String;
 
2898
  AllMask: String;
 
2899
  ASrcEdit: TSourceEditor;
 
2900
  AnUnitInfo: TUnitInfo;
2668
2901
begin
2669
2902
  OpenDialog:=TOpenDialog.Create(nil);
2670
2903
  try
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;
 
2907
 
 
2908
    // set InitialDir to
 
2909
    GetCurrentUnit(ASrcEdit,AnUnitInfo);
 
2910
    if Assigned(AnUnitInfo) and (not AnUnitInfo.IsVirtual) then
 
2911
      OpenDialog.InitialDir:=ExtractFilePath(AnUnitInfo.Filename);
 
2912
 
 
2913
    Filter := EnvironmentOptions.FileDialogFilter;
 
2914
 
 
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 + ')|' +
 
2919
        AllEditorMask;
 
2920
 
 
2921
    // prepend an all normal files filter
 
2922
    Filter:=lisLazarusFile + ' ('+AllMask+')|' + AllMask + '|' + Filter;
 
2923
 
 
2924
    // append an any files filter
 
2925
    if TFileDialog.FindMaskInFilter(Filter,GetAllFilesMask)<1 then
 
2926
      Filter:=Filter+ '|' + dlgAllFiles + ' (' + GetAllFilesMask + ')|' + GetAllFilesMask;
 
2927
 
 
2928
    OpenDialog.Filter := Filter;
 
2929
 
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
2688
 
        Begin
2689
 
          AFilename:=CleanAndExpandFilename(OpenDialog.Files.Strings[i]);
2690
 
          if i<OpenDialog.Files.Count-1 then
2691
 
            Include(OpenFlags,ofMultiOpen)
2692
 
          else
2693
 
            Exclude(OpenFlags,ofMultiOpen);
2694
 
          if DoOpenEditorFile(AFilename,-1,-1,OpenFlags)=mrAbort then begin
2695
 
            break;
 
2935
      try
 
2936
        SourceEditorManager.IncUpdateLock;
 
2937
        For I := 0 to OpenDialog.Files.Count-1 do
 
2938
          Begin
 
2939
            AFilename:=CleanAndExpandFilename(OpenDialog.Files.Strings[i]);
 
2940
            if i<OpenDialog.Files.Count-1 then
 
2941
              Include(OpenFlags,ofMultiOpen)
 
2942
            else
 
2943
              Exclude(OpenFlags,ofMultiOpen);
 
2944
            if DoOpenEditorFile(AFilename,-1,-1,OpenFlags)=mrAbort then begin
 
2945
              break;
 
2946
            end;
2696
2947
          end;
 
2948
        finally
 
2949
          SourceEditorManager.DecUpdateLock;
2697
2950
        end;
2698
2951
      UpdateEnvironment;
2699
2952
    end;
2730
2983
procedure TMainIDE.mnuRevertClicked(Sender: TObject);
2731
2984
begin
2732
2985
  if (SourceEditorManager.ActiveSourceWindowIndex < 0)
2733
 
     or (SourceEditorManager.ActiveSourceWindow.PageIndex < 0) then exit;
 
2986
  or (SourceEditorManager.ActiveSourceWindow.PageIndex < 0) then exit;
2734
2987
  DoOpenEditorFile('', SourceEditorManager.ActiveSourceWindow.PageIndex,
2735
2988
    SourceEditorManager.ActiveSourceWindowIndex, [ofRevert]);
2736
2989
end;
2772
3025
  DoSaveAll([sfCheckAmbiguousFiles]);
2773
3026
end;
2774
3027
 
 
3028
procedure TMainIDE.mnuExportHtml(Sender: TObject);
 
3029
var
 
3030
  SrcEdit: TSourceEditor;
 
3031
  AnUnitInfo: TUnitInfo;
 
3032
  Filename: string;
 
3033
  SaveDialog: TSaveDialog;
 
3034
begin
 
3035
  GetCurrentUnit(SrcEdit,AnUnitInfo);
 
3036
  if SrcEdit = nil then exit;
 
3037
 
 
3038
  SaveDialog:=TSaveDialog.Create(nil);
 
3039
  try
 
3040
    SaveDialog.Title:=lisSaveSpace;
 
3041
    SaveDialog.FileName:=SrcEdit.PageName+'.html';
 
3042
    SaveDialog.Filter := ' (*.html;*.htm)|*.html;*.htm';
 
3043
    SaveDialog.Options := [ofOverwritePrompt, ofPathMustExist{, ofNoReadOnlyReturn}]; // Does not work for desktop
 
3044
    // show save dialog
 
3045
    if (not SaveDialog.Execute) or (ExtractFileName(SaveDialog.Filename)='')
 
3046
    then begin
 
3047
      exit;
 
3048
    end;
 
3049
    Filename:=ExpandFileNameUTF8(SaveDialog.Filename);
 
3050
  finally
 
3051
    SaveDialog.Free;
 
3052
  end;
 
3053
 
 
3054
  try
 
3055
    SrcEdit.ExportAsHtml(Filename);
 
3056
  except
 
3057
    MessageDlg(lisFailedToSaveFile, mtError, [mbOK], 0);
 
3058
  end;
 
3059
end;
 
3060
 
2775
3061
procedure TMainIDE.mnuCloseClicked(Sender: TObject);
2776
3062
var
2777
3063
  PageIndex: integer;
2825
3111
  end;
2826
3112
  if NeedSave = 1 then begin
2827
3113
    Ed := TSourceEditor(SourceEditorManager.UniqueSourceEditors[Idx]);
2828
 
    r := QuestionDlg(lisSourceModified,
 
3114
    r := IDEQuestionDialog(lisSourceModified,
2829
3115
                     Format(lisSourceOfPageHasChangedSave, ['"', Ed.PageName, '"']),
2830
3116
                     mtConfirmation,
2831
 
                     [mrYes, lisMenuSave, mrNo, lisDiscardChanges, mrAbort], 0);
 
3117
                     [mrYes, lisMenuSave, mrNo, lisDiscardChanges, mrAbort]);
2832
3118
    case r of
2833
3119
      mrYes: DoSaveEditorFile(Ed, [sfCheckAmbiguousFiles]);
2834
3120
      mrNo: ; // don't save
2841
3127
      if CheckEditorNeedsSave(SourceEditorManager.UniqueSourceEditors[i], False) then begin
2842
3128
        dec(NeedSave);
2843
3129
        Ed := TSourceEditor(SourceEditorManager.UniqueSourceEditors[i]);
2844
 
        r := QuestionDlg(lisSourceModified,
 
3130
        r := IDEQuestionDialog(lisSourceModified,
2845
3131
                         Format(lisSourceOfPageHasChangedSaveExtended, ['"', Ed.PageName, '"', NeedSave]),
2846
3132
                         mtConfirmation,
2847
 
                         [mrYes, lisMenuSave, mrAll, lisMenuSaveAll,
 
3133
                         [mrYes, lisMenuSave, mrAll, lisSaveAll,
2848
3134
                          mrNo, lisDiscardChanges, mrIgnore, lisDiscardChangesAll,
2849
 
                          mrAbort], 0);
 
3135
                          mrAbort]);
2850
3136
        case r of
2851
3137
          mrYes: DoSaveEditorFile(Ed, [sfCheckAmbiguousFiles]);
2852
3138
          mrNo: ; // don't save
2877
3163
  ShowCleanDirectoryDialog(Project1.ProjectDirectory,GlobalMacroList);
2878
3164
end;
2879
3165
 
2880
 
Procedure TMainIDE.OnSrcNotebookFileNew(Sender: TObject);
 
3166
procedure TMainIDE.OnSrcNotebookFileNew(Sender: TObject);
2881
3167
begin
2882
3168
  mnuNewFormClicked(Sender);
2883
3169
end;
2884
3170
 
2885
 
Procedure TMainIDE.OnSrcNotebookFileClose(Sender: TObject;
 
3171
procedure TMainIDE.OnSrcNotebookFileClose(Sender: TObject;
2886
3172
  InvertedClose: boolean);
2887
3173
var
2888
3174
  PageIndex: LongInt;
2912
3198
    end;
2913
3199
    if NeedSave = 1 then begin
2914
3200
      Ed := ActiveSrcNoteBook.Editors[Idx];
2915
 
      r := QuestionDlg(lisSourceModified,
 
3201
      r := IDEQuestionDialog(lisSourceModified,
2916
3202
                       Format(lisSourceOfPageHasChangedSave, ['"', Ed.PageName, '"']),
2917
3203
                       mtConfirmation,
2918
 
                       [mrYes, lisMenuSave, mrNo, lisDiscardChanges, mrAbort], 0);
 
3204
                       [mrYes, lisMenuSave, mrNo, lisDiscardChanges, mrAbort]);
2919
3205
      case r of
2920
3206
        mrYes: DoSaveEditorFile(Ed, [sfCheckAmbiguousFiles]);
2921
3207
        mrNo: ; // don't save
2928
3214
        if CheckEditorNeedsSave(ActiveSrcNoteBook.Editors[i], True) then begin
2929
3215
          dec(NeedSave);
2930
3216
          Ed := ActiveSrcNoteBook.Editors[i];
2931
 
          r := QuestionDlg(lisSourceModified,
 
3217
          r := IDEQuestionDialog(lisSourceModified,
2932
3218
                           Format(lisSourceOfPageHasChangedSaveExtended, ['"', Ed.PageName, '"', NeedSave]),
2933
3219
                           mtConfirmation,
2934
 
                           [mrYes, lisMenuSave, mrAll, lisMenuSaveAll,
 
3220
                           [mrYes, lisMenuSave, mrAll, lisSaveAll,
2935
3221
                            mrNo, lisDiscardChanges, mrIgnore, lisDiscardChangesAll,
2936
 
                            mrAbort], 0);
 
3222
                            mrAbort]);
2937
3223
          case r of
2938
3224
            mrYes: DoSaveEditorFile(Ed, [sfCheckAmbiguousFiles]);
2939
3225
            mrNo: ; // don't save
2966
3252
    mnuCloseClicked(Sender);
2967
3253
end;
2968
3254
 
2969
 
Procedure TMainIDE.OnSrcNotebookFileOpen(Sender: TObject);
 
3255
procedure TMainIDE.OnSrcNotebookFileOpen(Sender: TObject);
2970
3256
begin
2971
3257
  mnuOpenClicked(Sender);
2972
3258
end;
2973
3259
 
2974
 
Procedure TMainIDE.OnSrcNoteBookFileOpenAtCursor(Sender: TObject);
 
3260
procedure TMainIDE.OnSrcNotebookFileOpenAtCursor(Sender: TObject);
2975
3261
begin
2976
3262
  mnuOpenFileAtCursorClicked(Sender);
2977
3263
end;
2978
3264
 
2979
 
Procedure TMainIDE.OnSrcNotebookFileSave(Sender: TObject);
 
3265
procedure TMainIDE.OnSrcNotebookFileSave(Sender: TObject);
2980
3266
begin
2981
3267
  mnuSaveClicked(Sender);
2982
3268
end;
2983
3269
 
2984
 
Procedure TMainIDE.OnSrcNotebookFileSaveAs(Sender: TObject);
 
3270
procedure TMainIDE.OnSrcNotebookFileSaveAs(Sender: TObject);
2985
3271
begin
2986
3272
  mnuSaveAsClicked(Sender);
2987
3273
end;
2988
3274
 
2989
 
Procedure TMainIDE.OnSrcNoteBookFindDeclaration(Sender: TObject);
 
3275
procedure TMainIDE.OnSrcNotebookFindDeclaration(Sender: TObject);
2990
3276
begin
2991
3277
  mnuFindDeclarationClicked(Sender);
2992
3278
end;
3004
3290
  Abort:=not DoShowCodeContext(JumpToError);
3005
3291
end;
3006
3292
 
3007
 
Procedure TMainIDE.OnSrcNotebookSaveAll(Sender: TObject);
 
3293
procedure TMainIDE.OnSrcNotebookSaveAll(Sender: TObject);
3008
3294
begin
3009
3295
  mnuSaveAllClicked(Sender);
3010
3296
end;
3059
3345
  ecQuit:
3060
3346
    mnuQuitClicked(Self);
3061
3347
 
3062
 
  ecBuild:
 
3348
  ecCompile:
3063
3349
    begin
3064
3350
      GetCurrentUnit(ASrcEdit,AnUnitInfo);
3065
 
      if (AnUnitInfo<>nil)
3066
 
      and AnUnitInfo.BuildFileIfActive then
 
3351
      if Assigned(AnUnitInfo) and AnUnitInfo.BuildFileIfActive then
3067
3352
        DoBuildFile(false)
3068
3353
      else
3069
 
        DoBuildProject(crCompile,[]);
 
3354
        DoBuildProject(crCompile, []);
3070
3355
    end;
3071
3356
 
3072
 
  ecBuildAll:    DoBuildProject(crBuild,[pbfCleanCompile,
3073
 
                                         pbfCompileDependenciesClean]);
3074
 
  ecQuickCompile:DoQuickCompile;
3075
 
  ecAbortBuild:  DoAbortBuild;
 
3357
  ecBuild: DoBuildProject(crBuild, [pbfCleanCompile]);
 
3358
  ecCleanUpCompiled: mnuCleanUpCompiledProjectClicked(nil);
 
3359
  ecQuickCompile: DoQuickCompile;
 
3360
  ecAbortBuild: DoAbortBuild;
3076
3361
 
3077
3362
  ecRun:
3078
3363
    begin
3091
3376
    DoRunFile;
3092
3377
 
3093
3378
  ecJumpToPrevError:
 
3379
    DoJumpToNextError(false);
 
3380
 
 
3381
  ecJumpToNextError:
3094
3382
    DoJumpToNextError(true);
3095
3383
 
3096
 
  ecJumpToNextError:
3097
 
    DoJumpToNextError(false);
3098
 
 
3099
3384
  ecFindInFiles:
3100
3385
    DoFindInFiles;
3101
3386
 
3102
3387
  ecFindProcedureDefinition,
3103
3388
  ecFindProcedureMethod:
3104
 
    DoJumpToProcedureSection;
 
3389
    DoJumpToOtherProcedureSection;
3105
3390
 
3106
3391
  ecFindDeclaration:
3107
3392
    DoFindDeclarationAtCursor;
3121
3406
  ecRemoveUnusedUnits:
3122
3407
    DoRemoveUnusedUnits;
3123
3408
 
 
3409
  ecUseUnit:
 
3410
    DoUseUnit;
 
3411
 
3124
3412
  ecFindOverloads:
3125
3413
    DoFindOverloads;
3126
3414
 
3158
3446
  ecToggleFPDocEditor:
3159
3447
    DoShowFPDocEditor(true,true);
3160
3448
 
3161
 
  ecViewUnits:
 
3449
  ecViewProjectUnits:
3162
3450
    DoViewUnitsAndForms(false);
3163
3451
 
3164
 
  ecViewForms:
 
3452
  ecViewProjectForms:
3165
3453
    DoViewUnitsAndForms(true);
3166
3454
 
3167
3455
  ecProjectInspector:
3191
3479
  ecConvertDFM2LFM:
3192
3480
    DoConvertDFMtoLFM;
3193
3481
 
 
3482
  ecManageExamples:
 
3483
    mnuToolManageExamplesClicked(Self);
 
3484
 
3194
3485
  ecBuildLazarus:
3195
3486
    mnuToolBuildLazarusClicked(Self);
3196
3487
 
 
3488
  ecBuildAdvancedLazarus:
 
3489
    mnuToolBuildAdvancedLazarusClicked(Self);
 
3490
 
3197
3491
  ecConfigBuildLazarus:
3198
3492
    mnuToolConfigBuildLazClicked(Self);
3199
3493
 
 
3494
  ecWindowManager:
 
3495
    mnuWindowManagerClicked(Self);
 
3496
 
3200
3497
  ecToggleFormUnit:
3201
3498
    mnuToggleFormUnitClicked(Self);
3202
3499
 
3219
3516
    mnuSearchProcedureList(self);
3220
3517
 
3221
3518
  ecInsertGUID:
3222
 
    mnuEditInsertGUID(self);
 
3519
    mnuSourceInsertGUID(self);
 
3520
 
 
3521
  ecInsertFilename:
 
3522
    mnuSourceInsertFilename(self);
3223
3523
 
3224
3524
  else
3225
3525
    Handled:=false;
3245
3545
  OnProcessIDECommand(Sender,Command,Result);
3246
3546
end;
3247
3547
 
3248
 
function TMainIDE.OnSelectDirectory(const Title, InitialDir: string
3249
 
  ): string;
 
3548
function TMainIDE.OnSelectDirectory(const Title, InitialDir: string): string;
3250
3549
var
3251
3550
  Dialog: TSelectDirectoryDialog;
3252
3551
  DummyResult: Boolean;
3283
3582
  DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; const HelpKeyword: string
3284
3583
  ): Integer;
3285
3584
begin
3286
 
  Result:=MessageDlg(aCaption,aMsg,DlgType,Buttons,HelpKeyword);
 
3585
  Result:=MessageDlg{ !!! DO NOT REPLACE WITH IDEMessageDialog }
 
3586
            (aCaption,aMsg,DlgType,Buttons,HelpKeyword);
3287
3587
end;
3288
3588
 
3289
3589
function TMainIDE.OnIDEQuestionDialog(const aCaption, aMsg: string;
3448
3748
 
3449
3749
procedure TMainIDE.mnuChgBuildModeClicked(Sender: TObject);
3450
3750
begin
3451
 
  DoOpenIDEOptions(TBuildModesEditorFrame, '', TAbstractIDEProjectOptions);
 
3751
  DoOpenIDEOptions(TBuildModesEditorFrame, '', [TProjectCompilerOptions], []);
3452
3752
end;
3453
3753
 
3454
3754
procedure TMainIDE.mnuSetBuildModeClick(Sender: TObject);
3463
3763
  if (Index<0) or (Index>=Project1.BuildModes.Count) then exit;
3464
3764
  NewMode:=Project1.BuildModes[Index];
3465
3765
  if NewMode=Project1.ActiveBuildMode then exit;
 
3766
  if not (ToolStatus in [itNone,itDebugger]) then begin
 
3767
    IDEMessageDialog('Error','You can not change the build mode while compiling.',
 
3768
      mtError,[mbOk]);
 
3769
    exit;
 
3770
  end;
3466
3771
 
3467
3772
  Project1.ActiveBuildMode:=NewMode;
3468
 
  MainBuildBoss.SetBuildTarget(Project1.CompilerOptions.TargetOS,
3469
 
    Project1.CompilerOptions.TargetCPU,Project1.CompilerOptions.LCLWidgetType,
3470
 
    bmsfsBackground);
 
3773
  MainBuildBoss.SetBuildTargetProject1(false);
3471
3774
end;
3472
3775
 
3473
3776
function TMainIDE.CreateDesignerForComponent(AnUnitInfo: TUnitInfo;
3506
3809
                 @TComponentPalette(IDEComponentPalette).OnGetNonVisualCompIcon;
3507
3810
    OnGetSelectedComponentClass:=@OnDesignerGetSelectedComponentClass;
3508
3811
    OnModified:=@OnDesignerModified;
3509
 
    OnPasteComponent:=@OnDesignerPasteComponent;
 
3812
    OnPasteComponents:=@OnDesignerPasteComponents;
 
3813
    OnPastedComponents:=@OnDesignerPastedComponents;
3510
3814
    OnProcessCommand:=@OnProcessIDECommand;
3511
3815
    OnPropertiesChanged:=@OnDesignerPropertiesChanged;
3512
3816
    OnRenameComponent:=@OnDesignerRenameComponent;
3516
3820
    OnViewLFM:=@OnDesignerViewLFM;
3517
3821
    OnSaveAsXML:=@OnDesignerSaveAsXML;
3518
3822
    OnShowObjectInspector:=@OnDesignerShowObjectInspector;
 
3823
    OnShowAnchorEditor:=@OnDesignerShowAnchorEditor;
 
3824
    OnShowTabOrderEditor:=@OnDesignerShowTabOrderEditor;
3519
3825
    ShowEditorHints:=EnvironmentOptions.ShowEditorHints;
3520
3826
    ShowComponentCaptions := EnvironmentOptions.ShowComponentCaptions;
3521
3827
  end;
3549
3855
procedure TMainIDE.UpdateIDEComponentPalette;
3550
3856
begin
3551
3857
  IDEComponentPalette.HideControls:=(FLastFormActivated<>nil)
3552
 
    and (not (TDesigner(FLastFormActivated.Designer).LookupRoot is TControl));
 
3858
    and (FLastFormActivated.Designer<>nil)
 
3859
    and (TDesigner(FLastFormActivated.Designer).LookupRoot<>nil)
 
3860
    and not ((FLastFormActivated.Designer as TDesigner).LookupRoot is TControl);
3553
3861
  IDEComponentPalette.UpdateVisible;
 
3862
  TComponentPalette(IDEComponentPalette).OnClassSelected := @ComponentPaletteClassSelected;
3554
3863
  SetupHints;
3555
3864
end;
3556
3865
 
3569
3878
    IDEWindowCreators.ShowForm(AnchorDesigner,true);
3570
3879
end;
3571
3880
 
 
3881
procedure TMainIDE.DoViewTabOrderEditor(Show: boolean);
 
3882
begin
 
3883
  if TabOrderDialog=nil then
 
3884
    TabOrderDialog:=TTabOrderDialog.Create(OwningComponent);
 
3885
  if Show then
 
3886
    IDEWindowCreators.ShowForm(TabOrderDialog,true);
 
3887
end;
 
3888
 
3572
3889
procedure TMainIDE.DoToggleViewComponentPalette;
3573
3890
var
3574
3891
  ComponentPaletteVisible: boolean;
3608
3925
    itDebugger:
3609
3926
      begin
3610
3927
        if (rfInteractive in AFlags)
3611
 
        and (QuestionDlg(lisStopDebugging,
 
3928
        and (IDEQuestionDialog(lisStopDebugging,
3612
3929
            lisStopTheDebugging, mtConfirmation,
3613
 
            [mrYes, lisMenuStop, mrCancel, lisContinue], 0) <> mrYes)
 
3930
            [mrYes, lisStop, mrCancel, lisContinue]) <> mrYes)
3614
3931
        then exit;
3615
3932
        if (DebugBoss.DoStopProject = mrOK) and (ToolStatus = itDebugger) and (rfCloseOnDone in AFlags) then
3616
3933
          FWaitForClose := True;
 
3934
        if rfSuccessOnTrigger in AFlags then
 
3935
          exit(true);
3617
3936
      end;
3618
3937
  end;
3619
3938
  Result := ToolStatus = itNone;
3644
3963
  Editable: Boolean;
3645
3964
  SelAvail: Boolean;
3646
3965
  SelEditable: Boolean;
3647
 
begin
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;
 
3968
begin
 
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;
 
3975
  with MainIDEBar do
 
3976
  begin
 
3977
    if Assigned(ActiveDesigner) then
 
3978
    begin
 
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;
 
3985
    end
 
3986
    else
 
3987
    begin
 
3988
      itmEditUndo.Enabled := Editable and SrcEditorActive;
 
3989
      itmEditRedo.Enabled := itmEditUndo.Enabled;
 
3990
      itmEditCut.Enabled := SelEditable;
 
3991
      itmEditCopy.Enabled := SelAvail;
 
3992
      itmEditPaste.Enabled := Editable;
 
3993
    end;
 
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;
 
4005
  end;
 
4006
end;
 
4007
 
 
4008
{------------------------------------------------------------------------------}
 
4009
 
 
4010
procedure TMainIDE.mnuSourceClicked(Sender: TObject);
 
4011
var
 
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;
 
4018
  CursorXY: TPoint;
 
4019
begin
 
4020
  Editable:=False;
 
4021
  SelAvail:=False;
 
4022
  IdentFound:=False;
 
4023
  StringFound:=False;
 
4024
  if BeginCodeTool(ASrcEdit,AnUnitInfo,[]) then begin
 
4025
    Assert(Assigned(ASrcEdit));
 
4026
    Editable:=not ASrcEdit.ReadOnly;
 
4027
    SelAvail:=ASrcEdit.SelectionAvailable;
 
4028
 
 
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);
 
4033
 
 
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);
 
4041
  end;
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;
3700
 
  end;
 
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;
 
4069
  //itmSourceRefactor
 
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;
 
4076
  end;
 
4077
end;
 
4078
 
 
4079
procedure TMainIDE.mnuProjectClicked(Sender: TObject);
 
4080
var
 
4081
  ASrcEdit: TSourceEditor;
 
4082
  AUnitInfo: TUnitInfo;
 
4083
  NotPartOfProj: Boolean;
 
4084
begin
 
4085
  GetCurrentUnit(ASrcEdit,AUnitInfo);
 
4086
  NotPartOfProj:=Assigned(AUnitInfo) and not AUnitInfo.IsPartOfProject;
 
4087
  MainIDEBar.itmProjectAddTo.Enabled:=NotPartOfProj;
 
4088
end;
 
4089
 
 
4090
procedure TMainIDE.mnuPackageClicked(Sender: TObject);
 
4091
var
 
4092
  ASrcEdit: TSourceEditor;
 
4093
  AUnitInfo: TUnitInfo;
 
4094
  PkgFile: TPkgFile;
 
4095
  CanOpenPkgOfFile, CanAddCurFile: Boolean;
 
4096
begin
 
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;
 
4106
  end;
 
4107
  MainIDEBar.itmPkgOpenPackageOfCurUnit.Enabled:=CanOpenPkgOfFile;
 
4108
  MainIDEBar.itmPkgAddCurFileToPkg.Enabled:=CanAddCurFile;
3701
4109
end;
3702
4110
 
3703
4111
{------------------------------------------------------------------------------}
3718
4126
 
3719
4127
{------------------------------------------------------------------------------}
3720
4128
 
3721
 
Procedure TMainIDE.mnuViewUnitsClicked(Sender: TObject);
 
4129
procedure TMainIDE.mnuViewUnitsClicked(Sender: TObject);
3722
4130
begin
3723
4131
  DoViewUnitsAndForms(false);
3724
4132
end;
3725
4133
 
3726
 
Procedure TMainIDE.mnuViewFormsClicked(Sender: TObject);
 
4134
procedure TMainIDE.mnuViewFormsClicked(Sender: TObject);
3727
4135
Begin
3728
4136
  DoViewUnitsAndForms(true);
3729
4137
end;
3730
4138
 
3731
 
Procedure TMainIDE.mnuViewUnitDependenciesClicked(Sender: TObject);
 
4139
procedure TMainIDE.mnuSourceUnitDependenciesClicked(Sender: TObject);
3732
4140
begin
3733
4141
  DoViewUnitDependencies(true);
3734
4142
end;
3735
4143
 
3736
 
procedure TMainIDE.mnuViewUnitInfoClicked(Sender: TObject);
 
4144
procedure TMainIDE.mnuSourceUnitInfoClicked(Sender: TObject);
3737
4145
begin
3738
4146
  DoViewUnitInfo;
3739
4147
end;
3740
4148
 
3741
 
Procedure TMainIDE.mnuViewCodeExplorerClick(Sender: TObject);
 
4149
procedure TMainIDE.mnuViewCodeExplorerClick(Sender: TObject);
3742
4150
begin
3743
4151
  DoShowCodeExplorer(true);
3744
4152
end;
3745
4153
 
3746
 
Procedure TMainIDE.mnuViewCodeBrowserClick(Sender: TObject);
 
4154
procedure TMainIDE.mnuViewCodeBrowserClick(Sender: TObject);
3747
4155
begin
3748
4156
  DoShowCodeBrowser(true);
3749
4157
end;
3750
4158
 
3751
 
Procedure TMainIDE.mnuViewComponentsClick(Sender: TObject);
 
4159
procedure TMainIDE.mnuViewComponentsClick(Sender: TObject);
3752
4160
begin
3753
4161
  DoShowComponentList(true);
3754
4162
end;
3758
4166
  DoShowRestrictionBrowser(true);
3759
4167
end;
3760
4168
 
3761
 
Procedure TMainIDE.mnuViewMessagesClick(Sender: TObject);
 
4169
procedure TMainIDE.mnuViewMessagesClick(Sender: TObject);
3762
4170
begin
3763
4171
  // it was already visible, but user does not see it, try to move in view
3764
4172
  DoShowMessagesView;
3765
4173
end;
3766
4174
 
3767
 
Procedure TMainIDE.mnuViewSearchResultsClick(Sender: TObject);
 
4175
procedure TMainIDE.mnuViewSearchResultsClick(Sender: TObject);
3768
4176
Begin
3769
 
  ShowSearchResultView(true);
 
4177
  DoShowSearchResultsView(true);
3770
4178
End;
3771
4179
 
3772
 
Procedure TMainIDE.mnuNewProjectClicked(Sender: TObject);
 
4180
procedure TMainIDE.mnuNewProjectClicked(Sender: TObject);
3773
4181
var
3774
4182
  NewProjectDesc: TProjectDescriptor;
3775
4183
Begin
3784
4192
  OpenDialog:TOpenDialog;
3785
4193
  AFilename: string;
3786
4194
  PreReadBuf: TCodeBuffer;
 
4195
  Filter: String;
3787
4196
Begin
3788
4197
  OpenDialog:=TOpenDialog.Create(nil);
3789
4198
  try
3790
4199
    InputHistories.ApplyFileDialogSettings(OpenDialog);
3791
4200
    OpenDialog.Title:=lisChooseProgramSourcePpPasLpr;
3792
4201
    OpenDialog.Options:=OpenDialog.Options+[ofPathMustExist,ofFileMustExist];
 
4202
    Filter := lisLazarusUnit + ' (*.pas;*.pp;*.p)|*.pas;*.pp;*.p'
 
4203
      + '|' + lisLazarusProjectSource + ' (*.lpr)|*.lpr';
 
4204
    Filter:=Filter+ '|' + dlgAllFiles + ' (' + GetAllFilesMask + ')|' + GetAllFilesMask;
 
4205
    OpenDialog.Filter := Filter;
3793
4206
    if OpenDialog.Execute then begin
3794
4207
      AFilename:=ExpandFileNameUTF8(OpenDialog.Filename);
3795
4208
      if not FilenameIsPascalSource(AFilename) then begin
3812
4225
  end;
3813
4226
end;
3814
4227
 
3815
 
Procedure TMainIDE.mnuOpenProjectClicked(Sender: TObject);
 
4228
procedure TMainIDE.mnuOpenProjectClicked(Sender: TObject);
3816
4229
var
3817
4230
  OpenDialog:TOpenDialog;
3818
4231
  AFileName: string;
3861
4274
            // or it is not yet a lazarus project ;)
3862
4275
            LPIFilename:=ChangeFileExt(AFilename,'.lpi');
3863
4276
            if FileExistsUTF8(LPIFilename) then begin
3864
 
              if QuestionDlg(lisProjectInfoFileDetected,
 
4277
              if IDEQuestionDialog(lisProjectInfoFileDetected,
3865
4278
                  Format(lisTheFileSeemsToBeTheProgramFileOfAnExistingLazarusP, [
3866
4279
                  AFilename]), mtConfirmation,
3867
 
                  [mrOk, lisOpenProject2, mrCancel], 0)
 
4280
                  [mrOk, lisOpenProject2, mrCancel])
3868
4281
                <>mrOk
3869
4282
              then
3870
4283
                exit;
3871
4284
              AFilename:=LPIFilename;
3872
4285
            end else begin
3873
 
              if QuestionDlg(lisFileHasNoProject,
 
4286
              if IDEQuestionDialog(lisFileHasNoProject,
3874
4287
                Format(lisTheFileIsNotALazarusProjectCreateANewProjectForThi, [
3875
4288
                  '"', AFilename, '"', #13, '"'+lowercase(SourceType)+'"']),
3876
 
                mtConfirmation, [mrYes, lisCreateProject, mrCancel], 0)<>mrYes
 
4289
                mtConfirmation, [mrYes, lisCreateProject, mrCancel])<>mrYes
3877
4290
              then
3878
4291
                exit;
3879
4292
              DoCreateProjectForProgram(PreReadBuf);
3896
4309
  ARecentProject: String;
3897
4310
begin
3898
4311
  // stop debugging/compiling/...
3899
 
  if not DoResetToolStatus([rfInteractive]) then exit;
 
4312
  if not DoResetToolStatus([rfInteractive, rfSuccessOnTrigger]) then exit;
3900
4313
 
3901
4314
  // check foreign windows
3902
4315
  if not CloseQueryIDEWindows then exit;
3903
4316
 
3904
4317
  // check project
3905
4318
  if SomethingOfProjectIsModified then begin
3906
 
    DlgResult:=QuestionDlg(lisProjectChanged,
3907
 
      Format(lisSaveChangesToProject, [Project1.Title]), mtConfirmation,
 
4319
    DlgResult:=IDEQuestionDialog(lisProjectChanged,
 
4320
      Format(lisSaveChangesToProject, [Project1.GetTitleOrName]), mtConfirmation,
3908
4321
      [mrYes, lisMenuSave, mrNoToAll, lisDiscardChanges,
3909
 
       mrAbort, lisDoNotCloseTheProject],
3910
 
      0);
 
4322
       mrAbort, lisDoNotCloseTheProject]);
3911
4323
    case DlgResult of
3912
4324
    mrYes:
3913
4325
      if not (DoSaveProject([]) in [mrOk,mrIgnore]) then exit;
3939
4351
              AddRecentProjectFileToEnvironment(ARecentProject);
3940
4352
          end;
3941
4353
        end;
 
4354
    tpws_examples:
 
4355
      mnuToolManageExamplesClicked(Sender);
3942
4356
    tpws_convert:
3943
4357
      mnuToolConvertDelphiProjectClicked(Sender);
3944
4358
    tpws_closeIDE:
3947
4361
  end;
3948
4362
end;
3949
4363
 
3950
 
Procedure TMainIDE.mnuSaveProjectClicked(Sender: TObject);
 
4364
procedure TMainIDE.mnuSaveProjectClicked(Sender: TObject);
3951
4365
Begin
3952
4366
  DoSaveProject([]);
3953
4367
end;
3983
4397
end;
3984
4398
 
3985
4399
procedure TMainIDE.mnuProjectOptionsClicked(Sender: TObject);
3986
 
var
3987
 
  NewCaption: String;
3988
4400
begin
3989
 
  NewCaption := Project1.Title;
3990
 
  if NewCaption = '' then
3991
 
    NewCaption := ExtractFilenameOnly(Project1.ProjectInfoFile);
3992
 
  DoOpenIDEOptions(nil, Format(dlgProjectOptionsFor, [NewCaption]), TAbstractIDEProjectOptions);
 
4401
  DoOpenIDEOptions(nil, Format(dlgProjectOptionsFor, [Project1.GetTitleOrName]),
 
4402
    [TAbstractIDEProjectOptions, TProjectCompilerOptions], []);
3993
4403
end;
3994
4404
 
3995
4405
function TMainIDE.UpdateProjectPOFile(AProject: TProject): TModalResult;
3996
4406
var
3997
 
  Files: TStringList;
 
4407
  Files: TFilenameToPointerTree;
3998
4408
  POFilename: String;
3999
4409
  AnUnitInfo: TUnitInfo;
4000
4410
  CurFilename: String;
4004
4414
  LRTFilename: String;
4005
4415
  UnitOutputDir: String;
4006
4416
  RSTFilename: String;
 
4417
  FileList: TStringList;
4007
4418
begin
4008
4419
  Result:=mrCancel;
4009
4420
  if (not AProject.EnableI18N) or AProject.IsVirtual then exit(mrOk);
4017
4428
 
4018
4429
  if AProject.POOutputDirectory <> '' then begin
4019
4430
    POOutDir:=AProject.GetPOOutDirectory;
4020
 
    if POOutDir<>'' then
4021
 
      POFilename:=TrimFilename(AppendPathDelim(POOutDir)+ExtractFileName(POFilename));
 
4431
    if POOutDir<>'' then begin
 
4432
      if not DirPathExistsCached(POOutDir) then begin
 
4433
        Result:=ForceDirectoryInteractive(POOutDir,[]);
 
4434
        if Result in [mrCancel,mrAbort] then exit;
 
4435
        if Result<>mrOk then
 
4436
          POOutDir:=''; // e.g. ignore if failed to create dir
 
4437
      end;
 
4438
      if POOutDir<>'' then
 
4439
        POFilename:=AppendPathDelim(POOutDir)+ExtractFileName(POFilename);
 
4440
    end;
4022
4441
  end;
4023
4442
 
4024
4443
  POFileAgeValid:=false;
4029
4448
 
4030
4449
  //DebugLn(['TMainIDE.UpdateProjectPOFile Updating POFilename="',POFilename,'"']);
4031
4450
 
4032
 
  Files := TStringList.Create;
 
4451
  Files := TFilenameToPointerTree.Create(false);
 
4452
  FileList:=TStringList.Create;
4033
4453
  try
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
 
4461
        continue;
 
4462
      // check .lrt file
 
4463
      LRTFilename:=ChangeFileExt(CurFilename,'.lrt');
 
4464
      if FileExistsCached(LRTFilename)
 
4465
      and ((not POFileAgeValid) or (FileAgeCached(LRTFilename)>POFileAge)) then
 
4466
        Files[LRTFilename]:=nil;
 
4467
      // check .rst file
 
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
4038
4471
      begin
4039
 
        // check .lrt file
4040
 
        LRTFilename:=ChangeFileExt(CurFilename,'.lrt');
4041
 
        if FileExistsCached(LRTFilename)
4042
 
        and ((not POFileAgeValid) or (FileAgeCached(LRTFilename)>POFileAge)) then
4043
 
          Files.Add(LRTFilename);
4044
 
        // check .rst file
4045
 
        RSTFilename:=ExtractFileName(ChangeFileExt(CurFilename,'.rst'));
4046
 
 
4047
 
        // the compiler puts the .rst in the unit output directory
4048
4472
        UnitOutputDir:=AProject.GetOutputDirectory;
4049
 
        if UnitOutputDir='' then
4050
 
          UnitOutputDir:=AProject.ProjectDirectory;
4051
 
 
4052
 
        RSTFilename:=TrimFilename(AppendPathDelim(UnitOutputDir)+RSTFilename);
4053
 
 
4054
 
        //DebugLn(['TMainIDE.UpdateProjectPOFile Looking for .rst file ="',RSTFilename,'"']);
4055
 
 
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));
4059
4475
      end;
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;
4061
4480
    end;
4062
4481
 
 
4482
    // update po files
 
4483
    if Files.Tree.Count=0 then exit(mrOk);
 
4484
    Files.GetNames(FileList);
4063
4485
    try
4064
 
      UpdatePoFile(Files, POFilename);
 
4486
      UpdatePoFileAndTranslations(FileList, POFilename);
4065
4487
      Result := mrOk;
4066
4488
    except
4067
4489
      on E:EPOFileError do begin
4070
4492
          E.Message]), mtError, [mbOk]);
4071
4493
      end;
4072
4494
    end;
4073
 
 
4074
4495
  finally
4075
 
    Files.Destroy;
 
4496
    FileList.Free;
 
4497
    Files.Free;
4076
4498
  end;
4077
4499
end;
4078
4500
 
4079
 
Procedure TMainIDE.mnuBuildProjectClicked(Sender: TObject);
 
4501
procedure TMainIDE.mnuCompileProjectClicked(Sender: TObject);
4080
4502
var
4081
4503
  ASrcEdit: TSourceEditor;
4082
4504
  AnUnitInfo: TUnitInfo;
4089
4511
    DoBuildProject(crCompile,[]);
4090
4512
end;
4091
4513
 
4092
 
Procedure TMainIDE.mnuBuildAllProjectClicked(Sender: TObject);
 
4514
procedure TMainIDE.mnuBuildProjectClicked(Sender: TObject);
4093
4515
Begin
4094
 
  DoBuildProject(crBuild,[pbfCleanCompile,pbfCompileDependenciesClean]);
 
4516
  DoBuildProject(crBuild,[pbfCleanCompile]);
4095
4517
end;
4096
4518
 
4097
4519
procedure TMainIDE.mnuQuickCompileProjectClicked(Sender: TObject);
4099
4521
  DoQuickCompile;
4100
4522
end;
4101
4523
 
4102
 
Procedure TMainIDE.mnuAbortBuildProjectClicked(Sender: TObject);
 
4524
procedure TMainIDE.mnuCleanUpCompiledProjectClicked(Sender: TObject);
 
4525
begin
 
4526
  if Project1.MainUnitInfo=nil then begin
 
4527
    // this project has no source to compile
 
4528
    IDEMessageDialog(lisCanNotCompileProject,
 
4529
      lisTheProjectHasNoMainSourceFile, mtError, [mbCancel], '');
 
4530
    exit;
 
4531
  end;
 
4532
 
 
4533
  if PrepareForCompile<>mrOk then exit;
 
4534
 
 
4535
  if ShowBuildProjectDialog(Project1)<>mrOk then exit;
 
4536
 
 
4537
  DoBuildProject(crBuild,[]);
 
4538
end;
 
4539
 
 
4540
procedure TMainIDE.mnuAbortBuildProjectClicked(Sender: TObject);
4103
4541
Begin
4104
4542
  DoAbortBuild;
4105
4543
end;
4106
4544
 
4107
 
Procedure TMainIDE.mnuRunProjectClicked(Sender: TObject);
 
4545
procedure TMainIDE.mnuRunProjectClicked(Sender: TObject);
4108
4546
var
4109
4547
  SrcEdit: TSourceEditor;
4110
4548
  AnUnitInfo: TUnitInfo;
4116
4554
    DoRunProject;
4117
4555
end;
4118
4556
 
4119
 
Procedure TMainIDE.mnuPauseProjectClicked(Sender: TObject);
 
4557
procedure TMainIDE.mnuPauseProjectClicked(Sender: TObject);
4120
4558
begin
4121
4559
  DebugBoss.DoPauseProject;
4122
4560
end;
4123
4561
 
4124
 
Procedure TMainIDE.mnuShowExecutionPointClicked(Sender: TObject);
 
4562
procedure TMainIDE.mnuShowExecutionPointClicked(Sender: TObject);
4125
4563
begin
4126
4564
  DebugBoss.DoShowExecutionPoint;
4127
4565
end;
4128
4566
 
4129
 
Procedure TMainIDE.mnuStepIntoProjectClicked(Sender: TObject);
 
4567
procedure TMainIDE.mnuStepIntoProjectClicked(Sender: TObject);
4130
4568
begin
4131
4569
  DebugBoss.DoStepIntoProject;
4132
4570
end;
4133
4571
 
4134
 
Procedure TMainIDE.mnuStepOverProjectClicked(Sender: TObject);
 
4572
procedure TMainIDE.mnuStepOverProjectClicked(Sender: TObject);
4135
4573
begin
4136
4574
  DebugBoss.DoStepOverProject;
4137
4575
end;
4151
4589
  DebugBoss.DoStepOutProject;
4152
4590
end;
4153
4591
 
4154
 
Procedure TMainIDE.mnuRunToCursorProjectClicked(Sender: TObject);
 
4592
procedure TMainIDE.mnuRunToCursorProjectClicked(Sender: TObject);
4155
4593
begin
4156
4594
  DebugBoss.DoRunToCursor;
4157
4595
end;
4158
4596
 
4159
 
Procedure TMainIDE.mnuStopProjectClicked(Sender: TObject);
 
4597
procedure TMainIDE.mnuStopProjectClicked(Sender: TObject);
4160
4598
begin
4161
4599
  DebugBoss.DoStopProject;
4162
4600
end;
4186
4624
 
4187
4625
procedure TMainIDE.mnuToolConfigureClicked(Sender: TObject);
4188
4626
begin
4189
 
  if ShowExtToolDialog(EnvironmentOptions.ExternalTools,GlobalMacroList)=mrOk then
 
4627
  if ShowExtToolDialog(ExternalTools,GlobalMacroList)=mrOk then
4190
4628
  begin
4191
4629
    // save to environment options
4192
 
    SaveDesktopSettings(EnvironmentOptions);
4193
 
    EnvironmentOptions.Save(false);
 
4630
    SaveEnvironment(true);
4194
4631
    // save shortcuts to editor options
4195
 
    EnvironmentOptions.ExternalTools.SaveShortCuts(EditorOpts.KeyMap);
 
4632
    ExternalTools.SaveShortCuts(EditorOpts.KeyMap);
4196
4633
    EditorOpts.Save;
4197
4634
    UpdateHighlighters(True);
4198
4635
    SourceEditorManager.ReloadEditorOptions;
4200
4637
  end;
4201
4638
end;
4202
4639
 
4203
 
procedure TMainIDE.mnuToolSyntaxCheckClicked(Sender: TObject);
 
4640
procedure TMainIDE.mnuSourceSyntaxCheckClicked(Sender: TObject);
4204
4641
begin
4205
4642
  DoCheckSyntax;
4206
4643
end;
4207
4644
 
4208
 
procedure TMainIDE.mnuToolGuessUnclosedBlockClicked(Sender: TObject);
 
4645
procedure TMainIDE.mnuSourceGuessUnclosedBlockClicked(Sender: TObject);
4209
4646
begin
4210
4647
  DoJumpToGuessedUnclosedBlock(true);
4211
4648
end;
4212
4649
 
4213
 
procedure TMainIDE.mnuToolGuessMisplacedIFDEFClicked(Sender: TObject);
 
4650
procedure TMainIDE.mnuSourceGuessMisplacedIFDEFClicked(Sender: TObject);
4214
4651
begin
4215
4652
  DoJumpToGuessedMisplacedIFDEF(true);
4216
4653
end;
4217
4654
 
4218
 
procedure TMainIDE.mnuToolMakeResourceStringClicked(Sender: TObject);
 
4655
procedure TMainIDE.mnuRefactorMakeResourceStringClicked(Sender: TObject);
4219
4656
begin
4220
4657
  DoMakeResourceString;
4221
4658
end;
4362
4799
  ShowConvertEncodingDlg;
4363
4800
end;
4364
4801
 
 
4802
procedure TMainIDE.mnuToolManageExamplesClicked(Sender: TObject);
 
4803
begin
 
4804
  DoManageExamples();
 
4805
end;
 
4806
 
4365
4807
procedure TMainIDE.mnuToolBuildLazarusClicked(Sender: TObject);
4366
4808
begin
4367
4809
  with MiscellaneousOptions do
4368
4810
    if BuildLazProfiles.ConfirmBuild then
4369
 
      if MessageDlg(Format(lisConfirmLazarusRebuild, [BuildLazProfiles.Current.Name]),
4370
 
                    mtConfirmation, mbYesNo, 0)<>mrYes then
 
4811
      if IDEMessageDialog(lisConfirmation, Format(lisConfirmLazarusRebuild, [
 
4812
        BuildLazProfiles.Current.Name]),
 
4813
                    mtConfirmation, mbYesNo)<>mrYes then
4371
4814
        exit;
4372
4815
  DoBuildLazarus([]);
4373
4816
end;
4391
4834
      exit;
4392
4835
    end;
4393
4836
    if BuildLazProfiles.ConfirmBuild then
4394
 
      if MessageDlg(Format(lisConfirmBuildAllProfiles, [s+sLineBreak]),
4395
 
                    mtConfirmation, mbYesNo, 0)<>mrYes then
 
4837
      if IDEMessageDialog(lisConfirmation, Format(lisConfirmBuildAllProfiles, [s
 
4838
        +sLineBreak]), mtConfirmation, mbYesNo)<>mrYes then
4396
4839
        exit;
4397
4840
    DoBuildAdvancedLazarus(BuildLazProfiles.Selected);
4398
4841
  end;
4405
4848
  LazSrcDirTemplate: TDefineTemplate;
4406
4849
  DlgResult: TModalResult;
4407
4850
begin
4408
 
  DlgResult:=ShowConfigureBuildLazarusDlg(MiscellaneousOptions.BuildLazProfiles);
 
4851
  MainBuildBoss.SetBuildTargetIDE;
 
4852
  try
 
4853
    DlgResult:=ShowConfigureBuildLazarusDlg(MiscellaneousOptions.BuildLazProfiles);
 
4854
  finally
 
4855
    MainBuildBoss.SetBuildTargetProject1(true);
 
4856
  end;
 
4857
 
4409
4858
  if DlgResult in [mrOk,mrYes,mrAll] then begin
4410
4859
    MiscellaneousOptions.Save;
 
4860
    IncreaseCompilerParseStamp;
4411
4861
    if DlgResult=mrAll then
4412
4862
      DoBuildAdvancedLazarus(MiscellaneousOptions.BuildLazProfiles.Selected)
4413
4863
    else if DlgResult=mrYes then begin
4440
4890
begin
4441
4891
  if not (Sender is TIDEMenuItem) then exit;
4442
4892
  Index:=itmCustomTools.IndexOf(TIDEMenuItem(Sender))-1;
4443
 
  if (Index<0) or (Index>=EnvironmentOptions.ExternalTools.Count) then exit;
 
4893
  if (Index<0) or (Index>=ExternalTools.Count) then exit;
4444
4894
  DoRunExternalTool(Index,false);
4445
4895
end;
4446
4896
 
4451
4901
 
4452
4902
//------------------------------------------------------------------------------
4453
4903
 
4454
 
procedure TMainIDE.SaveDesktopSettings(
4455
 
  TheEnvironmentOptions: TEnvironmentOptions);
 
4904
procedure TMainIDE.SaveDesktopSettings(TheEnvironmentOptions: TEnvironmentOptions);
 
4905
// Called also before reading EnvironmentOptions
4456
4906
begin
4457
4907
  IDEWindowCreators.SimpleLayoutStorage.StoreWindowPositions;
4458
4908
  // do not auto show the search results view
4459
4909
  IDEWindowCreators.SimpleLayoutStorage.ItemByFormID(
4460
4910
    NonModalIDEWindowNames[nmiwSearchResultsViewName]).Visible:=false;
4461
4911
 
4462
 
  with TheEnvironmentOptions do begin
4463
 
    ObjectInspectorOptions.Assign(ObjectInspector1);
4464
 
  end;
 
4912
  if ObjectInspector1<>nil then
 
4913
    TheEnvironmentOptions.ObjectInspectorOptions.Assign(ObjectInspector1);
4465
4914
end;
4466
4915
 
4467
 
procedure TMainIDE.LoadDesktopSettings(
4468
 
  TheEnvironmentOptions: TEnvironmentOptions);
 
4916
procedure TMainIDE.LoadDesktopSettings(TheEnvironmentOptions: TEnvironmentOptions);
4469
4917
begin
4470
 
  with TheEnvironmentOptions do begin
4471
 
    ObjectInspectorOptions.AssignTo(ObjectInspector1);
4472
 
  end;
 
4918
  if ObjectInspector1<>nil then
 
4919
    TheEnvironmentOptions.ObjectInspectorOptions.AssignTo(ObjectInspector1);
4473
4920
end;
4474
4921
 
4475
4922
procedure TMainIDE.UpdateDefaultPascalFileExtensions;
4507
4954
    SaveDesktopSettings(AOptions as TEnvironmentOptions);
4508
4955
end;
4509
4956
 
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);
4512
4960
var
4513
4961
  IDEOptionsDialog: TIDEOptionsDialog;
 
4962
  OptionsFilter: TIDEOptionsEditorFilter;
 
4963
  i: Integer;
4514
4964
begin
4515
4965
  IDEOptionsDialog := TIDEOptionsDialog.Create(nil);
4516
 
 
4517
4966
  try
4518
4967
    if ACaption <> '' then
4519
4968
      IDEOptionsDialog.Caption := ACaption;
4520
 
    if AOptionsFilter = nil then
 
4969
    if Length(AOptionsFilter) = 0 then
 
4970
    begin
 
4971
      SetLength(OptionsFilter, 1);
4521
4972
      if AEditor <> nil then
4522
 
        AOptionsFilter := AEditor.SupportedOptionsClass
 
4973
        OptionsFilter[0] := AEditor.SupportedOptionsClass
4523
4974
      else
4524
 
        AOptionsFilter := TAbstractIDEEnvironmentOptions;
4525
 
    IDEOptionsDialog.OptionsFilter := AOptionsFilter;
4526
 
    //DebugLn(['TMainIDE.DoOpenIDEOptions ',DbgSName(IDEOptionsDialog.OptionsFilter)]);
 
4975
        OptionsFilter[0] := TAbstractIDEEnvironmentOptions;
 
4976
    end
 
4977
    else
 
4978
    begin
 
4979
      SetLength(OptionsFilter, Length(AOptionsFilter));
 
4980
      for i := 0 to Length(AOptionsFilter) - 1 do
 
4981
        OptionsFilter[i] := AOptionsFilter[i];
 
4982
    end;
 
4983
    IDEOptionsDialog.OptionsFilter := OptionsFilter;
 
4984
    IDEOptionsDialog.Settings := ASettings;
4527
4985
    IDEOptionsDialog.OpenEditor(AEditor);
4528
 
 
4529
 
    with IDEOptionsDialog do
4530
 
    begin
4531
 
      OnLoadIDEOptions:=@Self.OnLoadIDEOptions;
4532
 
      OnSaveIDEOptions:=@Self.OnSaveIDEOptions;
4533
 
      ReadAll;
4534
 
    end;
 
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);
4541
4995
      else
4542
4996
        Application.TaskBarBehavior := tbDefault;
4543
4997
    end else begin
4544
 
      // restore
4545
 
      IDEOptionsDialog.WriteAll(true);
 
4998
      IDEOptionsDialog.WriteAll(true);           // restore
4546
4999
    end;
4547
5000
  finally
4548
5001
    IDEOptionsDialog.Free;
4555
5008
  SaveDesktopSettings(EnvironmentOptions);
4556
5009
end;
4557
5010
 
4558
 
procedure TMainIDE.DoEnvironmentOptionsBeforeWrite(Sender: TObject;
4559
 
  Restore: boolean);
 
5011
procedure TMainIDE.DoEnvironmentOptionsBeforeWrite(Sender: TObject; Restore: boolean);
4560
5012
begin
4561
5013
  if Restore then exit;
4562
5014
  OldCompilerFilename:=EnvironmentOptions.CompilerFilename;
4563
5015
  OldLanguage:=EnvironmentOptions.LanguageID;
4564
5016
end;
4565
5017
 
4566
 
procedure TMainIDE.DoEnvironmentOptionsAfterWrite(Sender: TObject;
4567
 
  Restore: boolean);
 
5018
procedure TMainIDE.DoEnvironmentOptionsAfterWrite(Sender: TObject; Restore: boolean);
4568
5019
var
4569
5020
  MacroValueChanged,
4570
5021
  FPCSrcDirChanged, FPCCompilerChanged,
4612
5063
 
4613
5064
  procedure UpdateObjectInspector;
4614
5065
  begin
4615
 
    EnvironmentOptions.ObjectInspectorOptions.AssignTo(ObjectInspector1);
 
5066
    if ObjectInspector1<>nil then
 
5067
      EnvironmentOptions.ObjectInspectorOptions.AssignTo(ObjectInspector1);
4616
5068
  end;
4617
5069
 
4618
5070
begin
4623
5075
  UpdateDefaultPascalFileExtensions;
4624
5076
  if OldLanguage <> EnvironmentOptions.LanguageID then
4625
5077
  begin
4626
 
    TranslateResourceStrings(EnvironmentOptions.LazarusDirectory,
 
5078
    TranslateResourceStrings(EnvironmentOptions.GetParsedLazarusDirectory,
4627
5079
                             EnvironmentOptions.LanguageID);
4628
5080
    PkgBoss.TranslateResourceStrings;
4629
5081
  end;
4633
5085
  FPCSrcDirChanged:=false;
4634
5086
  FPCCompilerChanged:=OldCompilerFilename<>EnvironmentOptions.CompilerFilename;
4635
5087
  LazarusSrcDirChanged:=false;
4636
 
  ChangeMacroValue('LazarusDir',EnvironmentOptions.LazarusDirectory);
4637
 
  ChangeMacroValue('FPCSrcDir',EnvironmentOptions.FPCSourceDirectory);
 
5088
  ChangeMacroValue('LazarusDir',EnvironmentOptions.GetParsedLazarusDirectory);
 
5089
  ChangeMacroValue('FPCSrcDir',EnvironmentOptions.GetParsedFPCSourceDirectory);
4638
5090
 
4639
5091
  if MacroValueChanged then CodeToolBoss.DefineTree.ClearCache;
4640
5092
  //debugln(['TMainIDE.DoEnvironmentOptionsAfterWrite FPCCompilerChanged=',FPCCompilerChanged,' FPCSrcDirChanged=',FPCSrcDirChanged,' LazarusSrcDirChanged=',LazarusSrcDirChanged]);
4641
5093
  if FPCCompilerChanged or FPCSrcDirChanged then
4642
 
    MainBuildBoss.RescanCompilerDefines(true,false,false);
 
5094
    MainBuildBoss.SetBuildTargetProject1(false);
4643
5095
 
4644
5096
  // update environment
4645
5097
  UpdateDesigners;
4675
5127
  CodeToolsOpts.AssignTo(CodeToolBoss);
4676
5128
end;
4677
5129
 
4678
 
procedure TMainIDE.DoCodeExplorerOptionsAfterWrite(Sender: TObject;
4679
 
  Restore: boolean);
 
5130
procedure TMainIDE.DoCodeExplorerOptionsAfterWrite(Sender: TObject; Restore: boolean);
4680
5131
begin
4681
5132
  if Restore then exit;
4682
5133
  if CodeExplorerView<>nil then
4695
5146
  AProject.BackupSession;
4696
5147
  AProject.BackupBuildModes;
4697
5148
  AProject.UpdateExecutableType;
4698
 
  AProject.CompilerOptions.UseAsDefault := False;
 
5149
  AProject.UseAsDefault := False;
4699
5150
end;
4700
5151
 
4701
 
procedure TMainIDE.DoProjectOptionsAfterWrite(Sender: TObject; Restore: boolean
4702
 
  );
 
5152
procedure TMainIDE.DoProjectOptionsAfterWrite(Sender: TObject; Restore: boolean);
4703
5153
var
4704
5154
  AProject: TProject absolute Sender;
4705
5155
  aFilename: String;
4715
5165
  function SetTitle: Boolean;
4716
5166
  var
4717
5167
    OldTitle: String;
 
5168
    NewTitle: String;
4718
5169
  begin
4719
5170
    Result := True;
4720
5171
    if (AProject.MainUnitID < 0) or
4724
5175
    if (OldTitle = '') and AProject.TitleIsDefault then
4725
5176
      Exit;
4726
5177
 
4727
 
    if (OldTitle <> AProject.Title) and (not AProject.TitleIsDefault) then
4728
 
      if not CodeToolBoss.SetApplicationTitleStatement(AProject.MainUnitInfo.Source, AProject.Title) then
 
5178
    NewTitle:=AProject.GetTitle;
 
5179
    if (OldTitle <> NewTitle) and (not AProject.TitleIsDefault) then
 
5180
      if not CodeToolBoss.SetApplicationTitleStatement(AProject.MainUnitInfo.Source, NewTitle) then
4729
5181
      begin
4730
 
        MessageDlg(lisProjOptsError,
4731
 
          'Unable to change project title in source.'#13 +
4732
 
          CodeToolBoss.ErrorMessage,
4733
 
          mtWarning, [mbOk], 0);
 
5182
        IDEMessageDialog(lisProjOptsError,
 
5183
          Format(lisUnableToChangeProjectTitleInSource, [#13, CodeToolBoss.
 
5184
            ErrorMessage]),
 
5185
          mtWarning, [mbOk]);
4734
5186
        Result := False;
4735
5187
        Exit;
4736
5188
      end;// set Application.Title:= statement
4738
5190
    if (OldTitle <> '') and AProject.TitleIsDefault then
4739
5191
      if not CodeToolBoss.RemoveApplicationTitleStatement(AProject.MainUnitInfo.Source) then
4740
5192
      begin
4741
 
        MessageDlg(lisProjOptsError,
4742
 
          'Unable to remove project title from source.'#13 +
4743
 
          CodeToolBoss.ErrorMessage,
4744
 
          mtWarning, [mbOk], 0);
 
5193
        IDEMessageDialog(lisProjOptsError,
 
5194
          Format(lisUnableToRemoveProjectTitleFromSource, [#13, CodeToolBoss.
 
5195
            ErrorMessage]),
 
5196
          mtWarning, [mbOk]);
4745
5197
        Result := False;
4746
5198
        Exit;
4747
5199
      end;// delete title
4774
5226
      if not CodeToolBoss.SetAllCreateFromStatements(AProject.MainUnitInfo.Source,
4775
5227
        AProject.TmpAutoCreatedForms) then
4776
5228
      begin
4777
 
        MessageDlg(lisProjOptsError,
 
5229
        IDEMessageDialog(lisProjOptsError,
4778
5230
          Format(lisProjOptsUnableToChangeTheAutoCreateFormList, [LineEnding]),
4779
 
          mtWarning, [mbOK], 0);
 
5231
          mtWarning, [mbOK]);
4780
5232
        Result := False;
4781
5233
        Exit;
4782
5234
      end;
4793
5245
    SetAutoCreateForms;
4794
5246
    // extend include path
4795
5247
    AProject.AutoAddOutputDirToIncPath;
4796
 
    if AProject.Resources.Modified and (AProject.MainUnitID >= 0) then
 
5248
    if AProject.ProjResources.Modified and (AProject.MainUnitID >= 0) then
4797
5249
    begin
4798
 
      if not AProject.Resources.Regenerate(AProject.MainFilename, True, False, '') then
4799
 
        MessageDlg(AProject.Resources.Messages.Text, mtWarning, [mbOk], 0);
 
5250
      if not AProject.ProjResources.Regenerate(AProject.MainFilename, True, False, '') then
 
5251
        IDEMessageDialog(lisCCOWarningCaption, AProject.ProjResources.Messages.
 
5252
          Text, mtWarning, [mbOk]);
4800
5253
    end;
4801
5254
    UpdateCaption;
4802
5255
    AProject.DefineTemplates.AllChanged;
4804
5257
  if Restore then
4805
5258
    AProject.RestoreBuildModes;
4806
5259
  IncreaseCompilerParseStamp;
4807
 
  MainBuildBoss.SetBuildTarget(Project1.CompilerOptions.TargetOS,
4808
 
    Project1.CompilerOptions.TargetCPU,Project1.CompilerOptions.LCLWidgetType,
4809
 
    bmsfsBackground);
4810
 
  if (not Restore) and AProject.CompilerOptions.UseAsDefault then
 
5260
  MainBuildBoss.SetBuildTargetProject1(false);
 
5261
  if (not Restore) and AProject.UseAsDefault then
4811
5262
  begin
4812
 
    aFilename:=AppendPathDelim(GetPrimaryConfigPath)+DefaultProjectCompilerOptionsFilename;
4813
 
    AProject.CompilerOptions.SaveToFile(aFilename);
 
5263
    aFilename:=AppendPathDelim(GetPrimaryConfigPath)+DefaultProjectOptionsFilename;
 
5264
    AProject.WriteProject([pwfSkipSeparateSessionInfo,pwfIgnoreModified],aFilename);
4814
5265
  end;
4815
5266
  if Restore then
4816
5267
    AProject.RestoreSession;
4817
5268
end;
4818
5269
 
 
5270
procedure TMainIDE.ComponentPaletteClassSelected(Sender: TObject);
 
5271
begin
 
5272
  if (Screen.CustomFormZOrderCount > 1)
 
5273
  and Assigned(Screen.CustomFormsZOrdered[1].Designer) then begin
 
5274
    // previous active form was designer form
 
5275
    ShowDesignerForm(Screen.CustomFormsZOrdered[1]);
 
5276
    Exit;
 
5277
  end;
 
5278
  DoShowDesignerFormOfCurrentSrc;
 
5279
end;
 
5280
 
4819
5281
procedure TMainIDE.mnuEnvEditorOptionsClicked(Sender: TObject);
4820
5282
begin
4821
5283
  DoOpenIDEOptions(TEditorGeneralOptionsFrame);
4836
5298
 
4837
5299
procedure TMainIDE.mnuEnvRescanFPCSrcDirClicked(Sender: TObject);
4838
5300
begin
4839
 
  MainBuildBoss.RescanCompilerDefines(false,true,false);
4840
 
end;
4841
 
 
4842
 
procedure TMainIDE.SaveEnvironment;
4843
 
begin
 
5301
  IncreaseBuildMacroChangeStamp;
 
5302
  MainBuildBoss.RescanCompilerDefines(false,true,false,false);
 
5303
end;
 
5304
 
 
5305
procedure TMainIDE.mnuWindowManagerClicked(Sender: TObject);
 
5306
begin
 
5307
  ShowEditorFileManagerForm;
 
5308
end;
 
5309
 
 
5310
procedure TMainIDE.SaveEnvironment(Immediately: boolean);
 
5311
begin
 
5312
  if not Immediately then
 
5313
  begin
 
5314
    fNeedSaveEnvironment:=true;
 
5315
    exit;
 
5316
  end;
 
5317
  fNeedSaveEnvironment:=false;
4844
5318
  SaveDesktopSettings(EnvironmentOptions);
4845
5319
  EnvironmentOptions.Save(false);
4846
5320
  //debugln('TMainIDE.SaveEnvironment A ',dbgsName(ObjectInspector1.Favourites));
4860
5334
begin
4861
5335
  //debugln('TMainIDE.CreateNewCodeBuffer START NewFilename=',NewFilename,' ',Descriptor.DefaultFilename,' ',Descriptor.ClassName);
4862
5336
  NewUnitName:='';
 
5337
  NewCodeBuffer:=nil;
4863
5338
  if NewFilename='' then begin
4864
5339
    // create a new unique filename
4865
5340
    SearchFlags:=[siffCheckAllProjects];
4933
5408
 
4934
5409
  // Figure out where we want to put the new form
4935
5410
  // if there is more place left of the OI put it left, otherwise right
4936
 
  p:=ObjectInspector1.ClientOrigin;
4937
 
  new_x:=p.X;
 
5411
  p:=Point(0,0);
 
5412
  if ObjectInspector1<>nil then begin
 
5413
    p:=ObjectInspector1.ClientOrigin;
 
5414
    new_x:=p.x;
 
5415
    new_y:=p.Y+10;
 
5416
  end else begin
 
5417
    new_x:=200;
 
5418
    new_y:=100;
 
5419
  end;
4938
5420
  if new_x>Screen.Width div 2 then
4939
5421
    new_x:=new_x-500
4940
 
  else
 
5422
  else if ObjectInspector1<>nil then
4941
5423
    new_x:=new_x+ObjectInspector1.Width;
4942
 
  new_y:=p.Y+10;
4943
5424
  r:=Screen.PrimaryMonitor.WorkareaRect;
4944
 
  new_x:=Max(r.Left,Min(new_x,r.Right-200));
4945
 
  new_y:=Max(r.Top,Min(new_y,r.Bottom-200));
 
5425
  new_x:=Max(r.Left,Min(new_x,r.Right-400));
 
5426
  new_y:=Max(r.Top,Min(new_y,r.Bottom-400));
4946
5427
 
4947
5428
  // create jit component
4948
5429
  NewComponent := FormEditor1.CreateComponent(nil,TComponentClass(AncestorType),
4975
5456
  Result:=mrOk;
4976
5457
end;
4977
5458
 
 
5459
function TMainIDE.NewUniqueComponentName(Prefix: string): string;
 
5460
 
 
5461
  function SearchProject(AProject: TProject; const Identifier: string): boolean;
 
5462
  var
 
5463
    i: Integer;
 
5464
    AnUnitInfo: TUnitInfo;
 
5465
  begin
 
5466
    if AProject=nil then exit(false);
 
5467
    Result:=true;
 
5468
    for i:=0 to AProject.UnitCount-1 do
 
5469
    begin
 
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;
 
5478
      end;
 
5479
    end;
 
5480
    Result:=false;
 
5481
  end;
 
5482
 
 
5483
  function SearchPackage(APackage: TLazPackage; const Identifier: string): boolean;
 
5484
  var
 
5485
    i: Integer;
 
5486
    PkgFile: TPkgFile;
 
5487
  begin
 
5488
    if APackage=nil then exit(false);
 
5489
    Result:=true;
 
5490
    if SysUtils.CompareText(APackage.Name,Identifier)=0 then exit;
 
5491
    for i:=0 to APackage.FileCount-1 do
 
5492
    begin
 
5493
      PkgFile:=APackage.Files[i];
 
5494
      if SysUtils.CompareText(PkgFile.Unit_Name,Identifier)=0 then exit;
 
5495
    end;
 
5496
    Result:=false;
 
5497
  end;
 
5498
 
 
5499
  function IdentifierExists(Identifier: string): boolean;
 
5500
  var
 
5501
    i: Integer;
 
5502
  begin
 
5503
    Result:=true;
 
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;
 
5508
    Result:=false;
 
5509
  end;
 
5510
 
 
5511
  function IdentifierIsOk(Identifier: string): boolean;
 
5512
  begin
 
5513
    Result:=false;
 
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;
 
5518
    Result:=true;
 
5519
  end;
 
5520
 
 
5521
var
 
5522
  i: Integer;
 
5523
begin
 
5524
  if IdentifierIsOk(Prefix) then
 
5525
    exit(Prefix);
 
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
 
5529
    Prefix:='Resource';
 
5530
  i:=0;
 
5531
  repeat
 
5532
    inc(i);
 
5533
    Result:=Prefix+IntToStr(i);
 
5534
  until IdentifierIsOk(Result);
 
5535
end;
 
5536
 
4978
5537
function TMainIDE.DoLoadResourceFile(AnUnitInfo: TUnitInfo;
4979
 
  var LFMCode, ResourceCode: TCodeBuffer;
 
5538
  var LFMCode, LRSCode: TCodeBuffer;
4980
5539
  IgnoreSourceErrors, AutoCreateResourceCode, ShowAbort: boolean): TModalResult;
 
5540
const
 
5541
  LfmSuffices: array[0..1] of string = ('.lfm', '.dfm');
4981
5542
var
4982
5543
  LFMFilename: string;
4983
5544
  LRSFilename: String;
4984
5545
  ResType: TResourceType;
 
5546
  i: Integer;
4985
5547
begin
4986
5548
  LFMCode:=nil;
4987
 
  ResourceCode:=nil;
 
5549
  LRSCode:=nil;
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
 
5558
          exit;
 
5559
        Break;
 
5560
      end;
 
5561
    end;
 
5562
  end;
4989
5563
  if AnUnitInfo.HasResources then begin
4990
5564
    //writeln('TMainIDE.DoLoadResourceFile A "',AnUnitInfo.Filename,'" "',AnUnitInfo.ResourceFileName,'"');
4991
 
 
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;
4998
5571
      end else begin
4999
5572
        LRSFilename:=MainBuildBoss.GetDefaultLRSFilename(AnUnitInfo);
5000
5573
        if AutoCreateResourceCode then begin
5001
 
          ResourceCode:=CodeToolBoss.CreateFile(LRSFilename);
 
5574
          LRSCode:=CodeToolBoss.CreateFile(LRSFilename);
5002
5575
        end else begin
5003
5576
          DebugLn(['TMainIDE.DoLoadResourceFile .lrs file not found of unit ',AnUnitInfo.Filename]);
5004
5577
          exit(mrCancel);
5006
5579
      end;
5007
5580
    end else begin
5008
5581
      LRSFilename:='';
5009
 
      ResourceCode:=nil;
 
5582
      LRSCode:=nil;
5010
5583
    end;
5011
 
 
5012
5584
    // if no resource file found (i.e. normally the .lrs file)
5013
5585
    // don't bother the user, because it is created automatically anyway
5014
 
 
5015
 
    // then load the lfm file (without parsing)
5016
 
    if (not AnUnitInfo.IsVirtual) and (AnUnitInfo.Component<>nil) then begin
5017
 
      LFMFilename:=ChangeFileExt(AnUnitInfo.Filename,'.lfm');
5018
 
      if not FileExistsUTF8(LFMFilename) then
5019
 
        LFMFilename:=ChangeFileExt(AnUnitInfo.Filename,'.dfm');
5020
 
      if (FileExistsUTF8(LFMFilename)) then begin
5021
 
        Result:=LoadCodeBuffer(LFMCode,LFMFilename,[lbfCheckIfText],ShowAbort);
5022
 
        if not (Result in [mrOk,mrIgnore]) then exit;
5023
 
      end;
5024
 
    end;
5025
5586
  end;
5026
5587
  Result:=mrOk;
5027
5588
end;
5042
5603
  AnUnitInfo:=Project1.UnitInfoWithFilename(AFilename);
5043
5604
  if AnUnitInfo = nil then
5044
5605
  begin
5045
 
    AFilename:=CleanAndExpandFilename(UnitFilename);
5046
 
    if not FileExistsInIDE(AFilename,[]) then begin
 
5606
    AFilename:=TrimAndExpandFilename(UnitFilename);
 
5607
    if (AFilename='') or (not FileExistsInIDE(AFilename,[])) then begin
5047
5608
      DebugLn(['TMainIDE.DoOpenComponent file not found ',AFilename]);
5048
5609
      exit(mrCancel);
5049
5610
    end;
5102
5663
 
5103
5664
function TMainIDE.DoShowSaveFileAsDialog(var AFilename: string;
5104
5665
  AnUnitInfo: TUnitInfo;
5105
 
  var ResourceCode: TCodeBuffer; CanAbort: boolean): TModalResult;
 
5666
  var LFMCode, LRSCode: TCodeBuffer; CanAbort: boolean): TModalResult;
5106
5667
var
5107
5668
  SaveDialog: TSaveDialog;
5108
5669
  SaveAsFilename, SaveAsFileExt, NewFilename, NewUnitName, NewFilePath,
5113
5674
  PkgDefaultDirectory: String;
5114
5675
  OldUnitName: String;
5115
5676
  IsPascal: Boolean;
 
5677
  Filter: String;
 
5678
  AllEditorExt: string;
 
5679
  AllFilter: string;
5116
5680
begin
5117
5681
  if (AnUnitInfo<>nil) and (AnUnitInfo.OpenEditorInfoCount>0) then
5118
5682
    SrcEdit := TSourceEditor(AnUnitInfo.OpenEditorInfo[0].EditorComponent)
5145
5709
  if SaveAsFilename='' then
5146
5710
    SaveAsFilename:=lisnoname;
5147
5711
 
 
5712
  //suggest lowercased name if user wants so
 
5713
  if EnvironmentOptions.LowercaseDefaultFilename = true then
 
5714
    SaveAsFilename:=LowerCase(SaveAsFilename);
 
5715
 
5148
5716
  // let user choose a filename
5149
5717
  SaveDialog:=TSaveDialog.Create(nil);
5150
5718
  try
5151
5719
    InputHistories.ApplyFileDialogSettings(SaveDialog);
5152
5720
    SaveDialog.Title:=lisSaveSpace+SaveAsFilename+' (*'+SaveAsFileExt+')';
5153
5721
    SaveDialog.FileName:=SaveAsFilename+SaveAsFileExt;
 
5722
 
 
5723
    Filter := lisLazarusUnit + ' (*.pas;*.pp)|*.pas;*.pp';
 
5724
    if (SaveAsFileExt='.lpi') then
 
5725
      Filter:=Filter+ '|' + lisLazarusProject + ' (*.lpi)|*.lpi';
 
5726
    if (SaveAsFileExt='.lfm') or (SaveAsFileExt='.dfm') then
 
5727
      Filter:=Filter+ '|' + lisLazarusForm + ' (*.lfm;*.dfm)|*.lfm;*.dfm';
 
5728
    if (SaveAsFileExt='.lpk') then
 
5729
      Filter:=Filter+ '|' + lisLazarusPackage + ' (*.lpk)|*.lpk';
 
5730
    if (SaveAsFileExt='.lpr') then
 
5731
      Filter:=Filter+ '|' + lisLazarusProjectSource + ' (*.lpr)|*.lpr';
 
5732
    // append a filter for all editor files
 
5733
    CreateFileDialogFilterForSourceEditorFiles(Filter,AllEditorExt,AllFilter);
 
5734
    if AllEditorExt<>'' then
 
5735
      Filter:=Filter+ '|' + lisEditorFileTypes + ' (' + AllEditorExt + ')|' + AllEditorExt;
 
5736
 
 
5737
    // append an any file filter *.*
 
5738
    Filter:=Filter+ '|' + dlgAllFiles + ' (' + GetAllFilesMask + ')|' + GetAllFilesMask;
 
5739
 
 
5740
    // prepend an all filter
 
5741
    Filter:=  lisLazarusFile + ' ('+AllFilter+')|' + AllFilter + '|' + Filter;
 
5742
    SaveDialog.Filter := Filter;
 
5743
 
5154
5744
    // if this is a project file, start in project directory
5155
5745
    if (AnUnitInfo=nil)
5156
5746
    or (AnUnitInfo.IsPartOfProject and (not Project1.IsVirtual)
5172
5762
      exit;
5173
5763
    end;
5174
5764
    NewFilename:=ExpandFileNameUTF8(SaveDialog.Filename);
 
5765
    //debugln(['TMainIDE.DoShowSaveFileAsDialog SaveDialog.Filename="',SaveDialog.Filename,'" NewFilename="',NewFilename,'"']);
5175
5766
  finally
5176
5767
    InputHistories.StoreFileDialogSettings(SaveDialog);
5177
5768
    SaveDialog.Free;
5195
5786
  // check unitname
5196
5787
  if FilenameIsPascalUnit(NewFilename) then begin
5197
5788
    NewUnitName:=ExtractFileNameOnly(NewFilename);
 
5789
    // do not rename the unit if new filename differs from its name only in case
 
5790
    if LowerCase(OldUnitName)=NewUnitName then
 
5791
      NewUnitName:=OldUnitName;
5198
5792
    if NewUnitName='' then begin
5199
5793
      Result:=mrCancel;
5200
5794
      exit;
5201
5795
    end;
5202
 
    if not IsValidIdent(NewUnitName) then begin
 
5796
    if not IsValidUnitName(NewUnitName) then begin
5203
5797
      AlternativeUnitName:=NameToValidIdentifier(NewUnitName);
5204
5798
      Result:=IDEMessageDialogAb(lisInvalidPascalIdentifierCap,
5205
5799
        Format(lisInvalidPascalIdentifierText,[NewUnitName,AlternativeUnitName]),
5206
5800
        mtWarning,[mbIgnore,mbCancel],CanAbort);
5207
5801
      if Result in [mrCancel,mrAbort] then exit;
5208
5802
      NewUnitName:=AlternativeUnitName;
5209
 
      Result:=mrCancel;
5210
5803
    end;
5211
5804
    if Project1.IndexOfUnitWithName(NewUnitName,true,AnUnitInfo)>=0 then
5212
5805
    begin
5262
5855
 
5263
5856
  if AnUnitInfo<>nil then begin
5264
5857
    // rename unit
5265
 
    Result:=DoRenameUnit(AnUnitInfo,NewFilename,NewUnitName,ResourceCode);
 
5858
    Result:=DoRenameUnit(AnUnitInfo,NewFilename,NewUnitName,LFMCode,LRSCode);
5266
5859
    AFilename:=AnUnitInfo.Filename;
5267
5860
    if Result<>mrOk then exit;
5268
5861
  end else begin
5304
5897
  PropInfo: PPropInfo; var Content: string);
5305
5898
var
5306
5899
  LRSWriter: TLRSObjectWriter;
5307
 
  Path, WriterRootPath: String;
 
5900
  Path: String;
5308
5901
begin
5309
5902
  if not Assigned(Instance) then exit;
5310
5903
  if not Assigned(PropInfo) then exit;
5311
5904
  if SysUtils.CompareText(PropInfo^.PropType^.Name,'TTRANSLATESTRING')<>0 then exit;
5312
 
  Path:='';
5313
5905
  if Writer.Driver is TLRSObjectWriter then begin
5314
5906
    LRSWriter:=TLRSObjectWriter(Writer.Driver);
5315
 
    WriterRootPath:=LRSWriter.GetStackPath(Writer.Root);
5316
 
    Path:=Copy(WriterRootPath, 1, Pos('.',WriterRootPath))+Instance.GetNamePath+'.'+PropInfo^.Name;
 
5907
    Path:=LRSWriter.GetStackPath;
5317
5908
  end else begin
5318
5909
    Path:=Instance.ClassName+'.'+PropInfo^.Name;
5319
5910
  end;
5323
5914
end;
5324
5915
 
5325
5916
function TMainIDE.DoSaveUnitComponent(AnUnitInfo: TUnitInfo;
5326
 
  ResourceCode, LFMCode: TCodeBuffer; Flags: TSaveFlags): TModalResult;
 
5917
  LRSCode, LFMCode: TCodeBuffer; Flags: TSaveFlags): TModalResult;
 
5918
 
 
5919
  function IsI18NEnabled(UnitOwners: TFPList): boolean;
 
5920
  var
 
5921
    i: Integer;
 
5922
    APackage: TLazPackage;
 
5923
    PkgFile: TPkgFile;
 
5924
  begin
 
5925
    if AnUnitInfo.IsPartOfProject then begin
 
5926
      // a project unit
 
5927
      Result:=AnUnitInfo.Project.EnableI18N and AnUnitInfo.Project.EnableI18NForLFM
 
5928
         and (not AnUnitInfo.DisableI18NForLFM);
 
5929
      exit;
 
5930
    end;
 
5931
    if (UnitOwners<>nil) then begin
 
5932
      for i:=0 to UnitOwners.Count-1 do begin
 
5933
        if TObject(UnitOwners[i]) is TLazPackage then begin
 
5934
          // a package unit
 
5935
          APackage:=TLazPackage(UnitOwners[i]);
 
5936
          Result:=false;
 
5937
          if APackage.EnableI18N and APackage.EnableI18NForLFM then begin
 
5938
            PkgFile:=APackage.FindPkgFile(AnUnitInfo.Filename,true,true);
 
5939
            Result:=(PkgFile<>nil) and (not PkgFile.DisableI18NForLFM);
 
5940
          end;
 
5941
          exit;
 
5942
        end;
 
5943
      end;
 
5944
    end;
 
5945
    // a rogue unit
 
5946
    Result:=false;
 
5947
  end;
 
5948
 
5327
5949
var
5328
5950
  ComponentSavingOk: boolean;
5329
5951
  MemStream, BinCompStream, TxtCompStream: TExtMemoryStream;
5338
5960
  Ancestor: TComponent;
5339
5961
  HasI18N: Boolean;
5340
5962
  UnitOwners: TFPList;
5341
 
  APackage: TLazPackage;
5342
 
  i: Integer;
5343
5963
  LRSFilename: String;
5344
5964
  PropPath: String;
5345
5965
  ResType: TResourceType;
5359
5979
  // <ClassName>.<PropertyName>=<PropertyValue>
5360
5980
  LRSFilename:='';
5361
5981
  ResType:=MainBuildBoss.GetResourceType(AnUnitInfo);
5362
 
  ResourceCode:=nil;
 
5982
  LRSCode:=nil;
5363
5983
 
5364
5984
  if (AnUnitInfo.Component<>nil) then begin
5365
5985
    // stream component to resource code and to lfm file
5382
6002
    // stream component to binary stream
5383
6003
    BinCompStream:=TExtMemoryStream.Create;
5384
6004
    if AnUnitInfo.ComponentLastBinStreamSize>0 then
5385
 
      BinCompStream.Capacity:=
5386
 
                       AnUnitInfo.ComponentLastBinStreamSize+LRSStreamChunkSize;
 
6005
      BinCompStream.Capacity:=AnUnitInfo.ComponentLastBinStreamSize+LRSStreamChunkSize;
5387
6006
    Writer:=nil;
5388
6007
    DestroyDriver:=false;
5389
6008
    Grubber:=nil;
5396
6015
          BinCompStream.Position:=0;
5397
6016
          Writer:=CreateLRSWriter(BinCompStream,DestroyDriver);
5398
6017
          // used to save lrt files
5399
 
          HasI18N:=AnUnitInfo.IsPartOfProject and (not AnUnitInfo.DisableI18NForLFM)
5400
 
             and AnUnitInfo.Project.EnableI18N and AnUnitInfo.Project.EnableI18NForLFM;
5401
 
          if (not HasI18N) and (UnitOwners<>nil) then begin
5402
 
            for i:=0 to UnitOwners.Count-1 do begin
5403
 
              if TObject(UnitOwners[i]) is TLazPackage then begin
5404
 
                APackage:=TLazPackage(UnitOwners[i]);
5405
 
                if APackage.EnableI18N then
5406
 
                  HasI18N:=true;
5407
 
              end;
5408
 
            end;
5409
 
          end;
 
6018
          HasI18N:=IsI18NEnabled(UnitOwners);
5410
6019
          if HasI18N then
5411
6020
            Grubber:=TLRTGrubber.Create(Writer);
5412
6021
          Writer.OnWriteMethodProperty:=@FormEditor1.WriteMethodPropertyEvent;
5418
6027
            Ancestor:=AncestorUnit.Component;
5419
6028
          //DebugLn(['TMainIDE.DoSaveUnitComponent Writer.WriteDescendent ARoot=',AnUnitInfo.Component,' Ancestor=',DbgSName(Ancestor)]);
5420
6029
          Writer.WriteDescendent(AnUnitInfo.Component,Ancestor);
5421
 
          if DestroyDriver then Writer.Driver.Free;
 
6030
          if DestroyDriver then
 
6031
            Writer.Driver.Free;
5422
6032
          FreeAndNil(Writer);
5423
6033
          AnUnitInfo.ComponentLastBinStreamSize:=BinCompStream.Size;
5424
6034
        except
5425
6035
          on E: Exception do begin
5426
6036
            PropPath:='';
5427
6037
            if Writer.Driver is TLRSObjectWriter then
5428
 
              PropPath:=TLRSObjectWriter(Writer.Driver).GetStackPath(AnUnitInfo.Component);
 
6038
              PropPath:=TLRSObjectWriter(Writer.Driver).GetStackPath;
5429
6039
            DumpExceptionBackTrace;
5430
6040
            ACaption:=lisStreamingError;
5431
6041
            AText:=Format(lisUnableToStreamT, [AnUnitInfo.ComponentName,
5432
 
                          AnUnitInfo.ComponentName]) + LineEnding
5433
 
                          +E.Message;
 
6042
                          AnUnitInfo.ComponentName]) + LineEnding + E.Message;
5434
6043
            if PropPath<>'' then
5435
6044
              AText := Atext + LineEnding + LineEnding + lisPathToInstance
5436
6045
                     + LineEnding + PropPath;
5437
 
            Result:=MessageDlg(ACaption, AText, mtError,
5438
 
                       [mbAbort, mbRetry, mbIgnore], 0);
 
6046
            Result:=IDEMessageDialog(ACaption, AText, mtError,
 
6047
                       [mbAbort, mbRetry, mbIgnore]);
5439
6048
            if Result=mrAbort then exit;
5440
6049
            if Result=mrIgnore then Result:=mrOk;
5441
6050
            ComponentSavingOk:=false;
5445
6054
 
5446
6055
      // create lazarus form resource code
5447
6056
      if ComponentSavingOk and (LRSFilename<>'') then begin
5448
 
        if ResourceCode=nil then begin
5449
 
          ResourceCode:=CodeToolBoss.CreateFile(LRSFilename);
5450
 
          ComponentSavingOk:=(ResourceCode<>nil);
 
6057
        if LRSCode=nil then begin
 
6058
          LRSCode:=CodeToolBoss.CreateFile(LRSFilename);
 
6059
          ComponentSavingOk:=(LRSCode<>nil);
5451
6060
        end;
5452
6061
        if ComponentSavingOk then begin
5453
 
          // there is no bug in the source, so the resource code should be
5454
 
          // changed too
 
6062
          // there is no bug in the source, so the resource code should be changed too
5455
6063
          MemStream:=TExtMemoryStream.Create;
5456
6064
          if AnUnitInfo.ComponentLastLRSStreamSize>0 then
5457
6065
            MemStream.Capacity:=AnUnitInfo.ComponentLastLRSStreamSize+LRSStreamChunkSize;
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);
5481
6089
            end;
5482
6090
            // add comment to resource file (if not already exists)
5483
 
            if (not CodeToolBoss.AddLazarusResourceHeaderComment(ResourceCode,
5484
 
               LRSComment)) then
 
6091
            if (not CodeToolBoss.AddLazarusResourceHeaderComment(LRSCode,LRSComment)) then
5485
6092
            begin
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;
5491
6098
            end;
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
5495
6102
            begin
5496
6103
              ACaption:=lisResourceSaveError;
5497
6104
              AText:=Format(
5498
6105
                lisUnableToAddResourceTFORMDATAToResourceFileProbably, [
5499
6106
                AnUnitInfo.ComponentName,
5500
 
                #13, '"', ResourceCode.FileName, '"', #13]
 
6107
                #13, '"', LRSCode.FileName, '"', #13]
5501
6108
                );
5502
 
              Result:=MessageDlg(ACaption, AText, mtError, [mbIgnore, mbAbort],0);
 
6109
              Result:=IDEMessageDialog(ACaption, AText, mtError, [mbIgnore, mbAbort]);
5503
6110
              if Result<>mrIgnore then exit;
5504
6111
            end else begin
5505
6112
              AnUnitInfo.ComponentResourceName:=AnUnitInfo.ComponentName;
5506
6113
            end;
5507
6114
          end else begin
5508
 
            ResourceCode.Source:=CompResourceCode;
 
6115
            LRSCode.Source:=CompResourceCode;
5509
6116
          end;
5510
6117
        end;
5511
6118
      end;
5519
6126
          if LFMCode=nil then begin
5520
6127
            LFMCode:=CodeToolBoss.CreateFile(LFMFilename);
5521
6128
            if LFMCode=nil then begin
5522
 
              Result:=QuestionDlg(lisUnableToCreateFile,
 
6129
              Result:=IDEQuestionDialog(lisUnableToCreateFile,
5523
6130
                Format(lisUnableToCreateFile2, ['"', LFMFilename, '"']),
5524
6131
                mtWarning, [mrIgnore, lisContinueWithoutLoadingForm,
5525
6132
                           mrCancel, lisCancelLoadingUnit,
5526
 
                           mrAbort, lisAbortAllLoading], 0);
 
6133
                           mrAbort, lisAbortAllLoading]);
5527
6134
              if Result<>mrIgnore then exit;
5528
6135
            end;
5529
6136
          end;
5569
6176
                    lisUnableToTransformBinaryComponentStreamOfTIntoText, [
5570
6177
                    AnUnitInfo.ComponentName, AnUnitInfo.ComponentName])
5571
6178
                    +#13+E.Message;
5572
 
                  Result:=MessageDlg(ACaption, AText, mtError,
5573
 
                                     [mbAbort, mbRetry, mbIgnore], 0);
 
6179
                  Result:=IDEMessageDialog(ACaption, AText, mtError,
 
6180
                                     [mbAbort, mbRetry, mbIgnore]);
5574
6181
                  if Result=mrAbort then exit;
5575
6182
                  if Result=mrIgnore then Result:=mrOk;
5576
6183
                end;
5614
6221
    writeln('TMainIDE.SaveFileResources F ',ResourceCode.Modified);
5615
6222
  {$ENDIF}
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
5619
6226
    begin
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
 
6233
        begin
 
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;
 
6238
        end;
5629
6239
      end;
5630
6240
    end else begin
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;
5636
6245
    end;
5637
6246
  end;
5657
6266
  if (AnUnitInfo.Component=nil) then exit;
5658
6267
  if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[]) then exit;
5659
6268
  // unselect methods in ObjectInspector1
5660
 
  if (ObjectInspector1.PropertyEditorHook.LookupRoot=AnUnitInfo.Component) then
 
6269
  if (ObjectInspector1<>nil)
 
6270
  and (ObjectInspector1.PropertyEditorHook.LookupRoot=AnUnitInfo.Component) then
5661
6271
  begin
5662
6272
    ObjectInspector1.EventGrid.ItemIndex:=-1;
5663
6273
    ObjectInspector1.FavouriteGrid.ItemIndex:=-1;
5668
6278
                               ComponentModified);
5669
6279
  // update ObjectInspector1
5670
6280
  if ComponentModified
 
6281
  and (ObjectInspector1<>nil)
5671
6282
  and (ObjectInspector1.PropertyEditorHook.LookupRoot=AnUnitInfo.Component) then
5672
6283
  begin
5673
6284
    ObjectInspector1.EventGrid.RefreshPropertyValues;
5677
6288
 
5678
6289
function TMainIDE.DoRenameUnit(AnUnitInfo: TUnitInfo;
5679
6290
  NewFilename, NewUnitName: string;
5680
 
  var ResourceCode: TCodeBuffer): TModalresult;
 
6291
  var LFMCode, LRSCode: TCodeBuffer): TModalresult;
5681
6292
var
5682
6293
  NewLFMFilename: String;
5683
6294
  OldSourceCode: String;
5684
6295
  NewSource: TCodeBuffer;
5685
6296
  NewFilePath: String;
5686
 
  NewResFilePath: String;
 
6297
  NewLRSFilePath: String;
5687
6298
  OldFilePath: String;
5688
 
  OldResFilePath: String;
 
6299
  OldLRSFilePath: String;
5689
6300
  OldFilename: String;
5690
 
  NewResFilename: String;
 
6301
  NewLRSFilename: String;
5691
6302
  NewHighlighter: TLazSyntaxHighlighter;
5692
6303
  AmbiguousFiles: TStringList;
5693
6304
  AmbiguousText: string;
5699
6310
  OldPPUFilename: String;
5700
6311
  OutDir: string;
5701
6312
  Owners: TFPList;
5702
 
  LFMBuf: TCodeBuffer;
 
6313
  OldFileExisted: Boolean;
 
6314
  ConvTool: TConvDelphiCodeTool;
5703
6315
begin
5704
6316
  Project1.BeginUpdate(false);
5705
6317
  try
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');
 
6320
    OldLFMFilename:='';
 
6321
    if FilenameIsPascalUnit(OldFilename) then begin
 
6322
      OldLFMFilename:=ChangeFileExt(OldFilename,'.lfm');
 
6323
      if not FileExistsUTF8(OldLFMFilename) then
 
6324
        OldLFMFilename:=ChangeFileExt(OldFilename,'.dfm');
 
6325
    end;
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,'"']);
5714
6329
 
5715
6330
    // check new resource file
5716
 
    NewLFMFilename:=ChangeFileExt(NewFilename,'.lfm');
 
6331
    NewLFMFilename:='';
 
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)
5724
6341
        then
5725
6342
      begin
5726
6343
        Result:=mrCancel;
5733
6350
    NewSource:=CodeToolBoss.CreateFile(NewFilename);
5734
6351
    NewSource.Source:=OldSourceCode;
5735
6352
    if NewSource=nil then begin
5736
 
      Result:=MessageDlg(lisUnableToCreateFile,
 
6353
      Result:=IDEMessageDialog(lisUnableToCreateFile,
5737
6354
        Format(lisCanNotCreateFile, ['"', NewFilename, '"']),
5738
 
        mtError,[mbCancel,mbAbort],0);
 
6355
        mtError,[mbCancel,mbAbort]);
5739
6356
      exit;
5740
6357
    end;
5741
6358
    // get final filename
5754
6371
 
5755
6372
      if SearchDirectoryInSearchPath(OldUnitPath,NewFilePath,1)<1 then begin
5756
6373
        //DebugLn('TMainIDE.DoRenameUnit NewFilePath="',NewFilePath,'" OldUnitPath="',OldUnitPath,'"');
5757
 
        if MessageDlg(lisExtendUnitPath,
 
6374
        if IDEMessageDialog(lisExtendUnitPath,
5758
6375
          Format(lisTheDirectoryIsNotYetInTheUnitPathAddIt, ['"', NewFilePath,
5759
6376
            '"', #13]),
5760
 
          mtConfirmation,[mbYes,mbNo],0)=mrYes then
 
6377
          mtConfirmation,[mbYes,mbNo])=mrYes then
5761
6378
        begin
5762
6379
          Project1.CompilerOptions.OtherUnitFiles:=
5763
6380
                       Project1.CompilerOptions.OtherUnitFiles+';'
5766
6383
      end;
5767
6384
    end;
5768
6385
 
 
6386
    // rename lfm file
 
6387
    if FilenameIsAbsolute(NewLFMFilename) then begin
 
6388
      if (LFMCode=nil)
 
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,'"']);
 
6396
          exit;
 
6397
        end;
 
6398
        LFMCode:=CodeToolBoss.LoadFile(NewLFMFilename,true,false);
 
6399
        if LFMCode<>nil then
 
6400
          NewLFMFilename:=LFMCode.Filename;
 
6401
        ConvTool:=TConvDelphiCodeTool.Create(NewSource);
 
6402
        try
 
6403
          if not ConvTool.RenameResourceDirectives then
 
6404
            debugln(['TMainIDE.DoRenameUnit WARNING: unable to rename resource directive in "',NewSource.Filename,'"']);
 
6405
        finally
 
6406
          ConvTool.Free;
 
6407
        end;
 
6408
      end;
 
6409
    end;
 
6410
 
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;
5779
6421
      end else begin
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;
5791
6433
        end else begin
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;
5795
6437
        end;
5796
 
        NewResFilename:=NewResFilePath
 
6438
        NewLRSFilename:=NewLRSFilePath
5797
6439
                        +ExtractFileNameOnly(NewFilename)+ResourceFileExt;
5798
6440
      end;
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)
5803
6445
        then
5804
 
          DebugLn(['TMainIDE.DoRenameUnit CodeToolBoss.SaveBufferAs failed: NewResFilename="',NewResFilename,'"']);
 
6446
          DebugLn(['TMainIDE.DoRenameUnit CodeToolBoss.SaveBufferAs failed: NewResFilename="',NewLRSFilename,'"']);
5805
6447
      end;
5806
6448
 
5807
6449
      {$IFDEF IDE_DEBUG}
5810
6452
      if ResourceCode<>nil then debugln('*** ResourceFileName ',ResourceCode.Filename);
5811
6453
      {$ENDIF}
5812
6454
    end else begin
5813
 
      NewResFilename:='';
 
6455
      NewLRSFilename:='';
5814
6456
    end;
5815
6457
    // rename unit name of jit class
5816
6458
    if (AnUnitInfo.Component<>nil) then
5820
6462
    debugln(['TMainIDE.DoRenameUnit D ',ResourceCode<>nil]);
5821
6463
    {$ENDIF}
5822
6464
 
5823
 
    // save new lfm
5824
 
    if FilenameIsAbsolute(OldLFMFilename) and FileExistsUTF8(OldLFMFilename) then
5825
 
    begin
5826
 
      LFMBuf:=CodeToolBoss.LoadFile(OldLFMFilename,false,false);
5827
 
      if (LFMBuf<>nil) and FilenameIsAbsolute(NewLFMFilename) then begin
5828
 
        Result:=SaveCodeBufferToFile(LFMBuf,NewLFMFilename,true);
5829
 
        if Result<>mrOk then begin
5830
 
          DebugLn(['TMainIDE.DoRenameUnit SaveCodeBufferToFile failed for ',NewLFMFilename]);
5831
 
        end;
5832
 
        if Result=mrAbort then exit;
5833
 
      end;
5834
 
    end;
5835
 
 
5836
6465
    // set new codebuffer in unitinfo and sourceeditor
5837
6466
    AnUnitInfo.Source:=NewSource;
5838
6467
    AnUnitInfo.ClearModifieds;
5843
6472
 
5844
6473
    // change unitname in lpi and in main source file
5845
6474
    AnUnitInfo.Unit_Name:=NewUnitName;
5846
 
    if ResourceCode<>nil then begin
 
6475
    if LRSCode<>nil then begin
5847
6476
      // change resource filename in the source include directive
5848
6477
      if not CodeToolBoss.RenameMainInclude(AnUnitInfo.Source,
5849
 
        ExtractFilename(ResourceCode.Filename),false)
 
6478
        ExtractFilename(LRSCode.Filename),false)
5850
6479
      then
5851
 
        DebugLn(['TMainIDE.DoRenameUnit CodeToolBoss.RenameMainInclude failed: AnUnitInfo.Source="',AnUnitInfo.Source,'" ResourceCode="',ExtractFilename(ResourceCode.Filename),'"']);
 
6480
        DebugLn(['TMainIDE.DoRenameUnit CodeToolBoss.RenameMainInclude failed: AnUnitInfo.Source="',AnUnitInfo.Source,'" ResourceCode="',ExtractFilename(LRSCode.Filename),'"']);
5852
6481
    end;
5853
6482
 
5854
6483
    // change unitname on SourceNotebook
5877
6506
                                 AnUnitInfo.IsPartOfProject);
5878
6507
    if Result=mrAbort then exit;
5879
6508
 
 
6509
    OldFileExisted:=FilenameIsAbsolute(OldFilename) and FileExistsUTF8(OldFilename);
 
6510
 
5880
6511
    // delete ambiguous files
5881
6512
    NewFilePath:=ExtractFilePath(NewFilename);
5882
6513
    AmbiguousFiles:=
5893
6524
          AmbiguousText:=
5894
6525
            Format(lisThereAreOtherFilesInTheDirectoryWithTheSameName,
5895
6526
                   [#13, #13, AmbiguousFiles.Text, #13]);
5896
 
        Result:=MessageDlg(lisAmbiguousFilesFound, AmbiguousText,
5897
 
          mtWarning,[mbYes,mbNo,mbAbort],0);
 
6527
        Result:=IDEMessageDialog(lisAmbiguousFilesFound, AmbiguousText,
 
6528
          mtWarning,[mbYes,mbNo,mbAbort]);
5898
6529
        if Result=mrAbort then exit;
5899
6530
        if Result=mrYes then begin
5900
6531
          NewFilePath:=AppendPathDelim(ExtractFilePath(NewFilename));
5902
6533
            AmbiguousFilename:=NewFilePath+AmbiguousFiles[i];
5903
6534
            if (FileExistsUTF8(AmbiguousFilename))
5904
6535
            and (not DeleteFileUTF8(AmbiguousFilename))
5905
 
            and (MessageDlg(lisPkgMangDeleteFailed, Format(lisDeletingOfFileFailed,
5906
 
              ['"', AmbiguousFilename, '"']), mtError, [mbIgnore, mbCancel], 0)=
 
6536
            and (IDEMessageDialog(lisPkgMangDeleteFailed, Format(lisDeletingOfFileFailed,
 
6537
              ['"', AmbiguousFilename, '"']), mtError, [mbIgnore, mbCancel])=
5907
6538
              mrCancel) then
5908
6539
            begin
5909
6540
              Result:=mrCancel;
5928
6559
        if (SearchDirectoryInSearchPath(
5929
6560
                     Project1.CompilerOptions.GetUnitPath(false),OldFilePath,1)<1)
5930
6561
        then begin
5931
 
          if MessageDlg(lisCleanUpUnitPath,
 
6562
          if IDEMessageDialog(lisCleanUpUnitPath,
5932
6563
              Format(lisTheDirectoryIsNoLongerNeededInTheUnitPathRemoveIt, ['"',
5933
6564
                OldFilePath, '"', #13]),
5934
 
              mtConfirmation,[mbYes,mbNo],0)=mrYes then
 
6565
              mtConfirmation,[mbYes,mbNo])=mrYes then
5935
6566
          begin
5936
6567
            Project1.CompilerOptions.OtherUnitFiles:=
5937
6568
                        RemoveSearchPaths(Project1.CompilerOptions.OtherUnitFiles,
5943
6574
 
5944
6575
    // delete old pas, .pp, .ppu
5945
6576
    if (CompareFilenames(NewFilename,OldFilename)<>0)
5946
 
    and FilenameIsAbsolute(OldFilename) and FileExistsUTF8(OldFilename) then begin
5947
 
      if MessageDlg(lisDeleteOldFile2,
 
6577
    and OldFileExisted then begin
 
6578
      if IDEMessageDialog(lisDeleteOldFile2,
5948
6579
        Format(lisDeleteOldFile, ['"', OldFilename, '"']),
5949
 
        mtConfirmation,[mbYes,mbNo],0)=mrYes then
 
6580
        mtConfirmation,[mbYes,mbNo])=mrYes then
5950
6581
      begin
5951
6582
        Result:=DeleteFileInteractive(OldFilename,[mbAbort]);
5952
6583
        if Result=mrAbort then exit;
5953
6584
        // delete old lfm
 
6585
        //debugln(['TMainIDE.DoRenameUnit NewLFMFilename=',NewLFMFilename,' exists=',FileExistsUTF8(NewLFMFilename),' Old=',OldLFMFilename,' exists=',FileExistsUTF8(OldLFMFilename)]);
5954
6586
        if FileExistsUTF8(NewLFMFilename) then begin
5955
6587
          // the new file has a lfm, so it is safe to delete the old
5956
6588
          // (if NewLFMFilename does not exist, it didn't belong to the unit
5962
6594
          end;
5963
6595
        end;
5964
6596
        // delete old lrs
5965
 
        if (ResourceCode<>nil) and FileExistsUTF8(ResourceCode.Filename) then begin
 
6597
        if (LRSCode<>nil) and FileExistsUTF8(LRSCode.Filename) then begin
5966
6598
          // the new file has a lrs, so it is safe to delete the old
5967
6599
          // (if the new lrs does not exist, it didn't belong to the unit
5968
6600
          //  or there was an error during delete. Never delete files in doubt.)
6033
6665
begin
6034
6666
  if ofProjectLoading in Flags then begin
6035
6667
    // this is a file, that was loaded last time, but was removed from disk
6036
 
    Result:=QuestionDlg(lisFileNotFound,
 
6668
    Result:=IDEQuestionDialog(lisFileNotFound,
6037
6669
      Format(lisTheFileWasNotFoundIgnoreWillGoOnLoadingTheProject, ['"',
6038
6670
        AFilename, '"', #13, #13, #13]),
6039
6671
      mtError, [mrIgnore, lisSkipFileAndContinueLoading,
6040
 
                mrAbort, lisAbortLoadingProject],
6041
 
      0);
 
6672
                mrAbort, lisAbortLoadingProject]);
6042
6673
    exit;
6043
6674
  end;
6044
6675
 
6048
6679
 
6049
6680
  if ofOnlyIfExists in Flags
6050
6681
  then begin
6051
 
    MessageDlg(lisFileNotFound, Format(lisFileNotFound2, ['"', AFilename, '"',
 
6682
    IDEMessageDialog(lisFileNotFound, Format(lisFileNotFound2, ['"', AFilename, '"',
6052
6683
      #13]),
6053
 
               mtInformation,[mbCancel],0);
 
6684
               mtInformation,[mbCancel]);
6054
6685
    // cancel loading file
6055
6686
    Exit;
6056
6687
  end;
6057
6688
 
6058
 
  if MessageDlg(lisFileNotFound,
 
6689
  if IDEMessageDialog(lisFileNotFound,
6059
6690
    Format(lisFileNotFoundDoYouWantToCreateIt, ['"', AFilename, '"', #13, #13])
6060
 
    ,mtInformation,[mbYes,mbNo],0)=mrYes then
 
6691
    ,mtInformation,[mbYes,mbNo])=mrYes then
6061
6692
  begin
6062
6693
    // create new file
6063
6694
    NewFlags:=[nfOpenInEditor,nfCreateDefaultSrc];
6110
6741
        // or it is not yet a lazarus project ;)
6111
6742
        LPIFilename:=ChangeFileExt(AFilename,'.lpi');
6112
6743
        if FileExistsUTF8(LPIFilename) then begin
6113
 
          if QuestionDlg(lisProjectInfoFileDetected,
 
6744
          if IDEQuestionDialog(lisProjectInfoFileDetected,
6114
6745
            Format(lisTheFileSeemsToBeTheProgramFileOfAnExistingLazarusP, [
6115
6746
              AFilename]), mtConfirmation,
6116
 
              [mrOk, lisOpenProject2, mrCancel, lisOpenTheFileAsNormalSource], 0)
 
6747
              [mrOk, lisOpenProject2, mrCancel, lisOpenTheFileAsNormalSource])
6117
6748
            =mrOk then
6118
6749
          begin
6119
6750
            Result:=DoOpenProjectFile(LPIFilename,[]);
6124
6755
          AText:=Format(lisTheFileSeemsToBeAProgramCloseCurrentProject, ['"',
6125
6756
            AFilename, '"', #13, #13]);
6126
6757
          ACaption:=lisProgramDetected;
6127
 
          if MessageDlg(ACaption, AText, mtConfirmation,
6128
 
              [mbYes, mbNo], 0)=mrYes then
 
6758
          if IDEMessageDialog(ACaption, AText, mtConfirmation,
 
6759
              [mbYes, mbNo])=mrYes then
6129
6760
          begin
6130
6761
            Result:=DoCreateProjectForProgram(PreReadBuf);
6131
6762
            Handled:=true;
6188
6819
  BufSize = 4096; // allocating mem in 4k chunks helps many mem managers
6189
6820
 
6190
6821
  ShowCommands: array[TWindowState] of Integer =
6191
 
    (SW_SHOWNORMAL, SW_MINIMIZE, SW_SHOWMAXIMIZED);
 
6822
    (SW_SHOWNORMAL, SW_MINIMIZE, SW_SHOWMAXIMIZED, SW_SHOWFULLSCREEN);
6192
6823
 
6193
6824
var
6194
6825
  TxtLFMStream, BinStream: TExtMemoryStream;
6249
6880
        exit;
6250
6881
      end;
6251
6882
    end;
6252
 
 
6253
6883
    //debugln('TMainIDE.DoLoadLFM LFM file loaded, parsing "',LFMBuf.Filename,'" ...');
6254
6884
 
6255
 
    if not AnUnitInfo.HasResources then begin
6256
 
      // someone created a .lfm file -> Update HasResources
6257
 
      AnUnitInfo.HasResources:=true;
6258
 
    end;
 
6885
    // someone created a .lfm file -> Update HasResources
 
6886
    AnUnitInfo.HasResources:=true;
6259
6887
 
6260
6888
    //debugln('TMainIDE.DoLoadLFM LFM="',LFMBuf.Source,'"');
6261
 
 
6262
6889
    if AnUnitInfo.Component=nil then begin
6263
6890
      // load/create new instance
6264
6891
 
6267
6894
                          NewClassName,LCLVersion,MissingClasses);
6268
6895
      if (NewClassName='') or (LFMType='') then begin
6269
6896
        DebugLn(['TMainIDE.DoLoadLFM LFM file corrupt']);
6270
 
        Result:=MessageDlg(lisLFMFileCorrupt,
 
6897
        Result:=IDEMessageDialog(lisLFMFileCorrupt,
6271
6898
          Format(lisUnableToFindAValidClassnameIn, ['"', LFMBuf.Filename, '"']),
6272
 
          mtError,[mbIgnore,mbCancel,mbAbort],0);
 
6899
          mtError,[mbIgnore,mbCancel,mbAbort]);
6273
6900
        exit;
6274
6901
      end;
6275
6902
 
6340
6967
              ACaption:=lisFormatError;
6341
6968
              AText:=Format(lisUnableToConvertTextFormDataOfFileIntoBinaryStream,
6342
6969
                [#13, '"', LFMBuf.Filename, '"', #13, E.Message]);
6343
 
              Result:=MessageDlg(ACaption, AText, mtError, [mbOk, mbCancel], 0);
 
6970
              Result:=IDEMessageDialog(ACaption, AText, mtError, [mbOk, mbCancel]);
6344
6971
              if Result=mrCancel then Result:=mrAbort;
6345
6972
              exit;
6346
6973
            end;
6365
6992
            NewControl.ControlStyle:=NewControl.ControlStyle+[csNoDesignVisible];
6366
6993
          if DisableAutoSize then
6367
6994
            NewControl.EnableAutoSizing;
 
6995
          if NewComponent is TFrame then
 
6996
            AnUnitInfo.ResourceBaseClass:=pfcbcFrame
 
6997
          else if NewComponent is TDataModule then
 
6998
            AnUnitInfo.ResourceBaseClass:=pfcbcDataModule
 
6999
          else if NewComponent is TForm then
 
7000
            AnUnitInfo.ResourceBaseClass:=pfcbcForm;
6368
7001
        end;
6369
7002
        Project1.InvalidateUnitComponentDesignerDependencies;
6370
7003
        AnUnitInfo.Component:=NewComponent;
6422
7055
  AnUnitInfo.ComponentName:=NewComponent.Name;
6423
7056
  AnUnitInfo.ComponentResourceName:=AnUnitInfo.ComponentName;
6424
7057
  DesignerForm := nil;
 
7058
  FLastFormActivated := nil;
6425
7059
  if not (ofLoadHiddenResource in OpenFlags) then
6426
7060
  begin
6427
7061
    DesignerForm := FormEditor1.GetDesignerForm(NewComponent);
6436
7070
    FDisplayState := dsForm;
6437
7071
    GlobalDesignHook.LookupRoot := NewComponent;
6438
7072
    TheControlSelection.AssignPersistent(NewComponent);
 
7073
    CreateObjectInspector;
6439
7074
  end;
6440
7075
 
6441
7076
  // show new form
6465
7100
    if (DescendantClassName<>'')
6466
7101
    and (SysUtils.CompareText(AComponentClassName,'TCustomForm')=0) then begin
6467
7102
      // this is a common user mistake
6468
 
      MessageDlg(lisCodeTemplError, Format(
 
7103
      IDEMessageDialog(lisCodeTemplError, Format(
6469
7104
        lisTheResourceClassDescendsFromProbablyThisIsATypoFor, ['"',
6470
7105
        DescendantClassName, '"', '"', AComponentClassName, '"']),
6471
 
        mtError,[mbCancel],0);
 
7106
        mtError,[mbCancel]);
6472
7107
      Result:=false;
6473
7108
      exit;
6474
7109
    end else if (DescendantClassName<>'')
6475
7110
    and (SysUtils.CompareText(AComponentClassName,'TComponent')=0) then begin
6476
7111
      // this is not yet implemented
6477
 
      MessageDlg(lisCodeTemplError, Format(
 
7112
      IDEMessageDialog(lisCodeTemplError, Format(
6478
7113
        lisUnableToOpenDesignerTheClassDoesNotDescendFromADes, [#13,
6479
7114
        DescendantClassName]),
6480
 
        mtError,[mbCancel],0);
 
7115
        mtError,[mbCancel]);
6481
7116
      Result:=false;
6482
7117
      exit;
6483
7118
    end else begin
6694
7329
  LoadResult: TModalResult;
6695
7330
  LoadingReferenceNames: TStringList;
6696
7331
begin
 
7332
  //debugln(['TMainIDE.DoFixupComponentReferences START']);
6697
7333
  Result:=mrOk;
6698
7334
  CurRoot:=RootComponent;
6699
7335
  while CurRoot.Owner<>nil do
6700
7336
    CurRoot:=CurRoot.Owner;
6701
7337
  RootUnitInfo:=Project1.UnitWithComponent(CurRoot);
6702
 
  if RootUnitInfo=nil then exit;
 
7338
  if RootUnitInfo=nil then begin
 
7339
    debugln(['TMainIDE.DoFixupComponentReferences WARNING: component without unitinfo: ',DbgSName(RootComponent),' CurRoot=',DbgSName(CurRoot)]);
 
7340
    exit;
 
7341
  end;
6703
7342
 
6704
7343
  UnitFilenames:=nil;
6705
7344
  ComponentNameToUnitFilename:=nil;
6716
7355
      // load referenced components
6717
7356
      ReferenceRootNames.Clear;
6718
7357
      GetFixupReferenceNames(CurRoot,ReferenceRootNames);
 
7358
      //debugln(['TMainIDE.DoFixupComponentReferences ',i,'/',RootComponents.Count,' ',DbgSName(CurRoot),' References=',ReferenceRootNames.Count]);
6719
7359
      for j:=0 to ReferenceRootNames.Count-1 do begin
6720
7360
        RefRootName:=ReferenceRootNames[j];
6721
7361
        ReferenceInstanceNames.Clear;
6903
7543
    LFMFilename:=ChangeFileExt(UnitCode.Filename,'.lfm');
6904
7544
    if FileExistsUTF8(LFMFilename) then begin
6905
7545
      UsingFilename:=AnUnitInfo.Filename;
6906
 
      Project1.ShortenFilename(UsingFilename);
 
7546
      Project1.ConvertToLPIFilename(UsingFilename);
6907
7547
      UsedFilename:=UnitCode.Filename;
6908
 
      Project1.ShortenFilename(UsedFilename);
6909
 
      TheModalResult:=QuestionDlg(lisCodeTemplError,
 
7548
      Project1.ConvertToLPIFilename(UsedFilename);
 
7549
      TheModalResult:=IDEQuestionDialog(lisCodeTemplError,
6910
7550
        Format(lisClassConflictsWithLfmFileTheUnitUsesTheUnitWhic, [#13,
6911
7551
          UsingFilename, #13, UsedFilename, #13, AComponentClassName, #13, #13,
6912
7552
          #13, AComponentClassName]),
6913
7553
        mtError,
6914
7554
          [mrCancel, lisCancelLoadingThisComponent,
6915
7555
           mrAbort, lisAbortWholeLoading,
6916
 
           mrIgnore, lisIgnoreUseTFormAsAncestor], 0);
 
7556
           mrIgnore, lisIgnoreUseTFormAsAncestor]);
6917
7557
      exit;
6918
7558
    end;
6919
7559
    // there is no .lfm file
7061
7701
 
7062
7702
  // check for circles
7063
7703
  if AnUnitInfo.LoadingComponent then begin
7064
 
    Result:=QuestionDlg(lisCodeTemplError, Format(
 
7704
    Result:=IDEQuestionDialog(lisCodeTemplError, Format(
7065
7705
      lisUnableToLoadTheComponentClassBecauseItDependsOnIts, ['"',
7066
7706
      AComponentClassName, '"']),
7067
7707
      mtError, [mrCancel, lisCancelLoadingThisComponent,
7068
 
               mrAbort, lisAbortWholeLoading], 0);
 
7708
               mrAbort, lisAbortWholeLoading]);
7069
7709
    exit;
7070
7710
  end;
7071
7711
 
7120
7760
    end;
7121
7761
 
7122
7762
    // not found => tell the user
7123
 
    Result:=QuestionDlg(lisCodeTemplError, Format(
7124
 
      lisUnableToFindTheUnitOfComponentClass, ['"', AComponentClassName, '"']),
 
7763
    Result:=IDEQuestionDialog(lisCodeTemplError,
 
7764
      Format(lisUnableToFindTheComponentClassItIsNotRegisteredViaR, [
 
7765
        AComponentClassName, #13, #13, #13, AnUnitInfo.Filename]),
7125
7766
      mtError, [mrCancel, lisCancelLoadingThisComponent,
7126
7767
               mrAbort, lisAbortWholeLoading,
7127
 
               mrIgnore, lisIgnoreUseTFormAsAncestor], 0);
 
7768
               mrIgnore, lisIgnoreUseTFormAsAncestor]);
7128
7769
  finally
7129
7770
    AnUnitInfo.LoadingComponent:=false;
7130
7771
  end;
7131
7772
end;
7132
7773
 
 
7774
procedure TMainIDE.FreeDesigner(AnUnitInfo: TUnitInfo; ADesigner: TDesigner;
 
7775
                                AFreeComponent: boolean);
 
7776
begin
 
7777
  AnUnitInfo.LoadedDesigner:=false;
 
7778
  ADesigner.PrepareFreeDesigner(AFreeComponent);
 
7779
  ADesigner.FinalizeFreeDesigner;
 
7780
end;
 
7781
 
7133
7782
{-------------------------------------------------------------------------------
7134
7783
  function TMainIDE.CloseUnitComponent
7135
7784
 
7235
7884
        {$IFDEF VerboseIDEMultiForm}
7236
7885
        DebugLn(['TMainIDE.CloseUnitComponent hiding component and freeing designer: ',AnUnitInfo.Filename,' ',DbgSName(AnUnitInfo.Component)]);
7237
7886
        {$ENDIF}
7238
 
        AnUnitInfo.LoadedDesigner:=false;
7239
 
        OldDesigner.FreeDesigner(false);
 
7887
        FreeDesigner(AnUnitInfo, OldDesigner, false);
7240
7888
      end else begin
7241
7889
        // free designer and design form
7242
7890
        {$IFDEF VerboseIDEMultiForm}
7243
7891
        DebugLn(['TMainIDE.CloseUnitComponent freeing component and designer: ',AnUnitInfo.Filename,' ',DbgSName(AnUnitInfo.Component)]);
7244
7892
        {$ENDIF}
7245
7893
        try
7246
 
          AnUnitInfo.LoadedDesigner:=false;
7247
 
          OldDesigner.FreeDesigner(true);
 
7894
          FreeDesigner(AnUnitInfo, OldDesigner, true);
7248
7895
        finally
7249
7896
          AnUnitInfo.Component:=nil;
7250
7897
        end;
7336
7983
  //DebugLn(['TMainIDE.UnitComponentIsUsed ',AnUnitInfo.Filename,' ',dbgs(AnUnitInfo.Flags)]);
7337
7984
end;
7338
7985
 
 
7986
function TMainIDE.RemoveFilesFromProject(AProject: TProject; UnitInfos: TFPList
 
7987
  ): TModalResult;
 
7988
var
 
7989
  i: Integer;
 
7990
  AnUnitInfo: TUnitInfo;
 
7991
  ShortUnitName: String;
 
7992
  Dummy: Boolean;
 
7993
  ObsoleteUnitPaths: String;
 
7994
  ObsoleteIncPaths: String;
 
7995
  p: Integer;
 
7996
  ProjUnitPaths: String;
 
7997
  CurDir: String;
 
7998
  ResolvedDir: String;
 
7999
  OldP: LongInt;
 
8000
  ProjIncPaths: String;
 
8001
begin
 
8002
  Result:=mrOk;
 
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);
 
8008
  // check ToolStatus
 
8009
  if (ToolStatus in [itCodeTools,itCodeToolAborting]) then begin
 
8010
    debugln('TMainIDE.RemoveUnitsFromProject wrong ToolStatus ',dbgs(ord(ToolStatus)));
 
8011
    exit;
 
8012
  end;
 
8013
  // commit changes from source editor to codetools
 
8014
  SaveSourceEditorChangesToCodeCache(nil);
 
8015
 
 
8016
  ObsoleteUnitPaths:='';
 
8017
  ObsoleteIncPaths:='';
 
8018
  AProject.BeginUpdate(true);
 
8019
  try
 
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)
 
8033
        then begin
 
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;
 
8041
              Result:=mrCancel;
 
8042
              exit;
 
8043
            end;
 
8044
          end;
 
8045
        end;
 
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;
 
8054
            Result:=mrCancel;
 
8055
            exit;
 
8056
          end;
 
8057
        end;
 
8058
      end;
 
8059
      if CompareFileExt(AnUnitInfo.Filename,'.inc',false)=0 then begin
 
8060
        // include file
 
8061
        if FilenameIsAbsolute(AnUnitInfo.Filename) then
 
8062
          ObsoleteIncPaths:=MergeSearchPaths(ObsoleteIncPaths,
 
8063
                        ChompPathDelim(ExtractFilePath(AnUnitInfo.Filename)));
 
8064
      end;
 
8065
    end;
 
8066
 
 
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)));
 
8077
      end;
 
8078
      AnUnitInfo:=AnUnitInfo.NextPartOfProject;
 
8079
    end;
 
8080
 
 
8081
    // check if compiler options contain paths of ObsoleteUnitPaths
 
8082
    if ObsoleteUnitPaths<>'' then begin
 
8083
      ProjUnitPaths:=AProject.CompilerOptions.OtherUnitFiles;
 
8084
      p:=1;
 
8085
      repeat
 
8086
        OldP:=p;
 
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
 
8096
          then begin
 
8097
            // remove
 
8098
            ProjUnitPaths:=RemoveSearchPaths(ProjUnitPaths,CurDir);
 
8099
            p:=OldP;
 
8100
          end;
 
8101
        end;
 
8102
      until false;
 
8103
      AProject.CompilerOptions.OtherUnitFiles:=ProjUnitPaths;
 
8104
    end;
 
8105
 
 
8106
    // check if compiler options contain paths of ObsoleteIncPaths
 
8107
    if ObsoleteIncPaths<>'' then begin
 
8108
      ProjIncPaths:=AProject.CompilerOptions.IncludePath;
 
8109
      p:=1;
 
8110
      repeat
 
8111
        OldP:=p;
 
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
 
8121
          then begin
 
8122
            // remove
 
8123
            ProjIncPaths:=RemoveSearchPaths(ProjIncPaths,CurDir);
 
8124
            p:=OldP;
 
8125
          end;
 
8126
        end;
 
8127
      until false;
 
8128
      AProject.CompilerOptions.IncludePath:=ProjIncPaths;
 
8129
    end;
 
8130
 
 
8131
  finally
 
8132
    ApplyCodeToolChanges;
 
8133
    AProject.EndUpdate;
 
8134
  end;
 
8135
end;
 
8136
 
7339
8137
function TMainIDE.GetAncestorUnit(AnUnitInfo: TUnitInfo): TUnitInfo;
7340
8138
begin
7341
8139
  if (AnUnitInfo=nil) or (AnUnitInfo.Component=nil) then
7369
8167
  MainIDEBar.itmFileSave.Enabled :=
7370
8168
    ((SrcEdit<>nil) and SrcEdit.Modified)
7371
8169
    or ((AnUnitInfo<>nil) and (AnUnitInfo.IsVirtual));
 
8170
  MainIDEBar.itmFileExportHtml.Enabled := (SrcEdit<>nil);
7372
8171
  if UpdateSaveAll then
7373
8172
    MainIDEBar.itmFileSaveAll.Enabled := MainIDEBar.itmProjectSave.Enabled;
7374
8173
  // toolbar buttons
7556
8355
      if UpdateModified and MainUnitSrcEdit.Modified
7557
8356
      then begin
7558
8357
        MainUnitSrcEdit.UpdateCodeBuffer;
7559
 
        MainUnitInfo.Modified:=true;
7560
8358
      end;
7561
8359
    end;
7562
8360
  end else
7576
8374
 
7577
8375
procedure TMainIDE.SaveSourceEditorProjectSpecificSettings;
7578
8376
var
7579
 
  AnEditorInfo: TUnitEditorInfo;
7580
8377
  i: Integer;
7581
8378
begin
7582
 
  for i := 0 to Project1.EditorInfoCount - 1 do begin
7583
 
    AnEditorInfo := Project1.EditorInfo[i];
7584
 
    if (AnEditorInfo.EditorComponent <> nil) then
7585
 
      SaveSrcEditorProjectSpecificSettings(AnEditorInfo);
7586
 
  end;
 
8379
  for i := 0 to Project1.AllEditorsInfoCount - 1 do
 
8380
    SaveSrcEditorProjectSpecificSettings(Project1.AllEditorsInfo[i]);
7587
8381
end;
7588
8382
 
7589
8383
function TMainIDE.DoShowSaveProjectAsDialog(UseMainSourceFile: boolean): TModalResult;
7619
8413
      if AFilename='' then
7620
8414
        AFilename:=ExtractFileName(Project1.MainFilename);
7621
8415
      if AFilename='' then
7622
 
        AFilename:=Trim(Project1.Title);
 
8416
        AFilename:=Trim(Project1.GetTitle);
7623
8417
      if AFilename='' then
7624
8418
        AFilename:='project1';
7625
8419
      Ext := LowerCase(ExtractFileExt(AFilename));
7633
8427
          AFilename := ChangeFileExt(AFilename, '.lpi');
7634
8428
      end;
7635
8429
      Ext := ExtractFileExt(AFilename);
7636
 
      SaveDialog.Title := Format(lisSaveProject, [Project1.Title, Ext]);
 
8430
      SaveDialog.Title := Format(lisSaveProject, [Project1.GetTitleOrName, Ext]);
7637
8431
      SaveDialog.FileName := AFilename;
7638
8432
      SaveDialog.Filter := '*' + Ext + '|' + '*' + Ext;
7639
8433
      SaveDialog.DefaultExt := ExtractFileExt(AFilename);
7657
8451
 
7658
8452
        // check program name
7659
8453
        NewProgramName:=ExtractFileNameOnly(AFilename);
7660
 
        if (NewProgramName='') or (not IsValidIdent(NewProgramName)) then begin
7661
 
          Result:=MessageDlg(lisInvalidProjectFilename,
 
8454
        if (NewProgramName='') or (not IsValidUnitName(NewProgramName)) then begin
 
8455
          Result:=IDEMessageDialog(lisInvalidProjectFilename,
7662
8456
            Format(lisisAnInvalidProjectNamePleaseChooseAnotherEGProject, ['"',
7663
8457
              SaveDialog.Filename, '"', #13]),
7664
 
            mtInformation,[mbRetry,mbAbort],0);
 
8458
            mtInformation,[mbRetry,mbAbort]);
7665
8459
          if Result=mrAbort then exit;
7666
8460
          continue; // try again
7667
8461
        end;
7695
8489
            ACaption:=lisChooseADifferentName;
7696
8490
            AText:=Format(lisTheProjectInfoFileIsEqualToTheProjectMainSource, [
7697
8491
              '"', NewLPIFilename, '"', #13]);
7698
 
            Result:=MessageDlg(ACaption, AText, mtError, [mbAbort,mbRetry],0);
 
8492
            Result:=IDEMessageDialog(ACaption, AText, mtError, [mbAbort,mbRetry]);
7699
8493
            if Result=mrAbort then exit;
7700
8494
            continue; // try again
7701
8495
          end;
7707
8501
            ACaption:=lisUnitIdentifierExists;
7708
8502
            AText:=Format(lisThereIsAUnitWithTheNameInTheProjectPleaseChoose, ['"',
7709
8503
              NewProgramName, '"', #13]);
7710
 
            Result:=MessageDlg(ACaption,AText,mtError,[mbRetry,mbAbort],0);
 
8504
            Result:=IDEMessageDialog(ACaption,AText,mtError,[mbRetry,mbAbort]);
7711
8505
            if Result=mrAbort then exit;
7712
8506
            continue; // try again
7713
8507
          end;
7729
8523
    begin
7730
8524
      ACaption:=lisOverwriteFile;
7731
8525
      AText:=Format(lisAFileAlreadyExistsReplaceIt, ['"', NewLPIFilename, '"', #13]);
7732
 
      Result:=MessageDlg(ACaption, AText, mtConfirmation, [mbOk, mbCancel], 0);
 
8526
      Result:=IDEMessageDialog(ACaption, AText, mtConfirmation, [mbOk, mbCancel]);
7733
8527
      if Result=mrCancel then exit;
7734
8528
    end
7735
8529
    else
7739
8533
        ACaption:=lisOverwriteFile;
7740
8534
        AText:=Format(lisAFileAlreadyExistsReplaceIt, ['"', NewProgramFilename,
7741
8535
          '"', #13]);
7742
 
        Result:=MessageDlg(ACaption, AText, mtConfirmation,[mbOk,mbCancel],0);
 
8536
        Result:=IDEMessageDialog(ACaption, AText, mtConfirmation,[mbOk,mbCancel]);
7743
8537
        if Result=mrCancel then exit;
7744
8538
      end;
7745
8539
    end;
7770
8564
    begin
7771
8565
      GetMainUnit(MainUnitInfo, MainUnitSrcEdit, true);
7772
8566
 
7773
 
      if not Project1.Resources.RenameDirectives(MainUnitInfo.Filename,NewProgramFilename)
 
8567
      if not Project1.ProjResources.RenameDirectives(MainUnitInfo.Filename,NewProgramFilename)
7774
8568
      then begin
7775
8569
        DebugLn(['TMainIDE.DoShowSaveProjectAsDialog failed renaming directives Old="',MainUnitInfo.Filename,'" New="',NewProgramFilename,'"']);
7776
8570
        // silently ignore
7783
8577
      // switch MainUnitInfo.Source to new code
7784
8578
      NewBuf := CodeToolBoss.CreateFile(NewProgramFilename);
7785
8579
      if NewBuf=nil then begin
7786
 
        Result:=MessageDlg(lisErrorCreatingFile, Format(lisUnableToCreateFile3, [
7787
 
          #13, '"', NewProgramFilename, '"']), mtError, [mbCancel], 0);
 
8580
        Result:=IDEMessageDialog(lisErrorCreatingFile, Format(lisUnableToCreateFile3, [
 
8581
          #13, '"', NewProgramFilename, '"']), mtError, [mbCancel]);
7788
8582
        exit;
7789
8583
      end;
7790
8584
 
7839
8633
  //DebugLn(['TMainIDE.DoShowSaveProjectAsDialog END OK']);
7840
8634
end;
7841
8635
 
 
8636
function TMainIDE.AskSaveProject(const ContinueText, ContinueBtn: string): TModalResult;
 
8637
var
 
8638
  DataModified: Boolean;
 
8639
  SrcModified: Boolean;
 
8640
begin
 
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);
 
8644
 
 
8645
  DataModified:=Project1.SomeDataModified(false);
 
8646
  SrcModified:=SourceEditorManager.SomethingModified(false);
 
8647
 
 
8648
  if Project1.IsVirtual
 
8649
  and (not DataModified)
 
8650
  and (not SrcModified) then begin
 
8651
    // only session changed of a new project => ignore
 
8652
    exit(mrOk)
 
8653
  end;
 
8654
 
 
8655
  if (Project1.SessionStorage=pssInProjectInfo)
 
8656
  or DataModified
 
8657
  then begin
 
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);
 
8664
  end
 
8665
  else if SrcModified then
 
8666
  begin
 
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);
 
8672
  end
 
8673
  else begin
 
8674
    // only session data changed
 
8675
    if Project1.SessionStorage=pssNone then
 
8676
      // session is not saved => skip
 
8677
      exit(mrOk)
 
8678
    else if not SomethingOfProjectIsModified then
 
8679
      // no change
 
8680
      exit(mrOk)
 
8681
    else begin
 
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);
 
8689
      end;
 
8690
    end;
 
8691
  end;
 
8692
  Result:=DoSaveProject([sfCanAbort]);
 
8693
  if Result=mrAbort then exit;
 
8694
  if Result<>mrOk then begin
 
8695
    Result:=IDEQuestionDialog(lisChangesWereNotSaved,
 
8696
      ContinueText,
 
8697
      mtConfirmation, [mrOk, ContinueBtn, mrAbort]);
 
8698
    if Result<>mrOk then exit(mrCancel);
 
8699
  end;
 
8700
end;
 
8701
 
7842
8702
function TMainIDE.DoCompleteLoadingProjectInfo: TModalResult;
7843
8703
begin
7844
8704
  UpdateCaption;
7845
8705
  EnvironmentOptions.LastSavedProjectFile:=Project1.ProjectInfoFile;
7846
 
  EnvironmentOptions.Save(false);
 
8706
  SaveEnvironment;
7847
8707
 
7848
 
  MainBuildBoss.RescanCompilerDefines(true,false,false);
 
8708
  MainBuildBoss.SetBuildTargetProject1(false);
7849
8709
 
7850
8710
  // load required packages
7851
8711
  PkgBoss.OpenProjectDependencies(Project1,true);
7857
8717
  Result:=mrOk;
7858
8718
end;
7859
8719
 
7860
 
procedure TMainIDE.OnCopyFile(const Filename: string; var Copy: boolean;
7861
 
  Data: TObject);
 
8720
procedure TMainIDE.OnCopyFile(const Filename: string; var Copy: boolean; Data: TObject);
7862
8721
begin
7863
8722
  if Data=nil then exit;
7864
8723
  if Data is TPublishModuleOptions then begin
7872
8731
begin
7873
8732
  case ErrorData.Error of
7874
8733
    ceSrcDirDoesNotExists:
7875
 
      MessageDlg(lisCopyError2,
 
8734
      IDEMessageDialog(lisCopyError2,
7876
8735
        Format(lisSourceDirectoryDoesNotExist, ['"', ErrorData.Param1, '"']),
7877
 
        mtError,[mbCancel],0);
 
8736
        mtError,[mbCancel]);
7878
8737
    ceCreatingDirectory:
7879
 
      MessageDlg(lisCopyError2,
 
8738
      IDEMessageDialog(lisCopyError2,
7880
8739
        Format(lisUnableToCreateDirectory, ['"', ErrorData.Param1, '"']),
7881
 
        mtError,[mbCancel],0);
 
8740
        mtError,[mbCancel]);
7882
8741
    ceCopyFileError:
7883
 
      MessageDlg(lisCopyError2,
 
8742
      IDEMessageDialog(lisCopyError2,
7884
8743
        Format(lisUnableToCopyFileTo, ['"', ErrorData.Param1, '"', #13, '"',
7885
8744
          ErrorData.Param1, '"']),
7886
 
        mtError,[mbCancel],0);
 
8745
        mtError,[mbCancel]);
7887
8746
  end;
7888
8747
end;
7889
8748
 
7970
8829
    try
7971
8830
      NewSrcEdit.EditorComponent.FoldState := FoldState;
7972
8831
    except
7973
 
      MessageDlg(lisError, lisFailedToLoadFoldStat, mtError, [mbOK], 0);
 
8832
      IDEMessageDialog(lisError, lisFailedToLoadFoldStat, mtError, [mbOK]);
7974
8833
    end;
7975
8834
 
7976
8835
    NewSrcEdit.EditorComponent.CaretXY:=NewCaretXY;
8000
8859
end;
8001
8860
 
8002
8861
function TMainIDE.DoNewFile(NewFileDescriptor: TProjectFileDescriptor;
8003
 
  var NewFilename: string; const NewSource: string;
 
8862
  var NewFilename: string; NewSource: string;
8004
8863
  NewFlags: TNewFlags; NewOwner: TObject): TModalResult;
8005
8864
 
8006
8865
  function BeautifySrc(const s: string): string;
8026
8885
  SrcNoteBook: TSourceNotebook;
8027
8886
  AShareEditor: TSourceEditor;
8028
8887
  DisableAutoSize: Boolean;
 
8888
  APackage: TLazPackage;
 
8889
  IsPartOfProject: Boolean;
 
8890
  RequiredPackages: String;
8029
8891
begin
8030
8892
  //debugln('TMainIDE.DoNewEditorFile A NewFilename=',NewFilename);
8031
8893
  // empty NewFilename is ok, it will be auto generated
8039
8901
    end;
8040
8902
  end;
8041
8903
 
 
8904
  Result:=NewFileDescriptor.Init(NewFilename,NewOwner,NewSource,nfQuiet in NewFlags);
 
8905
  if Result<>mrOk then exit;
 
8906
 
 
8907
  if FilenameIsAbsolute(NewFilename) and DirectoryExistsUTF8(NewFilename) then
 
8908
  begin
 
8909
    IDEMessageDialog(lisFileIsDirectory,
 
8910
      lisUnableToCreateNewFileBecauseThereIsAlreadyADirecto,
 
8911
      mtError,[mbCancel]);
 
8912
    exit(mrCancel);
 
8913
  end;
 
8914
 
8042
8915
  if NewOwner is TProject then
8043
8916
    AProject:=TProject(NewOwner)
8044
8917
  else
8045
8918
    AProject:=Project1;
 
8919
  if NewOwner is TLazPackage then
 
8920
    APackage:=TLazPackage(NewOwner)
 
8921
  else
 
8922
    APackage:=nil;
 
8923
 
 
8924
  OldUnitIndex:=AProject.IndexOfFilename(NewFilename);
 
8925
  if OldUnitIndex>=0 then begin
 
8926
    // the file is not really new
 
8927
    // => close form
 
8928
    Result:=CloseUnitComponent(AProject.Units[OldUnitIndex],
 
8929
                               [cfCloseDependencies,cfSaveDependencies]);
 
8930
    if Result<>mrOk then
 
8931
    begin
 
8932
      debugln(['TMainIDE.DoNewFile CloseUnitComponent failed']);
 
8933
      exit;
 
8934
    end;
 
8935
  end;
 
8936
 
 
8937
  IsPartOfProject:=(nfIsPartOfProject in NewFlags)
 
8938
                   or (NewOwner is TProject)
 
8939
                   or (AProject.FileIsInProjectDir(NewFilename)
 
8940
                       and (not (nfIsNotPartOfProject in NewFlags)));
 
8941
 
 
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
 
8946
  begin
 
8947
    if (NewFileDescriptor.ResourceClass.InheritsFrom(TForm))
 
8948
    or (NewFileDescriptor.ResourceClass.InheritsFrom(TFrame)) then
 
8949
      RequiredPackages:='LCL';
 
8950
  end;
 
8951
  if RequiredPackages<>'' then
 
8952
  begin
 
8953
    if IsPartOfProject then begin
 
8954
      Result:=PkgBoss.AddProjectDependencies(Project1,RequiredPackages);
 
8955
      if Result<>mrOk then
 
8956
      begin
 
8957
        debugln(['TMainIDE.DoNewFile PkgBoss.AddProjectDependencies failed RequiredPackages="',RequiredPackages,'"']);
 
8958
        exit;
 
8959
      end;
 
8960
    end;
 
8961
    if APackage<>nil then
 
8962
    begin
 
8963
      Result:=PkgBoss.AddPackageDependency(APackage,RequiredPackages);
 
8964
      if Result<>mrOk then
 
8965
      begin
 
8966
        debugln(['TMainIDE.DoNewFile PkgBoss.AddPackageDependency failed RequiredPackages="',RequiredPackages,'"']);
 
8967
        exit;
 
8968
      end;
 
8969
    end;
 
8970
  end;
 
8971
 
 
8972
  // check if the new file fits
 
8973
  Result:=NewFileDescriptor.CheckOwner(nfQuiet in NewFlags);
 
8974
  if Result<>mrOk then
 
8975
  begin
 
8976
    debugln(['TMainIDE.DoNewFile NewFileDescriptor.CheckOwner failed NewFilename="',NewFilename,'"']);
 
8977
    exit;
 
8978
  end;
8046
8979
 
8047
8980
  // create new codebuffer and apply naming conventions
 
8981
  NewBuffer:=nil;
 
8982
  NewUnitName:='';
8048
8983
  Result:=CreateNewCodeBuffer(NewFileDescriptor,NewOwner,NewFilename,NewBuffer,
8049
8984
                              NewUnitName);
8050
 
  if Result<>mrOk then exit;
8051
 
 
 
8985
  if Result<>mrOk then
 
8986
  begin
 
8987
    debugln(['TMainIDE.DoNewFile CreateNewCodeBuffer failed NewFilename="',NewFilename,'"']);
 
8988
    exit;
 
8989
  end;
8052
8990
  NewFilename:=NewBuffer.Filename;
8053
 
  OldUnitIndex:=AProject.IndexOfFilename(NewFilename);
 
8991
 
8054
8992
  if OldUnitIndex>=0 then begin
8055
8993
    // the file is not really new
8056
8994
    NewUnitInfo:=AProject.Units[OldUnitIndex];
8057
 
    // close form
8058
 
    Result:=CloseUnitComponent(NewUnitInfo,
8059
 
                               [cfCloseDependencies,cfSaveDependencies]);
8060
 
    if Result<>mrOk then exit;
8061
8995
    // assign source
8062
8996
    NewUnitInfo.Source:=NewBuffer;
8063
8997
  end else
8071
9005
  //debugln('TMainIDE.DoNewEditorFile A nfCreateDefaultSrc=',nfCreateDefaultSrc in NewFlags,' ResourceClass=',dbgs(NewFileDescriptor.ResourceClass));
8072
9006
  if nfCreateDefaultSrc in NewFlags then begin
8073
9007
    if (NewFileDescriptor.ResourceClass<>nil) then begin
8074
 
      NewUnitInfo.ComponentName:=
8075
 
        AProject.NewUniqueComponentName(NewFileDescriptor.DefaultResourceName);
 
9008
      NewUnitInfo.ComponentName:=NewUniqueComponentName(
 
9009
                                         NewFileDescriptor.DefaultResourceName);
8076
9010
      NewUnitInfo.ComponentResourceName:='';
8077
9011
    end;
8078
9012
    NewUnitInfo.CreateStartCode(NewFileDescriptor,NewUnitName);
8085
9019
  end;
8086
9020
 
8087
9021
  // add to project
8088
 
  with NewUnitInfo do begin
8089
 
    Loaded:=true;
8090
 
    IsPartOfProject:=(nfIsPartOfProject in NewFlags)
8091
 
                     or (NewOwner is TProject)
8092
 
                     or (AProject.FileIsInProjectDir(NewFilename)
8093
 
                         and (not (nfIsNotPartOfProject in NewFlags)));
8094
 
  end;
 
9022
  NewUnitInfo.Loaded:=true;
 
9023
  NewUnitInfo.IsPartOfProject:=IsPartOfProject;
8095
9024
  if OldUnitIndex<0 then begin
8096
 
    Project1.AddFile(NewUnitInfo,
 
9025
    AProject.AddFile(NewUnitInfo,
8097
9026
                     NewFileDescriptor.AddToProject
8098
9027
                     and NewFileDescriptor.IsPascalUnit
8099
9028
                     and NewUnitInfo.IsPartOfProject
8100
 
                     and (pfMainUnitHasUsesSectionForAllUnits in Project1.Flags));
 
9029
                     and (pfMainUnitHasUsesSectionForAllUnits in AProject.Flags));
8101
9030
  end;
8102
9031
 
8103
9032
  // syntax highlighter type
8104
9033
  NewUnitInfo.DefaultSyntaxHighlighter := FilenameToLazSyntaxHighlighter(NewFilename);
8105
9034
 
8106
 
  // required packages
8107
 
  if NewUnitInfo.IsPartOfProject and (NewFileDescriptor.RequiredPackages<>'')
8108
 
  then begin
8109
 
    if PkgBoss.AddProjectDependencies(Project1,NewFileDescriptor.RequiredPackages
8110
 
      )<>mrOk then exit;
8111
 
  end;
8112
 
 
8113
9035
  if nfOpenInEditor in NewFlags then begin
8114
9036
    // open a new sourceeditor
8115
9037
    SrcNoteBook := SourceEditorManager.ActiveOrNewSourceWindow;
8149
9071
        if (NewUnitInfo.Component<>nil)
8150
9072
        and NewFileDescriptor.UseCreateFormStatements
8151
9073
        and NewUnitInfo.IsPartOfProject
8152
 
        and Project1.AutoCreateForms
8153
 
        and (pfMainUnitHasCreateFormStatements in Project1.Flags) then
 
9074
        and AProject.AutoCreateForms
 
9075
        and (pfMainUnitHasCreateFormStatements in AProject.Flags) then
8154
9076
        begin
8155
 
          Project1.AddCreateFormToProjectFile(NewUnitInfo.Component.ClassName,
 
9077
          AProject.AddCreateFormToProjectFile(NewUnitInfo.Component.ClassName,
8156
9078
                                              NewUnitInfo.Component.Name);
8157
9079
        end;
8158
9080
      end else begin
8166
9088
        and (NewUnitInfo.Component is TControl) then
8167
9089
          TControl(NewUnitInfo.Component).EnableAutoSizing;
8168
9090
      end;
8169
 
      if Result<>mrOk then exit;
 
9091
      if Result<>mrOk then
 
9092
      begin
 
9093
        debugln(['TMainIDE.DoNewFile create designer form failed ',NewUnitInfo.Filename]);
 
9094
        exit;
 
9095
      end;
8170
9096
    end;
8171
9097
 
8172
9098
    // show form and select form
8173
9099
    if NewUnitInfo.Component<>nil then begin
8174
9100
      // show form
 
9101
      CreateObjectInspector;
8175
9102
      DoShowDesignerFormOfCurrentSrc;
8176
9103
    end else begin
8177
9104
      FDisplayState:= dsSource;
8200
9127
    // save and ask for filename
8201
9128
    NewUnitInfo.Modified:=true;
8202
9129
    Result:=DoSaveEditorFile(NewSrcEdit,[sfCheckAmbiguousFiles,sfSaveAs]);
8203
 
    if Result<>mrOk then exit;
 
9130
    if Result<>mrOk then
 
9131
    begin
 
9132
      debugln(['TMainIDE.DoNewFile DoSaveEditorFile failed ',NewFilename]);
 
9133
      exit;
 
9134
    end;
8204
9135
  end else if nfSave in NewFlags then begin
8205
9136
    if (nfOpenInEditor in NewFlags) or NewBuffer.IsVirtual then begin
8206
9137
      // save and ask for filename if needed
8207
9138
      NewUnitInfo.Modified:=true;
8208
9139
      Result:=DoSaveEditorFile(NewSrcEdit,[sfCheckAmbiguousFiles]);
8209
 
      if Result<>mrOk then exit;
 
9140
      if Result<>mrOk then
 
9141
      begin
 
9142
        debugln(['TMainIDE.DoNewFile DoSaveEditorFile SaveAs failed ',NewFilename]);
 
9143
        exit;
 
9144
      end;
8210
9145
    end else begin
8211
 
      // save quiet
 
9146
      // save quietly
8212
9147
      NewBuffer.Save;
8213
9148
    end;
8214
9149
  end;
8221
9156
function TMainIDE.DoNewOther: TModalResult;
8222
9157
var
8223
9158
  NewIDEItem: TNewIDEItemTemplate;
 
9159
  NewFile: TNewItemProjectFile;
8224
9160
begin
8225
9161
  Result:=ShowNewIDEItemDialog(NewIDEItem);
8226
9162
  if Result<>mrOk then exit;
8227
9163
  if NewIDEItem is TNewItemProjectFile then begin
8228
9164
    // file
8229
 
    if TNewItemProjectFile(NewIDEItem).Descriptor<>nil then
8230
 
      TNewItemProjectFile(NewIDEItem).Descriptor.Owner:=Project1;
 
9165
    NewFile:=TNewItemProjectFile(NewIDEItem);
 
9166
    if NewFile.Descriptor<>nil then
 
9167
      NewFile.Descriptor.Owner:=Project1;
8231
9168
    try
8232
 
      Result:=DoNewEditorFile(TNewItemProjectFile(NewIDEItem).Descriptor,
 
9169
      Result:=DoNewEditorFile(NewFile.Descriptor,
8233
9170
                                     '','',[nfOpenInEditor,nfCreateDefaultSrc]);
8234
9171
    finally
8235
 
      if TNewItemProjectFile(NewIDEItem).Descriptor<>nil then
8236
 
        TNewItemProjectFile(NewIDEItem).Descriptor.Owner:=nil;
 
9172
      if NewFile.Descriptor<>nil then
 
9173
        NewFile.Descriptor.Owner:=nil;
8237
9174
    end;
8238
9175
  end else if NewIDEItem is TNewItemProject then begin
8239
9176
    // project
8243
9180
    // packages
8244
9181
    PkgBoss.DoNewPackage;
8245
9182
  end else begin
8246
 
    MessageDlg(ueNotImplCap,
 
9183
    IDEMessageDialog(ueNotImplCap,
8247
9184
               lisSorryThisTypeIsNotYetImplemented,
8248
 
      mtInformation,[mbOk],0);
8249
 
  end;
8250
 
end;
8251
 
 
8252
 
function TMainIDE.DoSaveEditorFile(PageIndex:integer;
8253
 
  Flags: TSaveFlags):TModalResult;
 
9185
      mtInformation,[mbOk]);
 
9186
  end;
 
9187
end;
 
9188
 
 
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'
 
9195
var
 
9196
  i: Integer;
 
9197
  SrcEdit: TSourceEditor;
 
9198
  Ext: String;
 
9199
begin
 
9200
  AllMask:='|'+TFileDialog.ExtractAllFilterMasks(Filter);
 
9201
  AllEditorMask:='|';
 
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
 
9206
      Ext:='*'+Ext;
 
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;
 
9212
    end;
 
9213
  end;
 
9214
  System.Delete(AllMask,1,1);
 
9215
  System.Delete(AllEditorMask,1,1);
 
9216
  if AllEditorMask<>'' then begin
 
9217
    if AllMask<>'' then
 
9218
      AllMask:=AllMask+';';
 
9219
    AllMask:=AllMask+AllEditorMask;
 
9220
  end;
 
9221
end;
 
9222
 
 
9223
function TMainIDE.DoSaveEditorFile(PageIndex:integer; Flags: TSaveFlags):TModalResult;
8254
9224
begin
8255
9225
  Result := DoSaveEditorFile(
8256
9226
    SourceEditorManager.ActiveSourceWindow.FindSourceEditorWithPageIndex(PageIndex),
8262
9232
var
8263
9233
  AnUnitInfo: TUnitInfo;
8264
9234
  TestFilename, DestFilename: string;
8265
 
  ResourceCode, LFMCode: TCodeBuffer;
 
9235
  LRSCode, LFMCode: TCodeBuffer;
8266
9236
  MainUnitInfo: TUnitInfo;
8267
9237
  OldUnitName: String;
8268
9238
  OldFilename: String;
8279
9249
  {$ENDIF}
8280
9250
  {$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.DoSaveEditorFile A');{$ENDIF}
8281
9251
  Result:=mrCancel;
8282
 
  if not (ToolStatus in [itNone,itDebugger]) then begin
8283
 
    Result:=mrAbort;
8284
 
    exit;
8285
 
  end;
 
9252
  if not (ToolStatus in [itNone,itDebugger]) then
 
9253
    exit(mrAbort);
8286
9254
  CanAbort:=[sfCanAbort,sfProjectSaving]*Flags<>[];
8287
9255
 
8288
 
  if AEditor=nil then exit;
 
9256
  if AEditor=nil then exit(mrCancel);
8289
9257
  AnUnitInfo := Project1.UnitWithEditorComponent(AEditor);
8290
 
  if AnUnitInfo=nil then exit;
 
9258
  if AnUnitInfo=nil then exit(mrCancel);
8291
9259
 
8292
 
  // check if the unit is currently reverting
8293
 
  if AnUnitInfo.IsReverting then begin
8294
 
    Result:=mrOk;
8295
 
    exit;
8296
 
  end;
 
9260
  // do not save a unit which is currently reverting
 
9261
  if AnUnitInfo.IsReverting then
 
9262
    exit(mrOk);
8297
9263
  WasVirtual:=AnUnitInfo.IsVirtual;
8298
9264
  WasPascalSource:=FilenameIsPascalSource(AnUnitInfo.Filename);
8299
9265
 
8300
 
  // check if file is writable on disk
8301
 
  if (not AnUnitInfo.IsVirtual)
8302
 
  and FileExistsUTF8(AnUnitInfo.Filename) then
8303
 
    AnUnitInfo.FileReadOnly:=not FileIsWritable(AnUnitInfo.Filename)
8304
 
  else
8305
 
    AnUnitInfo.FileReadOnly:=false;
8306
 
 
8307
9266
  // if this file is part of the project and the project is virtual then save
8308
9267
  // project first
8309
9268
  if (not (sfProjectSaving in Flags)) and Project1.IsVirtual
8338
9297
    exit;
8339
9298
  end;
8340
9299
 
8341
 
  // if file is readonly then a simple Save is skipped
8342
 
  if (AnUnitInfo.ReadOnly) and ([sfSaveToTestDir,sfSaveAs]*Flags=[]) then
8343
 
  begin
8344
 
    Result:=mrOk;
8345
 
    exit;
8346
 
  end;
8347
 
 
8348
9300
  // if nothing modified then a simple Save can be skipped
8349
 
  //writeln('TMainIDE.DoSaveEditorFile A ',AnUnitInfo.Filename,' ',AnUnitInfo.NeedsSaveToDisk);
 
9301
  //debugln(['TMainIDE.DoSaveEditorFile A ',AnUnitInfo.Filename,' ',AnUnitInfo.NeedsSaveToDisk]);
8350
9302
  if ([sfSaveToTestDir,sfSaveAs]*Flags=[])
8351
9303
  and (not AnUnitInfo.NeedsSaveToDisk) then
8352
9304
  begin
8355
9307
      AnUnitInfo.SessionModified:=true;
8356
9308
      AEditor.Modified:=false;
8357
9309
    end;
8358
 
    Result:=mrOk;
8359
 
    exit;
 
9310
    exit(mrOk);
8360
9311
  end;
8361
9312
 
 
9313
  // check if file is writable on disk
 
9314
  if (not AnUnitInfo.IsVirtual)
 
9315
  and FileExistsUTF8(AnUnitInfo.Filename) then
 
9316
    AnUnitInfo.FileReadOnly:=not FileIsWritable(AnUnitInfo.Filename)
 
9317
  else
 
9318
    AnUnitInfo.FileReadOnly:=false;
 
9319
 
 
9320
  // if file is readonly then a simple Save is skipped
 
9321
  if (AnUnitInfo.ReadOnly) and ([sfSaveToTestDir,sfSaveAs]*Flags=[]) then
 
9322
    exit(mrOk);
 
9323
 
8362
9324
  // load old resource file
8363
9325
  LFMCode:=nil;
8364
 
  ResourceCode:=nil;
 
9326
  LRSCode:=nil;
8365
9327
  if WasPascalSource then
8366
9328
  begin
8367
 
    Result:=DoLoadResourceFile(AnUnitInfo,LFMCode,ResourceCode,
 
9329
    Result:=DoLoadResourceFile(AnUnitInfo,LFMCode,LRSCode,
8368
9330
                               not (sfSaveAs in Flags),true,CanAbort);
8369
 
    if Result in [mrIgnore,mrOk] then
8370
 
      Result:=mrCancel
8371
 
    else
 
9331
    if not (Result in [mrIgnore,mrOk]) then
8372
9332
      exit;
8373
9333
  end;
8374
9334
 
8380
9340
  if [sfSaveAs,sfSaveToTestDir]*Flags=[sfSaveAs] then begin
8381
9341
    // let user choose a filename
8382
9342
    NewFilename:=OldFilename;
8383
 
    Result:=DoShowSaveFileAsDialog(NewFilename,AnUnitInfo,ResourceCode,CanAbort);
8384
 
    if Result in [mrIgnore,mrOk] then
8385
 
      Result:=mrCancel
8386
 
    else
 
9343
    Result:=DoShowSaveFileAsDialog(NewFilename,AnUnitInfo,LFMCode,LRSCode,CanAbort);
 
9344
    if not (Result in [mrIgnore,mrOk]) then
8387
9345
      exit;
8388
 
    LFMCode:=nil;
8389
9346
  end;
8390
9347
 
8391
9348
  // save source
8392
9349
 
8393
9350
  // a) do before save events
8394
 
  if EditorOpts.AutoRemoveEmptyMethods
8395
 
  and (AnUnitInfo.Component<>nil) then begin
 
9351
  if EditorOpts.AutoRemoveEmptyMethods and (AnUnitInfo.Component<>nil) then begin
8396
9352
    // Note: When removing published methods, the source, the lfm, the lrs
8397
9353
    //       and the form must be changed. At the moment editing the lfm without
8398
9354
    //       the component is not yet implemented.
8415
9371
      DestFilename := TestFilename;
8416
9372
    end
8417
9373
    else
8418
 
      exit;
 
9374
      exit(mrCancel);
8419
9375
  end else
8420
9376
  begin
8421
9377
    if AnUnitInfo.Modified or AnUnitInfo.NeedsSaveToDisk then
8423
9379
      // save source to file
8424
9380
      Result := AnUnitInfo.WriteUnitSource;
8425
9381
      if Result <> mrOK then
8426
 
        Exit;
 
9382
        exit;
8427
9383
      DestFilename := AnUnitInfo.Filename;
8428
9384
    end;
8429
9385
  end;
8436
9392
  {$ENDIF}
8437
9393
  {$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.DoSaveEditorFile B');{$ENDIF}
8438
9394
  // save resource file and lfm file
8439
 
  if (ResourceCode<>nil) or (AnUnitInfo.Component<>nil) then begin
8440
 
    Result:=DoSaveUnitComponent(AnUnitInfo,ResourceCode,LFMCode,Flags);
8441
 
    if Result in [mrIgnore, mrOk] then
8442
 
      Result:=mrCancel
8443
 
    else
 
9395
  if (LRSCode<>nil) or (AnUnitInfo.Component<>nil) then begin
 
9396
    Result:=DoSaveUnitComponent(AnUnitInfo,LRSCode,LFMCode,Flags);
 
9397
    if not (Result in [mrIgnore, mrOk]) then
8444
9398
      exit;
8445
9399
  end;
8446
9400
 
8461
9415
  and  ((OldUnitName<>NewUnitName)
8462
9416
        or (CompareFilenames(OldFilename,NewFilename)<>0))
8463
9417
  then begin
8464
 
    if EnvironmentOptions.UnitRenameReferencesAction=urraNever then
8465
 
      Result:=mrOK
8466
 
    else begin
 
9418
    if EnvironmentOptions.UnitRenameReferencesAction<>urraNever then
 
9419
    begin
8467
9420
      // silently update references of new units (references were auto created
8468
9421
      // and keeping old references makes no sense)
8469
9422
      Confirm:=(EnvironmentOptions.UnitRenameReferencesAction=urraAsk)
8470
9423
               and (not WasVirtual);
8471
9424
      Result:=DoReplaceUnitUse(OldFilename,OldUnitName,NewFilename,NewUnitName,
8472
9425
               true,true,Confirm);
 
9426
      if Result<>mrOk then exit;
8473
9427
    end;
8474
 
    if Result<>mrOk then exit;
8475
9428
  end;
8476
9429
 
8477
9430
  {$IFDEF IDE_VERBOSE}
8478
 
  writeln('TMainIDE.DoSaveEditorFile END');
 
9431
  debugln(['TMainIDE.DoSaveEditorFile END ',NewFilename,' AnUnitInfo.Modified=',AnUnitInfo.Modified,' AEditor.Modified=',AEditor.Modified]);
8479
9432
  {$ENDIF}
8480
9433
  Result:=mrOk;
8481
9434
end;
8516
9469
  SrcEdit: TSourceEditor;
8517
9470
begin
8518
9471
  {$IFDEF IDE_DEBUG}
8519
 
  debugln('TMainIDE.DoCloseEditorFile A PageIndex=',IntToStr(AnUnitInfo.PageIndex));
 
9472
  //debugln('TMainIDE.DoCloseEditorFile A PageIndex=',IntToStr(AnUnitInfo.PageIndex));
8520
9473
  {$ENDIF}
8521
9474
  Result:=mrCancel;
8522
9475
  if AEditor = nil then exit;
8538
9491
  try
8539
9492
    //debugln(['TMainIDE.DoCloseEditorFile File=',AnUnitInfo.Filename,' UnitSession=',AnUnitInfo.SessionModified,' ProjSession=',project1.SessionModified]);
8540
9493
    if AnUnitInfo.OpenEditorInfoCount > 1 then begin
 
9494
      // opened multiple times => close one instance
8541
9495
      SourceEditorManager.CloseFile(AEditor);
8542
9496
      Result:=mrOk;
8543
9497
      exit;
8544
9498
    end;
8545
9499
 
8546
 
    if (AnUnitInfo.Component<>nil)
8547
 
    and (FLastFormActivated<>nil)
8548
 
    and (TDesigner(FLastFormActivated.Designer).LookupRoot=AnUnitInfo.Component)
8549
 
    then
 
9500
    if (AnUnitInfo.Component<>nil) and (FLastFormActivated<>nil)
 
9501
    and (TDesigner(FLastFormActivated.Designer).LookupRoot=AnUnitInfo.Component) then
8550
9502
      FLastFormActivated:=nil;
8551
9503
 
8552
9504
    // save some meta data of the source
8565
9517
          AText:=Format(lisSourceOfPageHasChangedSave, ['"',
8566
9518
            TSourceEditor(AEditor).PageName, '"']);
8567
9519
        ACaption:=lisSourceModified;
8568
 
        Result:=QuestionDlg(ACaption, AText,
 
9520
        Result:=IDEQuestionDialog(ACaption, AText,
8569
9521
            mtConfirmation, [mrYes, lisMenuSave, mrNo, lisDiscardChanges, mrAbort
8570
 
              ], 0);
 
9522
              ]);
8571
9523
      end else
8572
9524
        Result:=mrYes;
8573
9525
      if Result=mrYes then begin
8593
9545
    MainIDEBar.itmFileClose.Enabled:=SourceEditorManager.SourceEditorCount > 0;
8594
9546
    MainIDEBar.itmFileCloseAll.Enabled:=MainIDEBar.itmFileClose.Enabled;
8595
9547
 
8596
 
    // free sources
 
9548
    // free sources, forget changes
8597
9549
    if (AnUnitInfo.Source<>nil) then begin
8598
9550
      if (Project1.MainUnitInfo=AnUnitInfo)
8599
9551
      and (not (cfProjectClosing in Flags)) then begin
8600
 
        // lpr file closed in editor, but project kept open -> revert lpr file
8601
 
        Project1.MainUnitInfo.Source.Revert;
8602
 
      end else
 
9552
        AnUnitInfo.Source.Revert;
 
9553
      end else begin
8603
9554
        AnUnitInfo.Source.IsDeleted:=true;
 
9555
      end;
8604
9556
    end;
8605
9557
 
8606
9558
    // close file in project
8607
9559
    AnUnitInfo.Loaded:=false;
8608
9560
    if AnUnitInfo<>Project1.MainUnitInfo then
8609
9561
      AnUnitInfo.Source:=nil;
8610
 
    i:=Project1.IndexOf(AnUnitInfo);
8611
 
    if (i<>Project1.MainUnitID) and (AnUnitInfo.IsVirtual) then begin
8612
 
      Project1.RemoveUnit(i);
 
9562
    if not (cfProjectClosing in Flags) then begin
 
9563
      i:=Project1.IndexOf(AnUnitInfo);
 
9564
      if (i<>Project1.MainUnitID) and AnUnitInfo.IsVirtual then begin
 
9565
        Project1.RemoveUnit(i);
 
9566
      end;
8613
9567
    end;
8614
9568
 
8615
9569
  finally
8647
9601
  ): TModalResult;
8648
9602
var
8649
9603
  UnitIndex: integer;
8650
 
  ReOpen, Handled:boolean;
 
9604
  UnknownFile, Handled: boolean;
8651
9605
  NewUnitInfo:TUnitInfo;
8652
9606
  NewBuf: TCodeBuffer;
8653
9607
  FilenameNoPath: String;
8723
9677
 
8724
9678
  // normalize filename
8725
9679
  AFilename:=TrimFilename(AFilename);
8726
 
  DiskFilename:=FindDiskFilename(AFilename);
 
9680
  DiskFilename:=CodeToolBoss.DirectoryCachePool.FindDiskFilename(AFilename);
8727
9681
  if DiskFilename<>AFilename then begin
8728
9682
    // the case is different
8729
 
    DebugLn(['TMainIDE.DoOpenEditorFile Fixing file case: ',AFilename,' -> ',DiskFilename]);
 
9683
    DebugLn(['TMainIDE.DoOpenEditorFile Fixing file name: ',AFilename,' -> ',DiskFilename]);
8730
9684
    AFilename:=DiskFilename;
8731
9685
  end;
8732
9686
 
8741
9695
    DebugLn(['TMainIDE.DoOpenEditorFile ignoring special file: ',AFilename]);
8742
9696
    exit;
8743
9697
  end;
 
9698
  if DirectoryExistsUTF8(AFileName) then begin
 
9699
    debugln(['TMainIDE.DoOpenEditorFile skipping directory ',AFileName]);
 
9700
    exit(mrCancel);
 
9701
  end;
8744
9702
 
8745
9703
  if ([ofAddToRecent,ofRevert,ofVirtualFile]*Flags=[ofAddToRecent])
8746
9704
  and (AFilename<>'') and FilenameIsAbsolute(AFilename) then
8763
9721
    // check if file is a lazarus project (.lpi)
8764
9722
    if (CompareFileExt(AFilename,'.lpi',false)=0) then begin
8765
9723
      case
8766
 
        QuestionDlg(
 
9724
        IDEQuestionDialog(
8767
9725
          lisOpenProject, Format(lisOpenTheProject, [AFilename]), mtConfirmation,
8768
 
          [mrYes, lisOpenProject2, mrNoToAll, lisOpenAsXmlFile, mrCancel], 0)
 
9726
          [mrYes, lisOpenProject2, mrNoToAll, lisOpenAsXmlFile, mrCancel])
8769
9727
      of
8770
9728
        mrYes: begin
8771
9729
          Result:=DoOpenProjectFile(AFilename,[ofAddToRecent]);
8779
9737
    // check if file is a lazarus package (.lpk)
8780
9738
    if (CompareFileExt(AFilename,'.lpk',false)=0) then begin
8781
9739
      case
8782
 
        QuestionDlg(
 
9740
        IDEQuestionDialog(
8783
9741
          lisOpenPackage, Format(lisOpenThePackage, [AFilename]), mtConfirmation,
8784
 
          [mrYes, lisCompPalOpenPackage, mrNoToAll, lisOpenAsXmlFile, mrCancel], 0)
 
9742
          [mrYes, lisCompPalOpenPackage, mrNoToAll, lisOpenAsXmlFile, mrCancel])
8785
9743
      of
8786
9744
        mrYes: begin
8787
9745
          Result:=PkgBoss.DoOpenPackageFile(AFilename,[pofAddToRecent],CanAbort);
8793
9751
  end;
8794
9752
 
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
8805
 
      else
8806
 
        NewEditorInfo := NewUnitInfo.EditorInfo[0];
8807
 
      if (ofAddToProject in Flags) and (not NewUnitInfo.IsPartOfProject) then
8808
 
      begin
8809
 
        NewUnitInfo.IsPartOfProject:=true;
8810
 
        Project1.Modified:=true;
8811
 
      end;
8812
 
      if (not (ofProjectLoading in Flags)) and (NewEditorInfo.EditorComponent <> nil) then
8813
 
      begin
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
8820
 
        else
8821
 
          Result:=mrOk;
8822
 
        exit;
8823
 
      end;
8824
 
    end;
8825
 
  end else begin
 
9754
  if (ofRevert in Flags) then begin
8826
9755
    // revert
 
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,
8835
9767
          '"']),
8836
 
          mtInformation,[mbCancel],0);
 
9768
          mtInformation,[mbCancel]);
8837
9769
      end;
8838
9770
      Result:=mrCancel;
8839
9771
      exit;
8840
9772
    end;
8841
 
    ReOpen:=true;
8842
 
    if (ofAddToProject in Flags) and (not NewUnitInfo.IsPartOfProject) then
8843
 
    begin
8844
 
      NewUnitInfo.IsPartOfProject:=true;
8845
 
      Project1.Modified:=true;
 
9773
  end else begin
 
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
 
9783
      else
 
9784
        NewEditorInfo := NewUnitInfo.EditorInfo[0];
8846
9785
    end;
8847
9786
  end;
8848
9787
 
 
9788
  if (NewEditorInfo <> nil) and (ofAddToProject in Flags) and (not NewUnitInfo.IsPartOfProject) then
 
9789
  begin
 
9790
    NewUnitInfo.IsPartOfProject:=true;
 
9791
    Project1.Modified:=true;
 
9792
  end;
 
9793
 
 
9794
  if (NewEditorInfo <> nil) and (Flags * [ofProjectLoading, ofRevert] = []) and (NewEditorInfo.EditorComponent <> nil) then
 
9795
  begin
 
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
 
9802
    else
 
9803
      Result:=mrOk;
 
9804
    exit;
 
9805
  end;
 
9806
 
8849
9807
  Reverting:=false;
8850
9808
  if ofRevert in Flags then begin
8851
9809
    Reverting:=true;
8859
9817
      if (ofRevert in Flags) then begin
8860
9818
        // revert failed, due to missing file
8861
9819
        if not (ofQuiet in Flags) then begin
8862
 
          MessageDlg(lisRevertFailed, Format(lisPkgMangFileNotFound, ['"',
 
9820
          IDEMessageDialog(lisRevertFailed, Format(lisPkgMangFileNotFound, ['"',
8863
9821
            AFilename, '"']),
8864
 
            mtError,[mbCancel],0);
 
9822
            mtError,[mbCancel]);
8865
9823
        end;
8866
9824
        Result:=mrCancel;
8867
9825
        exit;
8872
9830
    end;
8873
9831
 
8874
9832
    // load the source
8875
 
    if ReOpen then begin
 
9833
    if UnknownFile then begin
 
9834
      // open unknown file // Never happens if ofRevert
 
9835
      Handled:=false;
 
9836
      Result:=DoOpenUnknownFile(AFilename,Flags,NewUnitInfo,Handled);
 
9837
      if (Result<>mrOk) or Handled then exit;
 
9838
      // the file was previously unknown, use the default EditorInfo
 
9839
      if AEditorInfo <> nil then
 
9840
        NewEditorInfo := AEditorInfo
 
9841
      else
 
9842
      if NewUnitInfo <> nil then
 
9843
        NewEditorInfo := NewUnitInfo.GetClosedOrNewEditorInfo
 
9844
      else
 
9845
        NewEditorInfo := nil;
 
9846
    end else begin
8876
9847
      // project knows this file => all the meta data is known
8877
9848
      // -> just load the source
8878
9849
      NewUnitInfo:=Project1.Units[UnitIndex];
8893
9864
      if FilenameIsPascalUnit(NewUnitInfo.Filename) then
8894
9865
        NewUnitInfo.ReadUnitNameFromSource(false);
8895
9866
      NewUnitInfo.Modified:=NewUnitInfo.Source.FileOnDiskNeedsUpdate;
8896
 
    end else begin
8897
 
      // open unknown file
8898
 
      Handled:=false;
8899
 
      Result:=DoOpenUnknownFile(AFilename,Flags,NewUnitInfo,Handled);
8900
 
      if Result<>mrOk then exit;
8901
 
      // the file was previously unknown, use the default EditorInfo
8902
 
      if AEditorInfo <> nil then
8903
 
        NewEditorInfo := AEditorInfo
8904
 
      else
8905
 
      if NewUnitInfo <> nil then
8906
 
        NewEditorInfo := NewUnitInfo.GetClosedOrNewEditorInfo
8907
 
      else
8908
 
        NewEditorInfo := nil;
8909
 
      if Handled then exit;
8910
9867
    end;
8911
9868
 
8912
9869
    // check readonly
9028
9985
      end else if FilenameIsAbsolute(CurUnitInfo.Filename)
9029
9986
      and FilenameIsPascalSource(CurUnitInfo.Filename)
9030
9987
      and FileExistsCached(CurUnitInfo.Filename) then begin
 
9988
        // this unit has a lfm, but the lpi does not know a ComponentName
 
9989
        // => maybe this component was added without the IDE
9031
9990
        LFMFilename:=ChangeFileExt(CurUnitInfo.Filename,'.lfm');
9032
 
        if FileExistsCached(LFMFilename) then begin
9033
 
          if ReadLFMHeaderFromFile(LFMFilename,LFMType,LFMComponentName,LFMClassName)
9034
 
          then begin
9035
 
            anUnitName:=CurUnitInfo.Unit_Name;
9036
 
            if anUnitName='' then
9037
 
              anUnitName:=ExtractFileNameOnly(LFMFilename);
9038
 
            ItemList.AddObject(anUnitName,
9039
 
              TViewUnitsEntry.Create(LFMComponentName, i,
9040
 
                                     CurUnitInfo = ActiveUnitInfo));
9041
 
          end;
 
9991
        if FileExistsCached(LFMFilename)
 
9992
        and ReadLFMHeaderFromFile(LFMFilename,LFMType,LFMComponentName,LFMClassName)
 
9993
        then begin
 
9994
          anUnitName:=CurUnitInfo.Unit_Name;
 
9995
          if anUnitName='' then
 
9996
            anUnitName:=ExtractFileNameOnly(LFMFilename);
 
9997
          ItemList.AddObject(anUnitName,
 
9998
            TViewUnitsEntry.Create(LFMComponentName, i,
 
9999
                                   CurUnitInfo = ActiveUnitInfo));
9042
10000
        end;
9043
10001
      end;
9044
10002
    end else
9068
10026
    end;
9069
10027
  end;
9070
10028
  case ItemType of
9071
 
    piUnit: DlgCaption := dlgMainViewUnits;
 
10029
    piUnit:      DlgCaption := dlgMainViewUnits;
9072
10030
    piComponent: DlgCaption := dlgMainViewForms;
9073
 
    piFrame: DlgCaption := dlgMainViewFrames;
9074
 
  end;
9075
 
  Result := ShowViewUnitsDlg(ItemList, MultiSelect, MultiSelectCheckedState, DlgCaption);
 
10031
    piFrame:     DlgCaption := dlgMainViewFrames;
 
10032
  end;
 
10033
  Result := ShowViewUnitsDlg(ItemList, MultiSelect, MultiSelectCheckedState, DlgCaption, ItemType);
 
10034
end;
 
10035
 
 
10036
function TMainIDE.SelectUnitComponents(DlgCaption: string;
 
10037
  ItemType: TIDEProjectItem; Files: TStringList; MultiSelect: boolean;
 
10038
  var MultiSelectCheckedState: Boolean): TModalResult;
 
10039
var
 
10040
  ActiveSourceEditor: TSourceEditor;
 
10041
  ActiveUnitInfo: TUnitInfo;
 
10042
  UnitToFilename: TStringToStringTree;
 
10043
  UnitPath: String;
 
10044
 
 
10045
  function ResourceFits(ResourceBaseClass: TPFComponentBaseClass): boolean;
 
10046
  begin
 
10047
    case ItemType of
 
10048
    piUnit: Result:=true;
 
10049
    piComponent: Result:=ResourceBaseClass<>pfcbcNone;
 
10050
    piFrame: Result:=ResourceBaseClass=pfcbcFrame;
 
10051
    else Result:=false;
 
10052
    end;
 
10053
  end;
 
10054
 
 
10055
  function CheckLFMBaseClass(aFilename: string): TPFComponentBaseClass;
 
10056
  var
 
10057
    LFMFilename: String;
 
10058
    LFMType: String;
 
10059
    LFMComponentName: String;
 
10060
    LFMClassName: String;
 
10061
    Code: TCodeBuffer;
 
10062
    Tool: TCodeTool;
 
10063
    ClassNode: TCodeTreeNode;
 
10064
    ListOfPFindContext: TFPList;
 
10065
    i: Integer;
 
10066
    Context: PFindContext;
 
10067
    AClassName: String;
 
10068
  begin
 
10069
    Result:=pfcbcNone;
 
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)
 
10076
    then exit;
 
10077
    Code:=CodeToolBoss.LoadFile(aFilename,true,false);
 
10078
    if Code=nil then exit;
 
10079
    if not CodeToolBoss.Explore(Code,Tool,false,true) then exit;
 
10080
    try
 
10081
      ClassNode:=Tool.FindClassNodeInInterface(LFMClassName,true,false,false);
 
10082
      if ClassNode=nil then exit;
 
10083
      ListOfPFindContext:=nil;
 
10084
      try
 
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
 
10092
            exit(pfcbcFrame)
 
10093
          else if CompareText(AClassName,'TForm')=0 then
 
10094
            exit(pfcbcForm)
 
10095
          else if CompareText(AClassName,'TDataModule')=0 then
 
10096
            exit(pfcbcDataModule);
 
10097
        end;
 
10098
      finally
 
10099
        FreeListOfPFindContext(ListOfPFindContext);
 
10100
      end;
 
10101
    except
 
10102
    end;
 
10103
  end;
 
10104
 
 
10105
  procedure AddUnit(AnUnitName,AFilename: string);
 
10106
  var
 
10107
    LFMFilename: String;
 
10108
  begin
 
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
 
10117
    end else begin
 
10118
      //debugln(['AddUnit unitpath=',UnitPath]);
 
10119
      if SearchDirectoryInSearchPath(UnitPath,ExtractFilePath(AFilename))<1 then
 
10120
        exit; // not reachable
 
10121
    end;
 
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;
 
10127
  end;
 
10128
 
 
10129
  procedure AddPackage(Pkg: TLazPackage);
 
10130
  var
 
10131
    i: Integer;
 
10132
    PkgFile: TPkgFile;
 
10133
  begin
 
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;
 
10144
      end;
 
10145
      AddUnit(PkgFile.Unit_Name,PkgFile.Filename);
 
10146
    end;
 
10147
  end;
 
10148
 
 
10149
var
 
10150
  Owners: TFPList;
 
10151
  APackage: TLazPackage;
 
10152
  AProject: TProject;
 
10153
  AnUnitInfo: TUnitInfo;
 
10154
  FirstDependency: TPkgDependency;
 
10155
  PkgList: TFPList;
 
10156
  i: Integer;
 
10157
  S2SItem: PStringToStringTreeItem;
 
10158
  AnUnitName: String;
 
10159
  AFilename: String;
 
10160
  UnitList: TStringList;
 
10161
begin
 
10162
  Result:=mrCancel;
 
10163
  GetCurrentUnit(ActiveSourceEditor, ActiveUnitInfo);
 
10164
  if ActiveUnitInfo=nil then exit;
 
10165
  Owners:=PkgBoss.GetPossibleOwnersOfUnit(ActiveUnitInfo.Filename,[]);
 
10166
  UnitPath:=CodeToolBoss.GetCompleteSrcPathForDirectory(ExtractFilePath(ActiveUnitInfo.Filename));
 
10167
  PkgList:=nil;
 
10168
  UnitToFilename:=TStringToStringTree.Create(false);
 
10169
  UnitList:=TStringList.Create;
 
10170
  try
 
10171
    // fetch owner of active unit
 
10172
    AProject:=nil;
 
10173
    APackage:=nil;
 
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]);
 
10178
          break;
 
10179
        end else if TObject(Owners[i]) is TLazPackage then begin
 
10180
          APackage:=TLazPackage(Owners[i]);
 
10181
        end;
 
10182
      end;
 
10183
    end;
 
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='')
 
10192
        then continue;
 
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;
 
10198
        end;
 
10199
        AddUnit(AnUnitInfo.Unit_Name,AnUnitInfo.Filename);
 
10200
      end;
 
10201
    end else if APackage<>nil then begin
 
10202
      // add package units
 
10203
      FirstDependency:=APackage.FirstRequiredDependency;
 
10204
      AddPackage(APackage);
 
10205
    end;
 
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]));
 
10211
 
 
10212
    // create Files
 
10213
    i:=0;
 
10214
    for S2SItem in UnitToFilename do begin
 
10215
      AnUnitName:=S2SItem^.Name;
 
10216
      UnitList.AddObject(AnUnitName,TViewUnitsEntry.Create(AnUnitName,i,false));
 
10217
      inc(i);
 
10218
    end;
 
10219
    // show dialog
 
10220
    Result := ShowViewUnitsDlg(UnitList, MultiSelect, MultiSelectCheckedState, DlgCaption, ItemType);
 
10221
 
 
10222
    // create list of selected files
 
10223
    i:=0;
 
10224
    for S2SItem in UnitToFilename do begin
 
10225
      AFilename:=S2SItem^.Value;
 
10226
      if TViewUnitsEntry(UnitList.Objects[i]).Selected then
 
10227
        Files.Add(AFilename);
 
10228
      inc(i);
 
10229
    end;
 
10230
 
 
10231
  finally
 
10232
    for i := 0 to UnitList.Count-1 do
 
10233
      TViewUnitsEntry(UnitList.Objects[i]).Free;
 
10234
    UnitList.Free;
 
10235
    PkgList.Free;
 
10236
    Owners.Free;
 
10237
    UnitToFilename.Free;
 
10238
  end;
9076
10239
end;
9077
10240
 
9078
10241
function TMainIDE.DoSelectFrame: TComponentClass;
9079
10242
var
9080
10243
  UnitList: TStringList;
9081
 
  i: integer;
9082
 
  AnUnitInfo: TUnitInfo;
9083
 
  LFMCode: TCodeBuffer;
9084
 
  LFMFilename: String;
9085
 
  TheModalResult: TModalResult;
9086
10244
  dummy: Boolean;
 
10245
  i: Integer;
 
10246
  aFilename: String;
 
10247
  AComponent: TComponent;
9087
10248
begin
9088
10249
  Result := nil;
9089
10250
  UnitList := TStringList.Create;
9090
 
  UnitList.Sorted := True;
9091
10251
  try
9092
10252
    dummy := false;
9093
 
    if SelectProjectItems(UnitList, piFrame, false, dummy) = mrOk then
 
10253
    if SelectUnitComponents('Select Frame',piFrame,UnitList, false, dummy) <> mrOk
 
10254
    then
 
10255
      exit;
 
10256
    for i := 0 to UnitList.Count-1 do
9094
10257
    begin
9095
 
      { This is where we check what the user selected. }
9096
 
      AnUnitInfo := nil;
9097
 
      for i := 0 to UnitList.Count-1 do
9098
 
      begin
9099
 
        if TViewUnitsEntry(UnitList.Objects[i]).Selected then
9100
 
        begin
9101
 
          AnUnitInfo := Project1.Units[TViewUnitsEntry(UnitList.Objects[i]).ID];
9102
 
          if (AnUnitInfo.Component=nil) then begin
9103
 
            // load the frame
9104
 
            LFMFilename:=ChangeFileExt(AnUnitInfo.Filename,'.lfm');
9105
 
            if not FileExistsUTF8(LFMFilename) then begin
9106
 
              DebugLn(['TMainIDE.DoSelectFrame file not found: ',LFMFilename]);
9107
 
              exit;
9108
 
            end;
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);
9113
 
              exit;
9114
 
            end;
9115
 
            TheModalResult:=DoLoadLFM(AnUnitInfo,LFMCode,
9116
 
                              [ofQuiet,ofOnlyIfExists,ofLoadHiddenResource],[]);
9117
 
            if TheModalResult<>mrOk then begin
9118
 
              debugln('TMainIDE.DoSelectFrame Failed streaming ',LFMFilename);
9119
 
              exit;
9120
 
            end;
9121
 
          end;
9122
 
          if (AnUnitInfo.Component<>nil) then
9123
 
          begin
9124
 
            Result := TComponentClass(AnUnitInfo.Component.ClassType);
9125
 
            //DebugLn(AnUnitInfo.ComponentName + ' has been selected');
9126
 
            break;
9127
 
          end;
9128
 
        end;
9129
 
      end;  { for }
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
 
10263
      then exit;
 
10264
      debugln(['TMainIDE.DoSelectFrame AncestorComponent=',DbgSName(AComponent)]);
 
10265
      Result := TComponentClass(AComponent.ClassType);
 
10266
      exit;
 
10267
    end;
9131
10268
  finally
9132
 
    for i := 0 to UnitList.Count-1 do
9133
 
      TViewUnitsEntry(UnitList.Objects[i]).Free;
9134
10269
    UnitList.Free;
9135
10270
  end;
9136
10271
end;
9178
10313
        end;
9179
10314
      end;  { for }
9180
10315
      if (AnUnitInfo <> nil) and (not OnlyForms) then
9181
 
      begin
9182
 
        SourceEditorManager.ShowActiveWindowOnTop(False);
9183
 
      end;
 
10316
        SourceEditorManager.ShowActiveWindowOnTop(True);
9184
10317
    end;  { if ShowViewUnitDlg... }
9185
10318
  finally
9186
10319
    for i := 0 to UnitList.Count-1 do
9201
10334
    UnitDependenciesView.OnOpenFile:=@UnitDependenciesViewOpenFile;
9202
10335
  end;
9203
10336
 
9204
 
  if not UnitDependenciesView.RootValid then begin
 
10337
  if (Project1 <> nil) and (not UnitDependenciesView.RootValid) then begin
9205
10338
    if Project1.MainUnitID>=0 then begin
9206
10339
      UnitDependenciesView.BeginUpdate;
9207
10340
      UnitDependenciesView.RootFilename:=Project1.MainUnitInfo.Filename;
9282
10415
            inc(UnitLineCountWithIncludes,SubCode.LineCount);
9283
10416
            Node:=TreeOfSourceCodes.FindSuccessor(Node);
9284
10417
          end;
 
10418
          TreeOfSourceCodes.Free;
9285
10419
        end;
9286
10420
      end;
9287
10421
    end;
9329
10463
    IDEWindowCreators.ShowForm(CodeBrowserView,true);
9330
10464
end;
9331
10465
 
9332
 
procedure TMainIDE.DoShowRestrictionBrowser(Show: boolean;
9333
 
  const RestrictedName: String);
 
10466
procedure TMainIDE.DoShowRestrictionBrowser(Show: boolean; const RestrictedName: String);
9334
10467
begin
9335
10468
  if RestrictionBrowserView = nil then
9336
10469
    RestrictionBrowserView := TRestrictionBrowserView.Create(OwningComponent);
9342
10475
 
9343
10476
procedure TMainIDE.DoShowComponentList(Show: boolean);
9344
10477
begin
9345
 
  if not Assigned(ComponentListForm) then
 
10478
  if ComponentListForm = nil then
9346
10479
  begin
9347
10480
    ComponentListForm := TComponentListForm.Create(OwningComponent);
9348
 
    ComponentListForm.Name:=ComponentListFormName;
 
10481
    ComponentListForm.Name:=NonModalIDEWindowNames[nmiwComponentList];
9349
10482
  end;
9350
10483
  if Show then
9351
 
    ComponentListForm.Show;
 
10484
    IDEWindowCreators.ShowForm(ComponentListForm,true);
 
10485
//    ComponentListForm.Show;
 
10486
end;
 
10487
 
 
10488
procedure TMainIDE.DoShowInspector(Show: boolean);
 
10489
begin
 
10490
  CreateObjectInspector;
 
10491
  if Show then begin
 
10492
    IDEWindowCreators.ShowForm(ObjectInspector1,true);
 
10493
    if ObjectInspector1.IsVisible then
 
10494
    begin
 
10495
      ObjectInspector1.FocusGrid;
 
10496
      if FDisplayState <> high(TDisplayState) then
 
10497
        FDisplayState:= Succ(FDisplayState);
 
10498
    end;
 
10499
  end;
9352
10500
end;
9353
10501
 
9354
10502
procedure TMainIDE.CreateIDEWindow(Sender: TObject; aFormName: string; var
9385
10533
  end
9386
10534
  else if ItIs(NonModalIDEWindowNames[nmiwSearchResultsViewName]) then
9387
10535
  begin
9388
 
    DoShowSearchResultsView(false,false);
 
10536
    DoShowSearchResultsView(false);
9389
10537
    AForm:=SearchResultsView;
9390
10538
  end
9391
10539
  else if ItIs(NonModalIDEWindowNames[nmiwAnchorEditor]) then
9393
10541
    DoViewAnchorEditor(false);
9394
10542
    AForm:=AnchorDesigner;
9395
10543
  end
 
10544
  else if ItIs(NonModalIDEWindowNames[nmiwTabOrderEditor]) then
 
10545
  begin
 
10546
    DoViewTabOrderEditor(false);
 
10547
    AForm:=TabOrderDialog;
 
10548
  end
9396
10549
  else if ItIs(NonModalIDEWindowNames[nmiwCodeBrowser]) then
9397
10550
  begin
9398
10551
    DoShowCodeBrowser(false);
9408
10561
    DoViewJumpHistory(false);
9409
10562
    AForm:=JumpHistoryViewWin;
9410
10563
  end
9411
 
  else if ItIs(ComponentListFormName) then
 
10564
  else if ItIs(NonModalIDEWindowNames[nmiwComponentList]) then
9412
10565
  begin
9413
10566
    DoShowComponentList(false);
9414
10567
    AForm:=ComponentListForm;
 
10568
  end
 
10569
  else if ItIs(DefaultObjectInspectorName) then
 
10570
  begin
 
10571
    DoShowInspector(false);
 
10572
    AForm:=ObjectInspector1;
9415
10573
  end;
9416
10574
  if (AForm<>nil) and DoDisableAutoSizing then
9417
10575
    AForm.DisableAutoSizing;
9462
10620
  until FileIsUnique(Result);
9463
10621
end;
9464
10622
 
9465
 
procedure TMainIDE.MarkUnitsModifiedUsingSubComponent(SubComponent: TComponent
9466
 
  );
 
10623
procedure TMainIDE.MarkUnitsModifiedUsingSubComponent(SubComponent: TComponent);
9467
10624
var
9468
10625
  UnitList: TFPList;
9469
10626
  i: Integer;
9532
10689
  Access: TEditorOptionsEditAccessOrderEntry;
9533
10690
begin
9534
10691
  Result := nil;
 
10692
  // Check for already open Editor. If there is none, then it must be opened in DoOpenEditorFile
9535
10693
  if AnUnitInfo.OpenEditorInfoCount = 0 then exit;
9536
10694
  for i := 0 to EditorOpts.MultiWinEditAccessOrder.Count - 1 do begin
9537
10695
    Access := EditorOpts.MultiWinEditAccessOrder[i];
9779
10937
  if FName='' then exit;
9780
10938
 
9781
10939
  // check if absolute filename
9782
 
  if FilenameIsAbsolute(FName) and FileExistsUTF8(FName) then
9783
 
    Found:=true;
 
10940
  if FilenameIsAbsolute(FName) then begin
 
10941
    if FileExistsUTF8(FName) then
 
10942
      Found:=true
 
10943
    else
 
10944
      exit;
 
10945
  end;
9784
10946
 
9785
 
  if (not Found) and (not FilenameIsAbsolute(FName)) then begin
 
10947
  if (not Found) then begin
9786
10948
    if IsIncludeDirective then begin
9787
10949
      // search include file
9788
10950
      SPath:='.;'+CodeToolBoss.DefineTree.GetIncludePathForDirectory(BaseDir);
9803
10965
    end;
9804
10966
  end;
9805
10967
 
 
10968
  if (not Found) then begin
 
10969
    // simple search relative to current unit
 
10970
    InFilename:=AppendPathDelim(BaseDir)+FName;
 
10971
    if FileExistsCached(InFilename) then begin
 
10972
      Found:=true;
 
10973
      FName:=InFilename;
 
10974
    end;
 
10975
  end;
 
10976
 
9806
10977
  if (not Found) and (System.Pos('.',FName)>0) and (not IsIncludeDirective) then
9807
10978
  begin
9808
10979
    // for example 'SysUtils.CompareText'
9851
11022
  if CodeToolBoss.FindDeclarationInInterface(ActiveUnitInfo.Source,
9852
11023
    AnIdentifier,NewSource, NewX, NewY, NewTopLine)
9853
11024
  then begin
9854
 
    DoJumpToCodePos(ActiveSrcEdit, ActiveUnitInfo,
9855
 
                    NewSource, NewX, NewY, NewTopLine, true);
 
11025
    DoJumpToCodePosition(ActiveSrcEdit, ActiveUnitInfo,
 
11026
                    NewSource, NewX, NewY, NewTopLine, [jfAddJumpPoint, jfFocusEditor]);
9856
11027
    Result:=mrOk;
9857
11028
  end else
9858
11029
    DoJumpToCodeToolBossError;
9878
11049
  if Result<>mrOk then exit;
9879
11050
  GetCurrentUnit(ActiveSrcEdit,ActiveUnitInfo);
9880
11051
  if ActiveUnitInfo<>nil then begin
9881
 
    DoJumpToCodePos(OldActiveSrcEdit, OldActiveUnitInfo,
 
11052
    DoJumpToCodePosition(OldActiveSrcEdit, OldActiveUnitInfo,
9882
11053
                    ActiveUnitInfo.Source,
9883
 
                    CursorPosition.X, CursorPosition.Y, TopLine, true);
 
11054
                    CursorPosition.X, CursorPosition.Y, TopLine, [jfAddJumpPoint, jfFocusEditor]);
9884
11055
    Result:=mrOk;
9885
11056
  end else begin
9886
11057
    Result:=mrCancel;
9902
11073
  end;
9903
11074
end;
9904
11075
 
9905
 
procedure TMainIDE.DoLoadDefaultCompilerOptions(AProject: TProject);
 
11076
procedure TMainIDE.DoMergeDefaultProjectOptions(AProject: TProject);
9906
11077
var
9907
11078
  AFilename: String;
9908
11079
begin
9909
 
  // load default compiler options if exists
9910
 
  AFilename:=AppendPathDelim(GetPrimaryConfigPath)+DefaultProjectCompilerOptionsFilename;
 
11080
  // load default project options if exists
 
11081
  AFilename:=AppendPathDelim(GetPrimaryConfigPath)+DefaultProjectOptionsFilename;
9911
11082
  if not FileExistsUTF8(AFilename) then
9912
 
    CopySecondaryConfigFile(DefaultProjectCompilerOptionsFilename);
9913
 
  if not FileExistsUTF8(AFilename) then exit;
9914
 
  if AProject.CompilerOptions.LoadFromFile(AFilename)<>mrOk then
9915
 
    DebugLn(['TMainIDE.DoLoadDefaultCompilerOptions failed']);
 
11083
    CopySecondaryConfigFile(DefaultProjectOptionsFilename);
 
11084
  if FileExistsUTF8(AFilename) then begin
 
11085
    if AProject.ReadProject(AFilename,[prfLoadParts,prfLoadPartBuildModes])<>mrOk then
 
11086
      DebugLn(['TMainIDE.DoLoadDefaultCompilerOptions failed']);
 
11087
  end else begin
 
11088
    // old way (<0.9.31)
 
11089
    // load default compiler options if exists
 
11090
    AFilename:=AppendPathDelim(GetPrimaryConfigPath)+DefaultProjectCompilerOptionsFilename;
 
11091
    if not FileExistsUTF8(AFilename) then
 
11092
      CopySecondaryConfigFile(DefaultProjectCompilerOptionsFilename);
 
11093
    if not FileExistsUTF8(AFilename) then exit;
 
11094
    if AProject.CompilerOptions.LoadFromFile(AFilename)<>mrOk then
 
11095
      DebugLn(['TMainIDE.DoLoadDefaultCompilerOptions failed']);
 
11096
  end;
9916
11097
end;
9917
11098
 
9918
11099
function TMainIDE.DoNewProject(ProjectDesc: TProjectDescriptor):TModalResult;
9926
11107
  Result:=ProjectDesc.InitDescriptor;
9927
11108
  if Result<>mrOk then exit;
9928
11109
 
9929
 
  // invalidate cached substituted macros
9930
 
  IncreaseCompilerParseStamp;
9931
 
 
9932
11110
  // close current project first
9933
 
  If Project1<>nil then begin
9934
 
    if SomethingOfProjectIsModified then begin
9935
 
      Result:=MessageDlg(lisProjectChanged, Format(lisSaveChangesToProject,
9936
 
       [Project1.Title]),
9937
 
        mtconfirmation, [mbYes, mbNo, mbAbort], 0);
9938
 
      if Result=mrYes then begin
9939
 
        Result:=DoSaveProject([]);
9940
 
        if Result=mrAbort then exit;
9941
 
      end else if Result in [mrCancel,mrAbort] then
9942
 
        exit;
9943
 
    end;
 
11111
  if Project1<>nil then begin
 
11112
    if not DoResetToolStatus([rfInteractive, rfSuccessOnTrigger]) then exit;
 
11113
 
 
11114
    if AskSaveProject(lisDoYouStillWantToCreateTheNewProject,
 
11115
      lisDiscardChangesCreateNewProject)<>mrOK then exit;
 
11116
 
9944
11117
    Result:=DoCloseProject;
9945
11118
    if Result=mrAbort then exit;
9946
11119
  end;
9947
11120
 
9948
11121
  // create a virtual project (i.e. unsaved and without real project directory)
9949
11122
 
 
11123
  // invalidate cached substituted macros
 
11124
  IncreaseCompilerParseStamp;
 
11125
 
9950
11126
  // switch codetools to virtual project directory
9951
11127
  CodeToolBoss.GlobalValues.Variables[ExternalMacroStart+'ProjPath']:=
9952
11128
    VirtualDirectory;
9953
11129
 
9954
 
  // create new project (TProject will automatically create the mainunit)
 
11130
  // create new project
9955
11131
 
9956
11132
  Project1:=CreateProjectObject(ProjectDesc,ProjectDescriptorProgram);
9957
11133
  try
9959
11135
    try
9960
11136
      Project1.CompilerOptions.CompilerPath:='$(CompPath)';
9961
11137
      if pfUseDefaultCompilerOptions in Project1.Flags then begin
9962
 
        DoLoadDefaultCompilerOptions(Project1);
 
11138
        DoMergeDefaultProjectOptions(Project1);
9963
11139
        Project1.Flags:=Project1.Flags-[pfUseDefaultCompilerOptions];
9964
11140
      end;
9965
11141
      Project1.AutoAddOutputDirToIncPath;
9967
11143
      if ProjInspector<>nil then ProjInspector.LazProject:=Project1;
9968
11144
 
9969
11145
      // add and load default required packages
9970
 
      PkgBoss.AddDefaultDependencies(Project1);
 
11146
      PkgBoss.OpenProjectDependencies(Project1,true);
9971
11147
 
9972
11148
      // rebuild codetools defines
9973
 
      MainBuildBoss.RescanCompilerDefines(true,false,false);
 
11149
      MainBuildBoss.SetBuildTargetProject1(false);
9974
11150
 
9975
11151
      // (i.e. remove old project specific things and create new)
9976
11152
      IncreaseCompilerParseStamp;
9989
11165
        debugln('TMainIDE.DoNewProject ProjectDesc.CreateStartFiles failed');
9990
11166
      end;
9991
11167
 
 
11168
      if (Project1.MainUnitInfo<>nil)
 
11169
      and ((Project1.FirstUnitWithEditorIndex=nil)
 
11170
       or ([pfMainUnitHasCreateFormStatements,pfMainUnitHasTitleStatement]*Project1.Flags=[]))
 
11171
      then begin
 
11172
        // the project has not created any secondary files
 
11173
        // or the project main source is not auto updated by the IDE
 
11174
        DoOpenMainUnit(-1,-1,[]);
 
11175
      end;
 
11176
 
9992
11177
      // init resource files
9993
 
      if not Project1.Resources.Regenerate(Project1.MainFilename, True, False,'') then
 
11178
      if not Project1.ProjResources.Regenerate(Project1.MainFilename, True, False,'') then
9994
11179
        DebugLn('TMainIDE.DoNewProject Project1.Resources.Regenerate failed');
9995
11180
    finally
9996
11181
      Project1.EndUpdate;
10032
11217
  DebugLn('TMainIDE.DoSaveProject A SaveAs=',dbgs(sfSaveAs in Flags),' SaveToTestDir=',dbgs(sfSaveToTestDir in Flags),' ProjectInfoFile=',Project1.ProjectInfoFile);
10033
11218
  {$ENDIF}
10034
11219
 
10035
 
  if DoCheckFilesOnDisk(true) in [mrCancel,mrAbort] then exit;
 
11220
  Result:=DoCheckFilesOnDisk(true);
 
11221
  if Result in [mrCancel,mrAbort] then exit;
10036
11222
 
10037
 
  if CheckMainSrcLCLInterfaces(sfQuietUnitCheck in Flags)<>mrOk then exit;
 
11223
  if CheckMainSrcLCLInterfaces(sfQuietUnitCheck in Flags)<>mrOk then
 
11224
    exit(mrCancel);
10038
11225
 
10039
11226
  // if this is a virtual project then save first the project info file
10040
11227
  // to get a project directory
10041
 
  if Project1.IsVirtual
10042
 
  and ([sfSaveToTestDir,sfDoNotSaveVirtualFiles]*Flags=[])
 
11228
  if Project1.IsVirtual and ([sfSaveToTestDir,sfDoNotSaveVirtualFiles]*Flags=[])
10043
11229
  then begin
10044
11230
    Result:=SaveProjectInfo(Flags);
10045
 
    if Result<>mrOk then exit;
 
11231
    if Result in [mrCancel,mrAbort] then exit;
10046
11232
  end;
10047
11233
 
10048
11234
  if (not (sfDoNotSaveVirtualFiles in Flags)) then
10062
11248
            Include(SaveFileFlags,sfSaveToTestDir);
10063
11249
        end;
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;
10066
11252
      end;
10067
11253
    end;
10068
11254
  end;
10069
11255
 
10070
11256
  Result:=SaveProjectInfo(Flags);
10071
 
  if Result<>mrOk then exit;
 
11257
  if Result in [mrCancel,mrAbort] then exit;
10072
11258
 
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
 
11263
      continue;
 
11264
    SaveFileFlags:=[sfProjectSaving]
 
11265
                   +Flags*[sfCheckAmbiguousFiles];
 
11266
    if AnUnitInfo = nil
 
11267
    then begin
 
11268
      // consistency check
 
11269
      DebugLn('TMainIDE.DoSaveProject - unit not found for page %d', [i]);
 
11270
      DumpStack;
 
11271
    end else begin
 
11272
      if AnUnitInfo.IsVirtual
10080
11273
      then begin
10081
 
        DebugLn('TMainIDE.DoSaveProject - unit not found for page %d', [i]);
10082
 
        DumpStack;
10083
 
      end else begin
10084
 
        if AnUnitInfo.IsVirtual
10085
 
        then begin
10086
 
          if (sfSaveToTestDir in Flags) then
10087
 
            Include(SaveFileFlags,sfSaveToTestDir)
10088
 
          else
10089
 
            continue;
10090
 
        end;
 
11274
        if (sfSaveToTestDir in Flags) then
 
11275
          Include(SaveFileFlags,sfSaveToTestDir)
 
11276
        else
 
11277
          continue;
10091
11278
      end;
10092
 
      Result:=DoSaveEditorFile(SourceEditorManager.SourceEditors[i], SaveFileFlags);
10093
 
      if Result=mrAbort then exit;
10094
11279
    end;
 
11280
    Result:=DoSaveEditorFile(SourceEditorManager.SourceEditors[i], SaveFileFlags);
 
11281
    if Result=mrAbort then exit;
 
11282
    // mrCancel: continue saving other files
10095
11283
  end;
10096
11284
 
10097
11285
  // update all lrs files
10098
11286
  if sfSaveToTestDir in Flags then
10099
 
    MainBuildBoss.UpdateProjectAutomaticFiles(EnvironmentOptions.TestBuildDirectory)
 
11287
    MainBuildBoss.UpdateProjectAutomaticFiles(EnvironmentOptions.GetParsedTestBuildDirectory)
10100
11288
  else
10101
11289
    MainBuildBoss.UpdateProjectAutomaticFiles('');
10102
11290
 
10164
11352
  FileReadable: Boolean;
10165
11353
  HandlerResult: TModalResult;
10166
11354
  AnEditorInfo: TUnitEditorInfo;
 
11355
  DiskFilename: String;
10167
11356
begin
10168
 
  // close the old project
10169
 
  if SomethingOfProjectIsModified then begin
10170
 
    case IDEQuestionDialog(lisProjectChanged,
10171
 
      Format(lisSaveChangesToProject, [Project1.Title]),
10172
 
      mtconfirmation, [mrYes, mrNoToAll, lisNo, mbCancel], '')
10173
 
    of
10174
 
      mrYes: if DoSaveProject([])=mrAbort then begin
10175
 
          Result:=mrAbort;
10176
 
          exit;
10177
 
        end;
10178
 
      mrNo, mrNoToAll:
10179
 
    else // mrCancel, mrAbort ...
10180
 
      exit(mrCancel);
10181
 
    end;
10182
 
  end;
 
11357
  Result:=mrCancel;
 
11358
 
10183
11359
  {$IFDEF IDE_VERBOSE}
10184
 
  writeln('TMainIDE.DoOpenProjectFile A "'+AFileName+'"');
 
11360
  debugln('TMainIDE.DoOpenProjectFile A "'+AFileName+'"');
10185
11361
  {$ENDIF}
10186
11362
  {$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.DoOpenProjectFile A');{$ENDIF}
10187
 
  Result:=mrCancel;
10188
11363
  if ExtractFileNameOnly(AFileName)='' then exit;
10189
11364
  //debugln('TMainIDE.DoOpenProjectFile A1 "'+AFileName+'"');
10190
11365
  AFilename:=ExpandFileNameUTF8(TrimFilename(AFilename));
10196
11371
  if not FileExistsUTF8(AFilename) then begin
10197
11372
    ACaption:=lisFileNotFound;
10198
11373
    AText:=Format(lisPkgMangFileNotFound, ['"', AFilename, '"']);
10199
 
    Result:=MessageDlg(ACaption, AText, mtError, [mbAbort], 0);
 
11374
    Result:=IDEMessageDialog(ACaption, AText, mtError, [mbAbort]);
10200
11375
    exit;
10201
11376
  end;
10202
11377
 
10205
11380
  if Result<>mrOk then exit;
10206
11381
  Ext:=lowercase(ExtractFileExt(AFilename));
10207
11382
 
 
11383
  DiskFilename:=CodeToolBoss.DirectoryCachePool.FindDiskFilename(AFilename);
 
11384
  if DiskFilename<>AFilename then begin
 
11385
    // the case is different
 
11386
    DebugLn(['TMainIDE.DoOpenProjectFile Fixing file name: ',AFilename,' -> ',DiskFilename]);
 
11387
    AFilename:=DiskFilename;
 
11388
  end;
 
11389
 
10208
11390
  // if there is a project info file, load that instead
10209
11391
  if (Ext<>'.lpi') and (FileExistsUTF8(ChangeFileExt(AFileName,'.lpi'))) then
10210
11392
  begin
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;
10223
11405
  end;
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]);
10228
11410
    exit;
10229
11411
  end;
10230
11412
 
10231
11413
  if ofAddToRecent in Flags then
10232
11414
    AddRecentProjectFileToEnvironment(AFileName);
10233
11415
 
 
11416
  if not DoResetToolStatus([rfInteractive, rfSuccessOnTrigger]) then exit;
 
11417
 
 
11418
  // save old project
 
11419
  if AskSaveProject(lisDoYouStillWantToOpenAnotherProject,
 
11420
    lisDiscardChangesAndOpenProject)<>mrOk then exit;
 
11421
 
10234
11422
  Result:=DoCloseProject;
10235
11423
  if Result=mrAbort then exit;
10236
11424
 
10237
11425
  // create a new project
10238
11426
  {$IFDEF IDE_VERBOSE}
10239
 
  writeln('TMainIDE.DoOpenProjectFile B');
 
11427
  debugln('TMainIDE.DoOpenProjectFile B');
10240
11428
  {$ENDIF}
10241
11429
  {$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.DoOpenProjectFile B');{$ENDIF}
10242
11430
  Project1:=CreateProjectObject(ProjectDescriptorProgram,
10271
11459
      end;
10272
11460
    end;
10273
11461
    {$IFDEF IDE_DEBUG}
10274
 
    writeln('TMainIDE.DoOpenProjectFile C');
 
11462
    debugln('TMainIDE.DoOpenProjectFile C');
10275
11463
    {$ENDIF}
10276
11464
    {$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.DoOpenProjectFile C');{$ENDIF}
10277
11465
    IncreaseCompilerParseStamp;
10278
11466
 
10279
11467
    // restore files
10280
 
    while EditorInfoIndex < Project1.EditorInfoCount do begin
 
11468
    while EditorInfoIndex < Project1.AllEditorsInfoCount do begin
10281
11469
      // TProject.ReadProject sorts alle UnitEditorInfos
10282
 
      AnEditorInfo := Project1.EditorInfo[EditorInfoIndex];
 
11470
      AnEditorInfo := Project1.AllEditorsInfo[EditorInfoIndex];
10283
11471
      AnUnitInfo := AnEditorInfo.UnitInfo;
10284
11472
      if (not AnUnitInfo.Loaded) or (AnEditorInfo.PageIndex < 0) then begin
10285
11473
        inc(EditorInfoIndex);
10308
11496
          AnUnitInfo.Loaded := False;
10309
11497
      end;
10310
11498
      inc(EditorInfoIndex);
10311
 
    end; // while EditorInfoIndex < Project1.EditorInfoCount
 
11499
    end; // while EditorInfoIndex < Project1.AllEditorsInfoCount
10312
11500
    Result:=mrCancel;
10313
11501
    {$IFDEF IDE_DEBUG}
10314
 
    writeln('TMainIDE.DoOpenProjectFile D');
 
11502
    debugln('TMainIDE.DoOpenProjectFile D');
10315
11503
    {$ENDIF}
10316
11504
 
10317
11505
    // set active editor source editor
10318
 
    for i := 0 to Project1.EditorInfoCount - 1 do begin
10319
 
      AnEditorInfo := Project1.EditorInfo[i];
 
11506
    for i := 0 to Project1.AllEditorsInfoCount - 1 do begin
 
11507
      AnEditorInfo := Project1.AllEditorsInfo[i];
10320
11508
      if AnEditorInfo.IsVisibleTab then
10321
11509
      begin
10322
11510
        if AnEditorInfo.WindowIndex >= SourceEditorManager.SourceWindowCount
10362
11550
    // select a form (object inspector, formeditor, control selection)
10363
11551
    if FLastFormActivated<>nil then begin
10364
11552
      LastDesigner:=TDesigner(FLastFormActivated.Designer);
10365
 
      debugln(['TMainIDE.DoOpenProjectFile ',DbgSName(FLastFormActivated),' ',DbgSName(FLastFormActivated.Designer)]);
 
11553
      debugln(['TMainIDE.DoOpenProjectFile select form in designer: ',DbgSName(FLastFormActivated),' ',DbgSName(FLastFormActivated.Designer)]);
10366
11554
      LastDesigner.SelectOnlyThisComponent(LastDesigner.LookupRoot);
10367
11555
    end;
10368
11556
 
10377
11565
    SourceEditorManager.DecUpdateLock;
10378
11566
    if (Result<>mrOk) and (Project1<>nil) then begin
10379
11567
      // mark all files, that are left to open as unloaded:
10380
 
      for i := EditorInfoIndex to Project1.EditorInfoCount - 1 do begin
10381
 
        AnEditorInfo := Project1.EditorInfo[i];
 
11568
      for i := EditorInfoIndex to Project1.AllEditorsInfoCount - 1 do begin
 
11569
        AnEditorInfo := Project1.AllEditorsInfo[i];
10382
11570
        AnEditorInfo.PageIndex := -1;
10383
11571
        AnUnitInfo := AnEditorInfo.UnitInfo;
10384
11572
        if AnUnitInfo.Loaded and (AnUnitInfo.OpenEditorInfoCount = 0) then
10423
11611
 
10424
11612
function TMainIDE.DoImExportCompilerOptions(Sender: TObject; out ImportExportResult: TImportExportOptionsResult): TModalResult;
10425
11613
var
10426
 
  CompOptsDialog: TfrmCompilerOptions;
10427
11614
  Options: TCompilerOptions;
10428
11615
  Filename: string;
10429
11616
begin
10430
11617
  Result := mrOk;
10431
 
  if Sender is TfrmCompilerOptions then
10432
 
  begin
10433
 
    CompOptsDialog := TfrmCompilerOptions(Sender);
10434
 
    Options := CompOptsDialog.CompilerOpts;
10435
 
  end
10436
 
  else
10437
11618
  if Sender is TCompilerOptions then
10438
 
  begin
10439
 
    Options := TCompilerOptions(Sender);
10440
 
    CompOptsDialog := nil;
10441
 
  end
 
11619
    Options := TCompilerOptions(Sender)
10442
11620
  else
10443
11621
    RaiseException('TMainIDE.OnCompilerOptionsImExport');
10444
11622
  ImportExportResult := ShowImExportCompilerOptionsDialog(Options, Filename);
10445
11623
  if Filename='' then Exit(mrCancel);
10446
11624
  case ImportExportResult of
10447
 
    ieorImport: Result := DoImportCompilerOptions(CompOptsDialog, Options, Filename);
10448
 
    ieorExport: Result := DoExportCompilerOptions(CompOptsDialog, Options, Filename);
 
11625
    ieorImport: Result := DoImportCompilerOptions(Options, Filename);
 
11626
    ieorExport: Result := DoExportCompilerOptions(Options, Filename);
10449
11627
  end;
10450
11628
end;
10451
11629
 
10478
11656
  {$IFDEF IDE_VERBOSE}
10479
11657
  writeln('[TMainIDE.DoCreateProjectForProgram] A ',ProgramBuf.Filename);
10480
11658
  {$ENDIF}
 
11659
 
 
11660
  if (Project1 <> nil) and (not DoResetToolStatus([rfInteractive, rfSuccessOnTrigger])) then exit;
 
11661
 
10481
11662
  Result:=DoSaveProjectIfChanged;
10482
11663
  if Result=mrAbort then exit;
10483
11664
 
10508
11689
    MainUnitInfo:=Project1.MainUnitInfo;
10509
11690
    MainUnitInfo.Source:=ProgramBuf;
10510
11691
    Project1.ProjectInfoFile:=ChangeFileExt(ProgramBuf.Filename,'.lpi');
10511
 
    DoLoadDefaultCompilerOptions(Project1);
 
11692
    DoMergeDefaultProjectOptions(Project1);
10512
11693
    UpdateCaption;
10513
11694
    IncreaseCompilerParseStamp;
10514
11695
 
10515
11696
    // add and load default required packages
10516
 
    PkgBoss.AddDefaultDependencies(Project1);
 
11697
    PkgBoss.OpenProjectDependencies(Project1,true);
10517
11698
 
10518
11699
    Result:=DoCompleteLoadingProjectInfo;
10519
11700
    if Result<>mrOk then exit;
10535
11716
function TMainIDE.DoSaveProjectIfChanged: TModalResult;
10536
11717
begin
10537
11718
  if SomethingOfProjectIsModified then begin
10538
 
    if MessageDlg(lisProjectChanged, Format(lisSaveChangesToProject,
10539
 
      [Project1.Title]),
10540
 
      mtconfirmation, [mbYes, mbNo, mbCancel], 0)=mrYes then
 
11719
    if IDEMessageDialog(lisProjectChanged, Format(lisSaveChangesToProject,
 
11720
      [Project1.GetTitleOrName]),
 
11721
      mtconfirmation, [mbYes, mbNo, mbCancel])=mrYes then
10541
11722
    begin
10542
11723
      if DoSaveProject([])=mrAbort then begin
10543
11724
        Result:=mrAbort;
10568
11749
    else
10569
11750
      s:=Format(lisTheFile, ['"', ActiveSourceEditor.PageName, '"']);
10570
11751
    s:=Format(lisisAlreadyPartOfTheProject, [s]);
10571
 
    MessageDlg(s,mtInformation,[mbOk],0);
 
11752
    IDEMessageDialog(lisInformation, s, mtInformation, [mbOk]);
10572
11753
    exit;
10573
11754
  end;
10574
11755
  if not ActiveUnitInfo.IsVirtual then
10576
11757
  else
10577
11758
    s:='"'+ActiveSourceEditor.PageName+'"';
10578
11759
  if (ActiveUnitInfo.Unit_Name<>'')
10579
 
  and (Project1.IndexOfUnitWithName(ActiveUnitInfo.Unit_Name,
10580
 
      true,ActiveUnitInfo)>=0) then
 
11760
  and (Project1.IndexOfUnitWithName(ActiveUnitInfo.Unit_Name,true,ActiveUnitInfo)>=0) then
10581
11761
  begin
10582
 
    MessageDlg(Format(
 
11762
    IDEMessageDialog(lisInformation, Format(
10583
11763
      lisUnableToAddToProjectBecauseThereIsAlreadyAUnitWith, [s]),
10584
 
      mtInformation, [mbOk], 0);
 
11764
      mtInformation, [mbOk]);
10585
11765
    exit;
10586
11766
  end;
10587
11767
 
10594
11774
          MsgResult:=IDEQuestionDialog(lisAddPackageRequirement,
10595
11775
            Format(lisTheUnitBelongsToPackage, [APackage.IDAsString]),
10596
11776
            mtConfirmation, [mrYes, lisAddPackageToProject2,
10597
 
                            mrIgnore, lisAddUnitNotRecommended,
10598
 
                            mrCancel],'');
 
11777
                            mrIgnore, lisAddUnitNotRecommended, mrCancel],'');
10599
11778
          case MsgResult of
10600
11779
            mrYes:
10601
11780
              begin
10625
11804
    end;
10626
11805
  end;
10627
11806
 
10628
 
  if MessageDlg(Format(lisAddToProject, [s]), mtConfirmation, [mbYes,
10629
 
    mbCancel], 0) in [mrOk,mrYes]
 
11807
  if IDEMessageDialog(lisConfirmation, Format(lisAddToProject, [s]),
 
11808
    mtConfirmation, [mbYes, mbCancel]) in [mrOk, mrYes]
10630
11809
  then begin
10631
11810
    DependencyAdded:=false;
10632
11811
    if FilenameIsPascalUnit(ActiveUnitInfo.Filename) then
10642
11821
        ActiveUnitInfo.ReadUnitNameFromSource(false);
10643
11822
        ShortUnitName:=ActiveUnitInfo.CreateUnitName;
10644
11823
        if (ShortUnitName<>'') then begin
10645
 
          if CodeToolBoss.AddUnitToMainUsesSection(
10646
 
            Project1.MainUnitInfo.Source,ShortUnitName,'')
 
11824
          if CodeToolBoss.AddUnitToMainUsesSection(Project1.MainUnitInfo.Source,ShortUnitName,'')
10647
11825
          then
10648
11826
            Project1.MainUnitInfo.Modified:=true;
10649
11827
        end;
10654
11832
 
10655
11833
function TMainIDE.DoRemoveFromProjectDialog: TModalResult;
10656
11834
var
10657
 
  UnitList: TStringList;
 
11835
  ViewUnitEntries: TStringList;
10658
11836
  i:integer;
10659
11837
  AName: string;
10660
11838
  AnUnitInfo: TUnitInfo;
 
11839
  UnitInfos: TFPList;
10661
11840
const
10662
11841
  MultiSelectCheckedState: Boolean = true;
10663
11842
Begin
10664
 
  UnitList := TStringList.Create;
10665
 
  UnitList.Sorted := True;
10666
 
 
 
11843
  ViewUnitEntries := TStringList.Create;
 
11844
  ViewUnitEntries.Sorted := True;
 
11845
  UnitInfos:=nil;
10667
11846
  try
10668
11847
    for i := 0 to Project1.UnitCount-1 do
10669
11848
    begin
10671
11850
      if (AnUnitInfo.IsPartOfProject) and (i<>Project1.MainUnitID) then
10672
11851
      begin
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));
10675
11854
      end;
10676
11855
    end;
10677
 
    if ShowViewUnitsDlg(UnitList, true, MultiSelectCheckedState, lisRemoveFromProject) = mrOk then
 
11856
    if ShowViewUnitsDlg(ViewUnitEntries, true, MultiSelectCheckedState,
 
11857
          lisRemoveFromProject, IDEImages.LoadImage(16, 'item_unit')) <> mrOk then
 
11858
      exit(mrOk);
 
11859
    { This is where we check what the user selected. }
 
11860
    UnitInfos:=TFPList.Create;
 
11861
    for i:=0 to ViewUnitEntries.Count-1 do
10678
11862
    begin
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
10681
11864
      begin
10682
 
        if TViewUnitsEntry(UnitList.Objects[i]).Selected then
10683
 
        begin
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
10688
 
          begin
10689
 
            if (AnUnitInfo.Unit_Name <> '') then
10690
 
            begin
10691
 
              if CodeToolBoss.RemoveUnitFromAllUsesSections(
10692
 
                Project1.MainUnitInfo.Source, AnUnitInfo.Unit_Name)
10693
 
              then
10694
 
                Project1.MainUnitInfo.Modified := true;
10695
 
            end;
10696
 
            if (AnUnitInfo.ComponentName <> '') then
10697
 
            begin
10698
 
              Project1.RemoveCreateFormFromProjectFile(
10699
 
                  'T' + AnUnitInfo.ComponentName, AnUnitInfo.ComponentName);
10700
 
            end;
10701
 
          end;
10702
 
        end;
10703
 
      end;  { for }
10704
 
    end;  { if ShowViewUnitsDlg.. }
 
11865
        AnUnitInfo:=Project1.Units[TViewUnitsEntry(ViewUnitEntries.Objects[i]).ID];
 
11866
        if AnUnitInfo.IsPartOfProject then
 
11867
          UnitInfos.Add(AnUnitInfo);
 
11868
      end;
 
11869
    end;
 
11870
    if UnitInfos.Count>0 then
 
11871
      Result:=RemoveFilesFromProject(Project1,UnitInfos)
 
11872
    else
 
11873
      Result:=mrOk;
10705
11874
  finally
10706
 
    for i := 0 to UnitList.Count-1 do
10707
 
      TViewUnitsEntry(UnitList.Objects[i]).Free;
10708
 
    UnitList.Free;
 
11875
    UnitInfos.Free;
 
11876
    for i := 0 to ViewUnitEntries.Count-1 do
 
11877
      TViewUnitsEntry(ViewUnitEntries.Objects[i]).Free;
 
11878
    ViewUnitEntries.Free;
10709
11879
  end;
10710
 
  Result := mrOk;
10711
11880
end;
10712
11881
 
10713
11882
function TMainIDE.DoWarnAmbiguousFiles: TModalResult;
10757
11926
    exit;
10758
11927
  end;
10759
11928
  if Project1=nil then Begin
10760
 
    MessageDlg(lisCreateAProjectFirst, mterror, [mbok], 0);
 
11929
    IDEMessageDialog(lisCCOErrorCaption, lisCreateAProjectFirst, mtError, [mbOK]);
10761
11930
    Exit;
10762
11931
  end;
10763
11932
 
10770
11939
    Result:=DoSaveAll([sfCheckAmbiguousFiles])
10771
11940
  else
10772
11941
    Result:=DoSaveProjectToTestDirectory([sfSaveNonProjectFiles]);
10773
 
  Project1.Resources.DoBeforeBuild(AReason, Project1.IsVirtual);
 
11942
  Project1.ProjResources.DoBeforeBuild(AReason, Project1.IsVirtual);
10774
11943
  Project1.UpdateExecutableType;
10775
11944
  if Result<>mrOk then begin
10776
11945
    {$IFDEF VerboseSaveForBuild}
10782
11951
  Result:=PkgBoss.DoSaveAllPackages([]);
10783
11952
end;
10784
11953
 
10785
 
function TMainIDE.DoCheckIfProjectNeedsCompilation(AProject: TProject;
10786
 
  const CompilerFilename, CompilerParams, SrcFilename: string;
10787
 
  out NeedBuildAllFlag: boolean): TModalResult;
10788
 
var
10789
 
  StateFilename: String;
10790
 
  StateFileAge: LongInt;
10791
 
  AnUnitInfo: TUnitInfo;
10792
 
begin
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))
10799
 
  then
10800
 
    NeedBuildAllFlag:=true;
10801
 
 
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);
10808
 
    exit(mrYes);
10809
 
  end;
10810
 
 
10811
 
  StateFileAge:=FileAgeCached(StateFilename);
10812
 
 
10813
 
  // check main source file
10814
 
  if FileExistsCached(SrcFilename) and (StateFileAge<FileAgeCached(SrcFilename)) then
10815
 
  begin
10816
 
    DebugLn('TMainIDE.CheckIfProjectNeedsCompilation  SrcFile outdated ',AProject.IDAsString);
10817
 
    exit(mrYes);
10818
 
  end;
10819
 
 
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,'"');
10825
 
    exit(mrYes);
10826
 
  end;
10827
 
  if not FileExistsUTF8(CompilerFilename) then begin
10828
 
    DebugLn('TMainIDE.CheckIfProjectNeedsCompilation  Compiler filename not found for ',AProject.IDAsString);
10829
 
    DebugLn('  File="',CompilerFilename,'"');
10830
 
    exit(mrYes);
10831
 
  end;
10832
 
  if FileAgeCached(CompilerFilename)<>AProject.LastCompilerFileDate then begin
10833
 
    DebugLn('TMainIDE.CheckIfProjectNeedsCompilation  Compiler file changed for ',AProject.IDAsString);
10834
 
    DebugLn('  File="',CompilerFilename,'"');
10835
 
    exit(mrYes);
10836
 
  end;
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,'"');
10841
 
    exit(mrYes);
10842
 
  end;
10843
 
 
10844
 
  // compiler and parameters are the same
10845
 
  // quick compile is possible
10846
 
  NeedBuildAllFlag:=false;
10847
 
 
10848
 
  // check all required packages
10849
 
  Result:=PackageGraph.CheckCompileNeedDueToDependencies(
10850
 
                                 AProject.FirstRequiredDependency,StateFileAge);
10851
 
  if Result<>mrNo then exit;
10852
 
 
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);
10859
 
      exit(mrYes);
10860
 
    end;
10861
 
    AnUnitInfo:=AnUnitInfo.NextPartOfProject;
10862
 
  end;
10863
 
 
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);
10871
 
      exit(mrYes);
10872
 
    end;
10873
 
    AnUnitInfo:=AnUnitInfo.NextUnitWithEditorIndex;
10874
 
  end;
10875
 
 
10876
 
  Result:=mrNo;
10877
 
end;
10878
 
 
10879
11954
function TMainIDE.DoSaveProjectToTestDirectory(Flags: TSaveFlags): TModalResult;
 
11955
var
 
11956
  TestDir: String;
10880
11957
begin
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;
 
11960
  if (TestDir='')
 
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, [
10887
 
        mbCancel], 0);
 
11966
        mbCancel]);
10888
11967
      Result:=mrCancel;
10889
11968
      exit;
10890
11969
    end;
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]);
10896
11975
    exit;
10927
12006
  MainUnitInfo:=Project1.MainUnitInfo;
10928
12007
  if (MainUnitInfo=nil) or (MainUnitInfo.Source=nil) then exit;
10929
12008
  if PackageGraph.FindDependencyRecursively(Project1.FirstRequiredDependency,
10930
 
    PackageGraph.LCLPackage)=nil
 
12009
    PackageGraph.LCLBasePackage)=nil
10931
12010
  then
10932
 
    exit; // project does not use LCL
10933
 
  // project uses LCL
 
12011
    exit; // project does not use LCLBase
 
12012
  // project uses LCLBase
10934
12013
  MainUsesSection:=nil;
10935
12014
  ImplementationUsesSection:=nil;
10936
12015
  try
10977
12056
  {$ENDIF}
10978
12057
end;
10979
12058
 
 
12059
function CheckCompileReasons(Reason: TCompileReason;
 
12060
  Options: TProjectCompilerOptions; Quiet: boolean): TModalResult;
 
12061
var
 
12062
  ProjToolOpts: TProjectCompilationToolOptions;
 
12063
begin
 
12064
  if (Reason in Options.CompileReasons)
 
12065
  and (Options.CompilerPath<>'') then
 
12066
    exit(mrOk);
 
12067
  if Options.ExecuteBefore is TProjectCompilationToolOptions then begin
 
12068
    ProjToolOpts:=TProjectCompilationToolOptions(Options.ExecuteBefore);
 
12069
    if (Reason in ProjToolOpts.CompileReasons) and (ProjToolOpts.Command<>'') then
 
12070
      exit(mrOk);
 
12071
  end;
 
12072
  if Options.ExecuteAfter is TProjectCompilationToolOptions then begin
 
12073
    ProjToolOpts:=TProjectCompilationToolOptions(Options.ExecuteAfter);
 
12074
    if (Reason in ProjToolOpts.CompileReasons) and (ProjToolOpts.Command<>'') then
 
12075
      exit(mrOk);
 
12076
  end;
 
12077
  // reason is not handled
 
12078
  if Quiet then exit(mrCancel);
 
12079
  Result:=IDEMessageDialog('Nothing to do',
 
12080
    'The project''s compiler options has no compile command.'#13
 
12081
    +'See Project / Compiler Options ... / Compilation',mtInformation,
 
12082
    [mbCancel,mbIgnore]);
 
12083
  if Result=mrIgnore then
 
12084
    Result:=mrOk;
 
12085
end;
 
12086
 
10980
12087
function TMainIDE.DoBuildProject(const AReason: TCompileReason;
10981
12088
  Flags: TProjectBuildFlags): TModalResult;
10982
12089
var
10993
12100
  err : TFPCErrorType;
10994
12101
  TargetExeDirectory: String;
10995
12102
  FPCVersion, FPCRelease, FPCPatch: integer;
 
12103
  Note: String;
 
12104
  OldToolStatus: TIDEToolStatus;
10996
12105
begin
10997
12106
  if Project1.MainUnitInfo=nil then begin
10998
12107
    // this project has no source to compile
11020
12129
    Result:=DoSaveForBuild(AReason);
11021
12130
    if Result<>mrOk then exit;
11022
12131
 
11023
 
    if (Project1.Resources.ResourceType=rtRes) then begin
 
12132
    if (Project1.ProjResources.ResourceType=rtRes) then begin
11024
12133
      // FPC resources are only supported with FPC 2.4+
11025
12134
      CodeToolBoss.GetFPCVersionForDirectory(
11026
12135
        ExtractFilePath(Project1.MainFilename),FPCVersion,FPCRelease,FPCPatch);
11027
12136
      if (FPCVersion=2) and (FPCRelease<4) then begin
11028
 
        MessageDlg(lisFPCTooOld,
 
12137
        IDEMessageDialog(lisFPCTooOld,
11029
12138
          lisTheProjectUsesTheNewFPCResourcesWhichRequiresAtLea,
11030
 
          mtError,[mbCancel],0);
 
12139
          mtError,[mbCancel]);
11031
12140
        exit(mrCancel);
11032
12141
      end;
11033
12142
    end;
11068
12177
      if Result<>mrOk then exit;
11069
12178
    end;
11070
12179
 
11071
 
    CompilerFilename:=Project1.GetCompilerFilename;
11072
 
    //DebugLn(['TMainIDE.DoBuildProject CompilerFilename="',CompilerFilename,'" CompilerPath="',Project1.CompilerOptions.CompilerPath,'"']);
11073
 
    // Note: use absolute paths, because some external tools resolve symlinked directories
11074
 
    CompilerParams :=
11075
 
      Project1.CompilerOptions.MakeOptionsString(SrcFilename,nil,[ccloAbsolutePaths])
11076
 
             + ' ' + PrepareCmdLineOption(SrcFilename);
11077
 
    //DebugLn('TMainIDE.DoBuildProject WorkingDir="',WorkingDir,'" SrcFilename="',SrcFilename,'" CompilerFilename="',CompilerFilename,'" CompilerParams="',CompilerParams,'"');
11078
 
 
11079
12180
    // warn for ambiguous files
11080
12181
    Result:=DoWarnAmbiguousFiles;
11081
12182
    if Result<>mrOk then
11088
12189
    // and check if a 'build all' is needed
11089
12190
    NeedBuildAllFlag:=false;
11090
12191
    if (AReason in Project1.CompilerOptions.CompileReasons) then begin
11091
 
      Result:=DoCheckIfProjectNeedsCompilation(Project1,
11092
 
                                               CompilerFilename,CompilerParams,
11093
 
                                               SrcFilename,NeedBuildAllFlag);
 
12192
      Note:='';
 
12193
      Result:=MainBuildBoss.DoCheckIfProjectNeedsCompilation(Project1,
 
12194
                                                         NeedBuildAllFlag,Note);
11094
12195
      if  (pbfOnlyIfNeeded in Flags)
11095
12196
      and (not (pfAlwaysBuild in Project1.Flags)) then begin
11096
12197
        if Result=mrNo then begin
11126
12227
    // create target output directory
11127
12228
    TargetExeName := Project1.CompilerOptions.CreateTargetFilename(Project1.MainFilename);
11128
12229
    if Project1.IsVirtual and (not FilenameIsAbsolute(TargetExeName)) then
11129
 
      TargetExeName := EnvironmentOptions.GetTestBuildDirectory + TargetExeName;
 
12230
      TargetExeName := GetTestBuildDirectory + TargetExeName;
11130
12231
    TargetExeDirectory:=ExtractFilePath(TargetExeName);
11131
12232
    if (FilenameIsAbsolute(TargetExeDirectory))
11132
12233
    and (not DirPathExistsCached(TargetExeDirectory)) then begin
11143
12244
 
11144
12245
    // create application bundle
11145
12246
    if Project1.UseAppBundle and (Project1.MainUnitID>=0)
11146
 
    and (MainBuildBoss.GetLCLWidgetType(true)=LCLPlatformDirNames[lpCarbon])
 
12247
    and (MainBuildBoss.GetLCLWidgetType=LCLPlatformDirNames[lpCarbon])
11147
12248
    then begin
11148
 
      Result:=CreateApplicationBundle(TargetExeName, Project1.Title);
 
12249
      Result:=CreateApplicationBundle(TargetExeName, Project1.GetTitleOrName);
11149
12250
      if not (Result in [mrOk,mrIgnore]) then exit;
11150
12251
      Result:=CreateAppBundleSymbolicLink(TargetExeName);
11151
12252
      if not (Result in [mrOk,mrIgnore]) then exit;
11152
12253
    end;
11153
12254
 
11154
 
    if not Project1.Resources.Regenerate(Project1.MainFilename, False, True, TargetExeDirectory) then
 
12255
    if not Project1.ProjResources.Regenerate(Project1.MainFilename, False, True, TargetExeDirectory) then
11155
12256
      Exit;
11156
12257
 
11157
12258
    // execute compilation tool 'Before'
11173
12274
    and (not (pbfDoNotCompileProject in Flags)) then begin
11174
12275
      try
11175
12276
        // change tool status
 
12277
        OldToolStatus := ToolStatus;  // It can still be itDebugger, if the debugger is still stopping. Prevent any "Run" command after building, until the debugger is clear
11176
12278
        ToolStatus:=itBuilder;
11177
12279
 
11178
12280
        ConnectOutputFilter;
11181
12283
            TheOutputFilter.ErrorTypeName[err] := ErrorNames[err];
11182
12284
 
11183
12285
        // compile
 
12286
        CompilerFilename:=Project1.GetCompilerFilename;
 
12287
        // Note: use absolute paths, because some external tools resolve symlinked directories
 
12288
        CompilerParams :=
 
12289
          Project1.CompilerOptions.MakeOptionsString(SrcFilename,[ccloAbsolutePaths])
 
12290
                 + ' ' + PrepareCmdLineOption(SrcFilename);
 
12291
        // write state file, to avoid building clean every time
 
12292
        Result:=Project1.SaveStateFile(CompilerFilename,CompilerParams,false);
 
12293
        if Result<>mrOk then begin
 
12294
          CompileProgress.Ready(lisInfoBuildError);
 
12295
          exit;
 
12296
        end;
 
12297
 
11184
12298
        Result:=TheCompiler.Compile(Project1,
11185
12299
                                WorkingDir,CompilerFilename,CompilerParams,
11186
12300
                                (pbfCleanCompile in Flags) or NeedBuildAllFlag,
11196
12310
          exit;
11197
12311
        end;
11198
12312
        // compilation succeded -> write state file
11199
 
        Result:=Project1.SaveStateFile(CompilerFilename,CompilerParams);
 
12313
        Result:=Project1.SaveStateFile(CompilerFilename,CompilerParams,true);
11200
12314
        if Result<>mrOk then begin
11201
12315
          CompileProgress.Ready(lisInfoBuildError);
11202
12316
          exit;
11210
12324
        end;
11211
12325
 
11212
12326
      finally
11213
 
        ToolStatus:=itNone;
 
12327
        if OldToolStatus = itDebugger then begin
 
12328
          ToolStatus := OldToolStatus;
 
12329
          if DebugBoss <> nil then
 
12330
            DebugBoss.UpdateToolStatus;  // Maybe "Reset Debugger was called and changed the state?
 
12331
        end
 
12332
        else
 
12333
          ToolStatus:=itNone;
11214
12334
      end;
11215
12335
    end;
11216
12336
 
11230
12350
      end;
11231
12351
    end;
11232
12352
 
11233
 
    Project1.Resources.DoAfterBuild(AReason, Project1.IsVirtual);
 
12353
    Project1.ProjResources.DoAfterBuild(AReason, Project1.IsVirtual);
11234
12354
    // add success message
11235
12355
    MessagesView.AddMsg(Format(lisProjectSuccessfullyBuilt, ['"',
11236
 
                                        Project1.ShortDescription, '"']),'',-1);
 
12356
                                        Project1.GetTitleOrName, '"']),'',-1);
11237
12357
    CompileProgress.Ready(lisInfoBuildSuccess);
11238
12358
  finally
11239
12359
    // check sources
11285
12405
  DebugLn(['TMainIDE.DoInitProjectRun ProgramFilename=',ProgramFilename]);
11286
12406
  if not FileExistsUTF8(ProgramFilename)
11287
12407
  then begin
11288
 
    MessageDlg(lisFileNotFound,
 
12408
    IDEMessageDialog(lisFileNotFound,
11289
12409
      Format(lisNoProgramFileSFound, ['"', ProgramFilename, '"']),
11290
 
      mtError,[mbCancel], 0);
 
12410
      mtError,[mbCancel]);
11291
12411
    Exit;
11292
12412
  end;
11293
12413
 
11308
12428
    Result := mrAbort;
11309
12429
    Exit;
11310
12430
  end;
11311
 
  debugln('[TMainIDE.DoRunProject] B ',EnvironmentOptions.DebuggerClass);
 
12431
  debugln('[TMainIDE.DoRunProject] B ',EnvironmentOptions.DebuggerConfig.DebuggerClass);
11312
12432
 
11313
12433
  Result := mrCancel;
11314
12434
 
11335
12455
  if CurResult=mrAbort then exit(mrAbort);
11336
12456
  if CurResult<>mrOk then Result:=mrCancel;
11337
12457
  CurResult:=DoSaveProject(Flags);
11338
 
  SaveEnvironment;
 
12458
  SaveEnvironment(true);
11339
12459
  SaveIncludeLinks;
11340
12460
  PkgBoss.SaveSettings;
11341
12461
  InputHistories.Save;
11350
12470
procedure TMainIDE.DoRestart;
11351
12471
 
11352
12472
const
11353
 
  DarwinStartlazBundlePath = 'Resources/startlazarus.app/Contents/MacOS/';
 
12473
  DarwinStartlazBundlePath = 'lazarus.app/Contents/Resources/startlazarus.app/Contents/MacOS/';
11354
12474
 
11355
12475
  procedure StartStarter;
11356
12476
  var
11363
12483
  begin
11364
12484
    StartLazProcess := TProcessUTF8.Create(nil);
11365
12485
    try
11366
 
      // TODO: use the target directory, where the new startlazarus is
11367
 
      StartLazProcess.CurrentDirectory := GetLazarusDirectory;
 
12486
      // use the same working directory as the IDE, so that all relative file
 
12487
      // names in parameters still work
 
12488
      StartLazProcess.CurrentDirectory := ParamBaseDirectory;
11368
12489
      //DebugLn('Parsing commandLine: ');
11369
12490
      Params := TStringList.Create;
11370
12491
      ParseCommandLine(Params, Dummy, Unused);
11371
12492
      //DebugLn('Done parsing CommandLine');
11372
 
      {$ifndef darwin}
11373
 
      ExeName := AppendPathDelim(StartLazProcess.CurrentDirectory) +
 
12493
      {$ifdef darwin}
 
12494
      ExeName := AppendPathDelim(EnvironmentOptions.GetParsedLazarusDirectory)+
 
12495
             DarwinStartlazBundlePath + 'startlazarus';
 
12496
      {$else}
 
12497
      ExeName := AppendPathDelim(EnvironmentOptions.GetParsedLazarusDirectory) +
11374
12498
        'startlazarus' + GetExecutableExt;
11375
 
      {$else}
11376
 
      ExeName := ExpandUNCFileNameUTF8(StartLazProcess.CurrentDirectory);
11377
 
      ExeName := AppendPathDelim( ExtractFilePath(ExeName) ) +
11378
 
             DarwinStartlazBundlePath + 'startlazarus' + GetExecutableExt;
11379
12499
      {$endif}
11380
12500
      if not FileExistsUTF8(ExeName) then begin
11381
12501
        IDEMessageDialog('Error',Format(lisCannotFindLazarusStarter,
11384
12504
      end;
11385
12505
      //DebugLn('Setting CommandLine');
11386
12506
      CmdLine := ExeName +
11387
 
         ' --lazarus-pid='+IntToStr(GetProcessID) + ' '                                                   +
 
12507
         ' --lazarus-pid='+IntToStr(GetProcessID) + ' '+
11388
12508
         GetCommandLineParameters(Params, False);
11389
12509
 
11390
12510
      DebugLn('CommandLine 1 : %s', [CmdLine]);
11405
12525
var CanClose: boolean;
11406
12526
begin
11407
12527
  DebugLn(['TMainIDE.DoRestart ']);
 
12528
  CompileProgress.Close;
11408
12529
  CanClose:=true;
11409
12530
  MainIDEBar.OnCloseQuery(Self, CanClose);
11410
12531
  if not CanClose then exit;
11431
12552
    ProjectLoaded:=Project1<>nil;
11432
12553
    DebugLn(['TMainIDE.DoExecuteRemoteControl.OpenFiles ProjectLoaded=',ProjectLoaded]);
11433
12554
 
11434
 
    // open project
11435
 
    if (Files<>nil) and (Files.Count>0) then begin
 
12555
    // open project (only the last in the list)
 
12556
    AProjectFilename:='';
 
12557
    for i:=Files.Count-1 downto 0 do begin
11436
12558
      AProjectFilename:=Files[0];
11437
12559
      if (CompareFileExt(AProjectFilename,'.lpr',false)=0) then
11438
12560
        AProjectFilename:=ChangeFileExt(AProjectFilename,'.lpi');
11439
12561
      if (CompareFileExt(AProjectFilename,'.lpi',false)=0) then begin
 
12562
        // open a project
 
12563
        Files.Delete(i); // remove from the list
11440
12564
        AProjectFilename:=CleanAndExpandFilename(AProjectFilename);
11441
12565
        if FileExistsUTF8(AProjectFilename) then begin
11442
12566
          DebugLn(['TMainIDE.DoExecuteRemoteControl.OpenFiles AProjectFilename="',AProjectFilename,'"']);
11443
 
          Files.Delete(0);
11444
 
          ProjectLoaded:=(DoOpenProjectFile(AProjectFilename,[])=mrOk);
 
12567
          if (Project1<>nil)
 
12568
          and (CompareFilenames(AProjectFilename,Project1.ProjectInfoFile)=0)
 
12569
          then begin
 
12570
            // project is already open => do not reopen
 
12571
            ProjectLoaded:=true;
 
12572
          end else begin
 
12573
            // open another project
 
12574
            ProjectLoaded:=(DoOpenProjectFile(AProjectFilename,[])=mrOk);
 
12575
          end;
11445
12576
        end;
11446
12577
      end;
11447
12578
    end;
11474
12605
 
11475
12606
var
11476
12607
  Filename: String;
11477
 
  List: TStringList;
 
12608
  List: TStringListUTF8;
11478
12609
  Files: TStrings;
11479
12610
  i: Integer;
 
12611
  CmdShow: Boolean;
11480
12612
begin
11481
12613
  Filename:=GetRemoteControlFilename;
11482
 
  if FileExistsUTF8(Filename) then begin
11483
 
    // the control file exists
11484
 
    if FRemoteControlFileValid then begin
11485
 
      List:=TStringList.Create;
11486
 
      Files:=nil;
 
12614
  if FileExistsUTF8(Filename) and (FRemoteControlFileAge<>FileAgeUTF8(Filename))
 
12615
  then begin
 
12616
    // the control file exists and has changed
 
12617
    List:=TStringListUTF8.Create;
 
12618
    Files:=nil;
 
12619
    try
 
12620
      // load and delete the file
11487
12621
      try
11488
 
        // load and delete the file
11489
 
        try
11490
 
          List.LoadFromFile(UTF8ToSys(Filename));
11491
 
        except
11492
 
          DebugLn(['TMainIDE.DoExecuteRemoteControl reading file failed: ',Filename]);
11493
 
        end;
11494
 
        DeleteFileUTF8(Filename);
11495
 
        FRemoteControlFileValid:=not FileExistsUTF8(Filename);
11496
 
        // execute
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])));
11501
 
        end;
11502
 
        if Files.Count>0 then begin
11503
 
          OpenFiles(Files);
11504
 
        end;
11505
 
      finally
11506
 
        List.Free;
11507
 
        Files.Free;
11508
 
      end;
11509
 
    end else begin
11510
 
      // the last time there was an error (e.g. read/delete failed)
11511
 
      // do not waste time again
 
12622
        List.LoadFromFile(Filename);
 
12623
      except
 
12624
        DebugLn(['TMainIDE.DoExecuteRemoteControl reading file failed: ',Filename]);
 
12625
      end;
 
12626
      DeleteFileUTF8(Filename);
 
12627
      FRemoteControlFileAge:=-1;
 
12628
      // execute
 
12629
      Files:=TStringList.Create;
 
12630
      CmdShow:=false;
 
12631
      for i:=0 to List.Count-1 do begin
 
12632
        if SysUtils.CompareText(List[i],'show')=0 then
 
12633
          CmdShow:=true;
 
12634
        if SysUtils.CompareText(copy(List[i],1,5),'open ')=0 then
 
12635
          Files.Add(copy(List[i],6,length(List[i])));
 
12636
      end;
 
12637
      if CmdShow then begin
 
12638
        // if minimized then restore, bring IDE to front
 
12639
        Application.MainForm.ShowOnTop;
 
12640
      end;
 
12641
      if Files.Count>0 then begin
 
12642
        OpenFiles(Files);
 
12643
      end;
 
12644
    finally
 
12645
      List.Free;
 
12646
      Files.Free;
11512
12647
    end;
11513
12648
  end else begin
11514
12649
    // the control file does not exist
11515
 
    // => remember the good state
11516
 
    FRemoteControlFileValid:=true;
 
12650
    FRemoteControlFileAge:=-1;
11517
12651
  end;
11518
12652
end;
11519
12653
 
11520
12654
//-----------------------------------------------------------------------------
11521
12655
 
11522
 
function TMainIDE.DoRunExternalTool(Index: integer; ShowAbort: Boolean
11523
 
  ): TModalResult;
 
12656
function TMainIDE.DoRunExternalTool(Index: integer; ShowAbort: Boolean): TModalResult;
11524
12657
begin
11525
12658
  SourceEditorManager.ClearErrorLines;
11526
 
  Result:=EnvironmentOptions.ExternalTools.Run(Index,GlobalMacroList,ShowAbort);
 
12659
  Result:=ExternalTools.Run(Index,GlobalMacroList,ShowAbort);
11527
12660
  DoCheckFilesOnDisk;
11528
12661
end;
11529
12662
 
11532
12665
  PkgOptions: string;
11533
12666
  InheritedOptionStrings: TInheritedCompOptsStrings;
11534
12667
  FPCVersion, FPCRelease, FPCPatch: integer;
11535
 
  IDEBuildFlags: TBuildLazarusFlags;
11536
12668
begin
11537
12669
  // create uses section addition for lazarus.pp
11538
12670
  Result:=PkgBoss.DoSaveAutoInstallConfig;
11540
12672
 
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);
11548
12678
 
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 ;
11554
 
  end;
 
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 ;
11555
12684
 
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;
11561
12689
end;
11562
12690
 
 
12691
function TMainIDE.DoManageExamples: TModalResult;
 
12692
begin
 
12693
  Result:=ShowManageExamplesDlg;
 
12694
end;
 
12695
 
11563
12696
function TMainIDE.DoBuildLazarusSub(Flags: TBuildLazarusFlags): TModalResult;
11564
12697
var
11565
12698
  PkgOptions: string;
11567
12700
  InheritedOptionStrings: TInheritedCompOptsStrings;
11568
12701
  CompiledUnitExt: String;
11569
12702
  FPCVersion, FPCRelease, FPCPatch: integer;
11570
 
  OnlyBase: boolean;
 
12703
  PkgCompileFlags: TPkgCompileFlags;
 
12704
  ProfileChanged: Boolean;
11571
12705
begin
11572
12706
  if ToolStatus<>itNone then begin
11573
 
    MessageDlg(lisNotNow,
 
12707
    IDEMessageDialog(lisNotNow,
11574
12708
      lisYouCanNotBuildLazarusWhileDebuggingOrCompiling,
11575
 
      mtError,[mbCancel],0);
 
12709
      mtError,[mbCancel]);
11576
12710
    Result:=mrCancel;
11577
12711
    exit;
11578
12712
  end;
11584
12718
  end;
11585
12719
 
11586
12720
  MessagesView.BeginBlock;
 
12721
  ProfileChanged:=false;
 
12722
  with MiscellaneousOptions do
11587
12723
  try
11588
12724
    MainBuildBoss.SetBuildTargetIDE;
11589
12725
 
11590
 
    // first compile all lazarus components (LCL, SynEdit, CodeTools, ...)
11591
 
    // but not the IDE
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.');
11601
 
      Result:=mrIgnore;
11602
 
      exit;
11603
 
    end;
11604
 
 
11605
 
    // then compile the 'installed' packages
11606
 
    if (not (blfOnlyIDE in Flags))
11607
 
    and (MiscellaneousOptions.BuildLazProfiles.CurrentIdeMode=mmNone) then begin
11608
 
      CompileProgress.Ready;
11609
 
      Result:=mrIgnore;
11610
 
      exit;
11611
 
    end;
11612
 
 
11613
 
    OnlyBase:=not ((blfWithStaticPackages in Flags)
11614
 
                   or MiscellaneousOptions.BuildLazOpts.WithStaticPackages);
11615
 
 
11616
 
    // prepare static auto install packages
11617
 
    PkgOptions:='';
 
12726
    // clean up
 
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],
 
12736
                             ProfileChanged);
 
12737
        if Result<>mrOk then begin
 
12738
          DebugLn('TMainIDE.DoBuildLazarus: Clean all failed.');
 
12739
          exit;
 
12740
        end;
 
12741
      end;
 
12742
    end;
 
12743
 
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.');
11622
12748
      exit;
11623
12749
    end;
11624
12750
 
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.');
11630
 
        exit;
11631
 
      end;
 
12752
    Result:=PkgBoss.DoSaveAutoInstallConfig;
 
12753
    if Result<>mrOk then begin
 
12754
      DebugLn('TMainIDE.DoBuildLazarus: Save AutoInstall Config failed.');
 
12755
      exit;
11632
12756
    end;
11633
12757
 
11634
12758
    // create inherited compiler options
11635
 
    if OnlyBase then
11636
 
      PkgOptions:=''
11637
 
    else
11638
 
      PkgOptions:=PackageGraph.GetIDEInstallPackageOptions(
 
12759
    PkgOptions:=PackageGraph.GetIDEInstallPackageOptions(
11639
12760
                PackageGraph.FirstAutoInstallDependency,InheritedOptionStrings);
11640
12761
 
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
11654
12774
    end;
11655
12775
 
11656
12776
    // save extra options
11657
 
    IDEBuildFlags:=Flags+[blfOnlyIDE];
11658
 
    if not OnlyBase then
11659
 
    begin
11660
 
      Result:=SaveIDEMakeOptions(MiscellaneousOptions.BuildLazProfiles,
11661
 
                                 GlobalMacroList,PkgOptions,IDEBuildFlags);
11662
 
      if Result<>mrOk then begin
11663
 
        DebugLn('TMainIDE.DoBuildLazarus: Save IDEMake options failed.');
11664
 
        exit;
11665
 
      end;
 
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.');
 
12782
      exit;
11666
12783
    end;
11667
12784
 
11668
 
    // make ide
 
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]
11675
 
                         );
 
12787
    IDEBuildFlags:=IDEBuildFlags+[blfUseMakeIDECfg,blfDontClean];
 
12788
    Result:=MakeLazarus(BuildLazProfiles.Current,ExternalTools,GlobalMacroList,
 
12789
                         PkgOptions,EnvironmentOptions.GetParsedCompilerFilename,
 
12790
                         EnvironmentOptions.GetParsedMakeFilename,IDEBuildFlags,
 
12791
                         ProfileChanged);
11676
12792
    if Result<>mrOk then exit;
11677
12793
 
 
12794
    if ProfileChanged then
 
12795
      MiscellaneousOptions.Save;
11678
12796
  finally
11679
 
    MainBuildBoss.SetBuildTarget('','','',bmsfsBackground);
 
12797
    MainBuildBoss.SetBuildTargetProject1(true);
11680
12798
 
11681
12799
    DoCheckFilesOnDisk;
11682
12800
    MessagesView.EndBlock;
11688
12806
  end;
11689
12807
end;
11690
12808
 
 
12809
function TMainIDE.ExternalTools: TExternalToolList;
 
12810
begin
 
12811
  Result:=TExternalToolList(EnvironmentOptions.ExternalTools);
 
12812
end;
 
12813
 
11691
12814
function TMainIDE.DoBuildLazarus(Flags: TBuildLazarusFlags): TModalResult;
11692
12815
begin
11693
12816
  Result:=DoBuildLazarusSub(Flags);
11695
12818
    if (Result=mrOK) then begin
11696
12819
      if BuildLazProfiles.RestartAfterBuild
11697
12820
      and (BuildLazProfiles.Current.TargetDirectory='')
11698
 
      and ((blfWithStaticPackages in Flags) or MainBuildBoss.BuildTargetIDEIsDefault)
 
12821
      and MainBuildBoss.BuildTargetIDEIsDefault
11699
12822
      then begin
11700
 
        CompileProgress.Close;
11701
12823
        mnuRestartClicked(nil);
11702
12824
      end
11703
12825
    end
11723
12845
        if ProfInd<>-1 then begin
11724
12846
          // Set current profile temporarily, used by the codetools functions.
11725
12847
          BuildLazProfiles.CurrentIndex:=ProfInd;
11726
 
// does not show message: IDEMessagesWindow.AddMsg('Building: '+BuildLazProfiles.Current.Name,'',-1);
 
12848
          // does not show message: IDEMessagesWindow.AddMsg('Building: '+BuildLazProfiles.Current.Name,'',-1);
11727
12849
          LazSrcTemplate:=
11728
12850
            CodeToolBoss.DefineTree.FindDefineTemplateByName(StdDefTemplLazarusSources,true);
11729
12851
          if Assigned(LazSrcTemplate) then begin
11827
12949
      ExtTool.CmdLineParams:=Params;
11828
12950
 
11829
12951
      // run
11830
 
      Result:=EnvironmentOptions.ExternalTools.Run(ExtTool,GlobalMacroList,true);
 
12952
      Result:=ExternalTools.Run(ExtTool,GlobalMacroList,true);
11831
12953
    finally
11832
12954
      // clean up
11833
12955
      ExtTool.Free;
11847
12969
var
11848
12970
  ActiveSrcEdit: TSourceEditor;
11849
12971
  ActiveUnitInfo: TUnitInfo;
 
12972
  FirstLine: String;
 
12973
  HasShebang: Boolean;
11850
12974
  RunFlags: TIDEDirRunFlags;
 
12975
  DefRunFlags: TIDEDirRunFlags;
11851
12976
  AlwaysBuildBeforeRun: boolean;
11852
12977
  RunWorkingDir: String;
 
12978
  DefRunCommand: String;
11853
12979
  RunCommand: String;
11854
12980
  ProgramFilename: string;
11855
12981
  Params: string;
11869
12995
    Result:=GetIDEDirectives(ActiveUnitInfo,DirectiveList);
11870
12996
    if Result<>mrOk then exit;
11871
12997
 
 
12998
    if ActiveUnitInfo.Source.LineCount>0 then
 
12999
      FirstLine:=ActiveUnitInfo.Source.GetLine(0)
 
13000
    else
 
13001
      FirstLine:='';
 
13002
    HasShebang:=copy(FirstLine,1,2)='#!';
 
13003
    DefRunFlags:=IDEDirRunFlagDefValues;
 
13004
    if HasShebang then Exclude(DefRunFlags,idedrfBuildBeforeRun);
11872
13005
    RunFlags:=GetIDEDirRunFlagFromString(
11873
 
                 GetIDEStringDirective(DirectiveList,
11874
 
                                       IDEDirectiveNames[idedRunFlags],''));
 
13006
      GetIDEStringDirective(DirectiveList,IDEDirectiveNames[idedRunFlags],''),
 
13007
      DefRunFlags);
11875
13008
    AlwaysBuildBeforeRun:=idedrfBuildBeforeRun in RunFlags;
11876
13009
    if AlwaysBuildBeforeRun then begin
11877
13010
      Result:=DoBuildFile(true);
11885
13018
      Result:=mrCancel;
11886
13019
      exit;
11887
13020
    end;
 
13021
    if HasShebang then
 
13022
      DefRunCommand:='instantfpc'+ExeExt+' '+ActiveUnitInfo.Filename
 
13023
    else
 
13024
      DefRunCommand:=IDEDirDefaultRunCommand;
11888
13025
    RunCommand:=GetIDEStringDirective(DirectiveList,
11889
13026
                                    IDEDirectiveNames[idedRunCommand],
11890
 
                                    IDEDirDefaultRunCommand);
11891
 
    if (not GlobalMacroList.SubstituteStr(RunCommand))
11892
 
    or (RunCommand='') then begin
11893
 
      Result:=mrCancel;
11894
 
      exit;
11895
 
    end;
 
13027
                                    DefRunCommand);
 
13028
    if (not GlobalMacroList.SubstituteStr(RunCommand)) then
 
13029
      exit(mrCancel);
 
13030
    if (RunCommand='') then
 
13031
      exit(mrCancel);
11896
13032
 
11897
13033
    SourceEditorManager.ClearErrorLines;
11898
13034
 
11914
13050
      ExtTool.CmdLineParams:=Params;
11915
13051
 
11916
13052
      // run
11917
 
      Result:=EnvironmentOptions.ExternalTools.Run(ExtTool,GlobalMacroList,false);
 
13053
      Result:=ExternalTools.Run(ExtTool,GlobalMacroList,false);
11918
13054
    finally
11919
13055
      // clean up
11920
13056
      ExtTool.Free;
12029
13165
    if OpenDialog.Execute and (OpenDialog.Files.Count>0) then begin
12030
13166
      For I := 0 to OpenDialog.Files.Count-1 do begin
12031
13167
        AFilename:=ExpandFileNameUTF8(OpenDialog.Files.Strings[i]);
12032
 
        DFMConverter:=TDFMConverter.Create;
 
13168
        DFMConverter:=TDFMConverter.Create(nil);
12033
13169
        try
12034
13170
          Result:=DFMConverter.Convert(AFilename);
12035
13171
        finally
12062
13198
  begin
12063
13199
    if not Quiet then
12064
13200
    begin
12065
 
      MessageDlg(lisNoLFMFile,
 
13201
      IDEMessageDialog(lisNoLFMFile,
12066
13202
        lisThisFunctionNeedsAnOpenLfmFileInTheSourceEditor,
12067
 
        mtError,[mbCancel],0);
 
13203
        mtError,[mbCancel]);
12068
13204
    end;
12069
13205
    Result:=mrCancel;
12070
13206
    exit;
12078
13214
      UnitFilename:='';
12079
13215
  end;
12080
13216
  if UnitFilename='' then begin
12081
 
    MessageDlg(lisNoPascalFile,
 
13217
    IDEMessageDialog(lisNoPascalFile,
12082
13218
      Format(lisUnableToFindPascalUnitPasPpForLfmFile, [#13, '"',
12083
13219
        LFMUnitInfo.Filename, '"']),
12084
 
      mtError,[mbCancel],0);
 
13220
      mtError,[mbCancel]);
12085
13221
    Result:=mrCancel;
12086
13222
    exit;
12087
13223
  end;
12107
13243
  try
12108
13244
    LFMChecker.RootMustBeClassInUnit:=true;
12109
13245
    LFMChecker.RootMustBeClassInIntf:=true;
12110
 
    LFMChecker.ObjectsMustExists:=true;
 
13246
    LFMChecker.ObjectsMustExist:=true;
12111
13247
    if LFMChecker.Repair=mrOk then begin
12112
13248
      if not Quiet then begin
12113
13249
        IDEMessageDialog(lisLFMIsOk,
12212
13348
    Index:=0;
12213
13349
    while (i<itmCustomTools.Count) do begin
12214
13350
      CurMenuItem:=itmCustomTools[i];
12215
 
      ExtTool:=EnvironmentOptions.ExternalTools[Index];
 
13351
      ExtTool:=ExternalTools[Index];
12216
13352
      CurMenuItem.Caption:=ExtTool.Title;
12217
13353
      if CurMenuItem is TIDEMenuCommand then
12218
13354
        TIDEMenuCommand(CurMenuItem).Command:=
12224
13360
  end;
12225
13361
 
12226
13362
begin
12227
 
  ToolCount:=EnvironmentOptions.ExternalTools.Count;
 
13363
  ToolCount:=ExternalTools.Count;
12228
13364
  CreateToolMenuItems;
12229
13365
  SetToolMenuItems;
12230
13366
end;
12241
13377
    Result:=DebugBoss.DoStopProject;
12242
13378
    if Result<>mrOk then exit;
12243
13379
  end;
 
13380
 
 
13381
  if MainBuildBoss.CompilerOnDiskChanged then
 
13382
    MainBuildBoss.RescanCompilerDefines(false,false,false,false);
12244
13383
end;
12245
13384
 
12246
13385
function TMainIDE.OnRunExternalTool(Tool: TIDEExternalToolOptions): TModalResult;
12247
13386
begin
12248
13387
  SourceEditorManager.ClearErrorLines;
12249
 
  Result:=EnvironmentOptions.ExternalTools.Run(Tool,GlobalMacroList,false);
 
13388
  Result:=ExternalTools.Run(Tool,GlobalMacroList,false);
12250
13389
  DoCheckFilesOnDisk;
12251
13390
end;
12252
13391
 
12399
13538
 
12400
13539
function TMainIDE.DoLoadMemoryStreamFromFile(MemStream: TMemoryStream;
12401
13540
  const AFilename:string): TModalResult;
12402
 
var FileStream: TFileStream;
 
13541
var
 
13542
  FileStream: TFileStreamUTF8;
12403
13543
  ACaption,AText:string;
12404
13544
begin
12405
13545
  repeat
12406
13546
    try
12407
 
      FileStream:=TFileStream.Create(UTF8ToSys(AFilename),fmOpenRead);
 
13547
      FileStream:=TFileStreamUTF8.Create(AFilename,fmOpenRead);
12408
13548
      try
12409
13549
        FileStream.Position:=0;
12410
13550
        MemStream.CopyFrom(FileStream,FileStream.Size);
12429
13569
  OldShortFilename: String;
12430
13570
  NewFilename: String;
12431
13571
  NewShortFilename: String;
12432
 
  ResourceCode: TCodeBuffer;
 
13572
  LFMCode, LRSCode: TCodeBuffer;
12433
13573
  NewUnitName: String;
12434
13574
begin
12435
13575
  Result:=mrOk;
12456
13596
    AnUnitInfo.ReadUnitNameFromSource(false);
12457
13597
    NewUnitName:=AnUnitInfo.CreateUnitName;
12458
13598
  end;
12459
 
  ResourceCode:=nil;
12460
 
  Result:=DoRenameUnit(AnUnitInfo,NewFilename,NewUnitName,ResourceCode);
 
13599
  LFMCode:=nil;
 
13600
  LRSCode:=nil;
 
13601
  Result:=DoRenameUnit(AnUnitInfo,NewFilename,NewUnitName,LFMCode,LRSCode);
12461
13602
end;
12462
13603
 
12463
13604
function TMainIDE.DoCheckFilesOnDisk(Instantaneous: boolean): TModalResult;
12485
13626
    InvalidateFileStateCache;
12486
13627
 
12487
13628
    if Project1.HasProjectInfoFileChangedOnDisk then begin
12488
 
      if QuestionDlg(lisProjectChangedOnDisk,
 
13629
      if IDEQuestionDialog(lisProjectChangedOnDisk,
12489
13630
        Format(lisTheProjectInformationFileHasChangedOnDisk, ['"',
12490
13631
          Project1.ProjectInfoFile, '"', #13]), mtConfirmation, [mrYes,
12491
13632
            lisReopenProject, mrIgnore], '')
12553
13694
 
12554
13695
  procedure ShowErrorForCommandAfter;
12555
13696
  begin
12556
 
    MessageDlg(lisInvalidCommand,
 
13697
    IDEMessageDialog(lisInvalidCommand,
12557
13698
      Format(lisTheCommandAfterIsNotExecutable, ['"', CmdAfterExe, '"']),
12558
 
      mtError,[mbCancel],0);
 
13699
      mtError,[mbCancel]);
12559
13700
  end;
12560
13701
 
12561
13702
begin
12563
13704
  Result:=mrCancel;
12564
13705
 
12565
13706
  // do not delete project files
12566
 
  DestDir:=TrimFilename(AppendPathDelim(DestDirectory));
12567
 
  SrcDir:=TrimFilename(AppendPathDelim(SrcDirectory));
 
13707
  DestDir:=TrimAndExpandDirectory(DestDirectory);
 
13708
  SrcDir:=TrimAndExpandDirectory(SrcDirectory);
12568
13709
  if (DestDir='') then begin
12569
 
    MessageDlg('Invalid publishing Directory',
 
13710
    IDEMessageDialog('Invalid publishing Directory',
12570
13711
      'Destination directory for publishing is empty.',mtError,
12571
 
      [mbCancel],0);
 
13712
      [mbCancel]);
12572
13713
    Result:=mrCancel;
12573
13714
    exit;
12574
13715
  end;
12575
13716
  //DebugLn('TMainIDE.DoPublishModule A SrcDir="',SrcDir,'" DestDir="',DestDir,'"');
12576
 
  if CompareFilenames(CleanAndExpandDirectory(SrcDir),
12577
 
                      CleanAndExpandDirectory(DestDir))=0
 
13717
  if CompareFilenames(SrcDir,DestDir)=0
12578
13718
  then begin
12579
 
    MessageDlg(lisInvalidPublishingDirectory,
 
13719
    IDEMessageDialog(lisInvalidPublishingDirectory,
12580
13720
      Format(lisSourceDirectoryAndDestinationDirectoryAreTheSameMa, ['"',
12581
13721
        SrcDir, '"', #13, '"', DestDir, '"', #13, #13, #13, #13, #13]),
12582
 
        mtError, [mbCancel], 0);
 
13722
        mtError, [mbCancel]);
12583
13723
    Result:=mrCancel;
12584
13724
    exit;
12585
13725
  end;
12605
13745
        CmdAfterExe:=TempCmd;
12606
13746
    end;
12607
13747
    if not FileIsExecutableCached(CmdAfterExe) then begin
12608
 
      MessageDlg(lisCommandAfterInvalid,
 
13748
      IDEMessageDialog(lisCommandAfterInvalid,
12609
13749
        Format(lisTheCommandAfterPublishingIsInvalid, [#13, '"', CmdAfterExe,
12610
 
          '"']), mtError, [mbCancel], 0);
 
13750
          '"']), mtError, [mbCancel]);
12611
13751
      Result:=mrCancel;
12612
13752
      exit;
12613
13753
    end;
12616
13756
  // clear destination directory
12617
13757
  if DirPathExists(DestDir) then begin
12618
13758
    // ask user, if destination can be delete
12619
 
    if MessageDlg(lisClearDirectory,
 
13759
    if IDEMessageDialog(lisClearDirectory,
12620
13760
      Format(lisInOrderToCreateACleanCopyOfTheProjectPackageAllFil, [#13, #13,
12621
13761
        '"', DestDir, '"']), mtConfirmation,
12622
 
      [mbYes,mbNo],0)<>mrYes
 
13762
      [mbYes,mbNo])<>mrYes
12623
13763
    then
12624
13764
      exit(mrCancel);
12625
13765
 
12626
13766
    if (not DeleteDirectory(ChompPathDelim(DestDir),true)) then begin
12627
 
      MessageDlg(lisUnableToCleanUpDestinationDirectory,
 
13767
      IDEMessageDialog(lisUnableToCleanUpDestinationDirectory,
12628
13768
        Format(lisUnableToCleanUpPleaseCheckPermissions, ['"', DestDir, '"', #13]
12629
13769
          ),
12630
 
        mtError,[mbOk],0);
 
13770
        mtError,[mbOk]);
12631
13771
      Result:=mrCancel;
12632
13772
      exit;
12633
13773
    end;
12648
13788
    NewProjectFilename:=DestDir+ExtractFilename(CurProject.ProjectInfoFile);
12649
13789
    DeleteFileUTF8(NewProjectFilename);
12650
13790
    Result:=CurProject.WriteProject(CurProject.PublishOptions.WriteFlags
12651
 
           +[pwfSkipDebuggerSettings,pwfSkipJumpPoints,pwfDoNotSaveSessionInfo,
12652
 
             pwfIgnoreModified],
 
13791
           +pwfSkipSessionInfo+[pwfIgnoreModified],
12653
13792
           NewProjectFilename);
12654
13793
    if Result<>mrOk then begin
12655
13794
      debugln('TMainIDE.DoPublishModule CurProject.WriteProject failed');
12665
13804
      Tool.Title:=lisCommandAfterPublishingModule;
12666
13805
      Tool.WorkingDirectory:=DestDir;
12667
13806
      Tool.CmdLineParams:=CmdAfterParams;
12668
 
      Result:=EnvironmentOptions.ExternalTools.Run(Tool,GlobalMacroList,false);
 
13807
      Result:=ExternalTools.Run(Tool,GlobalMacroList,false);
12669
13808
      if Result<>mrOk then exit;
12670
13809
    end else begin
12671
13810
      ShowErrorForCommandAfter;
12675
13814
  end;
12676
13815
end;
12677
13816
 
 
13817
procedure TMainIDE.PrepareBuildTarget(Quiet: boolean;
 
13818
  ScanFPCSrc: TScanModeFPCSources);
 
13819
begin
 
13820
  MainBuildBoss.SetBuildTargetProject1(Quiet,ScanFPCSrc);
 
13821
end;
 
13822
 
12678
13823
procedure TMainIDE.AbortBuild;
12679
13824
begin
12680
13825
  if TheOutputFilter<>nil then
12706
13851
  begin
12707
13852
    if Project1 <> nil then
12708
13853
    begin
12709
 
      ProjectName := Project1.Title;
12710
 
      if (ProjectName = '') and (Project1.ProjectInfoFile <> '') then
12711
 
        ProjectName := ExtractFileName(Project1.ProjectInfoFile);
 
13854
      ProjectName := Project1.GetTitleOrName;
12712
13855
      if ProjectName <> '' then
12713
13856
      begin
12714
13857
        if EnvironmentOptions.IDEProjectDirectoryInIdeTitle then
12743
13886
  i: Integer;
12744
13887
  AForm: TCustomForm;
12745
13888
begin
 
13889
  {$IFDEF DEBUGHIDEIDEWINDOWSONRUN}
 
13890
  DebugLn('TMainIDE.HideIDE ENTERED HiddenWindowsOnRun.Count=',dbgs(HiddenWindowsOnRun.Count),
 
13891
  ' LastFormActivated ',dbgsName(LastFormActivated),
 
13892
  ' WindowMenuActive ',dbgsName(WindowMenuActiveForm));
 
13893
  {$ENDIF}
 
13894
 
12746
13895
  // hide hints
12747
13896
  Application.HideHint;
12748
13897
  SourceEditorManager.HideHint;
12749
13898
 
12750
13899
  // hide designer forms
12751
 
  HideUnmodifiedDesigners;
 
13900
  // HideUnmodifiedDesigners;
12752
13901
 
12753
13902
  // collect all windows except the main bar
12754
 
  for i:=0 to Screen.CustomFormCount-1 do begin
 
13903
  for i:=0 to Screen.CustomFormCount-1 do
 
13904
  begin
12755
13905
    AForm:=Screen.CustomForms[i];
12756
13906
    if (AForm.Parent=nil)                     // ignore nested forms
12757
13907
    and (AForm<>MainIDEBar)                   // ignore the main bar
12758
 
    and (AForm.Designer=nil)                  // ignore designer forms
12759
 
    and (not (csDesigning in AForm.ComponentState))
12760
13908
    and (AForm.IsVisible)                     // ignore hidden forms
12761
13909
    and (not (fsModal in AForm.FormState))    // ignore modal forms
12762
13910
    and (HiddenWindowsOnRun.IndexOf(AForm)<0) // ignore already collected forms
12765
13913
  end;
12766
13914
 
12767
13915
  // hide all collected windows
12768
 
  for i:=0 to HiddenWindowsOnRun.Count-1 do begin
 
13916
  for i:=0 to HiddenWindowsOnRun.Count-1 do
 
13917
  begin
12769
13918
    AForm:=TCustomForm(HiddenWindowsOnRun[i]);
12770
 
    AForm.Hide;
 
13919
    if (AForm.Designer <> nil) or (csDesigning in AForm.ComponentState) then
 
13920
    begin
 
13921
      {$IFDEF DEBUGHIDEIDEWINDOWSONRUN}
 
13922
      DebugLn('TMainIDE.HideIDE: HIDING VIA LCLINTF ',dbgsName(AForm),' WindowState ',dbgs(AForm.WindowState),
 
13923
      ' IsIconic ',dbgs(LCLIntf.IsIconic(AForm.Handle)));
 
13924
      {$ENDIF}
 
13925
      LCLIntf.ShowWindow(AForm.Handle, SW_HIDE);
 
13926
    end else
 
13927
    begin
 
13928
      {$IFDEF DEBUGHIDEIDEWINDOWSONRUN}
 
13929
      DebugLn('TMainIDE.HideIDE: HIDING NON DESIGNED FORM ',dbgsName(AForm));
 
13930
      {$ENDIF}
 
13931
      AForm.Hide;
 
13932
    end;
12771
13933
  end;
12772
13934
 
12773
13935
  // minimize IDE
12774
13936
  MainIDEBar.HideIDE;
 
13937
  {$IFDEF DEBUGHIDEIDEWINDOWSONRUN}
 
13938
  DebugLn('TMainIDE.HideIDE EXITED ');
 
13939
  {$ENDIF}
12775
13940
end;
12776
13941
 
12777
13942
procedure TMainIDE.HideUnmodifiedDesigners;
12791
13956
procedure TMainIDE.UnhideIDE;
12792
13957
var
12793
13958
  AForm: TCustomForm;
 
13959
  i: Integer;
 
13960
  AActiveForm: TCustomForm;
12794
13961
begin
 
13962
  {$IFDEF DEBUGHIDEIDEWINDOWSONRUN}
 
13963
  DebugLn('TMainIDE.UnhideIDE  Active=',dbgsName(WindowMenuActiveForm));
 
13964
  {$ENDIF}
 
13965
  AActiveForm := WindowMenuActiveForm;
12795
13966
  // unminimize IDE
12796
13967
  MainIDEBar.UnhideIDE;
12797
13968
 
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)
12803
 
    else
 
13969
  // show other windows but keep order as it was before hiding.
 
13970
  for i := HiddenWindowsOnRun.Count - 1 downto 0 do
 
13971
  begin
 
13972
    AForm:=TCustomForm(HiddenWindowsOnRun[i]);
 
13973
    if (csDesigning in AForm.ComponentState) or (AForm.Designer <> nil) then
 
13974
    begin
 
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)));
 
13979
      {$ENDIF}
 
13980
      if LCLIntf.IsIconic(AForm.Handle) then
 
13981
        LCLIntf.ShowWindow(AForm.Handle, SW_SHOWMINIMIZED)
 
13982
      else
 
13983
        LCLIntf.ShowWindow(AForm.Handle, SW_SHOWNORMAL);
 
13984
      // ShowDesignerForm(AForm)
 
13985
    end else
 
13986
    begin
 
13987
      {$IFDEF DEBUGHIDEIDEWINDOWSONRUN}
 
13988
      DebugLn('TMainIDE.UnhideIDE: Showing AForm ',dbgsName(AForm));
 
13989
      {$ENDIF}
12804
13990
      AForm.Show;
12805
 
    HiddenWindowsOnRun.Delete(0);
 
13991
    end;
12806
13992
  end;
 
13993
  HiddenWindowsOnRun.Clear;
 
13994
  {$IFDEF DEBUGHIDEIDEWINDOWSONRUN}
 
13995
  DebugLn('TMainIDE.UnhideIDE: activating form ',dbgsName(AActiveForm));
 
13996
  {$ENDIF}
 
13997
  {activate form or app, must be so because of debugmanager !}
 
13998
  if Assigned(AActiveForm) then
 
13999
    AActiveForm.BringToFront
 
14000
  else
 
14001
    Application.BringToFront;
12807
14002
end;
12808
14003
 
12809
14004
procedure TMainIDE.DoBringToFrontFormOrUnit;
12816
14011
end;
12817
14012
 
12818
14013
procedure TMainIDE.DoBringToFrontFormOrInspector(ForceInspector: boolean);
12819
 
 
12820
 
  procedure ShowInspector;
12821
 
  begin
12822
 
    if ObjectInspector1=nil then exit;
12823
 
    IDEWindowCreators.ShowForm(ObjectInspector1,true);
12824
 
    if ObjectInspector1.IsVisible then
12825
 
    begin
12826
 
      ObjectInspector1.FocusGrid;
12827
 
      if FDisplayState <> high(TDisplayState) then
12828
 
        FDisplayState:= Succ(FDisplayState);
12829
 
    end;
12830
 
  end;
12831
 
 
12832
14014
begin
12833
14015
  if ForceInspector then begin
12834
 
    ShowInspector;
 
14016
    DoShowInspector(true);
12835
14017
    exit;
12836
14018
  end;
12837
14019
  case FDisplayState of
12843
14025
      DoShowSourceOfActiveDesignerForm;
12844
14026
 
12845
14027
    else
12846
 
      ShowInspector;
 
14028
      DoShowInspector(true);
12847
14029
  end;
12848
14030
end;
12849
14031
 
12852
14034
  ActiveSourceEditor: TSourceEditor;
12853
14035
  ActiveUnitInfo: TUnitInfo;
12854
14036
  AForm: TCustomForm;
 
14037
  UnitCodeBuf: TCodeBuffer;
12855
14038
begin
12856
14039
  GetCurrentUnit(ActiveSourceEditor,ActiveUnitInfo);
12857
14040
  if (ActiveUnitInfo = nil) then exit;
 
14041
 
 
14042
  if (ActiveUnitInfo.Component=nil)
 
14043
  and (ActiveUnitInfo.Source<>nil)
 
14044
  and (CompareFileExt(ActiveUnitInfo.Filename,'.inc',false)=0) then begin
 
14045
    // include file => get unit
 
14046
    UnitCodeBuf:=CodeToolBoss.GetMainCode(ActiveUnitInfo.Source);
 
14047
    if (UnitCodeBuf<>nil) and (UnitCodeBuf<>ActiveUnitInfo.Source) then begin
 
14048
      // unit found
 
14049
      ActiveUnitInfo:=Project1.ProjectUnitWithFilename(UnitCodeBuf.Filename);
 
14050
      if (ActiveUnitInfo=nil) or (ActiveUnitInfo.OpenEditorInfoCount=0) then begin
 
14051
        // open unit in source editor and load form
 
14052
        DoOpenEditorFile(UnitCodeBuf.Filename,-1,-1,
 
14053
          [ofOnlyIfExists,ofRegularFile,ofVirtualFile,ofDoLoadResource]);
 
14054
        exit;
 
14055
      end;
 
14056
    end;
 
14057
  end;
 
14058
 
12858
14059
  // load the form, if not already done
12859
14060
  AForm:=GetDesignerFormOfSource(ActiveUnitInfo,true);
12860
14061
  if AForm=nil then exit;
12884
14085
  FDisplayState:= dsSource;
12885
14086
end;
12886
14087
 
12887
 
procedure TMainIDE.OnMacroSubstitution(TheMacro: TTransferMacro;
12888
 
  const MacroName: string; var s:string;
12889
 
  const Data: PtrInt; var Handled, Abort: boolean; Depth: integer);
12890
 
var MacroLName:string;
12891
 
begin
12892
 
  if TheMacro=nil then begin
12893
 
    DebugLn('WARNING: Macro not defined: "'+MacroName+'".');
12894
 
    s:='';
12895
 
    //MessageDlg('Unknown Macro','Macro not defined: "'+s+'".',mtError,[mbAbort],0);
12896
 
    //DumpStack;
12897
 
    Handled:=true;
12898
 
    exit;
12899
 
  end;
12900
 
  MacroLName:=lowercase(MacroName);
12901
 
  Handled:=true;
12902
 
  if MacroLName='save' then begin
12903
 
    if (SourceEditorManager<>nil) and (SourceEditorManager.SourceEditorCount > 0) then
12904
 
      Abort:=(DoSaveEditorFile(SourceEditorManager.ActiveEditor,
12905
 
        [sfCheckAmbiguousFiles]) <> mrOk);
12906
 
    s:='';
12907
 
  end else if MacroLName='saveall' then begin
12908
 
    Abort:=(DoSaveAll([sfCheckAmbiguousFiles])<>mrOk);
12909
 
    s:='';
12910
 
  end else
12911
 
    Handled:=false;
12912
 
end;
12913
 
 
12914
14088
procedure TMainIDE.GetIDEFileState(Sender: TObject; const AFilename: string;
12915
14089
  NeededFlags: TIDEFileStateFlags; out ResultFlags: TIDEFileStateFlags);
12916
14090
var
12938
14112
function GetFPCMessage(ALine: TLazMessageLine; var FileName: String; var CaretPos: TPoint; var ErrType: TFPCErrorType): Boolean;
12939
14113
begin
12940
14114
  Result := Assigned(ALine.Parts);
12941
 
  if Result and (Aline.Filename = '') then
12942
 
    Aline.UpdateSourcePosition;
 
14115
  if Result and (ALine.Filename = '') then
 
14116
    ALine.UpdateSourcePosition;
12943
14117
  FileName:=ALine.Filename;
12944
14118
  CaretPos.x:=ALine.Column;
12945
14119
  CaretPos.y:=ALine.LineNumber;
12950
14124
 
12951
14125
function TMainIDE.DoJumpToCompilerMessage(Index:integer;
12952
14126
  FocusEditor: boolean): boolean;
12953
 
var MaxMessages: integer;
 
14127
var
 
14128
  MaxMessages: integer;
12954
14129
  Filename, SearchedFilename: string;
12955
14130
  LogCaretXY: TPoint;
12956
14131
  TopLine: integer;
12961
14136
  NewFilename: String;
12962
14137
  AnUnitInfo: TUnitInfo;
12963
14138
  AnEditorInfo: TUnitEditorInfo;
 
14139
  MsgLine: TLazMessageLine;
12964
14140
begin
12965
14141
  Result:=false;
12966
14142
 
12971
14147
    Index:=0;
12972
14148
    while (Index<MaxMessages) do begin
12973
14149
      // ParseFPCMessage doesn't support multilingual messages, by GetFPCMessage
12974
 
      if GetFPCMessage(MessagesView.VisibleItems[Index],Filename,LogCaretXY,MsgType) then
 
14150
      MsgLine:=MessagesView.VisibleItems[Index];
 
14151
      if GetFPCMessage(MsgLine,Filename,LogCaretXY,MsgType) then
12975
14152
      begin
12976
14153
        if MsgType in [etError,etFatal,etPanic] then break;
12977
14154
      end;
12985
14162
  if MessagesView.ExecuteMsgLinePlugin(imqfoJump) then exit;
12986
14163
 
12987
14164
  // default: jump to source position
12988
 
  if GetFPCMessage(MessagesView.VisibleItems[Index],Filename,LogCaretXY,MsgType) 
12989
 
  then begin
12990
 
    CurDir:=MessagesView.VisibleItems[Index].Directory;
 
14165
  MsgLine:=MessagesView.VisibleItems[Index];
 
14166
  if GetFPCMessage(MsgLine,Filename,LogCaretXY,MsgType) then begin
 
14167
    //debugln(['TMainIDE.DoJumpToCompilerMessage Index=',Index,' MsgFile=',MsgLine.Filename,' MsgY=',MsgLine.LineNumber,' File=',Filename,' XY=',dbgs(LogCaretXY),' ',MsgLine.Parts.Text]);
 
14168
    CurDir:=MsgLine.Directory;
12991
14169
    if (not FilenameIsAbsolute(Filename)) and (CurDir<>'') then begin
12992
14170
      // the directory was just hidden, re-append it
12993
14171
      NewFilename:=AppendPathDelim(CurDir)+Filename;
13023
14201
        SrcEdit:=SourceEditorManager.ActiveEditor;
13024
14202
        if LogCaretXY.Y>SrcEdit.EditorComponent.Lines.Count then
13025
14203
          LogCaretXY.Y:=SrcEdit.EditorComponent.Lines.Count;
 
14204
        if LogCaretXY.X<1 then
 
14205
          LogCaretXY.X:=1;
13026
14206
        TopLine:=LogCaretXY.Y-(SrcEdit.EditorComponent.LinesInWindow div 2);
13027
14207
        if TopLine<1 then TopLine:=1;
13028
14208
        if FocusEditor then begin
13031
14211
        end;
13032
14212
        SrcEdit.EditorComponent.LogicalCaretXY:=LogCaretXY;
13033
14213
        SrcEdit.EditorComponent.TopLine:=TopLine;
13034
 
        with SrcEdit.EditorComponent do begin
13035
 
          LeftChar:=Max(LogCaretXY.X - (CharsInWindow * 4 div 5),1);
13036
 
        end;
 
14214
        SrcEdit.CenterCursorHoriz(hcmSoftKeepEOL);
13037
14215
        SrcEdit.ErrorLine:=LogCaretXY.Y;
13038
14216
      end;
13039
14217
    end else begin
13040
14218
      if FilenameIsAbsolute(Filename) then begin
13041
 
        MessageDlg(Format(lisUnableToFindFile, ['"', Filename, '"']),
13042
 
           mtInformation,[mbOk],0)
 
14219
        IDEMessageDialog(lisInformation, Format(lisUnableToFindFile, ['"',
 
14220
          Filename, '"']), mtInformation,[mbOk])
13043
14221
      end else if Filename<>'' then begin
13044
 
        MessageDlg(Format(
 
14222
        IDEMessageDialog(lisInformation, Format(
13045
14223
          lisUnableToFindFileCheckSearchPathInProjectCompilerOption, ['"',
13046
14224
          Filename, '"', #13, #13]),
13047
 
           mtInformation,[mbOk],0);
 
14225
          mtInformation,[mbOk]);
13048
14226
      end;
13049
14227
    end;
13050
14228
  end;
13139
14317
        try
13140
14318
          SrcEdit.BeginUpdate;
13141
14319
          SrcEdit.EditorComponent.LogicalCaretXY:=LogCaretXY;
13142
 
          if not SrcEdit.IsLocked then
 
14320
          if not SrcEdit.IsLocked then begin
13143
14321
            SrcEdit.CenterCursor(True);
13144
 
          with SrcEdit.EditorComponent do begin
13145
 
            LeftChar:= Math.Max(LogCaretXY.X - (CharsInWindow * 4 div 5),1);
 
14322
            SrcEdit.CenterCursorHoriz(hcmSoftKeepEOL);
13146
14323
          end;
13147
14324
        finally
13148
14325
          SrcEdit.EndUpdate;
13151
14328
      end;
13152
14329
    end else if AFilename<>'' then begin
13153
14330
      if FilenameIsAbsolute(AFilename) then begin
13154
 
        MessageDlg(Format(lisUnableToFindFile, ['"', AFilename, '"']),
13155
 
           mtInformation,[mbOk],0)
 
14331
        IDEMessageDialog(lisInformation, Format(lisUnableToFindFile, ['"',
 
14332
          AFilename, '"']), mtInformation,[mbOk]);
13156
14333
      end else if AFileName<>'' then begin
13157
 
        MessageDlg(Format(
 
14334
        IDEMessageDialog(lisInformation, Format(
13158
14335
          lisUnableToFindFileCheckSearchPathInProjectCompilerOption, ['"',
13159
14336
          AFilename, '"', #13, #13]),
13160
 
           mtInformation,[mbOk],0);
 
14337
           mtInformation,[mbOk]);
13161
14338
      end;
13162
14339
    end;
13163
14340
  end;//if
13178
14355
    SourceEditorManager.ShowActiveWindowOnTop(False);
13179
14356
end;
13180
14357
 
13181
 
procedure TMainIDE.DoShowSearchResultsView(Show, BringToFront: boolean);
 
14358
procedure TMainIDE.DoShowSearchResultsView(Show: boolean);
13182
14359
begin
13183
 
  //set the event here for the selectionchanged event
13184
 
  if not assigned(SearchresultsView.OnSelectionChanged) then
13185
 
    SearchresultsView.OnSelectionChanged := @SearchresultsViewSelectionChanged;
13186
 
 
13187
 
  if Show and (not SearchResultsView.IsVisible) then
13188
 
  begin
13189
 
    IDEWindowCreators.ShowForm(SearchResultsView,BringToFront);
 
14360
  if SearchresultsView=Nil then begin
 
14361
    SearchresultsView:=TSearchResultsView.Create(OwningComponent);
 
14362
    SearchresultsView.OnSelectionChanged := OnSearchResultsViewSelectionChanged;
 
14363
  end;
 
14364
  if Show then begin
 
14365
    IDEWindowCreators.ShowForm(SearchresultsView,Show);
13190
14366
    // the sourcenotebook is more interesting than the search results
13191
14367
    SourceEditorManager.ShowActiveWindowOnTop(False);
13192
14368
  end;
13229
14405
    UnitInFilename: String;
13230
14406
  begin
13231
14407
    AnUnitName:=ExtractFileNameOnly(AFilename);
13232
 
    BaseDir:=EnvironmentOptions.LazarusDirectory+PathDelim+'ide';
 
14408
    BaseDir:=EnvironmentOptions.GetParsedLazarusDirectory+PathDelim+'ide';
13233
14409
    UnitInFilename:='';
13234
14410
    Result:=CodeToolBoss.DirectoryCachePool.FindUnitSourceInCompletePath(
13235
14411
                                       BaseDir,AnUnitName,UnitInFilename,true);
13343
14519
  compiled unit (.ppu).
13344
14520
  Find the source filename (pascal source or include file) and returns
13345
14521
  the absolute path.
 
14522
  With fsfMapTempToVirtualFiles files in the temp directory are stripped off
 
14523
  the temporary files resulting in the virtual file name of the CodeTools.
13346
14524
 
13347
14525
  First it searches in the current projects src path, then its unit path, then
13348
14526
  its include path. Then all used package source directories are searched.
13460
14638
  {$IFDEF VerboseFindSourceFile}
13461
14639
  debugln(['TMainIDE.FindSourceFile Filename="',AFilename,'" BaseDirectory="',BaseDirectory,'"']);
13462
14640
  {$ENDIF}
 
14641
  if AFilename='' then exit('');
13463
14642
 
13464
14643
  if fsfMapTempToVirtualFiles in Flags then
13465
14644
  begin
13476
14655
  if FilenameIsAbsolute(AFilename) then
13477
14656
  begin
13478
14657
    Result := AFilename;
13479
 
    if not FileExistsUTF8(Result) then
 
14658
    if not FileExistsCached(Result) then
13480
14659
      Result := '';
13481
14660
    Exit;
13482
14661
  end;
13491
14670
  {$IFDEF VerboseFindSourceFile}
13492
14671
  debugln(['TMainIDE.FindSourceFile trying Base "',Result,'"']);
13493
14672
  {$ENDIF}
13494
 
  if FileExistsUTF8(Result) then exit;
 
14673
  if FileExistsCached(Result) then exit;
13495
14674
  MarkPathAsSearched(BaseDir);
13496
14675
 
13497
14676
  // search file in debug path
13498
14677
  if fsfUseDebugPath in Flags then begin
13499
 
    SearchPath:=EnvironmentOptions.DebuggerSearchPath;
13500
 
    GlobalMacroList.SubstituteStr(SearchPath);
 
14678
    SearchPath:=EnvironmentOptions.GetParsedDebuggerSearchPath;
13501
14679
    SearchPath:=MergeSearchPaths(Project1.CompilerOptions.GetDebugPath(false),
13502
14680
                                 SearchPath);
13503
14681
    SearchPath:=TrimSearchPath(SearchPath,BaseDir);
13531
14709
    SearchPath:=TrimSearchPath(SearchPath,BaseDir);
13532
14710
    if SearchInPath(StartUnitPath,AFilename,Result) then exit;
13533
14711
 
13534
 
    // search include file in source directories of all required packages
13535
 
    SearchFile:=AFilename;
13536
 
    Result:=PkgBoss.FindIncludeFileInProjectDependencies(Project1,SearchFile);
13537
 
    {$IFDEF VerboseFindSourceFile}
13538
 
    debugln(['TMainIDE.FindSourceFile trying packages "',SearchPath,'" Result=',Result]);
13539
 
    {$ENDIF}
 
14712
    if not(fsfSkipPackages in Flags) then begin
 
14713
      // search include file in source directories of all required packages
 
14714
      SearchFile:=AFilename;
 
14715
      Result:=PkgBoss.FindIncludeFileInProjectDependencies(Project1,SearchFile);
 
14716
      {$IFDEF VerboseFindSourceFile}
 
14717
      debugln(['TMainIDE.FindSourceFile trying packages "',SearchPath,'" Result=',Result]);
 
14718
      {$ENDIF}
 
14719
    end;
13540
14720
    if Result<>'' then exit;
13541
14721
 
13542
14722
    Result:=SearchIndirectIncludeFile;
13549
14729
function TMainIDE.FileExistsInIDE(const Filename: string;
13550
14730
  SearchFlags: TProjectFileSearchFlags): boolean;
13551
14731
begin
13552
 
  Result:=FileExistsUTF8(Filename)
 
14732
  Result:=FileExistsCached(Filename)
13553
14733
          or (Project1.UnitInfoWithFilename(Filename,SearchFlags)<>nil);
13554
14734
end;
13555
14735
 
13593
14773
  DoOpenIDEOptions(TFormEditorOptionsFrame);
13594
14774
end;
13595
14775
 
13596
 
procedure TMainIDE.OnDesignerPasteComponent(Sender: TObject;
 
14776
procedure TMainIDE.OnDesignerPasteComponents(Sender: TObject;
13597
14777
  LookupRoot: TComponent; TxtCompStream: TStream; ParentControl: TWinControl;
13598
 
  var NewComponent: TComponent);
 
14778
  var NewComponents: TFPList);
13599
14779
var
13600
14780
  NewClassName: String;
13601
14781
  ARegComp: TRegisteredComponent;
13602
14782
  BinCompStream: TMemoryStream;
 
14783
  c: Char;
13603
14784
begin
13604
14785
  DebugLn('TMainIDE.OnDesignerPasteComponent A');
13605
 
  NewComponent:=nil;
13606
14786
 
13607
14787
  // check the class of the new component
13608
14788
  NewClassName:=FindLFMClassName(TxtCompStream);
13610
14790
  // check if component class is registered
13611
14791
  ARegComp:=IDEComponentPalette.FindComponent(NewClassName);
13612
14792
  if ARegComp=nil then begin
13613
 
    MessageDlg(lisClassNotFound,
 
14793
    IDEMessageDialog(lisClassNotFound,
13614
14794
      Format(lisClassIsNotARegisteredComponentClassUnableToPaste, ['"',
13615
14795
        NewClassName, '"', #13]),
13616
 
      mtError,[mbCancel],0);
 
14796
      mtError,[mbCancel]);
13617
14797
    exit;
13618
14798
  end;
13619
14799
 
13620
14800
  // check if there is a valid parent
13621
14801
  if (ParentControl=nil) and ARegComp.IsTControl then begin
13622
 
    MessageDlg(lisControlNeedsParent,
 
14802
    IDEMessageDialog(lisControlNeedsParent,
13623
14803
      Format(lisTheClassIsATControlAndCanNotBePastedOntoANonContro, ['"',
13624
14804
        NewClassName, '"', #13]),
13625
 
      mtError,[mbCancel],0);
 
14805
      mtError,[mbCancel]);
13626
14806
    exit;
13627
14807
  end;
13628
14808
 
13631
14811
  try
13632
14812
    try
13633
14813
      LRSObjectTextToBinary(TxtCompStream,BinCompStream);
 
14814
      // always append an "object list end"
 
14815
      c:=#0;
 
14816
      BinCompStream.Write(c,1);
13634
14817
    except
13635
14818
      on E: Exception do begin
13636
 
        MessageDlg(lisConversionError,
 
14819
        IDEMessageDialog(lisConversionError,
13637
14820
          Format(lisUnableToConvertComponentTextIntoBinaryFormat, [#13,
13638
14821
            E.Message]),
13639
 
          mtError,[mbCancel],0);
 
14822
          mtError,[mbCancel]);
13640
14823
        exit;
13641
14824
      end;
13642
14825
    end;
13644
14827
    BinCompStream.Position:=0;
13645
14828
 
13646
14829
    // create the component
13647
 
    NewComponent := FormEditor1.CreateChildComponentFromStream(BinCompStream,
13648
 
                     ARegComp.ComponentClass,LookupRoot,ParentControl);
13649
 
    if NewComponent=nil then begin
13650
 
      DebugLn('TMainIDE.OnDesignerPasteComponent FAILED');
 
14830
    FormEditor1.CreateChildComponentsFromStream(BinCompStream,
 
14831
                ARegComp.ComponentClass,LookupRoot,ParentControl,NewComponents);
 
14832
    if NewComponents.Count=0 then begin
 
14833
      DebugLn('TMainIDE.OnDesignerPasteComponent FAILED FormEditor1.CreateChildComponentFromStream');
13651
14834
      exit;
13652
14835
    end;
13653
14836
 
13656
14839
  end;
13657
14840
end;
13658
14841
 
 
14842
procedure TMainIDE.OnDesignerPastedComponents(Sender: TObject;
 
14843
  LookupRoot: TComponent);
 
14844
begin
 
14845
  DoFixupComponentReferences(LookupRoot,[]);
 
14846
end;
 
14847
 
13659
14848
procedure TMainIDE.OnDesignerPropertiesChanged(Sender: TObject);
13660
14849
begin
13661
 
  ObjectInspector1.RefreshPropertyValues;
 
14850
  if ObjectInspector1<>nil then
 
14851
    ObjectInspector1.RefreshPropertyValues;
13662
14852
end;
13663
14853
 
13664
14854
procedure TMainIDE.OnDesignerPersistentDeleted(Sender: TObject;
13669
14859
begin
13670
14860
  CurDesigner := TDesigner(Sender);
13671
14861
  if dfDestroyingForm in CurDesigner.Flags then exit;
13672
 
  ObjectInspector1.FillPersistentComboBox;
 
14862
  if ObjectInspector1<>nil then
 
14863
    ObjectInspector1.FillPersistentComboBox;
13673
14864
end;
13674
14865
 
13675
14866
procedure TMainIDE.OnPropHookPersistentDeleting(APersistent: TPersistent);
13762
14953
procedure TMainIDE.OnControlSelectionPropsChanged(Sender: TObject);
13763
14954
begin
13764
14955
  if (TheControlSelection=nil) or (FormEditor1=nil) then exit;
13765
 
  if not TheControlSelection.Equals(ObjectInspector1.Selection) then
13766
 
    ObjectInspector1.SaveChanges;
13767
 
  ObjectInspector1.RefreshPropertyValues;
 
14956
  if ObjectInspector1<>nil then begin
 
14957
    if not TheControlSelection.Equals(ObjectInspector1.Selection) then
 
14958
      ObjectInspector1.SaveChanges;
 
14959
    ObjectInspector1.RefreshPropertyValues;
 
14960
  end;
13768
14961
end;
13769
14962
 
13770
14963
procedure TMainIDE.OnControlSelectionFormChanged(Sender: TObject; OldForm,
13778
14971
  UpdateIDEComponentPalette;
13779
14972
end;
13780
14973
 
 
14974
procedure TMainIDE.OnGetDesignerSelection(
 
14975
  const ASelection: TPersistentSelectionList);
 
14976
begin
 
14977
  if TheControlSelection=nil then exit;
 
14978
  TheControlSelection.GetSelection(ASelection);
 
14979
end;
 
14980
 
13781
14981
 
13782
14982
// -----------------------------------------------------------------------------
13783
14983
 
13786
14986
  SaveSourceEditorChangesToCodeCache(nil);
13787
14987
end;
13788
14988
 
13789
 
function TMainIDE.UnitDependenciesViewGetProjectMainFilename(Sender: TObject
13790
 
  ): string;
 
14989
function TMainIDE.UnitDependenciesViewGetProjectMainFilename(Sender: TObject): string;
13791
14990
begin
13792
14991
  if Project1.MainUnitID>=0 then
13793
14992
    Result:=Project1.MainUnitInfo.Filename
13795
14994
    Result:='';
13796
14995
end;
13797
14996
 
13798
 
procedure TMainIDE.UnitDependenciesViewOpenFile(Sender: TObject;
13799
 
  const Filename: string);
 
14997
procedure TMainIDE.UnitDependenciesViewOpenFile(Sender: TObject; const Filename: string);
13800
14998
begin
13801
14999
  DoOpenEditorFile(Filename,-1,-1,[]);
13802
15000
end;
13815
15013
procedure TMainIDE.OnCodeExplorerJumpToCode(Sender: TObject;
13816
15014
  const Filename: string; const Caret: TPoint; TopLine: integer);
13817
15015
begin
13818
 
  DoJumpToSourcePosition(Filename,Caret.X,Caret.Y,TopLine,true);
 
15016
  DoJumpToSourcePosition(Filename,Caret.X,Caret.Y,TopLine,[jfAddJumpPoint, jfFocusEditor]);
13819
15017
end;
13820
15018
 
13821
15019
procedure TMainIDE.OnCodeExplorerShowOptions(Sender: TObject);
13834
15032
 
13835
15033
// -----------------------------------------------------------------------------
13836
15034
 
13837
 
procedure TMainIDE.InitCodeToolBoss;
 
15035
function TMainIDE.InitCodeToolBoss: boolean;
13838
15036
// initialize the CodeToolBoss, which is the frontend for the codetools.
13839
15037
//  - sets a basic set of compiler macros
13840
15038
var
13841
15039
  AFilename: string;
13842
15040
  InteractiveSetup: boolean;
 
15041
  Note: string;
 
15042
  CfgCache: TFPCTargetConfigCache;
 
15043
  OldLazDir: String;
13843
15044
begin
 
15045
  Result:=true;
13844
15046
  InteractiveSetup:=true;
13845
15047
  OpenEditorsOnCodeToolChange:=false;
13846
15048
 
13862
15064
    'PROJECT',nil,@CTMacroFunctionProject);
13863
15065
 
13864
15066
  CodeToolsOpts.AssignTo(CodeToolBoss);
13865
 
  if (not FileExistsCached(EnvironmentOptions.GetCompilerFilename)) then begin
13866
 
    DebugLn('');
13867
 
    DebugLn('NOTE: Compiler filename not set! (see Environment / Options ... / Environment / Files)');
13868
 
  end;
13869
15067
 
13870
 
  if (EnvironmentOptions.LazarusDirectory='')
13871
 
  or not DirPathExists(EnvironmentOptions.LazarusDirectory) then begin
13872
 
    DebugLn('');
13873
 
    DebugLn(
13874
 
      'NOTE: Lazarus source directory not set!  (see Environment / Options ... / Environment / Files)');
13875
 
  end;
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.
13879
 
    DebugLn('');
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
 
15070
      DebugLn('');
 
15071
      DebugLn('NOTE: invalid compiler filename! (see Tools / Options ... / Environment / Files)');
 
15072
    end;
 
15073
    if not DirPathExists(EnvironmentOptions.GetParsedLazarusDirectory) then begin
 
15074
      DebugLn('');
 
15075
      DebugLn('NOTE: Lazarus source directory not set!  (see Tools / Options ... / Environment / Files)');
 
15076
    end;
 
15077
    if (EnvironmentOptions.GetParsedFPCSourceDirectory='') then begin
 
15078
      DebugLn('');
 
15079
      DebugLn('NOTE: FPC source directory not set! (see Tools / Options ... / Environment / Files)');
 
15080
    end;
13881
15081
  end;
13882
15082
 
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;
 
15086
 
 
15087
  if InteractiveSetup then
 
15088
  begin
 
15089
    if (not ShowSetupDialog)
 
15090
    and (CheckLazarusDirectoryQuality(EnvironmentOptions.GetParsedLazarusDirectory,Note)<>sddqCompatible)
 
15091
    then begin
 
15092
      debugln(['Warning: incompatible Lazarus directory: ',EnvironmentOptions.GetParsedLazarusDirectory]);
 
15093
      ShowSetupDialog:=true;
 
15094
    end;
 
15095
    if (not ShowSetupDialog)
 
15096
    and (CheckCompilerQuality(EnvironmentOptions.GetParsedCompilerFilename,Note,
 
15097
                         CodeToolBoss.FPCDefinesCache.TestFilename)=sddqInvalid)
 
15098
    then begin
 
15099
      debugln(['Warning: invalid compiler: ',EnvironmentOptions.GetParsedCompilerFilename]);
 
15100
      ShowSetupDialog:=true;
 
15101
    end;
 
15102
    if (not ShowSetupDialog) then
 
15103
    begin
 
15104
      CfgCache:=CodeToolBoss.FPCDefinesCache.ConfigCaches.Find(
 
15105
        EnvironmentOptions.GetParsedCompilerFilename,'','','',true);
 
15106
      if CheckFPCSrcDirQuality(EnvironmentOptions.GetParsedFPCSourceDirectory,Note,
 
15107
        CfgCache.GetFPCVer)=sddqInvalid
 
15108
      then begin
 
15109
        debugln(['Warning: invalid fpc source directory: ',EnvironmentOptions.GetParsedFPCSourceDirectory]);
 
15110
        ShowSetupDialog:=true;
 
15111
      end;
 
15112
    end;
 
15113
    if ShowSetupDialog then begin
 
15114
      OldLazDir:=EnvironmentOptions.LazarusDirectory;
 
15115
      if ShowInitialSetupDialog<>mrOk then
 
15116
        exit(false);
 
15117
      if OldLazDir<>EnvironmentOptions.LazarusDirectory then begin
 
15118
        CollectTranslations(EnvironmentOptions.GetParsedLazarusDirectory);
 
15119
        TranslateResourceStrings(EnvironmentOptions.GetParsedLazarusDirectory,
 
15120
                                 EnvironmentOptions.LanguageID);
 
15121
      end;
 
15122
    end;
 
15123
  end;
13885
15124
 
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;
13893
15131
  end;
13894
15132
 
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;
13901
 
 
13902
15133
  // the first template is the "use default" flag
13903
15134
  CreateUseDefaultsFlagTemplate;
13904
15135
 
13905
 
  // create defines for the lazarus sources
13906
 
  SetupLazarusDirectory(InteractiveSetup);
13907
 
 
13908
 
  MainBuildBoss.RescanCompilerDefines(true,false,false);
 
15136
  MainBuildBoss.SetBuildTargetProject1(false);
13909
15137
 
13910
15138
  // load include file relationships
13911
15139
  AFilename:=AppendPathDelim(GetPrimaryConfigPath)+CodeToolsIncludeLinkFile;
13928
15156
 
13929
15157
  CompilerParseStampIncreased:=@OnCompilerParseStampIncreased;
13930
15158
 
 
15159
  {$IFDEF CheckNodeTool}
13931
15160
  // codetools consistency check
13932
15161
  CodeToolBoss.ConsistencyCheck;
 
15162
  {$ENDIF}
13933
15163
end;
13934
15164
 
13935
15165
procedure TMainIDE.ActivateCodeToolAbortableMode;
14268
15498
    AnUnitInfo := Project1.UnitWithEditorComponent(SaveEditor);
14269
15499
    if (AnUnitInfo<>nil) then
14270
15500
    begin
14271
 
      SaveSourceEditorChangesToCodeCache:=true;
 
15501
      //debugln(['SaveChanges ',AnUnitInfo.Filename,' ',SaveEditor.NeedsUpdateCodeBuffer]);
14272
15502
      if SaveEditor.NeedsUpdateCodeBuffer then
14273
15503
      begin
 
15504
        SaveSourceEditorChangesToCodeCache:=true;
14274
15505
        SaveEditor.UpdateCodeBuffer;
14275
 
        AnUnitInfo.Modified:=true;
 
15506
        //debugln(['TMainIDE.SaveSourceEditorChangesToCodeCache.SaveChanges ',AnUnitInfo.Filename,' Step=',TCodeBuffer(SaveEditor.CodeToolsBuffer).ChangeStep]);
14276
15507
      end;
14277
15508
    end;
14278
15509
  end;
14281
15512
  i: integer;
14282
15513
begin
14283
15514
  Result:=false;
 
15515
  //debugln(['TMainIDE.SaveSourceEditorChangesToCodeCache ']);
14284
15516
  if AEditor = nil then begin
14285
15517
    for i:=0 to SourceEditorManager.SourceEditorCount - 1 do
14286
15518
      SaveChanges(SourceEditorManager.SourceEditors[i]);
14304
15536
    ActiveUnitInfo := Project1.EditorInfoWithEditorComponent(ActiveSrcEdit).UnitInfo;
14305
15537
  end
14306
15538
  else begin
14307
 
  ActiveSrcEdit:=nil;
14308
 
  ActiveUnitInfo:=nil;
 
15539
    ActiveSrcEdit:=nil;
 
15540
    ActiveUnitInfo:=nil;
14309
15541
  end;
14310
15542
 
14311
15543
  // check global stati
14315
15547
  end;
14316
15548
  if (not (ctfSourceEditorNotNeeded in Flags)) and (SourceEditorManager.SourceEditorCount=0)
14317
15549
  then begin
14318
 
    DebugLn('TMainIDE.BeginCodeTool no editor');
 
15550
    DebugLn('TMainIDE.BeginCodeTool no source editor');
14319
15551
    exit;
14320
15552
  end;
14321
15553
 
14322
15554
  // check source editor
14323
15555
  if not (ctfUseGivenSourceEditor in Flags) then begin
14324
 
  if ctfSwitchToFormSource in Flags then
14325
 
    DoSwitchToFormSrc(ADesigner,ActiveSrcEdit,ActiveUnitInfo)
14326
 
  else if ADesigner<>nil then
14327
 
    GetDesignerUnit(ADesigner,ActiveSrcEdit,ActiveUnitInfo)
14328
 
  else
14329
 
    GetCurrentUnit(ActiveSrcEdit,ActiveUnitInfo);
 
15556
    if ctfSwitchToFormSource in Flags then
 
15557
      DoSwitchToFormSrc(ADesigner,ActiveSrcEdit,ActiveUnitInfo)
 
15558
    else if ADesigner<>nil then
 
15559
      GetDesignerUnit(ADesigner,ActiveSrcEdit,ActiveUnitInfo)
 
15560
    else
 
15561
      GetCurrentUnit(ActiveSrcEdit,ActiveUnitInfo);
14330
15562
  end;
14331
15563
  if (not (ctfSourceEditorNotNeeded in Flags)) and
14332
15564
     ((ActiveSrcEdit=nil) or (ActiveUnitInfo=nil))
14351
15583
end;
14352
15584
 
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;
14355
15587
var
14356
15588
  CodeBuffer: TCodeBuffer;
 
15589
  aFilename: String;
14357
15590
begin
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);
14362
15598
end;
14363
15599
 
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;
14368
15603
var
14369
 
  NewSrcEdit: TSourceEditor;
 
15604
  SrcEdit, NewSrcEdit: TSourceEditor;
14370
15605
  AnEditorInfo: TUnitEditorInfo;
 
15606
  s: String;
14371
15607
begin
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']);
14375
15611
    DumpStack;
14376
15612
    exit;
14377
15613
  end;
14378
15614
 
 
15615
  if ActiveSrcEdit = nil then
 
15616
    SrcEdit := nil
 
15617
  else
 
15618
    SrcEdit := ActiveSrcEdit as TSourceEditor;
 
15619
 
14379
15620
  SourceEditorManager.BeginAutoFocusLock;
14380
15621
  try
14381
 
    if (ActiveSrcEdit=nil) or (ActiveUnitInfo=nil) then
14382
 
      GetCurrentUnit(ActiveSrcEdit,ActiveUnitInfo);
 
15622
    if (SrcEdit=nil) or (ActiveUnitInfo=nil) then
 
15623
      GetCurrentUnit(SrcEdit,ActiveUnitInfo);
14383
15624
 
14384
 
    if AddJumpPoint and (ActiveUnitInfo <> nil) and (ActiveSrcEdit <> nil)
 
15625
    if (jfAddJumpPoint in Flags) and (ActiveUnitInfo <> nil) and (SrcEdit <> nil)
14385
15626
    then begin
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);
14390
15631
    end;
14391
15632
 
14393
15634
    then begin
14394
15635
      // jump to other file -> open it
14395
15636
      ActiveUnitInfo := Project1.UnitInfoWithFilename(NewSource.Filename);
 
15637
      if (ActiveUnitInfo = nil) and (Project1.IsVirtual) and (jfSearchVirtualFullPath in Flags)
 
15638
      then begin
 
15639
        s := AppendPathDelim(GetTestBuildDirectory);
 
15640
        if LazUTF8.UTF8LowerCase(copy(NewSource.Filename, 1, length(s))) = LazUTF8.UTF8LowerCase(s)
 
15641
        then ActiveUnitInfo := Project1.UnitInfoWithFilename(copy(NewSource.Filename, 1 + length(s), length(NewSource.Filename)), [pfsfOnlyVirtualFiles]);
 
15642
      end;
 
15643
 
 
15644
 
14396
15645
      AnEditorInfo := nil;
14397
15646
      if ActiveUnitInfo <> nil then
14398
15647
        AnEditorInfo := GetAvailableUnitEditorInfo(ActiveUnitInfo, Point(NewX,NewY), NewTopLine);
14416
15665
        SourceEditorManager.ActiveEditor := NewSrcEdit;
14417
15666
      end
14418
15667
      else
14419
 
        NewSrcEdit:=ActiveSrcEdit;
 
15668
        NewSrcEdit:=SrcEdit;
14420
15669
    end;
14421
15670
    if NewX<1 then NewX:=1;
14422
15671
    if NewY<1 then NewY:=1;
14423
 
    //debugln(['[TMainIDE.DoJumpToCodePos] ',NewX,',',NewY,',',NewTopLine]);
 
15672
    if jfMapLineFromDebug in Flags then
 
15673
      NewY := NewSrcEdit.DebugToSourceLine(NewY);
 
15674
    //debugln(['[TMainIDE.DoJumpToCodePosition] ',NewX,',',NewY,',',NewTopLine]);
 
15675
 
14424
15676
    try
14425
15677
      NewSrcEdit.BeginUpdate;
14426
15678
      NewSrcEdit.EditorComponent.MoveLogicalCaretIgnoreEOL(Point(NewX,NewY));
14430
15682
        else
14431
15683
          NewSrcEdit.TopLine:=NewTopLine;
14432
15684
      end;
14433
 
      //DebugLn('TMainIDE.DoJumpToCodePos NewY=',dbgs(NewY),' ',dbgs(TopLine),' ',dbgs(NewTopLine));
14434
 
      with NewSrcEdit.EditorComponent do
14435
 
        LeftChar:=Max(NewX - (CharsInWindow * 4 div 5), 1);
 
15685
      //DebugLn('TMainIDE.DoJumpToCodePosition NewY=',dbgs(NewY),' ',dbgs(TopLine),' ',dbgs(NewTopLine));
 
15686
      NewSrcEdit.CenterCursorHoriz(hcmSoftKeepEOL);
14436
15687
    finally
14437
15688
      NewSrcEdit.EndUpdate;
14438
15689
    end;
14439
 
    if MarkLine then
 
15690
    if jfMarkLine in Flags then
14440
15691
      NewSrcEdit.ErrorLine := NewY;
14441
15692
 
14442
 
    if FocusEditor then
 
15693
    if jfFocusEditor in Flags then
14443
15694
      SourceEditorManager.ShowActiveWindowOnTop(True);
14444
15695
    UpdateSourceNames;
14445
15696
    Result:=mrOk;
14518
15769
  CodeToolBoss.SourceCache.ClearAllSourceLogEntries;
14519
15770
end;
14520
15771
 
14521
 
procedure TMainIDE.DoJumpToProcedureSection;
 
15772
procedure TMainIDE.DoJumpToOtherProcedureSection;
14522
15773
var ActiveSrcEdit: TSourceEditor;
14523
15774
  ActiveUnitInfo: TUnitInfo;
14524
15775
  NewSource: TCodeBuffer;
14525
15776
  NewX, NewY, NewTopLine: integer;
14526
15777
  RevertableJump: boolean;
14527
15778
  LogCaret: TPoint;
 
15779
  Flags: TJumpToCodePosFlags;
14528
15780
begin
14529
15781
  if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[]) then exit;
14530
15782
  {$IFDEF IDE_DEBUG}
14536
15788
    LogCaret.X,LogCaret.Y,
14537
15789
    NewSource,NewX,NewY,NewTopLine,RevertableJump) then
14538
15790
  begin
14539
 
    DoJumpToCodePos(ActiveSrcEdit, ActiveUnitInfo,
14540
 
      NewSource, NewX, NewY, NewTopLine, not RevertableJump);
14541
 
  end else
 
15791
    Flags := [jfFocusEditor];
 
15792
    if not RevertableJump then include(Flags, jfAddJumpPoint);
 
15793
    DoJumpToCodePosition(ActiveSrcEdit, ActiveUnitInfo,
 
15794
      NewSource, NewX, NewY, NewTopLine, Flags);
 
15795
  end else begin
14542
15796
    DoJumpToCodeToolBossError;
 
15797
  end;
14543
15798
end;
14544
15799
 
14545
15800
procedure TMainIDE.DoJumpToCodeToolBossError;
14575
15830
 
14576
15831
  // jump to error in source editor
14577
15832
  if CodeToolBoss.ErrorCode<>nil then begin
14578
 
    ErrorCaret:=Point(CodeToolBoss.ErrorColumn,CodeToolBoss.ErrorLine);
 
15833
    ErrorCaret:=Point(Max(1,CodeToolBoss.ErrorColumn),Max(1,CodeToolBoss.ErrorLine));
14579
15834
    ErrorFilename:=CodeToolBoss.ErrorCode.Filename;
14580
15835
    ErrorTopLine:=CodeToolBoss.ErrorTopLine;
14581
15836
    SourceEditorManager.AddJumpPointClicked(Self);
14644
15899
    )
14645
15900
  then begin
14646
15901
    //debugln(['TMainIDE.DoFindDeclarationAtCaret ',NewSource.Filename,' NewX=',Newx,',y=',NewY,' ',NewTopLine]);
14647
 
    DoJumpToCodePos(ActiveSrcEdit, ActiveUnitInfo,
14648
 
      NewSource, NewX, NewY, NewTopLine, true);
 
15902
    DoJumpToCodePosition(ActiveSrcEdit, ActiveUnitInfo,
 
15903
      NewSource, NewX, NewY, NewTopLine, [jfAddJumpPoint, jfFocusEditor]);
14649
15904
  end else begin
14650
15905
    DoJumpToCodeToolBossError;
14651
15906
  end;
14669
15924
    FileInfo: TSearchRec;
14670
15925
    CurDirectory: String;
14671
15926
    CurFilename: String;
 
15927
    OnlyPascalSources: Boolean;
14672
15928
  begin
14673
15929
    Result:=mrCancel;
14674
 
    if (Options.ExtraFiles=nil) then begin
 
15930
    if (Options.ExtraFiles<>nil) then begin
14675
15931
      for i:=0 to Options.ExtraFiles.Count-1 do begin
14676
15932
        CurFileMask:=Options.ExtraFiles[i];
14677
15933
        if not GlobalMacroList.SubstituteStr(CurFileMask) then exit;
 
15934
        CurFileMask:=ChompPathDelim(CurFileMask);
 
15935
        if not FilenameIsAbsolute(CurFileMask) then begin
 
15936
          if Project1.IsVirtual then continue;
 
15937
          CurFileMask:=AppendPathDelim(Project1.ProjectDirectory+CurFileMask);
 
15938
        end;
 
15939
        CurFileMask:=TrimFilename(CurFileMask);
 
15940
        OnlyPascalSources:=false;
 
15941
        if DirPathExistsCached(CurFileMask) then begin
 
15942
          // a whole directory
 
15943
          OnlyPascalSources:=true;
 
15944
          CurFileMask:=AppendPathDelim(CurFileMask)+GetAllFilesMask;
 
15945
        end else if FileExistsCached(CurFileMask) then begin
 
15946
          // single file
 
15947
          Files.Add(CurFileMask);
 
15948
          continue;
 
15949
        end else begin
 
15950
          // a mask
 
15951
        end;
14678
15952
        if FindFirstUTF8(CurFileMask,faAnyFile,FileInfo)=0
14679
15953
        then begin
14680
15954
          CurDirectory:=AppendPathDelim(ExtractFilePath(CurFileMask));
14681
 
          if not FilenameIsAbsolute(CurDirectory) then begin
14682
 
            CurDirectory:=AppendPathDelim(Project1.ProjectDirectory)
14683
 
                          +CurDirectory;
14684
 
          end;
14685
15955
          repeat
14686
15956
            // check if special file
14687
15957
            if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='')
14688
15958
            then
14689
15959
              continue;
 
15960
            if OnlyPascalSources and not FilenameIsPascalSource(FileInfo.Name)
 
15961
            then
 
15962
              continue;
14690
15963
            CurFilename:=CurDirectory+FileInfo.Name;
 
15964
            //debugln(['AddExtraFiles ',CurFilename]);
14691
15965
            if FileIsText(CurFilename) then
14692
15966
              Files.Add(CurFilename);
14693
15967
          until FindNextUTF8(FileInfo)<>0;
14711
15985
  PascalReferences: TAVLTree;
14712
15986
  ListOfLazFPDocNode: TFPList;
14713
15987
  CurUnitname: String;
 
15988
  OldChange: Boolean;
14714
15989
begin
14715
15990
  Result:=mrCancel;
14716
15991
  if not BeginCodeTool(TargetSrcEdit,TargetUnitInfo,[]) then exit;
14724
15999
    DoJumpToCodeToolBossError;
14725
16000
    exit;
14726
16001
  end;
14727
 
  DoJumpToCodePos(TargetSrcEdit, TargetUnitInfo,
14728
 
    NewSource, NewX, NewY, NewTopLine, true);
 
16002
  DoJumpToCodePosition(TargetSrcEdit, TargetUnitInfo,
 
16003
    NewSource, NewX, NewY, NewTopLine, [jfAddJumpPoint, jfFocusEditor]);
14729
16004
  CodeToolBoss.GetIdentifierAt(NewSource,NewX,NewY,Identifier);
14730
16005
  CurUnitname:=ExtractFileNameOnly(NewSource.Filename);
14731
16006
 
14732
16007
  GetCurrentUnit(DeclarationSrcEdit,DeclarationUnitInfo);
14733
16008
  DeclarationCaretXY:=DeclarationSrcEdit.EditorComponent.LogicalCaretXY;
14734
 
  debugln('TMainIDE.DoFindRenameIdentifier A DeclarationCaretXY=x=',dbgs(DeclarationCaretXY.X),' y=',dbgs(DeclarationCaretXY.Y));
 
16009
  //debugln('TMainIDE.DoFindRenameIdentifier A DeclarationCaretXY=x=',dbgs(DeclarationCaretXY.X),' y=',dbgs(DeclarationCaretXY.Y));
14735
16010
 
14736
16011
  // let user choose the search scope
14737
16012
  Result:=ShowFindRenameIdentifierDialog(DeclarationUnitInfo.Source.Filename,
14738
16013
    DeclarationCaretXY,true,Rename,nil);
14739
16014
  if Result<>mrOk then begin
14740
 
    debugln('TMainIDE.DoFindRenameIdentifier failed: let user choose the search scope');
 
16015
    debugln('TMainIDE.DoFindRenameIdentifier failed: user cancelled dialog');
14741
16016
    exit;
14742
16017
  end;
14743
16018
 
14824
16099
          mtInformation,[mbCancel],'');
14825
16100
        exit(mrCancel);
14826
16101
      end;
14827
 
      if not CodeToolBoss.RenameIdentifier(PascalReferences,
14828
 
        Identifier,Options.RenameTo)
14829
 
      then begin
14830
 
        DoJumpToCodeToolBossError;
14831
 
        debugln('TMainIDE.DoFindRenameIdentifier unable to commit');
14832
 
        Result:=mrCancel;
14833
 
        exit;
 
16102
      OldChange:=OpenEditorsOnCodeToolChange;
 
16103
      OpenEditorsOnCodeToolChange:=true;
 
16104
      try
 
16105
        if not CodeToolBoss.RenameIdentifier(PascalReferences,
 
16106
          Identifier,Options.RenameTo)
 
16107
        then begin
 
16108
          DoJumpToCodeToolBossError;
 
16109
          debugln('TMainIDE.DoFindRenameIdentifier unable to commit');
 
16110
          Result:=mrCancel;
 
16111
          exit;
 
16112
        end;
 
16113
      finally
 
16114
        OpenEditorsOnCodeToolChange:=OldChange;
14834
16115
      end;
14835
16116
    end;
14836
16117
 
14864
16145
  Result:=ShowUnusedUnitsDialog;
14865
16146
end;
14866
16147
 
 
16148
function TMainIDE.DoUseUnit: TModalResult;
 
16149
begin
 
16150
  Result:=ShowUseUnitDialog;
 
16151
end;
 
16152
 
14867
16153
function TMainIDE.DoFindOverloads: TModalResult;
14868
16154
begin
14869
16155
  Result:=ShowFindOverloadsDialog;
14931
16217
    ActiveSrcEdit.EditorComponent.CaretY,
14932
16218
    NewSource,NewX,NewY,NewTopLine) then
14933
16219
  begin
14934
 
    DoJumpToCodePos(ActiveSrcEdit, ActiveUnitInfo,
14935
 
      NewSource, NewX, NewY, NewTopLine, false);
 
16220
    DoJumpToCodePosition(ActiveSrcEdit, ActiveUnitInfo,
 
16221
      NewSource, NewX, NewY, NewTopLine, [jfFocusEditor]);
14936
16222
  end else
14937
16223
    DoJumpToCodeToolBossError;
14938
16224
end;
14942
16228
  ActiveUnitInfo: TUnitInfo;
14943
16229
  NewSource: TCodeBuffer;
14944
16230
  NewX, NewY, NewTopLine: integer;
 
16231
  Flags: TJumpToCodePosFlags;
14945
16232
begin
14946
16233
  if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[]) then exit;
14947
16234
  {$IFDEF IDE_DEBUG}
14951
16238
  if CodeToolBoss.FindBlockStart(ActiveUnitInfo.Source,
14952
16239
    ActiveSrcEdit.EditorComponent.CaretX,
14953
16240
    ActiveSrcEdit.EditorComponent.CaretY,
14954
 
    NewSource,NewX,NewY,NewTopLine) then
 
16241
    NewSource,NewX,NewY,NewTopLine,true) then
14955
16242
  begin
14956
 
    DoJumpToCodePos(ActiveSrcEdit, ActiveUnitInfo,
14957
 
      NewSource, NewX, NewY, NewTopLine, false);
 
16243
    Flags:=[jfFocusEditor];
 
16244
    if (ActiveSrcEdit.EditorComponent.CaretY<>NewY)
 
16245
    or (Abs(ActiveSrcEdit.EditorComponent.CaretX-NewX)>10)
 
16246
    then
 
16247
      Include(Flags,jfAddJumpPoint);
 
16248
    DoJumpToCodePosition(ActiveSrcEdit, ActiveUnitInfo,
 
16249
      NewSource, NewX, NewY, NewTopLine, Flags);
14958
16250
  end else
14959
16251
    DoJumpToCodeToolBossError;
14960
16252
end;
14980
16272
  if CodeToolBoss.GuessUnclosedBlock(ActiveUnitInfo.Source,
14981
16273
    StartX,StartY,NewSource,NewX,NewY,NewTopLine) then
14982
16274
  begin
14983
 
    DoJumpToCodePos(ActiveSrcEdit, ActiveUnitInfo,
14984
 
      NewSource, NewX, NewY, NewTopLine, true);
 
16275
    DoJumpToCodePosition(ActiveSrcEdit, ActiveUnitInfo,
 
16276
      NewSource, NewX, NewY, NewTopLine, [jfAddJumpPoint, jfFocusEditor]);
14985
16277
  end else begin
14986
16278
    if CodeToolBoss.ErrorMessage='' then begin
14987
 
      MessageDlg(lisSuccess, lisAllBlocksLooksOk, mtInformation, [mbOk], 0);
 
16279
      IDEMessageDialog(lisSuccess, lisAllBlocksLooksOk, mtInformation, [mbOk]);
14988
16280
    end else
14989
16281
      DoJumpToCodeToolBossError;
14990
16282
  end;
15011
16303
  if CodeToolBoss.GuessMisplacedIfdefEndif(ActiveUnitInfo.Source,
15012
16304
    StartX,StartY,NewSource,NewX,NewY,NewTopLine) then
15013
16305
  begin
15014
 
    DoJumpToCodePos(ActiveSrcEdit, ActiveUnitInfo,
15015
 
      NewSource, NewX, NewY, NewTopLine, true);
 
16306
    DoJumpToCodePosition(ActiveSrcEdit, ActiveUnitInfo,
 
16307
      NewSource, NewX, NewY, NewTopLine, [jfAddJumpPoint, jfFocusEditor]);
15016
16308
  end else
15017
16309
    DoJumpToCodeToolBossError;
15018
16310
end;
15033
16325
    ActiveSrcEdit.EditorComponent.CaretY,
15034
16326
    NewSource,NewX,NewY,NewTopLine) then
15035
16327
  begin
15036
 
    DoJumpToCodePos(ActiveSrcEdit, ActiveUnitInfo,
15037
 
      NewSource, NewX, NewY, NewTopLine, false);
 
16328
    DoJumpToCodePosition(ActiveSrcEdit, ActiveUnitInfo,
 
16329
      NewSource, NewX, NewY, NewTopLine, [jfFocusEditor]);
15038
16330
  end else
15039
16331
    DoJumpToCodeToolBossError;
15040
16332
end;
15083
16375
    if not CodeToolBoss.GetStringConstBounds(
15084
16376
      CursorCode,CursorXY.X,CursorXY.Y,
15085
16377
      StartCode,StartPos.X,StartPos.Y,
15086
 
      EndCode,EndPos.X,EndPos.Y,
15087
 
      true) then
 
16378
      EndCode,EndPos.X,EndPos.Y,true) then
15088
16379
    begin
15089
16380
      DoJumpToCodeToolBossError;
15090
16381
      exit;
15092
16383
 
15093
16384
    // the codetools have calculated the maximum bounds
15094
16385
    if (StartCode=EndCode) and (CompareCaret(StartPos,EndPos)=0) then begin
15095
 
      MessageDlg(lisNoStringConstantFound,
 
16386
      IDEMessageDialog(lisNoStringConstantFound,
15096
16387
      Format(lisHintTheMakeResourcestringFunctionExpectsAStringCon, [#13]),
15097
 
      mtError,[mbCancel],0);
 
16388
      mtError,[mbCancel]);
15098
16389
      exit;
15099
16390
    end;
15100
16391
    // the user can shorten this range by selecting text
15106
16397
      if (StartCode<>ActiveUnitInfo.Source)
15107
16398
      or (EndCode<>ActiveUnitInfo.Source)
15108
16399
      then begin
15109
 
        MessageDlg(lisNoStringConstantFound, Format(
 
16400
        IDEMessageDialog(lisNoStringConstantFound, Format(
15110
16401
          lisInvalidExpressionHintTheMakeResourcestringFunction, [#13]),
15111
 
        mtError,[mbCancel],0);
 
16402
        mtError,[mbCancel]);
15112
16403
        exit;
15113
16404
      end;
15114
16405
    end else begin
15126
16417
      if (CompareCaret(SelectedStartPos,StartPos)>0)
15127
16418
      or (CompareCaret(SelectedEndPos,EndPos)<0)
15128
16419
      then begin
15129
 
        MessageDlg(lisSelectionExceedsStringConstant,
 
16420
        IDEMessageDialog(lisSelectionExceedsStringConstant,
15130
16421
        Format(lisHintTheMakeResourcestringFunctionExpectsAStringCon2, [#13]),
15131
 
        mtError,[mbCancel],0);
 
16422
        mtError,[mbCancel]);
15132
16423
        exit;
15133
16424
      end;
15134
16425
      StartPos:=SelectedStartPos;
15144
16435
      exit;
15145
16436
    end;
15146
16437
    if CodeToolBoss.Positions.Count=0 then begin
15147
 
      MessageDlg(lisNoResourceStringSectionFound,
 
16438
      IDEMessageDialog(lisNoResourceStringSectionFound,
15148
16439
        lisUnableToFindAResourceStringSectionInThisOrAnyOfThe,
15149
 
        mtError,[mbCancel],0);
 
16440
        mtError,[mbCancel]);
15150
16441
      exit;
15151
16442
    end;
15152
16443
 
15209
16500
function TMainIDE.DoFindInFiles: TModalResult;
15210
16501
begin
15211
16502
  Result:=mrOk;
15212
 
  DoArrangeSourceEditorAndMessageView(true);
15213
16503
  FindInFilesDialog.FindInFilesPerDialog(Project1);
15214
16504
end;
15215
16505
 
15237
16527
    begin
15238
16528
      ApplyCodeToolChanges;
15239
16529
      if NewSource<>nil then
15240
 
        DoJumpToCodePos(ActiveSrcEdit, ActiveUnitInfo,
15241
 
          NewSource, NewX, NewY, NewTopLine, true);
 
16530
        DoJumpToCodePosition(ActiveSrcEdit, ActiveUnitInfo,
 
16531
          NewSource, NewX, NewY, NewTopLine, [jfAddJumpPoint, jfFocusEditor]);
15242
16532
    end else begin
15243
16533
      // error: probably a syntax error or just not in a procedure head/body
15244
16534
      // or not in a class
15279
16569
    if CodeToolBoss.ErrorMessage<>'' then begin
15280
16570
      DoJumpToCodeToolBossError;
15281
16571
    end else if CTResult then begin
15282
 
      DoJumpToCodePos(ActiveSrcEdit,ActiveUnitInfo,
15283
 
        NewSource,NewX,NewY,NewTopLine,true);
 
16572
      DoJumpToCodePosition(ActiveSrcEdit,ActiveUnitInfo,
 
16573
        NewSource,NewX,NewY,NewTopLine,[jfAddJumpPoint, jfFocusEditor]);
15284
16574
    end;
15285
16575
  finally
15286
16576
    OpenEditorsOnCodeToolChange:=OldChange;
15305
16595
  SourceEditorManager.ShowActiveWindowOnTop(True);
15306
16596
end;
15307
16597
 
15308
 
Procedure TMainIDE.OnSrcNotebookEditorActived(Sender: TObject);
 
16598
procedure TMainIDE.OnSrcNotebookEditorActived(Sender: TObject);
15309
16599
var
15310
16600
  ActiveUnitInfo: TUnitInfo;
15311
16601
  ASrcEdit: TSourceEditor;
15323
16613
  ActiveUnitInfo.SetLastUsedEditor(SourceEditorManager.ActiveEditor);
15324
16614
 
15325
16615
  UpdateSaveMenuItemsAndButtons(false);
15326
 
  MainIDEBar.ToggleFormSpeedBtn.Enabled := Assigned(ActiveUnitInfo.Component);
15327
16616
  MainIDEBar.itmViewToggleFormUnit.Enabled := Assigned(ActiveUnitInfo.Component)
15328
16617
                                           or (ActiveUnitInfo.ComponentName<>'');
15329
16618
  MainIDEBar.ToggleFormSpeedBtn.Enabled := MainIDEBar.itmViewToggleFormUnit.Enabled;
15465
16754
  CurPos, CurFound: TProjectBookmark;
15466
16755
  AnUnitInfo: TUnitInfo;
15467
16756
  AnEditorInfo: TUnitEditorInfo;
 
16757
  NewXY: TPoint;
15468
16758
begin
15469
16759
  if ID < 0 then begin
15470
16760
    // ID < 0  => next/prev
15508
16798
 
15509
16799
      if CurFound = nil then exit;
15510
16800
      ID := CurFound.ID;
 
16801
      NewXY := CurFound.CursorPos;
15511
16802
    finally
15512
16803
      CurPos.Free;
15513
16804
    end;
15516
16807
  end
15517
16808
  else begin
15518
16809
    AnEditor := nil;
 
16810
    AnEditorInfo := nil;
15519
16811
    AnUnitInfo := TUnitInfo(Project1.Bookmarks.UnitInfoForBookmarkWithIndex(ID));
15520
 
    AnEditorInfo := nil;
15521
 
    if (AnUnitInfo <> nil) and (AnUnitInfo.OpenEditorInfoCount > 0) then
15522
 
      AnEditorInfo := GetAvailableUnitEditorInfo(AnUnitInfo,
15523
 
                        Project1.Bookmarks.BookmarkWithID(ID).CursorPos);
 
16812
    if (AnUnitInfo <> nil) and (AnUnitInfo.OpenEditorInfoCount > 0) then begin
 
16813
      NewXY := Project1.Bookmarks.BookmarkWithID(ID).CursorPos;
 
16814
      AnEditorInfo := GetAvailableUnitEditorInfo(AnUnitInfo, NewXY);
 
16815
    end;
15524
16816
    if AnEditorInfo <> nil then
15525
16817
      AnEditor := TSourceEditor(AnEditorInfo.EditorComponent);
15526
16818
    if AnEditor = nil then exit;
15527
16819
  end;
15528
16820
 
 
16821
  if (AnEditor <> SourceEditorManager.ActiveEditor)
 
16822
  or (AnEditor.EditorComponent.CaretX <> NewXY.X)
 
16823
  or (AnEditor.EditorComponent.CaretY <> NewXY.Y)
 
16824
  then
 
16825
    SourceEditorManager.AddJumpPointClicked(Self);
 
16826
 
15529
16827
  SourceEditorManager.ActiveEditor := AnEditor;
15530
16828
  SourceEditorManager.ShowActiveWindowOnTop(True);
15531
16829
  try
15580
16878
  SrcEditor := TSourceEditor(Sender);
15581
16879
  p :=Project1.EditorInfoWithEditorComponent(SrcEditor);
15582
16880
  if (p <> nil) then
15583
 
    p.EditorComponent := nil // Set EditorIndex := -1
 
16881
    p.EditorComponent := nil; // Set EditorIndex := -1
15584
16882
end;
15585
16883
 
15586
16884
procedure TMainIDE.OnSrcNotebookCurCodeBufferChanged(Sender: TObject);
15591
16889
 
15592
16890
procedure TMainIDE.OnSrcNotebookShowHintForSource(SrcEdit: TSourceEditor;
15593
16891
  ClientPos: TPoint; CaretPos: TPoint);
 
16892
 
 
16893
  function CheckExpressionIsValid(var Expr: String): boolean;
 
16894
  var
 
16895
    i: Integer;
 
16896
    InStr: Boolean;
 
16897
  begin
 
16898
    Result := True;
 
16899
    Expr := Trim(Expr);
 
16900
    if (Expr <> '') and (Expr[Length(Expr)] = ';') then
 
16901
      SetLength(Expr, Length(Expr) - 1);
 
16902
    if (pos(#10, Expr) < 1) and (pos(#13, Expr) < 1) then exit; // single line, assume ok
 
16903
 
 
16904
    Result := False;
 
16905
    InStr := False;
 
16906
    for i := 1 to Length(Expr) do begin
 
16907
      if Expr[i] = '''' then InStr := not InStr;
 
16908
      if (not InStr) and (Expr[i] in [';', ':']) then exit; // can not be an expression
 
16909
      // Todo: Maybe check for keywords: If Then Begin End ...
 
16910
    end;
 
16911
    Result := True;
 
16912
  end;
 
16913
 
15594
16914
var
15595
16915
  ActiveUnitInfo: TUnitInfo;
15596
16916
  BaseURL, SmartHintStr, Expression, DebugEval, DebugEvalDerefer: String;
15597
16917
  DBGType,DBGTypeDerefer: TDBGType;
 
16918
  HasHint: Boolean;
 
16919
  p: SizeInt;
 
16920
  Opts: TDBGEvaluateFlags;
15598
16921
begin
15599
16922
  //DebugLn(['TMainIDE.OnSrcNotebookShowHintForSource START']);
15600
16923
  if (SrcEdit=nil) then exit;
15609
16932
  writeln('');
15610
16933
  writeln('[TMainIDE.OnSrcNotebookShowHintForSource] ************ ',ActiveUnitInfo.Source.Filename,' X=',CaretPos.X,' Y=',CaretPos.Y);
15611
16934
  {$ENDIF}
 
16935
  HasHint:=false;
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
 
16941
    then
 
16942
      HasHint:=true;
15616
16943
    {$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.OnSrcNotebookShowHintForSource B');{$ENDIF}
15617
16944
  end;
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
 
16951
            Expression := '';
 
16952
        end
15623
16953
        else
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
 
16959
        Opts := [];
 
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
15635
16968
        begin
15636
16969
          if DBGType.Value.AsPointer <> nil then
15637
16970
          begin
15638
 
            if DebugBoss.Evaluate(Expression + '^', DebugEvalDerefer, DBGTypeDerefer) then
 
16971
            if DebugBoss.Evaluate(Expression + '^', DebugEvalDerefer, DBGTypeDerefer, Opts) then
15639
16972
            begin
15640
16973
              if Assigned(DBGTypeDerefer) and
15641
16974
                ( (DBGTypeDerefer.Kind <> skPointer) or
15648
16981
        end;
15649
16982
        FreeAndNil(DBGType);
15650
16983
        FreeAndNil(DBGTypeDerefer);
 
16984
        HasHint:=true;
15651
16985
        Expression := Expression + ' = ' + DebugEval;
15652
 
        if SmartHintStr<>'' then
15653
 
          SmartHintStr:=LineEnding+LineEnding+SmartHintStr;
15654
 
        SmartHintStr:=Expression+SmartHintStr;
 
16986
        if SmartHintStr<>'' then begin
 
16987
          p:=System.Pos('<body>',lowercase(SmartHintStr));
 
16988
          if p>0 then begin
 
16989
            Insert('<div class="debuggerhint">'
 
16990
                   +CodeHelpBoss.TextToHTML(Expression)+'</div><br>',
 
16991
                   SmartHintStr,p+length('<body>'));
 
16992
          end else begin
 
16993
            SmartHintStr:=Expression+LineEnding+LineEnding+SmartHintStr;
 
16994
          end;
 
16995
        end else
 
16996
          SmartHintStr:=Expression;
15655
16997
      end;
15656
16998
    end;
15657
16999
  end;
15658
17000
 
15659
 
  if SmartHintStr <> '' then
 
17001
  if HasHint then
15660
17002
    SrcEdit.ActivateHint(ClientPos, BaseURL, SmartHintStr);
15661
17003
end;
15662
17004
 
15665
17007
  FDisplayState:= dsSource;
15666
17008
end;
15667
17009
 
15668
 
Procedure TMainIDE.OnDesignerActivated(Sender: TObject);
 
17010
procedure TMainIDE.OnDesignerActivated(Sender: TObject);
15669
17011
begin
15670
17012
  FDisplayState:= dsForm;
15671
17013
  FLastFormActivated := (Sender as TDesigner).Form;
15696
17038
      Exit;
15697
17039
    end;
15698
17040
  end;
15699
 
  CloseUnitComponent(AnUnitInfo,[]);
 
17041
  if FDesignerToBeFreed=nil then
 
17042
    FDesignerToBeFreed:=TFilenameToStringTree.Create(false);
 
17043
  FDesignerToBeFreed[AnUnitInfo.Filename]:='1';
15700
17044
end;
15701
17045
 
15702
17046
procedure TMainIDE.OnDesignerRenameComponent(ADesigner: TDesigner;
15748
17092
    end;
15749
17093
 
15750
17094
    // check if classname
15751
 
    ConflictingClass:=AComponent.ClassType;
 
17095
    ConflictingClass:=AComponent.ClassType.ClassParent;
15752
17096
    while ConflictingClass<>nil do begin
15753
17097
      if SysUtils.CompareText(AName,ConflictingClass.ClassName)=0 then begin
15754
17098
        s:='This component has already the class '+ConflictingClass.ClassName;
16023
17367
begin
16024
17368
  ADesigner:=TDesigner(Sender);
16025
17369
  GetDesignerUnit(ADesigner,ASrcEdit,AnUnitInfo);
16026
 
  debugln('TMainIDE.OnDesignerViewLFM ',AnUnitInfo.Filename);
 
17370
  //debugln('TMainIDE.OnDesignerViewLFM ',AnUnitInfo.Filename);
16027
17371
  OnDesignerCloseQuery(Sender);
16028
17372
  if AnUnitInfo.OpenEditorInfoCount > 0 then
16029
17373
    EditorInfo := AnUnitInfo.OpenEditorInfo[0]
16092
17436
    end;
16093
17437
  except
16094
17438
    on E: Exception do begin
16095
 
      MessageDlg('Error',E.Message,mtError,[mbCancel],0);
 
17439
      IDEMessageDialog('Error',E.Message,mtError,[mbCancel]);
16096
17440
    end;
16097
17441
  end;
16098
17442
end;
16102
17446
  DoBringToFrontFormOrInspector(True);
16103
17447
end;
16104
17448
 
16105
 
Procedure TMainIDE.OnSrcNoteBookAddJumpPoint(ACaretXY: TPoint;
 
17449
procedure TMainIDE.OnDesignerShowAnchorEditor(Sender: TObject);
 
17450
begin
 
17451
  DoViewAnchorEditor(True);
 
17452
end;
 
17453
 
 
17454
procedure TMainIDE.OnDesignerShowTabOrderEditor(Sender: TObject);
 
17455
begin
 
17456
  DoViewTabOrderEditor(True);
 
17457
end;
 
17458
 
 
17459
procedure TMainIDE.OnSrcNoteBookAddJumpPoint(ACaretXY: TPoint;
16106
17460
  ATopLine: integer; AEditor: TSourceEditor; DeleteForwardHistory: boolean);
16107
17461
{off $DEFINE VerboseJumpHistory}
16108
17462
var
16133
17487
  {$ENDIF}
16134
17488
end;
16135
17489
 
16136
 
Procedure TMainIDE.OnSrcNotebookDeleteLastJumPoint(Sender: TObject);
 
17490
procedure TMainIDE.OnSrcNotebookDeleteLastJumPoint(Sender: TObject);
16137
17491
begin
16138
17492
  Project1.JumpHistory.DeleteLast;
16139
17493
end;
16140
17494
 
16141
 
Procedure TMainIDE.OnSrcNotebookJumpToHistoryPoint(var NewCaretXY: TPoint;
16142
 
  var NewTopLine: integer; var DestEditor: TSourceEditor; JumpAction: TJumpHistoryAction);
 
17495
procedure TMainIDE.OnSrcNotebookJumpToHistoryPoint(var NewCaretXY: TPoint;
 
17496
  var NewTopLine: integer; var DestEditor: TSourceEditor;
 
17497
  JumpAction: TJumpHistoryAction);
16143
17498
{ How the HistoryIndex works:
16144
17499
 
16145
17500
  When the user jumps around each time an item is added to the history list
16280
17635
  ActiveUnitInfo.UserReadOnly:=ActiveSourceEditor.ReadOnly;
16281
17636
end;
16282
17637
 
16283
 
Procedure TMainIDE.OnSrcNotebookViewJumpHistory(Sender: TObject);
 
17638
procedure TMainIDE.OnSrcNotebookViewJumpHistory(Sender: TObject);
16284
17639
begin
16285
17640
  DoViewJumpHistory(true);
16286
17641
end;
16300
17655
 
16301
17656
  SrcNB := TSourceNotebook(Sender);
16302
17657
  if (SrcNB.EditorCount = 1) then begin
16303
 
    DoCloseEditorFile(SrcNB.Editors[0], []);
 
17658
    DoCloseEditorFile(SrcNB.Editors[0], [cfSaveFirst]);
16304
17659
    CloseAction := caFree;
16305
17660
    exit;
16306
17661
  end;
16307
17662
 
16308
17663
  CloseAction := caHide;
16309
 
  case QuestionDlg(lisCloseAllTabsTitle, lisCloseAllTabsQuestion, mtConfirmation,
16310
 
                  [mrYes, lisCloseAllTabsClose, mrNo, lisCloseAllTabsHide, mrCancel],
16311
 
                  0)
 
17664
  case IDEQuestionDialog(lisCloseAllTabsTitle, lisCloseAllTabsQuestion, mtConfirmation,
 
17665
                  [mrYes, lisCloseAllTabsClose, mrNo, lisCloseAllTabsHide, mrCancel])
16312
17666
  of
16313
17667
    mrYes : begin
16314
17668
        SourceEditorManager.IncUpdateLock;
16327
17681
  end;
16328
17682
end;
16329
17683
 
 
17684
procedure TMainIDE.CreateObjectInspector;
 
17685
begin
 
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
 
17706
 
 
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';
 
17712
    Interval:=400;
 
17713
    OnTimer:=@OIChangedTimerTimer;
 
17714
  end;
 
17715
  EnvironmentOptions.ObjectInspectorOptions.AssignTo(ObjectInspector1);
 
17716
 
 
17717
  // connect to designers
 
17718
  ObjectInspector1.PropertyEditorHook:=GlobalDesignHook;
 
17719
  if FormEditor1<>nil then
 
17720
    FormEditor1.Obj_Inspector := ObjectInspector1;
 
17721
end;
 
17722
 
16330
17723
procedure TMainIDE.OnApplicationUserInput(Sender: TObject; Msg: Cardinal);
16331
17724
begin
16332
17725
  fUserInputSinceLastIdle:=true;
16342
17735
  AnUnitInfo: TUnitInfo;
16343
17736
  AnIDesigner: TIDesigner;
16344
17737
  HasResources: Boolean;
 
17738
  FileItem: PStringToStringTreeItem;
16345
17739
begin
16346
 
  if FNeedUpdateHighlighters then
 
17740
  if FNeedUpdateHighlighters then begin
 
17741
    {$IFDEF VerboseIdle}
 
17742
    debugln(['TMainIDE.OnApplicationIdle FNeedUpdateHighlighters']);
 
17743
    {$ENDIF}
16347
17744
    UpdateHighlighters(true);
 
17745
  end;
 
17746
  if fNeedSaveEnvironment then
 
17747
    SaveEnvironment(true);
 
17748
 
16348
17749
  GetDefaultProcessList.FreeStoppedProcesses;
16349
 
  EnvironmentOptions.ExternalTools.FreeStoppedProcesses;
 
17750
  ExternalTools.FreeStoppedProcesses;
16350
17751
  if (SplashForm<>nil) then FreeThenNil(SplashForm);
16351
17752
 
 
17753
  if Assigned(FDesignerToBeFreed) then begin
 
17754
    for FileItem in FDesignerToBeFreed do begin
 
17755
      if Project1=nil then break;
 
17756
      AnUnitInfo:=Project1.UnitInfoWithFilename(FileItem^.Name);
 
17757
      if AnUnitInfo=nil then continue;
 
17758
      if AnUnitInfo.Component=nil then continue;
 
17759
      CloseUnitComponent(AnUnitInfo,[]);
 
17760
    end;
 
17761
    FreeAndNil(FDesignerToBeFreed);
 
17762
  end;
16352
17763
  if FUserInputSinceLastIdle then
16353
17764
  begin
 
17765
    {$IFDEF VerboseIdle}
 
17766
    debugln(['TMainIDE.OnApplicationIdle FUserInputSinceLastIdle']);
 
17767
    {$ENDIF}
16354
17768
    FUserInputSinceLastIdle:=false;
16355
 
    UpdateWindowMenu;
16356
17769
    FormEditor1.CheckDesignerPositions;
16357
17770
    FormEditor1.PaintAllDesignerItems;
16358
17771
    GetCurrentUnit(SrcEdit,AnUnitInfo);
16361
17774
    begin
16362
17775
      AnIDesigner:=Screen.ActiveForm.Designer;
16363
17776
      if AnIDesigner is TDesigner then
16364
 
      begin
16365
 
        MainIDEBar.itmViewToggleFormUnit.Enabled := true;
16366
 
      end
 
17777
        MainIDEBar.itmViewToggleFormUnit.Enabled := true
16367
17778
      else
16368
17779
      begin
16369
17780
        HasResources:=false;
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')) )
16377
17789
          then
16378
17790
            HasResources:=true;
16379
17791
        end;
16380
17792
        MainIDEBar.itmViewToggleFormUnit.Enabled := HasResources;
16381
17793
      end;
16382
17794
      MainIDEBar.ToggleFormSpeedBtn.Enabled := MainIDEBar.itmViewToggleFormUnit.Enabled;
16383
 
 
16384
17795
      DebugBoss.UpdateButtonsAndMenuItems;
16385
17796
    end;
16386
17797
  end;
16387
 
 
16388
 
  if FCheckFilesOnDiskNeeded then
 
17798
  if FCheckFilesOnDiskNeeded then begin
 
17799
    {$IFDEF VerboseIdle}
 
17800
    debugln(['TMainIDE.OnApplicationIdle FCheckFilesOnDiskNeeded']);
 
17801
    {$ENDIF}
16389
17802
    DoCheckFilesOnDisk(true);
16390
 
 
16391
 
  if (FRemoteControlTimer=nil) and EnableRemoteControl then
 
17803
  end;
 
17804
  if (FRemoteControlTimer=nil) and EnableRemoteControl then begin
 
17805
    {$IFDEF VerboseIdle}
 
17806
    debugln(['TMainIDE.OnApplicationIdle EnableRemoteControl']);
 
17807
    {$ENDIF}
16392
17808
    SetupRemoteControl;
16393
 
 
16394
 
  if Screen.GetCurrentModalForm=nil then
 
17809
  end;
 
17810
  if Screen.GetCurrentModalForm=nil then begin
 
17811
    {$IFDEF VerboseIdle}
 
17812
    debugln(['TMainIDE.OnApplicationIdle Screen.GetCurrentModalForm']);
 
17813
    {$ENDIF}
16395
17814
    PkgBoss.OpenHiddenModifiedPackages;
 
17815
  end;
 
17816
end;
 
17817
 
 
17818
procedure TMainIDE.OnApplicationDeActivate(Sender: TObject);
 
17819
var
 
17820
  i: Integer;
 
17821
  AForm: TCustomForm;
 
17822
begin
 
17823
  if EnvironmentOptions.SingleTaskBarButton and FApplicationIsActivate
 
17824
    and (MainIDEBar.WindowState=wsNormal) then
 
17825
  begin
 
17826
    for i:=Screen.CustomFormCount-1 downto 0 do
 
17827
    begin
 
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);
 
17833
    end;
 
17834
    FApplicationIsActivate:=false;
 
17835
  end;
 
17836
end;
 
17837
 
 
17838
procedure TMainIDE.OnMainBarActive(Sender: TObject);
 
17839
var
 
17840
  i, FormCount: integer;
 
17841
  AForm: TCustomForm;
 
17842
begin
 
17843
   if EnvironmentOptions.SingleTaskBarButton and not FApplicationIsActivate
 
17844
   and (MainIDEBar.WindowState=wsNormal) then
 
17845
  begin
 
17846
    FApplicationIsActivate:=true;
 
17847
    FormCount:=0;
 
17848
    for i:=Screen.CustomFormCount-1 downto 0 do
 
17849
    begin
 
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
 
17854
        inc(FormCount);
 
17855
    end;
 
17856
    if FormCount<>LastActivatedWindows.Count then
 
17857
      LastActivatedWindows.Clear;
 
17858
    while LastActivatedWindows.Count>0 do
 
17859
    begin
 
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);
 
17865
    end;
 
17866
    MainIDEBar.BringToFront;
 
17867
  end;
16396
17868
end;
16397
17869
 
16398
17870
procedure TMainIDE.OnApplicationActivate(Sender: TObject);
16410
17882
  if Command=ecEditContextHelp then begin
16411
17883
    Key:=VK_UNKNOWN;
16412
17884
    ShowContextHelpEditor(Sender);
16413
 
  end else if Command=ecContextHelp then begin
 
17885
  end else if (Command=ecContextHelp) and (Sender is TControl) then begin
16414
17886
    Key:=VK_UNKNOWN;
16415
 
    ShowContextHelpForIDE(Sender);
 
17887
    LazarusHelp.ShowHelpForIDEControl(TControl(Sender));
16416
17888
  end;
16417
17889
end;
16418
17890
 
16429
17901
    if Length(FileNames) > 1 then
16430
17902
      Include(OpenFlags, ofRegularFile);
16431
17903
 
16432
 
    for I := 0 to High(FileNames) do
16433
 
    begin
16434
 
      AFilename := CleanAndExpandFilename(FileNames[I]);
16435
 
 
16436
 
      if I < High(FileNames) then
16437
 
        Include(OpenFlags, ofMultiOpen)
16438
 
      else
16439
 
        Exclude(OpenFlags, ofMultiOpen);
16440
 
 
16441
 
      if DoOpenEditorFile(AFilename, -1, -1, OpenFlags) = mrAbort then Break;
 
17904
    try
 
17905
      SourceEditorManager.IncUpdateLock;
 
17906
      for I := 0 to High(FileNames) do
 
17907
      begin
 
17908
        AFilename := CleanAndExpandFilename(FileNames[I]);
 
17909
 
 
17910
        if I < High(FileNames) then
 
17911
          Include(OpenFlags, ofMultiOpen)
 
17912
        else
 
17913
          Exclude(OpenFlags, ofMultiOpen);
 
17914
 
 
17915
        if DoOpenEditorFile(AFilename, -1, -1, OpenFlags) = mrAbort then Break;
 
17916
      end;
 
17917
    finally
 
17918
      SourceEditorManager.DecUpdateLock;
16442
17919
    end;
16443
17920
 
16444
17921
    SetRecentFilesMenu;
16446
17923
  end;
16447
17924
end;
16448
17925
 
 
17926
procedure TMainIDE.OnApplicationQueryEndSession(var Cancel: Boolean);
 
17927
begin
 
17928
  Cancel := False;
 
17929
end;
 
17930
 
 
17931
procedure TMainIDE.OnApplicationEndSession(Sender: TObject);
 
17932
begin
 
17933
  QuitIDE;
 
17934
end;
 
17935
 
 
17936
procedure TMainIDE.OnScreenChangedForm(Sender: TObject; Form: TCustomForm);
 
17937
begin
 
17938
  if (Screen.ActiveForm = MainIDEBar) or
 
17939
     (WindowMenuActiveForm = Screen.ActiveForm)
 
17940
  then
 
17941
    exit;
 
17942
  WindowMenuActiveForm := Screen.ActiveForm;
 
17943
  UpdateWindowMenu(True);
 
17944
end;
 
17945
 
16449
17946
procedure TMainIDE.OnScreenRemoveForm(Sender: TObject; AForm: TCustomForm);
16450
17947
begin
16451
17948
  HiddenWindowsOnRun.Remove(AForm);
16491
17988
  if (ARow <> nil)
16492
17989
  and FindDeclarationOfOIProperty(OI, ARow, Code, Caret, NewTopLine) then
16493
17990
  begin
16494
 
    if CodeHelpBoss.GetHTMLHint(Code, Caret.X, Caret.Y, [chhoComplete],
 
17991
    if CodeHelpBoss.GetHTMLHint(Code, Caret.X, Caret.Y, [],
16495
17992
      BaseURL, HtmlHint, CacheWasUsed) <> chprSuccess then
16496
17993
    begin
16497
17994
      HtmlHint := '';
16567
18064
    ShortDir:=CurDirectory;
16568
18065
    if (not Project1.IsVirtual) then
16569
18066
      ShortDir:=CreateRelativePath(ShortDir,Project1.ProjectDirectory);
16570
 
    if MessageDlg(lisAddToUnitSearchPath,
 
18067
    if IDEMessageDialog(lisAddToUnitSearchPath,
16571
18068
      Format(lisTheNewUnitIsNotYetInTheUnitSearchPathAddDirectory, [
16572
18069
        #13, CurDirectory]),
16573
 
      mtConfirmation,[mbYes,mbNo],0)=mrYes
 
18070
      mtConfirmation,[mbYes,mbNo])=mrYes
16574
18071
    then begin
16575
18072
      Project1.CompilerOptions.OtherUnitFiles:=
16576
18073
            MergeSearchPaths(Project1.CompilerOptions.OtherUnitFiles,ShortDir);
16620
18117
    ShortDir:=CurDirectory;
16621
18118
    if (not Project1.IsVirtual) then
16622
18119
      ShortDir:=CreateRelativePath(ShortDir,Project1.ProjectDirectory);
16623
 
    if MessageDlg(lisAddToIncludeSearchPath,
 
18120
    if IDEMessageDialog(lisAddToIncludeSearchPath,
16624
18121
      Format(lisTheNewIncludeFileIsNotYetInTheIncludeSearchPathAdd, [#13,
16625
18122
        CurDirectory]),
16626
 
      mtConfirmation,[mbYes,mbNo],0)=mrYes
 
18123
      mtConfirmation,[mbYes,mbNo])=mrYes
16627
18124
    then begin
16628
18125
      Project1.CompilerOptions.IncludePath:=
16629
18126
            MergeSearchPaths(Project1.CompilerOptions.IncludePath,ShortDir);
16637
18134
  ActiveSourceEditor: TSourceEditor;
16638
18135
  ActiveUnitInfo: TUnitInfo;
16639
18136
  ShortUnitName: String;
16640
 
  Dummy: Boolean;
16641
18137
  DependencyAdded: boolean;
16642
18138
begin
16643
18139
  Result:=mrOk;
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;
 
18154
        end else begin
 
18155
          DoJumpToCodeToolBossError;
 
18156
          Result:=mrCancel;
 
18157
        end;
 
18158
      end;
 
18159
    end;
 
18160
  end
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)
16654
 
  then begin
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;
16663
 
      end else begin
16664
 
        DoJumpToCodeToolBossError;
16665
 
        Result:=mrCancel;
16666
 
      end;
16667
 
    end;
16668
 
  end;
16669
18163
  Project1.Modified:=true;
16670
18164
end;
16671
18165
 
16672
18166
function TMainIDE.ProjInspectorRemoveFile(Sender: TObject; AnUnitInfo: TUnitInfo
16673
18167
  ): TModalresult;
16674
18168
var
16675
 
  ActiveSourceEditor: TSourceEditor;
16676
 
  ActiveUnitInfo: TUnitInfo;
16677
 
  ShortUnitName: String;
16678
 
  Dummy: Boolean;
 
18169
  UnitInfos: TFPList;
16679
18170
begin
16680
 
  Result:=mrOk;
16681
 
  if not AnUnitInfo.IsPartOfProject then exit;
16682
 
  Project1.BeginUpdate(true);
 
18171
  if not AnUnitInfo.IsPartOfProject then exit(mrOk);
 
18172
  UnitInfos:=TFPList.Create;
16683
18173
  try
16684
 
    AnUnitInfo.IsPartOfProject:=false;
16685
 
    if (Project1.MainUnitID>=0)
16686
 
    and (pfMainUnitHasUsesSectionForAllUnits in Project1.Flags)
16687
 
    then begin
16688
 
      BeginCodeTool(ActiveSourceEditor,ActiveUnitInfo,[]);
16689
 
      ShortUnitName:=AnUnitInfo.Unit_Name;
16690
 
      if (ShortUnitName<>'') then begin
16691
 
        Dummy:=CodeToolBoss.RemoveUnitFromAllUsesSections(
16692
 
                                      Project1.MainUnitInfo.Source,ShortUnitName);
16693
 
        if Dummy then
16694
 
          Project1.MainUnitInfo.Modified:=true
16695
 
        else begin
16696
 
          ApplyCodeToolChanges;
16697
 
          DoJumpToCodeToolBossError;
16698
 
          Result:=mrCancel;
16699
 
          exit;
16700
 
        end;
16701
 
      end;
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;
16708
 
          Result:=mrCancel;
16709
 
          exit;
16710
 
        end;
16711
 
      end;
16712
 
      ApplyCodeToolChanges;
16713
 
    end;
16714
 
    Project1.Modified:=true;
 
18174
    UnitInfos.Add(AnUnitInfo);
 
18175
    Result:=RemoveFilesFromProject(Project1,UnitInfos);
16715
18176
  finally
16716
 
    Project1.EndUpdate;
 
18177
    UnitInfos.Free;
16717
18178
  end;
16718
18179
end;
16719
18180
 
16722
18183
  DoTestCompilerSettings(Sender as TCompilerOptions);
16723
18184
end;
16724
18185
 
16725
 
procedure TMainIDE.OnCheckCompOptsAndMainSrcForNewUnit(
16726
 
  CompOpts: TLazCompilerOptions);
 
18186
function TMainIDE.OnCheckCompOptsAndMainSrcForNewUnit(
 
18187
  CompOpts: TLazCompilerOptions): TModalResult;
16727
18188
begin
16728
 
  CheckCompOptsAndMainSrcForNewUnit(CompOpts);
 
18189
  Result:=CheckCompOptsAndMainSrcForNewUnit(CompOpts);
16729
18190
end;
16730
18191
 
16731
18192
procedure TMainIDE.ProjInspectorOpen(Sender: TObject);
16733
18194
  CurUnitInfo: TUnitInfo;
16734
18195
begin
16735
18196
  CurUnitInfo:=ProjInspector.GetSelectedFile;
16736
 
  if CurUnitInfo<>nil then begin
16737
 
    DoOpenEditorFile(CurUnitInfo.Filename,-1,-1,[ofRegularFile]);
16738
 
    exit;
16739
 
  end;
16740
 
  if PkgBoss.OnProjectInspectorOpen(Sender) then exit;
 
18197
  if CurUnitInfo<>nil then
 
18198
    DoOpenEditorFile(CurUnitInfo.Filename,-1,-1,[ofRegularFile])
 
18199
  else
 
18200
    PkgBoss.OnProjectInspectorOpen(Sender);
16741
18201
end;
16742
18202
 
16743
18203
procedure TMainIDE.OnExtToolNeedsOutputFilter(var OutputFilter: TOutputFilter;
16769
18229
  aBounds: TRect; out DockSibling: string; out DockAlign: TAlign);
16770
18230
var
16771
18231
  SrcEditWnd: TSourceNotebook;
 
18232
  ScreenR: TRect;
16772
18233
begin
16773
18234
  DockSibling:='';
16774
18235
  DockAlign:=alNone;
16775
18236
  if (ObjectInspector1<>nil) and (aFormName=ObjectInspector1.Name) then begin
16776
18237
    // place object inspector below main bar
16777
 
    aBounds:=Rect(0,Min(MainIDEBar.Top+MainIDEBar.Height+25,200),230,Screen.Height-150);
16778
 
    // do not dock object inspector, because this would hide the designers
 
18238
    ScreenR:=IDEWindowCreators.GetScreenrectForDefaults;
 
18239
    aBounds:=Rect(ScreenR.Left,
 
18240
       Min(MainIDEBar.Top+MainIDEBar.Height+25,200),230,
 
18241
       ScreenR.Bottom-ScreenR.Top-150);
 
18242
    // do not dock object inspector, because this would hide the floating designers
16779
18243
  end
16780
18244
  else if (aFormName=NonModalIDEWindowNames[nmiwMessagesViewName]) then begin
16781
18245
    // place messages below source editor
 
18246
    ScreenR:=IDEWindowCreators.GetScreenrectForDefaults;
16782
18247
    if SourceEditorManager.SourceWindowCount>0 then begin
16783
18248
      SrcEditWnd:=SourceEditorManager.SourceWindows[0];
16784
18249
      aBounds:=GetParentForm(SrcEditWnd).BoundsRect;
16785
18250
      aBounds.Top:=aBounds.Bottom+25;
16786
18251
      aBounds.Bottom:=aBounds.Top+100;
16787
18252
    end else begin
16788
 
      aBounds:=Rect(250,Screen.Height-200,Screen.Width-250,100);
 
18253
      aBounds:=Rect(ScreenR.Left+250,ScreenR.Bottom-200,ScreenR.Right-250,100);
16789
18254
    end;
16790
18255
    if IDEDockMaster<>nil then begin
16791
18256
      DockSibling:=NonModalIDEWindowNames[nmiwSourceNoteBookName];
16794
18259
  end;
16795
18260
end;
16796
18261
 
16797
 
procedure TMainIDE.RenameInheritedMethods(AnUnitInfo: TUnitInfo; List: TStrings
16798
 
  );
 
18262
procedure TMainIDE.RenameInheritedMethods(AnUnitInfo: TUnitInfo; List: TStrings);
16799
18263
var
16800
18264
  UsedByDependency: TUnitComponentDependency;
16801
18265
  DependingUnit: TUnitInfo;
16836
18300
var
16837
18301
  HelpControl: TControl;
16838
18302
begin
16839
 
  if FOIHelpProvider = nil then
 
18303
  if (FOIHelpProvider = nil) and (ObjectInspector1<>nil) then
16840
18304
  begin
16841
 
    HelpControl := CreateIDEHTMLControl(ObjectInspector1, FOIHelpProvider);
 
18305
    HelpControl := CreateIDEHTMLControl(ObjectInspector1, FOIHelpProvider, [ihcScrollable]);
16842
18306
    HelpControl.Parent := ObjectInspector1.InfoPanel;
16843
18307
    HelpControl.Align := alClient;
16844
18308
    HelpControl.BorderSpacing.Around := 2;
 
18309
    HelpControl.Color := clForm;
16845
18310
  end;
16846
18311
  Result := FOIHelpProvider;
16847
18312
end;
16876
18341
  ): TCustomForm;
16877
18342
begin
16878
18343
  Result:=nil;
 
18344
 
16879
18345
  if AnUnitInfo.Component<>nil then
16880
18346
    Result:=FormEditor1.GetDesignerForm(AnUnitInfo.Component);
16881
18347
  if ((Result=nil) or (Result.Designer=nil)) and LoadForm
16925
18391
var
16926
18392
  ActiveSrcEdit: TSourceEditor;
16927
18393
  ActiveUnitInfo: TUnitInfo;
16928
 
  //D: DWord;
16929
18394
begin
16930
18395
  if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[ctfSwitchToFormSource]) then
16931
18396
    Exit;
16933
18398
  WriteLn('');
16934
18399
  WriteLn('[TMainIDE.OnPropHookMethodExists] ************ ',AMethodName);
16935
18400
  {$ENDIF}
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
16943
18405
  begin
16944
18406
    DoJumpToCodeToolBossError;
16945
 
    raise Exception.Create(lisUnableToFindMethodPleaseFixTheErrorShownInTheMessage);
 
18407
    raise Exception.Create(lisUnableToFindMethod+' '+lisPleaseFixTheErrorInTheMessageWindow);
16946
18408
  end;
16947
18409
end;
16948
18410
 
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
 
18420
}
 
18421
{ $DEFINE VerboseOnPropHookCreateMethod}
16952
18422
var
16953
18423
  ActiveSrcEdit: TSourceEditor;
16954
18424
  ActiveUnitInfo: TUnitInfo;
 
18425
 
 
18426
  function GetInheritedMethodPath: string;
 
18427
  var
 
18428
    OldJITMethod: TJITMethod;
 
18429
    OldMethod: TMethod;
 
18430
    APropName: String;
 
18431
    p: Integer;
 
18432
    OldMethodOwner: TComponent;
 
18433
  begin
 
18434
    Result:='';
 
18435
    {$IFDEF VerboseOnPropHookCreateMethod}
 
18436
    debugln(['  GetInheritedMethodPath APersistent=',DbgSName(APersistent),' APropertyPath="',APropertyPath,'" AMethodName="',AMethodName,'"']);
 
18437
    {$ENDIF}
 
18438
 
 
18439
    // get old method
 
18440
    p:=length(APropertyPath);
 
18441
    while (p>0) and (APropertyPath[p]<>'.') do dec(p);
 
18442
    if p<1 then exit;
 
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']);
 
18448
      {$ENDIF}
 
18449
      exit;
 
18450
    end;
 
18451
 
 
18452
    {$IFDEF VerboseOnPropHookCreateMethod}
 
18453
    debugln(['  GetInheritedMethodPath  OldJITMethod=',DbgSName(OldJITMethod.TheClass),'.',OldJITMethod.TheMethodName]);
 
18454
    {$ENDIF}
 
18455
 
 
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),')']);
 
18462
      {$ENDIF}
 
18463
      exit;
 
18464
    end;
 
18465
    // the old method is from another lookup root (e.g. not the current form)
 
18466
 
 
18467
    if ActiveUnitInfo.Component.InheritsFrom(OldJITMethod.TheClass) then
 
18468
    begin
 
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,'"']);
 
18474
      {$ENDIF}
 
18475
      exit;
 
18476
    end;
 
18477
 
 
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)
 
18483
    else begin
 
18484
      {$IFDEF VerboseOnPropHookCreateMethod}
 
18485
      debugln(['  GetInheritedMethodPath there is no simple way to get the owner of a TPersistent. Not calling old method.']);
 
18486
      {$ENDIF}
 
18487
      exit;
 
18488
    end;
 
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.']);
 
18495
      {$ENDIF}
 
18496
      exit;
 
18497
    end;
 
18498
 
 
18499
    {$IFDEF VerboseOnPropHookCreateMethod}
 
18500
    DebugLn(['  GetInheritedMethodPath OldMethodOwner=',dbgsName(OldMethodOwner)]);
 
18501
    {$ENDIF}
 
18502
    // create a path to the nested component
 
18503
    while (OldMethodOwner<>nil) and (OldMethodOwner<>ActiveUnitInfo.Component) do
 
18504
    begin
 
18505
      if Result<>'' then
 
18506
        Result:='.'+Result;
 
18507
      Result:=OldMethodOwner.Name+Result;
 
18508
      OldMethodOwner:=OldMethodOwner.Owner;
 
18509
    end;
 
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]);
 
18515
      {$ENDIF}
 
18516
    end;
 
18517
    Result:='';
 
18518
  end;
 
18519
 
 
18520
var
16955
18521
  r: boolean;
16956
18522
  OldChange: Boolean;
16957
 
  p: Integer;
16958
 
  APropName: String;
16959
 
  OldMethod: TMethod;
16960
 
  JITMethod: TJITMethod;
16961
 
  OverrideMethodName: String;
16962
 
  AComponent: TComponent;
 
18523
  InheritedMethodPath: String;
16963
18524
begin
16964
18525
  Result.Code:=nil;
16965
18526
  Result.Data:=nil;
16966
18527
  if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[ctfSwitchToFormSource])
16967
18528
  then exit;
16968
 
  {$IFDEF IDE_DEBUG}
 
18529
  {$IFDEF VerboseOnPropHookCreateMethod}
16969
18530
  debugln('');
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]);
16972
18533
  {$ENDIF}
16973
 
 
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);
16979
 
    if p>0 then begin
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
16994
 
          begin
16995
 
            if OverrideMethodName<>'' then
16996
 
              OverrideMethodName:='.'+OverrideMethodName;
16997
 
            OverrideMethodName:=AComponent.Name+OverrideMethodName;
16998
 
            AComponent:=AComponent.Owner;
16999
 
          end;
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]);
17006
 
          end;
17007
 
        end;
17008
 
      end;
17009
 
    end;
 
18534
  if ActiveUnitInfo.Component=nil then begin
 
18535
    {$IFDEF VerboseOnPropHookCreateMethod}
 
18536
    debugln(['TMainIDE.OnPropHookCreateMethod failed ActiveUnitInfo.Component=nil']);
 
18537
    {$ENDIF}
17010
18538
  end;
17011
18539
 
 
18540
  InheritedMethodPath:=GetInheritedMethodPath;
17012
18541
  OldChange:=OpenEditorsOnCodeToolChange;
17013
18542
  OpenEditorsOnCodeToolChange:=true;
17014
18543
  try
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]);
 
18547
    {$ENDIF}
17016
18548
    r:=CodeToolBoss.CreatePublishedMethod(ActiveUnitInfo.Source,
17017
18549
        ActiveUnitInfo.Component.ClassName,AMethodName,
17018
18550
        ATypeInfo,false,GetClassUnitName(APersistent.ClassType),APropertyPath,
17019
 
        OverrideMethodName);
17020
 
    {$IFDEF IDE_DEBUG}
17021
 
    debugln('');
17022
 
    debugln('[TMainIDE.OnPropHookCreateMethod] ************2 ',r,' ',AMethodName);
 
18551
        InheritedMethodPath);
 
18552
    {$IFDEF VerboseOnPropHookCreateMethod}
 
18553
    debugln(['[TMainIDE.OnPropHookCreateMethod] ************ ',dbgs(r),' AMethodName="',AMethodName,'"']);
17023
18554
    {$ENDIF}
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);
17032
18563
    end;
17033
18564
  finally
17034
18565
    OpenEditorsOnCodeToolChange:=OldChange;
17075
18606
    AClassName,CurMethodName,
17076
18607
    NewSource,NewX,NewY,NewTopLine) then
17077
18608
  begin
17078
 
    DoJumpToCodePos(ActiveSrcEdit, ActiveUnitInfo,
17079
 
      NewSource, NewX, NewY, NewTopLine, true);
 
18609
    DoJumpToCodePosition(ActiveSrcEdit, ActiveUnitInfo,
 
18610
      NewSource, NewX, NewY, NewTopLine, [jfAddJumpPoint, jfFocusEditor]);
17080
18611
  end else begin
17081
18612
    DebugLn(['TMainIDE.OnPropHookShowMethod failed finding the method in code']);
17082
18613
    DoJumpToCodeToolBossError;
17083
 
    raise Exception.Create(lisUnableToShowMethodPleaseFixTheErrorShownInTheMessage
17084
 
      );
 
18614
    raise Exception.Create(lisUnableToShowMethod+' '+lisPleaseFixTheErrorInTheMessageWindow);
17085
18615
  end;
17086
18616
end;
17087
18617
 
17138
18668
  Result:=false;
17139
18669
  if (not (AParent is TControl))
17140
18670
  and (APersistentClass.InheritsFrom(TControl)) then begin
17141
 
    MessageDlg(lisCodeToolsDefsInvalidParent,
 
18671
    IDEMessageDialog(lisCodeToolsDefsInvalidParent,
17142
18672
      Format(lisACanNotHoldTControlsYouCanOnlyPutNonVisualComponen, [
17143
18673
        AParent.ClassName, #13]),
17144
 
      mtError,[mbCancel],0);
 
18674
      mtError,[mbCancel]);
17145
18675
    UpdateIDEComponentPalette;
17146
18676
    exit;
17147
18677
  end;
17156
18686
procedure TMainIDE.OnPropHookModified(Sender: TObject);
17157
18687
begin
17158
18688
  // any change of property can cause a change of a display name
17159
 
  ObjectInspector1.FillPersistentComboBox;
 
18689
  if ObjectInspector1<>nil then
 
18690
    ObjectInspector1.FillPersistentComboBox;
17160
18691
end;
17161
18692
 
17162
18693
{-------------------------------------------------------------------------------
17166
18697
  This handler is called whenever a new component was added to a designed form
17167
18698
  and should be added to form source
17168
18699
-------------------------------------------------------------------------------}
17169
 
procedure TMainIDE.OnPropHookPersistentAdded(APersistent: TPersistent;
17170
 
  Select: boolean);
 
18700
procedure TMainIDE.OnPropHookPersistentAdded(APersistent: TPersistent; Select: boolean);
17171
18701
var
17172
18702
  RegComp: TRegisteredComponent;
17173
18703
  ADesigner: TDesigner;
17206
18736
    ADesigner:=FindRootDesigner(AComponent) as TDesigner;
17207
18737
  end;
17208
18738
 
17209
 
  if (RegComp<>nil) or (ClassUnitInfo<>nil) then begin
 
18739
  if (ADesigner<>nil) and ((RegComp<>nil) or (ClassUnitInfo<>nil)) then begin
17210
18740
    if not BeginCodeTool(ADesigner,ActiveSrcEdit,ActiveUnitInfo,
17211
18741
      [ctfSwitchToFormSource])
17212
18742
    then exit;
17235
18765
                                   Ancestor);
17236
18766
  end;
17237
18767
 
17238
 
  ObjectInspector1.FillPersistentComboBox;
 
18768
  if ObjectInspector1<>nil then
 
18769
    ObjectInspector1.FillPersistentComboBox;
17239
18770
 
17240
18771
  //writeln('TMainIDE.OnPropHookPersistentAdded D ',AComponent.Name,':',AComponent.ClassName,' ',Select);
17241
18772
  // select component
17348
18879
end;
17349
18880
 
17350
18881
procedure TMainIDE.mnuEditCopyClicked(Sender: TObject);
 
18882
var
 
18883
  ActiveDesigner: TComponentEditorDesigner;
17351
18884
begin
17352
 
  DoSourceEditorCommand(ecCopy);
 
18885
  ActiveDesigner := GetActiveDesignerSkipMainBar;
 
18886
  if Assigned(ActiveDesigner) then
 
18887
    ActiveDesigner.CopySelection
 
18888
  else
 
18889
    DoSourceEditorCommand(ecCopy);
17353
18890
end;
17354
18891
 
17355
18892
procedure TMainIDE.mnuEditCutClicked(Sender: TObject);
 
18893
var
 
18894
  ActiveDesigner: TComponentEditorDesigner;
17356
18895
begin
17357
 
  DoSourceEditorCommand(ecCut);
 
18896
  ActiveDesigner := GetActiveDesignerSkipMainBar;
 
18897
  if Assigned(ActiveDesigner) then
 
18898
    ActiveDesigner.CutSelection
 
18899
  else
 
18900
    DoSourceEditorCommand(ecCut);
17358
18901
end;
17359
18902
 
17360
18903
procedure TMainIDE.mnuEditPasteClicked(Sender: TObject);
 
18904
var
 
18905
  ActiveDesigner: TComponentEditorDesigner;
17361
18906
begin
17362
 
  DoSourceEditorCommand(ecPaste);
 
18907
  ActiveDesigner := GetActiveDesignerSkipMainBar;
 
18908
  if Assigned(ActiveDesigner) then
 
18909
    ActiveDesigner.PasteSelection([cpsfFindUniquePositions])
 
18910
  else
 
18911
    DoSourceEditorCommand(ecPaste);
17363
18912
end;
17364
18913
 
17365
18914
procedure TMainIDE.mnuEditRedoClicked(Sender: TObject);
17382
18931
  DoSourceEditorCommand(ecBlockUnindent);
17383
18932
end;
17384
18933
 
17385
 
procedure TMainIDE.mnuEditEncloseBlockClicked(Sender: TObject);
 
18934
procedure TMainIDE.mnuSourceEncloseBlockClicked(Sender: TObject);
17386
18935
begin
17387
18936
  DoSourceEditorCommand(ecSelectionEnclose);
17388
18937
end;
17397
18946
  DoSourceEditorCommand(ecSelectionLowerCase);
17398
18947
end;
17399
18948
 
 
18949
procedure TMainIDE.mnuEditSwapCaseBlockClicked(Sender: TObject);
 
18950
begin
 
18951
  DoSourceEditorCommand(ecSelectionSwapCase);
 
18952
end;
 
18953
 
17400
18954
procedure TMainIDE.mnuEditTabsToSpacesBlockClicked(Sender: TObject);
17401
18955
begin
17402
18956
  DoSourceEditorCommand(ecSelectionTabs2Spaces);
17403
18957
end;
17404
18958
 
17405
 
procedure TMainIDE.mnuEditCommentBlockClicked(Sender: TObject);
 
18959
procedure TMainIDE.mnuSourceCommentBlockClicked(Sender: TObject);
17406
18960
begin
17407
18961
  DoSourceEditorCommand(ecSelectionComment);
17408
18962
end;
17409
18963
 
17410
 
procedure TMainIDE.mnuEditUncommentBlockClicked(Sender: TObject);
 
18964
procedure TMainIDE.mnuSourceUncommentBlockClicked(Sender: TObject);
17411
18965
begin
17412
18966
  DoSourceEditorCommand(ecSelectionUncomment);
17413
18967
end;
17414
18968
 
17415
 
procedure TMainIDE.mnuEditToggleCommentClicked(Sender: TObject);
 
18969
procedure TMainIDE.mnuSourceToggleCommentClicked(Sender: TObject);
17416
18970
begin
17417
18971
  DoSourceEditorCommand(ecToggleComment);
17418
18972
end;
17419
18973
 
17420
 
procedure TMainIDE.mnuEditConditionalBlockClicked(Sender: TObject);
 
18974
procedure TMainIDE.mnuSourceEncloseInIFDEFClicked(Sender: TObject);
17421
18975
begin
17422
 
  DoSourceEditorCommand(ecSelectionConditional);
 
18976
  DoSourceEditorCommand(ecSelectionEncloseIFDEF);
17423
18977
end;
17424
18978
 
17425
18979
procedure TMainIDE.mnuEditSortBlockClicked(Sender: TObject);
17426
18980
begin
 
18981
  // MG: sometimes the function does nothing
 
18982
  debugln(['TMainIDE.mnuEditSortBlockClicked ',DbgSName(FindOwnerControl(GetFocus))]);
17427
18983
  DoSourceEditorCommand(ecSelectionSort);
17428
18984
end;
17429
18985
 
17447
19003
  DoSourceEditorCommand(ecSelectToBrace);
17448
19004
end;
17449
19005
 
 
19006
procedure TMainIDE.mnuEditSelectWordClick(Sender: TObject);
 
19007
begin
 
19008
  DoSourceEditorCommand(ecSelectWord);
 
19009
end;
 
19010
 
17450
19011
procedure TMainIDE.mnuEditSelectLineClick(Sender: TObject);
17451
19012
begin
17452
19013
  DoSourceEditorCommand(ecSelectLine);
17457
19018
  DoSourceEditorCommand(ecSelectParagraph);
17458
19019
end;
17459
19020
 
17460
 
procedure TMainIDE.mnuEditInsertGPLNoticeClick(Sender: TObject);
 
19021
procedure TMainIDE.mnuSourceInsertGPLNoticeClick(Sender: TObject);
17461
19022
begin
17462
19023
  DoSourceEditorCommand(ecInsertGPLNotice);
17463
19024
end;
17464
19025
 
17465
 
procedure TMainIDE.mnuEditInsertLGPLNoticeClick(Sender: TObject);
 
19026
procedure TMainIDE.mnuSourceInsertLGPLNoticeClick(Sender: TObject);
17466
19027
begin
17467
19028
  DoSourceEditorCommand(ecInsertLGPLNotice);
17468
19029
end;
17469
19030
 
17470
 
procedure TMainIDE.mnuEditInsertModifiedLGPLNoticeClick(Sender: TObject);
 
19031
procedure TMainIDE.mnuSourceInsertModifiedLGPLNoticeClick(Sender: TObject);
17471
19032
begin
17472
19033
  DoSourceEditorCommand(ecInsertModifiedLGPLNotice);
17473
19034
end;
17474
19035
 
17475
 
procedure TMainIDE.mnuEditInsertUsernameClick(Sender: TObject);
 
19036
procedure TMainIDE.mnuSourceInsertMITNoticeClick(Sender: TObject);
 
19037
begin
 
19038
  DoSourceEditorCommand(ecInsertMITNotice);
 
19039
end;
 
19040
 
 
19041
procedure TMainIDE.mnuSourceInsertUsernameClick(Sender: TObject);
17476
19042
begin
17477
19043
  DoSourceEditorCommand(ecInsertUserName);
17478
19044
end;
17479
19045
 
17480
 
procedure TMainIDE.mnuEditInsertDateTimeClick(Sender: TObject);
 
19046
procedure TMainIDE.mnuSourceInsertDateTimeClick(Sender: TObject);
17481
19047
begin
17482
19048
  DoSourceEditorCommand(ecInsertDateTime);
17483
19049
end;
17484
19050
 
17485
 
procedure TMainIDE.mnuEditInsertChangeLogEntryClick(Sender: TObject);
 
19051
procedure TMainIDE.mnuSourceInsertChangeLogEntryClick(Sender: TObject);
17486
19052
begin
17487
19053
  DoSourceEditorCommand(ecInsertChangeLogEntry);
17488
19054
end;
17489
19055
 
17490
 
procedure TMainIDE.mnuEditInsertGUID(Sender: TObject);
 
19056
procedure TMainIDE.mnuSourceInsertGUID(Sender: TObject);
17491
19057
begin
17492
19058
  DoInsertGUID;
17493
19059
end;
17494
19060
 
 
19061
procedure TMainIDE.mnuSourceInsertFilename(Sender: TObject);
 
19062
begin
 
19063
  DoInsertFilename;
 
19064
end;
 
19065
 
17495
19066
procedure TMainIDE.mnuSearchFindInFiles(Sender: TObject);
17496
19067
begin
17497
19068
  DoFindInFiles;
17502
19073
  DoFindRenameIdentifier(false);
17503
19074
end;
17504
19075
 
17505
 
procedure TMainIDE.mnuSearchRenameIdentifierClicked(Sender: TObject);
17506
 
begin
17507
 
  DoFindRenameIdentifier(true);
17508
 
end;
17509
 
 
17510
 
procedure TMainIDE.mnuEditCompleteCodeClicked(Sender: TObject);
17511
 
begin
17512
 
  DoCompleteCodeAtCursor;
17513
 
end;
17514
 
 
17515
 
procedure TMainIDE.mnuEditExtractProcClicked(Sender: TObject);
17516
 
begin
17517
 
  DoExtractProcFromSelection;
17518
 
end;
17519
 
 
17520
19076
procedure TMainIDE.mnuEditInsertCharacterClicked(Sender: TObject);
17521
19077
begin
17522
19078
  DoSourceEditorCommand(ecInsertCharacter);
17523
19079
end;
17524
19080
 
17525
 
procedure TMainIDE.mnuEditInsertCVSAuthorClick(Sender: TObject);
 
19081
procedure TMainIDE.mnuSourceInsertCVSAuthorClick(Sender: TObject);
17526
19082
begin
17527
19083
  DoSourceEditorCommand(ecInsertCVSAuthor);
17528
19084
end;
17529
19085
 
17530
 
procedure TMainIDE.mnuEditInsertCVSDateClick(Sender: TObject);
 
19086
procedure TMainIDE.mnuSourceInsertCVSDateClick(Sender: TObject);
17531
19087
begin
17532
19088
  DoSourceEditorCommand(ecInsertCVSDate);
17533
19089
end;
17534
19090
 
17535
 
procedure TMainIDE.mnuEditInsertCVSHeaderClick(Sender: TObject);
 
19091
procedure TMainIDE.mnuSourceInsertCVSHeaderClick(Sender: TObject);
17536
19092
begin
17537
19093
  DoSourceEditorCommand(ecInsertCVSHeader);
17538
19094
end;
17539
19095
 
17540
 
procedure TMainIDE.mnuEditInsertCVSIDClick(Sender: TObject);
 
19096
procedure TMainIDE.mnuSourceInsertCVSIDClick(Sender: TObject);
17541
19097
begin
17542
19098
  DoSourceEditorCommand(ecInsertCVSID);
17543
19099
end;
17544
19100
 
17545
 
procedure TMainIDE.mnuEditInsertCVSLogClick(Sender: TObject);
 
19101
procedure TMainIDE.mnuSourceInsertCVSLogClick(Sender: TObject);
17546
19102
begin
17547
19103
  DoSourceEditorCommand(ecInsertCVSLog);
17548
19104
end;
17549
19105
 
17550
 
procedure TMainIDE.mnuEditInsertCVSNameClick(Sender: TObject);
 
19106
procedure TMainIDE.mnuSourceInsertCVSNameClick(Sender: TObject);
17551
19107
begin
17552
19108
  DoSourceEditorCommand(ecInsertCVSName);
17553
19109
end;
17554
19110
 
17555
 
procedure TMainIDE.mnuEditInsertCVSRevisionClick(Sender: TObject);
 
19111
procedure TMainIDE.mnuSourceInsertCVSRevisionClick(Sender: TObject);
17556
19112
begin
17557
19113
  DoSourceEditorCommand(ecInsertCVSRevision);
17558
19114
end;
17559
19115
 
17560
 
procedure TMainIDE.mnuEditInsertCVSSourceClick(Sender: TObject);
 
19116
procedure TMainIDE.mnuSourceInsertCVSSourceClick(Sender: TObject);
17561
19117
begin
17562
19118
  DoSourceEditorCommand(ecInsertCVSSource);
17563
19119
end;
17564
19120
 
 
19121
procedure TMainIDE.mnuSourceCompleteCodeClicked(Sender: TObject);
 
19122
begin
 
19123
  DoCompleteCodeAtCursor;
 
19124
end;
 
19125
 
 
19126
procedure TMainIDE.mnuSourceUseUnitClicked(Sender: TObject);
 
19127
begin
 
19128
  DoSourceEditorCommand(ecUseUnit);
 
19129
end;
 
19130
 
 
19131
procedure TMainIDE.mnuRefactorRenameIdentifierClicked(Sender: TObject);
 
19132
begin
 
19133
  DoFindRenameIdentifier(true);
 
19134
end;
 
19135
 
 
19136
procedure TMainIDE.mnuRefactorExtractProcClicked(Sender: TObject);
 
19137
begin
 
19138
  DoExtractProcFromSelection;
 
19139
end;
 
19140
 
 
19141
procedure TMainIDE.mnuRefactorInvertAssignmentClicked(Sender: TObject);
 
19142
begin
 
19143
  DoSourceEditorCommand(ecInvertAssignment);
 
19144
end;
 
19145
 
 
19146
procedure TMainIDE.mnuRefactorShowAbstractMethodsClicked(Sender: TObject);
 
19147
begin
 
19148
  DoSourceEditorCommand(ecShowAbstractMethods);
 
19149
end;
 
19150
 
 
19151
procedure TMainIDE.mnuRefactorShowEmptyMethodsClicked(Sender: TObject);
 
19152
begin
 
19153
  DoSourceEditorCommand(ecRemoveEmptyMethods);
 
19154
end;
 
19155
 
 
19156
procedure TMainIDE.mnuRefactorShowUnusedUnitsClicked(Sender: TObject);
 
19157
begin
 
19158
  DoSourceEditorCommand(ecRemoveUnusedUnits);
 
19159
end;
 
19160
 
 
19161
procedure TMainIDE.mnuRefactorFindOverloadsClicked(Sender: TObject);
 
19162
begin
 
19163
  DoSourceEditorCommand(ecFindOverloads);
 
19164
end;
 
19165
 
17565
19166
procedure TMainIDE.DoCommand(ACommand: integer);
17566
19167
var
17567
19168
  ActiveSourceEditor: TSourceEditor;
17587
19188
  end;
17588
19189
end;
17589
19190
 
17590
 
procedure TMainIDE.DoSourceEditorCommand(EditorCommand: integer);
 
19191
procedure TMainIDE.DoSourceEditorCommand(EditorCommand: integer; CheckFocus: boolean);
17591
19192
var
17592
19193
  CurFocusControl: TWinControl;
 
19194
  ActiveSourceEditor: TSourceEditor;
 
19195
  ActiveUnitInfo: TUnitInfo;
17593
19196
begin
17594
 
  // check that the currently focus is on the MainIDEBar or on the SourceEditor
17595
 
  CurFocusControl:=FindOwnerControl(GetFocus);
17596
 
  if (CurFocusControl<>nil) then begin
17597
 
    CurFocusControl:=GetParentForm(CurFocusControl);
17598
 
    if (CurFocusControl<>MainIDEBar) and not(CurFocusControl is TSourceNotebook) then
17599
 
    begin
17600
 
      // continue processing shortcut, not handled yet
17601
 
      MainIDEBar.mnuMainMenu.ShortcutHandled := false;
17602
 
      exit;
 
19197
  CurFocusControl:=Nil;
 
19198
  ActiveSourceEditor:=Nil;
 
19199
  // check if focus is on MainIDEBar or on SourceEditor
 
19200
  if CheckFocus then
 
19201
  begin
 
19202
    CurFocusControl:=FindOwnerControl(GetFocus);
 
19203
    while (CurFocusControl<>nil) do begin
 
19204
      if (CurFocusControl=MainIDEBar) or (CurFocusControl is TSourceNotebook) then
 
19205
        break;
 
19206
      CurFocusControl:=CurFocusControl.Parent;
17603
19207
    end;
17604
19208
  end;
17605
 
  DoCommand(EditorCommand);
 
19209
  if Assigned(CurFocusControl) then
 
19210
  begin    // MainIDEBar or SourceNotebook has focus -> find active source editor
 
19211
    GetCurrentUnit(ActiveSourceEditor,ActiveUnitInfo);
 
19212
    if Assigned(ActiveSourceEditor) then
 
19213
      ActiveSourceEditor.DoEditorExecuteCommand(EditorCommand); // pass the command
 
19214
  end;
 
19215
  // Not passed to source editor -> continue processing shortcut, not handled yet
 
19216
  if (CurFocusControl=Nil) or (ActiveSourceEditor=Nil) then
 
19217
    MainIDEBar.mnuMainMenu.ShortcutHandled := false;
17606
19218
end;
17607
19219
 
17608
19220
procedure TMainIDE.DoInsertGUID;
17615
19227
begin
17616
19228
  // get active source editor
17617
19229
  if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[]) then exit;
17618
 
  if ActiveSrcEdit = nil then
17619
 
    Exit; //==>
 
19230
  if ActiveSrcEdit = nil then Exit;
17620
19231
 
17621
19232
  CreateGUID(lGUID);
17622
19233
  ActiveSrcEdit.Selection := Format(cGUID, [GUIDToString(lGUID)]);
17623
19234
end;
17624
19235
 
 
19236
procedure TMainIDE.DoInsertFilename;
 
19237
var
 
19238
  ActiveSrcEdit: TSourceEditor;
 
19239
  ActiveUnitInfo: TUnitInfo;
 
19240
begin
 
19241
  if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[]) then exit;
 
19242
  if ActiveSrcEdit = nil then Exit;
 
19243
  with TOpenDialog.Create(nil) do
 
19244
  try
 
19245
    Title:=lisSelectFile;
 
19246
    if Execute then
 
19247
      ActiveSrcEdit.Selection := FileName;
 
19248
  finally
 
19249
    Free;
 
19250
  end;
 
19251
end;
 
19252
 
17625
19253
function TMainIDE.DoReplaceUnitUse(OldFilename, OldUnitName, NewFilename,
17626
19254
  NewUnitName: string; IgnoreErrors, Quiet, Confirm: boolean): TModalResult;
17627
19255
{ Replaces all references to a unit
17636
19264
  PascalReferences: TAVLTree;
17637
19265
  i: Integer;
17638
19266
  MsgResult: TModalResult;
 
19267
  OnlyEditorFiles: Boolean;
 
19268
  aFilename: String;
17639
19269
begin
17640
19270
  if (CompareFilenames(OldFilename,NewFilename)=0)
17641
19271
  and (OldUnitName=NewUnitName) then // compare unitnames case sensitive, maybe only the case changed
17642
19272
    exit(mrOk);
 
19273
  OnlyEditorFiles:=not FilenameIsAbsolute(OldFilename); // this was a new file, files on disk can not refer to it
17643
19274
 
17644
19275
  OwnerList:=nil;
17645
19276
  OldCode:=nil;
17647
19278
  PascalReferences:=nil;
17648
19279
  Files:=TStringList.Create;
17649
19280
  try
17650
 
    // get owners of unit
17651
 
    OwnerList:=PkgBoss.GetOwnersOfUnit(NewFilename);
17652
 
    if OwnerList=nil then exit(mrOk);
17653
 
    PkgBoss.ExtendOwnerListWithUsedByOwners(OwnerList);
17654
 
    ReverseList(OwnerList);
 
19281
    if OnlyEditorFiles then begin
 
19282
      // search only in open files
 
19283
      for i:=0 to SourceEditorManagerIntf.UniqueSourceEditorCount-1 do begin
 
19284
        aFilename:=SourceEditorManagerIntf.UniqueSourceEditors[i].FileName;
 
19285
        if not FilenameIsPascalSource(aFilename) then continue;
 
19286
        Files.Add(aFileName);
 
19287
      end;
 
19288
      // add project's main source file
 
19289
      if (Project1<>nil) and (Project1.MainUnitID>=0) then
 
19290
        Files.Add(Project1.MainFilename);
 
19291
    end else begin
 
19292
      // get owners of unit
 
19293
      OwnerList:=PkgBoss.GetOwnersOfUnit(NewFilename);
 
19294
      if OwnerList=nil then exit(mrOk);
 
19295
      PkgBoss.ExtendOwnerListWithUsedByOwners(OwnerList);
 
19296
      ReverseList(OwnerList);
17655
19297
 
17656
 
    // get source files of packages and projects
17657
 
    ExtraFiles:=PkgBoss.GetSourceFilesOfOwners(OwnerList);
17658
 
    try
17659
 
      if ExtraFiles<>nil then
17660
 
        Files.AddStrings(ExtraFiles);
17661
 
    finally
17662
 
      ExtraFiles.Free;
 
19298
      // get source files of packages and projects
 
19299
      ExtraFiles:=PkgBoss.GetSourceFilesOfOwners(OwnerList);
 
19300
      try
 
19301
        if ExtraFiles<>nil then
 
19302
          Files.AddStrings(ExtraFiles);
 
19303
      finally
 
19304
        ExtraFiles.Free;
 
19305
      end;
17663
19306
    end;
17664
19307
    for i:=Files.Count-1 downto 0 do begin
17665
19308
      if (CompareFilenames(Files[i],OldFilename)=0)
17772
19415
  {$I ../images/laz_images.lrs}
17773
19416
  // we have a bundle icon, don't use low quality standard icon
17774
19417
  ShowSplashScreen:=true;
 
19418
  DebugLogger.ParamForEnabledLogGroups := '--debug-enable=';
17775
19419
end.
17776
19420
 
17777
19421