PageRenderTime 162ms CodeModel.GetById 4ms app.highlight 142ms RepoModel.GetById 1ms app.codeStats 0ms

/ide/mainbase.pas

http://github.com/graemeg/lazarus
Pascal | 1967 lines | 1588 code | 217 blank | 162 comment | 105 complexity | f84a116ee812e1a9e5af3dc0acd87103 MD5 | raw file
   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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
  43 *                                                                         *
  44 ***************************************************************************
  45}
  46unit MainBase;
  47
  48{$mode objfpc}{$H+}
  49
  50interface
  51
  52{$I ide.inc}
  53
  54uses
  55{$IFDEF IDE_MEM_CHECK}
  56  MemCheck,
  57{$ENDIF}
  58  Math, Classes, LCLType, LCLProc, LCLIntf, Buttons, Menus, ComCtrls,
  59  SysUtils, types, Controls, Graphics, ExtCtrls, Dialogs, LazFileUtils, Forms,
  60  CodeToolManager, AVL_Tree, SynEditKeyCmds, PackageIntf,
  61  // IDEIntf
  62  IDEImagesIntf, SrcEditorIntf, LazIDEIntf, MenuIntf, NewItemIntf,
  63  IDECommands, IDEWindowIntf, ProjectIntf, ToolBarIntf,
  64  // IDE
  65  LazConf, LazarusIDEStrConsts, ProjectDefs, Project, IDEDialogs,
  66  TransferMacros, ObjectInspector, PropEdits, BuildManager,
  67  EnvironmentOpts, EditorOptions, CompilerOptions, KeyMapping, IDEProcs,
  68  Debugger, IDEOptionDefs, Splash, Designer,
  69  SourceEditor, FindInFilesDlg,
  70  MainBar, MainIntf, SourceSynEditor, PseudoTerminalDlg,
  71  DesktopManager, ImgList;
  72
  73type
  74  TResetToolFlag = (
  75    rfInteractive,
  76    rfCloseOnDone,
  77    rfSuccessOnTrigger
  78  );
  79  TResetToolFlags = set of TResetToolFlag;
  80
  81  { TMainIDEBase }
  82
  83  TMainIDEBase = class(TMainIDEInterface)
  84  private
  85    FWindowMenuActiveForm: TCustomForm;
  86    FDisplayState: TDisplayState;
  87    procedure SetDisplayState(AValue: TDisplayState);
  88  protected
  89    FNeedUpdateHighlighters: boolean;
  90
  91    function CreateMenuSeparator : TMenuItem;
  92    procedure CreateMenuItem(Section: TIDEMenuSection;
  93                             var MenuCommand: TIDEMenuCommand;
  94                             const MenuItemName, MenuItemCaption: String;
  95                             const bmpName: String = '';
  96                             mnuEnabled: Boolean = true;
  97                             mnuChecked: Boolean = false;
  98                             mnuVisible: Boolean = true);
  99    procedure CreateMenuSeparatorSection(ParentSection: TIDEMenuSection;
 100                             var Section: TIDEMenuSection; const AName: String);
 101    procedure CreateMenuSubSection(ParentSection: TIDEMenuSection;
 102                             var Section: TIDEMenuSection;
 103                             const AName, ACaption: String;
 104                             const bmpName: String = '');
 105    procedure CreateMainMenuItem(var Section: TIDEMenuSection;
 106                                 const MenuItemName, MenuItemCaption: String);
 107    procedure SetupMainMenu; virtual;
 108    procedure SetupFileMenu; virtual;
 109    procedure SetupEditMenu; virtual;
 110    procedure SetupSearchMenu; virtual;
 111    procedure SetupViewMenu; virtual;
 112    procedure SetupSourceMenu; virtual;
 113    procedure SetupProjectMenu; virtual;
 114    procedure SetupRunMenu; virtual;
 115    procedure SetupPackageMenu; virtual;
 116    procedure SetupToolsMenu; virtual;
 117    procedure SetupWindowsMenu; virtual;
 118    procedure SetupHelpMenu; virtual;
 119
 120    procedure LoadMenuShortCuts; virtual;
 121    procedure SetToolStatus(const AValue: TIDEToolStatus); override;
 122
 123    procedure DoMnuWindowClicked(Sender: TObject);
 124    procedure mnuOpenProjectClicked(Sender: TObject); virtual; abstract;
 125    procedure mnuOpenRecentClicked(Sender: TObject); virtual; abstract;
 126    procedure mnuWindowItemClick(Sender: TObject); virtual;
 127    procedure mnuCenterWindowItemClick(Sender: TObject); virtual;
 128    procedure mnuWindowSourceItemClick(Sender: TObject); virtual;
 129    procedure mnuBuildModeClicked(Sender: TObject); virtual; abstract;
 130
 131    procedure UpdateWindowMenu;
 132
 133  public
 134    function DoResetToolStatus(AFlags: TResetToolFlags): boolean; virtual; abstract;
 135
 136    constructor Create(TheOwner: TComponent); override;
 137    procedure StartIDE; virtual; abstract;
 138    destructor Destroy; override;
 139    procedure CreateOftenUsedForms; virtual; abstract;
 140    function GetMainBar: TForm; override;
 141    procedure SetRecentProjectFilesMenu;
 142    procedure SetRecentFilesMenu;
 143    function BeginCodeTool(var ActiveSrcEdit: TSourceEditor;
 144                           out ActiveUnitInfo: TUnitInfo;
 145                           Flags: TCodeToolsFlags): boolean;
 146    function BeginCodeTool(ADesigner: TDesigner;
 147                           var ActiveSrcEdit: TSourceEditor;
 148                           out ActiveUnitInfo: TUnitInfo;
 149                           Flags: TCodeToolsFlags): boolean;
 150    procedure ActivateCodeToolAbortableMode;
 151    function OnCodeToolBossCheckAbort: boolean;
 152    procedure DoShowDesignerFormOfCurrentSrc(AComponentPaletteClassSelected: Boolean); virtual; abstract;
 153    function CreateDesignerForComponent(AnUnitInfo: TUnitInfo;
 154                        AComponent: TComponent): TCustomForm; virtual; abstract;
 155    procedure UpdateSaveMenuItemsAndButtons(UpdateSaveAll: boolean); virtual; abstract;
 156
 157    procedure DoMergeDefaultProjectOptions(AProject: TProject);
 158    procedure DoSwitchToFormSrc(var ActiveSourceEditor:TSourceEditor;
 159      var ActiveUnitInfo:TUnitInfo);
 160    procedure DoSwitchToFormSrc(ADesigner: TIDesigner;
 161      var ActiveSourceEditor:TSourceEditor; var ActiveUnitInfo:TUnitInfo);
 162
 163    procedure GetUnitInfoForDesigner(ADesigner: TIDesigner;
 164                              out ActiveSourceEditor: TSourceEditorInterface;
 165                              out ActiveUnitInfo: TUnitInfo); override;
 166    procedure GetCurrentUnitInfo(out ActiveSourceEditor: TSourceEditorInterface;
 167                              out ActiveUnitInfo: TUnitInfo); override;
 168    procedure GetCurrentUnit(out ActiveSourceEditor: TSourceEditor;
 169                             out ActiveUnitInfo: TUnitInfo); virtual; abstract;
 170    procedure GetDesignerUnit(ADesigner: TDesigner;
 171          out ActiveSourceEditor: TSourceEditor; out ActiveUnitInfo: TUnitInfo); virtual; abstract;
 172    procedure GetObjectInspectorUnit(
 173          out ActiveSourceEditor: TSourceEditor; out ActiveUnitInfo: TUnitInfo); virtual; abstract;
 174    procedure GetUnitWithForm(AForm: TCustomForm;
 175          out ActiveSourceEditor: TSourceEditor; out ActiveUnitInfo: TUnitInfo); virtual; abstract;
 176    procedure GetUnitWithPersistent(APersistent: TPersistent;
 177          out ActiveSourceEditor: TSourceEditor; out ActiveUnitInfo: TUnitInfo); virtual; abstract;
 178    procedure DoShowComponentList(State: TIWGetFormState = iwgfShowOnTop); virtual; abstract;
 179
 180    function DoOpenMacroFile(Sender: TObject; const AFilename: string): TModalResult; override;
 181
 182    procedure SetRecentSubMenu(Section: TIDEMenuSection; FileList: TStringList;
 183                               OnClickEvent: TNotifyEvent); override;
 184    procedure UpdateHighlighters(Immediately: boolean = false); override;
 185
 186    procedure FindInFilesPerDialog(AProject: TProject); override;
 187    procedure FindInFiles(AProject: TProject; const FindText: string); override;
 188
 189    procedure SelComponentPageButtonMouseDown(Sender: TObject;
 190      Button: TMouseButton; Shift: TShiftState; X, Y: Integer); virtual; abstract;
 191    procedure SelComponentPageButtonClick(Sender: TObject); virtual; abstract;
 192  public
 193    property WindowMenuActiveForm: TCustomForm read FWindowMenuActiveForm write FWindowMenuActiveForm;
 194    property DisplayState: TDisplayState read FDisplayState write SetDisplayState;
 195  end;
 196
 197  { TJumpToSectionToolButton }
 198
 199  TJumpToSectionToolButton = class(TIDEToolButton)
 200  private
 201    procedure AddMenuItem(aCmd: TIDEMenuCommand);
 202  public
 203    procedure DoOnAdded; override;
 204    procedure RefreshMenu;
 205  end;
 206
 207  { TSetBuildModeToolButton }
 208
 209  TSetBuildModeToolButton = class(TIDEToolButton)
 210  private
 211    procedure RefreshMenu(Sender: TObject);
 212    procedure mnuSetBuildModeClick(Sender: TObject);
 213  public
 214    procedure DoOnAdded; override;
 215  end;
 216
 217  { TOpenFileToolButton }
 218
 219  TOpenFileToolButton = class(TIDEToolButton)
 220  private
 221    FIndex: TStringList;
 222
 223    procedure RefreshMenu(Sender: TObject);
 224    procedure mnuOpenFile(Sender: TObject);
 225    procedure mnuProjectFile(Sender: TObject);
 226  public
 227    constructor Create(aOwner: TComponent); override;
 228    destructor Destroy; override;
 229
 230    procedure DoOnAdded; override;
 231  end;
 232
 233  { TOpenFileMenuItem }
 234
 235  TOpenFileMenuItem = class(TMenuItem)
 236  public
 237    FileName: string;
 238  end;
 239
 240  { TNewFormUnitToolButton }
 241
 242  TNewFormUnitToolButton = class(TIDEToolButton)
 243  private
 244    SetDefaultMenuItem: TMenuItem;
 245
 246    procedure RefreshMenu(Sender: TObject);
 247    procedure mnuSetFormUnitTemplate(Sender: TObject);
 248  protected
 249    class function FindDefaultTemplateName(Category: TNewIDEItemCategory): string; virtual; abstract;
 250    class procedure SetTemplateName(const TemplateName: string); virtual; abstract;
 251    class procedure UpdateHint(const AHint: string); virtual; abstract;
 252  public
 253    procedure DoOnAdded; override;
 254
 255    class procedure UpdateHints;
 256  end;
 257
 258  { TNewUnitToolButton }
 259
 260  TNewUnitToolButton = class(TNewFormUnitToolButton)
 261  protected
 262    class function FindDefaultTemplateName(Category: TNewIDEItemCategory): string; override;
 263    class procedure SetTemplateName(const TemplateName: string); override;
 264    class procedure UpdateHint(const AHint: string); override;
 265  end;
 266
 267  { TNewFormToolButton }
 268
 269  TNewFormToolButton = class(TNewFormUnitToolButton)
 270  protected
 271    class function FindDefaultTemplateName(Category: TNewIDEItemCategory): string; override;
 272    class procedure SetTemplateName(const TemplateName: string); override;
 273    class procedure UpdateHint(const AHint: string); override;
 274  end;
 275
 276  { TNewFormUnitMenuItem }
 277
 278  TNewFormUnitMenuItem = class(TMenuItem)
 279  public
 280    TemplateName: string;
 281  end;
 282
 283function  GetMainIde: TMainIDEBase;
 284
 285property MainIDE: TMainIDEBase read GetMainIde;
 286
 287  { Normally the IDE builds itself with packages named in config files.
 288    When the IDE should keep the packages installed in the current executable
 289    set KeepInstalledPackages to true. }
 290var KeepInstalledPackages: boolean = false;
 291
 292implementation
 293
 294function GetMainIde: TMainIDEBase;
 295begin
 296  Result := TMainIDEBase(MainIDEInterface)
 297end;
 298
 299{ TNewFormUnitToolButton }
 300
 301procedure TNewFormUnitToolButton.DoOnAdded;
 302begin
 303  inherited DoOnAdded;
 304
 305  PopupMenu := TPopupMenu.Create(Self);
 306  PopupMenu.OnPopup := @RefreshMenu;
 307
 308  SetDefaultMenuItem:=TMenuItem.Create(PopupMenu);
 309  SetDefaultMenuItem.Caption:=lisSetDefault;
 310  PopupMenu.Items.Add(SetDefaultMenuItem);
 311
 312  UpdateHints;
 313end;
 314
 315procedure TNewFormUnitToolButton.mnuSetFormUnitTemplate(Sender: TObject);
 316begin
 317  SetTemplateName((Sender as TNewFormUnitMenuItem).TemplateName);
 318  EnvironmentOptions.Save(False);
 319
 320  UpdateHints;
 321end;
 322
 323procedure TNewFormUnitToolButton.RefreshMenu(Sender: TObject);
 324var
 325  TemplateName: String;
 326  Category: TNewIDEItemCategory;
 327  i: Integer;
 328  CurTemplate: TNewIDEItemTemplate;
 329  TheIndex: Integer;
 330  xItem: TNewFormUnitMenuItem;
 331begin
 332  Category:=NewIDEItems.FindCategoryByPath(FileDescGroupName,true);
 333  TemplateName:=FindDefaultTemplateName(Category);
 334
 335  // create menu items
 336  TheIndex:=0;
 337  for i:=0 to Category.Count-1 do begin
 338    CurTemplate:=Category[i];
 339    if not CurTemplate.VisibleInNewDialog then continue;
 340    if TheIndex<SetDefaultMenuItem.Count then
 341      xItem:=SetDefaultMenuItem[TheIndex] as TNewFormUnitMenuItem
 342    else begin
 343      xItem:=TNewFormUnitMenuItem.Create(SetDefaultMenuItem);
 344      SetDefaultMenuItem.Add(xItem);
 345    end;
 346    xItem.OnClick:=@mnuSetFormUnitTemplate;
 347    xItem.Caption:=CurTemplate.LocalizedName;
 348    xItem.TemplateName:=CurTemplate.Name;
 349    xItem.ShowAlwaysCheckable:=true;
 350    xItem.Checked:=CompareText(TemplateName,CurTemplate.Name)=0;
 351    inc(TheIndex);
 352  end;
 353  // remove unneeded items
 354  while SetDefaultMenuItem.Count>TheIndex do
 355    SetDefaultMenuItem.Items[SetDefaultMenuItem.Count-1].Free;
 356end;
 357
 358class procedure TNewFormUnitToolButton.UpdateHints;
 359var
 360  Category: TNewIDEItemCategory;
 361  TemplateName: String;
 362  Template: TNewIDEItemTemplate;
 363begin
 364  if not Assigned(NewIDEItems) then
 365    Exit;
 366  Category:=NewIDEItems.FindCategoryByPath(FileDescGroupName,true);
 367  TemplateName:=FindDefaultTemplateName(Category);
 368  if TemplateName<>'' then  //try to get the LocalizedName
 369  begin
 370    Template:=Category.FindTemplateByName(TemplateName);
 371    if Assigned(Template) then
 372      TemplateName := Template.LocalizedName;
 373  end;
 374  UpdateHint(Format(lisMenuNewCustom, [TemplateName]));
 375end;
 376
 377{ TNewFormToolButton }
 378
 379class function TNewFormToolButton.FindDefaultTemplateName(
 380  Category: TNewIDEItemCategory): string;
 381begin
 382  Result:=EnvironmentOptions.NewFormTemplate;
 383  if (Result='') or (Category.FindTemplateByName(Result)=nil) then
 384    Result:=FileDescNameLCLForm;
 385end;
 386
 387class procedure TNewFormToolButton.SetTemplateName(const TemplateName: string);
 388begin
 389  EnvironmentOptions.NewFormTemplate:=TemplateName;
 390end;
 391
 392class procedure TNewFormToolButton.UpdateHint(const AHint: string);
 393begin
 394  MainIDEBar.itmFileNewForm.Hint := AHint;
 395end;
 396
 397{ TNewUnitToolButton }
 398
 399class function TNewUnitToolButton.FindDefaultTemplateName(
 400  Category: TNewIDEItemCategory): string;
 401begin
 402  Result:=EnvironmentOptions.NewUnitTemplate;
 403  if (Result='') or (Category.FindTemplateByName(Result)=nil) then
 404    Result:=FileDescNamePascalUnit;
 405end;
 406
 407class procedure TNewUnitToolButton.SetTemplateName(const TemplateName: string);
 408begin
 409  EnvironmentOptions.NewUnitTemplate:=TemplateName;
 410end;
 411
 412class procedure TNewUnitToolButton.UpdateHint(const AHint: string);
 413begin
 414  MainIDEBar.itmFileNewUnit.Hint := AHint;
 415end;
 416
 417{ TOpenFileToolButton }
 418
 419constructor TOpenFileToolButton.Create(aOwner: TComponent);
 420begin
 421  inherited Create(aOwner);
 422
 423  FIndex := TStringList.Create;
 424end;
 425
 426destructor TOpenFileToolButton.Destroy;
 427begin
 428  FIndex.Free;
 429
 430  inherited Destroy;
 431end;
 432
 433procedure TOpenFileToolButton.DoOnAdded;
 434begin
 435  inherited DoOnAdded;
 436
 437  DropdownMenu := TPopupMenu.Create(Self);
 438  DropdownMenu.OnPopup := @RefreshMenu;
 439  DropdownMenu.Images := TCustomImageList.Create(Self);
 440  DropdownMenu.Images.Width := 16;
 441  DropdownMenu.Images.Height := 16;
 442  Style := tbsDropDown;
 443end;
 444
 445procedure TOpenFileToolButton.mnuOpenFile(Sender: TObject);
 446begin
 447  if MainIDE.DoOpenEditorFile((Sender as TOpenFileMenuItem).FileName,-1,-1,
 448    [ofAddToRecent])=mrOk then
 449  begin
 450    MainIDE.SetRecentFilesMenu;
 451    MainIDE.SaveEnvironment;
 452  end;
 453end;
 454
 455procedure TOpenFileToolButton.mnuProjectFile(Sender: TObject);
 456begin
 457  MainIDE.DoOpenProjectFile((Sender as TOpenFileMenuItem).FileName,[ofAddToRecent]);
 458end;
 459
 460procedure TOpenFileToolButton.RefreshMenu(Sender: TObject);
 461  procedure AddFile(const AFileName: string; const AOnClick: TNotifyEvent);
 462  var
 463    AMenuItem: TOpenFileMenuItem;
 464    xExt: string;
 465  begin
 466    AMenuItem := TOpenFileMenuItem.Create(DropdownMenu);
 467    DropdownMenu.Items.Add(AMenuItem);
 468    AMenuItem.OnClick := AOnClick;
 469    AMenuItem.FileName := AFileName;
 470    AMenuItem.Caption := AFilename;
 471    xExt := ExtractFileExt(AFileName);
 472    if SameFileName(xExt, '.lpi') or SameFileName(xExt, '.lpr') then
 473      AMenuItem.ImageIndex := LoadProjectIconIntoImages(AFileName, DropdownMenu.Images, FIndex);
 474  end;
 475
 476  procedure AddFiles(List: TStringList; MaxCount: integer; const AOnClick: TNotifyEvent);
 477  var
 478    i: integer;
 479  begin
 480    i := 0;
 481    while (i < List.Count) and (i < MaxCount) do
 482    begin
 483      AddFile(List[i], AOnClick);
 484      inc(i);
 485    end;
 486  end;
 487
 488begin
 489  DropdownMenu.Items.Clear;
 490
 491  // first add recent projects
 492  AddFiles(EnvironmentOptions.RecentProjectFiles, EnvironmentOptions.MaxRecentProjectFiles, @mnuProjectFile);
 493  // add a separator
 494  DropdownMenu.Items.AddSeparator;
 495  // then add recent files
 496  AddFiles(EnvironmentOptions.RecentOpenFiles, EnvironmentOptions.MaxRecentOpenFiles, @mnuOpenFile);
 497end;
 498
 499{ TSetBuildModeToolButton }
 500
 501procedure TSetBuildModeToolButton.DoOnAdded;
 502begin
 503  inherited DoOnAdded;
 504
 505  DropdownMenu := TPopupMenu.Create(Self);
 506  DropdownMenu.OnPopup := @RefreshMenu;
 507  Style := tbsDropDown;
 508end;
 509
 510procedure TSetBuildModeToolButton.mnuSetBuildModeClick(Sender: TObject);
 511var
 512  TheMenuItem: TMenuItem;
 513  TheIndex: LongInt;
 514  NewMode: TProjectBuildMode;
 515begin
 516  TheMenuItem := (Sender as TMenuItem);
 517  if TheMenuItem.Caption = '-' then exit;
 518  TheIndex := TheMenuItem.MenuIndex;
 519  if (TheIndex < 0) or (TheIndex >= Project1.BuildModes.Count) then exit;
 520  NewMode := Project1.BuildModes[TheIndex];
 521  if NewMode = Project1.ActiveBuildMode then exit;
 522  if not (MainIDE.ToolStatus in [itNone,itDebugger]) then begin
 523    IDEMessageDialog('Error','You can not change the build mode while compiling.',
 524      mtError,[mbOk]);
 525    exit;
 526  end;
 527
 528  Project1.ActiveBuildMode := NewMode;
 529  MainBuildBoss.SetBuildTargetProject1(false);
 530  MainIDE.UpdateCaption;
 531end;
 532
 533procedure TSetBuildModeToolButton.RefreshMenu(Sender: TObject);
 534var
 535  aMenu: TPopupMenu;
 536  CurIndex: Integer;
 537  i: Integer;
 538
 539  procedure AddMode(CurMode: TProjectBuildMode);
 540  var
 541    AMenuItem: TMenuItem;
 542  begin
 543    if aMenu.Items.Count > CurIndex then
 544      AMenuItem := aMenu.Items[CurIndex]
 545    else
 546    begin
 547      AMenuItem := TMenuItem.Create(DropdownMenu);
 548      AMenuItem.Name := aMenu.Name + 'Mode' + IntToStr(CurIndex);
 549      AMenuItem.OnClick := @mnuSetBuildModeClick;
 550      aMenu.Items.Add(AMenuItem);
 551    end;
 552    AMenuItem.Caption := CurMode.GetCaption;
 553    AMenuItem.Checked := (Project1<>nil) and (Project1.ActiveBuildMode=CurMode);
 554    AMenuItem.ShowAlwaysCheckable:=true;
 555    inc(CurIndex);
 556  end;
 557
 558begin
 559  // fill the PopupMenu:
 560  CurIndex := 0;
 561  aMenu := DropdownMenu;
 562  if Project1<>nil then
 563    for i:=0 to Project1.BuildModes.Count-1 do
 564      AddMode(Project1.BuildModes[i]);
 565  // remove unused menuitems
 566  while aMenu.Items.Count > CurIndex do
 567    aMenu.Items[aMenu.Items.Count - 1].Free;
 568end;
 569
 570{ TJumpToSectionToolButton }
 571
 572procedure TJumpToSectionToolButton.DoOnAdded;
 573begin
 574  inherited DoOnAdded;
 575  RefreshMenu;
 576end;
 577
 578procedure TJumpToSectionToolButton.AddMenuItem(aCmd: TIDEMenuCommand);
 579var
 580  xItem: TMenuItem;
 581begin
 582  xItem := TMenuItem.Create(DropdownMenu);
 583  DropdownMenu.Items.Add(xItem);
 584  xItem.Caption := aCmd.Caption;
 585  xItem.OnClick := aCmd.OnClick;
 586  xItem.ImageIndex := aCmd.ImageIndex;
 587end;
 588
 589procedure TJumpToSectionToolButton.RefreshMenu;
 590begin
 591  if DropdownMenu = nil then
 592  begin
 593    DropdownMenu := TPopupMenu.Create(Self);
 594    if Assigned(FToolBar) then
 595      DropdownMenu.Images := FToolBar.Images;
 596    Style := tbsDropDown;
 597  end;
 598  DropdownMenu.Items.Clear;
 599  AddMenuItem(MainIDEBar.itmJumpToInterface);
 600  AddMenuItem(MainIDEBar.itmJumpToInterfaceUses);
 601  AddMenuItem(MainIDEBar.itmJumpToImplementation);
 602  AddMenuItem(MainIDEBar.itmJumpToImplementationUses);
 603  AddMenuItem(MainIDEBar.itmJumpToInitialization);
 604end;
 605
 606//{$IFDEF LCLCarbon}
 607//var
 608//  mnuApple: TIDEMenuSection = nil;
 609//{$ENDIF}
 610
 611{ TMainIDEBase }
 612
 613procedure TMainIDEBase.mnuWindowItemClick(Sender: TObject);
 614var
 615  i: Integer;
 616  Form: TCustomForm;
 617  nfd: Boolean;
 618begin
 619  i:=Screen.CustomFormCount-1;
 620  while (i>=0) do begin
 621    Form:=Screen.CustomForms[i];
 622    nfd := EnvironmentOptions.Desktop.IDENameForDesignedFormList;
 623    if (nfd and (Form.Name=(Sender as TIDEMenuCommand).Caption))
 624    or ((not nfd) and (Form.Caption=(Sender as TIDEMenuCommand).Caption)) then
 625      begin
 626        IDEWindowCreators.ShowForm(Form,true);
 627        break;
 628      end;
 629    dec(i);
 630  end;
 631end;
 632
 633procedure TMainIDEBase.mnuCenterWindowItemClick(Sender: TObject);
 634var
 635  i: Integer;
 636  Form: TCustomForm;
 637  r, NewBounds: TRect;
 638  nfd: Boolean;
 639begin
 640  i:=Screen.CustomFormCount-1;
 641  while (i>=0) do begin
 642    Form:=Screen.CustomForms[i];
 643    nfd := EnvironmentOptions.Desktop.IDENameForDesignedFormList;
 644    if (nfd and (Form.Name=(Sender as TIDEMenuCommand).Caption))
 645    or ((not nfd) and (Form.Caption=(Sender as TIDEMenuCommand).Caption)) then
 646    begin
 647      // show
 648      if not Form.IsVisible then
 649        IDEWindowCreators.ShowForm(Form,true);
 650      // move to monitor of main IDE bar
 651      Form:=GetParentForm(Form);
 652      if Form<>MainIDEBar then begin
 653        // center on main IDE
 654        Form.MakeFullyVisible(MainIDEBar.Monitor,true);
 655        debugln(['TMainIDEBase.mnuCenterWindowItemClick ',DbgSName(Form),' ',dbgs(Form.BoundsRect)]);
 656        r:=MainIDEBar.BoundsRect;
 657        if Form.Width<MainIDEBar.Width then
 658          NewBounds.Left:=(r.Left+r.Right-Form.Width) div 2
 659        else
 660          NewBounds.Left:=r.Left+50;
 661        if Form.Height<MainIDEBar.Height then
 662          NewBounds.Top:=(r.Top+r.Bottom-Form.Height) div 2
 663        else
 664          NewBounds.Top:=r.Top+50;
 665        NewBounds.Right:=NewBounds.Left+Max(70,Form.Width);
 666        NewBounds.Bottom:=NewBounds.Top+Max(70,Form.Height);
 667        debugln(['TMainIDEBase.mnuCenterWindowItemClick New=',dbgs(NewBounds)]);
 668        Form.BoundsRect:=NewBounds;
 669        Form.WindowState:=wsNormal;
 670        Form.BringToFront;
 671      end;
 672      break;
 673    end;
 674    dec(i);
 675  end;
 676end;
 677
 678procedure TMainIDEBase.mnuWindowSourceItemClick(Sender: TObject);
 679var
 680  i: LongInt;
 681begin
 682  if SourceEditorManager = nil then exit;
 683  i:=(sender as TIDEMenuCommand).tag;
 684  if (i<0) or (i>=SourceEditorManager.SourceEditorCount) then exit;
 685  SourceEditorManager.ActiveEditor := SourceEditorManager.SourceEditors[i];
 686  SourceEditorManager.ShowActiveWindowOnTop(True);
 687end;
 688
 689procedure TMainIDEBase.SetToolStatus(const AValue: TIDEToolStatus);
 690begin
 691  if ToolStatus=AValue then exit;
 692  inherited SetToolStatus(AValue);
 693  UpdateCaption;
 694end;
 695
 696constructor TMainIDEBase.Create(TheOwner: TComponent);
 697begin
 698  // Do not own everything in one big component hierachy. Otherwise the
 699  // notifications slow down everything
 700  fOwningComponent:=TComponent.Create(nil);
 701  inherited Create(TheOwner);
 702end;
 703
 704destructor TMainIDEBase.Destroy;
 705begin
 706  FreeThenNil(fOwningComponent);
 707  inherited Destroy;
 708end;
 709
 710procedure TMainIDEBase.GetUnitInfoForDesigner(ADesigner: TIDesigner;
 711  out ActiveSourceEditor: TSourceEditorInterface; out ActiveUnitInfo: TUnitInfo);
 712var
 713  SrcEdit: TSourceEditor;
 714begin
 715  ActiveSourceEditor:=nil;
 716  ActiveUnitInfo:=nil;
 717  if ADesigner is TDesigner then begin
 718    GetDesignerUnit(TDesigner(ADesigner),SrcEdit,ActiveUnitInfo);
 719    ActiveSourceEditor:=SrcEdit;
 720  end;
 721end;
 722
 723procedure TMainIDEBase.GetCurrentUnitInfo(
 724  out ActiveSourceEditor: TSourceEditorInterface; out ActiveUnitInfo: TUnitInfo);
 725var
 726  ASrcEdit: TSourceEditor;
 727  AnUnitInfo: TUnitInfo;
 728begin
 729  GetCurrentUnit(ASrcEdit, AnUnitInfo);
 730  ActiveSourceEditor:=ASrcEdit;
 731  ActiveUnitInfo:=AnUnitInfo;
 732end;
 733
 734function TMainIDEBase.GetMainBar: TForm;
 735begin
 736  Result:=MainIDEBar;
 737end;
 738
 739procedure TMainIDEBase.SetRecentProjectFilesMenu;
 740begin
 741  SetRecentSubMenu(itmProjectRecentOpen,
 742                   EnvironmentOptions.RecentProjectFiles,
 743                   @mnuOpenProjectClicked);
 744end;
 745
 746procedure TMainIDEBase.SetRecentFilesMenu;
 747begin
 748  SetRecentSubMenu(itmFileRecentOpen,
 749                   EnvironmentOptions.RecentOpenFiles,
 750                   @mnuOpenRecentClicked);
 751end;
 752
 753function TMainIDEBase.BeginCodeTool(var ActiveSrcEdit: TSourceEditor;
 754  out ActiveUnitInfo: TUnitInfo; Flags: TCodeToolsFlags): boolean;
 755begin
 756  Result:=BeginCodeTool(nil,ActiveSrcEdit,ActiveUnitInfo,Flags);
 757end;
 758
 759function TMainIDEBase.BeginCodeTool(ADesigner: TDesigner;
 760  var ActiveSrcEdit: TSourceEditor; out ActiveUnitInfo: TUnitInfo;
 761  Flags: TCodeToolsFlags): boolean;
 762var
 763  Edit: TIDESynEditor;
 764begin
 765  Result:=false;
 766  if (ctfUseGivenSourceEditor in Flags) and (Project1<>nil)
 767  and (ActiveSrcEdit<>nil) then begin
 768    ActiveUnitInfo := Project1.EditorInfoWithEditorComponent(ActiveSrcEdit).UnitInfo;
 769  end
 770  else begin
 771    ActiveSrcEdit:=nil;
 772    ActiveUnitInfo:=nil;
 773  end;
 774
 775  // check global stati
 776  if (ToolStatus in [itCodeTools,itCodeToolAborting]) then begin
 777    debugln('TMainIDEBase.BeginCodeTool impossible ',dbgs(ord(ToolStatus)));
 778    exit;
 779  end;
 780  if (not (ctfSourceEditorNotNeeded in Flags)) and (SourceEditorManager.SourceEditorCount=0)
 781  then begin
 782    //DebugLn('TMainIDEBase.BeginCodeTool no source editor');
 783    exit;
 784  end;
 785
 786  // check source editor
 787  if not (ctfUseGivenSourceEditor in Flags) then begin
 788    if ctfSwitchToFormSource in Flags then
 789      DoSwitchToFormSrc(ADesigner,ActiveSrcEdit,ActiveUnitInfo)
 790    else if ADesigner<>nil then
 791      GetDesignerUnit(ADesigner,ActiveSrcEdit,ActiveUnitInfo)
 792    else
 793      GetCurrentUnit(ActiveSrcEdit,ActiveUnitInfo);
 794  end;
 795  if (not (ctfSourceEditorNotNeeded in Flags)) and
 796     ((ActiveSrcEdit=nil) or (ActiveUnitInfo=nil))
 797  then exit;
 798
 799  // init codetools
 800  SaveSourceEditorChangesToCodeCache(nil);
 801  if ActiveSrcEdit<>nil then begin
 802    Edit:=ActiveSrcEdit.EditorComponent;
 803    CodeToolBoss.VisibleEditorLines:=Edit.LinesInWindow;
 804    CodeToolBoss.TabWidth:=Edit.TabWidth;
 805    CodeToolBoss.IndentSize:=Edit.BlockIndent+Edit.BlockTabIndent*Edit.TabWidth;
 806    CodeToolBoss.UseTabs:=Edit.BlockTabIndent>0;
 807  end else begin
 808    CodeToolBoss.VisibleEditorLines:=25;
 809    CodeToolBoss.TabWidth:=EditorOpts.TabWidth;
 810    CodeToolBoss.IndentSize:=EditorOpts.BlockIndent+EditorOpts.BlockTabIndent*EditorOpts.TabWidth;
 811    CodeToolBoss.UseTabs:=EditorOpts.BlockTabIndent>0;
 812  end;
 813
 814  if ctfActivateAbortMode in Flags then
 815    ActivateCodeToolAbortableMode;
 816
 817  Result:=true;
 818end;
 819
 820procedure TMainIDEBase.ActivateCodeToolAbortableMode;
 821begin
 822  if ToolStatus=itNone then
 823    RaiseException('TMainIDEBase.ActivateCodeToolAbortableMode Error 1');
 824  ToolStatus:=itCodeTools;
 825  CodeToolBoss.OnCheckAbort:=@OnCodeToolBossCheckAbort;
 826  CodeToolBoss.Abortable:=true;
 827end;
 828
 829function TMainIDEBase.OnCodeToolBossCheckAbort: boolean;
 830begin
 831  Result:=true;
 832  if ToolStatus<>itCodeTools then exit;
 833  Application.ProcessMessages;
 834  Result:=ToolStatus<>itCodeTools;
 835end;
 836
 837procedure TMainIDEBase.DoMergeDefaultProjectOptions(AProject: TProject);
 838var
 839  AFilename: String;
 840  ShortFilename: String;
 841begin
 842  // load default project options if exists
 843  AFilename:=AppendPathDelim(GetPrimaryConfigPath)+DefaultProjectOptionsFilename;
 844  if not FileExistsUTF8(AFilename) then
 845    CopySecondaryConfigFile(DefaultProjectOptionsFilename);
 846  if FileExistsUTF8(AFilename) then
 847    if AProject.ReadProject(AFilename,nil,False)<>mrOk then
 848      DebugLn(['TMainIDEBase.DoLoadDefaultCompilerOptions failed']);
 849
 850  // change target file name
 851  AFilename:=ExtractFileName(AProject.CompilerOptions.TargetFilename);
 852  if AFilename='' then
 853    exit; // using default -> ok
 854  if CompareFilenames(AFilename,ExtractFilename(AProject.ProjectInfoFile))=0
 855  then exit; // target file name and project name fit -> ok
 856
 857  // change target file to project name
 858  ShortFilename:=ExtractFileNameOnly(AProject.ProjectInfoFile);
 859  if ShortFilename<>'' then
 860    AProject.CompilerOptions.TargetFilename:=
 861      ExtractFilePath(AProject.CompilerOptions.TargetFilename)
 862        +ShortFilename+ExtractFileExt(AFilename);
 863  AProject.CompilerOptions.Modified:=false;
 864end;
 865
 866procedure TMainIDEBase.DoSwitchToFormSrc(var ActiveSourceEditor: TSourceEditor;
 867  var ActiveUnitInfo: TUnitInfo);
 868begin
 869  DoSwitchToFormSrc(nil,ActiveSourceEditor,ActiveUnitInfo);
 870end;
 871
 872procedure TMainIDEBase.DoSwitchToFormSrc(ADesigner: TIDesigner;
 873  var ActiveSourceEditor: TSourceEditor; var ActiveUnitInfo: TUnitInfo);
 874begin
 875  if (ADesigner<>nil) then
 876    ActiveUnitInfo:=Project1.UnitWithComponent(ADesigner.LookupRoot)
 877  else if (GlobalDesignHook.LookupRoot<>nil)
 878  and (GlobalDesignHook.LookupRoot is TComponent) then
 879    ActiveUnitInfo:=Project1.UnitWithComponent(TComponent(GlobalDesignHook.LookupRoot))
 880  else
 881    ActiveUnitInfo:=nil;
 882  if (ActiveUnitInfo<>nil) and (ActiveUnitInfo.OpenEditorInfoCount > 0) then begin
 883    ActiveSourceEditor := TSourceEditor(ActiveUnitInfo.OpenEditorInfo[0].EditorComponent);
 884    SourceEditorManagerIntf.ActiveEditor := ActiveSourceEditor;
 885  end
 886  else
 887    ActiveSourceEditor:=nil;
 888end;
 889
 890procedure TMainIDEBase.DoMnuWindowClicked(Sender: TObject);
 891begin
 892  UpdateWindowMenu;
 893end;
 894
 895procedure TMainIDEBase.SetDisplayState(AValue: TDisplayState);
 896begin
 897  if FDisplayState=AValue then Exit;
 898  FDisplayState:=AValue;
 899  {$IFDEF VerboseIDEDisplayState}
 900  debugln(['TMainIDEBase.SetDisplayState ',dbgs(DisplayState)]);
 901  {$ENDIF}
 902end;
 903
 904function TMainIDEBase.CreateMenuSeparator : TMenuItem;
 905begin
 906  Result := TMenuItem.Create(MainIDEBar);
 907  Result.Caption := '-';
 908end;
 909
 910procedure TMainIDEBase.CreateMenuItem(Section: TIDEMenuSection;
 911  var MenuCommand: TIDEMenuCommand; const MenuItemName, MenuItemCaption: String;
 912  const bmpName: String; mnuEnabled: Boolean; mnuChecked: Boolean;
 913  mnuVisible: Boolean);
 914begin
 915  MenuCommand:=RegisterIDEMenuCommand(Section,MenuItemName,MenuItemCaption);
 916  MenuCommand.Enabled:=mnuEnabled;
 917  MenuCommand.Checked:=mnuChecked;
 918  MenuCommand.Visible:=mnuVisible;
 919  if bmpName<>'' then
 920    MenuCommand.ImageIndex := IDEImages.LoadImage(16, bmpName);
 921end;
 922
 923procedure TMainIDEBase.CreateMenuSeparatorSection(
 924  ParentSection: TIDEMenuSection; var Section: TIDEMenuSection;
 925  const AName: String);
 926begin
 927  Section:=RegisterIDEMenuSection(ParentSection,AName);
 928  Section.ChildrenAsSubMenu := false;
 929end;
 930
 931procedure TMainIDEBase.CreateMenuSubSection(ParentSection: TIDEMenuSection;
 932  var Section: TIDEMenuSection; const AName, ACaption: String;
 933  const bmpName: String = '');
 934begin
 935  Section:=RegisterIDESubMenu(ParentSection,AName,ACaption);
 936  if bmpName<>'' then
 937    Section.ImageIndex := IDEImages.LoadImage(16, bmpName);
 938end;
 939
 940procedure TMainIDEBase.CreateMainMenuItem(var Section: TIDEMenuSection;
 941  const MenuItemName, MenuItemCaption: String);
 942begin
 943  Section:=RegisterIDESubMenu(mnuMain,MenuItemName,MenuItemCaption);
 944end;
 945
 946procedure TMainIDEBase.SetupMainMenu;
 947begin
 948  MainIDEBar.mnuMainMenu := TMainMenu.Create(MainIDEBar);
 949  MainIDEBar.mnuMainMenu.Images := IDEImages.Images_16;
 950  with MainIDEBar do begin
 951    mnuMain:=RegisterIDEMenuRoot('IDEMainMenu',nil);
 952    {$ifdef LCLCarbon}
 953    // Under Apple there is a special policy: every application should create
 954    // a special Apple menu and put Quit, About there.
 955    // See issue: http://bugs.freepascal.org/view.php?id=12294
 956    // See http://lists.apple.com/archives/carbon-development/2002/Apr/msg01183.html, for details
 957    //CreateMainMenuItem(mnuApple,'AppleApplication','');
 958    {$endif}
 959    CreateMainMenuItem(mnuFile,'File',lisMenuFile);
 960    CreateMainMenuItem(mnuEdit,'Edit',lisMenuEdit);
 961    CreateMainMenuItem(mnuSearch,'Search',lisMenuSearch);
 962    CreateMainMenuItem(mnuView,'View',lisMenuView);
 963    CreateMainMenuItem(mnuSource,'Source',lisMenuSource);
 964    CreateMainMenuItem(mnuProject,'Project',lisMenuProject);
 965    CreateMainMenuItem(mnuRun,'Run',lisMenuRun);
 966    CreateMainMenuItem(mnuPackage,'Package',lisMenuPackage);
 967    mnuComponent:=mnuPackage;
 968    CreateMainMenuItem(mnuTools,'Tools',lisMenuTools);
 969    CreateMainMenuItem(mnuWindow,'Window',lisMenuWindow);
 970    mnuWindow.OnClick  := @DoMnuWindowClicked;
 971    CreateMainMenuItem(mnuHelp,'Help',lisMenuHelp);
 972  end;
 973end;
 974
 975procedure TMainIDEBase.SetupFileMenu;
 976var
 977  ParentMI: TIDEMenuSection;
 978begin
 979  with MainIDEBar do begin
 980    CreateMenuSeparatorSection(mnuFile,itmFileNew,'itmFileNew');
 981    ParentMI:=itmFileNew;
 982    CreateMenuItem(ParentMI,itmFileNewUnit,'itmFileNewUnit',lisMenuNewUnit,'item_unit');
 983    CreateMenuItem(ParentMI,itmFileNewForm,'itmFileNewForm',lisMenuNewForm,'item_form');
 984    CreateMenuItem(ParentMI,itmFileNewOther,'itmFileNewOther',lisMenuNewOther,'menu_new');
 985
 986    CreateMenuSeparatorSection(mnuFile,itmFileOpenSave,'itmFileOpenSave');
 987    ParentMI:=itmFileOpenSave;
 988    CreateMenuItem(ParentMI, itmFileOpen, 'itmFileOpen', lisMenuOpen, 'laz_open');
 989    CreateMenuItem(ParentMI,itmFileRevert,'itmFileRevert',lisMenuRevert, 'menu_file_revert');
 990    CreateMenuItem(ParentMI, itmFileOpenUnit, 'itmFileOpenUnit', lisMenuOpenUnit, 'laz_openunit');
 991    CreateMenuSubSection(ParentMI,itmFileRecentOpen,'itmFileRecentOpen',lisMenuOpenRecent);
 992    CreateMenuItem(ParentMI,itmFileSave,'itmFileSave',lisMenuSave,'laz_save');
 993    CreateMenuItem(ParentMI,itmFileSaveAs,'itmFileSaveAs',lisMenuSaveAs,'menu_saveas');
 994    CreateMenuItem(ParentMI,itmFileSaveAll,'itmFileSaveAll',lisSaveAll,'menu_save_all');
 995    CreateMenuItem(ParentMI,itmFileExportHtml,'itmFileExportHtml',lisExportHtml);
 996    CreateMenuItem(ParentMI,itmFileClose,'itmFileClose',lisMenuCloseEditorFile,'menu_close',false);
 997    CreateMenuItem(ParentMI,itmFileCloseAll,'itmFileCloseAll',lisMenuCloseAll,'menu_close_all',false);
 998
 999    CreateMenuSeparatorSection(mnuFile,itmFileDirectories,'itmFileDirectories');
