IDE: IDECommands refactoring; deleted menu item Project -> Change Build Mode

git-svn-id: trunk@50441 -
This commit is contained in:
ondrej 2015-11-20 14:04:24 +00:00
parent 25a0220972
commit b1ae15362f
8 changed files with 88 additions and 53 deletions

View File

@ -551,6 +551,7 @@ type
procedure SetEnabled(const AEnabled: Boolean);
procedure SetVisible(const AVisible: Boolean);
procedure SetCaption(const ACaption: string);
procedure SetHint(const AHint: string);
protected
function GetLocalizedName: string; virtual;
procedure SetLocalizedName(const AValue: string); virtual;
@ -586,6 +587,7 @@ type
property Enabled: Boolean write SetEnabled;
property Visible: Boolean write SetVisible;
property Caption: string write SetCaption;
property Hint: string write SetHint;
public
property Name: String read FName;
property Command: word read FCommand;// see the ecXXX constants above
@ -815,6 +817,7 @@ function CompareIDEShortCuts(Data1, Data2: Pointer): integer;
function CompareIDEShortCutKey1s(Data1, Data2: Pointer): integer;
function IdentToIDECommand(const Ident: string; var Cmd: longint): boolean;
function IDECommandToIdent(Cmd: longint; var Ident: string): boolean;
function IDECommandToIdent(Cmd: longint): string;
procedure GetIDEEditorCommandValues(Proc: TGetStrProc);
implementation
@ -1324,6 +1327,14 @@ begin
xUser.Enabled := AEnabled;
end;
procedure TIDECommand.SetHint(const AHint: string);
var
xUser: TIDESpecialCommand;
begin
for xUser in FUsers do
xUser.Hint := AHint;
end;
function TIDECommand.AsShortCut: TShortCut;
var
CurKey: TIDEShortCut;
@ -2189,6 +2200,13 @@ begin
Result := IntToIdent(Cmd, Ident, IDEEditorCommandStrs);
end;
function IDECommandToIdent(Cmd: longint): string;
begin
Result := '';
if not IDECommandToIdent(Cmd, Result) then
raise Exception.CreateFmt('IDECommandToIdent: command %d not found', [Cmd]);
end;
procedure GetIDEEditorCommandValues(Proc: TGetStrProc);
var
i: integer;

View File

@ -488,12 +488,6 @@ function TEditorKeymappingOptionsFrame.KeyMappingRelationToCaption(
KeyRelation: TKeyCommandRelation): String;
const
MaxLength = 60;
function AddBrakets(S: String): String;
begin
Result := '[' + S + ']';
end;
begin
with KeyRelation do
begin
@ -502,18 +496,7 @@ begin
Result := UTF8Copy(LocalizedName, 1, MaxLength)+'...';
if Result <> '' then
Result := Result + ' ';
if (ShortcutA.Key1 = VK_UNKNOWN) and (ShortcutB.Key1 = VK_UNKNOWN) then
Result := Result{ + lisNone2 }
else
if (ShortcutA.Key1 = VK_UNKNOWN) then
Result := Result + AddBrakets(KeyAndShiftStateToEditorKeyString(ShortcutB))
else
if (ShortcutB.Key1 = VK_UNKNOWN) then
Result := Result + AddBrakets(KeyAndShiftStateToEditorKeyString(ShortcutA))
else
Result := Result + AddBrakets(KeyAndShiftStateToEditorKeyString(ShortcutA))
+ ' '+lisOr+' ' +
AddBrakets(KeyAndShiftStateToEditorKeyString(ShortcutB));
Result := Result + KeyValuesToCaptionStr(ShortcutA, ShortcutB, '[');
end;
end;

View File

@ -273,16 +273,16 @@ begin
ToolBarOpts.Break := False;
with ToolBarOpts.ButtonNames do
begin
Add('IDEMainMenu/File/itmFileNew/itmFileNewForm');
Add('IDEMainMenu/File/itmFileNew/itmFileNewUnit');
Add('NewForm');
Add('NewUnit');
Add(cIDEToolbarDivider);
Add('IDEMainMenu/File/itmFileOpenSave/itmFileOpen');
Add('IDEMainMenu/File/itmFileOpenSave/itmFileSave');
Add('IDEMainMenu/File/itmFileOpenSave/itmFileSaveAll');
Add('Open');
Add('Save');
Add('SaveAll');
Add(cIDEToolbarDivider);
Add('IDEMainMenu/View/itmViewMainWindows/itmViewToggleFormUnit');
Add('Toggle between Unit and Form');
Add(cIDEToolbarDivider);
Add('IDEMainMenu/Tools/itmSecondaryTools/itmToolManageDesktops');
Add('Manage desktops');
end;
FToolBars.Add(ToolBarOpts);
@ -292,16 +292,16 @@ begin
ToolBarOpts.Break := True;
with ToolBarOpts.ButtonNames do
begin
Add('IDEMainMenu/Project/itmProjectAddRemoveSection/itmProjectViewUnits');
Add('IDEMainMenu/Project/itmProjectAddRemoveSection/itmProjectViewForms');
Add('View Units');
Add('View Forms');
Add(cIDEToolbarDivider);
Add('IDEMainMenu/Project/itmProjectAddRemoveSection/itmProjectBuildMode');
Add('IDEMainMenu/Run/itmRunnning/itmRunMenuRun');
Add('IDEMainMenu/Run/itmRunnning/itmRunMenuPause');
Add('IDEMainMenu/Run/itmRunnning/itmRunMenuStop');
Add('IDEMainMenu/Run/itmRunnning/itmRunMenuStepOver');
Add('IDEMainMenu/Run/itmRunnning/itmRunMenuStepInto');
Add('IDEMainMenu/Run/itmRunnning/itmRunMenuStepOut');
Add('Change build mode');
Add('Run program');
Add('Pause program');
Add('Stop program');
Add('Step over');
Add('Step into');
Add('Step out');
end;
FToolBars.Add(ToolBarOpts);
end;

