View Issue Details

IDProjectCategoryView StatusLast Update
0020243LazarusPatchpublic2011-10-08 22:16
ReporterFlávio Etrusco (notifications not working)Assigned ToJuha Manninen 
PrioritylowSeverityfeatureReproducibilityN/A
Status resolvedResolutionfixed 
Product Version0.9.31 (SVN)Product Build 
Target VersionFixed in Version 
Summary0020243: GraphicPropEdit: implement copy'n'paste
DescriptionImplement copy'n'paste for TGraphic editor.
Only tested on Windows.
TagsNo tags attached.
Fixed in Revisionr32344, r32766, r32770
LazTarget0.99.0
Widgetset
Attached Files
  • GraphicPropEdit-implement-copy-paste-r32336.patch (4,972 bytes)
    91e7c2ebc5a39df78e0e357a0847e7ded951e90c
    diff --git ideintf/graphicpropedit.lfm ideintf/graphicpropedit.lfm
    index f8ad063..5886c14 100644
    --- ideintf/graphicpropedit.lfm
    +++ ideintf/graphicpropedit.lfm
    @@ -11,7 +11,7 @@ object GraphicPropertyEditorForm: TGraphicPropertyEditorForm
       Constraints.MinWidth = 200
       OnCreate = FormCreate
       Position = poScreenCenter
    -  LCLVersion = '0.9.27'
    +  LCLVersion = '0.9.31'
       object GroupBox1: TGroupBox
         Left = 6
         Height = 337
    @@ -25,13 +25,13 @@ object GraphicPropertyEditorForm: TGraphicPropertyEditorForm
         TabOrder = 0
         object ScrollBox: TScrollBox
           AnchorSideRight.Control = GroupBox1
    -      AnchorSideRight.Side = asrBottom
           AnchorSideBottom.Control = GroupBox1
    -      AnchorSideBottom.Side = asrBottom
           Left = 6
           Height = 307
           Top = 6
           Width = 322
    +      HorzScrollBar.Page = 318
    +      VertScrollBar.Page = 303
           Align = alClient
           BorderSpacing.Around = 6
           ClientHeight = 303
    @@ -59,7 +59,6 @@ object GraphicPropertyEditorForm: TGraphicPropertyEditorForm
           ClientWidth = 86
           TabOrder = 1
           object LoadButton: TButton
    -        AnchorSideRight.Side = asrBottom
             Left = 6
             Height = 25
             Top = 6
    @@ -92,6 +91,22 @@ object GraphicPropertyEditorForm: TGraphicPropertyEditorForm
             OnClick = ClearButtonClick
             TabOrder = 2
           end
    +      object CopyButton: TButton
    +        Left = 6
    +        Height = 25
    +        Top = 112
    +        Width = 74
    +        Action = CopyAction
    +        TabOrder = 3
    +      end
    +      object PasteButton: TButton
    +        Left = 6
    +        Height = 25
    +        Top = 143
    +        Width = 74
    +        Action = PasteAction
    +        TabOrder = 4
    +      end
         end
       end
       object OkCancelButtonPanel: TButtonPanel
    @@ -99,6 +114,14 @@ object GraphicPropertyEditorForm: TGraphicPropertyEditorForm
         Height = 26
         Top = 349
         Width = 424
    +    OKButton.Name = 'OKButton'
    +    OKButton.Caption = '&OK'
    +    HelpButton.Name = 'HelpButton'
    +    HelpButton.Caption = '&Help'
    +    CloseButton.Name = 'CloseButton'
    +    CloseButton.Caption = '&Close'
    +    CancelButton.Name = 'CancelButton'
    +    CancelButton.Caption = 'Cancel'
         TabOrder = 1
         ShowButtons = [pbOK, pbCancel]
         ShowBevel = False
    @@ -108,8 +131,27 @@ object GraphicPropertyEditorForm: TGraphicPropertyEditorForm
         top = 182
       end
       object SaveDialog: TSavePictureDialog
    -    Title = 'Save file as'
         left = 186
         top = 182
       end
    +  object ActionList: TActionList
    +    left = 355
    +    top = 244
    +    object CopyAction: TEditCopy
    +      Category = 'Edit'
    +      Caption = '&Copy'
    +      Hint = 'Copy'
    +      OnExecute = CopyActionExecute
    +      OnUpdate = CopyActionUpdate
    +      ShortCut = 16451
    +    end
    +    object PasteAction: TEditPaste
    +      Category = 'Edit'
    +      Caption = '&Paste'
    +      Hint = 'Paste'
    +      OnExecute = PasteActionExecute
    +      OnUpdate = PasteActionUpdate
    +      ShortCut = 16470
    +    end
    +  end
     end
    diff --git ideintf/graphicpropedit.pas ideintf/graphicpropedit.pas
    index 0e4f1b1..64ca72b 100644
    --- ideintf/graphicpropedit.pas
    +++ ideintf/graphicpropedit.pas
    @@ -24,7 +24,7 @@ interface
     
     uses
       Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
    -  ExtCtrls, Buttons, ButtonPanel, ExtDlgs,
    +  ExtCtrls, Buttons, ButtonPanel, ExtDlgs, ActnList, StdActns, Clipbrd,
       IDEDialogs, ObjInspStrConsts;
     
     type
    @@ -32,6 +32,11 @@ type
       { TGraphicPropertyEditorForm }
     
       TGraphicPropertyEditorForm = class(TForm)
    +    ActionList: TActionList;
    +    CopyButton: TButton;
    +    PasteButton: TButton;
    +    CopyAction: TEditCopy;
    +    PasteAction: TEditPaste;
         OkCancelButtonPanel: TButtonPanel;
         ImagePreview: TImage;
         LoadButton: TButton;
    @@ -42,6 +47,10 @@ type
         GroupBox1: TGroupBox;
         SaveDialog: TSavePictureDialog;
         ScrollBox: TScrollBox;
    +    procedure CopyActionExecute(Sender: TObject);
    +    procedure CopyActionUpdate(Sender: TObject);
    +    procedure PasteActionExecute(Sender: TObject);
    +    procedure PasteActionUpdate(Sender: TObject);
         procedure ClearButtonClick(Sender: TObject);
         procedure FormCreate(Sender: TObject);
         procedure LoadButtonClick(Sender: TObject);
    @@ -91,6 +100,26 @@ begin
       Modified := True;
     end;
     
    +procedure TGraphicPropertyEditorForm.CopyActionExecute(Sender: TObject);
    +begin
    +  Clipboard.Assign(ImagePreview.Picture.Graphic);
    +end;
    +
    +procedure TGraphicPropertyEditorForm.CopyActionUpdate(Sender: TObject);
    +begin
    +  CopyAction.Enabled := ImagePreview.Picture.Graphic <> nil;
    +end;
    +
    +procedure TGraphicPropertyEditorForm.PasteActionExecute(Sender: TObject);
    +begin
    +  ImagePreview.Picture.Assign(Clipboard);
    +end;
    +
    +procedure TGraphicPropertyEditorForm.PasteActionUpdate(Sender: TObject);
    +begin
    +  PasteAction.Enabled := Clipboard.HasPictureFormat;
    +end;
    +
     procedure TGraphicPropertyEditorForm.LoadButtonClick(Sender: TObject);
     begin
       InitIDEFileDialog(OpenDialog);
    
  • graphiceditor-cleanup-and-fix-paste-r32724.patch (12,096 bytes)
    ec580b2c30d06be5165f99d216a4636c8752665a
    diff --git ideintf/graphicpropedit.lfm ideintf/graphicpropedit.lfm
    index 129faf3..ed16f86 100644
    --- ideintf/graphicpropedit.lfm
    +++ ideintf/graphicpropedit.lfm
    @@ -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
    diff --git ideintf/graphicpropedit.pas ideintf/graphicpropedit.pas
    index 64ca72b..1ccab19 100644
    --- ideintf/graphicpropedit.pas
    +++ ideintf/graphicpropedit.pas
    @@ -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
    +  Result := ImagePreview.Picture.Graphic;
    +end;
    +
    +procedure TGraphicPropertyEditorForm.SetGraphic(Value: TGraphic);
    +begin
    +  ImagePreview.Picture.Assign(Value);
    +  FModified := False;
    +end;
    +
    +procedure TGraphicPropertyEditorForm.SetCaptionDetail(Value: String);
     begin
    -  if FModified = AValue then Exit;
    -  FModified := AValue;
    +  Caption := oisLoadImageDialog + ' - ' + Value;
     end;
     
     end.
    diff --git ideintf/graphpropedits.pas ideintf/graphpropedits.pas
    index da7e667..b8eda65 100644
    --- ideintf/graphpropedits.pas
    +++ ideintf/graphpropedits.pas
    @@ -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;
    +          AGraphic := TGraphicClass(GetTypeData(GetPropType)^.ClassType).Create;
    +          FreeGraphic := True;
    +        end;
     
    -          if FreeGraphic then 
    -            AGraphic := TGraphicClass(GetTypeData(GetPropType)^.ClassType).Create;
    +        AGraphic.Assign(TheDialog.Graphic);
     
    -          if AGraphic.ClassType = TheDialog.Preview.Picture.Graphic.ClassType then
    -            AGraphic.LoadFromFile(TheDialog.FileName)
    +        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
    -            AGraphic.Assign(TheDialog.Preview.Picture.Graphic);
    -
    -          SetPtrValue(AGraphic);
    -          Modified;
    +            //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;
    

