Reverted trunk back to revision 38 (base for 1.0.6 release branch)

This commit is contained in:
Mark van Renswoude 2015-03-14 09:46:57 +00:00
parent 6aca2ebe1b
commit 77cf10ddf6
16 changed files with 1114 additions and 1512 deletions

View File

@ -1,45 +0,0 @@
object ButtonAssignmentFrame: TButtonAssignmentFrame
Left = 0
Top = 0
Width = 261
Height = 41
TabOrder = 0
DesignSize = (
261
41)
object lblFunction: TLabel
Left = 53
Top = 6
Width = 208
Height = 13
Anchors = [akLeft, akTop, akRight]
AutoSize = False
Caption = '[runtime: function]'
EllipsisPosition = epEndEllipsis
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = [fsBold]
ParentFont = False
end
object lblCategory: TLabel
Left = 53
Top = 22
Width = 208
Height = 13
Anchors = [akLeft, akTop, akRight]
AutoSize = False
Caption = '[runtime: category]'
EllipsisPosition = epEndEllipsis
end
object btnConfiguration: TButton
Left = 0
Top = 0
Width = 41
Height = 41
Caption = 'P&?'
TabOrder = 0
OnClick = btnConfigurationClick
end
end

View File

@ -1,87 +0,0 @@
unit ButtonAssignmentFrm;
interface
uses
System.Classes,
Vcl.Controls,
Vcl.Forms,
Vcl.StdCtrls;
type
TButtonAssignmentFrame = class(TFrame)
btnConfiguration: TButton;
lblFunction: TLabel;
lblCategory: TLabel;
procedure btnConfigurationClick(Sender: TObject);
private
FLEDIndex: Integer;
FOnConfigurationClick: TNotifyEvent;
function GetCategoryName: string;
function GetFunctionName: string;
procedure SetCategoryName(const Value: string);
procedure SetFunctionName(const Value: string);
public
constructor Create(AOwner: TComponent); override;
property LEDIndex: Integer read FLEDIndex write FLEDIndex;
property CategoryName: string read GetCategoryName write SetCategoryName;
property FunctionName: string read GetFunctionName write SetFunctionName;
property OnConfigurationClick: TNotifyEvent read FOnConfigurationClick write FOnConfigurationClick;
end;
implementation
uses
Graphics;
{$R *.dfm}
{ TButtonAssignmentFrame }
constructor TButtonAssignmentFrame.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
lblCategory.Font.Color := clGrayText;
SetCategoryName('');
SetFunctionName('');
end;
function TButtonAssignmentFrame.GetCategoryName: string;
begin
Result := lblCategory.Caption;
end;
function TButtonAssignmentFrame.GetFunctionName: string;
begin
Result := lblFunction.Caption;
end;
procedure TButtonAssignmentFrame.SetCategoryName(const Value: string);
begin
lblCategory.Caption := Value;
end;
procedure TButtonAssignmentFrame.SetFunctionName(const Value: string);
begin
lblFunction.Caption := Value;
end;
procedure TButtonAssignmentFrame.btnConfigurationClick(Sender: TObject);
begin
if Assigned(FOnConfigurationClick) then
FOnConfigurationClick(Self);
end;
end.

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,7 @@
unit MainFrm;
// #ToDo1 -oMvR: 3-3-2013: trigger profile update when Save As only changes the name
interface
uses
System.Classes,
@ -19,12 +21,11 @@ uses
pngimage,
X2UtPersistIntf,
ButtonAssignmentFrm,
FSXSimConnectIntf,
LEDStateConsumer,
Profile,
ProfileManager,
Settings, VirtualTrees, Vcl.ImgList, Vcl.ActnList, Vcl.ToolWin, Vcl.Menus;
Settings;
const
@ -44,6 +45,13 @@ const
type
TLEDControls = record
ConfigureButton: TButton;
CategoryLabel: TLabel;
FunctionLabel: TLabel;
end;
TMainForm = class(TForm, IProfileObserver)
imgStateNotFound: TImage;
lblG940Throttle: TLabel;
@ -64,6 +72,35 @@ type
btnCheckUpdates: TButton;
lblProxy: TLabel;
tsButtons: TTabSheet;
btnP1: TButton;
lblP1Function: TLabel;
lblP1Category: TLabel;
btnP2: TButton;
lblP2Function: TLabel;
lblP2Category: TLabel;
btnP3: TButton;
lblP3Function: TLabel;
lblP3Category: TLabel;
btnP4: TButton;
lblP4Function: TLabel;
lblP4Category: TLabel;
btnP5: TButton;
lblP5Function: TLabel;
lblP5Category: TLabel;
btnP6: TButton;
lblP6Function: TLabel;
lblP6Category: TLabel;
btnP7: TButton;
lblP7Function: TLabel;
lblP7Category: TLabel;
btnP8: TButton;
lblP8Function: TLabel;
lblP8Category: TLabel;
lblProfile: TLabel;
cmbProfiles: TComboBox;
btnSaveProfile: TButton;
btnDeleteProfile: TButton;
bvlProfiles: TBevel;
pnlFSX: TPanel;
imgFSXStateNotConnected: TImage;
imgFSXStateConnected: TImage;
@ -75,44 +112,11 @@ type
cbProfileMenuCascaded: TCheckBox;
lblProfileSwitching: TLabel;
bvlProfileSwitching: TBevel;
TrayIcon: TTrayIcon;
bafP1: TButtonAssignmentFrame;
bafP2: TButtonAssignmentFrame;
bafP3: TButtonAssignmentFrame;
bafP4: TButtonAssignmentFrame;
bafP5: TButtonAssignmentFrame;
bafP6: TButtonAssignmentFrame;
bafP7: TButtonAssignmentFrame;
bafP8: TButtonAssignmentFrame;
vstProfile: TVirtualStringTree;
pnlProfiles: TPanel;
tbProfiles: TToolBar;
tbNewProfile: TToolButton;
tbSaveProfile: TToolButton;
ActionList: TActionList;
actNewProfile: TAction;
actSaveProfile: TAction;
actRevertProfile: TAction;
tbRevertProfile: TToolButton;
ImageList: TImageList;
tbDeleteProfile: TToolButton;
actDeleteProfile: TAction;
ToolButton1: TToolButton;
tbSetActiveProfile: TToolButton;
actSetActiveProfile: TAction;
pmnProfiles: TPopupMenu;
pmnProfilesNew: TMenuItem;
pmnProfilesSave: TMenuItem;
pmnProfilesRevert: TMenuItem;
pmnProfilesDelete: TMenuItem;
pmnProfilesSetActive: TMenuItem;
pmnProfilesSep1: TMenuItem;
tbRenameProfile: TToolButton;
actRenameProfile: TAction;
procedure FormCreate(Sender: TObject);
procedure lblLinkLinkClick(Sender: TObject; const Link: string; LinkType: TSysLinkType);
procedure btnCheckUpdatesClick(Sender: TObject);
procedure LEDButtonClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure cmbProfilesClick(Sender: TObject);
procedure cbCheckUpdatesClick(Sender: TObject);
@ -120,14 +124,8 @@ type
procedure btnDeleteProfileClick(Sender: TObject);
procedure cbProfileMenuClick(Sender: TObject);
procedure cbProfileMenuCascadedClick(Sender: TObject);
procedure actNewProfileExecute(Sender: TObject);
procedure actSaveProfileExecute(Sender: TObject);
procedure actRevertProfileExecute(Sender: TObject);
procedure actSetActiveProfileExecute(Sender: TObject);
procedure actDeleteProfileExecute(Sender: TObject);
procedure actRenameProfileExecute(Sender: TObject);
private
FLEDControls: array[0..LED_COUNT - 1] of TButtonAssignmentFrame;
FLEDControls: array[0..LED_COUNT - 1] of TLEDControls;
FEventMonitor: TOmniEventMonitor;
FProfilesFilename: string;
@ -182,8 +180,6 @@ type
procedure HandleDeviceStateMessage(AMessage: TOmniMessage);
procedure HandleFSXStateMessage(AMessage: TOmniMessage);
procedure LEDConfigurationClick(Sender: TObject);
procedure CMAskAutoUpdate(var Msg: TMessage); message CM_ASKAUTOUPDATE;
property EventMonitor: TOmniEventMonitor read FEventMonitor;
@ -291,7 +287,7 @@ begin
worker := TFSXStateMonitorWorker.Create;
EventMonitor.Monitor(CreateTask(worker)).Run;
Profiles.Attach(Self);
TProfileManager.Attach(Self);
FindLEDControls;
@ -310,7 +306,7 @@ begin
FinalizeProfileMenu;
UnregisterDeviceArrival;
Profiles.Detach(Self);
TProfileManager.Detach(Self);
end;
@ -382,7 +378,7 @@ var
profile: TProfile;
begin
profile := Profiles.ActiveProfile;
profile := TProfileManager.Instance.ActiveProfile;
if Settings.ActiveProfile <> profile.Name then
begin
@ -390,13 +386,12 @@ begin
SaveSettings;
end;
// #ToDo1 -oMvR: 21-4-2013: invalidate profile node
// FLockChangeProfile := True;
// try
// cmbProfiles.ItemIndex := cmbProfiles.Items.IndexOfObject(profile);
// finally
// FLockChangeProfile := False;
// end;
FLockChangeProfile := True;
try
cmbProfiles.ItemIndex := cmbProfiles.Items.IndexOfObject(profile);
finally
FLockChangeProfile := False;
end;
LoadActiveProfile;
end;
@ -416,17 +411,20 @@ procedure TMainForm.FindLEDControls;
var
ledIndex: Integer;
ledNumber: string;
buttonFrame: TButtonAssignmentFrame;
begin
for ledIndex := 0 to Pred(LED_COUNT) do
begin
ledNumber := IntToStr(Succ(ledIndex));
buttonFrame := (ComponentByName('bafP' + ledNumber, ledIndex) as TButtonAssignmentFrame);
buttonFrame.OnConfigurationClick := LEDConfigurationClick;
FLEDControls[ledIndex].ConfigureButton := (ComponentByName('btnP' + ledNumber, ledIndex) as TButton);
FLEDControls[ledIndex].CategoryLabel := (ComponentByName('lblP' + ledNumber + 'Category', ledIndex) as TLabel);
FLEDControls[ledIndex].FunctionLabel := (ComponentByName('lblP' + ledNumber + 'Function', ledIndex) as TLabel);
FLEDControls[ledIndex] := buttonFrame;
FLEDControls[ledIndex].ConfigureButton.OnClick := LEDButtonClick;
FLEDControls[ledIndex].CategoryLabel.Caption := '';
FLEDControls[ledIndex].CategoryLabel.Font.Color := clGrayText;
FLEDControls[ledIndex].FunctionLabel.Caption := '';
end;
end;
@ -456,43 +454,43 @@ begin
begin
Debug.Log('UI: Succesfully converted 0.x profile');
defaultProfile.Name := DefaultProfileName;
defaultProfile.IsTemporary := True;
end;
if Assigned(defaultProfile) then
Profiles.Add(defaultProfile);
TProfileManager.Add(defaultProfile);
end else
begin
persistXML := TX2UtPersistXML.Create;
try
persistXML.FileName := FProfilesFilename;
Profiles.Load(persistXML.CreateReader);
TProfileManager.Load(persistXML.CreateReader);
finally
FreeAndNil(persistXML);
end;
end;
{ Make sure we always have a profile }
if Profiles.Count = 0 then
if TProfileManager.Instance.Count = 0 then
begin
Debug.Log('UI: No profiles found, creating default profile');
Profiles.Add(CreateDefaultProfile);
TProfileManager.Add(CreateDefaultProfile);
end;
// #ToDo1 -oMvR: 21-4-2013: load tree
// FLockChangeProfile := True;
// try
// cmbProfiles.Items.BeginUpdate;
// try
// cmbProfiles.Items.Clear;
//
// for profile in TProfileManager.Instance do
// cmbProfiles.Items.AddObject(profile.Name, profile);
// finally
// cmbProfiles.Items.EndUpdate;
// end;
// finally
// FLockChangeProfile := False;
// end;
FLockChangeProfile := True;
try
cmbProfiles.Items.BeginUpdate;
try
cmbProfiles.Items.Clear;
for profile in TProfileManager.Instance do
cmbProfiles.Items.AddObject(profile.Name, profile);
finally
cmbProfiles.Items.EndUpdate;
end;
finally
FLockChangeProfile := False;
end;
finally
Debug.UnIndent;
end;
@ -509,7 +507,7 @@ begin
persistXML := TX2UtPersistXML.Create;
try
persistXML.FileName := FProfilesFilename;
Profiles.Save(persistXML.CreateWriter);
TProfileManager.Instance.Save(persistXML.CreateWriter);
finally
FreeAndNil(persistXML);
end;
@ -554,22 +552,13 @@ begin
{ Default profile }
profile := nil;
if Length(Settings.ActiveProfile) > 0 then
begin
{ Version 0.2 used the profile name, not a UID }
if Settings.ActiveProfile[1] <> '{' then
begin
profile := Profiles.FindByName(Settings.ActiveProfile);
if Assigned(profile) then
Settings.ActiveProfile := profile.UID;
end else
profile := Profiles.FindByUID(Settings.ActiveProfile);
end;
profile := TProfileManager.Instance.Find(Settings.ActiveProfile);
{ LoadProfiles ensures there's always at least 1 profile }
if (not Assigned(profile)) and (Profiles.Count > 0) then
profile := Profiles[0];
if (not Assigned(profile)) and (TProfileManager.Instance.Count > 0) then
profile := TProfileManager.Instance[0];
Profiles.ActiveProfile := profile;
TProfileManager.Instance.ActiveProfile := profile;
{ Auto-update }
cbCheckUpdates.Checked := Settings.CheckUpdates;
@ -612,7 +601,7 @@ begin
{ Default button functions are assigned during UpdateButton }
Result := TProfile.Create;
Result.Name := DefaultProfileName;
// Result.IsTemporary := True;
Result.IsTemporary := True;
end;
@ -622,8 +611,7 @@ var
buttonIndex: Integer;
begin
// #ToDo1 -oMvR: 21-4-2013: change to LoadSelectedProfile
activeProfile := Profiles.ActiveProfile;
activeProfile := TProfileManager.Instance.ActiveProfile;
if not Assigned(activeProfile) then
exit;
@ -664,52 +652,16 @@ begin
if Assigned(buttonFunction) then
begin
FLEDControls[AButtonIndex].CategoryName := buttonFunction.GetCategoryName;
FLEDControls[AButtonIndex].FunctionName := buttonFunction.GetDisplayName;
FLEDControls[AButtonIndex].CategoryLabel.Caption := buttonFunction.GetCategoryName;
FLEDControls[AButtonIndex].FunctionLabel.Caption := buttonFunction.GetDisplayName;
end;
end;
procedure TMainForm.actDeleteProfileExecute(Sender: TObject);
begin
//
end;
procedure TMainForm.actNewProfileExecute(Sender: TObject);
begin
//
end;
procedure TMainForm.actRenameProfileExecute(Sender: TObject);
begin
//
end;
procedure TMainForm.actRevertProfileExecute(Sender: TObject);
begin
//
end;
procedure TMainForm.actSaveProfileExecute(Sender: TObject);
begin
//
end;
procedure TMainForm.actSetActiveProfileExecute(Sender: TObject);
begin
//
end;
procedure TMainForm.AddProfile(AProfile: TProfile);
begin
// cmbProfiles.Items.AddObject(AProfile.Name, AProfile);
Profiles.Add(AProfile, True);
cmbProfiles.Items.AddObject(AProfile.Name, AProfile);
TProfileManager.Instance.Add(AProfile, True);
end;
@ -719,18 +671,18 @@ var
oldItemIndex: Integer;
begin
// itemIndex := cmbProfiles.Items.IndexOfObject(AProfile);
// if itemIndex > -1 then
// begin
// oldItemIndex := cmbProfiles.ItemIndex;
// FLockChangeProfile := True;
// try
// cmbProfiles.Items[itemIndex] := AProfile.Name;
// cmbProfiles.ItemIndex := oldItemIndex;
// finally
// FLockChangeProfile := False;
// end;
// end;
itemIndex := cmbProfiles.Items.IndexOfObject(AProfile);
if itemIndex > -1 then
begin
oldItemIndex := cmbProfiles.ItemIndex;
FLockChangeProfile := True;
try
cmbProfiles.Items[itemIndex] := AProfile.Name;
cmbProfiles.ItemIndex := oldItemIndex;
finally
FLockChangeProfile := False;
end;
end;
end;
@ -739,39 +691,39 @@ var
itemIndex: Integer;
begin
// itemIndex := cmbProfiles.Items.IndexOfObject(AProfile);
// if itemIndex > -1 then
// begin
// TProfileManager.Remove(AProfile);
// cmbProfiles.Items.Delete(itemIndex);
//
// if TProfileManager.Instance.Count = 0 then
// AddProfile(CreateDefaultProfile);
//
// if ASetActiveProfile then
// begin
// if itemIndex >= TProfileManager.Instance.Count then
// itemIndex := Pred(TProfileManager.Instance.Count);
//
// FLockChangeProfile := True;
// try
// cmbProfiles.ItemIndex := itemIndex;
// TProfileManager.Instance.ActiveProfile := TProfile(cmbProfiles.Items.Objects[itemIndex]);
// finally
// FLockChangeProfile := False;
// end;
// end;
// end;
itemIndex := cmbProfiles.Items.IndexOfObject(AProfile);
if itemIndex > -1 then
begin
TProfileManager.Remove(AProfile);
cmbProfiles.Items.Delete(itemIndex);
if TProfileManager.Instance.Count = 0 then
AddProfile(CreateDefaultProfile);
if ASetActiveProfile then
begin
if itemIndex >= TProfileManager.Instance.Count then
itemIndex := Pred(TProfileManager.Instance.Count);
FLockChangeProfile := True;
try
cmbProfiles.ItemIndex := itemIndex;
TProfileManager.Instance.ActiveProfile := TProfile(cmbProfiles.Items.Objects[itemIndex]);
finally
FLockChangeProfile := False;
end;
end;
end;
end;
procedure TMainForm.cmbProfilesClick(Sender: TObject);
begin
// if not FLockChangeProfile then
// begin
// if cmbProfiles.ItemIndex > -1 then
// TProfileManager.Instance.ActiveProfile := TProfile(cmbProfiles.Items.Objects[cmbProfiles.ItemIndex]);
// end;
if not FLockChangeProfile then
begin
if cmbProfiles.ItemIndex > -1 then
TProfileManager.Instance.ActiveProfile := TProfile(cmbProfiles.Items.Objects[cmbProfiles.ItemIndex]);
end;
end;
@ -834,7 +786,7 @@ begin
end;
procedure TMainForm.LEDConfigurationClick(Sender: TObject);
procedure TMainForm.LEDButtonClick(Sender: TObject);
function GetUniqueProfileName(const AName: string): string;
var
@ -844,15 +796,14 @@ procedure TMainForm.LEDConfigurationClick(Sender: TObject);
Result := AName;
counter := 0;
// while Assigned(Profiles.Find(Result)) do
// begin
// Inc(counter);
// Result := Format('%s (%d)', [AName, counter]);
// end;
while Assigned(TProfileManager.Find(Result)) do
begin
Inc(counter);
Result := Format('%s (%d)', [AName, counter]);
end;
end;
// #ToDo1 -oMvR: 6-5-2013: new style!
var
activeProfile: TProfile;
buttonIndex: NativeInt;
@ -860,25 +811,25 @@ var
newProfile: Boolean;
begin
activeProfile := Profiles.ActiveProfile;
activeProfile := TProfileManager.Instance.ActiveProfile;
if not Assigned(activeProfile) then
exit;
{ Behaviour similar to the Windows System Sounds control panel;
when a change occurs, create a temporary profile "(modified)"
so the original profile can still be selected }
// if not activeProfile.IsTemporary then
// begin
// profile := TProfile.Create;
// profile.Assign(activeProfile);
// profile.Name := GetUniqueProfileName(profile.Name + ProfilePostfixModified);
// profile.IsTemporary := True;
// newProfile := True;
// end else
// begin
if not activeProfile.IsTemporary then
begin
profile := TProfile.Create;
profile.Assign(activeProfile);
profile.Name := GetUniqueProfileName(profile.Name + ProfilePostfixModified);
profile.IsTemporary := True;
newProfile := True;
end else
begin
profile := activeProfile;
newProfile := False;
// end;
end;
buttonIndex := (Sender as TComponent).Tag;
if TButtonFunctionForm.Execute(profile, buttonIndex) then
@ -1004,13 +955,13 @@ var
begin
name := '';
profile := Profiles.ActiveProfile;
profile := TProfileManager.Instance.ActiveProfile;
existingProfile := nil;
repeat
if InputQuery('Save profile as', 'Save this profile as:', name) then
begin
existingProfile := Profiles.FindByName(name);
existingProfile := TProfileManager.Find(name);
if existingProfile = profile then
existingProfile := nil;
@ -1035,24 +986,24 @@ begin
existingProfile.Assign(profile);
existingProfile.Name := name;
UpdateProfile(existingProfile);
Profiles.ActiveProfile := existingProfile;
TProfileManager.Instance.ActiveProfile := existingProfile;
// if profile.IsTemporary then
// DeleteProfile(profile, False);
if profile.IsTemporary then
DeleteProfile(profile, False);
end else
begin
// if profile.IsTemporary then
// begin
// profile.Name := name;
// profile.IsTemporary := False;
// UpdateProfile(profile);
// end else
// begin
if profile.IsTemporary then
begin
profile.Name := name;
profile.IsTemporary := False;
UpdateProfile(profile);
end else
begin
newProfile := TProfile.Create;
newProfile.Assign(profile);
newProfile.Name := name;
AddProfile(newProfile);
// end;
end;
end;
SaveProfiles;
@ -1064,7 +1015,7 @@ var
activeProfile: TProfile;
begin
activeProfile := Profiles.ActiveProfile;
activeProfile := TProfileManager.Instance.ActiveProfile;
if Assigned(activeProfile) then
begin
if MessageBox(Self.Handle, PChar(Format('Do you want to remove the profile named "%s"?', [activeProfile.Name])),

View File

@ -1,8 +1,8 @@
program G940LEDControl;
uses
System.SysUtils,
Vcl.Forms,
Forms,
SysUtils,
MainFrm in 'Forms\MainFrm.pas' {MainForm},
LogiJoystickDLL in '..\Shared\LogiJoystickDLL.pas',
SimConnect in '..\Shared\SimConnect.pas',
@ -36,8 +36,7 @@ uses
FSXLEDFunctionProviderIntf in 'Units\FSXLEDFunctionProviderIntf.pas',
GxDbugIntf in 'Units\GxDbugIntf.pas',
DebugLog in 'Units\DebugLog.pas',
DebugLogGExperts in 'Units\DebugLogGExperts.pas',
ButtonAssignmentFrm in 'Forms\ButtonAssignmentFrm.pas' {ButtonAssignmentFrame: TFrame};
DebugLogGExperts in 'Units\DebugLogGExperts.pas';
{$R *.res}

View File

@ -8,7 +8,7 @@
<FrameworkType>VCL</FrameworkType>
<ProjectVersion>13.4</ProjectVersion>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<Config Condition="'$(Config)'==''">Release</Config>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
<TargetedPlatforms>1</TargetedPlatforms>
<AppType>Application</AppType>
@ -148,11 +148,6 @@
<DCCReference Include="Units\GxDbugIntf.pas"/>
<DCCReference Include="Units\DebugLog.pas"/>
<DCCReference Include="Units\DebugLogGExperts.pas"/>
<DCCReference Include="Forms\ButtonAssignmentFrm.pas">
<Form>ButtonAssignmentFrame</Form>
<FormType>dfm</FormType>
<DesignClass>TFrame</DesignClass>
</DCCReference>
<BuildConfiguration Include="Debug">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -118,7 +118,6 @@ type
FProfileMenu: Boolean;
FProfileMenuCascaded: Boolean;
// #ToDo1 -oMvR: 6-5-2013: change to object list
FMenuProfiles: TStringList;
FMenuWasCascaded: Boolean;
protected
@ -312,9 +311,9 @@ begin
if AEnabled <> FObservingProfileManager then
begin
if AEnabled then
Profiles.Attach(Self)
TProfileManager.Attach(Self)
else
Profiles.Detach(Self);
TProfileManager.Detach(Self);
FObservingProfileManager := AEnabled;
end;
@ -553,9 +552,9 @@ begin
exit;
profileName := FMenuProfiles[Pred(AEventID)];
profile := Profiles.FindByUID(profileName);
profile := TProfileManager.Find(profileName);
if Assigned(profile) then
Profiles.ActiveProfile := profile;
TProfileManager.Instance.ActiveProfile := profile;
end;
@ -686,12 +685,8 @@ begin
if ProfileMenu then
begin
try
for profile in Profiles.LockList do
FMenuProfiles.Add(profile.Name);
finally
Profiles.UnlockList;
end;
for profile in TProfileManager.Instance do
FMenuProfiles.Add(profile.Name);
FMenuProfiles.Sort;

View File

@ -44,8 +44,8 @@ type
TProfile = class(TPersistent)
private
FUID: string;
FName: string;
FIsTemporary: Boolean;
FButtons: TProfileButtonList;
function GetButton(Index: Integer): TProfileButton;
@ -61,8 +61,8 @@ type
function HasButton(AIndex: Integer): Boolean;
property UID: string read FUID write FUID;
property Name: string read FName write FName;
property IsTemporary: Boolean read FIsTemporary write FIsTemporary;
property ButtonCount: Integer read GetButtonCount;
property Buttons[Index: Integer]: TProfileButton read GetButton;
@ -71,7 +71,7 @@ type
TProfileList = class(TObjectList<TProfile>)
public
// function Find(const AName: string): TProfile;
function Find(const AName: string): TProfile;
procedure Load(AReader: IX2PersistReader);
procedure Save(AWriter: IX2PersistWriter);
@ -92,6 +92,7 @@ const
KeyProviderUID = 'ProviderUID';
KeyFunctionUID = 'FunctionUID';
KeyIsTemporary = 'IsTemporary';
{ TProfileButton }
@ -231,8 +232,8 @@ begin
begin
sourceProfile := TProfile(Source);
FUID := sourceProfile.UID;
FName := sourceProfile.Name;
FIsTemporary := sourceProfile.IsTemporary;
FButtons.Clear;
for buttonIndex := 0 to Pred(sourceProfile.ButtonCount) do
@ -250,8 +251,8 @@ var
begin
buttonIndex := 0;
// if not AReader.ReadBoolean(KeyIsTemporary, FIsTemporary) then
// FIsTemporary := False;
if not AReader.ReadBoolean(KeyIsTemporary, FIsTemporary) then
FIsTemporary := False;
while AReader.BeginSection(SectionButton + IntToStr(buttonIndex)) do
try
@ -276,7 +277,7 @@ var
buttonIndex: Integer;
begin
// AWriter.WriteBoolean(KeyIsTemporary, IsTemporary);
AWriter.WriteBoolean(KeyIsTemporary, IsTemporary);
for buttonIndex := 0 to Pred(FButtons.Count) do
begin
@ -329,7 +330,6 @@ end;
{ TProfileList }
{
function TProfileList.Find(const AName: string): TProfile;
var
profile: TProfile;
@ -344,7 +344,6 @@ begin
break;
end;
end;
}
procedure TProfileList.Load(AReader: IX2PersistReader);

View File

@ -3,6 +3,7 @@ unit ProfileManager;
interface
uses
System.Classes,
System.SyncObjs,
Profile,
X2UtPersistIntf;
@ -20,53 +21,57 @@ type
TProfileManager = class;
ILockedProfileList = interface
['{4F647762-AA70-4315-BB1C-E85E320F4E82}']
function GetEnumerator: TProfileList.TEnumerator;
TProfileManagerEnumerator = class(TProfileList.TEnumerator)
private
FManager: TProfileManager;
public
constructor Create(AManager: TProfileManager);
destructor Destroy; override;
end;
TProfileManager = class(TObject)
private
FLock: TCriticalSection;
FProfiles: TProfileList;
FObservers: TInterfaceList;
FProfileList: TProfileList;
FActiveProfile: TProfile;
function GetActiveProfile: TProfile;
function GetCount: Integer;
function GetItem(Index: Integer): TProfile;
procedure SetActiveProfile(const Value: TProfile);
procedure SetItem(Index: Integer; const Value: TProfile);
protected
property Observers: TInterfaceList read FObservers;
property ProfileList: TProfileList read FProfileList;
property Profiles: TProfileList read FProfiles;
public
class function Instance(): TProfileManager;
constructor Create;
destructor Destroy; override;
procedure Add(AProfile: TProfile; ASetActive: Boolean = False);
function FindByName(const AName: string): TProfile;
function FindByUID(const AName: string): TProfile;
function Remove(const AProfile: TProfile): Integer;
procedure Lock;
procedure Unlock;
procedure Load(AReader: IX2PersistReader);
procedure Save(AWriter: IX2PersistWriter);
class procedure Add(AProfile: TProfile; ASetActive: Boolean = False);
class function Find(const AName: string): TProfile;
class function Remove(const AProfile: TProfile): Integer;
procedure Attach(AObserver: IProfileObserver);
procedure Detach(AObserver: IProfileObserver);
class procedure Load(AReader: IX2PersistReader);
class procedure Save(AWriter: IX2PersistWriter);
function LockList: ILockedProfileList;
procedure UnlockList;
class procedure Attach(AObserver: IProfileObserver);
class procedure Detach(AObserver: IProfileObserver);
property ActiveProfile: TProfile read FActiveProfile write SetActiveProfile;
function GetEnumerator: TProfileManagerEnumerator;
property ActiveProfile: TProfile read GetActiveProfile write SetActiveProfile;
property Count: Integer read GetCount;
property Items[Index: Integer]: TProfile read GetItem write SetItem; default;
end;
{ Singleton }
function Profiles: TProfileManager;
implementation
@ -78,20 +83,8 @@ var
ProfileManagerInstance: TProfileManager;
type
TLockedProfileList = class(TInterfacedObject, ILockedProfileList)
private
FList: TProfileList;
public
constructor Create(AList: TProfileList);
function GetEnumerator: TProfileList.TEnumerator;
end;
function Profiles: TProfileManager;
{ TProfileManager }
class function TProfileManager.Instance: TProfileManager;
begin
if not Assigned(ProfileManagerInstance) then
ProfileManagerInstance := TProfileManager.Create;
@ -100,130 +93,136 @@ begin
end;
{ TProfileManager }
constructor TProfileManager.Create;
begin
inherited Create;
FObservers := TInterfaceList.Create;
FProfileList := TProfileList.Create(True);
FProfiles := TProfileList.Create(True);
FLock := TCriticalSection.Create;
end;
destructor TProfileManager.Destroy;
begin
FreeAndNil(FProfileList);
FreeAndNil(FLock);
FreeAndNil(FProfiles);
FreeAndNil(FObservers);
inherited;
end;
procedure TProfileManager.Add(AProfile: TProfile; ASetActive: Boolean);
procedure TProfileManager.Lock;
begin
end;
procedure TProfileManager.Unlock;
begin
end;
class procedure TProfileManager.Add(AProfile: TProfile; ASetActive: Boolean);
var
observer: IInterface;
begin
TMonitor.Enter(ProfileList);
Instance.Lock;
try
ProfileList.Add(AProfile);
Instance.Profiles.Add(AProfile);
finally
TMonitor.Exit(ProfileList);
Instance.Unlock;
end;
for observer in Observers do
for observer in Instance.Observers do
(observer as IProfileObserver).ObserveAdd(AProfile);
if ASetActive then
SetActiveProfile(AProfile);
Instance.SetActiveProfile(AProfile);
end;
function TProfileManager.FindByName(const AName: string): TProfile;
class function TProfileManager.Find(const AName: string): TProfile;
begin
// Result := Instance.ProfileList.Find(AName);
Result := Instance.Profiles.Find(AName);
end;
function TProfileManager.FindByUID(const AName: string): TProfile;
begin
//
end;
function TProfileManager.Remove(const AProfile: TProfile): Integer;
class function TProfileManager.Remove(const AProfile: TProfile): Integer;
var
observer: IInterface;
begin
TMonitor.Enter(ProfileList);
Instance.Lock;
try
Result := ProfileList.Remove(AProfile);
Result := Instance.Profiles.Remove(AProfile);
finally
TMonitor.Exit(ProfileList);
Instance.Unlock;
end;
for observer in Observers do
for observer in Instance.Observers do
(observer as IProfileObserver).ObserveRemove(AProfile);
end;
procedure TProfileManager.Load(AReader: IX2PersistReader);
class procedure TProfileManager.Load(AReader: IX2PersistReader);
begin
TMonitor.Enter(ProfileList);
Instance.Lock;
try
ProfileList.Load(AReader);
Instance.Profiles.Load(AReader);
finally
TMonitor.Exit(ProfileList);
Instance.Unlock;
end;
end;
procedure TProfileManager.Save(AWriter: IX2PersistWriter);
class procedure TProfileManager.Save(AWriter: IX2PersistWriter);
begin
TMonitor.Enter(ProfileList);
Instance.Lock;
try
ProfileList.Save(AWriter);
Instance.Profiles.Save(AWriter);
finally
TMonitor.Exit(ProfileList);
Instance.Unlock;
end;
end;
procedure TProfileManager.Attach(AObserver: IProfileObserver);
class procedure TProfileManager.Attach(AObserver: IProfileObserver);
begin
Observers.Add(AObserver as IProfileObserver);
Instance.Observers.Add(AObserver as IProfileObserver);
end;
procedure TProfileManager.Detach(AObserver: IProfileObserver);
class procedure TProfileManager.Detach(AObserver: IProfileObserver);
begin
Observers.Remove(AObserver as IProfileObserver);
Instance.Observers.Remove(AObserver as IProfileObserver);
end;
function TProfileManager.LockList: ILockedProfileList;
function TProfileManager.GetActiveProfile: TProfile;
begin
TMonitor.Enter(ProfileList);
Result := TLockedProfileList.Create(ProfileList);
end;
procedure TProfileManager.UnlockList;
begin
TMonitor.Exit(ProfileList);
Result := Instance.FActiveProfile;
end;
function TProfileManager.GetCount: Integer;
begin
Result := ProfileList.Count;
Result := Instance.Profiles.Count;
end;
function TProfileManager.GetEnumerator: TProfileManagerEnumerator;
begin
Result := TProfileManagerEnumerator.Create(Self);
end;
function TProfileManager.GetItem(Index: Integer): TProfile;
begin
Result := ProfileList[Index];
Result := Profiles[Index];
end;
@ -243,24 +242,26 @@ end;
procedure TProfileManager.SetItem(Index: Integer; const Value: TProfile);
begin
ProfileList[Index] := Value;
Profiles[Index] := Value;
end;
{ TLockedProfileList }
constructor TLockedProfileList.Create(AList: TProfileList);
{ TProfileManagerEnumerator }
constructor TProfileManagerEnumerator.Create(AManager: TProfileManager);
begin
inherited Create;
inherited Create(AManager.Profiles);
FList := AList;
FManager := AManager;
FManager.Lock;
end;
function TLockedProfileList.GetEnumerator: TProfileList.TEnumerator;
destructor TProfileManagerEnumerator.Destroy;
begin
Result := FList.GetEnumerator;
end;
FManager.Unlock;
inherited;
end;
initialization
finalization