IDE: Import/export paths in path editor dialog. Part of issue #25903.

git-svn-id: trunk@46200 -
This commit is contained in:
juha 2014-09-13 08:40:50 +00:00
parent 4ee0f9c9c5
commit 3985d2f0cb
4 changed files with 109 additions and 25 deletions

View File

@ -730,7 +730,7 @@ begin
lisLowercaseStringGivenAsParameter,
@CodeMacroLower,nil);
RegisterCodeMacro('Paste', lisPasteClipboard,
lisPasteTextFromClipboard,
lisPasteFromClipboard,
@CodeMacroPaste,nil);
RegisterCodeMacro('ProcedureHead', lisInsertProcedureHead,
'Insert header of current procedure'#13

View File

@ -4700,6 +4700,8 @@ resourcestring
lisPathEditorDeleteHint = 'Delete the selected path';
lisPathEditorDeleteInvalidHint = 'Remove non-existent (gray) paths from the list';
lisPathEditorTemplAddHint = 'Add template to the list';
lisExportAllItemsToFile = 'Export All Items to File';
lisImportFromFile = 'Import from File';
// version info tab
VersionInfoTitle = 'Version Info';
@ -5113,7 +5115,7 @@ resourcestring
lisLowercaseString = 'lowercase string';
lisLowercaseStringGivenAsParameter = 'Lowercase string given as parameter';
lisPasteClipboard = 'paste clipboard';
lisPasteTextFromClipboard = 'Paste text from clipboard';
lisPasteFromClipboard = 'Paste from clipboard';
lisInsertProcedureHead = 'insert procedure head';
lisInsertProcedureName = 'insert procedure name';
lisInsertNameOfCurrentProcedure = 'Insert name of current procedure';

View File

@ -267,5 +267,24 @@ object PathEditorDialog: TPathEditorDialog
Caption = 'Paste'
OnClick = PasteMenuItemClick
end
object SeparMenuItem: TMenuItem
Caption = '-'
end
object ExportMenuItem: TMenuItem
Caption = 'Export to file'
OnClick = ExportMenuItemClick
end
object ImportMenuItem: TMenuItem
Caption = 'Import from file'
OnClick = ImportMenuItemClick
end
end
object OpenDialog1: TOpenDialog
left = 476
top = 197
end
object SaveDialog1: TSaveDialog
left = 512
top = 197
end
end

View File

@ -22,8 +22,9 @@ interface
uses
Classes, SysUtils, types, Forms, Controls, Buttons, StdCtrls, Dialogs,
FileUtil, ButtonPanel, ExtCtrls, EditBtn, MacroIntf, LCLType, Graphics, Menus,
TransferMacros, LazarusIDEStrConsts, shortpathedit, Clipbrd, LCLProc;
FileUtil, ButtonPanel, ExtCtrls, EditBtn, MacroIntf, IDEImagesIntf, LCLType,
Graphics, Menus, TransferMacros, LazarusIDEStrConsts, shortpathedit, Clipbrd,
LCLProc;
type
@ -33,6 +34,11 @@ type
AddTemplateButton: TBitBtn;
ButtonPanel1: TButtonPanel;
CopyMenuItem: TMenuItem;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
ExportMenuItem: TMenuItem;
ImportMenuItem: TMenuItem;
SeparMenuItem: TMenuItem;
PasteMenuItem: TMenuItem;
PopupMenu1: TPopupMenu;
ReplaceButton: TBitBtn;
@ -51,6 +57,7 @@ type
procedure AddButtonClick(Sender: TObject);
procedure AddTemplateButtonClick(Sender: TObject);
procedure CopyMenuItemClick(Sender: TObject);
procedure ExportMenuItemClick(Sender: TObject);
procedure PasteMenuItemClick(Sender: TObject);
procedure DeleteInvalidPathsButtonClick(Sender: TObject);
procedure DeleteButtonClick(Sender: TObject);
@ -67,6 +74,7 @@ type
Shift: TShiftState);
procedure PathListBoxSelectionChange(Sender: TObject; User: boolean);
procedure ReplaceButtonClick(Sender: TObject);
procedure ImportMenuItemClick(Sender: TObject);
procedure TemplatesListBoxDblClick(Sender: TObject);
procedure TemplatesListBoxSelectionChange(Sender: TObject; User: boolean);
private
@ -78,11 +86,13 @@ type
function BaseRelative(const APath: string): String;
function PathAsAbsolute(const APath: string): String;
function PathMayExist(APath: string): TObject;
procedure ReadHelper(Paths: TStringList);
procedure SetBaseDirectory(const AValue: string);
procedure SetPath(const AValue: string);
procedure SetTemplates(const AValue: string);
function TextToPath(const AText: string): string;
procedure UpdateButtons;
procedure WriteHelper(Paths: TStringList);
public
property BaseDirectory: string read FBaseDirectory write SetBaseDirectory;
property EffectiveBaseDirectory: string read FEffectiveBaseDirectory;
@ -101,8 +111,7 @@ type
public
procedure Click; override;
property CurrentPathEditor: TPathEditorDialog read FCurrentPathEditor;
property OnExecuted: TOnPathEditorExecuted
read FOnExecuted write FOnExecuted;
property OnExecuted: TOnPathEditorExecuted read FOnExecuted write FOnExecuted;
end;
function PathEditorDialog: TPathEditorDialog;
@ -219,44 +228,86 @@ begin
end;
end;
procedure TPathEditorDialog.WriteHelper(Paths: TStringList);
// Helper method for writing paths. Collect paths to a StringList.
var
i: integer;
begin
for i := 0 to PathListBox.Count-1 do
Paths.Add(PathAsAbsolute(PathListBox.Items[i]));
end;
procedure TPathEditorDialog.CopyMenuItemClick(Sender: TObject);
var
Paths: TStringList;
i: integer;
begin
Paths := TStringList.Create;
try
for i := 0 to PathListBox.Count-1 do
Paths.Add(PathAsAbsolute(PathListBox.Items[i]));
WriteHelper(Paths);
Clipboard.AsText := Paths.Text;
finally
Paths.Free;
end;
end;
procedure TPathEditorDialog.PasteMenuItemClick(Sender: TObject);
procedure TPathEditorDialog.ExportMenuItemClick(Sender: TObject);
var
Paths: TStringList;
begin
if not SaveDialog1.Execute then Exit;
Paths := TStringList.Create;
try
WriteHelper(Paths);
Paths.SaveToFile(SaveDialog1.FileName);
finally
Paths.Free;
end;
end;
procedure TPathEditorDialog.ReadHelper(Paths: TStringList);
// Helper method for reading paths. Insert paths from a StringList to the ListBox.
var
s: string;
y, i: integer;
begin
y := PathListBox.ItemIndex;
if y = -1 then
y := PathListBox.Count-1;
for i := 0 to Paths.Count-1 do
begin
s := Trim(Paths[i]);
if s <> '' then
begin
Inc(y);
PathListBox.Items.InsertObject(y, BaseRelative(s), PathMayExist(s));
end;
end;
//PathListBox.ItemIndex := y;
UpdateButtons;
end;
procedure TPathEditorDialog.PasteMenuItemClick(Sender: TObject);
var
Paths: TStringList;
begin
Paths := TStringList.Create;
try
y := PathListBox.ItemIndex;
if y = -1 then
y := PathListBox.Count-1;
Paths.Text := Clipboard.AsText;
for i := 0 to Paths.Count-1 do
begin
s := Trim(Paths[i]);
if s <> '' then
begin
Inc(y);
PathListBox.Items.InsertObject(y, BaseRelative(s), PathMayExist(s));
end;
end;
//PathListBox.ItemIndex := y;
UpdateButtons;
ReadHelper(Paths);
finally
Paths.Free;
end;
end;
procedure TPathEditorDialog.ImportMenuItemClick(Sender: TObject);
var
Paths: TStringList;
begin
if not OpenDialog1.Execute then Exit;
Paths := TStringList.Create;
try
Paths.LoadFromFile(OpenDialog1.FileName);
ReadHelper(Paths);
finally
Paths.Free;
end;
@ -292,6 +343,8 @@ begin
end;
procedure TPathEditorDialog.FormCreate(Sender: TObject);
const
Filt = 'Text file (*.txt)|*.txt|All files (*)|*';
begin
Caption:=dlgDebugOptionsPathEditorDlgCaption;
@ -312,8 +365,18 @@ begin
AddTemplateButton.Caption:=lisCodeTemplAdd;
AddTemplateButton.Hint:=lisPathEditorTemplAddHint;
PopupMenu1.Images:=IDEImages.Images_16;
CopyMenuItem.Caption:=lisCopyAllItemsToClipboard;
PasteMenuItem.Caption:=lisPaste;
CopyMenuItem.ImageIndex:=IDEImages.LoadImage(16, 'laz_copy');
PasteMenuItem.Caption:=lisPasteFromClipboard;
PasteMenuItem.ImageIndex:=IDEImages.LoadImage(16, 'laz_paste');
ExportMenuItem.Caption:=lisExportAllItemsToFile;
ExportMenuItem.ImageIndex:=IDEImages.LoadImage(16, 'laz_save');
ImportMenuItem.Caption:=lisImportFromFile;
ImportMenuItem.ImageIndex:=IDEImages.LoadImage(16, 'laz_open');
OpenDialog1.Filter:=Filt;
SaveDialog1.Filter:=Filt;
MoveUpButton.LoadGlyphFromResourceName(HInstance, 'arrow_up');
MoveDownButton.LoadGlyphFromResourceName(HInstance, 'arrow_down');