1 {
2  /***************************************************************************
3                     mainbase.pas  -  the "integrated" in IDE
4                     ----------------------------------------
5   TMainIDEBase is the ancestor of TMainIDE. The various top level parts of the
6   IDE (called bosses/managers) access the TMainIDE via TMainIDEBase.
7 
8 
9   main.pp      - TMainIDE = class(TMainIDEBase)
10                    The highest manager/boss of the IDE. Only lazarus.pp uses
11                    this unit.
12   mainbase.pas - TMainIDEBase = class(TMainIDEInterface)
13                    The ancestor class used by (and only by) the other
14                    bosses/managers like debugmanager, pkgmanager.
15   mainintf.pas - TMainIDEInterface = class(TLazIDEInterface)
16                    The interface class of the top level functions of the IDE.
17                    TMainIDEInterface is used by functions/units, that uses
18                    several different parts of the IDE (designer, source editor,
19                    codetools), so they can't be added to a specific boss and
20                    which are yet too small to become a boss of their own.
21   lazideintf.pas - TLazIDEInterface = class(TComponent)
22                    For designtime packages, this is the interface class of the
23                    top level functions of the IDE.
24 
25  ***************************************************************************/
26 
27  ***************************************************************************
28  *                                                                         *
29  *   This source is free software; you can redistribute it and/or modify   *
30  *   it under the terms of the GNU General Public License as published by  *
31  *   the Free Software Foundation; either version 2 of the License, or     *
32  *   (at your option) any later version.                                   *
33  *                                                                         *
34  *   This code is distributed in the hope that it will be useful, but      *
35  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
36  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
37  *   General Public License for more details.                              *
38  *                                                                         *
39  *   A copy of the GNU General Public License is available on the World    *
40  *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
41  *   obtain it by writing to the Free Software Foundation,                 *
42  *   Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA.   *
43  *                                                                         *
44  ***************************************************************************
45 }
46 unit MainBase;
47 
48 {$mode objfpc}{$H+}
49 
50 interface
51 
52 {$I ide.inc}
53 
54 uses
55   {$IFDEF IDE_MEM_CHECK}
56   MemCheck,
57   {$ENDIF}
58   // RTL + FCL
59   Classes, SysUtils, Types, Math,
60   // LCL
61   LCLProc, Buttons, Menus, ComCtrls, Controls, Graphics, Dialogs, Forms, ImgList,
62   // LazUtils
63   LazFileUtils, LazUTF8,
64   // Codetools
65   CodeToolManager,
66   // SynEdit
67   SynEditKeyCmds,
68   // IDEIntf
69   IDEImagesIntf, SrcEditorIntf, LazIDEIntf, MenuIntf, NewItemIntf, PackageIntf,
70   IDECommands, IDEWindowIntf, ProjectIntf, ToolBarIntf, ObjectInspector,
71   PropEdits, IDEDialogs, IDEUtils, EditorSyntaxHighlighterDef,
72   // IDE
73   LazConf, LazarusIDEStrConsts, Project, EnvironmentOpts,
74   EditorOptions, CompilerOptions, SourceEditor, SourceSynEditor, FindInFilesDlg,
75   Splash, MainBar, MainIntf, Designer, Debugger, RunParamsOpts;
76 
77 type
78   TResetToolFlag = (
79     rfInteractive,
80     rfCloseOnDone,
81     rfSuccessOnTrigger
82   );
83   TResetToolFlags = set of TResetToolFlag;
84 
85   TIdleIdeAction = (
86     iiaUpdateHighlighters,
87     iiaSaveEnvironment,
88     iiaUserInputSinceLastIdle,
89     iiaCheckFilesOnDisk,
90     iiaUpdateDefineTemplates,
91     iiaRestartWanted
92   );
93   TIdleIdeActions = set of TIdleIdeAction;
94 
95   { TMainIDEBase }
96 
97   TMainIDEBase = class(TMainIDEInterface)
98   private
99     FWindowMenuActiveForm: TCustomForm;
100     FDisplayState: TDisplayState;
101     procedure SetDisplayState(AValue: TDisplayState);
102     procedure UpdateWindowMenu;
103   protected
104     FIdleIdeActions: TIdleIdeActions;
105 
CreateMenuSeparatornull106     function CreateMenuSeparator(Section: TIDEMenuSection): TIDEMenuCommand;
107     procedure CreateMenuItem(Section: TIDEMenuSection;
108                              var MenuCommand: TIDEMenuCommand;
109                              const MenuItemName, MenuItemCaption: String;
110                              const bmpName: String = '';
111                              mnuEnabled: Boolean = true;
112                              mnuChecked: Boolean = false;
113                              mnuVisible: Boolean = true);
114     procedure CreateMenuSeparatorSection(ParentSection: TIDEMenuSection;
115                              var Section: TIDEMenuSection; const AName: String);
116     procedure CreateMenuSubSection(ParentSection: TIDEMenuSection;
117                              var Section: TIDEMenuSection;
118                              const AName, ACaption: String;
119                              const bmpName: String = '');
120     procedure CreateMainMenuItem(var Section: TIDEMenuSection;
121                                  const MenuItemName, MenuItemCaption: String);
122     procedure SetupMainMenu; virtual;
123     procedure SetupAppleMenu; virtual;
124     procedure SetupFileMenu; virtual;
125     procedure SetupEditMenu; virtual;
126     procedure SetupSearchMenu; virtual;
127     procedure SetupViewMenu; virtual;
128     procedure SetupSourceMenu; virtual;
129     procedure SetupProjectMenu; virtual;
130     procedure SetupRunMenu; virtual;
131     procedure SetupPackageMenu; virtual;
132     procedure SetupToolsMenu; virtual;
133     procedure SetupWindowsMenu; virtual;
134     procedure SetupHelpMenu; virtual;
135 
136     procedure LoadMenuShortCuts; virtual;
137     procedure SetToolStatus(const AValue: TIDEToolStatus); override;
138 
139     procedure DoMnuWindowClicked(Sender: TObject);
140     procedure ShowMainIDEBar(Center: boolean);
141     procedure mnuOpenProjectClicked(Sender: TObject); virtual; abstract;
142     procedure mnuOpenRecentClicked(Sender: TObject);
143     procedure mnuWindowItemClick(Sender: TObject); virtual;
144     procedure mnuCenterWindowItemClick(Sender: TObject); virtual;
145     procedure mnuWindowSourceItemClick(Sender: TObject); virtual;
146     procedure mnuBuildModeClicked(Sender: TObject); virtual; abstract;
147 
148   public
DoResetToolStatusnull149     function DoResetToolStatus(AFlags: TResetToolFlags): boolean; virtual; abstract;
150 
151     constructor Create(TheOwner: TComponent); override;
152     procedure StartIDE; virtual; abstract;
153     destructor Destroy; override;
154     procedure CreateOftenUsedForms; virtual; abstract;
GetMainBarnull155     function GetMainBar: TForm; override;
BeginCodeToolnull156     function BeginCodeTool(var ActiveSrcEdit: TSourceEditor;
157                            out ActiveUnitInfo: TUnitInfo;
158                            Flags: TCodeToolsFlags): boolean;
BeginCodeToolnull159     function BeginCodeTool(ADesigner: TDesigner;
160                            var ActiveSrcEdit: TSourceEditor;
161                            out ActiveUnitInfo: TUnitInfo;
162                            Flags: TCodeToolsFlags): boolean;
163     procedure ActivateCodeToolAbortableMode;
OnCodeToolBossCheckAbortnull164     function OnCodeToolBossCheckAbort: boolean;
165     procedure DoShowDesignerFormOfCurrentSrc(AComponentPaletteClassSelected: Boolean); virtual; abstract;
CreateDesignerForComponentnull166     function CreateDesignerForComponent(AnUnitInfo: TUnitInfo;
167                         AComponent: TComponent): TCustomForm; virtual; abstract;
168     procedure UpdateSaveMenuItemsAndButtons(UpdateSaveAll: boolean); virtual; abstract;
169 
170     procedure DoMergeDefaultProjectOptions;
171     procedure DoSwitchToFormSrc(var ActiveSourceEditor:TSourceEditor;
172       var ActiveUnitInfo:TUnitInfo);
173     procedure DoSwitchToFormSrc(ADesigner: TIDesigner;
174       var ActiveSourceEditor:TSourceEditor; var ActiveUnitInfo:TUnitInfo);
175 
176     procedure GetUnitInfoForDesigner(ADesigner: TIDesigner;
177                               out ActiveSourceEditor: TSourceEditorInterface;
178                               out ActiveUnitInfo: TUnitInfo); override;
179     procedure GetCurrentUnitInfo(out ActiveSourceEditor: TSourceEditorInterface;
180                               out ActiveUnitInfo: TUnitInfo); override;
181     procedure GetCurrentUnit(out ActiveSourceEditor: TSourceEditor;
182                              out ActiveUnitInfo: TUnitInfo); virtual; abstract;
183     procedure GetDesignerUnit(ADesigner: TDesigner;
184           out ActiveSourceEditor: TSourceEditor; out ActiveUnitInfo: TUnitInfo); virtual; abstract;
185     procedure GetObjectInspectorUnit(
186           out ActiveSourceEditor: TSourceEditor; out ActiveUnitInfo: TUnitInfo); virtual; abstract;
187     procedure GetUnitWithForm(AForm: TCustomForm;
188           out ActiveSourceEditor: TSourceEditor; out ActiveUnitInfo: TUnitInfo); virtual; abstract;
189     procedure GetUnitWithPersistent(APersistent: TPersistent;
190           out ActiveSourceEditor: TSourceEditor; out ActiveUnitInfo: TUnitInfo); virtual; abstract;
191     procedure DoShowComponentList(State: TIWGetFormState = iwgfShowOnTop); virtual; abstract;
192 
DoOpenMacroFilenull193     function DoOpenMacroFile(Sender: TObject; const AFilename: string): TModalResult; override;
194 
195     procedure SetRecentSubMenu(Section: TIDEMenuSection; FileList: TStringList;
196                                OnClickEvent: TNotifyEvent); override;
197     procedure SetRecentProjectFilesMenu;
198     procedure SetRecentFilesMenu;
199     procedure UpdateRecentFilesEnv;
200     procedure DoOpenRecentFile(AFilename: string);
201 
202     procedure UpdateHighlighters(Immediately: boolean = false); override;
203     procedure UpdateDefineTemplates;
204 
205     procedure FindInFilesPerDialog(AProject: TProject); override;
206     procedure FindInFiles(AProject: TProject; const FindText: string); override;
207 
208     procedure SelComponentPageButtonMouseDown(Sender: TObject;
209       Button: TMouseButton; Shift: TShiftState; X, Y: Integer); virtual; abstract;
210     procedure SelComponentPageButtonClick(Sender: TObject); virtual; abstract;
211   public
212     property WindowMenuActiveForm: TCustomForm read FWindowMenuActiveForm write FWindowMenuActiveForm;
213     property DisplayState: TDisplayState read FDisplayState write SetDisplayState;
214   end;
215 
216   { TOpenFileToolButton }
217 
218   TOpenFileToolButton = class(TIDEToolButton)
219   private
220     FIndex: TStringList;
221 
222     procedure RefreshMenu(Sender: TObject);
223     procedure mnuOpenFile(Sender: TObject);
224     procedure mnuProjectFile(Sender: TObject);
225   public
226     constructor Create(aOwner: TComponent); override;
227     destructor Destroy; override;
228 
229     procedure DoOnAdded; override;
230   end;
231 
232   { TOpenFileMenuItem }
233 
234   TOpenFileMenuItem = class(TMenuItem)
235   public
236     FileName: string;
237   end;
238 
239   { TNewFormUnitToolButton }
240 
241   TNewFormUnitToolButton = class(TIDEToolButton)
242   private
243     SetDefaultMenuItem: TMenuItem;
244 
245     procedure RefreshMenu(Sender: TObject);
246     procedure mnuSetFormUnitTemplate(Sender: TObject);
247   protected
FindDefaultTemplateNamenull248     class function FindDefaultTemplateName(Category: TNewIDEItemCategory): string; virtual; abstract;
249     class procedure SetTemplateName(const TemplateName: string); virtual; abstract;
250     class procedure UpdateHint(const AHint: string); virtual; abstract;
251   public
252     procedure DoOnAdded; override;
253 
254     class procedure UpdateHints;
255   end;
256 
257   { TNewUnitToolButton }
258 
259   TNewUnitToolButton = class(TNewFormUnitToolButton)
260   protected
FindDefaultTemplateNamenull261     class function FindDefaultTemplateName(Category: TNewIDEItemCategory): string; override;
262     class procedure SetTemplateName(const TemplateName: string); override;
263     class procedure UpdateHint(const AHint: string); override;
264   end;
265 
266   { TNewFormToolButton }
267 
268   TNewFormToolButton = class(TNewFormUnitToolButton)
269   protected
FindDefaultTemplateNamenull270     class function FindDefaultTemplateName(Category: TNewIDEItemCategory): string; override;
271     class procedure SetTemplateName(const TemplateName: string); override;
272     class procedure UpdateHint(const AHint: string); override;
273   end;
274 
275   { TNewFormUnitMenuItem }
276 
277   TNewFormUnitMenuItem = class(TMenuItem)
278   public
279     TemplateName: string;
280   end;
281 
282   TRunOptionItem = class(TMenuItem)
283   public
284     RunOptionName: string;
285   end;
286 
287   TRunToolButton = class(TIDEToolButton)
288   private
289     procedure ChangeRunMode(Sender: TObject);
290     procedure MenuOnPopup(Sender: TObject);
291 
292     procedure RefreshMenu;
293     procedure RunParametersClick(Sender: TObject);
294   public
295     procedure DoOnAdded; override;
296   end;
297 
GetMainIdenull298 function GetMainIde: TMainIDEBase;
PrepareForCompileWithMsgnull299 function PrepareForCompileWithMsg: TModalResult; // Ensure starting compilation is OK.
UpdateTargetFilenamenull300 function UpdateTargetFilename(const ABaseFN: String): Boolean;
301 
302 property MainIDE: TMainIDEBase read GetMainIde;
303 
304   { Normally the IDE builds itself with packages named in config files.
305     When the IDE should keep the packages installed in the current executable
306     set KeepInstalledPackages to true. }
307 var KeepInstalledPackages: boolean = false;
308 
309 implementation
310 
GetMainIdenull311 function GetMainIde: TMainIDEBase;
312 begin
313   Result := TMainIDEBase(MainIDEInterface)
314 end;
315 
PrepareForCompileWithMsgnull316 function PrepareForCompileWithMsg: TModalResult;
317 begin
318   Result:=mrCancel;
319   if Project1=nil then exit;
320   if Project1.MainUnitInfo=nil then
321     // this project has no source to compile
322     IDEMessageDialog(lisCanNotCompileProject,lisTheProjectHasNoMainSourceFile,mtError,[mbCancel])
323   else
324     Result:=MainIDE.PrepareForCompile;
325 end;
326 
UpdateTargetFilenamenull327 function UpdateTargetFilename(const ABaseFN: String): Boolean;
328 // Return True if Project1.TargetFilename was actually changed.
329 var
330   TargetF, StemFN, NewTargetFN: String;
331   i: Integer;
332 begin
333   TargetF:=ExtractFileName(Project1.TargetFilename);
334   StemFN:=ExtractFileNameOnly(ABaseFN);
335   if (TargetF='') or (StemFN='') then exit(False);   // Using default -> ok
336   Result:=CompareFilenames(TargetF,StemFN)<>0;       // Names differ -> update.
337   if Result then
338   begin
339     NewTargetFN:=ExtractFilePath(Project1.TargetFilename) + StemFN
340                + ExtractFileExt(TargetF);
341     for i := 0 to Project1.BuildModes.Count-1 do     // Update all buildmodes.
342       Project1.BuildModes[i].CompilerOptions.TargetFilename:=NewTargetFN;
343   end;
344 end;
345 
346 { TNewFormUnitToolButton }
347 
348 procedure TNewFormUnitToolButton.DoOnAdded;
349 begin
350   inherited DoOnAdded;
351 
352   PopupMenu := TPopupMenu.Create(Self);
353   PopupMenu.OnPopup := @RefreshMenu;
354 
355   SetDefaultMenuItem:=TMenuItem.Create(PopupMenu);
356   SetDefaultMenuItem.Caption:=lisSetDefault;
357   PopupMenu.Items.Add(SetDefaultMenuItem);
358 
359   UpdateHints;
360 end;
361 
362 procedure TNewFormUnitToolButton.mnuSetFormUnitTemplate(Sender: TObject);
363 begin
364   SetTemplateName((Sender as TNewFormUnitMenuItem).TemplateName);
365   EnvironmentOptions.Save(False);
366 
367   UpdateHints;
368 end;
369 
370 procedure TNewFormUnitToolButton.RefreshMenu(Sender: TObject);
371 var
372   TemplateName: String;
373   Category: TNewIDEItemCategory;
374   i: Integer;
375   CurTemplate: TNewIDEItemTemplate;
376   TheIndex: Integer;
377   xItem: TNewFormUnitMenuItem;
378 begin
379   Category:=NewIDEItems.FindCategoryByPath(FileDescGroupName,true);
380   TemplateName:=FindDefaultTemplateName(Category);
381 
382   // create menu items
383   TheIndex:=0;
384   for i:=0 to Category.Count-1 do begin
385     CurTemplate:=Category[i];
386     if not CurTemplate.VisibleInNewDialog then continue;
387     if TheIndex<SetDefaultMenuItem.Count then
388       xItem:=SetDefaultMenuItem[TheIndex] as TNewFormUnitMenuItem
389     else begin
390       xItem:=TNewFormUnitMenuItem.Create(SetDefaultMenuItem);
391       SetDefaultMenuItem.Add(xItem);
392     end;
393     xItem.OnClick:=@mnuSetFormUnitTemplate;
394     xItem.Caption:=CurTemplate.LocalizedName;
395     xItem.TemplateName:=CurTemplate.Name;
396     xItem.ShowAlwaysCheckable:=true;
397     xItem.Checked:=CompareText(TemplateName,CurTemplate.Name)=0;
398     inc(TheIndex);
399   end;
400   // remove unneeded items
401   while SetDefaultMenuItem.Count>TheIndex do
402     SetDefaultMenuItem.Items[SetDefaultMenuItem.Count-1].Free;
403 end;
404 
405 class procedure TNewFormUnitToolButton.UpdateHints;
406 var
407   Category: TNewIDEItemCategory;
408   TemplateName: String;
409   Template: TNewIDEItemTemplate;
410 begin
411   if not Assigned(NewIDEItems) then
412     Exit;
413   Category:=NewIDEItems.FindCategoryByPath(FileDescGroupName,true);
414   TemplateName:=FindDefaultTemplateName(Category);
415   if TemplateName<>'' then  //try to get the LocalizedName
416   begin
417     Template:=Category.FindTemplateByName(TemplateName);
418     if Assigned(Template) then
419       TemplateName := Template.LocalizedName;
420   end;
421   UpdateHint(Format(lisMenuNewCustom, [TemplateName]));
422 end;
423 
424 { TNewFormToolButton }
425 
TNewFormToolButton.FindDefaultTemplateNamenull426 class function TNewFormToolButton.FindDefaultTemplateName(
427   Category: TNewIDEItemCategory): string;
428 begin
429   Result:=EnvironmentOptions.NewFormTemplate;
430   if (Result='') or (Category.FindTemplateByName(Result)=nil) then
431     Result:=FileDescNameLCLForm;
432 end;
433 
434 class procedure TNewFormToolButton.SetTemplateName(const TemplateName: string);
435 begin
436   EnvironmentOptions.NewFormTemplate:=TemplateName;
437 end;
438 
439 class procedure TNewFormToolButton.UpdateHint(const AHint: string);
440 begin
441   MainIDEBar.itmFileNewForm.Hint := AHint;
442 end;
443 
444 { TNewUnitToolButton }
445 
TNewUnitToolButton.FindDefaultTemplateNamenull446 class function TNewUnitToolButton.FindDefaultTemplateName(
447   Category: TNewIDEItemCategory): string;
448 begin
449   Result:=EnvironmentOptions.NewUnitTemplate;
450   if (Result='') or (Category.FindTemplateByName(Result)=nil) then
451     Result:=FileDescNamePascalUnit;
452 end;
453 
454 class procedure TNewUnitToolButton.SetTemplateName(const TemplateName: string);
455 begin
456   EnvironmentOptions.NewUnitTemplate:=TemplateName;
457 end;
458 
459 class procedure TNewUnitToolButton.UpdateHint(const AHint: string);
460 begin
461   MainIDEBar.itmFileNewUnit.Hint := AHint;
462 end;
463 
464 { TOpenFileToolButton }
465 
466 constructor TOpenFileToolButton.Create(aOwner: TComponent);
467 begin
468   inherited Create(aOwner);
469 
470   FIndex := TStringList.Create;
471 end;
472 
473 destructor TOpenFileToolButton.Destroy;
474 begin
475   FIndex.Free;
476 
477   inherited Destroy;
478 end;
479 
480 procedure TOpenFileToolButton.DoOnAdded;
481 begin
482   inherited DoOnAdded;
483 
484   DropdownMenu := TPopupMenu.Create(Self);
485   DropdownMenu.OnPopup := @RefreshMenu;
486   DropdownMenu.Images := LCLGlyphs;
487   Style := tbsDropDown;
488 end;
489 
490 procedure TOpenFileToolButton.mnuOpenFile(Sender: TObject);
491 begin
492   // Hint holds the full filename, Caption may have a shortened form.
493   MainIDE.DoOpenRecentFile((Sender as TOpenFileMenuItem).Hint);
494 end;
495 
496 procedure TOpenFileToolButton.mnuProjectFile(Sender: TObject);
497 begin
498   MainIDE.DoOpenProjectFile((Sender as TOpenFileMenuItem).Hint, [ofAddToRecent]);
499 end;
500 
501 procedure TOpenFileToolButton.RefreshMenu(Sender: TObject);
502 
503   procedure AddFile(const AFileName: string; const AOnClick: TNotifyEvent);
504   var
505     AMenuItem: TOpenFileMenuItem;
506   begin
507     AMenuItem := TOpenFileMenuItem.Create(DropdownMenu);
508     DropdownMenu.Items.Add(AMenuItem);
509     AMenuItem.OnClick := AOnClick;
510     AMenuItem.FileName := AFileName;
511     AMenuItem.Caption := ShortDisplayFilename(AFilename);
512     AMenuItem.Hint := AFilename; // Hint is not shown, it just holds the full filename.
513     if FilenameExtIn(AFileName,['.lpi','.lpr']) then
514       AMenuItem.ImageIndex := LoadProjectIconIntoImages(AFileName, DropdownMenu.Images, FIndex);
515   end;
516 
517   procedure AddFiles(List: TStringList; MaxCount: integer; const AOnClick: TNotifyEvent);
518   var
519     i: integer;
520   begin
521     i := 0;
522     while (i < List.Count) and (i < MaxCount) do
523     begin
524       AddFile(List[i], AOnClick);
525       inc(i);
526     end;
527   end;
528 
529 begin
530   DropdownMenu.Items.Clear;
531 
532   // first add recent projects
533   AddFiles(EnvironmentOptions.RecentProjectFiles, EnvironmentOptions.MaxRecentProjectFiles,
534            @mnuProjectFile);
535   // add a separator
536   DropdownMenu.Items.AddSeparator;
537   // then add recent files
538   AddFiles(EnvironmentOptions.RecentOpenFiles, EnvironmentOptions.MaxRecentOpenFiles,
539            @mnuOpenFile);
540 end;
541 
542 {$IFDEF LCLCocoa}
543 var
544   mnuApple: TIDEMenuSection = nil;
545   itmAppleAbout: TIDEMenuSection;
546   itmApplePref: TIDEMenuSection;
547 {$ENDIF}
548 
FormMatchesCmdnull549 function FormMatchesCmd(aForm: TCustomForm; aCmd: TIDEMenuCommand): Boolean;
550 begin
551   if EnvironmentOptions.Desktop.IDENameForDesignedFormList and IsFormDesign(aForm) then
552     Result := aForm.Name = aCmd.Caption
553   else
554     Result := aForm.Caption = aCmd.Caption;
555 end;
556 
557 { TMainIDEBase }
558 
559 procedure TMainIDEBase.mnuWindowItemClick(Sender: TObject);
560 var
561   Form: TCustomForm;
562 begin
563   Form:=TCustomForm(TIDEMenuCommand(Sender).UserTag);
564   if Form=MainIDEBar then
565     ShowMainIDEBar(false)
566   else
567     IDEWindowCreators.ShowForm(Form, true);
568 end;
569 
570 procedure TMainIDEBase.mnuCenterWindowItemClick(Sender: TObject);
571 var
572   i: Integer;
573   Form: TCustomForm;
574   r, NewBounds: TRect;
575 begin
576   Form:=TCustomForm(TIDEMenuCommand(Sender).UserTag);
577   if Form=MainIDEBar then begin
578     ShowMainIDEBar(true);
579     exit;
580   end;
581 
582   i:=Screen.CustomFormCount-1;
583   while (i>=0) do begin
584     Form:=Screen.CustomForms[i];
585     if FormMatchesCmd(Form, Sender as TIDEMenuCommand) then
586     begin
587       // show
588       if not Form.IsVisible then
589         IDEWindowCreators.ShowForm(Form,true);
590       // move to monitor of main IDE bar
591       Form:=GetParentForm(Form);
592       if Form<>MainIDEBar then begin
593         // center on main IDE
594         Form.MakeFullyVisible(MainIDEBar.Monitor,true);
595         debugln(['TMainIDEBase.mnuCenterWindowItemClick ',DbgSName(Form),' ',dbgs(Form.BoundsRect)]);
596         r:=MainIDEBar.BoundsRect;
597         if Form.Width<MainIDEBar.Width then
598           NewBounds.Left:=(r.Left+r.Right-Form.Width) div 2
599         else
600           NewBounds.Left:=r.Left+50;
601         if Form.Height<MainIDEBar.Height then
602           NewBounds.Top:=(r.Top+r.Bottom-Form.Height) div 2
603         else
604           NewBounds.Top:=r.Top+50;
605         NewBounds.Right:=NewBounds.Left+Max(70,Form.Width);
606         NewBounds.Bottom:=NewBounds.Top+Max(70,Form.Height);
607         debugln(['TMainIDEBase.mnuCenterWindowItemClick New=',dbgs(NewBounds)]);
608         Form.BoundsRect:=NewBounds;
609         Form.WindowState:=wsNormal;
610         Form.BringToFront;
611       end;
612       break;
613     end;
614     dec(i);
615   end;
616 end;
617 
618 procedure TMainIDEBase.mnuWindowSourceItemClick(Sender: TObject);
619 var
620   i: LongInt;
621 begin
622   if SourceEditorManager = nil then exit;
623   i:=(sender as TIDEMenuCommand).tag;
624   if (i<0) or (i>=SourceEditorManager.SourceEditorCount) then exit;
625   SourceEditorManager.ActiveEditor := SourceEditorManager.SourceEditors[i];
626   SourceEditorManager.ShowActiveWindowOnTop(True);
627 end;
628 
629 procedure TMainIDEBase.SetToolStatus(const AValue: TIDEToolStatus);
630 begin
631   if ToolStatus=AValue then exit;
632   inherited SetToolStatus(AValue);
633   UpdateCaption;
634 end;
635 
636 constructor TMainIDEBase.Create(TheOwner: TComponent);
637 begin
638   // Do not own everything in one big component hierachy. Otherwise the
639   // notifications slow down everything
640   fOwningComponent:=TComponent.Create(nil);
641   inherited Create(TheOwner);
642 end;
643 
644 destructor TMainIDEBase.Destroy;
645 begin
646   FreeThenNil(fOwningComponent);
647   inherited Destroy;
648 end;
649 
650 procedure TMainIDEBase.GetUnitInfoForDesigner(ADesigner: TIDesigner;
651   out ActiveSourceEditor: TSourceEditorInterface; out ActiveUnitInfo: TUnitInfo);
652 var
653   SrcEdit: TSourceEditor;
654 begin
655   ActiveSourceEditor:=nil;
656   ActiveUnitInfo:=nil;
657   if ADesigner is TDesigner then begin
658     GetDesignerUnit(TDesigner(ADesigner),SrcEdit,ActiveUnitInfo);
659     ActiveSourceEditor:=SrcEdit;
660   end;
661 end;
662 
663 procedure TMainIDEBase.GetCurrentUnitInfo(
664   out ActiveSourceEditor: TSourceEditorInterface; out ActiveUnitInfo: TUnitInfo);
665 var
666   ASrcEdit: TSourceEditor;
667   AnUnitInfo: TUnitInfo;
668 begin
669   GetCurrentUnit(ASrcEdit, AnUnitInfo);
670   ActiveSourceEditor:=ASrcEdit;
671   ActiveUnitInfo:=AnUnitInfo;
672 end;
673 
GetMainBarnull674 function TMainIDEBase.GetMainBar: TForm;
675 begin
676   Result:=MainIDEBar;
677 end;
678 
BeginCodeToolnull679 function TMainIDEBase.BeginCodeTool(var ActiveSrcEdit: TSourceEditor;
680   out ActiveUnitInfo: TUnitInfo; Flags: TCodeToolsFlags): boolean;
681 begin
682   Result:=BeginCodeTool(nil,ActiveSrcEdit,ActiveUnitInfo,Flags);
683 end;
684 
BeginCodeToolnull685 function TMainIDEBase.BeginCodeTool(ADesigner: TDesigner;
686   var ActiveSrcEdit: TSourceEditor; out ActiveUnitInfo: TUnitInfo;
687   Flags: TCodeToolsFlags): boolean;
688 var
689   Edit: TIDESynEditor;
690 begin
691   Result:=false;
692   if (ctfUseGivenSourceEditor in Flags) and (Project1<>nil)
693   and (ActiveSrcEdit<>nil) then begin
694     ActiveUnitInfo := Project1.EditorInfoWithEditorComponent(ActiveSrcEdit).UnitInfo;
695   end
696   else begin
697     ActiveSrcEdit:=nil;
698     ActiveUnitInfo:=nil;
699   end;
700 
701   // check global stati
702   if (ToolStatus in [itCodeTools,itCodeToolAborting]) then begin
703     debugln('TMainIDEBase.BeginCodeTool impossible ',dbgs(ord(ToolStatus)));
704     exit;
705   end;
706   if (not (ctfSourceEditorNotNeeded in Flags)) and (SourceEditorManager.SourceEditorCount=0)
707   then begin
708     //DebugLn('TMainIDEBase.BeginCodeTool no source editor');
709     exit;
710   end;
711 
712   // check source editor
713   if not (ctfUseGivenSourceEditor in Flags) then begin
714     if ctfSwitchToFormSource in Flags then
715       DoSwitchToFormSrc(ADesigner,ActiveSrcEdit,ActiveUnitInfo)
716     else if ADesigner<>nil then
717       GetDesignerUnit(ADesigner,ActiveSrcEdit,ActiveUnitInfo)
718     else
719       GetCurrentUnit(ActiveSrcEdit,ActiveUnitInfo);
720   end;
721   if (not (ctfSourceEditorNotNeeded in Flags)) and
722      ((ActiveSrcEdit=nil) or (ActiveUnitInfo=nil))
723   then exit;
724 
725   // init codetools
726   SaveSourceEditorChangesToCodeCache(nil);
727   if ActiveSrcEdit<>nil then begin
728     Edit:=ActiveSrcEdit.EditorComponent;
729     CodeToolBoss.VisibleEditorLines:=Edit.LinesInWindow;
730     CodeToolBoss.TabWidth:=Edit.TabWidth;
731     CodeToolBoss.IndentSize:=Edit.BlockIndent+Edit.BlockTabIndent*Edit.TabWidth;
732     CodeToolBoss.UseTabs:=Edit.BlockTabIndent>0;
733   end else begin
734     CodeToolBoss.VisibleEditorLines:=25;
735     CodeToolBoss.TabWidth:=EditorOpts.TabWidth;
736     CodeToolBoss.IndentSize:=EditorOpts.BlockIndent+EditorOpts.BlockTabIndent*EditorOpts.TabWidth;
737     CodeToolBoss.UseTabs:=EditorOpts.BlockTabIndent>0;
738   end;
739 
740   if ctfActivateAbortMode in Flags then
741     ActivateCodeToolAbortableMode;
742 
743   Result:=true;
744 end;
745 
746 procedure TMainIDEBase.ActivateCodeToolAbortableMode;
747 begin
748   if ToolStatus=itNone then
749     RaiseGDBException('TMainIDEBase.ActivateCodeToolAbortableMode Error 1');
750   ToolStatus:=itCodeTools;
751   CodeToolBoss.OnCheckAbort:=@OnCodeToolBossCheckAbort;
752   CodeToolBoss.Abortable:=true;
753 end;
754 
OnCodeToolBossCheckAbortnull755 function TMainIDEBase.OnCodeToolBossCheckAbort: boolean;
756 begin
757   Result:=true;
758   if ToolStatus<>itCodeTools then exit;
759   Application.ProcessMessages;
760   Result:=ToolStatus<>itCodeTools;
761 end;
762 
763 procedure TMainIDEBase.DoMergeDefaultProjectOptions;
764 var
765   AFilename: String;
766 begin
767   // load default project options if exists
768   AFilename:=AppendPathDelim(GetPrimaryConfigPath)+DefaultProjectOptionsFilename;
769   if not FileExistsUTF8(AFilename) then
770     CopySecondaryConfigFile(DefaultProjectOptionsFilename);
771   if FileExistsUTF8(AFilename) then
772     if Project1.ReadProject(AFilename,nil,False)<>mrOk then
773       DebugLn(['TMainIDEBase.DoLoadDefaultCompilerOptions failed']);
774 
775   // change target file name
776   Assert(Project1.CompilerOptions.TargetFilename = Project1.TargetFilename,
777          'DoMergeDefaultProjectOptions: TargetFilename mismatch.');
778   if UpdateTargetFilename(Project1.ProjectInfoFile) then
779     Project1.CompilerOptions.Modified:=false;
780 end;
781 
782 procedure TMainIDEBase.DoSwitchToFormSrc(var ActiveSourceEditor: TSourceEditor;
783   var ActiveUnitInfo: TUnitInfo);
784 begin
785   DoSwitchToFormSrc(nil,ActiveSourceEditor,ActiveUnitInfo);
786 end;
787 
788 procedure TMainIDEBase.DoSwitchToFormSrc(ADesigner: TIDesigner;
789   var ActiveSourceEditor: TSourceEditor; var ActiveUnitInfo: TUnitInfo);
790 begin
791   if (ADesigner<>nil) then
792     ActiveUnitInfo:=Project1.UnitWithComponent(ADesigner.LookupRoot)
793   else if GlobalDesignHook.LookupRoot is TComponent then
794     ActiveUnitInfo:=Project1.UnitWithComponent(TComponent(GlobalDesignHook.LookupRoot))
795   else
796     ActiveUnitInfo:=nil;
797   if (ActiveUnitInfo<>nil) and (ActiveUnitInfo.OpenEditorInfoCount > 0) then begin
798     ActiveSourceEditor := TSourceEditor(ActiveUnitInfo.OpenEditorInfo[0].EditorComponent);
799     SourceEditorManagerIntf.ActiveEditor := ActiveSourceEditor;
800   end
801   else
802     ActiveSourceEditor:=nil;
803 end;
804 
805 procedure TMainIDEBase.DoMnuWindowClicked(Sender: TObject);
806 begin
807   UpdateWindowMenu;
808 end;
809 
810 procedure TMainIDEBase.ShowMainIDEBar(Center: boolean);
811 var
812   NewBounds, WorkArea: TRect;
813   aMonitor: TMonitor;
814   x, y: LongInt;
815 begin
816   debugln(['TMainIDEBase.ShowMainIDEBar Center=',Center]);
817   NewBounds:=MainIDEBar.BoundsRect;
818   aMonitor:=MainIDEBar.Monitor;
819   if aMonitor=nil then
820     aMonitor:=Screen.PrimaryMonitor;
821   WorkArea:=aMonitor.WorkareaRect;
822 
823   // for experimental or buggy widgetsets: sanity check workarea
824   WorkArea.Right:=Max(WorkArea.Right,WorkArea.Left+400);
825   WorkArea.Bottom:=Max(WorkArea.Bottom,WorkArea.Top+400);
826 
827   if NewBounds.Left<WorkArea.Left then begin
828     // move right
829     OffsetRect(NewBounds,WorkArea.Left-NewBounds.Left,0);
830     NewBounds.Right:=Min(NewBounds.Right,WorkArea.Right);
831   end else if NewBounds.Right>WorkArea.Right then begin
832     // move left
833     NewBounds.Left:=Max(NewBounds.Left-(NewBounds.Right-WorkArea.Right),WorkArea.Left);
834   end;
835   if NewBounds.Top<WorkArea.Top then begin
836     // move down
837     OffsetRect(NewBounds,0,WorkArea.Top-NewBounds.Top);
838     NewBounds.Bottom:=Min(NewBounds.Bottom,WorkArea.Bottom);
839   end else if NewBounds.Bottom>WorkArea.Bottom then begin
840     // move up
841     NewBounds.Top:=Max(NewBounds.Top-(NewBounds.Bottom-WorkArea.Bottom),WorkArea.Top);
842   end;
843   if Center then begin
844     x:=(WorkArea.Right-WorkArea.Left-(NewBounds.Right-NewBounds.Left)) div 2;
845     y:=(WorkArea.Bottom-WorkArea.Top-(NewBounds.Bottom-NewBounds.Top)) div 2;
846     OffsetRect(NewBounds,x-NewBounds.Left,y-NewBounds.Top);
847   end;
848 
849   MainIDEBar.BoundsRect:=NewBounds;
850   MainIDEBar.WindowState:=wsNormal;
851   MainIDEBar.BringToFront;
852 end;
853 
854 procedure TMainIDEBase.SetDisplayState(AValue: TDisplayState);
855 begin
856   if FDisplayState=AValue then Exit;
857   FDisplayState:=AValue;
858   {$IFDEF VerboseIDEDisplayState}
859   debugln(['TMainIDEBase.SetDisplayState ',dbgs(DisplayState)]);
860   {$ENDIF}
861 end;
862 
863 var
864   SeparatorNum: Integer=0;
865 
TMainIDEBase.CreateMenuSeparatornull866 function TMainIDEBase.CreateMenuSeparator(Section: TIDEMenuSection): TIDEMenuCommand;
867 begin
868   Inc(SeparatorNum);
869   Result:=nil;
870   CreateMenuItem(Section, Result, 'Separator'+IntToStr(SeparatorNum), '-');  // Result - var parameter
871 end;
872 
873 procedure TMainIDEBase.CreateMenuItem(Section: TIDEMenuSection;
874   var MenuCommand: TIDEMenuCommand; const MenuItemName, MenuItemCaption: String;
875   const bmpName: String; mnuEnabled: Boolean; mnuChecked: Boolean;
876   mnuVisible: Boolean);
877 begin
878   MenuCommand:=RegisterIDEMenuCommand(Section,MenuItemName,MenuItemCaption);
879   MenuCommand.Enabled:=mnuEnabled;
880   MenuCommand.Checked:=mnuChecked;
881   MenuCommand.Visible:=mnuVisible;
882   if bmpName<>'' then
883     MenuCommand.ImageIndex := IDEImages.LoadImage(bmpName);
884 end;
885 
886 procedure TMainIDEBase.CreateMenuSeparatorSection(
887   ParentSection: TIDEMenuSection; var Section: TIDEMenuSection;
888   const AName: String);
889 begin
890   Section:=RegisterIDEMenuSection(ParentSection,AName);
891 end;
892 
893 procedure TMainIDEBase.CreateMenuSubSection(ParentSection: TIDEMenuSection;
894   var Section: TIDEMenuSection; const AName, ACaption: String;
895   const bmpName: String = '');
896 begin
897   Section:=RegisterIDESubMenu(ParentSection,AName,ACaption);
898   if bmpName<>'' then
899     Section.ImageIndex := IDEImages.LoadImage(bmpName);
900 end;
901 
902 procedure TMainIDEBase.CreateMainMenuItem(var Section: TIDEMenuSection;
903   const MenuItemName, MenuItemCaption: String);
904 begin
905   Section:=RegisterIDESubMenu(mnuMain,MenuItemName,MenuItemCaption);
906 end;
907 
908 procedure TMainIDEBase.SetupAppleMenu;
909 begin
910   with MainIDEBar do begin
911     {$IFDEF LCLCocoa}
912     CreateMenuSeparatorSection(mnuApple,itmAppleAbout,'itmAppleAbout');
913     CreateMenuSeparatorSection(mnuApple,itmApplePref,'itmApplePref');
914     {$ENDIF}
915   end;
916 end;
917 
918 procedure TMainIDEBase.SetupMainMenu;
919 begin
920   MainIDEBar.mnuMainMenu := TMainMenu.Create(MainIDEBar);
921   MainIDEBar.mnuMainMenu.Images := IDEImages.Images_16;
922   with MainIDEBar do begin
923     mnuMain:=RegisterIDEMenuRoot('IDEMainMenu',nil);
924     {$ifdef LCLCocoa}
925     // Under Apple there is a special policy: every application should create
926     // a special Apple menu and put Quit, About there.
927     // See issue: http://bugs.freepascal.org/view.php?id=12294
928     // See http://lists.apple.com/archives/carbon-development/2002/Apr/msg01183.html, for details
929     CreateMainMenuItem(mnuApple,'AppleApplication',#$EF#$A3#$BF);
930     {$endif}
931     CreateMainMenuItem(mnuFile,'File',lisMenuFile);
932     CreateMainMenuItem(mnuEdit,'Edit',lisMenuEdit);
933     CreateMainMenuItem(mnuSearch,'Search',lisMenuSearch);
934     CreateMainMenuItem(mnuView,'View',lisMenuView);
935     CreateMainMenuItem(mnuSource,'Source',lisMenuSource);
936     CreateMainMenuItem(mnuProject,'Project',lisMenuProject);
937     CreateMainMenuItem(mnuRun,'Run',lisMenuRun);
938     CreateMainMenuItem(mnuPackage,'Package',lisMenuPackage);
939     mnuComponent:=mnuPackage;
940     CreateMainMenuItem(mnuTools,'Tools',lisMenuTools);
941     CreateMainMenuItem(mnuWindow,'Window',lisMenuWindow);
942     mnuWindow.OnClick  := @DoMnuWindowClicked;
943     CreateMainMenuItem(mnuHelp,'Help',lisMenuHelp);
944   end;
945 end;
946 
947 procedure TMainIDEBase.SetupFileMenu;
948 var
949   ParentMI: TIDEMenuSection;
950 begin
951   with MainIDEBar do begin
952     CreateMenuSeparatorSection(mnuFile,itmFileNew,'itmFileNew');
953     ParentMI:=itmFileNew;
954     CreateMenuItem(ParentMI,itmFileNewUnit,'itmFileNewUnit',lisMenuNewUnit,'menu_new_unit');
955     CreateMenuItem(ParentMI,itmFileNewForm,'itmFileNewForm',lisMenuNewForm,'menu_new_form');
956     CreateMenuItem(ParentMI,itmFileNewOther,'itmFileNewOther',lisMenuNewOther,'menu_new');
957 
958     CreateMenuSeparatorSection(mnuFile,itmFileOpenSave,'itmFileOpenSave');
959     ParentMI:=itmFileOpenSave;
960     CreateMenuItem(ParentMI, itmFileOpen, 'itmFileOpen', lisMenuOpen, 'laz_open');
961     CreateMenuItem(ParentMI,itmFileRevert,'itmFileRevert',lisMenuRevert, 'menu_file_revert');
962     CreateMenuItem(ParentMI, itmFileOpenUnit, 'itmFileOpenUnit', lisMenuOpenUnit, 'laz_open_unit');
963     CreateMenuSubSection(ParentMI,itmFileRecentOpen,'itmFileRecentOpen',lisMenuOpenRecent, 'laz_open_recent');
964     CreateMenuItem(ParentMI,itmFileSave,'itmFileSave',lisMenuSave,'laz_save');
965     CreateMenuItem(ParentMI,itmFileSaveAs,'itmFileSaveAs',lisMenuSaveAs,'menu_saveas');
966     CreateMenuItem(ParentMI,itmFileSaveAll,'itmFileSaveAll',lisSaveAll,'menu_save_all');
967     CreateMenuItem(ParentMI,itmFileExportHtml,'itmFileExportHtml',lisExportHtml);
968     CreateMenuItem(ParentMI,itmFileClose,'itmFileClose',lisMenuCloseEditorFile,'menu_close',false);
969     CreateMenuItem(ParentMI,itmFileCloseAll,'itmFileCloseAll',lisMenuCloseAll,'menu_close_all',false);
970 
971     CreateMenuSeparatorSection(mnuFile,itmFileDirectories,'itmFileDirectories');
972     ParentMI:=itmFileDirectories;
973     CreateMenuItem(ParentMI,itmFileCleanDirectory,'itmFileCleanDirectory',lisMenuCleanDirectory, 'menu_clean');
974 
975     CreateMenuSeparatorSection(mnuFile,itmFileIDEStart,'itmFileIDEStart');
976     ParentMI:=itmFileIDEStart;
977     CreateMenuItem(ParentMI,itmFileRestart,'itmFileRestart',lisRestart, 'laz_refresh');
978     CreateMenuItem(ParentMI,itmFileQuit,'itmFileQuit',lisBtnQuit, 'menu_exit');
979   end;
980 end;
981 
982 procedure TMainIDEBase.SetupEditMenu;
983 var
984   ParentMI: TIDEMenuSection;
985 begin
986   with MainIDEBar do begin
987     CreateMenuSeparatorSection(mnuEdit,itmEditReUndo,'itmEditReUndo');
988     ParentMI:=itmEditReUndo;
989     CreateMenuItem(ParentMI,itmEditUndo,'itmEditUndo',lisUndo,'menu_undo');
990     CreateMenuItem(ParentMI,itmEditRedo,'itmEditRedo',lisRedo,'menu_redo');
991 
992     CreateMenuSeparatorSection(mnuEdit,itmEditClipboard,'itmEditClipboard');
993     ParentMI:=itmEditClipboard;
994     CreateMenuItem(ParentMI,itmEditCut,'itmEditCut',lisCut,'laz_cut');
995     CreateMenuItem(ParentMI,itmEditCopy,'itmEditCopy',lisCopy,'laz_copy');
996     CreateMenuItem(ParentMI,itmEditPaste,'itmEditPaste',lisPaste,'laz_paste');
997     CreateMenuItem(ParentMI,itmEditMultiPaste,'itmEditMultiPaste',lisMenuMultiPaste);
998 
999     // "Select" menu items
1000     CreateMenuSeparatorSection(mnuEdit,itmEditSelect,'itmEditSelect');
1001     ParentMI:=itmEditSelect;
1002     CreateMenuItem(ParentMI,itmEditSelectAll,'itmEditSelectAll',lisMenuSelectAll, 'menu_select_all');
1003     CreateMenuItem(ParentMI,itmEditSelectToBrace,'itmEditSelectToBrace',lisMenuSelectToBrace);
1004     CreateMenuItem(ParentMI,itmEditSelectCodeBlock,'itmEditSelectCodeBlock',lisMenuSelectCodeBlock);
1005     CreateMenuItem(ParentMI,itmEditSelectWord,'itmEditSelectWord',lisMenuSelectWord);
1006     CreateMenuItem(ParentMI,itmEditSelectLine,'itmEditSelectLine',lisMenuSelectLine);
1007     CreateMenuItem(ParentMI,itmEditSelectParagraph,'itmEditSelectParagraph',lisMenuSelectParagraph);
1008 
1009     // "Char Conversion" menu items
1010     CreateMenuSeparatorSection(mnuEdit,itmEditBlockActions,'itmEditBlockActions');
1011     ParentMI:=itmEditBlockActions;
1012     CreateMenuItem(ParentMI,itmEditIndentBlock,'itmEditIndentBlock',lisMenuIndentSelection,'menu_indent');
1013     CreateMenuItem(ParentMI,itmEditUnindentBlock,'itmEditUnindentBlock',lisMenuUnindentSelection,'menu_unindent');
1014     CreateMenuItem(ParentMI,itmEditUpperCaseBlock,'itmEditUpperCaseBlock',lisMenuUpperCaseSelection, 'menu_edit_uppercase');
1015     CreateMenuItem(ParentMI,itmEditLowerCaseBlock,'itmEditLowerCaseBlock',lisMenuLowerCaseSelection, 'menu_edit_lowercase');
1016     CreateMenuItem(ParentMI,itmEditSwapCaseBlock,'itmEditSwapCaseBlock',lisMenuSwapCaseSelection, 'menu_edit_uppercase');
1017     CreateMenuItem(ParentMI,itmEditSortBlock,'itmEditSortBlock',lisMenuSortSelection, 'menu_edit_sort');
1018     CreateMenuItem(ParentMI,itmEditTabsToSpacesBlock,'itmEditTabsToSpacesBlock',lisMenuTabsToSpacesSelection);
1019     CreateMenuItem(ParentMI,itmEditSelectionBreakLines,'itmEditSelectionBreakLines',lisMenuBeakLinesInSelection);
1020 
1021     // *** insert text ***:
1022     CreateMenuSeparatorSection(mnuEdit,itmEditInsertions,'itmEditInsertions');
1023     ParentMI:=itmEditInsertions;
1024     CreateMenuItem(ParentMI,itmEditInsertCharacter,'itmEditInsertCharacter',lisMenuInsertCharacter);
1025   end;
1026 end;
1027 
1028 procedure TMainIDEBase.SetupSearchMenu;
1029 var
1030   ParentMI: TIDEMenuSection;
1031 begin
1032   with MainIDEBar do begin
1033     CreateMenuSeparatorSection(mnuSearch,itmSearchFindReplace,'itmSearchFindReplace');
1034     ParentMI:=itmSearchFindReplace;
1035 
1036     CreateMenuItem(ParentMI,itmSearchFind, 'itmSearchFind', lisMenuFind2, 'menu_search_find');
1037     CreateMenuItem(ParentMI,itmSearchFindNext,'itmSearchFindNext',lisMenuFindNext, 'menu_search_find_next');
1038     CreateMenuItem(ParentMI,itmSearchFindPrevious,'itmSearchFindPrevious',lisMenuFindPrevious, 'menu_search_find_previous');
1039     CreateMenuItem(ParentMI,itmSearchFindInFiles,'itmSearchFindInFiles',lisMenuFindInFiles, 'menu_search_files');
1040     CreateMenuItem(ParentMI,itmSearchReplace, 'itmSearchReplace', lisBtnDlgReplace, 'menu_search_replace');
1041     CreateMenuItem(ParentMI,itmIncrementalFind,'itmIncrementalFind',lisMenuIncrementalFind, 'menu_search_incremental');
1042 
1043     CreateMenuSeparatorSection(mnuSearch,itmJumpings,'itmJumpings');
1044     ParentMI:=itmJumpings;
1045 
1046     CreateMenuItem(ParentMI,itmGotoLine,'itmGotoLine',lisMenuGotoLine, 'menu_goto_line');
1047     CreateMenuItem(ParentMI,itmJumpBack,'itmJumpBack',lisMenuJumpBack, 'menu_search_jumpback');
1048     CreateMenuItem(ParentMI,itmJumpForward,'itmJumpForward',lisMenuJumpForward, 'menu_search_jumpforward');
1049     CreateMenuItem(ParentMI,itmAddJumpPoint,'itmAddJumpPoint',lisMenuAddJumpPointToHistory, 'menu_add_jump_point_to_history');
1050     CreateMenuItem(ParentMI,itmJumpToNextError,'itmJumpToNextError',lisMenuJumpToNextError, 'menu_search_next_error');
1051     CreateMenuItem(ParentMI,itmJumpToPrevError,'itmJumpToPrevError',lisMenuJumpToPrevError, 'menu_search_previous_error');
1052 
1053     CreateMenuSubSection(ParentMI,itmJumpToSection,'itmJumpToSection',lisMenuJumpTo, 'menu_jumpto_section');
1054     ParentMI:=itmJumpToSection;
1055 
1056     CreateMenuItem(ParentMI,itmJumpToInterface,'itmJumpToInterface',lisMenuJumpToInterface, 'menu_jumpto_interface');
1057     CreateMenuItem(ParentMI,itmJumpToInterfaceUses,'itmJumpToInterfaceUses',lisMenuJumpToInterfaceUses, 'menu_jumpto_interfaceuses');
1058     CreateMenuSeparator(ParentMI);
1059     CreateMenuItem(ParentMI,itmJumpToImplementation,'itmJumpToImplementation',lisMenuJumpToImplementation, 'menu_jumpto_implementation');
1060     CreateMenuItem(ParentMI,itmJumpToImplementationUses,'itmJumpToImplementationUses',lisMenuJumpToImplementationUses, 'menu_jumpto_implementationuses');
1061     CreateMenuSeparator(ParentMI);
1062     CreateMenuItem(ParentMI,itmJumpToInitialization,'itmJumpToInitialization',lisMenuJumpToInitialization, 'menu_jumpto_initialization');
1063 
1064     CreateMenuSeparatorSection(mnuSearch,itmBookmarks,'itmBookmarks');
1065     ParentMI:=itmBookmarks;
1066 
1067     CreateMenuItem(ParentMI,itmSetFreeBookmark,'itmSetFreeBookmark',lisMenuSetFreeBookmark, 'menu_search_set_bookmark');
1068     CreateMenuItem(ParentMI,itmJumpToNextBookmark,'itmJumpToNextBookmark',lisMenuJumpToNextBookmark, 'menu_search_next_bookmark');
1069     CreateMenuItem(ParentMI,itmJumpToPrevBookmark,'itmJumpToPrevBookmark',lisMenuJumpToPrevBookmark, 'menu_search_previous_bookmark');
1070 
1071     CreateMenuSeparatorSection(mnuSearch,itmCodeToolSearches,'itmCodeToolSearches');
1072     ParentMI:=itmCodeToolSearches;
1073 
1074     CreateMenuItem(ParentMI,itmFindBlockOtherEnd,'itmFindBlockOtherEnd',lisMenuFindBlockOtherEndOfCodeBlock);
1075     CreateMenuItem(ParentMI,itmFindBlockStart,'itmFindBlockStart',lisMenuFindCodeBlockStart);
1076     CreateMenuItem(ParentMI,itmFindDeclaration,'itmFindDeclaration',lisMenuFindDeclarationAtCursor);
1077     CreateMenuItem(ParentMI,itmOpenFileAtCursor,'itmOpenFileAtCursor',lisMenuOpenFilenameAtCursor,'menu_search_openfile_atcursor');
1078     CreateMenuItem(ParentMI,itmGotoIncludeDirective,'itmGotoIncludeDirective',lisMenuGotoIncludeDirective);
1079     CreateMenuItem(ParentMI,itmSearchFindIdentifierRefs,'itmSearchFindIdentifierRefs',lisMenuFindIdentifierRefs);
1080     CreateMenuItem(ParentMI,itmSearchProcedureList,'itmSearchProcedureList',lisMenuProcedureList, 'menu_search_procedure_list');
1081   end;
1082 end;
1083 
1084 procedure TMainIDEBase.SetupViewMenu;
1085 var
1086   ParentMI: TIDEMenuSection;
1087 begin
1088   with MainIDEBar do begin
1089     CreateMenuSeparatorSection(mnuView,itmViewMainWindows,'itmViewMainWindows');
1090     ParentMI:=itmViewMainWindows;
1091     CreateMenuItem(ParentMI,itmViewToggleFormUnit,'itmViewToggleFormUnit',lisMenuViewToggleFormUnit, 'menu_view_toggle_form_unit');
1092     CreateMenuItem(ParentMI,itmViewInspector,'itmViewInspector',lisMenuViewObjectInspector, 'menu_view_inspector');
1093     CreateMenuItem(ParentMI,itmViewSourceEditor,'itmViewSourceEditor',lisMenuViewSourceEditor, 'menu_view_source_editor');
1094     CreateMenuItem(ParentMI,itmViewMessage,'itmViewMessage',lisMenuViewMessages, 'menu_view_messages');
1095     CreateMenuItem(ParentMI,itmViewCodeExplorer,'itmViewCodeExplorer',lisMenuViewCodeExplorer, 'menu_view_code_explorer');
1096     CreateMenuItem(ParentMI,itmViewFPDocEditor,'itmViewFPDocEditor',lisFPDocEditor);
1097     CreateMenuItem(ParentMI,itmViewCodeBrowser,'itmViewCodeBrowser',lisMenuViewCodeBrowser, 'menu_view_code_browser');
1098     CreateMenuItem(ParentMI,itmSourceUnitDependencies,'itmSourceUnitDependencies',lisMenuViewUnitDependencies);
1099     CreateMenuItem(ParentMI,itmViewRestrictionBrowser,'itmViewRestrictionBrowser',lisMenuViewRestrictionBrowser, 'menu_view_restriction_browser');
1100     CreateMenuItem(ParentMI,itmViewComponents,'itmViewComponents',lisMenuViewComponents, 'menu_view_components');
1101     CreateMenuItem(ParentMI,itmJumpHistory,'itmJumpHistory',lisMenuViewJumpHistory, 'menu_view_jump_history');
1102     CreateMenuItem(ParentMI,itmMacroListView,'itmMacroListView',lisMenuMacroListView);
1103 
1104     CreateMenuSeparatorSection(mnuView,itmViewDesignerWindows,'itmViewDesignerWindows');
1105     ParentMI:=itmViewDesignerWindows;
1106     CreateMenuItem(ParentMI,itmViewAnchorEditor,'itmViewAnchorEditor',lisMenuViewAnchorEditor,'menu_view_anchor_editor');
1107     CreateMenuItem(ParentMI,itmViewTabOrder,'itmViewTabOrder',lisMenuViewTabOrder,'tab_order');
1108 
1109     CreateMenuSeparatorSection(mnuView,itmViewSecondaryWindows,'itmViewSecondaryWindows');
1110     ParentMI:=itmViewSecondaryWindows;
1111     CreateMenuItem(ParentMI,itmViewSearchResults,'itmViewSearchResults',lisMenuViewSearchResults, 'menu_view_search_results');
1112     CreateMenuSubSection(ParentMI,itmViewDebugWindows,'itmViewDebugWindows',lisMenuDebugWindows,'debugger');
1113     begin
1114       CreateMenuItem(itmViewDebugWindows,itmViewWatches,'itmViewWatches',lisMenuViewWatches,'debugger_watches');
1115       CreateMenuItem(itmViewDebugWindows,itmViewBreakPoints,'itmViewBreakPoints',lisMenuViewBreakPoints,'debugger_breakpoints');
1116       CreateMenuItem(itmViewDebugWindows,itmViewLocals,'itmViewLocals',lisMenuViewLocalVariables);
1117       if HasConsoleSupport then
1118         CreateMenuItem(itmViewDebugWindows,itmViewPseudoTerminal,'itmViewPseudoTerminal',lisMenuViewPseudoTerminal)
1119       else
1120         itmViewPseudoTerminal := nil;
1121       CreateMenuItem(itmViewDebugWindows,itmViewRegisters,'itmViewRegisters',lisMenuViewRegisters);
1122       CreateMenuItem(itmViewDebugWindows,itmViewCallStack,'itmViewCallStack',lisMenuViewCallStack,'debugger_call_stack');
1123       CreateMenuItem(itmViewDebugWindows,itmViewThreads,'itmViewThreads',lisMenuViewThreads);
1124       CreateMenuItem(itmViewDebugWindows,itmViewAssembler,'itmViewAssembler',lisMenuViewAssembler);
1125       CreateMenuItem(itmViewDebugWindows,itmViewDebugEvents,'itmViewDebugEvents',lisMenuViewDebugEvents,'debugger_event_log');
1126       CreateMenuItem(itmViewDebugWindows,itmViewDbgHistory,'itmViewDbgHistory',lisMenuViewHistory);
1127     end;
1128     CreateMenuSubSection(ParentMI, itmViewIDEInternalsWindows, 'itmViewIDEInternalsWindows', lisMenuIDEInternals);
1129     begin
1130       CreateMenuItem(itmViewIDEInternalsWindows, itmViewFPCInfo, 'itmViewFPCInfo', lisMenuAboutFPC);
1131       CreateMenuItem(itmViewIDEInternalsWindows, itmViewIDEInfo, 'itmViewIDEInfo', lisAboutIDE);
1132       CreateMenuItem(itmViewIDEInternalsWindows, itmViewNeedBuild, 'itmViewNeedBuild', lisMenuWhatNeedsBuilding);
1133       CreateMenuItem(itmViewIDEInternalsWindows,itmViewDebugOutput,'itmViewDebugOutput',lisMenuViewDebugOutput,'debugger_output');
1134       {$IFDEF EnableFPDocSearch}
1135       CreateMenuItem(itmViewIDEInternalsWindows, itmSearchInFPDocFiles,'itmSearchInFPDocFiles','Search in FPDoc files');
1136       {$ENDIF}
1137     end;
1138   end;
1139 end;
1140 
1141 procedure TMainIDEBase.SetupSourceMenu;
1142 var
1143   ParentMI, SubParentMI: TIDEMenuSection;
1144 begin
1145   with MainIDEBar do begin
1146     CreateMenuSeparatorSection(mnuSource,itmSourceBlockActions,'itmSourceBlockActions');
1147     ParentMI:=itmSourceBlockActions;
1148     CreateMenuItem(ParentMI,itmSourceCommentBlock,'itmSourceCommentBlock',lisMenuCommentSelection, 'menu_comment');
1149     CreateMenuItem(ParentMI,itmSourceUncommentBlock,'itmSourceUncommentBlock',lisMenuUncommentSelection, 'menu_uncomment');
1150     CreateMenuItem(ParentMI,itmSourceToggleComment,'itmSourceToggleComment',lisMenuToggleComment, 'menu_comment');
1151     CreateMenuItem(ParentMI,itmSourceEncloseBlock,'itmSourceEncloseBlock',lisMenuEncloseSelection);
1152     CreateMenuItem(ParentMI,itmSourceEncloseInIFDEF,'itmSourceEncloseInIFDEF',lisMenuEncloseInIFDEF);
1153     CreateMenuItem(ParentMI,itmSourceCompleteCodeInteractive,'itmSourceCompleteCodeInteractive',lisMenuCompleteCodeInteractive);
1154     CreateMenuItem(ParentMI,itmRefactorInvertAssignment,'itmInvertAssignment',uemInvertAssignment);
1155     CreateMenuItem(ParentMI,itmSourceUseUnit,'itmSourceUseUnit',lisMenuUseUnit);
1156     // Refactor
1157     CreateMenuSeparatorSection(mnuSource,itmSourceRefactor,'itmSourceRefactor');
1158     CreateMenuSubSection(ParentMI,itmSourceRefactor,'itmSourceRefactor',uemRefactor);
1159     SubParentMI:=itmSourceRefactor;
1160       CreateMenuSeparatorSection(SubParentMI,itmRefactorCodeTools,'itmRefactorCodeTools');
1161       ParentMI:=itmRefactorCodeTools;
1162       CreateMenuItem(ParentMI,itmRefactorRenameIdentifier,'itmRefactorRenameIdentifier',lisMenuRenameIdentifier);
1163       CreateMenuItem(ParentMI,itmRefactorExtractProc,'itmRefactorExtractProc',lisMenuExtractProc);
1164 
1165       CreateMenuSeparatorSection(SubParentMI,itmRefactorAdvanced,'itmRefactorAdvanced');
1166       ParentMI:=itmRefactorAdvanced;
1167       CreateMenuItem(ParentMI,itmRefactorShowAbstractMethods,'itmShowAbstractMethods',srkmecAbstractMethods);
1168       CreateMenuItem(ParentMI,itmRefactorShowEmptyMethods,'itmShowEmptyMethods',srkmecEmptyMethods);
1169       CreateMenuItem(ParentMI,itmRefactorShowUnusedUnits,'itmShowUnusedUnits',srkmecUnusedUnits);
1170       {$IFDEF EnableFindOverloads}
1171       CreateMenuItem(ParentMI,itmRefactorFindOverloads,'itmFindOverloads',srkmecFindOverloadsCapt);
1172       {$ENDIF}
1173 
1174       CreateMenuSeparatorSection(SubParentMI,itmRefactorTools,'itmRefactorTools');
1175       ParentMI:=itmRefactorTools;
1176       CreateMenuItem(ParentMI,itmRefactorMakeResourceString,'itmRefactorMakeResourceString',
1177                      lisMenuMakeResourceString,'menu_tool_make_resourcestring');
1178     // CodeToolChecks
1179     CreateMenuSeparatorSection(mnuSource,itmSourceCodeToolChecks,'itmSourceCodeToolChecks');
1180     ParentMI:=itmSourceCodeToolChecks;
1181     CreateMenuItem(ParentMI,itmSourceSyntaxCheck,'itmSourceSyntaxCheck',lisMenuQuickSyntaxCheck, 'menu_tool_syntax_check');
1182     CreateMenuItem(ParentMI,itmSourceGuessUnclosedBlock,'itmSourceGuessUnclosedBlock',lisMenuGuessUnclosedBlock);
1183     {$IFDEF GuessMisplacedIfdef}
1184     CreateMenuItem(ParentMI,itmSourceGuessMisplacedIFDEF,'itmSourceGuessMisplacedIFDEF',lisMenuGuessMisplacedIFDEF);
1185     {$ENDIF}
1186 
1187     CreateMenuSeparatorSection(mnuSource,itmSourceInsertions,'itmSourceInsertions');
1188     ParentMI:=itmSourceInsertions;
1189     // *** insert text ***:
1190     CreateMenuSubSection(ParentMI,itmSourceInsertCVSKeyWord,'itmSourceInsertCVSKeyWord',lisMenuInsertCVSKeyword);
1191     SubParentMI:=itmSourceInsertCVSKeyWord;
1192       // insert CVS keyword sub menu items
1193       CreateMenuItem(SubParentMI,itmSourceInsertCVSAuthor,'itmSourceInsertCVSAuthor','Author');
1194       CreateMenuItem(SubParentMI,itmSourceInsertCVSDate,'itmSourceInsertCVSDate','Date');
1195       CreateMenuItem(SubParentMI,itmSourceInsertCVSHeader,'itmSourceInsertCVSHeader','Header');
1196       CreateMenuItem(SubParentMI,itmSourceInsertCVSID,'itmSourceInsertCVSID','ID');
1197       CreateMenuItem(SubParentMI,itmSourceInsertCVSLog,'itmSourceInsertCVSLog','Log');
1198       CreateMenuItem(SubParentMI,itmSourceInsertCVSName,'itmSourceInsertCVSName','Name');
1199       CreateMenuItem(SubParentMI,itmSourceInsertCVSRevision,'itmSourceInsertCVSRevision','Revision');
1200       CreateMenuItem(SubParentMI,itmSourceInsertCVSSource,'itmSourceInsertCVSSource','Source');
1201 
1202     CreateMenuSubSection(ParentMI,itmSourceInsertGeneral,'itmSourceInsertGeneral',lisMenuInsertGeneral);
1203     SubParentMI:=itmSourceInsertGeneral;
1204       // insert general text sub menu items
1205       CreateMenuItem(SubParentMI,itmSourceInsertGPLNotice,'itmSourceInsertGPLNotice',lisMenuInsertGPLNotice);
1206       CreateMenuItem(SubParentMI,itmSourceInsertGPLNoticeTranslated,'itmSourceInsertGPLNoticeTranslated',lisMenuInsertGPLNoticeTranslated);
1207       CreateMenuItem(SubParentMI,itmSourceInsertLGPLNotice,'itmSourceInsertLGPLNotice',lisMenuInsertLGPLNotice);
1208       CreateMenuItem(SubParentMI,itmSourceInsertLGPLNoticeTranslated,'itmSourceInsertLGPLNoticeTranslated',lisMenuInsertLGPLNoticeTranslated);
1209       CreateMenuItem(SubParentMI,itmSourceInsertModifiedLGPLNotice,'itmSourceInsertModifiedLGPLNotice',lisMenuInsertModifiedLGPLNotice);
1210       CreateMenuItem(SubParentMI,itmSourceInsertModifiedLGPLNoticeTranslated,'itmSourceInsertModifiedLGPLNoticeTranslated',lisMenuInsertModifiedLGPLNoticeTranslated);
1211       CreateMenuItem(SubParentMI,itmSourceInsertMITNotice,'itmSourceInsertMITNotice',lisMenuInsertMITNotice);
1212       CreateMenuItem(SubParentMI,itmSourceInsertMITNoticeTranslated,'itmSourceInsertMITNoticeTranslated',lisMenuInsertMITNoticeTranslated);
1213       CreateMenuItem(SubParentMI,itmSourceInsertUsername,'itmSourceInsertUsername',lisMenuInsertUsername);
1214       CreateMenuItem(SubParentMI,itmSourceInsertDateTime,'itmSourceInsertDateTime',lisMenuInsertDateTime);
1215       CreateMenuItem(SubParentMI,itmSourceInsertChangeLogEntry,'itmSourceInsertChangeLogEntry',lisMenuInsertChangeLogEntry);
1216       CreateMenuItem(SubParentMI,itmSourceInsertGUID,'itmSourceInsertGUID',srkmecInsertGUID);
1217 
1218     CreateMenuItem(itmSourceInsertions,itmSourceInsertFilename,'itmSourceInsertFilename',lisMenuInsertFilename);
1219 
1220     CreateMenuSeparatorSection(mnuSource,itmSourceTools,'itmSourceTools');
1221     ParentMI:=itmSourceTools;
1222     CreateMenuItem(ParentMI,itmSourceUnitInfo,'itmViewUnitInfo',lisMenuViewUnitInfo, 'menu_view_unit_info');
1223   end;
1224 end;
1225 
1226 procedure TMainIDEBase.SetupProjectMenu;
1227 var
1228   ParentMI: TIDEMenuSection;
1229 begin
1230   with MainIDEBar do begin
1231     CreateMenuSeparatorSection(mnuProject,itmProjectNewSection,'itmProjectNewSection');
1232     ParentMI:=itmProjectNewSection;
1233     CreateMenuItem(ParentMI,itmProjectNew,'itmProjectNew',lisMenuNewProject, 'menu_project_new');
1234     CreateMenuItem(ParentMI,itmProjectNewFromFile,'itmProjectNewFromFile',lisMenuNewProjectFromFile, 'menu_project_from_file');
1235 
1236     CreateMenuSeparatorSection(mnuProject,itmProjectOpenSection,'itmProjectOpenSection');
1237     ParentMI:=itmProjectOpenSection;
1238     CreateMenuItem(ParentMI,itmProjectOpen,'itmProjectOpen',lisMenuOpenProject,'menu_project_open');
1239     CreateMenuSubSection(ParentMI,itmProjectRecentOpen,'itmProjectRecentOpen',lisMenuOpenRecentProject,'menu_project_open_recent');
1240     CreateMenuItem(ParentMI,itmProjectClose,'itmProjectClose',lisMenuCloseProject, 'menu_project_close');
1241 
1242     CreateMenuSeparatorSection(mnuProject,itmProjectSaveSection,'itmProjectSaveSection');
1243     ParentMI:=itmProjectSaveSection;
1244     CreateMenuItem(ParentMI,itmProjectSave,'itmProjectSave',lisMenuSaveProject, 'menu_project_save');
1245     CreateMenuItem(ParentMI,itmProjectSaveAs,'itmProjectSaveAs',lisMenuSaveProjectAs, 'menu_project_save_as');
1246     CreateMenuItem(ParentMI, itmProjectResaveFormsWithI18n, 'itmProjectResaveFo'
1247       +'rmsWithI18n', lisMenuResaveFormsWithI18n);
1248     CreateMenuItem(ParentMI,itmProjectPublish,'itmProjectPublish',lisMenuPublishProject);
1249 
1250     CreateMenuSeparatorSection(mnuProject,itmProjectWindowSection,'itmProjectWindowSection');
1251     ParentMI:=itmProjectWindowSection;
1252     CreateMenuItem(ParentMI,itmProjectInspector,'itmProjectInspector',lisMenuProjectInspector+' ...','menu_project_inspector');
1253     CreateMenuItem(ParentMI,itmProjectOptions,'itmProjectOptions',lisMenuProjectOptions,'menu_project_options');
1254 
1255     CreateMenuSeparatorSection(mnuProject,itmProjectAddRemoveSection,'itmProjectAddRemoveSection');
1256     ParentMI:=itmProjectAddRemoveSection;
1257     CreateMenuItem(ParentMI,itmProjectAddTo,'itmProjectAddTo',lisMenuAddToProject, 'menu_project_add');
1258     CreateMenuItem(ParentMI,itmProjectRemoveFrom,'itmProjectRemoveFrom',lisMenuRemoveFromProject, 'menu_project_remove');
1259     CreateMenuItem(ParentMI,itmProjectViewUnits,'itmProjectViewUnits',lisMenuViewUnits, 'menu_view_units');
1260     CreateMenuItem(ParentMI,itmProjectViewForms,'itmProjectViewForms',lisMenuViewForms, 'menu_view_forms');
1261     CreateMenuItem(ParentMI,itmProjectViewSource,'itmProjectViewSource',lisMenuViewProjectSource, 'item_project_source');
1262   end;
1263 end;
1264 
1265 procedure TMainIDEBase.SetupRunMenu;
1266 var
1267   ParentMI: TIDEMenuSection;
1268 begin
1269   with MainIDEBar do begin
1270     CreateMenuSeparatorSection(mnuRun,itmRunBuilding,'itmRunBuilding');
1271     ParentMI:=itmRunBuilding;
1272     CreateMenuItem(ParentMI,itmRunMenuCompile,'itmRunMenuCompile',lisCompile,'menu_build');
1273     CreateMenuItem(ParentMI,itmRunMenuBuild,'itmRunMenuBuild',lisBuild,'menu_build_all');
1274     CreateMenuItem(ParentMI,itmRunMenuQuickCompile,'itmRunMenuQuickCompile',lisMenuQuickCompile,'menu_quick_compile');
1275     CreateMenuItem(ParentMI,itmRunMenuCleanUpAndBuild,'itmRunMenuCleanUpAndBuild',lisMenuCleanUpAndBuild,'menu_build');
1276     CreateMenuItem(ParentMI,itmRunMenuBuildManyModes,'itmRunMenuBuildManyModes',lisMenuCompileManyModes,'menu_build_all');
1277     CreateMenuItem(ParentMI,itmRunMenuAbortBuild,'itmRunMenuAbortBuild',lisMenuAbortBuild,'menu_abort_build');
1278 
1279     CreateMenuSeparatorSection(mnuRun,itmRunnning,'itmRunnning');
1280     ParentMI:=itmRunnning;
1281     CreateMenuItem(ParentMI,itmRunMenuRunWithoutDebugging,'itmRunMenuRunWithoutDebugging',lisMenuRunWithoutDebugging,'menu_run_withoutdebugging');
1282     CreateMenuItem(ParentMI,itmRunMenuRun,'itmRunMenuRun',lisMenuProjectRun,'menu_run');
1283     CreateMenuItem(ParentMI,itmRunMenuPause,'itmRunMenuPause',lisPause,'menu_pause', False);
1284     CreateMenuItem(ParentMI,itmRunMenuShowExecutionPoint,'itmRunMenuShowExecutionPoint',
1285                    lisMenuShowExecutionPoint,'debugger_show_execution_point', False);
1286     CreateMenuItem(ParentMI,itmRunMenuStepInto,'itmRunMenuStepInto',lisMenuStepInto,'menu_stepinto');
1287     CreateMenuItem(ParentMI,itmRunMenuStepOver,'itmRunMenuStepOver',lisMenuStepOver,'menu_stepover');
1288     CreateMenuItem(ParentMI,itmRunMenuStepOut,'itmRunMenuStepOut',lisMenuStepOut,'menu_stepout');
1289     CreateMenuItem(ParentMI,itmRunMenuStepToCursor,'itmRunMenuStepToCursor',lisMenuStepToCursor,'menu_step_cursor');
1290     CreateMenuItem(ParentMI,itmRunMenuRunToCursor,'itmRunMenuRunToCursor',lisMenuRunToCursor,'menu_run_cursor');
1291     CreateMenuItem(ParentMI,itmRunMenuStop,'itmRunMenuStop',lisStop,'menu_stop', False);
1292 
1293     CreateMenuItem(ParentMI,itmRunMenuAttach,'itmRunMenuAttach',srkmecAttach+' ...','', False);
1294     CreateMenuItem(ParentMI,itmRunMenuDetach,'itmRunMenuDetach',srkmecDetach,'', False);
1295 
1296     CreateMenuItem(ParentMI,itmRunMenuRunParameters,'itmRunMenuRunParameters',lisMenuRunParameters, 'menu_run_parameters');
1297     CreateMenuItem(ParentMI,itmRunMenuResetDebugger,'itmRunMenuResetDebugger',lisMenuResetDebugger, 'menu_reset_debugger');
1298 
1299     CreateMenuSeparatorSection(mnuRun,itmRunBuildingFile,'itmRunBuildingFile');
1300     ParentMI:=itmRunBuildingFile;
1301     CreateMenuItem(ParentMI,itmRunMenuBuildFile,'itmRunMenuBuildFile',lisMenuBuildFile, 'menu_build_file');
1302     CreateMenuItem(ParentMI,itmRunMenuRunFile,'itmRunMenuRunFile',lisMenuRunFile,'menu_run_file');
1303     CreateMenuItem(ParentMI,itmRunMenuConfigBuildFile,'itmRunMenuConfigBuildFile',lisMenuConfigBuildFile, 'menu_build_run_file');
1304 
1305     CreateMenuSeparatorSection(mnuRun,itmRunDebugging,'itmRunDebugging');
1306     ParentMI:=itmRunDebugging;
1307     CreateMenuItem(ParentMI,itmRunMenuInspect,'itmRunMenuInspect',lisMenuInspect, 'debugger_inspect', False);
1308     CreateMenuItem(ParentMI,itmRunMenuEvaluate,'itmRunMenuEvaluate',lisMenuEvaluate, 'debugger_modify', False);
1309     CreateMenuItem(ParentMI,itmRunMenuAddWatch,'itmRunMenuAddWatch',lisMenuAddWatch, '', False);
1310     CreateMenuSubSection(ParentMI,itmRunMenuAddBreakpoint,'itmRunMenuAddBreakpoint',lisMenuAddBreakpoint, '');
1311     CreateMenuItem(itmRunMenuAddBreakpoint,itmRunMenuAddBPSource,'itmRunMenuAdddBPSource',lisSourceBreakpoint, '', False);
1312     CreateMenuItem(itmRunMenuAddBreakpoint,itmRunMenuAddBPAddress,'itmRunMenuAddBPAddress',lisAddressBreakpoint, '', False);
1313     CreateMenuItem(itmRunMenuAddBreakpoint,itmRunMenuAddBpWatchPoint,'itmRunMenuAddBpWatchPoint',lisWatchPointBreakpoint, '', False);
1314   end;
1315 end;
1316 
1317 procedure TMainIDEBase.SetupPackageMenu;
1318 var
1319   ParentMI: TIDEMenuSection;
1320 begin
1321   with MainIDEBar do begin
1322     CreateMenuSeparatorSection(mnuComponent,itmPkgOpening,'itmPkgOpening');
1323     ParentMI:=itmPkgOpening;
1324     CreateMenuItem(ParentMI,itmPkgNewPackage,'itmPkgNewPackage',lisMenuNewPackage);
1325     CreateMenuItem(ParentMI,itmPkgOpenLoadedPackage,'itmPkgOpenPackage',lisMenuOpenPackage,'pkg_installed');
1326     CreateMenuItem(ParentMI,itmPkgOpenPackageFile,'itmPkgOpenPackageFile',lisMenuOpenPackageFile,'pkg_open');
1327     CreateMenuItem(ParentMI,itmPkgOpenPackageOfCurUnit,'itmPkgOpenPackageOfCurUnit',lisMenuOpenPackageOfCurUnit);
1328     CreateMenuSubSection(ParentMI,itmPkgOpenRecent,'itmPkgOpenRecent',lisMenuOpenRecentPkg, 'pkg_open_recent');
1329 
1330     CreateMenuSeparatorSection(mnuComponent,itmPkgUnits,'itmPkgUnits');
1331     ParentMI:=itmPkgUnits;
1332     CreateMenuItem(ParentMI,itmPkgAddCurFileToPkg,'itmPkgAddCurFileToPkg',lisMenuAddCurFileToPkg,'pkg_add');
1333     CreateMenuItem(ParentMI, itmPkgAddNewComponentToPkg, 'itmPkgAddNewComponentToPkg', lisMenuNewComponent+' ...', 'pkg_add');
1334 
1335     CreateMenuSeparatorSection(mnuComponent,itmPkgGraphSection,'itmPkgGraphSection');
1336     ParentMI:=itmPkgGraphSection;
1337     CreateMenuItem(ParentMI,itmPkgPkgGraph,'itmPkgPkgGraph',lisMenuPackageGraph+' ...','pkg_graph');
1338     CreateMenuItem(ParentMI,itmPkgPackageLinks,'itmPkgPackageLinks',lisMenuPackageLinks);
1339     CreateMenuItem(ParentMI,itmPkgEditInstallPkgs,'itmPkgEditInstallPkgs',lisMenuEditInstallPkgs,'pkg_properties');
1340   end;
1341 end;
1342 
1343 procedure TMainIDEBase.SetupToolsMenu;
1344 var
1345   ParentMI: TIDEMenuSection;
1346 begin
1347   with MainIDEBar do begin
1348     CreateMenuSeparatorSection(mnuTools,itmOptionsDialogs,'itmOptionsDialogs');
1349     ParentMI:=itmOptionsDialogs;
1350     {$ifndef LCLCocoa}
1351     CreateMenuItem(ParentMI,itmEnvGeneralOptions,'itmEnvGeneralOptions',
1352                    lisMenuGeneralOptions,'menu_environment_options');
1353     {$else}
1354     CreateMenuItem(itmApplePref,itmEnvGeneralOptions,'itmEnvGeneralOptions',
1355                    lisMacPreferences,'menu_environment_options');
1356     {$endif}
1357     CreateMenuItem(ParentMI,itmToolRescanFPCSrcDir,'itmToolRescanFPCSrcDir',
1358                    lisMenuRescanFPCSourceDirectory);
1359     CreateMenuItem(ParentMI,itmEnvCodeTemplates,'itmEnvCodeTemplates',lisMenuEditCodeTemplates,'');
1360     CreateMenuItem(ParentMI,itmEnvCodeToolsDefinesEditor,'itmEnvCodeToolsDefinesEditor',
1361                    lisMenuCodeToolsDefinesEditor,'menu_codetoolsdefineseditor');
1362 
1363     CreateMenuSeparatorSection(mnuTools,itmCustomTools,'itmCustomTools');
1364     ParentMI:=itmCustomTools;
1365     CreateMenuItem(ParentMI,itmToolConfigure,'itmToolConfigure',lisMenuConfigExternalTools);
1366 
1367     CreateMenuSeparatorSection(mnuTools,itmSecondaryTools,'itmSecondaryTools');
1368     ParentMI:=itmSecondaryTools;
1369     CreateMenuItem(ParentMI,itmToolManageDesktops,'itmToolManageDesktops', lisDesktops, 'menu_manage_desktops');
1370     CreateMenuItem(ParentMI,itmToolManageExamples,'itmToolManageExamples',lisMenuExampleProjects, 'camera');
1371     CreateMenuItem(ParentMI,itmToolDiff,'itmToolDiff',lisMenuCompareFiles, 'menu_tool_diff');
1372 
1373     CreateMenuSeparatorSection(mnuTools,itmConversion,'itmConversion');
1374     ParentMI:=itmConversion;
1375     CreateMenuItem(ParentMI,itmToolConvertEncoding,'itmToolConvertEncoding',lisMenuConvertEncoding);
1376     CreateMenuItem(ParentMI,itmToolCheckLFM,'itmToolCheckLFM',lisMenuCheckLFM, 'menu_tool_check_lfm');
1377 
1378     CreateMenuSubSection(mnuTools,itmDelphiConversion,'itmDelphiConversion',lisMenuDelphiConversion,'menu_tool_del_to_laz');
1379     ParentMI:=itmDelphiConversion;
1380     CreateMenuItem(ParentMI,itmToolConvertDelphiUnit,'itmToolConvertDelphiUnit',lisMenuConvertDelphiUnit,'menu_tool_del_to_laz_unit');
1381     CreateMenuItem(ParentMI,itmToolConvertDelphiProject,'itmToolConvertDelphiProject',lisMenuConvertDelphiProject,'menu_tool_del_to_laz_project');
1382     CreateMenuItem(ParentMI,itmToolConvertDelphiPackage,'itmToolConvertDelphiPackage',lisMenuConvertDelphiPackage,'menu_tool_del_to_laz_pkg');
1383     CreateMenuItem(ParentMI,itmToolConvertDFMtoLFM,'itmToolConvertDFMtoLFM',lisMenuConvertDFMtoLFM,'menu_tool_del_to_laz_form');
1384 
1385     CreateMenuSeparatorSection(mnuTools,itmBuildingLazarus,'itmBuildingLazarus');
1386     ParentMI:=itmBuildingLazarus;
1387     CreateMenuItem(ParentMI,itmToolBuildLazarus,'itmToolBuildLazarus',lisMenuBuildLazarus,'menu_build_lazarus');
1388     CreateMenuItem(ParentMI,itmToolConfigureBuildLazarus,'itmToolConfigureBuildLazarus',
1389                    lisMenuConfigureBuildLazarus, 'menu_configure_build_lazarus');
1390   end;
1391 end;
1392 
1393 procedure TMainIDEBase.SetupWindowsMenu;
1394 var
1395   ParentMI: TIDEMenuSection;
1396 begin
1397   with MainIDEBar do begin
1398     CreateMenuSeparatorSection(mnuWindow,itmWindowManagers,'itmWindowManagers');
1399     ParentMI:=itmWindowManagers;
1400     CreateMenuItem(ParentMI,itmWindowManager,'itmWindowManager', lisManageSourceEditors, 'menu_manage_source_editors');
1401     // Populated later with a list of editor names
1402     CreateMenuSeparatorSection(mnuWindow,itmWindowLists,'itmWindowLists');
1403     CreateMenuSeparatorSection(mnuWindow,itmCenterWindowLists,'itmCenterWindowLists');
1404     itmCenterWindowLists.ChildrenAsSubMenu:=true;
1405     itmCenterWindowLists.Caption:=lisCenterALostWindow;
1406     CreateMenuSeparatorSection(mnuWindow,itmTabLists,'itmTabLists');
1407     CreateMenuSubSection(itmTabLists,itmTabListProject,'itmTabListProject', dlgEnvProject);
1408     CreateMenuSeparatorSection(itmTabLists, itmTabListPackage, 'itmTabListPackage');
1409     CreateMenuSubSection(itmTabLists,itmTabListOther,'itmTabListOther', lisMEOther);
1410   end;
1411 end;
1412 
1413 procedure TMainIDEBase.SetupHelpMenu;
1414 var
1415   ParentMI: TIDEMenuSection;
1416 begin
1417   with MainIDEBar do begin
1418     CreateMenuSeparatorSection(mnuHelp,itmOnlineHelps,'itmOnlineHelps');
1419     ParentMI:=itmOnlineHelps;
1420 
1421     CreateMenuItem(ParentMI,itmHelpOnlineHelp,'itmHelpOnlineHelp',
1422                    lisMenuOnlineHelp, 'btn_help');
1423     CreateMenuItem(ParentMI,itmHelpReportingBug,'itmHelpReportingBug',
1424                    lisMenuReportingBug, 'menu_reportingbug');
1425 
1426     CreateMenuSeparatorSection(mnuHelp,itmInfoHelps,'itmInfoHelps');
1427     // old behavior restored, until Tiger issue is fixed.
1428     // http://bugs.freepascal.org/view.php?id=14411
1429 
1430 
1431     // under Cocoa: add About item to the Apple menu
1432     ParentMI:=itmInfoHelps;
1433     CreateMenuItem({$ifndef LCLCocoa}ParentMI{$else}itmAppleAbout{$endif}, itmHelpAboutLazarus,'itmHelpAboutLazarus',
1434                    lisAboutLazarus, 'menu_information');
1435 
1436     CreateMenuSeparatorSection(mnuHelp,itmHelpTools,'itmHelpTools');
1437     ParentMI:=itmHelpTools;
1438   end;
1439 end;
1440 
1441 procedure TMainIDEBase.LoadMenuShortCuts;
1442 begin
1443 end;
1444 
TMainIDEBase.DoOpenMacroFilenull1445 function TMainIDEBase.DoOpenMacroFile(Sender: TObject; const AFilename: string
1446   ): TModalResult;
1447 begin
1448   Result:=DoOpenEditorFile(AFilename,-1,-1,
1449                   [ofOnlyIfExists,ofAddToRecent,ofRegularFile,ofConvertMacros]);
1450 end;
1451 
GetIconIndexnull1452 function GetIconIndex(AForm: TWinControl): Integer;
1453 begin
1454   if csDesigning in AForm.ComponentState then             // in designer
1455     case AForm.ClassName of
1456       'TFrameProxyDesignerForm':
1457         Exit(IDEImages.GetImageIndex('frame_designer'));      // frame
1458       'TNonControlProxyDesignerForm':
1459         Exit(IDEImages.GetImageIndex('datamodule_designer')); // datamodule
1460     else
1461       Exit(IDEImages.GetImageIndex('form_designer'));         // own form class (TForm1, TForm2, etc.)
1462     end;
1463 
1464   with MainIDEBar do
1465   case AForm.ClassName of
1466     'TCharacterMapDialog':     Exit(-1);                      // for future icon
1467     'TObjectInspectorDlg':     Exit(itmViewInspector.ImageIndex);
1468     'TSourceNotebook':         Exit(itmViewSourceEditor.ImageIndex);
1469     'TMessagesView':           Exit(itmViewMessage.ImageIndex);
1470     'TCodeExplorerView':       Exit(itmViewCodeExplorer.ImageIndex);
1471     'TFPDocEditor':            Exit(-1);                      // for future icon
1472     'TCodeBrowserView':        Exit(itmViewCodeBrowser.ImageIndex);
1473     'TUnitDependenciesWindow': Exit(-1);                      // for future icon
1474     'TRestrictionBrowserView': Exit(itmViewRestrictionBrowser.ImageIndex);
1475     'TComponentListForm':      Exit(itmViewComponents.ImageIndex);
1476     'TJumpHistoryViewWin':     Exit(itmJumpHistory.ImageIndex);
1477     'TMacroListView':          Exit(-1);                      // for future icon
1478     'TTabOrderDialog':         Exit(itmViewTabOrder.ImageIndex);
1479     'TSearchResultsView':      Exit(itmViewSearchResults.ImageIndex);
1480     'TWatchesDlg':             Exit(itmViewWatches.ImageIndex);
1481     'TBreakPointsDlg':         Exit(itmViewBreakPoints.ImageIndex);
1482     'TLocalsDlg':              Exit(-1);                      // for future icon
1483     'TRegistersDlg':           Exit(-1);                      // for future icon
1484     'TCallStackDlg':           Exit(itmViewCallStack.ImageIndex);
1485     'TThreadsDlg':             Exit(-1);                      // for future icon
1486     'TAssemblerDlg':           Exit(-1);                      // for future icon
1487     'TDbgEventsForm':          Exit(-1);                      // for future icon
1488     'THistoryDialog':          Exit(-1);                      // for future icon
1489     'TDbgOutputForm':          Exit(itmViewDebugOutput.ImageIndex);
1490     'TProjectInspectorForm':   Exit(itmProjectInspector.ImageIndex);
1491     'TPkgGraphExplorerDlg':    Exit(itmPkgPkgGraph.ImageIndex);
1492     'TPackageEditorForm':      Exit(IDEImages.GetImageIndex('item_package'));
1493     'TDSFieldsEditorFrm':               Exit(-1);             // for future icon
1494     'TDBGridColumnsPropertyEditorForm': Exit(-1);             // for future icon
1495     'TActionListEditor':                Exit(-1);             // for future icon
1496     'TCollectionPropertyEditorForm':    Exit(-1);             // for future icon
1497     'TSeriesEditorForm':                Exit(-1);             // for future icon
1498     // In packages, may not be installed:
1499     'TProjectGroupEditorForm': Exit(IDEImages.GetImageIndex('pg_item'));
1500     'THeapTrcViewForm':        Exit(-1);                      // for future icon
1501     'TIDETodoWindow':          Exit(IDEImages.GetImageIndex('menu_view_todo'));
1502     'TAnchorDesigner':         Exit(IDEImages.GetImageIndex('menu_view_anchor_editor'));
1503   else
1504     Exit(-1);
1505   end;
1506 end;
1507 
GetMenuItemnull1508 function GetMenuItem(Index: Integer; ASection: TIDEMenuSection): TIDEMenuItem;
1509 begin
1510   Result := RegisterIDEMenuCommand(ASection,'Window'+IntToStr(Index)+ASection.Name,'');
1511   Result.CreateMenuItem;
1512 end;
1513 
1514 procedure InitMenuItem(AMenuItem: TIDEMenuItem; AForm: TCustomForm; AIcon: Integer);
1515 begin
1516   AMenuItem.ImageIndex := AIcon;
1517   if not IsFormDesign(AForm) then
1518     AMenuItem.Caption := AForm.Caption
1519   else
1520     case AForm.ClassName of
1521       'TFrameProxyDesignerForm',         // frame
1522       'TNonControlProxyDesignerForm':    // datamodule
1523           AMenuItem.Caption := AForm.Caption;
1524     else                                 // form
1525       if EnvironmentOptions.Desktop.IDENameForDesignedFormList then
1526         AMenuItem.Caption := AForm.Name
1527       else
1528         AMenuItem.Caption := AForm.Caption;
1529     end;
1530   AMenuItem.UserTag := {%H-}PtrUInt(AForm);
1531 end;
1532 
1533 procedure TMainIDEBase.UpdateWindowMenu;
1534 var
1535   WindowsList: TFPList;
1536   i, EditorIndex, ItemCountProject, ItemCountOther, IconInd: Integer;
1537   CurMenuItem: TIDEMenuItem;
1538   AForm: TForm;
1539   EdList: TStringListUTF8Fast;
1540   se: TSourceEditor;
1541   P: TIDEPackage;
1542   aSection: TIDEMenuSection;
1543   s: String;
1544 begin
1545   itmWindowLists.Clear;
1546   itmCenterWindowLists.Clear;
1547 
1548   WindowsList:=TFPList.Create;
1549   // add typical IDE windows at the start of the list
1550   for i := 0 to SourceEditorManager.SourceWindowCount - 1 do
1551     WindowsList.Add(SourceEditorManager.SourceWindows[i]);
1552   if (ObjectInspector1<>nil) and (ObjectInspector1.Visible) then
1553     WindowsList.Add(ObjectInspector1);
1554   {$IFNDEF MSWindows}
1555   if MainIDEBar.Parent=nil then
1556     WindowsList.Add(MainIDEBar);
1557   {$ENDIF}
1558   // add special IDE windows
1559   for i := 0 to Screen.FormCount-1 do begin
1560     AForm := Screen.Forms[i];
1561     //debugln(['TMainIDEBase.UpdateWindowMenu ',DbgSName(AForm),' Vis=',AForm.IsVisible,' Des=',DbgSName(AForm.Designer)]);
1562     if (AForm=MainIDEBar) or (AForm=SplashForm) or IsFormDesign(AForm)
1563     or (WindowsList.IndexOf(AForm)>=0) then
1564       continue;
1565     if IDEDockMaster<>nil then
1566     begin
1567       if not IDEDockMaster.AddableInWindowMenu(AForm) then continue;
1568     end else begin
1569       if (AForm.Parent<>nil) or not AForm.IsVisible then continue;
1570     end;
1571     WindowsList.Add(AForm);
1572   end;
1573   // add designer forms and datamodule forms
1574   for i := 0 to Screen.FormCount-1 do begin
1575     AForm := Screen.Forms[i];
1576     if (AForm.Designer<>nil) and (WindowsList.IndexOf(AForm)<0) then
1577       WindowsList.Add(AForm);
1578   end;
1579   // create menuitems for all windows
1580   for i := 0 to WindowsList.Count-1 do
1581   begin
1582     IconInd := GetIconIndex(TWinControl(WindowsList[i]));
1583     // in the 'bring to front' list
1584     CurMenuItem := GetMenuItem(i, itmWindowLists);
1585     InitMenuItem(CurMenuItem, TCustomForm(WindowsList[i]), IconInd);
1586     CurMenuItem.Checked := WindowMenuActiveForm = TCustomForm(WindowsList[i]);
1587     CurMenuItem.OnClick := @mnuWindowItemClick;
1588     // in the 'center' list
1589     CurMenuItem := GetMenuItem(i, itmCenterWindowLists);
1590     InitMenuItem(CurMenuItem, TCustomForm(WindowsList[i]), IconInd);
1591     CurMenuItem.OnClick := @mnuCenterWindowItemClick;
1592   end;
1593   //create source page menuitems
1594   itmTabListProject.Visible := False;
1595   itmTabListOther.Visible := False;
1596   itmTabListProject.Checked := False;
1597   itmTabListOther.Checked := False;
1598 
1599   itmTabListProject.Clear;
1600   itmTabListPackage.Clear;
1601   itmTabListOther.Clear;
1602 
1603   if SourceEditorManager.SourceEditorCount > 0 then begin
1604     ItemCountProject := 0;
1605     ItemCountOther := 0;
1606     EdList := TStringListUTF8Fast.Create;
1607     EdList.OwnsObjects := False;
1608     for i := 0 to SourceEditorManager.SourceEditorCount - 1 do begin
1609       se := SourceEditorManager.SourceEditors[i];
1610       EdList.AddObject(se.PageName+' '+se.FileName+se.Owner.Name, TObject(PtrUInt(i)));
1611     end;
1612     EdList.Sorted := True;
1613     for i := 0 to EdList.Count - 1 do
1614     begin
1615       EditorIndex := PtrUInt(EdList.Objects[i]);
1616       se := SourceEditorManager.SourceEditors[EditorIndex];
1617       if (se.GetProjectFile <> nil) and (se.GetProjectFile.IsPartOfProject) then begin
1618         aSection := itmTabListProject;
1619         CurMenuItem := GetMenuItem(ItemCountProject, aSection);
1620         inc(ItemCountProject);
1621       end else begin
1622         SourceEditorManager.OnPackageForSourceEditor(P, se);
1623         if P <> nil then begin
1624           s := Format(lisTabsFor, [p.Name]);
1625           if itmTabListPackage.FindByName(S) is TIDEMenuSection then
1626             aSection := TIDEMenuSection(itmTabListPackage.FindByName(S))
1627           else
1628             aSection := RegisterIDESubMenu(itmTabListPackage, S, S);
1629           CurMenuItem := GetMenuItem(aSection.Count, aSection);
1630         end else begin
1631           aSection := itmTabListOther;
1632           CurMenuItem := GetMenuItem(ItemCountOther, aSection);
1633           inc(ItemCountOther);
1634         end;
1635       end;
1636       aSection.Visible := True;
1637       if se.SharedEditorCount > 1 then
1638         CurMenuItem.Caption := se.PageName + ' ('+TForm(se.Owner).Caption+')'
1639       else
1640         CurMenuItem.Caption := se.PageName;
1641       if CurMenuItem.MenuItem <> nil then
1642         CurMenuItem.Checked := SourceEditorManager.ActiveEditor = se;
1643       if (SourceEditorManager.ActiveEditor = se) and (aSection.MenuItem <> nil) then
1644         aSection.Checked := true;
1645       CurMenuItem.OnClick := @mnuWindowSourceItemClick;
1646       CurMenuItem.Tag := EditorIndex;
1647     end;
1648     EdList.Free;
1649 
1650     for i := 0 to itmTabListPackage.Count - 1 do begin
1651       if itmTabListPackage.Items[i] is TIDEMenuSection then begin
1652         aSection := itmTabListPackage.Items[i] as TIDEMenuSection;
1653         aSection.Caption := aSection.Caption +  Format(' (%d)', [aSection.Count]);
1654       end;
1655     end;
1656     itmTabListProject.Caption := dlgEnvProject +  Format(' (%d)', [itmTabListProject.Count]);
1657     itmTabListOther.Caption := lisMEOther +  Format(' (%d)', [itmTabListOther.Count]);
1658     if itmTabListPackage.TopSeparator <> nil then
1659       itmTabListPackage.TopSeparator.Visible := False;
1660     if itmTabListOther.TopSeparator <> nil then
1661       itmTabListOther.TopSeparator.Visible := False;
1662   end;
1663   WindowsList.Free;           // clean up
1664 end;
1665 
1666 procedure TMainIDEBase.SetRecentSubMenu(Section: TIDEMenuSection;
1667   FileList: TStringList; OnClickEvent: TNotifyEvent);
1668 var
1669   i: integer;
1670   AMenuItem: TIDEMenuItem;
1671 begin
1672   // create enough menuitems
1673   while Section.Count<FileList.Count do begin
1674     AMenuItem:=RegisterIDEMenuCommand(Section.GetPath,
1675                               Section.Name+'Recent'+IntToStr(Section.Count),'');
1676   end;
1677   // delete unused menuitems
1678   while Section.Count>FileList.Count do
1679     Section.Items[Section.Count-1].Free;
1680   Section.Enabled:=(Section.Count>0);
1681   // set captions and event
1682   for i:=0 to FileList.Count-1 do begin
1683     AMenuItem:=Section.Items[i];
1684     AMenuItem.Caption := ShortDisplayFilename(FileList[i]);
1685     AMenuItem.Hint := FileList[i]; // Hint is not shown, it just holds the full filename.
1686     AMenuItem.OnClick := OnClickEvent;
1687   end;
1688 end;
1689 
1690 procedure TMainIDEBase.SetRecentProjectFilesMenu;
1691 begin
1692   SetRecentSubMenu(itmProjectRecentOpen,
1693                    EnvironmentOptions.RecentProjectFiles,
1694                    @mnuOpenProjectClicked);
1695 end;
1696 
1697 procedure TMainIDEBase.SetRecentFilesMenu;
1698 begin
1699   SetRecentSubMenu(itmFileRecentOpen,
1700                    EnvironmentOptions.RecentOpenFiles,
1701                    @mnuOpenRecentClicked);
1702 end;
1703 
1704 procedure TMainIDEBase.UpdateRecentFilesEnv;
1705 begin
1706   SetRecentFilesMenu;
1707   SaveEnvironment;
1708 end;
1709 
1710 procedure TMainIDEBase.DoOpenRecentFile(AFilename: string);
1711 begin
1712   if DoOpenEditorFile(AFilename,-1,-1,[ofAddToRecent])=mrOk then
1713     UpdateRecentFilesEnv
1714   else begin
1715     // open failed
1716     if not FileExistsUTF8(AFilename) then begin
1717       // file does not exist -> delete it from recent file list
1718       EnvironmentOptions.RemoveFromRecentOpenFiles(AFilename);
1719       UpdateRecentFilesEnv;
1720     end;
1721   end;
1722 end;
1723 
1724 procedure TMainIDEBase.mnuOpenRecentClicked(Sender: TObject);
1725 begin
1726   // Hint holds the full filename, Caption may have a shortened form.
1727   DoOpenRecentFile((Sender as TIDEMenuItem).Hint);
1728 end;
1729 
1730 procedure TMainIDEBase.UpdateHighlighters(Immediately: boolean);
1731 var
1732   ASrcEdit: TSourceEditor;
1733   h: TLazSyntaxHighlighter;
1734   i: Integer;
1735   AnEditorInfo: TUnitEditorInfo;
1736 begin
1737   if Immediately then begin
1738     Exclude(FIdleIdeActions, iiaUpdateHighlighters);
1739     for h := Low(TLazSyntaxHighlighter) to High(TLazSyntaxHighlighter) do
1740       if Highlighters[h]<>nil then begin
1741         Highlighters[h].BeginUpdate;
1742         EditorOpts.GetHighlighterSettings(Highlighters[h]);
1743         Highlighters[h].EndUpdate;
1744       end;
1745     if Project1<>nil then begin
1746       for i := 0 to SourceEditorManager.SourceEditorCount - 1 do begin
1747         ASrcEdit := SourceEditorManager.SourceEditors[i];
1748         AnEditorInfo:=Project1.EditorInfoWithEditorComponent(ASrcEdit);
1749         if AnEditorInfo <> nil then
1750           ASrcEdit.SyntaxHighlighterType := AnEditorInfo.SyntaxHighlighter;
1751       end;
1752     end;
1753   end
1754   else
1755     Include(FIdleIdeActions, iiaUpdateHighlighters);
1756 end;
1757 
1758 procedure TMainIDEBase.UpdateDefineTemplates;
1759 begin
1760   Include(FIdleIdeActions, iiaUpdateDefineTemplates);
1761 end;
1762 
1763 procedure TMainIDEBase.FindInFilesPerDialog(AProject: TProject);
1764 begin
1765   FindInFilesDialog.FindInFilesPerDialog(AProject);
1766 end;
1767 
1768 procedure TMainIDEBase.FindInFiles(AProject: TProject; const FindText: string);
1769 begin
1770   FindInFilesDialog.FindInFiles(AProject, FindText);
1771 end;
1772 
1773 { TRunToolButton }
1774 
1775 procedure TRunToolButton.ChangeRunMode(Sender: TObject);
1776 begin
1777   Project1.RunParameterOptions.ActiveModeName := (Sender as TRunOptionItem).RunOptionName;
1778   Project1.SessionModified:=true;
1779 end;
1780 
1781 procedure TRunToolButton.DoOnAdded;
1782 begin
1783   inherited DoOnAdded;
1784 
1785   DropdownMenu := TPopupMenu.Create(Self);
1786   Style := tbsDropDown;
1787   DropdownMenu.OnPopup := @MenuOnPopup;
1788   if Assigned(FToolBar) then
1789     DropdownMenu.Images := IDEImages.Images_16;
1790 end;
1791 
1792 procedure TRunToolButton.MenuOnPopup(Sender: TObject);
1793 begin
1794   RefreshMenu;
1795 end;
1796 
1797 procedure TRunToolButton.RefreshMenu;
1798   procedure _AddMode(const _Mode: TRunParamsOptionsMode; const _Parent: TMenuItem;
1799     const _OnClick: TNotifyEvent);
1800   var
1801     xItem: TRunOptionItem;
1802   begin
1803     xItem := TRunOptionItem.Create(_Parent.Menu);
1804     _Parent.Add(xItem);
1805     xItem.Caption := _Mode.Name;
1806     xItem.OnClick := _OnClick;
1807     xItem.RunOptionName := _Mode.Name;
1808     xItem.Checked := (Project1<>nil) and (_Mode.Name = Project1.RunParameterOptions.ActiveModeName);
1809   end;
1810 
1811 var
1812   xPM: TPopupMenu;
1813   i: Integer;
1814   xMIRunParameters: TMenuItem;
1815   xMode: TRunParamsOptionsMode;
1816 begin
1817   xPM := DropdownMenu;
1818   xPM.Items.Clear;
1819 
1820   xMIRunParameters := TMenuItem.Create(xPM);
1821   xMIRunParameters.Caption := dlgRunParameters+' ...';
1822   xMIRunParameters.ImageIndex := IDEImages.LoadImage('menu_run_parameters');
1823   xMIRunParameters.OnClick := @RunParametersClick;
1824 
1825   if Project1<>nil then
1826   for i:=0 to Project1.RunParameterOptions.Count-1 do
1827   begin
1828     xMode := Project1.RunParameterOptions[i] as TRunParamsOptionsMode;
1829     _AddMode(xMode, xPM.Items, @ChangeRunMode);
1830   end;
1831 
1832   if xPM.Items.Count > 0 then
1833     xPM.Items.AddSeparator;
1834   xPM.Items.Add(xMIRunParameters);
1835 end;
1836 
1837 procedure TRunToolButton.RunParametersClick(Sender: TObject);
1838 begin
1839   ExecuteIDECommand(Sender, ecRunParameters);
1840 end;
1841 
1842 end.
1843 
1844 
1845