View File

@ -218,6 +218,8 @@ function KeySchemeNameToSchemeType(const SchemeName: string): TKeyMapScheme;
function ShiftStateToCfgStr(Shift: TShiftState): string;
function KeyValuesToCfgStr(const ShortcutA, ShortcutB: TIDEShortCut): string;
function KeyValuesToCaptionStr(const ShortcutA, ShortcutB: TIDEShortCut;
Brackets: Char = '['): String;
function CfgStrToShiftState(const s: string): TShiftState;
function CompareLoadedKeyCommands(Data1, Data2: Pointer): integer;
@ -801,6 +803,35 @@ begin
end;
end;
function KeyValuesToCaptionStr(const ShortcutA, ShortcutB: TIDEShortCut;
Brackets: Char): String;
function AddBrakets(S: String): String;
begin
if Brackets = '[' then
Result := '[' + S + ']'
else if Brackets = '(' then
Result := '(' + S + ')'
else if Brackets > #0 then
Result := Brackets + S + Brackets
else
Result := S;
end;
begin
Result := '';
if (ShortcutA.Key1 = VK_UNKNOWN) and (ShortcutB.Key1 = VK_UNKNOWN) then
Result := Result{ + lisNone2 }
else
if (ShortcutA.Key1 = VK_UNKNOWN) then
Result := Result + AddBrakets(KeyAndShiftStateToEditorKeyString(ShortcutB))
else
if (ShortcutB.Key1 = VK_UNKNOWN) then
Result := Result + AddBrakets(KeyAndShiftStateToEditorKeyString(ShortcutA))
else
Result := Result + AddBrakets(KeyAndShiftStateToEditorKeyString(ShortcutA))
+ ' '+lisOr+' ' +
AddBrakets(KeyAndShiftStateToEditorKeyString(ShortcutB));
end;
function IDEShortCutEmpty(const Key: TIDEShortCut): boolean;
begin
Result:=(Key.Key1=VK_UNKNOWN) and (Key.Key2=VK_UNKNOWN);

View File

@ -322,7 +322,7 @@ type
procedure mnuViewFormsClicked(Sender: TObject);
procedure mnuViewProjectSourceClicked(Sender: TObject);
procedure mnuProjectOptionsClicked(Sender: TObject);
procedure mnuBuildModeClicked(Sender: TObject);
procedure mnuBuildModeClicked(Sender: TObject); override;
// run menu
procedure mnuCompileProjectClicked(Sender: TObject);
@ -2698,7 +2698,6 @@ begin
itmProjectViewUnits.OnClick := @mnuViewUnitsClicked;
itmProjectViewForms.OnClick := @mnuViewFormsClicked;
itmProjectViewSource.OnClick := @mnuViewProjectSourceClicked;
itmProjectBuildMode.OnClick := @mnuBuildModeClicked;
end;
end;
@ -3785,6 +3784,7 @@ procedure TMainIDE.UpdateProjectCommands(Sender: TObject);
var
ASrcEdit: TSourceEditor;
AUnitInfo: TUnitInfo;
xCmd: TIDECommand;
begin
GetCurrentUnit(ASrcEdit,AUnitInfo);
if not UpdateProjectCommandsStamp.Changed(AUnitInfo) then
@ -3792,6 +3792,15 @@ begin
IDECommandList.FindIDECommand(ecAddCurUnitToProj).Enabled:=Assigned(AUnitInfo) and not AUnitInfo.IsPartOfProject;
IDECommandList.FindIDECommand(ecBuildManyModes).Enabled:=(Project1<>nil) and (Project1.BuildModes.Count>1);
xCmd := IDECommandList.FindIDECommand(ecProjectChangeBuildMode);
if Assigned(Project1) then
xCmd.Hint :=
Trim(lisChangeBuildMode + ' ' + KeyValuesToCaptionStr(xCmd.ShortcutA, xCmd.ShortcutB, '(')) + sLineBreak +
Format('[%s]', [Project1.ActiveBuildMode.GetCaption])
else
xCmd.Hint :=
Trim(lisChangeBuildMode + ' ' + KeyValuesToCaptionStr(xCmd.ShortcutA, xCmd.ShortcutB, '('));
end;
procedure TMainIDE.UpdatePackageCommands(Sender: TObject);
@ -7885,7 +7894,6 @@ begin
end;
MainIDEBar.Caption := NewCaption;
Application.Title := NewTitle;
TSetBuildModeToolButton.UpdateHints;
end;
procedure TMainIDE.HideIDE;