Relationships

parent of 0020252 closedFelipe Monteiro de Carvalho [Patch] BitBtn with Kind<>bkCustom should not save Caption to LFM but be translated via lclstrconsts 

Activities

2011-09-14 17:12

 

GraphicPropEdit-implement-copy-paste-r32336.patch (4,972 bytes)
91e7c2ebc5a39df78e0e357a0847e7ded951e90c
diff --git ideintf/graphicpropedit.lfm ideintf/graphicpropedit.lfm
index f8ad063..5886c14 100644
--- ideintf/graphicpropedit.lfm
+++ ideintf/graphicpropedit.lfm
@@ -11,7 +11,7 @@ object GraphicPropertyEditorForm: TGraphicPropertyEditorForm
   Constraints.MinWidth = 200
   OnCreate = FormCreate
   Position = poScreenCenter
-  LCLVersion = '0.9.27'
+  LCLVersion = '0.9.31'
   object GroupBox1: TGroupBox
     Left = 6
     Height = 337
@@ -25,13 +25,13 @@ object GraphicPropertyEditorForm: TGraphicPropertyEditorForm
     TabOrder = 0
     object ScrollBox: TScrollBox
       AnchorSideRight.Control = GroupBox1
-      AnchorSideRight.Side = asrBottom
       AnchorSideBottom.Control = GroupBox1
