IDE: Move "Support UTF8 RTL" button to Project options window. Add -dEnableUTF8RTL to MatrixOptions (Additions and Overrides).

git-svn-id: trunk@47593 -
This commit is contained in:
juha 2015-02-05 15:46:46 +00:00
parent 25753901f7
commit 9569ce56d2
5 changed files with 192 additions and 87 deletions

View File

@ -101,6 +101,7 @@ type
fCaptionPatternMacroValue: string;
procedure AddLCLWidgetTypeValues(ParentMenu: TPopupMenu; Mcr: TLazBuildMacro);
procedure AddMacroValues(ParentMI: TMenuItem; Mcr: TLazBuildMacro);
function ActiveModeAsText: string;
procedure DoWriteSettings;
procedure FillMenus;
procedure MoveRow(Direction: integer);
@ -112,6 +113,8 @@ type
procedure UpdateEnabledModesInGrid(Options: TBuildMatrixOptions;
StorageGroup: TGroupedMatrixGroup; var HasChanged: boolean);
procedure UpdateGridStorageGroups;
function CheckAndUpdateUtf8RtlSupport(UpdateIt: Boolean;
out WasUpdated: Boolean): Boolean;
protected
procedure VisibleChanged; override;
public
@ -123,6 +126,8 @@ type
procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
procedure RestoreSettings(AOptions: TAbstractIDEOptions); override;
function HasSupportForUtf8Rtl: Boolean;
function SupportUtf8Rtl: Boolean;
procedure UpdateModes(UpdateGrid: boolean = true);
procedure UpdateActiveMode;
public
@ -160,6 +165,9 @@ var
implementation
const
EnableUTF8RTL = '-dEnableUTF8RTL';
function BuildMatrixOptionTypeCaption(Typ: TBuildMatrixOptionType): string;
begin
case Typ of
@ -727,26 +735,20 @@ begin
Result:=AddMatrixTarget(Grid.Matrix,StorageGroup);
end;
function TCompOptModeMatrixFrame.ActiveModeAsText: string;
begin
if EnvironmentOptions.UseBuildModes then
Result:=Grid.Modes[Grid.ActiveMode].Caption
else
Result:=LazProject.BuildModes[0].GetCaption;
end;
procedure TCompOptModeMatrixFrame.CreateNewOption(aTyp, aValue: string);
var
aRow: Integer;
MatRow: TGroupedMatrixRow;
Group: TGroupedMatrixGroup;
NewRow: TGroupedMatrixValue;
procedure CreateOption;
var
Capt: String;
begin
if aTyp='' then
aTyp:=Grid.TypeColumn.PickList.Names[0];
if EnvironmentOptions.UseBuildModes then
Capt:=Grid.Modes[Grid.ActiveMode].Caption
else
Capt:=LazProject.BuildModes[0].GetCaption;
NewRow:=Grid.Matrix.AddValue(Group,Capt,aTyp,aValue,CreateBuildMatrixOptionGUID);
end;
begin
aRow:=Grid.Row;
if aRow<Grid.FixedRows then aRow:=Grid.FixedRows;
@ -754,6 +756,8 @@ begin
Grid.MatrixChanging;
try
Grid.StoreUndo;
if aTyp='' then
aTyp:=Grid.TypeColumn.PickList.Names[0];
MatRow:=Grid.Matrix[aRow-1];
//debugln(['TCompOptModeMatrix.CreateNewOption ',DbgSName(MatRow),' ',MatRow.AsString]);
if MatRow is TGroupedMatrixGroup then begin
@ -768,11 +772,13 @@ begin
end;
end;
// add option as first item of Group
CreateOption;
NewRow:=Grid.Matrix.AddValue(Group, ActiveModeAsText, aTyp, aValue,
CreateBuildMatrixOptionGUID);
end else begin
// add behind current value
Group:=MatRow.Group;
CreateOption;
NewRow:=Grid.Matrix.AddValue(Group, ActiveModeAsText, aTyp, aValue,
CreateBuildMatrixOptionGUID);
Group.Move(Group.Count-1,MatRow.GetGroupIndex+1);
end;
Grid.Matrix.RebuildRows;
@ -870,10 +876,9 @@ end;
procedure TCompOptModeMatrixFrame.UpdateGridStorageGroups;
var
i: Integer;
i, j: Integer;
MatRow: TGroupedMatrixRow;
GroupRow: TGroupedMatrixGroup;
j: Integer;
begin
fGroupIDE:=nil;
fGroupProject:=nil;
@ -902,6 +907,71 @@ begin
DoWriteSettings;
end;
function TCompOptModeMatrixFrame.CheckAndUpdateUtf8RtlSupport(UpdateIt: Boolean;
out WasUpdated: Boolean): Boolean;
// Returns True if the support already was there.
var
GrpIndex: Integer;
Target: TGroupedMatrixGroup;
i: Integer;
ValueRow: TGroupedMatrixValue;
AMode: String;
begin
Result := False;
WasUpdated := False;
for GrpIndex:=0 to GroupProject.Count-1 do
begin
Target := TGroupedMatrixGroup(GroupProject[GrpIndex]);
if not (Target is TGroupedMatrixGroup) then
exit;
for i:=0 to Target.Count-1 do
begin
ValueRow := TGroupedMatrixValue(Target[i]);
if not (ValueRow is TGroupedMatrixValue) then
exit;
Result := (ValueRow.Typ = 'Custom') and (ValueRow.Value = EnableUTF8RTL);
if Result then
begin
AMode := ActiveModeAsText;
Result := (ValueRow.ModeList.IndexOf(AMode)>=0);
if (not Result) and UpdateIt then
begin
Grid.MatrixChanging;
try
ValueRow.ModeList.Add(AMode);
finally
Grid.MatrixChanged;
end;
WasUpdated := True;
end;
Exit;
end;
end;
end;
end;
function TCompOptModeMatrixFrame.HasSupportForUtf8Rtl: Boolean;
var
Dummy: Boolean;
begin
Result := CheckAndUpdateUtf8RtlSupport(False, Dummy);
end;
function TCompOptModeMatrixFrame.SupportUtf8Rtl: Boolean;
// Add a compiler flag to make FPC default string UTF-8,
// assign UTF-8 backends for Ansi...() functions etc.
// Returns true if the flag was really added and did not exist earlier.
var
WasUpdated: Boolean;
begin
Result := not CheckAndUpdateUtf8RtlSupport(True, WasUpdated);
if Result and not WasUpdated then
begin
CreateNewOption(BuildMatrixOptionTypeCaption(bmotCustom), EnableUTF8RTL);
UpdateModes;
end;
end;
procedure TCompOptModeMatrixFrame.UpdateModes(UpdateGrid: boolean);
var
i: Integer;

