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, lisLowercaseStringGivenAsParameter,
@CodeMacroLower,nil); @CodeMacroLower,nil);
RegisterCodeMacro('Paste', lisPasteClipboard, RegisterCodeMacro('Paste', lisPasteClipboard,
lisPasteTextFromClipboard, lisPasteFromClipboard,
@CodeMacroPaste,nil); @CodeMacroPaste,nil);
RegisterCodeMacro('ProcedureHead', lisInsertProcedureHead, RegisterCodeMacro('ProcedureHead', lisInsertProcedureHead,
'Insert header of current procedure'#13 'Insert header of current procedure'#13

View File

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

View File

@ -267,5 +267,24 @@ object PathEditorDialog: TPathEditorDialog
Caption = 'Paste' Caption = 'Paste'
OnClick = PasteMenuItemClick OnClick = PasteMenuItemClick
end 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
end end

View File

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