-      AnchorSideBottom.Side = asrBottom
       Left = 6
       Height = 307
       Top = 6
       Width = 322
+      HorzScrollBar.Page = 318
+      VertScrollBar.Page = 303
       Align = alClient
       BorderSpacing.Around = 6
       ClientHeight = 303
@@ -59,7 +59,6 @@ object GraphicPropertyEditorForm: TGraphicPropertyEditorForm
       ClientWidth = 86
       TabOrder = 1
       object LoadButton: TButton
-        AnchorSideRight.Side = asrBottom
         Left = 6
         Height = 25
         Top = 6
@@ -92,6 +91,22 @@ object GraphicPropertyEditorForm: TGraphicPropertyEditorForm
         OnClick = ClearButtonClick
         TabOrder = 2
       end
+      object CopyButton: TButton
+        Left = 6
+        Height = 25
+        Top = 112
+        Width = 74
+        Action = CopyAction
+        TabOrder = 3
+      end
+      object PasteButton: TButton
+        Left = 6
+        Height = 25
+        Top = 143
+        Width = 74
+        Action = PasteAction
+        TabOrder = 4
+      end
     end
   end
   object OkCancelButtonPanel: TButtonPanel
@@ -99,6 +114,14 @@ object GraphicPropertyEditorForm: TGraphicPropertyEditorForm
     Height = 26
     Top = 349
     Width = 424