View File

@ -702,7 +702,6 @@ object CompilerOtherOptionsFrame: TCompilerOtherOptionsFrame
TabOrder = 2
object memoCustomOptions: TMemo
AnchorSideLeft.Control = grpCustomOptions
AnchorSideRight.Control = btnSupportUTF8RTL
AnchorSideBottom.Control = grpCustomOptions
AnchorSideBottom.Side = asrBottom
Left = 0
@ -718,7 +717,8 @@ object CompilerOtherOptionsFrame: TCompilerOtherOptionsFrame
WordWrap = False
end
object btnAllOptions: TBitBtn
AnchorSideLeft.Control = btnDefines
AnchorSideLeft.Control = memoCustomOptions
AnchorSideLeft.Side = asrBottom
AnchorSideRight.Control = btnDefines
AnchorSideRight.Side = asrBottom
Left = 367
@ -732,10 +732,9 @@ object CompilerOtherOptionsFrame: TCompilerOtherOptionsFrame
TabOrder = 1
end
object btnDefines: TBitBtn
AnchorSideLeft.Control = btnSupportUTF8RTL
AnchorSideLeft.Control = btnAllOptions
AnchorSideTop.Control = btnAllOptions
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = btnSupportUTF8RTL
AnchorSideRight.Side = asrBottom
Left = 367
Height = 30
@ -748,20 +747,5 @@ object CompilerOtherOptionsFrame: TCompilerOtherOptionsFrame
OnClick = btnDefinesClick
TabOrder = 2
end
object btnSupportUTF8RTL: TBitBtn
AnchorSideTop.Control = btnDefines
AnchorSideTop.Side = asrBottom
AnchorSideRight.Side = asrBottom
Left = 367
Height = 30
Top = 76
Width = 150
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Top = 6
Caption = 'Support UTF-8 RTL'
OnClick = btnSupportUTF8RTLClick
TabOrder = 3
end
end
end

View File

