IDE: Export/Import for Desktop Manager dialog. Issue #28401, patch from Balázs Székely.

git-svn-id: trunk@49556 -
This commit is contained in:
juha 2015-07-18 08:21:02 +00:00
parent 64e74b9e18
commit 0e0621ae82
3 changed files with 209 additions and 26 deletions

View File

@ -1,24 +1,24 @@
object DesktopForm: TDesktopForm
Left = 472
Height = 202
Top = 431
Left = 670
Height = 291
Top = 382
Width = 432
BorderIcons = [biSystemMenu]
Caption = 'DesktopForm'
ClientHeight = 202
ClientHeight = 291
ClientWidth = 432
OnCreate = FormCreate
Position = poScreenCenter
LCLVersion = '1.5'
object SaveBitBtn: TBitBtn
AnchorSideLeft.Control = DeleteBitBtn
AnchorSideLeft.Control = SetDebugDesktopBitBtn
AnchorSideTop.Control = DesktopListBox
AnchorSideRight.Control = DeleteBitBtn
AnchorSideRight.Side = asrBottom
Left = 280
Left = 271
Height = 23
Top = 14
Width = 146
Width = 155
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 6
Caption = 'Save current desktop'
@ -27,8 +27,8 @@ object DesktopForm: TDesktopForm
end
object ButtonPanel1: TButtonPanel
Left = 6
Height = 34
Top = 162
Height = 37
Top = 248
Width = 420
OKButton.Name = 'OKButton'
OKButton.Caption = 'Close and use selected desktop'
@ -47,9 +47,9 @@ object DesktopForm: TDesktopForm
object DesktopListBox: TListBox
AnchorSideRight.Control = SaveBitBtn
Left = 11
Height = 147
Height = 236
Top = 8
Width = 259
Width = 250
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Right = 10
ItemHeight = 0
@ -66,10 +66,10 @@ object DesktopForm: TDesktopForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = SetDebugDesktopBitBtn
AnchorSideRight.Side = asrBottom
Left = 280
Left = 271
Height = 23
Top = 120
Width = 146
Top = 132
Width = 155
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 4
Caption = 'Delete'
@ -80,10 +80,10 @@ object DesktopForm: TDesktopForm
AnchorSideTop.Control = SelectedDesktopLabel
AnchorSideTop.Side = asrBottom
AnchorSideRight.Side = asrBottom
Left = 280
Height = 23
Top = 66
Width = 146
Left = 271
Height = 29
Top = 70
Width = 155
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Top = 6
@ -95,10 +95,10 @@ object DesktopForm: TDesktopForm
AnchorSideLeft.Control = SaveBitBtn
AnchorSideTop.Control = SaveBitBtn
AnchorSideTop.Side = asrBottom
Left = 280
Height = 13
Left = 271
Height = 17
Top = 47
Width = 86
Width = 100
BorderSpacing.Top = 10
Caption = 'Selected desktop:'
ParentColor = False
@ -109,14 +109,46 @@ object DesktopForm: TDesktopForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = SetDebugDesktopBitBtn
AnchorSideRight.Side = asrBottom
Left = 280
Left = 271
Height = 23
Top = 93
Width = 146
Top = 105
Width = 155
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 4
BorderSpacing.Top = 6
Caption = 'Rename'
OnClick = RenameBitBtnClick
TabOrder = 3
end
object ExportBitBtn: TBitBtn
AnchorSideLeft.Control = DeleteBitBtn
AnchorSideTop.Control = DeleteBitBtn
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = DeleteBitBtn
AnchorSideRight.Side = asrBottom
Left = 271
Height = 23
Top = 167
Width = 155
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 12
Caption = 'Export'
OnClick = ExportBitBtnClick
TabOrder = 6
end
object ImportBitBtn: TBitBtn
AnchorSideLeft.Control = ExportBitBtn
AnchorSideTop.Control = ExportBitBtn
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ExportBitBtn
AnchorSideRight.Side = asrBottom
Left = 271
Height = 23
Top = 194
Width = 155
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 4
Caption = 'Import'
OnClick = ImportBitBtnClick
TabOrder = 7
end
end

View File

