mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-18 17:09:32 +01:00
IDE: Improve copy'n'paste in GraphicPropEdit. Issue #20243, patch from Flávio Etrusco
git-svn-id: trunk@32766 -
This commit is contained in:
parent
910873ae42
commit
d6c890be77
@ -38,6 +38,8 @@ object GraphicPropertyEditorForm: TGraphicPropertyEditorForm
|
|||||||
ClientWidth = 318
|
ClientWidth = 318
|
||||||
Color = clWindow
|
Color = clWindow
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
|
ParentShowHint = False
|
||||||
|
ShowHint = True
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
object ImagePreview: TImage
|
object ImagePreview: TImage
|
||||||
Left = 0
|
Left = 0
|
||||||
@ -63,10 +65,9 @@ object GraphicPropertyEditorForm: TGraphicPropertyEditorForm
|
|||||||
Height = 25
|
Height = 25
|
||||||
Top = 6
|
Top = 6
|
||||||
Width = 74
|
Width = 74
|
||||||
|
Action = FileOpenAction
|
||||||
Align = alTop
|
Align = alTop
|
||||||
BorderSpacing.Around = 6
|
BorderSpacing.Around = 6
|
||||||
Caption = 'Load'
|
|
||||||
OnClick = LoadButtonClick
|
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
end
|
end
|
||||||
object SaveButton: TButton
|
object SaveButton: TButton
|
||||||
@ -74,10 +75,9 @@ object GraphicPropertyEditorForm: TGraphicPropertyEditorForm
|
|||||||
Height = 25
|
Height = 25
|
||||||
Top = 37
|
Top = 37
|
||||||
Width = 74
|
Width = 74
|
||||||
|
Action = FileSaveAction
|
||||||
Align = alTop
|
Align = alTop
|
||||||
BorderSpacing.Around = 6
|
BorderSpacing.Around = 6
|
||||||
Caption = 'Save'
|
|
||||||
OnClick = SaveButtonClick
|
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
end
|
end
|
||||||
object ClearButton: TButton
|
object ClearButton: TButton
|
||||||
@ -85,10 +85,9 @@ object GraphicPropertyEditorForm: TGraphicPropertyEditorForm
|
|||||||
Height = 25
|
Height = 25
|
||||||
Top = 68
|
Top = 68
|
||||||
Width = 74
|
Width = 74
|
||||||
|
Action = ClearAction
|
||||||
Align = alTop
|
Align = alTop
|
||||||
BorderSpacing.Around = 6
|
BorderSpacing.Around = 6
|
||||||
Caption = 'Clear'
|
|
||||||
OnClick = ClearButtonClick
|
|
||||||
TabOrder = 2
|
TabOrder = 2
|
||||||
end
|
end
|
||||||
object CopyButton: TButton
|
object CopyButton: TButton
|
||||||
@ -149,5 +148,25 @@ object GraphicPropertyEditorForm: TGraphicPropertyEditorForm
|
|||||||
OnUpdate = PasteActionUpdate
|
OnUpdate = PasteActionUpdate
|
||||||
ShortCut = 16470
|
ShortCut = 16470
|
||||||
end
|
end
|
||||||
|
object FileOpenAction: TAction
|
||||||
|
Category = 'File'
|
||||||
|
Caption = 'Load'
|
||||||
|
OnExecute = FileOpenActionExecute
|
||||||
|
ShortCut = 16463
|
||||||
|
end
|
||||||
|
object FileSaveAction: TAction
|
||||||
|
Category = 'File'
|
||||||
|
Caption = 'Save'
|
||||||
|
OnExecute = FileSaveActionExecute
|
||||||
|
OnUpdate = FileSaveActionUpdate
|
||||||
|
ShortCut = 16467
|
||||||
|
end
|
||||||
|
object ClearAction: TEditDelete
|
||||||
|
Category = 'Edit'
|
||||||
|
Caption = 'Clear'
|
||||||
|
Hint = 'Delete'
|
||||||
|
OnExecute = ClearActionExecute
|
||||||
|
ShortCut = 46
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -32,6 +32,9 @@ type
|
|||||||
{ TGraphicPropertyEditorForm }
|
{ TGraphicPropertyEditorForm }
|
||||||
|
|
||||||
TGraphicPropertyEditorForm = class(TForm)
|
TGraphicPropertyEditorForm = class(TForm)
|
||||||
|
FileOpenAction: TAction;
|
||||||
|
FileSaveAction: TAction;
|
||||||
|
ClearAction: TEditDelete;
|
||||||
ActionList: TActionList;
|
ActionList: TActionList;
|
||||||
CopyButton: TButton;
|
CopyButton: TButton;
|
||||||
PasteButton: TButton;
|
PasteButton: TButton;
|
||||||
@ -51,23 +54,25 @@ type
|
|||||||
procedure CopyActionUpdate(Sender: TObject);
|
procedure CopyActionUpdate(Sender: TObject);
|
||||||
procedure PasteActionExecute(Sender: TObject);
|
procedure PasteActionExecute(Sender: TObject);
|
||||||
procedure PasteActionUpdate(Sender: TObject);
|
procedure PasteActionUpdate(Sender: TObject);
|
||||||
procedure ClearButtonClick(Sender: TObject);
|
procedure ClearActionExecute(Sender: TObject);
|
||||||
procedure FormCreate(Sender: TObject);
|
procedure FormCreate(Sender: TObject);
|
||||||
procedure LoadButtonClick(Sender: TObject);
|
procedure FileOpenActionExecute(Sender: TObject);
|
||||||
procedure SaveButtonClick(Sender: TObject);
|
procedure FileSaveActionExecute(Sender: TObject);
|
||||||
|
procedure FileSaveActionUpdate(Sender: TObject);
|
||||||
|
procedure PictureChanged(Sender: TObject);
|
||||||
private
|
private
|
||||||
|
FFileName: String;
|
||||||
FModified: Boolean;
|
FModified: Boolean;
|
||||||
procedure SetModified(const AValue: Boolean);
|
function GetGraphic: TGraphic;
|
||||||
{ private declarations }
|
procedure SetGraphic(Value: TGraphic);
|
||||||
|
procedure SetCaptionDetail(Value: String);
|
||||||
public
|
public
|
||||||
FileName: String;
|
property CaptionDetail: String write SetCaptionDetail;
|
||||||
property Modified: Boolean read FModified write SetModified;
|
property FileName: String read FFileName;
|
||||||
property Preview: TImage read ImagePreview write ImagePreview;
|
property Modified: Boolean read FModified;
|
||||||
|
property Graphic: TGraphic read GetGraphic write SetGraphic;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
|
||||||
GraphicPropertyEditorForm: TGraphicPropertyEditorForm;
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
@ -76,28 +81,21 @@ implementation
|
|||||||
|
|
||||||
procedure TGraphicPropertyEditorForm.FormCreate(Sender: TObject);
|
procedure TGraphicPropertyEditorForm.FormCreate(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
FileName := '';
|
|
||||||
Caption := oisLoadImageDialog;
|
Caption := oisLoadImageDialog;
|
||||||
GroupBox1.Caption:=oisPEPicture;
|
GroupBox1.Caption:=oisPEPicture;
|
||||||
OkCancelButtonPanel.OKButton.Caption := oisOK;
|
OkCancelButtonPanel.OKButton.Caption := oisOK;
|
||||||
OkCancelButtonPanel.CancelButton.Caption := oisCancel;
|
OkCancelButtonPanel.CancelButton.Caption := oisCancel;
|
||||||
LoadButton.Caption := oisLoad;
|
FileOpenAction.Caption := oisLoad;
|
||||||
SaveButton.Caption := oisSave;
|
FileSaveAction.Caption := oisSave;
|
||||||
ClearButton.Caption := oisClear;
|
ClearAction.Caption := oisClear;
|
||||||
OpenDialog.Title:=oisPEOpenImageFile;
|
OpenDialog.Title:=oisPEOpenImageFile;
|
||||||
SaveDialog.Title:=oisPESaveImageAs;
|
SaveDialog.Title:=oisPESaveImageAs;
|
||||||
|
ImagePreview.OnPictureChanged:=@PictureChanged;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TGraphicPropertyEditorForm.ClearButtonClick(Sender: TObject);
|
procedure TGraphicPropertyEditorForm.ClearActionExecute(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
with Preview do
|
ImagePreview.Picture.Clear;
|
||||||
begin
|
|
||||||
Picture.Clear;
|
|
||||||
end;
|
|
||||||
|
|
||||||
ScrollBox.Invalidate;
|
|
||||||
SaveButton.Enabled := False;
|
|
||||||
Modified := True;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TGraphicPropertyEditorForm.CopyActionExecute(Sender: TObject);
|
procedure TGraphicPropertyEditorForm.CopyActionExecute(Sender: TObject);
|
||||||
@ -110,6 +108,11 @@ begin
|
|||||||
CopyAction.Enabled := ImagePreview.Picture.Graphic <> nil;
|
CopyAction.Enabled := ImagePreview.Picture.Graphic <> nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TGraphicPropertyEditorForm.FileSaveActionUpdate(Sender: TObject);
|
||||||
|
begin
|
||||||
|
(Sender as TAction).Enabled := (Graphic <> nil) and (not Graphic.Empty);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TGraphicPropertyEditorForm.PasteActionExecute(Sender: TObject);
|
procedure TGraphicPropertyEditorForm.PasteActionExecute(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
ImagePreview.Picture.Assign(Clipboard);
|
ImagePreview.Picture.Assign(Clipboard);
|
||||||
@ -120,15 +123,14 @@ begin
|
|||||||
PasteAction.Enabled := Clipboard.HasPictureFormat;
|
PasteAction.Enabled := Clipboard.HasPictureFormat;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TGraphicPropertyEditorForm.LoadButtonClick(Sender: TObject);
|
procedure TGraphicPropertyEditorForm.FileOpenActionExecute(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
InitIDEFileDialog(OpenDialog);
|
InitIDEFileDialog(OpenDialog);
|
||||||
if OpenDialog.Execute then
|
if OpenDialog.Execute then
|
||||||
begin
|
begin
|
||||||
FileName := OpenDialog.FileName;
|
|
||||||
try
|
try
|
||||||
Preview.Picture.LoadFromFile(FileName);
|
ImagePreview.Picture.LoadFromFile(OpenDialog.FileName);
|
||||||
Modified := True;
|
FFileName := OpenDialog.FileName; // OnPictureChange clears the field.
|
||||||
except
|
except
|
||||||
on E: Exception do begin
|
on E: Exception do begin
|
||||||
MessageDlg(oisErrorLoadingImage,
|
MessageDlg(oisErrorLoadingImage,
|
||||||
@ -139,29 +141,44 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
StoreIDEFileDialog(OpenDialog);
|
StoreIDEFileDialog(OpenDialog);
|
||||||
|
|
||||||
SaveButton.Enabled := False;
|
|
||||||
if Assigned(Preview.Picture.Graphic) then
|
|
||||||
if not Preview.Picture.Graphic.Empty then
|
|
||||||
SaveButton.Enabled := True;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TGraphicPropertyEditorForm.SaveButtonClick(Sender: TObject);
|
procedure TGraphicPropertyEditorForm.PictureChanged(Sender: TObject);
|
||||||
|
begin
|
||||||
|
FModified := True;
|
||||||
|
FFileName := '';
|
||||||
|
if Graphic <> nil then
|
||||||
|
ScrollBox.Hint := Graphic.ClassName
|
||||||
|
else
|
||||||
|
ScrollBox.Hint := '';
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TGraphicPropertyEditorForm.FileSaveActionExecute(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
InitIDEFileDialog(SaveDialog);
|
InitIDEFileDialog(SaveDialog);
|
||||||
if SaveDialog.Execute then
|
if SaveDialog.Execute then
|
||||||
if SaveDialog.FilterIndex > 1 then
|
if SaveDialog.FilterIndex > 1 then
|
||||||
Preview.Picture.SaveToFile(SaveDialog.FileName, SaveDialog.GetFilterExt)
|
ImagePreview.Picture.SaveToFile(SaveDialog.FileName, SaveDialog.GetFilterExt)
|
||||||
else
|
else
|
||||||
Preview.Picture.SaveToFile(SaveDialog.FileName);
|
ImagePreview.Picture.SaveToFile(SaveDialog.FileName);
|
||||||
|
|
||||||
StoreIDEFileDialog(SaveDialog);
|
StoreIDEFileDialog(SaveDialog);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TGraphicPropertyEditorForm.SetModified(const AValue: Boolean);
|
function TGraphicPropertyEditorForm.GetGraphic: TGraphic;
|
||||||
begin
|
begin
|
||||||
if FModified = AValue then Exit;
|
Result := ImagePreview.Picture.Graphic;
|
||||||
FModified := AValue;
|
end;
|
||||||
|
|
||||||
|
procedure TGraphicPropertyEditorForm.SetGraphic(Value: TGraphic);
|
||||||
|
begin
|
||||||
|
ImagePreview.Picture.Assign(Value);
|
||||||
|
FModified := False;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TGraphicPropertyEditorForm.SetCaptionDetail(Value: String);
|
||||||
|
begin
|
||||||
|
Caption := oisLoadImageDialog + ' - ' + Value;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|||||||
@ -173,37 +173,40 @@ begin
|
|||||||
TheDialog := TGraphicPropertyEditorForm.Create(nil);
|
TheDialog := TGraphicPropertyEditorForm.Create(nil);
|
||||||
FreeGraphic:=false;
|
FreeGraphic:=false;
|
||||||
try
|
try
|
||||||
|
TheDialog.CaptionDetail := GetComponent(0).GetNamePath + '.' + GetName();
|
||||||
if (AGraphic <> nil) then
|
if (AGraphic <> nil) then
|
||||||
TheDialog.Preview.Picture.Assign(AGraphic)
|
TheDialog.Graphic := AGraphic;
|
||||||
else
|
|
||||||
AGraphic := nil;
|
|
||||||
|
|
||||||
if (TheDialog.ShowModal = mrOK) then
|
if (TheDialog.ShowModal = mrOK) and TheDialog.Modified then
|
||||||
begin
|
begin
|
||||||
if TheDialog.Preview.Picture.Graphic <> nil then
|
if (TheDialog.Graphic <> nil) and (not TheDialog.Graphic.Empty) then
|
||||||
begin
|
begin
|
||||||
if TheDialog.Modified and FileExistsUTF8(TheDialog.FileName) then
|
if AGraphic = nil then
|
||||||
begin
|
begin
|
||||||
FreeGraphic := AGraphic = nil;
|
AGraphic := TGraphicClass(GetTypeData(GetPropType)^.ClassType).Create;
|
||||||
|
FreeGraphic := True;
|
||||||
if FreeGraphic then
|
|
||||||
AGraphic := TGraphicClass(GetTypeData(GetPropType)^.ClassType).Create;
|
|
||||||
|
|
||||||
if AGraphic.ClassType = TheDialog.Preview.Picture.Graphic.ClassType then
|
|
||||||
AGraphic.LoadFromFile(TheDialog.FileName)
|
|
||||||
else
|
|
||||||
AGraphic.Assign(TheDialog.Preview.Picture.Graphic);
|
|
||||||
|
|
||||||
SetPtrValue(AGraphic);
|
|
||||||
Modified;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
AGraphic.Assign(TheDialog.Graphic);
|
||||||
|
|
||||||
|
if (AGraphic.ClassType = TheDialog.Graphic.ClassType)
|
||||||
|
and not AGraphic.Equals(TheDialog.Graphic) then
|
||||||
|
begin
|
||||||
|
if (TheDialog.FileName <> '') and FileExistsUTF8(TheDialog.FileName) then
|
||||||
|
begin
|
||||||
|
AGraphic.LoadFromFile(TheDialog.FileName);
|
||||||
|
//MessageDlg('Differences detected, file reloaded', mtInformation, [mbOK], 0);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
//MessageDlg('Image may be different', mtWarning, [mbOK], 0);
|
||||||
|
end;
|
||||||
|
|
||||||
|
SetPtrValue(AGraphic);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if AGraphic <> nil then
|
if AGraphic <> nil then
|
||||||
begin
|
|
||||||
AGraphic.Clear;
|
AGraphic.Clear;
|
||||||
Modified;
|
Modified;
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
if FreeGraphic then
|
if FreeGraphic then
|
||||||
@ -234,19 +237,26 @@ var
|
|||||||
begin
|
begin
|
||||||
Picture := TPicture(GetObjectValue(TPicture));
|
Picture := TPicture(GetObjectValue(TPicture));
|
||||||
TheDialog := TGraphicPropertyEditorForm.Create(nil);
|
TheDialog := TGraphicPropertyEditorForm.Create(nil);
|
||||||
if (Picture.Graphic <> nil) then
|
|
||||||
TheDialog.Preview.Picture.Graphic := Picture.Graphic;
|
|
||||||
try
|
try
|
||||||
if (TheDialog.ShowModal = mrOK) then
|
TheDialog.CaptionDetail := GetComponent(0).GetNamePath + '.' + GetName();
|
||||||
|
if (Picture.Graphic <> nil) then
|
||||||
|
TheDialog.Graphic := Picture.Graphic;
|
||||||
|
if (TheDialog.ShowModal = mrOK) and TheDialog.Modified then
|
||||||
begin
|
begin
|
||||||
if TheDialog.Preview.Picture.Graphic <> nil then
|
if TheDialog.Graphic <> nil then
|
||||||
begin
|
begin
|
||||||
if TheDialog.FileName <> '' then
|
Picture.Graphic := TheDialog.Graphic;
|
||||||
if FileExistsUTF8(TheDialog.FileName) then
|
if not Picture.Graphic.Equals(TheDialog.Graphic) then
|
||||||
|
begin
|
||||||
|
if (TheDialog.FileName <> '') and FileExistsUTF8(TheDialog.FileName) then
|
||||||
begin
|
begin
|
||||||
Picture.LoadFromFile(TheDialog.FileName);
|
Picture.LoadFromFile(TheDialog.FileName);
|
||||||
AddPackage(Picture);
|
//MessageDlg('Differences detected, file reloaded', mtInformation, [mbOK], 0);
|
||||||
end;
|
end
|
||||||
|
else
|
||||||
|
//MessageDlg('Image may be different', mtWarning, [mbOK], 0);
|
||||||
|
end;
|
||||||
|
AddPackage(Picture);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Picture.Graphic := nil;
|
Picture.Graphic := nil;
|
||||||
@ -267,15 +277,13 @@ begin
|
|||||||
ABitmap := TBitmap(GetObjectValue(TBitmap));
|
ABitmap := TBitmap(GetObjectValue(TBitmap));
|
||||||
TheDialog := TGraphicPropertyEditorForm.Create(nil);
|
TheDialog := TGraphicPropertyEditorForm.Create(nil);
|
||||||
try
|
try
|
||||||
|
TheDialog.CaptionDetail := GetComponent(0).GetNamePath + '.' + GetName();
|
||||||
if not ABitmap.Empty then
|
if not ABitmap.Empty then
|
||||||
TheDialog.Preview.Picture.Assign(ABitmap);
|
TheDialog.Graphic := ABitmap;
|
||||||
if (TheDialog.ShowModal = mrOK) then
|
if (TheDialog.ShowModal = mrOK) and TheDialog.Modified then
|
||||||
begin
|
begin
|
||||||
if TheDialog.Modified then
|
ABitmap.Assign(TheDialog.Graphic);
|
||||||
begin
|
Modified;
|
||||||
ABitmap.Assign(TheDialog.Preview.Picture.Graphic);
|
|
||||||
Modified;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
TheDialog.Free;
|
TheDialog.Free;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user