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

View File

@ -8,14 +8,16 @@ uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
Buttons, ButtonPanel, Buttons, ButtonPanel,
LCLType, LazarusIDEStrConsts, LCLProc, EnvironmentOpts, LCLType, LazarusIDEStrConsts, LCLProc, EnvironmentOpts,
IDEWindowIntf, IDEOptionsIntf; IDEWindowIntf, IDEOptionsIntf, IDEOptionDefs, Laz2_XMLCfg, InputHistory;
type type
{ TDesktopForm } { TDesktopForm }
TDesktopForm = class(TForm) TDesktopForm = class(TForm)
ExportBitBtn: TBitBtn;
ButtonPanel1: TButtonPanel; ButtonPanel1: TButtonPanel;
ImportBitBtn: TBitBtn;
RenameBitBtn: TBitBtn; RenameBitBtn: TBitBtn;
SelectedDesktopLabel: TLabel; SelectedDesktopLabel: TLabel;
SetDebugDesktopBitBtn: TBitBtn; SetDebugDesktopBitBtn: TBitBtn;
@ -28,7 +30,9 @@ type
ARect: TRect; {%H-}State: TOwnerDrawState); ARect: TRect; {%H-}State: TOwnerDrawState);
procedure DesktopListBoxKeyPress(Sender: TObject; var Key: char); procedure DesktopListBoxKeyPress(Sender: TObject; var Key: char);
procedure DesktopListBoxSelectionChange(Sender: TObject; {%H-}User: boolean); procedure DesktopListBoxSelectionChange(Sender: TObject; {%H-}User: boolean);
procedure ExportBitBtnClick(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure ImportBitBtnClick(Sender: TObject);
procedure RenameBitBtnClick(Sender: TObject); procedure RenameBitBtnClick(Sender: TObject);
procedure SaveBitBtnClick(Sender: TObject); procedure SaveBitBtnClick(Sender: TObject);
procedure SetDebugDesktopBitBtnClick(Sender: TObject); procedure SetDebugDesktopBitBtnClick(Sender: TObject);
@ -86,6 +90,8 @@ begin
DeleteBitBtn.LoadGlyphFromResourceName(HInstance, 'laz_delete'); DeleteBitBtn.LoadGlyphFromResourceName(HInstance, 'laz_delete');
RenameBitBtn.Caption := lisRename; RenameBitBtn.Caption := lisRename;
RenameBitBtn.LoadGlyphFromResourceName(HInstance, 'laz_edit'); RenameBitBtn.LoadGlyphFromResourceName(HInstance, 'laz_edit');
ExportBitBtn.Caption := lisExport;
ImportBitBtn.Caption := lisImport;
SetDebugDesktopBitBtn.Caption := dlgToggleSelectedDebugDesktop; SetDebugDesktopBitBtn.Caption := dlgToggleSelectedDebugDesktop;
SetDebugDesktopBitBtn.LoadGlyphFromResourceName(HInstance, 'menu_run'); SetDebugDesktopBitBtn.LoadGlyphFromResourceName(HInstance, 'menu_run');
ButtonPanel1.OKButton.Caption := dlgCloseAndUseSelectedDesktop; ButtonPanel1.OKButton.Caption := dlgCloseAndUseSelectedDesktop;
@ -174,6 +180,115 @@ begin
end; end;
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); procedure TDesktopForm.DesktopListBoxDblClick(Sender: TObject);
begin begin
if ButtonPanel1.OKButton.Enabled then if ButtonPanel1.OKButton.Enabled then
@ -243,6 +358,8 @@ begin
RenameBitBtn.Enabled := DeleteBitBtn.Enabled; RenameBitBtn.Enabled := DeleteBitBtn.Enabled;
SetDebugDesktopBitBtn.Enabled := DeleteBitBtn.Enabled; SetDebugDesktopBitBtn.Enabled := DeleteBitBtn.Enabled;
ButtonPanel1.OKButton.Enabled := DeleteBitBtn.Enabled; ButtonPanel1.OKButton.Enabled := DeleteBitBtn.Enabled;
ExportBitBtn.Enabled := DeleteBitBtn.Enabled;
ImportBitBtn.Enabled := DeleteBitBtn.Enabled;
end; end;
procedure TDesktopForm.SaveBitBtnClick(Sender: TObject); procedure TDesktopForm.SaveBitBtnClick(Sender: TObject);

View File

@ -330,6 +330,10 @@ type
constructor Create(aEnvOpts: TEnvironmentOptions); constructor Create(aEnvOpts: TEnvironmentOptions);
destructor Destroy; override; destructor Destroy; override;
procedure AddFromCfg(Path: String); 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 IndexOf(aName: string): integer;
function Find(aName: string): TDesktopOpt; function Find(aName: string): TDesktopOpt;
property Items[Index: Integer]: TDesktopOpt read GetItem; default; property Items[Index: Integer]: TDesktopOpt read GetItem; default;
@ -914,6 +918,35 @@ begin
end; end;
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; function TDesktopOptList.IndexOf(aName: string): integer;
begin begin
Result:=Count-1; Result:=Count-1;
@ -1943,6 +1976,7 @@ begin
end; end;
// The user can define many desktops. They are saved under path Desktops/. // The user can define many desktops. They are saved under path Desktops/.
FXMLCfg.DeletePath('Desktops/');
CurPath:='Desktops/'; CurPath:='Desktops/';
FXMLCfg.SetDeleteValue(CurPath+'Count', FDesktops.Count, 0); FXMLCfg.SetDeleteValue(CurPath+'Count', FDesktops.Count, 0);
FXMLCfg.SetDeleteValue(CurPath+'DebugDesktop', FDebugDesktopName, ''); FXMLCfg.SetDeleteValue(CurPath+'DebugDesktop', FDebugDesktopName, '');