added "syncro-mode" to project configurations editor

This commit is contained in:
Basile Burg 2015-01-11 03:14:59 +01:00
parent 17b1ed48c9
commit 148c7729a9
2 changed files with 140 additions and 9 deletions

View File

@ -1,7 +1,7 @@
inherited CEProjectConfigurationWidget: TCEProjectConfigurationWidget inherited CEProjectConfigurationWidget: TCEProjectConfigurationWidget
Left = 1429 Left = 632
Height = 273 Height = 273
Top = 30 Top = 322
Width = 445 Width = 445
Caption = 'Project configuration' Caption = 'Project configuration'
ClientHeight = 273 ClientHeight = 273
@ -34,7 +34,7 @@ inherited CEProjectConfigurationWidget: TCEProjectConfigurationWidget
Height = 23 Height = 23
Hint = 'select a configuration' Hint = 'select a configuration'
Top = 1 Top = 1
Width = 346 Width = 316
Align = alClient Align = alClient
BorderSpacing.Top = 1 BorderSpacing.Top = 1
BorderSpacing.Right = 1 BorderSpacing.Right = 1
@ -44,7 +44,7 @@ inherited CEProjectConfigurationWidget: TCEProjectConfigurationWidget
TabOrder = 0 TabOrder = 0
end end
object btnAddConf: TSpeedButton object btnAddConf: TSpeedButton
Left = 347 Left = 317
Height = 24 Height = 24
Hint = 'add an empty configuration' Hint = 'add an empty configuration'
Top = 0 Top = 0
@ -54,7 +54,7 @@ inherited CEProjectConfigurationWidget: TCEProjectConfigurationWidget
ShowCaption = False ShowCaption = False
end end
object btnDelConf: TSpeedButton object btnDelConf: TSpeedButton
Left = 377 Left = 347
Height = 24 Height = 24
Hint = 'remove selected configuration' Hint = 'remove selected configuration'
Top = 0 Top = 0
@ -64,7 +64,7 @@ inherited CEProjectConfigurationWidget: TCEProjectConfigurationWidget
ShowCaption = False ShowCaption = False
end end
object btnCloneConf: TSpeedButton object btnCloneConf: TSpeedButton
Left = 407 Left = 377
Height = 24 Height = 24
Hint = 'clone selected configuration' Hint = 'clone selected configuration'
Top = 0 Top = 0
@ -73,6 +73,16 @@ inherited CEProjectConfigurationWidget: TCEProjectConfigurationWidget
OnClick = btnCloneCurrClick OnClick = btnCloneCurrClick
ShowCaption = False ShowCaption = False
end end
object btnSyncEdit: TSpeedButton
Left = 407
Height = 24
Hint = 'syncrhonize each configuration'
Top = 0
Width = 30
Align = alRight
OnClick = btnSyncEditClick
ShowCaption = False
end
end end
object Panel2: TPanel[1] object Panel2: TPanel[1]
Left = 4 Left = 4
@ -138,6 +148,7 @@ inherited CEProjectConfigurationWidget: TCEProjectConfigurationWidget
Indent = 16 Indent = 16
NameFont.Color = clWindowText NameFont.Color = clWindowText
OnEditorFilter = GridEditorFilter OnEditorFilter = GridEditorFilter
OnModified = GridModified
PreferredSplitterX = 145 PreferredSplitterX = 145
SplitterX = 145 SplitterX = 145
ValueFont.Color = clGreen ValueFont.Color = clGreen

View File