@ -8,14 +8,16 @@ uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
Buttons, ButtonPanel,
LCLType, LazarusIDEStrConsts, LCLProc, EnvironmentOpts,
IDEWindowIntf, IDEOptionsIntf;
IDEWindowIntf, IDEOptionsIntf, IDEOptionDefs, Laz2_XMLCfg, InputHistory;
type
{ TDesktopForm }
TDesktopForm = class(TForm)
ExportBitBtn: TBitBtn;
ButtonPanel1: TButtonPanel;
ImportBitBtn: TBitBtn;
RenameBitBtn: TBitBtn;
SelectedDesktopLabel: TLabel;
SetDebugDesktopBitBtn: TBitBtn;
@ -28,7 +30,9 @@ type
ARect: TRect; {%H-}State: TOwnerDrawState);
procedure DesktopListBoxKeyPress(Sender: TObject; var Key: char);
procedure DesktopListBoxSelectionChange(Sender: TObject; {%H-}User: boolean);
procedure ExportBitBtnClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ImportBitBtnClick(Sender: TObject);
procedure RenameBitBtnClick(Sender: TObject);
procedure SaveBitBtnClick(Sender: TObject);
procedure SetDebugDesktopBitBtnClick(Sender: TObject);
@ -86,6 +90,8 @@ begin
DeleteBitBtn.LoadGlyphFromResourceName(HInstance, 'laz_delete');
RenameBitBtn.Caption := lisRename;
RenameBitBtn.LoadGlyphFromResourceName(HInstance, 'laz_edit');
ExportBitBtn.Caption := lisExport;
ImportBitBtn.Caption := lisImport;
SetDebugDesktopBitBtn.Caption := dlgToggleSelectedDebugDesktop;
SetDebugDesktopBitBtn.LoadGlyphFromResourceName(HInstance, 'menu_run');
ButtonPanel1.OKButton.Caption := dlgCloseAndUseSelectedDesktop;
@ -174,6 +180,115 @@ begin
end;
end;
procedure TDesktopForm.ExportBitBtnClick(Sender: TObject);
var
FXMLCfg: TRttiXMLConfig;
FConfigStore: TXMLOptionsStorage;
SaveDialog: TSaveDialog;
xDesktopName, Filename: string;
xDesktopID: Integer;
begin
if DesktopListBox.ItemIndex < 0 then
Exit;
xDesktopName := DesktopListBox.Items[DesktopListBox.ItemIndex];
if xDesktopName = '' then
Exit;
xDesktopID := EnvironmentOptions.Desktops.IndexOf(xDesktopName);
if xDesktopID = -1 then
Exit;
SaveDialog := TSaveDialog.Create(nil);
try
try
InputHistories.ApplyFileDialogSettings(SaveDialog);
SaveDialog.Filter := dlgFilterXML +' (*.xml)|*.xml';
SaveDialog.Options := SaveDialog.Options + [ofOverwritePrompt];
if SaveDialog.Execute then
begin
Filename := SaveDialog.Filename;
if ExtractFileExt(Filename) = '' then
Filename := Filename + '.xml';
FXMLCfg := TRttiXMLConfig.CreateClean(Filename);
try
FConfigStore := TXMLOptionsStorage.Create(FXMLCfg);
try
EnvironmentOptions.Desktops.SaveToXML(FXMLCfg, FConfigStore, xDesktopID);
FConfigStore.WriteToDisk;
ShowMessageFmt(lisSuccessfullyExported, [SaveDialog.Filename]);
finally
FConfigStore.Free;
end;
finally
FreeAndNil(FXMLCfg);
end;
end;
InputHistories.StoreFileDialogSettings(SaveDialog);
except
on E: Exception do
begin
DebugLn('ERROR: [TDesktopMangerDialog.ExportBitBtnClick] ', E.Message);
end;
end;
finally
SaveDialog.Free;
end;
end;
procedure TDesktopForm.ImportBitBtnClick(Sender: TObject);
var
FXMLCfg: TRttiXMLConfig;
FConfigStore: TXMLOptionsStorage;
OpenDialog: TOpenDialog;
xDesktopName, Filename: string;
xDesktopID: Integer;
begin
if DesktopListBox.ItemIndex < 0 then
Exit;
xDesktopName := DesktopListBox.Items[DesktopListBox.ItemIndex];
if xDesktopName = '' then
Exit;
xDesktopID := EnvironmentOptions.Desktops.IndexOf(xDesktopName);
if xDesktopID = -1 then
Exit;
OpenDialog := TOpenDialog.Create(nil);
try
try
InputHistories.ApplyFileDialogSettings(OpenDialog);
OpenDialog.Filter := dlgFilterXML +' (*.xml)|*.xml';
if OpenDialog.Execute then
begin
Filename := OpenDialog.Filename;
FXMLCfg := TRttiXMLConfig.Create(Filename);
try
FConfigStore := TXMLOptionsStorage.Create(FXMLCfg);
try
EnvironmentOptions.Desktops.LoadFromXML(FXMLCfg, FConfigStore, xDesktopID);
ShowMessageFmt(lisSuccessfullyImported, [OpenDialog.Filename]);
finally
FConfigStore.Free;
end;
finally
FreeAndNil(FXMLCfg);
end;
end;
InputHistories.StoreFileDialogSettings(OpenDialog);
except
on E: Exception do
begin
DebugLn('ERROR: [TDesktopMangerDialog.ImportBitBtnClick] ', E.Message);
end;
end;
finally
OpenDialog.Free;
end;
end;
procedure TDesktopForm.DesktopListBoxDblClick(Sender: TObject);
begin
if ButtonPanel1.OKButton.Enabled then
@ -243,6 +358,8 @@ begin
RenameBitBtn.Enabled := DeleteBitBtn.Enabled;
SetDebugDesktopBitBtn.Enabled := DeleteBitBtn.Enabled;
ButtonPanel1.OKButton.Enabled := DeleteBitBtn.Enabled;
ExportBitBtn.Enabled := DeleteBitBtn.Enabled;
ImportBitBtn.Enabled := DeleteBitBtn.Enabled;
end;
procedure TDesktopForm.SaveBitBtnClick(Sender: TObject);

