1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982
|
unit Options;
// Copyright (C) 2003, 2004 MySQL AB
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
interface
uses
Windows, Classes, TntClasses, Forms, TntForms, SysUtils, Messages, ComCtrls,
TntComCtrls, myx_public_interface, AuxFuncs, Types, StrUtils;
const
WM_OptionsChanged = WM_USER + 100;
type
// Universal connection between option storage and option user.
IOptionChangeListener = interface
procedure OptionChanged;
end;
IOptionProvider = interface
['{B37BCB77-4A85-4863-8615-C3ED9AB96C4D}']
procedure AddListener(Listener: IOptionChangeListener);
function GetOptionAsBoolean(Name: WideString): Boolean;
function GetOptionAsDouble(Name: WideString): Double;
function GetOptionAsInteger(Name: WideString): Integer;
function GetOptionAsString(Name: WideString): WideString;
procedure RemoveListener(Listener: IOptionChangeListener);
procedure SetOptionAsBoolean(Name: WideString; Value: Boolean);
procedure SetOptionAsDouble(Name: WideString; Value: Double);
procedure SetOptionAsInteger(Name: WideString; Value: Integer);
procedure SetOptionAsString(Name: WideString; Value: WideString);
property OptionAsBoolean[Name: WideString]: Boolean read GetOptionAsBoolean write SetOptionAsBoolean;
property OptionAsDouble[Name: WideString]: Double read GetOptionAsDouble write SetOptionAsDouble;
property OptionAsInteger[Name: WideString]: Integer read GetOptionAsInteger write SetOptionAsInteger;
property OptionAsString[Name: WideString]: WideString read GetOptionAsString write SetOptionAsString;
procedure AddWindowPos(Win: TTntForm);
function RestoreWindowPos(Win: TTntForm; DoSize: Boolean = True): Boolean;
end;
TDoPageContentChanged = procedure(Sender: TObject) of object;
TMyxOptions = class(TInterfacedObject, IOptionProvider)
private
// Options stored as associated list.
// TODO: Use Hashmap.
FOptions: TTntStringList;
FFormatSettings: TFormatSettings; // Used to convert float values language neutrally.
FChangeListeners: TInterfaceList;
// Option provider implementation.
function GetOptionAsBoolean(Name: WideString): Boolean;
function GetOptionAsDouble(Name: WideString): Double;
function GetOptionAsInteger(Name: WideString): Integer;
function GetOptionAsString(Name: WideString): WideString;
// TODO: Set method must use groups for options.
procedure SetOptionAsBoolean(Name: WideString; Value: Boolean);
procedure SetOptionAsDouble(Name: WideString; Value: Double);
procedure SetOptionAsInteger(Name: WideString; Value: Integer);
procedure SetOptionAsString(Name: WideString; Value: WideString);
public
WindowPosList: TTntStringList;
IgnoreWarningsList: TTntStringList;
constructor Create; virtual;
destructor Destroy; override;
procedure AddListener(Listener: IOptionChangeListener);
procedure Changed;
procedure LoadOptions; virtual; abstract;
procedure RemoveListener(Listener: IOptionChangeListener);
procedure StoreOptions; virtual; abstract;
function CheckBoolStr(s: WideString): Boolean;
procedure AddParam(OptionGroup: TMYX_OPTION_GROUP; name: WideString; value: WideString);
procedure AddWindowPos(Win: TTntForm);
function RestoreWindowPos(Win: TTntForm; DoSize: Boolean = True): Boolean; virtual;
procedure StoreListOptions(Groups: TMYX_OPTION_GROUP_List);
end;
TMyxWindowPos = class
constructor Create; overload;
constructor Create(AsWideString: WideString); overload;
function AsWideString: WideString;
public
Name: WideString;
State: TWindowState;
Pos: TPoint;
Size: TPoint;
MonitorNum: Integer;
end;
TMYXCommonOptions = class(TMyxOptions)
procedure LoadOptions; override;
procedure StoreOptions; override;
public
ConnectionToUse: WideString;
ConnectionUsername,
ConnectionPassword,
ConnectionHost,
ConnectionPort,
ConnectionSchema: WideString;
AvailableLanguages: WideString;
AvailableLanguageCodes: WideString;
AvailablePasswordStorageTypes: WideString;
StoreWindowsPositions,
ShowTipOfDay: Boolean;
Language: WideString;
XPStyleEnabled: Boolean;
//FileDialogPaths: TTntStringList;
XMLDir, UserDataDir: WideString;
PasswordStorageType: MYX_PASSWORD_STORAGE_TYPE;
EditorTableShowSQLBeforeApplying,
EditorTableAllColumnsNotNullPerDef,
EditorTableIntegerUnsignedPerDef: Boolean;
EditorTablePKDataType,
EditorTableDefColumnDataType,
EditorTablePKAutoNaming,
EditorTableIndexAutoNaming,
EditorTableFKAutoNaming,
EditorTableDefaultStorageEngine: WideString;
DefaultFontName,
DataFontName,
CodeFontName: WideString;
DefaultFontHeight,
DataFontHeight,
CodeFontHeight,
CodeFontWidth,
CodeFontCharset: Integer;
DisableTransparencyEffects: Boolean;
public
destructor Destroy; override;
function RestoreWindowPos(Win: TTntForm; DoSize: Boolean = True): Boolean; override;
end;
TApplicationOptionsForm = class(TTntForm)
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure SetControls(PageNr: integer); virtual; abstract;
procedure ApplyChanges(PageNr: integer); virtual; abstract;
public
{ Public declarations }
OptionsImgNames: TTntStringList;
DockOptionPageControl: TTntPageControl;
DoPageContentChanged: TDoPageContentChanged;
end;
function GetWinPos(Win: TTntForm; WindowPosList: TTntStringList): TMyxWindowPos;
procedure SetWinPos(Win: TTntForm; WinPos: TMyxWindowPos; DoSize: Boolean = True);
var
MYXCommonOptions: TMYXCommonOptions;
MYXCommonOptionProvider: IOptionProvider;
//----------------------------------------------------------------------------------------------------------------------
implementation
const
oleaut = 'oleaut32.dll';
function SysAllocStringLen(P: PWideChar; Len: Integer): PWideChar; stdcall;
external oleaut name 'SysAllocStringLen';
procedure SysFreeString(const S: PWideChar); stdcall;
external oleaut name 'SysFreeString';
//----------------------------------------------------------------------------------------------------------------------
constructor TMyxOptions.Create;
begin
inherited Create;
WindowPosList := TTntStringList.Create;
IgnoreWarningsList := TTntStringList.Create;
FOptions := TTntStringList.Create;
// Fill the format settings with language neutral values (actually english is used but for all system languages).
GetLocaleFormatSettings(MakeLong(LANG_ENGLISH, SUBLANG_NEUTRAL), FFormatSettings);
LoadOptions;
end;
//----------------------------------------------------------------------------------------------------------------------
destructor TMyxOptions.Destroy;
var
I: integer;
begin
for I := 0 to WindowPosList.Count - 1 do
WindowPosList.Objects[I].Free;
WindowPosList.Free;
IgnoreWarningsList.Free;
for I := 0 to FOptions.Count - 1 do
SysFreeString(PWideChar(FOptions.Objects[I]));
FOptions.Free;
FChangeListeners.Free;
inherited Destroy;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMyxOptions.AddListener(Listener: IOptionChangeListener);
begin
if FChangeListeners = nil then
FChangeListeners := TInterfaceList.Create;
if FChangeListeners.IndexOf(Listener) = -1 then
FChangeListeners.Add(Listener);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMyxOptions.Changed;
var
I: Integer;
begin
if Assigned(FChangeListeners) then
begin
for I := 0 to FChangeListeners.Count - 1 do
IOptionChangeListener(FChangeListeners[I]).OptionChanged;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
function TMyxOptions.GetOptionAsBoolean(Name: WideString): Boolean;
var
Value: WideString;
Index: Integer;
begin
if FOptions.Find(Name, Index) then
begin
Value := PWideChar(FOptions.Objects[Index]);
// Value will be converted to ANSI using the current locale.
Result := StrToBoolDef(Value, False);
end
else
Result := False;
end;
//----------------------------------------------------------------------------------------------------------------------
function TMyxOptions.GetOptionAsDouble(Name: WideString): Double;
var
Value: WideString;
Index: Integer;
begin
if FOptions.Find(Name, Index) then
begin
Value := PWideChar(FOptions.Objects[Index]);
// Value will be converted to ANSI using the current locale.
Result := StrToFloatDef(Value, 0, FFormatSettings);
end
else
Result := 0;
end;
//----------------------------------------------------------------------------------------------------------------------
function TMyxOptions.GetOptionAsInteger(Name: WideString): Integer;
var
Value: WideString;
Index: Integer;
begin
if FOptions.Find(Name, Index) then
begin
Value := PWideChar(FOptions.Objects[Index]);
// Value will be converted to ANSI using the current locale.
Result := StrToIntDef(Value, 0);
end
else
Result := 0;
end;
//----------------------------------------------------------------------------------------------------------------------
function TMyxOptions.GetOptionAsString(Name: WideString): WideString;
var
Index: Integer;
begin
if FOptions.Find(Name, Index) then
Result := PWideChar(FOptions.Objects[Index])
else
Result := '';
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMyxOptions.RemoveListener(Listener: IOptionChangeListener);
begin
if Assigned(FChangeListeners) then
FChangeListeners.Remove(Listener);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMyxOptions.SetOptionAsBoolean(Name: WideString; Value: Boolean);
var
ValueString: WideString;
begin
ValueString := BoolToStr(Value, True);
SetOptionAsString(Name, ValueString);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMyxOptions.SetOptionAsDouble(Name: WideString; Value: Double);
var
ValueString: WideString;
begin
ValueString := FloatToStr(Value, FFormatSettings);
SetOptionAsString(Name, ValueString);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMyxOptions.SetOptionAsInteger(Name: WideString; Value: Integer);
var
ValueString: WideString;
begin
ValueString := IntToStr(Value);
SetOptionAsString(Name, ValueString);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMyxOptions.SetOptionAsString(Name, Value: WideString);
var
Index: Integer;
Temp: PWideChar;
NeedSort: Boolean;
begin
if not FOptions.Find(Name, Index) then
begin
Index := FOptions.Add(Name);
NeedSort := True;
end
else
begin
Temp := Pointer(FOptions.Objects[Index]);
SysFreeString(Temp);
NeedSort := False;
end;
Temp := SysAllocStringLen(PWideChar(Value), Length(Value));
FOptions.Objects[Index] := Pointer(Temp);
if NeedSort then
FOptions.Sort;
end;
//----------------------------------------------------------------------------------------------------------------------
function TMyxOptions.CheckBoolStr(s: WideString): Boolean;
begin
Result := (StrToIntDef(s, 1) = 1);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMyxOptions.AddParam(OptionGroup: TMYX_OPTION_GROUP; name: WideString; value: WideString);
begin
OptionGroup.name_value_pairs.Add(TMYX_NAME_VALUE_PAIR.create(name, value));
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMyxOptions.AddWindowPos(Win: TTntForm);
var
WinPos: TMyxWindowPos;
begin
WinPos := GetWinPos(Win, WindowPosList);
while (WindowPosList.IndexOf(Win.Name) > -1) do
WindowPosList.Delete(WindowPosList.IndexOf(Win.Name));
WindowPosList.AddObject(Win.Name, WinPos);
StoreOptions;
end;
//----------------------------------------------------------------------------------------------------------------------
function TMyxOptions.RestoreWindowPos(Win: TTntForm; DoSize: Boolean): Boolean;
var
i: integer;
WinPos: TMyxWindowPos;
begin
WinPos := nil;
i := WindowPosList.IndexOf(Win.Name);
if (i > -1) then
WinPos := TMyxWindowPos(WindowPosList.Objects[i]);
if Assigned(WinPos) then
begin
SetWinPos(Win, WinPos, DoSize);
Result := True;
end
else
begin
Win.Position := poScreenCenter;
Result := False;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMyxOptions.StoreListOptions(Groups: TMYX_OPTION_GROUP_List);
var
I: Integer;
OptionGroup: TMYX_OPTION_GROUP;
begin
OptionGroup := TMYX_OPTION_GROUP.create('main');
Groups.Add(OptionGroup);
for I := 0 to FOptions.Count - 1 do
OptionGroup.name_value_pairs.Add(TMYX_NAME_VALUE_PAIR.create(FOptions[I], PWideChar(FOptions.Objects[I])));
end;
//----------------- TMyWindowPos ---------------------------------------------------------------------------------------
function GetNextNumValue(var S: WideString): integer;
var
p, l: Integer;
begin
p := Pos('=', S);
l := Pos(';', S);
result := StrToIntDef(Copy(S, p + 1, l - p - 1), 0);
S := Copy(S, l + 1, Length(S));
end;
constructor TMyxWindowPos.Create;
begin
inherited;
end;
constructor TMyxWindowPos.Create(AsWideString: WideString);
begin
inherited Create;
Pos.X := GetNextNumValue(AsWideString);
Pos.Y := GetNextNumValue(AsWideString);
Size.X := GetNextNumValue(AsWideString);
Size.Y := GetNextNumValue(AsWideString);
State := TWindowState(GetNextNumValue(AsWideString));
MonitorNum := GetNextNumValue(AsWideString);
end;
function TMyxWindowPos.AsWideString: WideString;
var
s: WideString;
begin
s := s + 'x=' + IntToStr(Pos.X) + '; y=' + IntToStr(Pos.Y) +
'; w=' + IntToStr(Size.X) + '; h=' + IntToStr(Size.Y) +
'; s=' + IntToStr(Ord(State)) + '; m=' + IntToStr(MonitorNum);
Result := s;
end;
function GetWinPos(Win: TTntForm;
WindowPosList: TTntStringList): TMyxWindowPos;
var
WinPos: TMyxWindowPos;
i: integer;
begin
WinPos := TMyxWindowPos.Create;
WinPos.Name := Win.Name;
WinPos.State := Win.WindowState;
WinPos.MonitorNum := Win.Monitor.MonitorNum;
//P:=win.ClientToScreen(Point(0, 0));
if (Win.WindowState <> wsMaximized) then
begin
WinPos.Pos := Point(Win.Left, Win.Top);
WinPos.Size := Point(Win.Width, Win.Height);
end
else
begin
i := WindowPosList.IndexOf(Win.Name);
if (i > -1) then
begin
WinPos.Pos := TMyxWindowPos(WindowPosList.Objects[i]).Pos;
WinPos.Size := TMyxWindowPos(WindowPosList.Objects[i]).Size;
//Check if this position is on the right monitor
if (WinPos.Pos.X < Screen.Monitors[WinPos.MonitorNum].Left) or
(WinPos.Pos.X >= Screen.Monitors[WinPos.MonitorNum].Left +
Screen.Monitors[WinPos.MonitorNum].Width) then
begin
WinPos.Pos.X := Screen.Monitors[WinPos.MonitorNum].Left;
WinPos.Pos.Y := Screen.Monitors[WinPos.MonitorNum].Top;
end;
end
else
begin
WinPos.Pos := Point(0, 0);
WinPos.Size := Point(0, 0);
end;
end;
Result := WinPos;
end;
procedure SetWinPos(Win: TTntForm; WinPos: TMyxWindowPos; DoSize: Boolean);
begin
if (WinPos.Pos.X < 0) then
Win.Left := 0
else
if (WinPos.Pos.X >= Screen.DesktopWidth - 10) then
Win.Left := Screen.Width - 10
else
Win.Left := WinPos.Pos.X;
if (WinPos.Pos.Y < 0) then
Win.Top := 0
else
if (WinPos.Pos.Y >= Screen.DesktopHeight - 10) then
Win.Left := Screen.Height - 10
else
Win.Top := WinPos.Pos.Y;
if (DoSize) then
begin
if (WinPos.Size.X < 100) then
Win.Width := 100
else
Win.Width := WinPos.Size.X;
if (WinPos.Size.Y < 40) then
Win.Height := 40
else
Win.Height := WinPos.Size.Y;
end;
Win.WindowState := WinPos.State;
end;
// -------------------------------------------------
// TMYXCommonOptions
destructor TMYXCommonOptions.Destroy;
begin
inherited;
end;
procedure TMYXCommonOptions.LoadOptions;
var
POptions: PMYX_APPLICATION_OPTIONS;
Options: TMYX_APPLICATION_OPTIONS;
i, j: integer;
error: MYX_LIB_ERROR;
OptionGroupName,
OptionName,
OptionValue: WideString;
ExePath: WideString;
begin
if (UserDataDir = '') then
UserDataDir := GetApplicationDataDir + 'MySQL\';
ForceDirectories(UserDataDir);
ExePath := ExtractFilePath(Application.ExeName);
//Detect if XPStyle is enabled
XPStyleEnabled := getXPStyleEnabled;
AvailableLanguages := 'English'; //#13#10'German';
AvailableLanguageCodes := 'en'; //#13#10'de';
AvailablePasswordStorageTypes := 'Plaintext'#13#10'Obscured';
if (not (IsWinNT)) then
AvailablePasswordStorageTypes :=
AvailablePasswordStorageTypes + #13#10'OS Specific';
XMLDir := ExtractFilePath(Application.ExeName) + 'XML\';
//------------------------------------------------------------
//Initialize Values
Language := 'en';
//Initialize Default Values
PasswordStorageType := MYX_PASSWORD_NOT_STORED;
StoreWindowsPositions := True;
ShowTipOfDay := False;
EditorTableShowSQLBeforeApplying := True;
EditorTableAllColumnsNotNullPerDef := True;
EditorTableIntegerUnsignedPerDef := True;
EditorTablePKDataType := 'INTEGER';
EditorTableDefColumnDataType := 'VARCHAR(45)';
EditorTablePKAutoNaming := 'id%tablename%';
EditorTableIndexAutoNaming := 'Index_%nr%';
EditorTableFKAutoNaming := 'FK_%tablename%_%nr%';
EditorTableShowSQLBeforeApplying := True;
EditorTableAllColumnsNotNullPerDef := True;
EditorTableIntegerUnsignedPerDef := True;
EditorTablePKDataType := 'INTEGER';
EditorTableDefColumnDataType := 'VARCHAR(45)';
EditorTablePKAutoNaming := 'id%tablename%';
EditorTableIndexAutoNaming := 'Index_%nr%';
EditorTableFKAutoNaming := 'FK_%tablename%_%nr%';
EditorTableDefaultStorageEngine := 'InnoDB';
DefaultFontName := 'MS Sans Serif';
DataFontName := 'MS Sans Serif';
CodeFontName := 'Bitstream Vera Sans Mono';
CodeFontCharset := 1; //DEFAULT_CHARSET
if(Screen.PixelsPerInch<>96)then
begin
DefaultFontHeight := -13;
DataFontHeight := -13;
CodeFontHeight := -13;
CodeFontWidth := 8;
end
else
begin
DefaultFontHeight := -11;
DataFontHeight := -11;
CodeFontHeight := -11;
CodeFontWidth := 7;
end;
DisableTransparencyEffects := False;
//------------------------------------------------------------
//Read Options file
if (FileExists(UserDataDir + 'mysqlx_common_options.xml')) then
begin
POptions := myx_get_application_options(
UserDataDir + 'mysqlx_common_options.xml',
@error);
try
if (error <> MYX_NO_ERROR) then
begin
ShowModalDialog('XML Error',
'Error while loading Options file ''' +
UserDataDir + 'mysqlx_common_options.xml' + ''''#13#10 +
'Error Number ' + IntToStr(Ord(error)),
myx_mtError);
end
else
begin
Options := TMYX_APPLICATION_OPTIONS.Create(POptions);
try
for i := 0 to Options.option_groups.Count - 1 do
for j := 0 to Options.option_groups[i].name_value_pairs.Count - 1 do
begin
OptionGroupName := Options.option_groups[i].name;
OptionName := Options.option_groups[i].name_value_pairs[j].name;
OptionValue := Options.option_groups[i].name_value_pairs[j].value;
SetOptionAsString(OptionName, OptionValue);
if (CompareText(OptionGroupName, 'General') = 0) then
begin
if (CompareText(OptionName, 'Language') = 0) then
Language := OptionValue
else
if (CompareText(OptionName, 'PasswordStorageType') = 0) then
PasswordStorageType := MYX_PASSWORD_STORAGE_TYPE(StrToIntDef(OptionValue, 1))
else
if (CompareText(OptionName, 'StoreWindowsPositions') = 0) then
StoreWindowsPositions := (OptionValue = '1')
else
if (CompareText(OptionName, 'ShowTipOfDay') = 0) then
ShowTipOfDay := (OptionValue = '1')
else
if (CompareText(OptionName, 'IgnoreWarningsList') = 0) then
IgnoreWarningsList.Text :=
AnsiReplaceText(OptionValue, '#13#10', #13#10)
else
if (CompareText(OptionName, 'DisableTransparencyEffects') = 0) then
DisableTransparencyEffects := (OptionValue = '1')
else
if (CompareText(OptionName, 'PasswordStorageType') = 0) then
PasswordStorageType := MYX_PASSWORD_STORAGE_TYPE(StrToIntDef(OptionValue, 1))
else
if (CompareText(OptionName, 'StoreWindowsPositions') = 0) then
StoreWindowsPositions := (OptionValue = '1')
else
if (CompareText(OptionName, 'ShowTipOfDay') = 0) then
ShowTipOfDay := (OptionValue = '1')
else
if (CompareText(OptionName, 'IgnoreWarningsList') = 0) then
IgnoreWarningsList.Text :=
AnsiReplaceText(OptionValue, '#13#10', #13#10)
else
;
end
else
if (CompareText(OptionGroupName, 'Editors') = 0) then
begin
if (CompareText(OptionName, 'EditorTableShowSQLBeforeApplying') = 0) then
EditorTableShowSQLBeforeApplying := (OptionValue = '1')
else
if (CompareText(OptionName, 'EditorTableAllColumnsNotNullPerDef') = 0) then
EditorTableAllColumnsNotNullPerDef := (OptionValue = '1')
else
if (CompareText(OptionName, 'EditorTableIntegerUnsignedPerDef') = 0) then
EditorTableIntegerUnsignedPerDef := (OptionValue = '1')
else
if (CompareText(OptionName, 'EditorTablePKDataType') = 0) then
EditorTablePKDataType := OptionValue
else
if (CompareText(OptionName, 'EditorTablePKAutoNaming') = 0) then
EditorTablePKAutoNaming := OptionValue
else
if (CompareText(OptionName, 'EditorTableIndexAutoNaming') = 0) then
EditorTableIndexAutoNaming := OptionValue
else
if (CompareText(OptionName, 'EditorTableFKAutoNaming') = 0) then
EditorTableFKAutoNaming := OptionValue
else
if (CompareText(OptionName, 'EditorTableDefaultStorageEngine') = 0) then
EditorTableDefaultStorageEngine := OptionValue
else
;
end
else
if (CompareText(OptionGroupName, 'Fonts') = 0) then
begin
if (CompareText(OptionName, 'DefaultFontName') = 0) then
DefaultFontName := OptionValue
else
if (CompareText(OptionName, 'DataFontName') = 0) then
DataFontName := OptionValue
else
if (CompareText(OptionName, 'CodeFontName') = 0) then
CodeFontName := OptionValue
else
if (CompareText(OptionName, 'DefaultFontHeight') = 0) then
DefaultFontHeight := StrToIntDef(OptionValue, -11)
else
if (CompareText(OptionName, 'DataFontHeight') = 0) then
DataFontHeight := StrToIntDef(OptionValue, -11)
else
if (CompareText(OptionName, 'CodeFontWidth') = 0) then
CodeFontWidth := StrToIntDef(OptionValue, 8)
else
if (CompareText(OptionName, 'CodeFontHeight') = 0) then
CodeFontHeight := StrToIntDef(OptionValue, -11)
else
if (CompareText(OptionName, 'CodeFontCharset') = 0) then
CodeFontCharset := StrToIntDef(OptionValue, 8)
else
;
end
else
if (CompareText(OptionGroupName, 'WindowPos') = 0) then
begin
WindowPosList.AddObject(OptionName, TMyxWindowPos.Create(OptionValue));
end;
end;
finally
Options.Free;
end;
end;
finally
//Free Application Options
myx_free_application_options(POptions);
end;
end;
AuxFuncs.DefaultFontName := DefaultFontName;
AuxFuncs.DataFontName := DataFontName;
AuxFuncs.DefaultFontHeight := DefaultFontHeight;
AuxFuncs.DataFontHeight := DataFontHeight;
Changed;
end;
//----------------------------------------------------------------------------------------------------------------------
function TMYXCommonOptions.RestoreWindowPos(Win: TTntForm; DoSize: Boolean): Boolean;
begin
if (StoreWindowsPositions) then
Result := inherited RestoreWindowpos(Win, DoSize)
else
Result := False;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMYXCommonOptions.StoreOptions;
var
Options: TMYX_APPLICATION_OPTIONS;
OptionGroup: TMYX_OPTION_GROUP;
ExePath: WideString;
i: integer;
begin
ExePath := ExtractFilePath(Application.ExeName);
//Create Application Options
Options := TMYX_APPLICATION_OPTIONS.create;
try
//-----------------------------------------------
//Create Option Group
OptionGroup := TMYX_OPTION_GROUP.create('General');
Options.option_groups.Add(OptionGroup);
//Add Values
AddParam(OptionGroup, 'Language', Language);
AddParam(OptionGroup, 'PasswordStorageType',
IntToStr(Ord(PasswordStorageType)));
AddParam(OptionGroup, 'StoreWindowsPositions',
IntToStr(Ord(StoreWindowsPositions)));
AddParam(OptionGroup, 'ShowTipOfDay',
IntToStr(Ord(ShowTipOfDay)));
AddParam(OptionGroup, 'Language', Language);
AddParam(OptionGroup, 'DisableTransparencyEffects',
IntToStr(Ord(DisableTransparencyEffects)));
AddParam(OptionGroup, 'IgnoreWarningsList',
AnsiReplaceText(IgnoreWarningsList.Text, #13#10, '#13#10'));
//------------------------------------------------------
//Create Option Group
OptionGroup := TMYX_OPTION_GROUP.create('Editors');
Options.option_groups.Add(OptionGroup);
AddParam(OptionGroup, 'EditorTableShowSQLBeforeApplying',
IntToStr(Ord(EditorTableShowSQLBeforeApplying)));
AddParam(OptionGroup, 'EditorTableAllColumnsNotNullPerDef',
IntToStr(Ord(EditorTableAllColumnsNotNullPerDef)));
AddParam(OptionGroup, 'EditorTableIntegerUnsignedPerDef',
IntToStr(Ord(EditorTableIntegerUnsignedPerDef)));
AddParam(OptionGroup, 'EditorTablePKDataType', EditorTablePKDataType);
AddParam(OptionGroup, 'EditorTablePKAutoNaming', EditorTablePKAutoNaming);
AddParam(OptionGroup, 'EditorTableIndexAutoNaming', EditorTableIndexAutoNaming);
AddParam(OptionGroup, 'EditorTableFKAutoNaming', EditorTableFKAutoNaming);
AddParam(OptionGroup, 'EditorTableDefaultStorageEngine', EditorTableDefaultStorageEngine);
//------------------------------------------------------
//Create Option Group
OptionGroup := TMYX_OPTION_GROUP.create('Fonts');
Options.option_groups.Add(OptionGroup);
AddParam(OptionGroup, 'DefaultFontName', DefaultFontName);
AddParam(OptionGroup, 'DataFontName', DataFontName);
AddParam(OptionGroup, 'CodeFontName', CodeFontName);
AddParam(OptionGroup, 'DefaultFontHeight', IntToStr(DefaultFontHeight));
AddParam(OptionGroup, 'DataFontHeight', IntToStr(DataFontHeight));
AddParam(OptionGroup, 'CodeFontWidth', IntToStr(CodeFontWidth));
AddParam(OptionGroup, 'CodeFontHeight', IntToStr(CodeFontHeight));
AddParam(OptionGroup, 'CodeFontCharset', IntToStr(CodeFontCharset));
//-----------------------------------------------
//Create Option Group
OptionGroup := TMYX_OPTION_GROUP.create('WindowPos');
Options.option_groups.Add(OptionGroup);
//Store all window positions
for i := 0 to WindowPosList.Count - 1 do
AddParam(OptionGroup, WindowPosList[i],
TMyxWindowPos(WindowPosList.Objects[i]).AsWideString);
//-----------------------------------------------
//Store Options to file
myx_store_application_options(Options.get_record_pointer, UserDataDir + 'mysqlx_common_options.xml');
Changed;
finally
Options.Free;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
constructor TApplicationOptionsForm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
OptionsImgNames := TTntStringList.Create;
DockOptionPageControl := nil;
DoPageContentChanged := nil;
end;
//----------------------------------------------------------------------------------------------------------------------
destructor TApplicationOptionsForm.Destroy;
begin
OptionsImgNames.Free;
inherited Destroy;
end;
//----------------------------------------------------------------------------------------------------------------------
end.
|