@ -42,7 +42,6 @@ type
TCompilerOtherOptionsFrame = class(TAbstractIDEOptionsEditor)
btnDefines: TBitBtn;
btnAllOptions: TBitBtn;
btnSupportUTF8RTL: TBitBtn;
grpCustomOptions: TGroupBox;
grpConditionals: TGroupBox;
CondStatusbar: TStatusBar;
@ -51,7 +50,6 @@ type
memoCustomOptions: TMemo;
procedure btnAllOptionsClick(Sender: TObject);
procedure btnDefinesClick(Sender: TObject);
procedure btnSupportUTF8RTLClick(Sender: TObject);
procedure CondSynEditChange(Sender: TObject);
procedure CondSynEditKeyPress(Sender: TObject; var Key: char);
procedure CondSynEditProcessUserCommand(Sender: TObject;
@ -101,6 +99,8 @@ type
procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
function HasSupportForUtf8Rtl: Boolean;
function SupportUtf8Rtl: Boolean;
property StatusMessage: string read FStatusMessage write SetStatusMessage;
property DefaultVariables: TCTCfgScriptVariables read FDefaultVariables;
property CompletionValues: TStrings read FCompletionValues;
@ -113,6 +113,9 @@ implementation
{$R *.lfm}
const
FcUTF8 = '-FcUTF8';
{ TCompilerOtherOptionsFrame }
procedure TCompilerOtherOptionsFrame.btnAllOptionsClick(Sender: TObject);
@ -170,23 +173,18 @@ begin
end;
end;
procedure TCompilerOtherOptionsFrame.btnSupportUTF8RTLClick(Sender: TObject);
var
Opts: String;
procedure AddUtf8Define(aDefine: String);
begin
if Pos(aDefine, Opts) = 0 then
memoCustomOptions.Lines.Add(aDefine);
end;
function TCompilerOtherOptionsFrame.HasSupportForUtf8Rtl: Boolean;
begin
Opts := memoCustomOptions.Text;
// This makes FPC default string type UTF-8.
// Assign UTF-8 backends for Ansi...() functions etc.
AddUtf8Define('-dEnableUTF8RTL');
// For WideString/UnicodeString/UTF8String literals.
AddUtf8Define('-FcUTF8');
Result := Pos(FcUTF8, memoCustomOptions.Text) > 0;
end;
function TCompilerOtherOptionsFrame.SupportUtf8Rtl: Boolean;
// Add a compiler flag for WideString/UnicodeString/UTF8String literals.
// Returns true if the flag was really added and did not exist earlier.
begin
Result := not HasSupportForUtf8Rtl;
if Result then
memoCustomOptions.Lines.Add(FcUTF8);
end;
// Events dealing with conditionals SynEdit :
@ -724,7 +722,6 @@ begin
grpConditionals.Caption := lisConditionals;
btnAllOptions.Caption := lisDlgAllOptions;
btnDefines.Caption := lisDlgDefines;
btnSupportUTF8RTL.Caption := lisSupportUTF8RTL;
end;
procedure TCompilerOtherOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);

View File