1000    ParentMI:=itmFileDirectories;
1001    CreateMenuItem(ParentMI,itmFileCleanDirectory,'itmFileCleanDirectory',lisMenuCleanDirectory, 'menu_clean');
1002
1003    CreateMenuSeparatorSection(mnuFile,itmFileIDEStart,'itmFileIDEStart');
1004    ParentMI:=itmFileIDEStart;
1005    CreateMenuItem(ParentMI,itmFileRestart,'itmFileRestart',lisRestart, 'laz_refresh');
1006    CreateMenuItem(ParentMI,itmFileQuit,'itmFileQuit',lisBtnQuit, 'menu_exit');
1007  end;
1008end;
1009
1010procedure TMainIDEBase.SetupEditMenu;
1011var
1012  ParentMI: TIDEMenuSection;
1013begin
1014  with MainIDEBar do begin
1015    CreateMenuSeparatorSection(mnuEdit,itmEditReUndo,'itmEditReUndo');
1016    ParentMI:=itmEditReUndo;
1017    CreateMenuItem(ParentMI,itmEditUndo,'itmEditUndo',lisUndo,'menu_undo');
1018    CreateMenuItem(ParentMI,itmEditRedo,'itmEditRedo',lisRedo,'menu_redo');
1019
1020    CreateMenuSeparatorSection(mnuEdit,itmEditClipboard,'itmEditClipboard');
1021    ParentMI:=itmEditClipboard;
1022    CreateMenuItem(ParentMI,itmEditCut,'itmEditCut',lisCut,'laz_cut');
1023    CreateMenuItem(ParentMI,itmEditCopy,'itmEditCopy',lisCopy,'laz_copy');
1024    CreateMenuItem(ParentMI,itmEditPaste,'itmEditPaste',lisPaste,'laz_paste');
1025
1026    // "Select" menu items
1027    CreateMenuSeparatorSection(mnuEdit,itmEditSelect,'itmEditSelect');
1028    ParentMI:=itmEditSelect;
1029    CreateMenuItem(ParentMI,itmEditSelectAll,'itmEditSelectAll',lisMenuSelectAll, 'menu_select_all');
1030    CreateMenuItem(ParentMI,itmEditSelectToBrace,'itmEditSelectToBrace',lisMenuSelectToBrace);
1031    CreateMenuItem(ParentMI,itmEditSelectCodeBlock,'itmEditSelectCodeBlock',lisMenuSelectCodeBlock);
1032    CreateMenuItem(ParentMI,itmEditSelectWord,'itmEditSelectWord',lisMenuSelectWord);
1033    CreateMenuItem(ParentMI,itmEditSelectLine,'itmEditSelectLine',lisMenuSelectLine);
1034    CreateMenuItem(ParentMI,itmEditSelectParagraph,'itmEditSelectParagraph',lisMenuSelectParagraph);
1035
1036    // "Char Conversion" menu items
1037    CreateMenuSeparatorSection(mnuEdit,itmEditBlockActions,'itmEditBlockActions');
1038    ParentMI:=itmEditBlockActions;
1039    CreateMenuItem(ParentMI,itmEditIndentBlock,'itmEditIndentBlock',lisMenuIndentSelection,'menu_indent');
1040    CreateMenuItem(ParentMI,itmEditUnindentBlock,'itmEditUnindentBlock',lisMenuUnindentSelection,'menu_unindent');
1041    CreateMenuItem(ParentMI,itmEditUpperCaseBlock,'itmEditUpperCaseBlock',lisMenuUpperCaseSelection, 'menu_edit_uppercase');
1042    CreateMenuItem(ParentMI,itmEditLowerCaseBlock,'itmEditLowerCaseBlock',lisMenuLowerCaseSelection, 'menu_edit_lowercase');
1043    CreateMenuItem(ParentMI,itmEditSwapCaseBlock,'itmEditSwapCaseBlock',lisMenuSwapCaseSelection, 'menu_edit_uppercase');
1044    CreateMenuItem(ParentMI,itmEditSortBlock,'itmEditSortBlock',lisMenuSortSelection, 'menu_edit_sort');
1045    CreateMenuItem(ParentMI,itmEditTabsToSpacesBlock,'itmEditTabsToSpacesBlock',lisMenuTabsToSpacesSelection);
1046    CreateMenuItem(ParentMI,itmEditSelectionBreakLines,'itmEditSelectionBreakLines',lisMenuBeakLinesInSelection);
1047
1048    // *** insert text ***:
1049    CreateMenuSeparatorSection(mnuEdit,itmEditInsertions,'itmEditInsertions');
1050    ParentMI:=itmEditInsertions;
1051    CreateMenuItem(ParentMI,itmEditInsertCharacter,'itmEditInsertCharacter',lisMenuInsertCharacter);
1052  end;
1053end;
1054
1055procedure TMainIDEBase.SetupSearchMenu;
1056var
1057  ParentMI: TIDEMenuSection;
1058begin
1059  with MainIDEBar do begin
1060    CreateMenuSeparatorSection(mnuSearch,itmSearchFindReplace,'itmSearchFindReplace');
1061    ParentMI:=itmSearchFindReplace;
1062
1063    CreateMenuItem(ParentMI,itmSearchFind, 'itmSearchFind', lisMenuFind2, 'menu_search_find');
1064    CreateMenuItem(ParentMI,itmSearchFindNext,'itmSearchFindNext',lisMenuFindNext, 'menu_search_find_next');
1065    CreateMenuItem(ParentMI,itmSearchFindPrevious,'itmSearchFindPrevious',lisMenuFindPrevious, 'menu_search_find_previous');
1066    CreateMenuItem(ParentMI,itmSearchFindInFiles,'itmSearchFindInFiles',lisMenuFindInFiles, 'menu_search_files');
1067    CreateMenuItem(ParentMI, itmSearchReplace, 'itmSearchReplace', lisBtnDlgReplace, 'menu_search_replace');
1068    CreateMenuItem(ParentMI,itmIncrementalFind,'itmIncrementalFind',lisMenuIncrementalFind, 'menu_search_incremental');
1069
1070    CreateMenuSeparatorSection(mnuSearch,itmJumpings,'itmJumpings');
1071    ParentMI:=itmJumpings;
1072
1073    CreateMenuItem(ParentMI,itmGotoLine,'itmGotoLine',lisMenuGotoLine, 'menu_goto_line');
1074    CreateMenuItem(ParentMI,itmJumpBack,'itmJumpBack',lisMenuJumpBack, 'menu_search_jumpback');
1075    CreateMenuItem(ParentMI,itmJumpForward,'itmJumpForward',lisMenuJumpForward, 'menu_search_jumpforward');
1076    CreateMenuItem(ParentMI,itmAddJumpPoint,'itmAddJumpPoint',lisMenuAddJumpPointToHistory);
1077    CreateMenuItem(ParentMI,itmJumpToNextError,'itmJumpToNextError',lisMenuJumpToNextError);
1078    CreateMenuItem(ParentMI,itmJumpToPrevError,'itmJumpToPrevError',lisMenuJumpToPrevError);
1079
1080    CreateMenuSubSection(ParentMI,itmJumpToSection,'itmJumpToSection',lisMenuJumpTo);
1081    ParentMI:=itmJumpToSection;
1082
1083    CreateMenuItem(ParentMI,itmJumpToInterface,'itmJumpToInterface',lisMenuJumpToInterface, 'menu_jumpto_interface');
1084    CreateMenuItem(ParentMI,itmJumpToInterfaceUses,'itmJumpToInterfaceUses',lisMenuJumpToInterfaceUses, 'menu_jumpto_interfaceuses');
1085    CreateMenuItem(ParentMI,itmJumpToImplementation,'itmJumpToImplementation',lisMenuJumpToImplementation, 'menu_jumpto_implementation');
1086    CreateMenuItem(ParentMI,itmJumpToImplementationUses,'itmJumpToImplementationUses',lisMenuJumpToImplementationUses, 'menu_jumpto_implementationuses');
1087    CreateMenuItem(ParentMI,itmJumpToInitialization,'itmJumpToInitialization',lisMenuJumpToInitialization, 'menu_jumpto_initialization');
1088
1089    CreateMenuSeparatorSection(mnuSearch,itmBookmarks,'itmBookmarks');
1090    ParentMI:=itmBookmarks;
1091
1092    CreateMenuItem(ParentMI,itmSetFreeBookmark,'itmSetFreeBookmark',lisMenuSetFreeBookmark, 'menu_search_set_bookmark');
1093    CreateMenuItem(ParentMI,itmJumpToNextBookmark,'itmJumpToNextBookmark',lisMenuJumpToNextBookmark, 'menu_search_next_bookmark');
1094    CreateMenuItem(ParentMI,itmJumpToPrevBookmark,'itmJumpToPrevBookmark',lisMenuJumpToPrevBookmark, 'menu_search_previous_bookmark');
1095
1096    CreateMenuSeparatorSection(mnuSearch,itmCodeToolSearches,'itmCodeToolSearches');
1097    ParentMI:=itmCodeToolSearches;
1098
1099    CreateMenuItem(ParentMI,itmFindBlockOtherEnd,'itmFindBlockOtherEnd',lisMenuFindBlockOtherEndOfCodeBlock);
1100    CreateMenuItem(ParentMI,itmFindBlockStart,'itmFindBlockStart',lisMenuFindCodeBlockStart);
1101    CreateMenuItem(ParentMI,itmFindDeclaration,'itmFindDeclaration',lisMenuFindDeclarationAtCursor);
1102    CreateMenuItem(ParentMI,itmOpenFileAtCursor,'itmOpenFileAtCursor',lisMenuOpenFilenameAtCursor,'menu_search_openfile_atcursor');
1103    CreateMenuItem(ParentMI,itmGotoIncludeDirective,'itmGotoIncludeDirective',lisMenuGotoIncludeDirective);
1104    CreateMenuItem(ParentMI,itmSearchFindIdentifierRefs,'itmSearchFindIdentifierRefs',lisMenuFindIdentifierRefs);
1105    CreateMenuItem(ParentMI,itmSearchProcedureList,'itmSearchProcedureList',lisMenuProcedureList);
1106  end;
1107end;
1108
1109procedure TMainIDEBase.SetupViewMenu;
1110var
1111  ParentMI: TIDEMenuSection;
1112begin
1113  with MainIDEBar do begin
1114    CreateMenuSeparatorSection(mnuView,itmViewMainWindows,'itmViewMainWindows');
1115    ParentMI:=itmViewMainWindows;
1116    CreateMenuItem(ParentMI,itmViewToggleFormUnit,'itmViewToggleFormUnit',lisMenuViewToggleFormUnit, 'menu_view_toggle_form_unit');
1117    CreateMenuItem(ParentMI,itmViewInspector,'itmViewInspector',lisMenuViewObjectInspector, 'menu_view_inspector');
1118    CreateMenuItem(ParentMI,itmViewSourceEditor,'itmViewSourceEditor',lisMenuViewSourceEditor, 'menu_view_source_editor');
1119    CreateMenuItem(ParentMI,itmViewMessage,'itmViewMessage',lisMenuViewMessages);
1120    CreateMenuItem(ParentMI,itmViewCodeExplorer,'itmViewCodeExplorer',lisMenuViewCodeExplorer, 'menu_view_code_explorer');
1121    CreateMenuItem(ParentMI,itmViewFPDocEditor,'itmViewFPDocEditor',lisFPDocEditor);
1122    CreateMenuItem(ParentMI,itmViewCodeBrowser,'itmViewCodeBrowser',lisMenuViewCodeBrowser, 'menu_view_code_browser');
1123    CreateMenuItem(ParentMI,itmSourceUnitDependencies,'itmSourceUnitDependencies',lisMenuViewUnitDependencies);
1124    CreateMenuItem(ParentMI,itmViewRestrictionBrowser,'itmViewRestrictionBrowser',lisMenuViewRestrictionBrowser, 'menu_view_rectriction_browser');
1125    CreateMenuItem(ParentMI,itmViewComponents,'itmViewComponents',lisMenuViewComponents);
1126    CreateMenuItem(ParentMI,itmJumpHistory,'itmJumpHistory',lisMenuViewJumpHistory);
1127    CreateMenuItem(ParentMI,itmMacroListView,'itmMacroListView',lisMenuMacroListView);
1128
1129    CreateMenuSeparatorSection(mnuView,itmViewDesignerWindows,'itmViewDesignerWindows');
1130    ParentMI:=itmViewDesignerWindows;
1131    CreateMenuItem(ParentMI,itmViewAnchorEditor,'itmViewAnchorEditor',lisMenuViewAnchorEditor,'menu_view_anchor_editor');
1132    CreateMenuItem(ParentMI,itmViewTabOrder,'itmViewTabOrder',lisMenuViewTabOrder,'tab_order');
1133
1134    CreateMenuSeparatorSection(mnuView,itmViewSecondaryWindows,'itmViewSecondaryWindows');
1135    ParentMI:=itmViewSecondaryWindows;
1136    CreateMenuItem(ParentMI,itmViewSearchResults,'itmViewSearchResults',lisMenuViewSearchResults);
1137    CreateMenuSubSection(ParentMI,itmViewDebugWindows,'itmViewDebugWindows',lisMenuDebugWindows,'debugger');
1138    begin
1139      CreateMenuItem(itmViewDebugWindows,itmViewWatches,'itmViewWatches',lisMenuViewWatches,'debugger_watches');
1140      CreateMenuItem(itmViewDebugWindows,itmViewBreakPoints,'itmViewBreakPoints',lisMenuViewBreakPoints,'debugger_breakpoints');
1141      CreateMenuItem(itmViewDebugWindows,itmViewLocals,'itmViewLocals',lisMenuViewLocalVariables);
1142      if HasConsoleSupport then
1143        CreateMenuItem(itmViewDebugWindows,itmViewPseudoTerminal,'itmViewPseudoTerminal',lisMenuViewPseudoTerminal)
1144      else
1145        itmViewPseudoTerminal := nil;
1146      CreateMenuItem(itmViewDebugWindows,itmViewRegisters,'itmViewRegisters',lisMenuViewRegisters);
1147      CreateMenuItem(itmViewDebugWindows,itmViewCallStack,'itmViewCallStack',lisMenuViewCallStack,'debugger_call_stack');
1148      CreateMenuItem(itmViewDebugWindows,itmViewThreads,'itmViewThreads',lisMenuViewThreads);
1149      CreateMenuItem(itmViewDebugWindows,itmViewAssembler,'itmViewAssembler',lisMenuViewAssembler);
1150      CreateMenuItem(itmViewDebugWindows,itmViewDebugEvents,'itmViewDebugEvents',lisMenuViewDebugEvents,'debugger_event_log');
1151      CreateMenuItem(itmViewDebugWindows,itmViewDebugOutput,'itmViewDebugOutput',lisMenuViewDebugOutput,'debugger_output');
1152      CreateMenuItem(itmViewDebugWindows,itmViewDbgHistory,'itmViewDbgHistory',lisMenuViewHistory);
1153    end;
1154    CreateMenuSubSection(ParentMI, itmViewIDEInternalsWindows, 'itmViewIDEInternalsWindows', lisMenuIDEInternals);
1155    begin
1156      CreateMenuItem(itmViewIDEInternalsWindows, itmViewFPCInfo, 'itmViewFPCInfo', lisMenuAboutFPC);
1157      CreateMenuItem(itmViewIDEInternalsWindows, itmViewIDEInfo, 'itmViewIDEInfo', lisAboutIDE);
1158      CreateMenuItem(itmViewIDEInternalsWindows, itmViewNeedBuild, 'itmViewNeedBuild', lisMenuWhatNeedsBuilding);
1159      {$IFDEF EnableFPDocSearch}
1160      CreateMenuItem(itmViewIDEInternalsWindows, itmSearchInFPDocFiles,'itmSearchInFPDocFiles','Search in FPDoc files');
1161      {$ENDIF}
1162    end;
1163  end;
1164end;
1165
1166procedure TMainIDEBase.SetupSourceMenu;
1167var
1168  ParentMI, SubParentMI: TIDEMenuSection;
1169begin
1170  with MainIDEBar do begin
1171    CreateMenuSeparatorSection(mnuSource,itmSourceBlockActions,'itmSourceBlockActions');
1172    ParentMI:=itmSourceBlockActions;
1173    CreateMenuItem(ParentMI,itmSourceCommentBlock,'itmSourceCommentBlock',lisMenuCommentSelection, 'menu_comment');
1174    CreateMenuItem(ParentMI,itmSourceUncommentBlock,'itmSourceUncommentBlock',lisMenuUncommentSelection, 'menu_uncomment');
1175    CreateMenuItem(ParentMI,itmSourceToggleComment,'itmSourceToggleComment',lisMenuToggleComment, 'menu_comment');
1176    CreateMenuItem(ParentMI,itmSourceEncloseBlock,'itmSourceEncloseBlock',lisMenuEncloseSelection);
1177    CreateMenuItem(ParentMI,itmSourceEncloseInIFDEF,'itmSourceEncloseInIFDEF',lisMenuEncloseInIFDEF);
1178    CreateMenuItem(ParentMI,itmSourceCompleteCodeInteractive,'itmSourceCompleteCodeInteractive',lisMenuCompleteCodeInteractive);
1179    CreateMenuItem(ParentMI,itmRefactorInvertAssignment,'itmInvertAssignment',uemInvertAssignment);
1180    CreateMenuItem(ParentMI,itmSourceUseUnit,'itmSourceUseUnit',lisMenuUseUnit);
1181    // Refactor
1182    CreateMenuSeparatorSection(mnuSource,itmSourceRefactor,'itmSourceRefactor');
1183    CreateMenuSubSection(ParentMI,itmSourceRefactor,'itmSourceRefactor',uemRefactor);
1184    SubParentMI:=itmSourceRefactor;
1185      CreateMenuSeparatorSection(SubParentMI,itmRefactorCodeTools,'itmRefactorCodeTools');
1186      ParentMI:=itmRefactorCodeTools;
1187      CreateMenuItem(ParentMI,itmRefactorRenameIdentifier,'itmRefactorRenameIdentifier',lisMenuRenameIdentifier);
1188      CreateMenuItem(ParentMI,itmRefactorExtractProc,'itmRefactorExtractProc',lisMenuExtractProc);
1189
1190      CreateMenuSeparatorSection(SubParentMI,itmRefactorAdvanced,'itmRefactorAdvanced');
1191      ParentMI:=itmRefactorAdvanced;
1192      CreateMenuItem(ParentMI,itmRefactorShowAbstractMethods,'itmShowAbstractMethods',srkmecAbstractMethods);
1193      CreateMenuItem(ParentMI,itmRefactorShowEmptyMethods,'itmShowEmptyMethods',srkmecEmptyMethods);
1194      CreateMenuItem(ParentMI,itmRefactorShowUnusedUnits,'itmShowUnusedUnits',srkmecUnusedUnits);
1195      {$IFDEF EnableFindOverloads}
1196      CreateMenuItem(ParentMI,itmRefactorFindOverloads,'itmFindOverloads',srkmecFindOverloadsCapt);
1197      {$ENDIF}
1198
1199      CreateMenuSeparatorSection(SubParentMI,itmRefactorTools,'itmRefactorTools');
1200      ParentMI:=itmRefactorTools;
1201      CreateMenuItem(ParentMI,itmRefactorMakeResourceString,'itmRefactorMakeResourceString',
1202                     lisMenuMakeResourceString,'menu_tool_make_resourcestring');
1203    // CodeToolChecks
1204    CreateMenuSeparatorSection(mnuSource,itmSourceCodeToolChecks,'itmSourceCodeToolChecks');
1205    ParentMI:=itmSourceCodeToolChecks;
1206    CreateMenuItem(ParentMI,itmSourceSyntaxCheck,'itmSourceSyntaxCheck',lisMenuQuickSyntaxCheck, 'menu_tool_syntax_check');
1207    CreateMenuItem(ParentMI,itmSourceGuessUnclosedBlock,'itmSourceGuessUnclosedBlock',lisMenuGuessUnclosedBlock);
1208    CreateMenuItem(ParentMI,itmSourceGuessMisplacedIFDEF,'itmSourceGuessMisplacedIFDEF',lisMenuGuessMisplacedIFDEF);
1209
1210    CreateMenuSeparatorSection(mnuSource,itmSourceInsertions,'itmSourceInsertions');
1211    ParentMI:=itmSourceInsertions;
1212    // *** insert text ***:
1213    CreateMenuSubSection(ParentMI,itmSourceInsertCVSKeyWord,'itmSourceInsertCVSKeyWord',lisMenuInsertCVSKeyword);
1214    SubParentMI:=itmSourceInsertCVSKeyWord;
1215      // insert CVS keyword sub menu items
1216      CreateMenuItem(SubParentMI,itmSourceInsertCVSAuthor,'itmSourceInsertCVSAuthor','Author');
1217      CreateMenuItem(SubParentMI,itmSourceInsertCVSDate,'itmSourceInsertCVSDate','Date');
1218      CreateMenuItem(SubParentMI,itmSourceInsertCVSHeader,'itmSourceInsertCVSHeader','Header');
1219      CreateMenuItem(SubParentMI,itmSourceInsertCVSID,'itmSourceInsertCVSID','ID');
1220      CreateMenuItem(SubParentMI,itmSourceInsertCVSLog,'itmSourceInsertCVSLog','Log');
1221      CreateMenuItem(SubParentMI,itmSourceInsertCVSName,'itmSourceInsertCVSName','Name');
1222      CreateMenuItem(SubParentMI,itmSourceInsertCVSRevision,'itmSourceInsertCVSRevision','Revision');
1223      CreateMenuItem(SubParentMI,itmSourceInsertCVSSource,'itmSourceInsertCVSSource','Source');
1224
1225    CreateMenuSubSection(ParentMI,itmSourceInsertGeneral,'itmSourceInsertGeneral',lisMenuInsertGeneral);
1226    SubParentMI:=itmSourceInsertGeneral;
1227      // insert general text sub menu items
1228      CreateMenuItem(SubParentMI,itmSourceInsertGPLNotice,'itmSourceInsertGPLNotice',lisMenuInsertGPLNotice);
1229      CreateMenuItem(SubParentMI,itmSourceInsertGPLNoticeTranslated,'itmSourceInsertGPLNoticeTranslated',lisMenuInsertGPLNoticeTranslated);
1230      CreateMenuItem(SubParentMI,itmSourceInsertLGPLNotice,'itmSourceInsertLGPLNotice',lisMenuInsertLGPLNotice);
1231      CreateMenuItem(SubParentMI,itmSourceInsertLGPLNoticeTranslated,'itmSourceInsertLGPLNoticeTranslated',lisMenuInsertLGPLNoticeTranslated);
1232      CreateMenuItem(SubParentMI,itmSourceInsertModifiedLGPLNotice,'itmSourceInsertModifiedLGPLNotice',lisMenuInsertModifiedLGPLNotice);
1233      CreateMenuItem(SubParentMI,itmSourceInsertModifiedLGPLNoticeTranslated,'itmSourceInsertModifiedLGPLNoticeTranslated',lisMenuInsertModifiedLGPLNoticeTranslated);
1234      CreateMenuItem(SubParentMI,itmSourceInsertMITNotice,'itmSourceInsertMITNotice',lisMenuInsertMITNotice);
1235      CreateMenuItem(SubParentMI,itmSourceInsertMITNoticeTranslated,'itmSourceInsertMITNoticeTranslated',lisMenuInsertMITNoticeTranslated);
1236      CreateMenuItem(SubParentMI,itmSourceInsertUsername,'itmSourceInsertUsername',lisMenuInsertUsername);
1237      CreateMenuItem(SubParentMI,itmSourceInsertDateTime,'itmSourceInsertDateTime',lisMenuInsertDateTime);
1238      CreateMenuItem(SubParentMI,itmSourceInsertChangeLogEntry,'itmSourceInsertChangeLogEntry',lisMenuInsertChangeLogEntry);
1239      CreateMenuItem(SubParentMI,itmSourceInsertGUID,'itmSourceInsertGUID',srkmecInsertGUID);
1240
1241    CreateMenuItem(itmSourceInsertions,itmSourceInsertFilename,'itmSourceInsertFilename',lisMenuInsertFilename);
1242
1243    CreateMenuSeparatorSection(mnuSource,itmSourceTools,'itmSourceTools');
1244    ParentMI:=itmSourceTools;
1245    CreateMenuItem(ParentMI,itmSourceUnitInfo,'itmViewUnitInfo',lisMenuViewUnitInfo, 'menu_view_unit_info');
1246  end;
1247end;
1248
1249procedure TMainIDEBase.SetupProjectMenu;
1250var
1251  ParentMI: TIDEMenuSection;
1252begin
1253  with MainIDEBar do begin
1254    CreateMenuSeparatorSection(mnuProject,itmProjectNewSection,'itmProjectNewSection');
1255    ParentMI:=itmProjectNewSection;
1256    CreateMenuItem(ParentMI,itmProjectNew,'itmProjectNew',lisMenuNewProject, 'item_project');
1257    CreateMenuItem(ParentMI,itmProjectNewFromFile,'itmProjectNewFromFile',lisMenuNewProjectFromFile, 'menu_project_from_file');
1258
1259    CreateMenuSeparatorSection(mnuProject,itmProjectOpenSection,'itmProjectOpenSection');
1260    ParentMI:=itmProjectOpenSection;
1261    CreateMenuItem(ParentMI,itmProjectOpen,'itmProjectOpen',lisMenuOpenProject,'menu_project_open');
1262    CreateMenuSubSection(ParentMI,itmProjectRecentOpen,'itmProjectRecentOpen',lisMenuOpenRecentProject);
1263    CreateMenuItem(ParentMI,itmProjectClose,'itmProjectClose',lisMenuCloseProject, 'menu_project_close');
1264
1265    CreateMenuSeparatorSection(mnuProject,itmProjectSaveSection,'itmProjectSaveSection');
1266    ParentMI:=itmProjectSaveSection;
1267    CreateMenuItem(ParentMI,itmProjectSave,'itmProjectSave',lisMenuSaveProject, 'menu_project_save');
1268    CreateMenuItem(ParentMI,itmProjectSaveAs,'itmProjectSaveAs',lisMenuSaveProjectAs, 'menu_project_saveas');
1269    CreateMenuItem(ParentMI, itmProjectResaveFormsWithI18n, 'itmProjectResaveFo'
1270      +'rmsWithI18n', lisMenuResaveFormsWithI18n);
1271    CreateMenuItem(ParentMI,itmProjectPublish,'itmProjectPublish',lisMenuPublishProject);
1272
1273    CreateMenuSeparatorSection(mnuProject,itmProjectWindowSection,'itmProjectWindowSection');
1274    ParentMI:=itmProjectWindowSection;
1275    CreateMenuItem(ParentMI,itmProjectInspector,'itmProjectInspector',lisMenuProjectInspector+' ...','menu_project_inspector');
1276    CreateMenuItem(ParentMI,itmProjectOptions,'itmProjectOptions',lisMenuProjectOptions,'menu_project_options');
1277
1278    CreateMenuSeparatorSection(mnuProject,itmProjectAddRemoveSection,'itmProjectAddRemoveSection');
1279    ParentMI:=itmProjectAddRemoveSection;
1280    CreateMenuItem(ParentMI,itmProjectAddTo,'itmProjectAddTo',lisMenuAddToProject, 'menu_project_add');
1281    CreateMenuItem(ParentMI,itmProjectRemoveFrom,'itmProjectRemoveFrom',lisMenuRemoveFromProject, 'menu_project_remove');
1282    CreateMenuItem(ParentMI,itmProjectViewUnits,'itmProjectViewUnits',lisMenuViewUnits, 'menu_view_units');
1283    CreateMenuItem(ParentMI,itmProjectViewForms,'itmProjectViewForms',lisMenuViewForms, 'menu_view_forms');
1284    CreateMenuItem(ParentMI,itmProjectViewSource,'itmProjectViewSource',lisMenuViewProjectSource, 'menu_project_viewsource');
1285  end;
1286end;
1287
1288procedure TMainIDEBase.SetupRunMenu;
1289var
1290  ParentMI: TIDEMenuSection;
1291begin
1292  with MainIDEBar do begin
1293    CreateMenuSeparatorSection(mnuRun,itmRunBuilding,'itmRunBuilding');
1294    ParentMI:=itmRunBuilding;
1295    CreateMenuItem(ParentMI,itmRunMenuCompile,'itmRunMenuCompile',lisCompile,'menu_build');
1296    CreateMenuItem(ParentMI,itmRunMenuBuild,'itmRunMenuBuild',lisBuild,'menu_build_all');
1297    CreateMenuItem(ParentMI,itmRunMenuQuickCompile,'itmRunMenuQuickCompile',lisMenuQuickCompile,'menu_quick_compile');
1298    CreateMenuItem(ParentMI,itmRunMenuCleanUpAndBuild,'itmRunMenuCleanUpAndBuild',lisMenuCleanUpAndBuild,'menu_build');
1299    CreateMenuItem(ParentMI,itmRunMenuBuildManyModes,'itmRunMenuBuildManyModes',lisMenuCompileManyModes,'menu_build_all');
1300    CreateMenuItem(ParentMI,itmRunMenuAbortBuild,'itmRunMenuAbortBuild',lisMenuAbortBuild,'menu_abort_build');
1301
1302    CreateMenuSeparatorSection(mnuRun,itmRunnning,'itmRunnning');
1303    ParentMI:=itmRunnning;
1304    CreateMenuItem(ParentMI,itmRunMenuRunWithoutDebugging,'itmRunMenuRunWithoutDebugging',lisMenuRunWithoutDebugging,'menu_run_withoutdebugging');
1305    CreateMenuItem(ParentMI,itmRunMenuRun,'itmRunMenuRun',lisMenuProjectRun,'menu_run');
1306    CreateMenuItem(ParentMI,itmRunMenuPause,'itmRunMenuPause',lisPause,'menu_pause', False);
1307    CreateMenuItem(ParentMI,itmRunMenuShowExecutionPoint,'itmRunMenuShowExecutionPoint',
1308                   lisMenuShowExecutionPoint,'debugger_show_execution_point', False);
1309    CreateMenuItem(ParentMI,itmRunMenuStepInto,'itmRunMenuStepInto',lisMenuStepInto,'menu_stepinto');
1310    CreateMenuItem(ParentMI,itmRunMenuStepOver,'itmRunMenuStepOver',lisMenuStepOver,'menu_stepover');
1311    CreateMenuItem(ParentMI,itmRunMenuStepOut,'itmRunMenuStepOut',lisMenuStepOut,'menu_stepout');
1312    CreateMenuItem(ParentMI,itmRunMenuRunToCursor,'itmRunMenuRunToCursor',lisMenuRunToCursor,'menu_run_cursor');
1313    CreateMenuItem(ParentMI,itmRunMenuStop,'itmRunMenuStop',lisStop,'menu_stop', False);
1314
1315    CreateMenuItem(ParentMI,itmRunMenuAttach,'itmRunMenuAttach',srkmecAttach+' ...','', False);
1316    CreateMenuItem(ParentMI,itmRunMenuDetach,'itmRunMenuDetach',srkmecDetach,'', False);
1317
1318    CreateMenuItem(ParentMI,itmRunMenuRunParameters,'itmRunMenuRunParameters',lisMenuRunParameters, 'menu_run_parameters');
1319    CreateMenuItem(ParentMI,itmRunMenuResetDebugger,'itmRunMenuResetDebugger',lisMenuResetDebugger, 'menu_reset_debugger');
1320
1321    CreateMenuSeparatorSection(mnuRun,itmRunBuildingFile,'itmRunBuildingFile');
1322    ParentMI:=itmRunBuildingFile;
1323    CreateMenuItem(ParentMI,itmRunMenuBuildFile,'itmRunMenuBuildFile',lisMenuBuildFile, 'menu_build_file');
1324    CreateMenuItem(ParentMI,itmRunMenuRunFile,'itmRunMenuRunFile',lisMenuRunFile,'menu_run_file');
1325    CreateMenuItem(ParentMI,itmRunMenuConfigBuildFile,'itmRunMenuConfigBuildFile',lisMenuConfigBuildFile, 'menu_build_run_file');
1326
1327    CreateMenuSeparatorSection(mnuRun,itmRunDebugging,'itmRunDebugging');
1328    ParentMI:=itmRunDebugging;
1329    CreateMenuItem(ParentMI,itmRunMenuInspect,'itmRunMenuInspect',lisMenuInspect, 'debugger_inspect', False);
1330    CreateMenuItem(ParentMI,itmRunMenuEvaluate,'itmRunMenuEvaluate',lisMenuEvaluate, 'debugger_modify', False);
1331    CreateMenuItem(ParentMI,itmRunMenuAddWatch,'itmRunMenuAddWatch',lisMenuAddWatch, '', False);
1332    CreateMenuSubSection(ParentMI,itmRunMenuAddBreakpoint,'itmRunMenuAddBreakpoint',lisMenuAddBreakpoint, '');
1333    CreateMenuItem(itmRunMenuAddBreakpoint,itmRunMenuAddBPSource,'itmRunMenuAdddBPSource',lisSourceBreakpoint, '', False);
1334    CreateMenuItem(itmRunMenuAddBreakpoint,itmRunMenuAddBPAddress,'itmRunMenuAddBPAddress',lisAddressBreakpoint, '', False);
1335    CreateMenuItem(itmRunMenuAddBreakpoint,itmRunMenuAddBpWatchPoint,'itmRunMenuAddBpWatchPoint',lisWatchPointBreakpoint, '', False);
1336  end;
1337end;
1338
1339procedure TMainIDEBase.SetupPackageMenu;
1340var
1341  ParentMI: TIDEMenuSection;
1342begin
1343  with MainIDEBar do begin
1344    CreateMenuSeparatorSection(mnuComponent,itmPkgOpening,'itmPkgOpening');
1345    ParentMI:=itmPkgOpening;
1346    CreateMenuItem(ParentMI,itmPkgNewPackage,'itmPkgNewPackage',lisMenuNewPackage);
1347    CreateMenuItem(ParentMI,itmPkgOpenLoadedPackage,'itmPkgOpenPackage',lisMenuOpenPackage,'pkg_installed');
1348    CreateMenuItem(ParentMI,itmPkgOpenPackageFile,'itmPkgOpenPackageFile',lisMenuOpenPackageFile,'pkg_open');
1349    CreateMenuItem(ParentMI,itmPkgOpenPackageOfCurUnit,'itmPkgOpenPackageOfCurUnit',lisMenuOpenPackageOfCurUnit);
1350    CreateMenuSubSection(ParentMI,itmPkgOpenRecent,'itmPkgOpenRecent',lisMenuOpenRecentPkg);
1351
1352    CreateMenuSeparatorSection(mnuComponent,itmPkgUnits,'itmPkgUnits');
1353    ParentMI:=itmPkgUnits;
1354    CreateMenuItem(ParentMI,itmPkgAddCurFileToPkg,'itmPkgAddCurFileToPkg',lisMenuAddCurFileToPkg,'pkg_add');
1355    CreateMenuItem(ParentMI, itmPkgAddNewComponentToPkg, 'itmPkgAddNewComponentToPkg', lisMenuNewComponent+' ...', 'pkg_add');
1356
1357    CreateMenuSeparatorSection(mnuComponent,itmPkgGraphSection,'itmPkgGraphSection');
1358    ParentMI:=itmPkgGraphSection;
1359    CreateMenuItem(ParentMI,itmPkgPkgGraph,'itmPkgPkgGraph',lisMenuPackageGraph+' ...','pkg_graph');
1360    CreateMenuItem(ParentMI,itmPkgPackageLinks,'itmPkgPackageLinks',lisMenuPackageLinks);
1361    CreateMenuItem(ParentMI,itmPkgEditInstallPkgs,'itmPkgEditInstallPkgs',lisMenuEditInstallPkgs,'pkg_properties');
1362
1363    {$IFDEF CustomIDEComps}
1364    CreateMenuItem(ParentMI,itmCompsConfigCustomComps,'itmCompsConfigCustomComps',lisMenuConfigCustomComps);
1365    {$ENDIF}
1366  end;
1367end;
1368
1369procedure TMainIDEBase.SetupToolsMenu;
1370var
1371  ParentMI: TIDEMenuSection;
1372begin
1373  with MainIDEBar do begin
1374    CreateMenuSeparatorSection(mnuTools,itmOptionsDialogs,'itmOptionsDialogs');
1375    ParentMI:=itmOptionsDialogs;
1376    CreateMenuItem(ParentMI,itmEnvGeneralOptions,'itmEnvGeneralOptions',
1377                   lisMenuGeneralOptions,'menu_environment_options');
1378    CreateMenuItem(ParentMI,itmToolRescanFPCSrcDir,'itmToolRescanFPCSrcDir',
1379                   lisMenuRescanFPCSourceDirectory);
1380    CreateMenuItem(ParentMI,itmEnvCodeTemplates,'itmEnvCodeTemplates',lisMenuEditCodeTemplates,'');
1381    CreateMenuItem(ParentMI,itmEnvCodeToolsDefinesEditor,'itmEnvCodeToolsDefinesEditor',
1382                   lisMenuCodeToolsDefinesEditor,'menu_codetoolsdefineseditor');
1383
1384    CreateMenuSeparatorSection(mnuTools,itmCustomTools,'itmCustomTools');
1385    ParentMI:=itmCustomTools;
1386    CreateMenuItem(ParentMI,itmToolConfigure,'itmToolConfigure',lisMenuConfigExternalTools);
1387
1388    CreateMenuSeparatorSection(mnuTools,itmSecondaryTools,'itmSecondaryTools');
1389    ParentMI:=itmSecondaryTools;
1390    CreateMenuItem(ParentMI,itmToolManageDesktops,'itmToolManageDesktops', lisDesktops, 'menu_manage_desktops');
1391    CreateMenuItem(ParentMI,itmToolManageExamples,'itmToolManageExamples',lisMenuExampleProjects, 'camera');
1392    CreateMenuItem(ParentMI,itmToolDiff,'itmToolDiff',lisMenuCompareFiles, 'menu_tool_diff');
1393
1394    CreateMenuSeparatorSection(mnuTools,itmConversion,'itmConversion');
1395    ParentMI:=itmConversion;
1396    CreateMenuItem(ParentMI,itmToolConvertEncoding,'itmToolConvertEncoding',lisMenuConvertEncoding);
1397    CreateMenuItem(ParentMI,itmToolCheckLFM,'itmToolCheckLFM',lisMenuCheckLFM, 'menu_tool_check_lfm');
1398
1399    CreateMenuSubSection(mnuTools,itmDelphiConversion,'itmDelphiConversion',lisMenuDelphiConversion,'menu_tool_dfm_to_lfm');
1400    ParentMI:=itmDelphiConversion;
1401    CreateMenuItem(ParentMI,itmToolConvertDelphiUnit,'itmToolConvertDelphiUnit',lisMenuConvertDelphiUnit,'menu_tool_dfm_to_lfm');
1402    CreateMenuItem(ParentMI,itmToolConvertDelphiProject,'itmToolConvertDelphiProject',lisMenuConvertDelphiProject,'menu_tool_dfm_to_lfm');
1403    CreateMenuItem(ParentMI,itmToolConvertDelphiPackage,'itmToolConvertDelphiPackage',lisMenuConvertDelphiPackage,'menu_tool_dfm_to_lfm');
1404    CreateMenuItem(ParentMI,itmToolConvertDFMtoLFM,'itmToolConvertDFMtoLFM',lisMenuConvertDFMtoLFM,'menu_tool_dfm_to_lfm');
1405
1406    CreateMenuSeparatorSection(mnuTools,itmBuildingLazarus,'itmBuildingLazarus');
1407    ParentMI:=itmBuildingLazarus;
1408    CreateMenuItem(ParentMI,itmToolBuildLazarus,'itmToolBuildLazarus',lisMenuBuildLazarus,'menu_build_lazarus');
1409    CreateMenuItem(ParentMI,itmToolConfigureBuildLazarus,'itmToolConfigureBuildLazarus',
1410                   lisMenuConfigureBuildLazarus, 'menu_configure_build_lazarus');
1411  end;
1412end;
1413
1414procedure TMainIDEBase.SetupWindowsMenu;
1415var
1416  ParentMI: TIDEMenuSection;
1417begin
1418  with MainIDEBar do begin
1419    CreateMenuSeparatorSection(mnuWindow,itmWindowManagers,'itmWindowManagers');
1420    ParentMI:=itmWindowManagers;
1421    CreateMenuItem(ParentMI,itmWindowManager,'itmWindowManager', lisManageSourceEditors, 'pkg_files');
1422    // Populated later with a list of editor names
1423    CreateMenuSeparatorSection(mnuWindow,itmWindowLists,'itmWindowLists');
1424    CreateMenuSeparatorSection(mnuWindow,itmCenterWindowLists,'itmCenterWindowLists');
1425    itmCenterWindowLists.ChildrenAsSubMenu:=true;
1426    itmCenterWindowLists.Caption:=lisCenterALostWindow;
1427    CreateMenuSeparatorSection(mnuWindow,itmTabLists,'itmTabLists');
1428    CreateMenuSubSection(itmTabLists,itmTabListProject,'itmTabListProject', dlgEnvProject);
1429    CreateMenuSeparatorSection(itmTabLists, itmTabListPackage, 'itmTabListPackage');
1430    CreateMenuSubSection(itmTabLists,itmTabListOther,'itmTabListOther', lisMEOther);
1431  end;
1432end;
1433
1434procedure TMainIDEBase.SetupHelpMenu;
1435var
1436  ParentMI: TIDEMenuSection;
1437begin
1438  with MainIDEBar do begin
1439    CreateMenuSeparatorSection(mnuHelp,itmOnlineHelps,'itmOnlineHelps');
1440    ParentMI:=itmOnlineHelps;
1441
1442    CreateMenuItem(ParentMI,itmHelpOnlineHelp,'itmHelpOnlineHelp',
1443                   lisMenuOnlineHelp, 'menu_help');
1444    CreateMenuItem(ParentMI,itmHelpReportingBug,'itmHelpReportingBug',
1445                   lisMenuReportingBug, 'menu_reportingbug');
1446
1447    // old behavior restored, until Tiger issue is fixed.
1448    // http://bugs.freepascal.org/view.php?id=14411
1449    (*
1450   {$ifdef LCLCarbon}
1451    // under Carbon: add About item to the Apple menu
1452    CreateMenuItem(mnuApple, itmHelpAboutLazarus,'itmHelpAboutLazarus',
1453                   lisAboutLazarus, 'menu_information');
1454    
1455    CreateMenuSeparatorSection(mnuHelp,itmInfoHelps,'itmInfoHelps');
1456    {$else}*)
1457    // otherwise: add About item to the Help menu
1458    CreateMenuSeparatorSection(mnuHelp,itmInfoHelps,'itmInfoHelps');
1459    ParentMI:=itmInfoHelps;
1460    CreateMenuItem(ParentMI,itmHelpAboutLazarus,'itmHelpAboutLazarus',
1461                 lisAboutLazarus, 'menu_information');
1462    //{$endif}
1463
1464    CreateMenuSeparatorSection(mnuHelp,itmHelpTools,'itmHelpTools');
1465    ParentMI:=itmHelpTools;
1466  end;
1467end;
1468
1469procedure TMainIDEBase.LoadMenuShortCuts;
1470
1471  function GetCmdAndBtn(ACommand: word; out ToolButton: TIDEButtonCommand): TIDECommand;
1472  begin
1473    Result:=IDECommandList.FindIDECommand(ACommand);
1474    if Result<>nil then
1475      ToolButton := RegisterIDEButtonCommand(Result)
1476    else
1477      ToolButton := nil;
1478  end;
1479
1480  function GetCommand(ACommand: word): TIDECommand;
1481  var
1482    ToolButton: TIDEButtonCommand;
1483  begin
1484    Result:=GetCmdAndBtn(ACommand, ToolButton);
1485  end;
1486
1487  function GetCommand(ACommand: word; ToolButtonClass: TIDEToolButtonClass): TIDECommand;
1488  var
1489    ToolButton: TIDEButtonCommand;
1490  begin
1491    Result:=GetCmdAndBtn(ACommand, ToolButton);
1492    if ToolButton<>nil then
1493      ToolButton.ToolButtonClass := ToolButtonClass;
1494  end;
1495
1496var
1497  xBtnItem: TIDEButtonCommand;
1498begin
1499  with MainIDEBar do begin
1500    // file menu
1501    itmFileNewUnit.Command:=GetCommand(ecNewUnit, TNewUnitToolButton);
1502    itmFileNewForm.Command:=GetCommand(ecNewForm, TNewFormToolButton);
1503    itmFileNewOther.Command:=GetCommand(ecNew);
1504    itmFileOpen.Command:=GetCommand(ecOpen, TOpenFileToolButton);
1505    itmFileOpenUnit.Command:=GetCommand(ecOpenUnit);
1506    itmFileRevert.Command:=GetCommand(ecRevert);
1507    itmFileSave.Command:=GetCommand(ecSave);
1508    itmFileSaveAs.Command:=GetCommand(ecSaveAs);
1509    itmFileSaveAll.Command:=GetCommand(ecSaveAll);
1510    itmFileClose.Command:=GetCommand(ecClose);
1511    itmFileCloseAll.Command:=GetCommand(ecCloseAll);
1512    itmFileCleanDirectory.Command:=GetCommand(ecCleanDirectory);
1513    itmFileQuit.Command:=GetCommand(ecQuit);
1514
1515    // edit menu
1516    itmEditUndo.Command:=GetCommand(ecUndo);
1517    itmEditRedo.Command:=GetCommand(ecRedo);
1518    itmEditCut.Command:=GetCommand(ecCut);
1519    itmEditCopy.Command:=GetCommand(ecCopy);
1520    itmEditPaste.Command:=GetCommand(ecPaste);
1521
1522    itmEditSelectAll.Command:=GetCommand(ecSelectAll);
1523    itmEditSelectToBrace.Command:=GetCommand(ecSelectToBrace);
1524    itmEditSelectCodeBlock.Command:=GetCommand(ecSelectCodeBlock);
1525    itmEditSelectWord.Command:=GetCommand(ecSelectWord);
1526    itmEditSelectLine.Command:=GetCommand(ecSelectLine);
1527    itmEditSelectParagraph.Command:=GetCommand(ecSelectParagraph);
1528
1529    itmEditIndentBlock.Command:=GetCommand(ecBlockIndent);
1530    itmEditUnindentBlock.Command:=GetCommand(ecBlockUnindent);
1531    itmEditUpperCaseBlock.Command:=GetCommand(ecSelectionUpperCase);
1532    itmEditLowerCaseBlock.Command:=GetCommand(ecSelectionLowerCase);
1533    itmEditSwapCaseBlock.Command:=GetCommand(ecSelectionSwapCase);
1534    itmEditSortBlock.Command:=GetCommand(ecSelectionSort);
1535    itmEditTabsToSpacesBlock.Command:=GetCommand(ecSelectionTabs2Spaces);
1536    itmEditSelectionBreakLines.Command:=GetCommand(ecSelectionBreakLines);
1537
1538    itmEditInsertCharacter.Command:=GetCommand(ecInsertCharacter);
1539
1540    // search menu
1541    itmSearchFind.Command:=GetCommand(ecFind);
1542    itmSearchFindNext.Command:=GetCommand(ecFindNext);
1543    itmSearchFindPrevious.Command:=GetCommand(ecFindPrevious);
1544    itmSearchFindInFiles.Command:=GetCommand(ecFindInFiles);
1545    itmSearchFindIdentifierRefs.Command:=GetCommand(ecFindIdentifierRefs);
1546    itmSearchReplace.Command:=GetCommand(ecReplace);
1547    itmIncrementalFind.Command:=GetCommand(ecIncrementalFind);
1548    itmGotoLine.Command:=GetCommand(ecGotoLineNumber);
1549    itmJumpBack.Command:=GetCommand(ecJumpBack);
1550    itmJumpForward.Command:=GetCommand(ecJumpForward);
1551    itmAddJumpPoint.Command:=GetCommand(ecAddJumpPoint);
1552    itmJumpToNextError.Command:=GetCommand(ecJumpToNextError);
1553    itmJumpToPrevError.Command:=GetCommand(ecJumpToPrevError);
1554    itmSetFreeBookmark.Command:=GetCommand(ecSetFreeBookmark);
1555    itmJumpToNextBookmark.Command:=GetCommand(ecNextBookmark);
1556    itmJumpToPrevBookmark.Command:=GetCommand(ecPrevBookmark);
1557    itmJumpToInterface.Command:=GetCommand(ecJumpToInterface, TJumpToSectionToolButton);
1558    itmJumpToInterfaceUses.Command:=GetCommand(ecJumpToInterfaceUses, TJumpToSectionToolButton);
1559    itmJumpToImplementation.Command:=GetCommand(ecJumpToImplementation, TJumpToSectionToolButton);
1560    itmJumpToImplementationUses.Command:=GetCommand(ecJumpToImplementationUses, TJumpToSectionToolButton);
1561    itmJumpToInitialization.Command:=GetCommand(ecJumpToInitialization, TJumpToSectionToolButton);
1562    GetCmdAndBtn(ecJumpToProcedureHeader, xBtnItem);
1563    xBtnItem.Caption := lisMenuJumpToProcedureHeader;
1564    xBtnItem.OnClick := @SourceEditorManager.JumpToProcedureHeaderClicked;
1565    xBtnItem.ImageIndex := IDEImages.LoadImage(16, 'menu_jumpto_procedureheader');
1566    GetCmdAndBtn(ecJumpToProcedureBegin, xBtnItem);
1567    xBtnItem.Caption := lisMenuJumpToProcedureBegin;
1568    xBtnItem.ImageIndex := IDEImages.LoadImage(16, 'menu_jumpto_procedurebegin');
1569    xBtnItem.OnClick := @SourceEditorManager.JumpToProcedureBeginClicked;
1570    itmFindBlockOtherEnd.Command:=GetCommand(ecFindBlockOtherEnd);
1571    itmFindBlockStart.Command:=GetCommand(ecFindBlockStart);
1572    itmFindDeclaration.Command:=GetCommand(ecFindDeclaration);
1573    itmOpenFileAtCursor.Command:=GetCommand(ecOpenFileAtCursor);
1574    itmGotoIncludeDirective.Command:=GetCommand(ecGotoIncludeDirective);
1575    itmSearchProcedureList.Command:=GetCommand(ecProcedureList);
1576
1577    // view menu
1578    itmViewToggleFormUnit.Command:=GetCommand(ecToggleFormUnit);
1579    itmViewInspector.Command:=GetCommand(ecToggleObjectInsp);
1580    itmViewSourceEditor.Command:=GetCommand(ecToggleSourceEditor);
1581    itmViewCodeExplorer.Command:=GetCommand(ecToggleCodeExpl);
1582    itmViewFPDocEditor.Command:=GetCommand(ecToggleFPDocEditor);
1583    itmViewCodeBrowser.Command:=GetCommand(ecToggleCodeBrowser);
1584    itmViewRestrictionBrowser.Command:=GetCommand(ecToggleRestrictionBrowser);
1585    itmViewComponents.Command:=GetCommand(ecViewComponents);
1586    itmMacroListView.Command:=GetCommand(ecViewMacroList);
1587    itmJumpHistory.Command:=GetCommand(ecViewJumpHistory);
1588    itmViewMessage.Command:=GetCommand(ecToggleMessages);
1589    itmViewSearchResults.Command:=GetCommand(ecToggleSearchResults);
1590    itmViewAnchorEditor.Command:=GetCommand(ecViewAnchorEditor);
1591    itmViewTabOrder.Command:=GetCommand(ecViewTabOrder);
1592    //itmPkgPackageLinks.Command:=GetCommand(ec?);
1593
1594    // source menu
1595    itmSourceCommentBlock.Command:=GetCommand(ecSelectionComment);
1596    itmSourceUncommentBlock.Command:=GetCommand(ecSelectionUncomment);
1597    itmSourceToggleComment.Command:=GetCommand(ecToggleComment);
1598    itmSourceEncloseBlock.Command:=GetCommand(ecSelectionEnclose);
1599    itmSourceEncloseInIFDEF.Command:=GetCommand(ecSelectionEncloseIFDEF);
1600    itmSourceCompleteCodeInteractive.Command:=GetCommand(ecCompleteCodeInteractive);
1601    itmSourceUseUnit.Command:=GetCommand(ecUseUnit);
1602
1603    itmSourceSyntaxCheck.Command:=GetCommand(ecSyntaxCheck);
1604    itmSourceGuessUnclosedBlock.Command:=GetCommand(ecGuessUnclosedBlock);
1605    itmSourceGuessMisplacedIFDEF.Command:=GetCommand(ecGuessMisplacedIFDEF);
1606
1607    itmSourceInsertCVSAuthor.Command:=GetCommand(ecInsertCVSAuthor);
1608    itmSourceInsertCVSDate.Command:=GetCommand(ecInsertCVSDate);
1609    itmSourceInsertCVSHeader.Command:=GetCommand(ecInsertCVSHeader);
1610    itmSourceInsertCVSID.Command:=GetCommand(ecInsertCVSID);
1611    itmSourceInsertCVSLog.Command:=GetCommand(ecInsertCVSLog);
1612    itmSourceInsertCVSName.Command:=GetCommand(ecInsertCVSName);
1613    itmSourceInsertCVSRevision.Command:=GetCommand(ecInsertCVSRevision);
1614    itmSourceInsertCVSSource.Command:=GetCommand(ecInsertCVSSource);
1615
1616    itmSourceInsertGPLNotice.Command:=GetCommand(ecInsertGPLNotice);
1617    itmSourceInsertGPLNoticeTranslated.Command:=GetCommand(ecInsertGPLNoticeTranslated);
1618    itmSourceInsertLGPLNotice.Command:=GetCommand(ecInsertLGPLNotice);
1619    itmSourceInsertLGPLNoticeTranslated.Command:=GetCommand(ecInsertLGPLNoticeTranslated);
1620    itmSourceInsertModifiedLGPLNotice.Command:=GetCommand(ecInsertModifiedLGPLNotice);
1621    itmSourceInsertModifiedLGPLNoticeTranslated.Command:=GetCommand(ecInsertModifiedLGPLNoticeTranslated);
1622    itmSourceInsertMITNotice.Command:=GetCommand(ecInsertMITNotice);
1623    itmSourceInsertMITNoticeTranslated.Command:=GetCommand(ecInsertMITNoticeTranslated);
1624    itmSourceInsertUsername.Command:=GetCommand(ecInsertUserName);
1625    itmSourceInsertDateTime.Command:=GetCommand(ecInsertDateTime);
1626    itmSourceInsertChangeLogEntry.Command:=GetCommand(ecInsertChangeLogEntry);
1627    itmSourceInsertGUID.Command:=GetCommand(ecInsertGUID);
1628    itmSourceInsertFilename.Command:=GetCommand(ecInsertFilename);
1629
1630    itmSourceUnitInfo.Command:=GetCommand(ecViewUnitInfo);
1631    itmSourceUnitDependencies.Command:=GetCommand(ecViewUnitDependencies);
1632
1633    // refactor menu
1634    itmRefactorRenameIdentifier.Command:=GetCommand(ecRenameIdentifier);
1635    itmRefactorExtractProc.Command:=GetCommand(ecExtractProc);
1636    itmRefactorInvertAssignment.Command:=GetCommand(ecInvertAssignment);
1637
1638    itmRefactorShowAbstractMethods.Command:=GetCommand(ecShowAbstractMethods);
1639    itmRefactorShowEmptyMethods.Command:=GetCommand(ecRemoveEmptyMethods);
1640    itmRefactorShowUnusedUnits.Command:=GetCommand(ecRemoveUnusedUnits);
1641    {$IFDEF EnableFindOverloads}
1642    itmRefactorFindOverloads.Command:=GetCommand(ecFindOverloads);
1643    {$ENDIF}
1644    itmRefactorMakeResourceString.Command:=GetCommand(ecMakeResourceString);
1645
1646    // project menu
1647    itmProjectNew.Command:=GetCommand(ecNewProject);
1648    itmProjectNewFromFile.Command:=GetCommand(ecNewProjectFromFile);
1649    itmProjectOpen.Command:=GetCommand(ecOpenProject);
1650    itmProjectClose.Command:=GetCommand(ecCloseProject);
1651    itmProjectSave.Command:=GetCommand(ecSaveProject);
1652    itmProjectSaveAs.Command:=GetCommand(ecSaveProjectAs);
1653    itmProjectResaveFormsWithI18n.Command:=GetCommand(ecProjectResaveFormsWithI18n);
1654    itmProjectPublish.Command:=GetCommand(ecPublishProject);
1655    itmProjectInspector.Command:=GetCommand(ecProjectInspector);
1656    itmProjectOptions.Command:=GetCommand(ecProjectOptions);
1657    itmProjectAddTo.Command:=GetCommand(ecAddCurUnitToProj);
1658    itmProjectRemoveFrom.Command:=GetCommand(ecRemoveFromProj);
1659    itmProjectViewUnits.Command:=GetCommand(ecViewProjectUnits);
1660    itmProjectViewForms.Command:=GetCommand(ecViewProjectForms);
1661    itmProjectViewSource.Command:=GetCommand(ecViewProjectSource);
1662    GetCmdAndBtn(ecProjectChangeBuildMode, xBtnItem);
1663    xBtnItem.Caption := lisChangeBuildMode;
1664    xBtnItem.ToolButtonClass:=TSetBuildModeToolButton;
1665    xBtnItem.ImageIndex := IDEImages.LoadImage(16, 'menu_compiler_options');
1666    xBtnItem.OnClick := @mnuBuildModeClicked;
1667
1668    // run menu
1669    itmRunMenuCompile.Command:=GetCommand(ecCompile);
1670    itmRunMenuBuild.Command:=GetCommand(ecBuild);
1671    itmRunMenuQuickCompile.Command:=GetCommand(ecQuickCompile);
1672    itmRunMenuCleanUpAndBuild.Command:=GetCommand(ecCleanUpAndBuild);
1673    itmRunMenuBuildManyModes.Command:=GetCommand(ecBuildManyModes);
1674    itmRunMenuAbortBuild.Command:=GetCommand(ecAbortBuild);
1675    itmRunMenuRunWithoutDebugging.Command:=GetCommand(ecRunWithoutDebugging);
1676    itmRunMenuRun.Command:=GetCommand(ecRun);
1677    itmRunMenuPause.Command:=GetCommand(ecPause);
1678    itmRunMenuStepInto.Command:=GetCommand(ecStepInto);
1679    itmRunMenuStepOver.Command:=GetCommand(ecStepOver);
1680    itmRunMenuStepOut.Command:=GetCommand(ecStepOut);
1681    itmRunMenuRunToCursor.Command:=GetCommand(ecRunToCursor);
1682    itmRunMenuStop.Command:=GetCommand(ecStopProgram);
1683    itmRunMenuAttach.Command:=GetCommand(ecAttach);
1684    itmRunMenuDetach.Command:=GetCommand(ecDetach);
1685    itmRunMenuResetDebugger.Command:=GetCommand(ecResetDebugger);
1686    itmRunMenuRunParameters.Command:=GetCommand(ecRunParameters);
1687    itmRunMenuBuildFile.Command:=GetCommand(ecBuildFile);
1688    itmRunMenuRunFile.Command:=GetCommand(ecRunFile);
1689    itmRunMenuConfigBuildFile.Command:=GetCommand(ecConfigBuildFile);
1690
1691    // package menu
1692    itmPkgNewPackage.Command:=GetCommand(ecNewPackage);
1693    itmPkgOpenLoadedPackage.Command:=GetCommand(ecOpenPackage);
1694    itmPkgOpenPackageFile.Command:=GetCommand(ecOpenPackageFile);
1695    itmPkgOpenPackageOfCurUnit.Command:=GetCommand(ecOpenPackageOfCurUnit);
1696    itmPkgAddCurFileToPkg.Command:=GetCommand(ecAddCurFileToPkg);
1697    itmPkgAddNewComponentToPkg.Command:=GetCommand(ecNewPkgComponent);
1698    itmPkgPkgGraph.Command:=GetCommand(ecPackageGraph);
1699    itmPkgPackageLinks.Command:=GetCommand(ecPackageLinks);
1700    itmPkgEditInstallPkgs.Command:=GetCommand(ecEditInstallPkgs);
1701    {$IFDEF CustomIDEComps}
1702    itmCompsConfigCustomComps.Command:=GetCommand(ecConfigCustomComps);
1703    {$ENDIF}
1704
1705    // tools menu
1706    itmEnvGeneralOptions.Command:=GetCommand(ecEnvironmentOptions);
1707    itmToolRescanFPCSrcDir.Command:=GetCommand(ecRescanFPCSrcDir);
1708    itmEnvCodeTemplates.Command:=GetCommand(ecEditCodeTemplates);
1709    itmEnvCodeToolsDefinesEditor.Command:=GetCommand(ecCodeToolsDefinesEd);
1710
1711    itmToolConfigure.Command:=GetCommand(ecExtToolSettings);
1712
1713    itmToolManageDesktops.Command:=GetCommand(ecManageDesktops, TShowDesktopsToolButton);
1714    itmToolManageExamples.Command:=GetCommand(ecManageExamples);
1715    itmToolDiff.Command:=GetCommand(ecDiff);
1716
1717    itmToolConvertDFMtoLFM.Command:=GetCommand(ecConvertDFM2LFM);
1718    itmToolCheckLFM.Command:=GetCommand(ecCheckLFM);
1719    itmToolConvertDelphiUnit.Command:=GetCommand(ecConvertDelphiUnit);
1720    itmToolConvertDelphiProject.Command:=GetCommand(ecConvertDelphiProject);
1721    itmToolConvertDelphiPackage.Command:=GetCommand(ecConvertDelphiPackage);
1722    itmToolConvertEncoding.Command:=GetCommand(ecConvertEncoding);
1723    itmToolBuildLazarus.Command:=GetCommand(ecBuildLazarus);
1724    itmToolConfigureBuildLazarus.Command:=GetCommand(ecConfigBuildLazarus);
1725
1726    // window menu
1727    itmWindowManager.Command:=GetCommand(ecManageSourceEditors);
1728
1729    // help menu
1730    itmHelpAboutLazarus.Command:=GetCommand(ecAboutLazarus);
1731    itmHelpOnlineHelp.Command:=GetCommand(ecOnlineHelp);
1732    itmHelpReportingBug.Command:=GetCommand(ecReportingBug);
1733  end;
1734end;
1735
1736function TMainIDEBase.DoOpenMacroFile(Sender: TObject; const AFilename: string
1737  ): TModalResult;
1738begin
1739  Result:=DoOpenEditorFile(AFilename,-1,-1,
1740                  [ofOnlyIfExists,ofAddToRecent,ofRegularFile,ofConvertMacros]);
1741end;
1742
1743procedure TMainIDEBase.UpdateWindowMenu;
1744
1745  function GetMenuItem(Index: Integer; ASection: TIDEMenuSection): TIDEMenuItem; inline;
1746  begin
1747    if ASection.Count > Index then
1748      Result := ASection.Items[Index]
1749    else
1750    begin
1751      Result := RegisterIDEMenuCommand(ASection.GetPath,'Window'+IntToStr(Index)+ASection.Name,'');
1752      Result.CreateMenuItem;
1753    end;
1754  end;
1755
1756  procedure ClearMenuItem(ARemainCount: Integer; ASection: TIDEMenuSection); inline;
1757  begin
1758    with ASection do
1759      while Count > ARemainCount do
1760        Items[Count-1].Free;
1761  end;
1762
1763var
1764  WindowsList: TFPList;
1765  i, j, ItemCount, ItemCountProject, ItemCountOther: Integer;
1766  CurMenuItem: TIDEMenuItem;
1767  AForm: TForm;
1768  EdList: TStringList;
1769  EditorCur: TSourceEditor;
1770  P: TIDEPackage;
1771  M: TIDEMenuSection;
1772  s: String;
1773begin
1774  //DebugLn('TMainIDEBase.UpdateWindowMenu: enter');
1775  WindowsList:=TFPList.Create;
1776  // add typical IDE windows at the start of the list
1777  for i := 0 to SourceEditorManager.SourceWindowCount - 1 do
1778    WindowsList.Add(SourceEditorManager.SourceWindows[i]);
1779  if (ObjectInspector1<>nil) and (ObjectInspector1.Visible) then
1780    WindowsList.Add(ObjectInspector1);
1781  // add special IDE windows
1782  for i:=0 to Screen.FormCount-1 do begin
1783    AForm:=Screen.Forms[i];
1784    //debugln(['TMainIDEBase.UpdateWindowMenu ',DbgSName(AForm),' Vis=',AForm.IsVisible,' Des=',DbgSName(AForm.Designer)]);
1785    if (not AForm.IsVisible) or (AForm=MainIDEBar) or (AForm=SplashForm)
1786    or IsFormDesign(AForm) or (WindowsList.IndexOf(AForm)>=0) then
1787      continue;
1788    if IDEDockMaster<>nil then
1789    begin
1790      if not IDEDockMaster.AddableInWindowMenu(AForm) then continue;
1791    end else begin
1792      if AForm.Parent<>nil then continue;
1793    end;
1794    WindowsList.Add(AForm);
1795  end;
1796  // add designer forms and datamodule forms
1797  for i:=0 to Screen.FormCount-1 do begin
1798    AForm:=Screen.Forms[i];
1799    if (AForm.Designer<>nil) and (WindowsList.IndexOf(AForm)<0) then
1800      WindowsList.Add(AForm);
1801  end;
1802  // create menuitems for all windows
1803  ItemCount := WindowsList.Count;
1804  for i:=0 to WindowsList.Count-1 do
1805  begin
1806    // in the 'bring to front' list
1807    CurMenuItem := GetMenuItem(i, itmWindowLists);
1808    if EnvironmentOptions.Desktop.IDENameForDesignedFormList
1809    and IsFormDesign(TWinControl(WindowsList[i])) then
1810      CurMenuItem.Caption:=TCustomForm(WindowsList[i]).Name
1811    else
1812       CurMenuItem.Caption:=TCustomForm(WindowsList[i]).Caption;
1813    CurMenuItem.MenuItem.Checked := WindowMenuActiveForm = TCustomForm(WindowsList[i]);
1814    CurMenuItem.OnClick:=@mnuWindowItemClick;
1815    // in the 'center' list
1816    CurMenuItem := GetMenuItem(i, itmCenterWindowLists);
1817    if EnvironmentOptions.Desktop.IDENameForDesignedFormList
1818    and IsFormDesign(TWinControl(WindowsList[i])) then
1819      CurMenuItem.Caption:=TCustomForm(WindowsList[i]).Name
1820    else
1821      CurMenuItem.Caption:=TCustomForm(WindowsList[i]).Caption;
1822    CurMenuItem.OnClick:=@mnuCenterWindowItemClick;
1823  end;
1824  //create source page menuitems
1825  itmTabListProject.Visible := False;
1826  itmTabListOther.Visible := False;
1827  itmTabListProject.MenuItem.Checked := False;
1828  itmTabListOther.MenuItem.Checked := False;
1829  itmTabListPackage.Clear;
1830
1831  if SourceEditorManager.SourceEditorCount > 0 then begin
1832    ItemCountProject := 0;
1833    ItemCountOther := 0;
1834    EdList := TStringList.Create;
1835    EdList.OwnsObjects := False;
1836    EdList.Sorted := True;
1837    // sort
1838    for i := 0 to SourceEditorManager.SourceEditorCount - 1 do begin
1839      EdList.AddObject(SourceEditorManager.SourceEditors[i].PageName+' '
1840                       +SourceEditorManager.SourceEditors[i].FileName
1841                       +SourceEditorManager.SourceEditors[i].Owner.Name,
1842                       TObject(PtrUInt(i))
1843                      );
1844    end;
1845    for i := 0 to EdList.Count - 1 do
1846    begin
1847      j := PtrUInt(EdList.Objects[i]);
1848      EditorCur := SourceEditorManager.SourceEditors[j];
1849      if (EditorCur.GetProjectFile <> nil) and (EditorCur.GetProjectFile.IsPartOfProject) then begin
1850        M := itmTabListProject;
1851        CurMenuItem := GetMenuItem(ItemCountProject, M);
1852        inc(ItemCountProject);
1853      end else begin
1854        SourceEditorManager.OnPackageForSourceEditor(P, EditorCur);
1855        if P <> nil then begin
1856          s := Format(lisTabsFor, [p.Name]);
1857          if itmTabListPackage.FindByName(S) is TIDEMenuSection then
1858            M := TIDEMenuSection(itmTabListPackage.FindByName(S))
1859          else
1860            M := RegisterIDESubMenu(itmTabListPackage, S, S);
1861          CurMenuItem := GetMenuItem(M.Count, M);
1862        end else begin
1863          M := itmTabListOther;
1864          CurMenuItem := GetMenuItem(ItemCountOther, M);
1865          inc(ItemCountOther);
1866        end;
1867      end;
1868      M.Visible := True;
1869      if EditorCur.SharedEditorCount > 1 then
1870        CurMenuItem.Caption := EditorCur.PageName + ' ('+TForm(EditorCur.Owner).Caption+')'
1871        //CurMenuItem.Caption := EditorCur.PageName
1872        //  + ' ('+IntToStr(1+SourceEditorManager.IndexOfSourceWindow(TSourceEditorWindowInterface(EditorCur.Owner)))+')'
1873      else
1874        CurMenuItem.Caption := EditorCur.PageName;
1875      if CurMenuItem.MenuItem <> nil then
1876        CurMenuItem.MenuItem.Checked := SourceEditorManager.ActiveEditor = EditorCur;
1877      if (SourceEditorManager.ActiveEditor = EditorCur) and (M.MenuItem <> nil) then
1878        M.MenuItem.Checked := true;
1879      CurMenuItem.OnClick := @mnuWindowSourceItemClick;
1880      CurMenuItem.Tag := j;
1881    end;
1882    EdList.Free;
1883    ClearMenuItem(ItemCountProject, itmTabListProject);
1884    ClearMenuItem(ItemCountOther, itmTabListOther);
1885    for i := 0 to itmTabListPackage.Count - 1 do begin
1886      if itmTabListPackage.Items[i] is TIDEMenuSection then begin
1887        M := itmTabListPackage.Items[i] as TIDEMenuSection;
1888        M.Caption := M.Caption +  Format(' (%d)', [M.Count]);
1889      end;
1890    end;
1891    itmTabListProject.Caption := dlgEnvProject +  Format(' (%d)', [itmTabListProject.Count]);
1892    itmTabListOther.Caption := lisMEOther +  Format(' (%d)', [itmTabListOther.Count]);
1893    if itmTabListPackage.TopSeparator <> nil then
1894      itmTabListPackage.TopSeparator.Visible := False;
1895    if itmTabListOther.TopSeparator <> nil then
1896      itmTabListOther.TopSeparator.Visible := False;
1897  end;
1898  // remove unused menuitems
1899  ClearMenuItem(ItemCount, itmWindowLists);
1900  ClearMenuItem(ItemCount, itmCenterWindowLists);
1901  WindowsList.Free;           // clean up
1902end;
1903
1904procedure TMainIDEBase.SetRecentSubMenu(Section: TIDEMenuSection;
1905  FileList: TStringList; OnClickEvent: TNotifyEvent);
1906var
1907  i: integer;
1908  AMenuItem: TIDEMenuItem;
1909begin
1910  // create enough menuitems
1911  while Section.Count<FileList.Count do begin
1912    AMenuItem:=RegisterIDEMenuCommand(Section.GetPath,
1913                              Section.Name+'Recent'+IntToStr(Section.Count),'');
1914  end;
1915  // delete unused menuitems
1916  while Section.Count>FileList.Count do
1917    Section.Items[Section.Count-1].Free;
1918  Section.Enabled:=(Section.Count>0);
1919  // set captions and event
1920  for i:=0 to FileList.Count-1 do begin
1921    AMenuItem:=Section.Items[i];
1922    AMenuItem.Caption := FileList[i];
1923    AMenuItem.OnClick := OnClickEvent;
1924  end;
1925end;
1926
1927procedure TMainIDEBase.UpdateHighlighters(Immediately: boolean = false);
1928var
1929  ASrcEdit: TSourceEditor;
1930  h: TLazSyntaxHighlighter;
1931  i: Integer;
1932  AnEditorInfo: TUnitEditorInfo;
1933begin
1934  if Immediately then begin
1935    FNeedUpdateHighlighters:=false;
1936    for h := Low(TLazSyntaxHighlighter) to High(TLazSyntaxHighlighter) do
1937      if Highlighters[h]<>nil then begin
1938        Highlighters[h].BeginUpdate;
1939        EditorOpts.GetHighlighterSettings(Highlighters[h]);
1940        Highlighters[h].EndUpdate;
1941      end;
1942    if Project1<>nil then begin
1943      for i := 0 to SourceEditorManager.SourceEditorCount - 1 do begin
1944        ASrcEdit := SourceEditorManager.SourceEditors[i];
1945        AnEditorInfo:=Project1.EditorInfoWithEditorComponent(ASrcEdit);
1946        if AnEditorInfo <> nil then
1947          ASrcEdit.SyntaxHighlighterType := AnEditorInfo.SyntaxHighlighter;
1948      end;
1949    end;
1950  end else begin
1951    FNeedUpdateHighlighters:=true;
1952  end;
1953end;
1954
1955procedure TMainIDEBase.FindInFilesPerDialog(AProject: TProject);
1956begin
1957  FindInFilesDialog.FindInFilesPerDialog(AProject);
1958end;
1959
1960procedure TMainIDEBase.FindInFiles(AProject: TProject; const FindText: string);
1961begin
1962  FindInFilesDialog.FindInFiles(AProject, FindText);
1963end;
1964
1965end.
1966
1967