@ -5,15 +5,17 @@ unit ce_projconf;
interface interface
uses uses
Classes, SysUtils, FileUtil, RTTIGrids, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, RTTIGrids, RTTICtrls, Forms, Controls, Graphics,
ExtCtrls, ComCtrls, StdCtrls, Menus, Buttons, PropEdits, ObjectInspector, Dialogs, ExtCtrls, ComCtrls, StdCtrls, Menus, Buttons, rttiutils, typinfo,
ce_dmdwrap, ce_project, ce_widget, ce_interfaces, ce_observer; PropEdits, ObjectInspector, ce_dmdwrap, ce_project, ce_widget, ce_interfaces,
ce_observer;
type type
{ TCEProjectConfigurationWidget } { TCEProjectConfigurationWidget }
TCEProjectConfigurationWidget = class(TCEWidget, ICEProjectObserver) TCEProjectConfigurationWidget = class(TCEWidget, ICEProjectObserver)
btnSyncEdit: TSpeedButton;
imgList: TImageList; imgList: TImageList;
Panel2: TPanel; Panel2: TPanel;
selConf: TComboBox; selConf: TComboBox;
@ -27,13 +29,21 @@ type
procedure btnAddConfClick(Sender: TObject); procedure btnAddConfClick(Sender: TObject);
procedure btnDelConfClick(Sender: TObject); procedure btnDelConfClick(Sender: TObject);
procedure btnCloneCurrClick(Sender: TObject); procedure btnCloneCurrClick(Sender: TObject);
procedure btnSyncEditClick(Sender: TObject);
procedure GridEditorFilter(Sender: TObject; aEditor: TPropertyEditor;var aShow: boolean); procedure GridEditorFilter(Sender: TObject; aEditor: TPropertyEditor;var aShow: boolean);
procedure GridModified(Sender: TObject);
procedure selConfChange(Sender: TObject); procedure selConfChange(Sender: TObject);
procedure TreeChange(Sender: TObject; Node: TTreeNode); procedure TreeChange(Sender: TObject; Node: TTreeNode);
procedure GridFilter(Sender: TObject; aEditor: TPropertyEditor;var aShow: boolean); procedure GridFilter(Sender: TObject; aEditor: TPropertyEditor;var aShow: boolean);
private private
fProj: TCEProject; fProj: TCEProject;
fSyncroMode: boolean;
fSyncroPropValue: string;
function getGridTarget: TPersistent; function getGridTarget: TPersistent;
procedure setSyncroMode(aValue: boolean);
function syncroSetPropAsString(const ASection, Item, Default: string): string;
procedure syncroGetPropAsString(const ASection, Item, Value: string);
property syncroMode: boolean read fSyncroMode write setSyncroMode;
protected protected
procedure UpdateByEvent; override; procedure UpdateByEvent; override;
public public
@ -63,6 +73,8 @@ begin
btnDelConf.Glyph.Assign(png); btnDelConf.Glyph.Assign(png);
png.LoadFromLazarusResource('cog_go'); png.LoadFromLazarusResource('cog_go');
btnCloneConf.Glyph.Assign(png); btnCloneConf.Glyph.Assign(png);
png.LoadFromLazarusResource('link_break');
btnSyncEdit.Glyph.Assign(png);
finally finally
png.Free; png.Free;
end; end;
@ -85,6 +97,7 @@ begin
beginUpdateByEvent; beginUpdateByEvent;
fProj := aProject; fProj := aProject;
endUpdateByEvent; endUpdateByEvent;
syncroMode := false;
end; end;
procedure TCEProjectConfigurationWidget.projClosing(aProject: TCEProject); procedure TCEProjectConfigurationWidget.projClosing(aProject: TCEProject);
@ -94,6 +107,7 @@ begin
Grid.TIObject := nil; Grid.TIObject := nil;
Grid.ItemIndex := -1; Grid.ItemIndex := -1;
self.selConf.Clear; self.selConf.Clear;
syncroMode := false;
fProj := nil; fProj := nil;
end; end;
@ -138,6 +152,106 @@ begin
if aEditor.ClassType = TCollectionPropertyEditor then aShow := false; if aEditor.ClassType = TCollectionPropertyEditor then aShow := false;
end; end;
procedure TCEProjectConfigurationWidget.setSyncroMode(aValue: boolean);
var
png: TPortableNetworkGraphic;
begin
if fSyncroMode = aValue then exit;
//
fSyncroMode := aValue;
png := TPortableNetworkGraphic.Create;
try
if fSyncroMode then png.LoadFromLazarusResource('link')
else png.LoadFromLazarusResource('link_break');
btnSyncEdit.Glyph.Assign(png);
finally
png.Free;
end;
end;
function TCEProjectConfigurationWidget.syncroSetPropAsString(const ASection, Item, Default: string): string;
begin
result := fSyncroPropValue;
end;
procedure TCEProjectConfigurationWidget.syncroGetPropAsString(const ASection, Item, Value: string);
begin
fSyncroPropValue := Value;
end;
procedure TCEProjectConfigurationWidget.GridModified(Sender: TObject);
var
propstr: string;
src_list, trg_list: rttiutils.TPropInfoList;
src_prop, trg_prop: PPropInfo;
storage: rttiutils.TPropsStorage;
trg_obj: TPersistent;
i: Integer;
begin
if fProj = nil then exit;
if not fSyncroMode then exit;
if Grid.TIObject = nil then exit;
if Grid.ItemIndex = -1 then exit;
//
storage := nil;
src_prop:= nil;
trg_prop:= nil;
trg_obj := nil;
propstr := Grid.PropertyPath(Grid.ItemIndex);
storage := rttiutils.TPropsStorage.Create;
storage.OnReadString := @syncroSetPropAsString;
storage.OnWriteString := @syncroGetPropAsString;
src_list:= rttiutils.TPropInfoList.Create(getGridTarget, tkAny);
fProj.beginUpdate;
try
src_prop := src_list.Find(propstr);
if src_prop = nil then exit;
storage.AObject := getGridTarget;
storage.StoreAnyProperty(src_prop);
for i:= 0 to fProj.OptionsCollection.Count-1 do
begin
// skip current config
if i = fProj.ConfigurationIndex then continue;
// find target persistent
if Grid.TIObject = fProj.currentConfiguration.messagesOptions then
trg_obj := fProj.configuration[i].messagesOptions else
if Grid.TIObject = fProj.currentConfiguration.debugingOptions then
trg_obj := fProj.configuration[i].debugingOptions else
if Grid.TIObject = fProj.currentConfiguration.documentationOptions then
trg_obj := fProj.configuration[i].documentationOptions else
if Grid.TIObject = fProj.currentConfiguration.outputOptions then
trg_obj := fProj.configuration[i].outputOptions else
if Grid.TIObject = fProj.currentConfiguration.otherOptions then
trg_obj := fProj.configuration[i].otherOptions else
if Grid.TIObject = fProj.currentConfiguration.pathsOptions then
trg_obj := fProj.configuration[i].pathsOptions else
if Grid.TIObject = fProj.currentConfiguration.preBuildProcess then
trg_obj := fProj.configuration[i].preBuildProcess else
if Grid.TIObject = fProj.currentConfiguration.postBuildProcess then
trg_obj := fProj.configuration[i].postBuildProcess else
if Grid.TIObject = fProj.currentConfiguration.runOptions then
trg_obj := fProj.configuration[i].runOptions
else continue;
// find target property
storage.AObject := trg_obj;
trg_list := rttiutils.TPropInfoList.Create(trg_obj, tkAny);
try
trg_prop := trg_list.Find(propstr);
if trg_prop <> nil then
storage.LoadAnyProperty(trg_prop);
finally
trg_list.Free;
trg_prop := nil;
end;
end;
finally
storage.free;
src_list.free;
fProj.endUpdate;
fSyncroPropValue := '';
end;
end;
procedure TCEProjectConfigurationWidget.btnAddConfClick(Sender: TObject); procedure TCEProjectConfigurationWidget.btnAddConfClick(Sender: TObject);
var var
nme: string; nme: string;
@ -185,6 +299,12 @@ begin
endUpdateByEvent; endUpdateByEvent;
end; end;
procedure TCEProjectConfigurationWidget.btnSyncEditClick(Sender: TObject);
begin
if fProj = nil then exit;
syncroMode := not syncroMode;
end;
procedure TCEProjectConfigurationWidget.GridFilter(Sender: TObject; aEditor: TPropertyEditor; procedure TCEProjectConfigurationWidget.GridFilter(Sender: TObject; aEditor: TPropertyEditor;
var aShow: boolean); var aShow: boolean);
begin begin