PageRenderTime 82ms CodeModel.GetById 33ms app.highlight 21ms RepoModel.GetById 2ms app.codeStats 3ms

/ide/mainbase.pas

http://github.com/graemeg/lazarus
Pascal | 1967 lines | 1588 code | 217 blank | 162 comment | 105 complexity | f84a116ee812e1a9e5af3dc0acd87103 MD5 | raw file

Large files files are truncated, but you can click here to view the full 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'…

Large files files are truncated, but you can click here to view the full file