View File

@ -274,7 +274,6 @@ type
itmProjectViewUnits: TIDEMenuCommand;
itmProjectViewForms: TIDEMenuCommand;
itmProjectViewSource: TIDEMenuCommand;
itmProjectBuildMode: TIDEMenuCommand;
// run menu
//mnuRun: TIDEMenuSection;

View File

@ -126,6 +126,7 @@ type
procedure mnuWindowItemClick(Sender: TObject); virtual;
procedure mnuCenterWindowItemClick(Sender: TObject); virtual;
procedure mnuWindowSourceItemClick(Sender: TObject); virtual;
procedure mnuBuildModeClicked(Sender: TObject); virtual; abstract;
procedure UpdateWindowMenu;
@ -211,8 +212,6 @@ type
procedure mnuSetBuildModeClick(Sender: TObject);
public
procedure DoOnAdded; override;
class procedure UpdateHints;
end;
{ TOpenFileToolButton }
@ -480,7 +479,6 @@ begin
DropdownMenu := TPopupMenu.Create(Self);
DropdownMenu.OnPopup := @RefreshMenu;
Style := tbsDropDown;
UpdateHints;
end;
procedure TSetBuildModeToolButton.mnuSetBuildModeClick(Sender: TObject);
@ -543,16 +541,6 @@ begin
aMenu.Items[aMenu.Items.Count - 1].Free;
end;
class procedure TSetBuildModeToolButton.UpdateHints;
const
cActiveBuildMode = '[%s]';
begin
if Assigned(Project1) then
MainIDEBar.itmProjectBuildMode.Hint :=
lisChangeBuildMode + MainIDEBar.itmProjectBuildMode.GetShortcut + sLineBreak +
Format(cActiveBuildMode, [Project1.ActiveBuildMode.GetCaption]);
end;
{ TJumpToSectionToolButton }
procedure TJumpToSectionToolButton.DoOnAdded;
@ -1275,7 +1263,6 @@ begin
CreateMenuItem(ParentMI,itmProjectViewUnits,'itmProjectViewUnits',lisMenuViewUnits, 'menu_view_units');
CreateMenuItem(ParentMI,itmProjectViewForms,'itmProjectViewForms',lisMenuViewForms, 'menu_view_forms');
CreateMenuItem(ParentMI,itmProjectViewSource,'itmProjectViewSource',lisMenuViewProjectSource, 'menu_project_viewsource');
CreateMenuItem(ParentMI,itmProjectBuildMode,'itmProjectBuildMode',lisChangeBuildMode+' ...', 'menu_compiler_options');
end;
end;
@ -1648,7 +1635,10 @@ begin
itmProjectViewUnits.Command:=GetCommand(ecViewProjectUnits);
itmProjectViewForms.Command:=GetCommand(ecViewProjectForms);
itmProjectViewSource.Command:=GetCommand(ecViewProjectSource);
itmProjectBuildMode.Command:=GetCommand(ecProjectChangeBuildMode,TSetBuildModeToolButton);
GetCmdAndBtn(ecProjectChangeBuildMode, xBtnItem);
xBtnItem.ToolButtonClass:=TSetBuildModeToolButton;
xBtnItem.ImageIndex := IDEImages.LoadImage(16, 'menu_compiler_options');
xBtnItem.OnClick := @mnuBuildModeClicked;
// run menu
itmRunMenuCompile.Command:=GetCommand(ecCompile);

View File

@ -69,6 +69,8 @@ type
private
FUnitInfo: TUnitInfo;
FProjectChangeStamp: Int64;
FCompilerParseStamp: integer;
FBuildMacroChangeStamp: integer;
public
function Changed(AUnitInfo: TUnitInfo): Boolean;
end;
@ -477,12 +479,16 @@ begin
Result := not(
(FUnitInfo = AUnitInfo)
and (FProjectChangeStamp = CurProjectChangeStamp)
and (FCompilerParseStamp = CompilerParseStamp)
and (FBuildMacroChangeStamp = BuildMacroChangeStamp)
);
if not Result then Exit;
FUnitInfo := AUnitInfo;
FProjectChangeStamp := CurProjectChangeStamp;
FCompilerParseStamp := CompilerParseStamp;
FBuildMacroChangeStamp := BuildMacroChangeStamp;
end;
{ TPackageCommandsStamp }