+    OKButton.Name = 'OKButton'
+    OKButton.Caption = '&OK'
+    HelpButton.Name = 'HelpButton'
+    HelpButton.Caption = '&Help'
+    CloseButton.Name = 'CloseButton'
+    CloseButton.Caption = '&Close'
+    CancelButton.Name = 'CancelButton'
+    CancelButton.Caption = 'Cancel'
     TabOrder = 1
     ShowButtons = [pbOK, pbCancel]
     ShowBevel = False
@@ -108,8 +131,27 @@ object GraphicPropertyEditorForm: TGraphicPropertyEditorForm
     top = 182
   end
   object SaveDialog: TSavePictureDialog
-    Title = 'Save file as'
     left = 186
     top = 182
   end
+  object ActionList: TActionList
+    left = 355
+    top = 244
+    object CopyAction: TEditCopy
+      Category = 'Edit'
+      Caption = '&Copy'
+      Hint = 'Copy'
+      OnExecute = CopyActionExecute
+      OnUpdate = CopyActionUpdate
+      ShortCut = 16451
+    end
+    object PasteAction: TEditPaste
+      Category = 'Edit'
+      Caption = '&Paste'
+      Hint = 'Paste'
+      OnExecute = PasteActionExecute
+      OnUpdate = PasteActionUpdate
+      ShortCut = 16470
+    end
+  end
 end
diff --git ideintf/graphicpropedit.pas ideintf/graphicpropedit.pas
index 0e4f1b1..64ca72b 100644
--- ideintf/graphicpropedit.pas
+++ ideintf/graphicpropedit.pas
@@ -24,7 +24,7 @@ interface
 
 uses
   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
-  ExtCtrls, Buttons, ButtonPanel, ExtDlgs,
+  ExtCtrls, Buttons, ButtonPanel, ExtDlgs, ActnList, StdActns, Clipbrd,
   IDEDialogs, ObjInspStrConsts;
 
 type
@@ -32,6 +32,11 @@ type
   { TGraphicPropertyEditorForm }
 
   TGraphicPropertyEditorForm = class(TForm)
+    ActionList: TActionList;
+    CopyButton: TButton;
+    PasteButton: TButton;
+    CopyAction: TEditCopy;
+    PasteAction: TEditPaste;
     OkCancelButtonPanel: TButtonPanel;
     ImagePreview: TImage;
     LoadButton: TButton;
@@ -42,6 +47,10 @@ type
     GroupBox1: TGroupBox;
     SaveDialog: TSavePictureDialog;
     ScrollBox: TScrollBox;
+    procedure CopyActionExecute(Sender: TObject);
+    procedure CopyActionUpdate(Sender: TObject);
+    procedure PasteActionExecute(Sender: TObject);
+    procedure PasteActionUpdate(Sender: TObject);
     procedure ClearButtonClick(Sender: TObject);
     procedure FormCreate(Sender: TObject);
     procedure LoadButtonClick(Sender: TObject);
@@ -91,6 +100,26 @@ begin
   Modified := True;
 end;
 