@ -6,22 +6,22 @@ object IDEOptionsDialog: TIDEOptionsDialog
ActiveControl = FilterEdit
BorderIcons = [biSystemMenu]
Caption = 'IDEOptionsDialog'
ClientHeight = 404
ClientWidth = 689
ClientHeight = 500
ClientWidth = 800
Constraints.MinHeight = 350
Constraints.MinWidth = 500
OnShow = FormShow
Position = poScreenCenter
LCLVersion = '1.3'
LCLVersion = '1.5'
object ButtonPanel: TButtonPanel
AnchorSideLeft.Control = Owner
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner
Left = 6
Height = 41
Top = 357
Width = 677
Height = 38
Top = 456
Width = 788
BorderSpacing.Left = 6
BorderSpacing.Right = 6
BorderSpacing.Bottom = 6
@ -40,7 +40,7 @@ object IDEOptionsDialog: TIDEOptionsDialog
end
object CatTVSplitter: TSplitter
Left = 255
Height = 357
Height = 456
Top = 0
Width = 4
end
@ -48,12 +48,12 @@ object IDEOptionsDialog: TIDEOptionsDialog
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner
Left = 0
Height = 357
Height = 456
Top = 0
Width = 255
Align = alLeft
BevelOuter = bvNone
ClientHeight = 357
ClientHeight = 456
ClientWidth = 255
Constraints.MinWidth = 150
TabOrder = 2
@ -65,12 +65,12 @@ object IDEOptionsDialog: TIDEOptionsDialog
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = SettingsPanel
Left = 6
Height = 300
Top = 37
Height = 396
Top = 40
Width = 249
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 6
DefaultItemHeight = 18
DefaultItemHeight = 22
ReadOnly = True
TabOrder = 0
OnChange = CategoryTreeChange
@ -102,7 +102,7 @@ object IDEOptionsDialog: TIDEOptionsDialog
object SettingsPanel: TPanel
Left = 0
Height = 20
Top = 337
Top = 436
Width = 255
Align = alBottom
AutoSize = True
@ -120,23 +120,23 @@ object IDEOptionsDialog: TIDEOptionsDialog
Left = 259
Height = 40
Top = 0
Width = 424
Width = 535
Anchors = [akTop, akLeft, akRight]
BevelOuter = bvNone
ClientHeight = 40
ClientWidth = 424
ClientWidth = 535
TabOrder = 3
object BuildModeComboBox: TComboBox
AnchorSideLeft.Control = UseBuildModeCheckBox
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = UseBuildModeCheckBox
AnchorSideTop.Side = asrCenter
Left = 119
Height = 25
Left = 126
Height = 28
Top = 5
Width = 154
BorderSpacing.Left = 7
ItemHeight = 0
ItemHeight = 20
OnSelect = BuildModeComboBoxSelect
Style = csDropDownList
TabOrder = 0
@ -146,11 +146,11 @@ object IDEOptionsDialog: TIDEOptionsDialog
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = BuildModeComboBox
AnchorSideTop.Side = asrCenter
Left = 288
Left = 291
Height = 25
Top = 5
Top = 7
Width = 25
BorderSpacing.Left = 15
BorderSpacing.Left = 11
Caption = '...'
OnClick = BuildModeManageButtonClick
TabOrder = 1
@ -158,9 +158,9 @@ object IDEOptionsDialog: TIDEOptionsDialog
object UseBuildModeCheckBox: TCheckBox
AnchorSideTop.Side = asrCenter
Left = 12
Height = 21
Height = 24
Top = 7
Width = 100
Width = 107
BorderSpacing.Left = 6
Caption = 'Build modes'
OnChange = UseBuildModeCheckBoxChange
@ -168,6 +168,21 @@ object IDEOptionsDialog: TIDEOptionsDialog
ShowHint = True
TabOrder = 2
end
object SupportUtf8RtlButton: TButton
AnchorSideLeft.Control = BuildModeManageButton
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = BuildModeManageButton
AnchorSideTop.Side = asrCenter
Left = 331
Height = 30
Top = 4
Width = 150
AutoSize = True
BorderSpacing.Left = 15
Caption = 'Support UTF-8 RTL'
OnClick = SupportUtf8RtlButtonClick
TabOrder = 3
end
end
object EditorsPanel: TScrollBox
AnchorSideLeft.Control = CatTVSplitter
@ -178,9 +193,9 @@ object IDEOptionsDialog: TIDEOptionsDialog
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ButtonPanel
Left = 259
Height = 317
Height = 416
Top = 40
Width = 424
Width = 535
HorzScrollBar.Page = 1
HorzScrollBar.Tracking = True
VertScrollBar.Page = 1

View File

