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