+procedure TGraphicPropertyEditorForm.CopyActionExecute(Sender: TObject);
+begin
+  Clipboard.Assign(ImagePreview.Picture.Graphic);
+end;
+
+procedure TGraphicPropertyEditorForm.CopyActionUpdate(Sender: TObject);
+begin
+  CopyAction.Enabled := ImagePreview.Picture.Graphic <> nil;
+end;
+
+procedure TGraphicPropertyEditorForm.PasteActionExecute(Sender: TObject);
+begin
+  ImagePreview.Picture.Assign(Clipboard);
+end;
+
+procedure TGraphicPropertyEditorForm.PasteActionUpdate(Sender: TObject);
+begin
+  PasteAction.Enabled := Clipboard.HasPictureFormat;
+end;
+
 procedure TGraphicPropertyEditorForm.LoadButtonClick(Sender: TObject);
 begin
   InitIDEFileDialog(OpenDialog);

Juha Manninen

2011-09-15 00:34

developer   ~0051832

Flávio, how to test this feature?

Flávio Etrusco (notifications not working)

2011-09-15 00:37

developer   ~0051833

Last edited: 2011-09-15 00:38

Place a TImage in a form, edit the Graphic. There are now two new buttons: Copy and Paste. Try to copy to and paste from clipboard :)
Thanks for looking into it!

Juha Manninen

2011-09-15 10:08

developer   ~0051847

Applied and tested also on Linux.
Thanks.
Thanks for applying all the patches :)
BTW I forgot to comment about some changes in the LFM (or strip them...).
It would have to be updated some day anyway, but...
'cobines' just resported a bug pertaining to the TButtonPanel additions in the LFM: 0020252
Juha, sorry, I can't believe I overlooked this: the PropEditor isn't assigning the pasted image to the property.
TGraphicPropertyEditor.Edit (ideintf\graphpropedits.pas, line 183) checks whether the file exists and only loads from it :-/ I'll prepare a new patch.

Felipe Monteiro de Carvalho

2011-10-03 10:49

developer   ~0052424

Discussion can continue in the issue 20252

Flávio Etrusco (notifications not working)

2011-10-03 18:13

developer   ~0052458

Last edited: 2011-10-03 18:15

Edit: I think the issue was changed in error.

2011-10-08 10:13

 

graphiceditor-cleanup-and-fix-paste-r32724.patch (12,096 bytes)
ec580b2c30d06be5165f99d216a4636c8752665a
diff --git ideintf/graphicpropedit.lfm ideintf/graphicpropedit.lfm
index 129faf3..ed16f86 100644
--- ideintf/graphicpropedit.lfm
+++ ideintf/graphicpropedit.lfm
@@ -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
diff --git ideintf/graphicpropedit.pas ideintf/graphicpropedit.pas
index 64ca72b..1ccab19 100644
--- ideintf/graphicpropedit.pas
+++ ideintf/graphicpropedit.pas
@@ -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
+  Result := ImagePreview.Picture.Graphic;
+end;
+
+procedure TGraphicPropertyEditorForm.SetGraphic(Value: TGraphic);
+begin
+  ImagePreview.Picture.Assign(Value);
+  FModified := False;
+end;
+
+procedure TGraphicPropertyEditorForm.SetCaptionDetail(Value: String);
 begin
-  if FModified = AValue then Exit;
-  FModified := AValue;
+  Caption := oisLoadImageDialog + ' - ' + Value;
 end;
 
 end.
diff --git ideintf/graphpropedits.pas ideintf/graphpropedits.pas
index da7e667..b8eda65 100644
--- ideintf/graphpropedits.pas
+++ ideintf/graphpropedits.pas
@@ -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;
+          AGraphic := TGraphicClass(GetTypeData(GetPropType)^.ClassType).Create;
+          FreeGraphic := True;
+        end;
 
-          if FreeGraphic then 
-            AGraphic := TGraphicClass(GetTypeData(GetPropType)^.ClassType).Create;
+        AGraphic.Assign(TheDialog.Graphic);
 