View File

@ -330,6 +330,10 @@ type
constructor Create(aEnvOpts: TEnvironmentOptions);
destructor Destroy; override;
procedure AddFromCfg(Path: String);
procedure SaveToXML(aXMLCfg: TRttiXMLConfig; aConfigStore: TXMLOptionsStorage;
Index: Integer);
procedure LoadFromXML(aXMLCfg: TRttiXMLConfig; aConfigStore: TXMLOptionsStorage;
Index: Integer);
function IndexOf(aName: string): integer;
function Find(aName: string): TDesktopOpt;
property Items[Index: Integer]: TDesktopOpt read GetItem; default;
@ -914,6 +918,35 @@ begin
end;
end;
procedure TDesktopOptList.SaveToXML(aXMLCfg: TRttiXMLConfig;
aConfigStore: TXMLOptionsStorage; Index: Integer);
var
I: Integer;
CurPath: String;
begin
CurPath := 'Desktops/';
Items[Index].SetConfig(aXMLCfg, aConfigStore);
aXMLCfg.SetDeleteValue(CurPath + 'Count', 1, 0);
Items[Index].Save(CurPath + 'Desktop1/');
end;
procedure TDesktopOptList.LoadFromXML(aXMLCfg: TRttiXMLConfig;
aConfigStore: TXMLOptionsStorage; Index: Integer);
var
I: Integer;
CurPath: String;
xDesktop: TDesktopOpt;
begin
CurPath := 'Desktops/';
if aXMLCfg.HasPath(CurPath, True) then
begin
xDesktop := TDesktopOpt.Create(Items[Index].Name, False);
Items[Index].Assign(xDesktop);
Items[Index].SetConfig(aXMLCfg, aConfigStore);
Items[Index].Load(CurPath + 'Desktop1/');
end;
end;
function TDesktopOptList.IndexOf(aName: string): integer;
begin
Result:=Count-1;
@ -1943,6 +1976,7 @@ begin
end;
// The user can define many desktops. They are saved under path Desktops/.
FXMLCfg.DeletePath('Desktops/');
CurPath:='Desktops/';
FXMLCfg.SetDeleteValue(CurPath+'Count', FDesktops.Count, 0);
FXMLCfg.SetDeleteValue(CurPath+'DebugDesktop', FDebugDesktopName, '');