@ -30,13 +30,12 @@ unit IDEOptionsDlg;
interface
uses
Classes, SysUtils,
LCLProc, LCLType, Controls, Forms, ComCtrls,
Buttons, ButtonPanel, ExtCtrls, EditBtn, StdCtrls, Dialogs, TreeFilterEdit,
Classes, SysUtils, LCLProc, LCLType, Controls, Forms, ComCtrls, Buttons,
ButtonPanel, ExtCtrls, EditBtn, StdCtrls, Dialogs, TreeFilterEdit,
IDEWindowIntf, IDEOptionsIntf, IDECommands, IDEHelpIntf, ProjectIntf,
CompOptsIntf, IDEDialogs,
EnvironmentOpts, LazarusIDEStrConsts, EditorOptions,
BuildModesManager, project_save_options, Project, Compiler_ModeMatrix;
CompOptsIntf, IDEDialogs, EnvironmentOpts, LazarusIDEStrConsts, EditorOptions,
BuildModesManager, TransferMacros, project_save_options, Project,
ModeMatrixOpts, Compiler_ModeMatrix, Compiler_Other_Options;
type
TIDEOptsDlgAction = (
@ -51,6 +50,7 @@ type
TIDEOptionsDialog = class(TAbstractOptionsEditorDialog)
BuildModeComboBox: TComboBox;
SupportUtf8RtlButton: TButton;
UseBuildModeCheckBox: TCheckBox;
BuildModeManageButton: TButton;
BuildModeSelectPanel: TPanel;
@ -61,6 +61,7 @@ type
EditorsPanel: TScrollBox;
FilterEdit: TTreeFilterEdit;
SettingsPanel: TPanel;
procedure SupportUtf8RtlButtonClick(Sender: TObject);
procedure UseBuildModeCheckBoxChange(Sender: TObject);
procedure BuildModeComboBoxSelect(Sender: TObject);
procedure BuildModeManageButtonClick(Sender: TObject);
@ -97,6 +98,7 @@ type
function AllBuildModes: boolean;
procedure UpdateBuildModeButtons;
procedure SetBuildModeVisibility(AVisibility: Boolean);
procedure UpdateUtf8RtlButtonState;
public
constructor Create(AOwner: TComponent); override;
function ShowModal: Integer; override;
@ -137,6 +139,7 @@ begin
SettingsPanel.Constraints.MinHeight:=0;
SetBuildModeVisibility(False);
UseBuildModeCheckBox.Caption:=lisBuildModes;
SupportUtf8RtlButton.Caption := lisSupportUTF8RTL;
IDEDialogLayoutList.ApplyLayout(Self, Width, Height);
Caption := dlgIDEOptions;
@ -218,6 +221,38 @@ procedure TIDEOptionsDialog.UseBuildModeCheckBoxChange(Sender: TObject);
begin
EnvironmentOptions.UseBuildModes:=(Sender as TCheckBox).Checked;
UpdateBuildModeButtons;
UpdateUtf8RtlButtonState;
end;
procedure TIDEOptionsDialog.UpdateUtf8RtlButtonState;
var
OtherOptions: TCompilerOtherOptionsFrame;
ModeMatrix: TCompOptModeMatrixFrame;
Dummy: Boolean;
begin
OtherOptions:=TCompilerOtherOptionsFrame(FindEditor(TCompilerOtherOptionsFrame));
ModeMatrix:=TCompOptModeMatrixFrame(FindEditor(TCompOptModeMatrixFrame));
if Assigned(OtherOptions) and Assigned(ModeMatrix) then
SupportUtf8RtlButton.Enabled :=
not (OtherOptions.HasSupportForUtf8Rtl and ModeMatrix.HasSupportForUtf8Rtl);
end;
procedure TIDEOptionsDialog.SupportUtf8RtlButtonClick(Sender: TObject);
var
OtherOptions: TCompilerOtherOptionsFrame;
ModeMatrix: TCompOptModeMatrixFrame;
begin
OtherOptions:=TCompilerOtherOptionsFrame(FindEditor(TCompilerOtherOptionsFrame));
ModeMatrix:=TCompOptModeMatrixFrame(FindEditor(TCompOptModeMatrixFrame));
if Assigned(OtherOptions) and Assigned(ModeMatrix) then begin
// For WideString/UnicodeString/UTF8String literals.
OtherOptions.SupportUtf8Rtl;
// Make FPC default string UTF-8. Assign UTF-8 backends for Ansi...() functions etc.
ModeMatrix.SupportUtf8Rtl;
UpdateUtf8RtlButtonState;
ShowMessage('This build mode now has support for UTF-8 RTL.' + LineEnding
+' Flags are in pages "Other" and "Additions and Overrides".');
end;
end;
procedure TIDEOptionsDialog.BuildModeComboBoxSelect(Sender: TObject);
@ -228,6 +263,7 @@ begin
else begin
Assert(BuildModeSelectPanel.Visible, 'BuildModeComboBoxSelect: BuildModeSelectPanel not Visible');
SwitchBuildMode(BuildModeComboBox.Text);
UpdateUtf8RtlButtonState;
end;
end;
@ -236,6 +272,7 @@ begin
if ShowBuildModesDlg(Project1.SessionStorage in pssHasSeparateSession) <> mrOK then
exit;
UpdateBuildModeCombo(BuildModeComboBox);
UpdateUtf8RtlButtonState;
end;
procedure TIDEOptionsDialog.CategoryTreeCollapsed(Sender: TObject; Node: TTreeNode);
@ -610,6 +647,7 @@ begin
UseBuildModeCheckBox.Enabled := not ManyBuildModes;
BuildModeComboBox.Visible := EnvironmentOptions.UseBuildModes;
BuildModeManageButton.Visible := EnvironmentOptions.UseBuildModes;
ModeMatrix:=TCompOptModeMatrixFrame(FindEditor(TCompOptModeMatrixFrame));
if Assigned(ModeMatrix) then
ModeMatrix.UpdateModes;
@ -755,6 +793,7 @@ procedure TIDEOptionsDialog.UpdateBuildModeGUI;
begin
UpdateBuildModeCombo(BuildModeComboBox);
UpdateBuildModeButtons;
UpdateUtf8RtlButtonState;
end;
end.