-          if AGraphic.ClassType = TheDialog.Preview.Picture.Graphic.ClassType then
-            AGraphic.LoadFromFile(TheDialog.FileName)
+        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
-            AGraphic.Assign(TheDialog.Preview.Picture.Graphic);
-
-          SetPtrValue(AGraphic);
-          Modified;
+            //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;
New patch attached. But I just realized I forgot to ask about the messages (Dlgs). In case it's decided they are desirable, I can prepare a patch with localizable strings.

Juha Manninen

2011-10-08 13:29

developer   ~0052772

I applied the new patch in r32766. It seems to work, thanks.

Yes, all GUI texts should support localization. I will keep this issue open in case you want fix it, too.
So they are desirable? I'll provide a patch then. (Did you see I meant some info&warning messages that are commented out in the code?)

Juha Manninen

2011-10-08 22:15

developer   ~0052789

Ah yes, you meant the commented out messages. I personally don't like many messages all the time so I guess they are OK now.

I was thinking of the Copy and Paste texts. I fixed them in r32770.

Issue History

Date Modified Username Field Change
2011-09-14 17:12 Flávio Etrusco (notifications not working) New Issue
2011-09-14 17:12 Flávio Etrusco (notifications not working) File Added: GraphicPropEdit-implement-copy-paste-r32336.patch
2011-09-14 17:12 Flávio Etrusco (notifications not working) LazTarget => -
2011-09-14 17:50 Flávio Etrusco (notifications not working) LazTarget - => 0.99.0
2011-09-14 17:50 Flávio Etrusco (notifications not working) Target Version => 0.99.0
2011-09-15 00:33 Juha Manninen Status new => assigned
2011-09-15 00:33 Juha Manninen Assigned To => Juha Manninen
2011-09-15 00:34 Juha Manninen Note Added: 0051832
2011-09-15 00:37 Flávio Etrusco (notifications not working) Note Added: 0051833
2011-09-15 00:38 Flávio Etrusco (notifications not working) Note Edited: 0051833
2011-09-15 10:08 Juha Manninen Fixed in Revision => r32344
2011-09-15 10:08 Juha Manninen Status assigned => resolved
2011-09-15 10:08 Juha Manninen Resolution open => fixed
2011-09-15 10:08 Juha Manninen Note Added: 0051847
2011-09-15 12:00 Flávio Etrusco (notifications not working) Note Added: 0051851
2011-09-22 12:06 Flávio Etrusco (notifications not working) Status resolved => assigned
2011-09-22 12:06 Flávio Etrusco (notifications not working) Resolution fixed => reopened
2011-09-22 12:06 Flávio Etrusco (notifications not working) Note Added: 0052101
2011-10-03 10:49 Felipe Monteiro de Carvalho Relationship added parent of 0020252
2011-10-03 10:49 Felipe Monteiro de Carvalho Status assigned => resolved
2011-10-03 10:49 Felipe Monteiro de Carvalho Resolution reopened => fixed
2011-10-03 10:49 Felipe Monteiro de Carvalho Note Added: 0052424
2011-10-03 18:13 Flávio Etrusco (notifications not working) Note Added: 0052458
2011-10-03 18:15 Flávio Etrusco (notifications not working) Note Edited: 0052458
2011-10-03 18:16 Flávio Etrusco (notifications not working) Status resolved => assigned
2011-10-03 18:16 Flávio Etrusco (notifications not working) Resolution fixed => reopened
2011-10-08 10:13 Flávio Etrusco (notifications not working) File Added: graphiceditor-cleanup-and-fix-paste-r32724.patch
2011-10-08 10:17 Flávio Etrusco (notifications not working) Note Added: 0052771
2011-10-08 13:29 Juha Manninen Note Added: 0052772
2011-10-08 17:28 Flávio Etrusco (notifications not working) Note Added: 0052781
2011-10-08 22:15 Juha Manninen Fixed in Revision r32344 => r32344, r32766, r32770
2011-10-08 22:15 Juha Manninen Status assigned => resolved
2011-10-08 22:15 Juha Manninen Resolution reopened => fixed
2011-10-08 22:15 Juha Manninen Note Added: 0052789