Browse Source

ADD: Hotkey to edit comment dialog

Alexander Koblov 11 years ago
parent
commit
f566bbb94e
5 changed files with 80 additions and 21 deletions
  1. 23 15
      src/fdescredit.lfm
  2. 1 0
      src/fdescredit.lrt
  3. 48 5
      src/fdescredit.pas
  4. 7 1
      src/uglobs.pas
  5. 1 0
      src/ulng.pas

+ 23 - 15
src/fdescredit.lfm

@@ -10,14 +10,14 @@ object frmDescrEdit: TfrmDescrEdit
   ClientWidth = 400
   OnCreate = FormCreate
   Position = poScreenCenter
-  LCLVersion = '1.1'
+  LCLVersion = '1.2.0.3'
   object lblEditCommentFor: TLabel
     AnchorSideLeft.Control = Owner
     AnchorSideTop.Control = Owner
     Left = 12
-    Height = 18
+    Height = 13
     Top = 12
-    Width = 115
+    Width = 85
     BorderSpacing.Left = 12
     BorderSpacing.Top = 12
     Caption = 'E&dit comment for:'
@@ -28,10 +28,10 @@ object frmDescrEdit: TfrmDescrEdit
     AnchorSideTop.Control = cbEncoding
     AnchorSideTop.Side = asrCenter
     AnchorSideRight.Control = cbEncoding
-    Left = 214
-    Height = 18
-    Top = 216
-    Width = 62
+    Left = 229
+    Height = 13
+    Top = 223
+    Width = 47
     Anchors = [akTop, akRight]
     BorderSpacing.Right = 12
     Caption = '&Encoding:'
@@ -43,9 +43,9 @@ object frmDescrEdit: TfrmDescrEdit
     AnchorSideTop.Control = lblEditCommentFor
     AnchorSideTop.Side = asrBottom
     Left = 12
-    Height = 18
-    Top = 36
-    Width = 27
+    Height = 13
+    Top = 31
+    Width = 18
     BorderSpacing.Top = 6
     Caption = '???'
     Font.Style = [fsBold]
@@ -60,8 +60,8 @@ object frmDescrEdit: TfrmDescrEdit
     AnchorSideRight.Side = asrBottom
     AnchorSideBottom.Control = cbEncoding
     Left = 12
-    Height = 136
-    Top = 62
+    Height = 155
+    Top = 52
     Width = 376
     Anchors = [akTop, akLeft, akRight, akBottom]
     BorderSpacing.Left = 12
@@ -76,12 +76,12 @@ object frmDescrEdit: TfrmDescrEdit
     AnchorSideRight.Side = asrBottom
     AnchorSideBottom.Control = btnCancel
     Left = 288
-    Height = 30
-    Top = 210
+    Height = 21
+    Top = 219
     Width = 100
     Anchors = [akRight, akBottom]
     BorderSpacing.Bottom = 12
-    ItemHeight = 0
+    ItemHeight = 13
     OnChange = cbEncodingChange
     Style = csDropDownList
     TabOrder = 1
@@ -120,4 +120,12 @@ object frmDescrEdit: TfrmDescrEdit
     ModalResult = 2
     TabOrder = 3
   end
+  object ActionList: TActionList
+    left = 104
+    top = 224
+    object actSaveDescription: TAction
+      Caption = 'Save Description'
+      OnExecute = actExecute
+    end
+  end
 end

+ 1 - 0
src/fdescredit.lrt

@@ -4,3 +4,4 @@ TFRMDESCREDIT.LBLENCODING.CAPTION=&Encoding:
 TFRMDESCREDIT.LBLFILENAME.CAPTION=???
 TFRMDESCREDIT.BTNOK.CAPTION=&OK
 TFRMDESCREDIT.BTNCANCEL.CAPTION=&Cancel
+TFRMDESCREDIT.ACTSAVEDESCRIPTION.CAPTION=Save Description

+ 48 - 5
src/fdescredit.pas

@@ -3,7 +3,7 @@
    -------------------------------------------------------------------------
    Dialog for editing file comments.
 
-   Copyright (C) 2008-2010  Koblov Alexander (A[email protected])
+   Copyright (C) 2008-2014 Alexander Koblov (a[email protected])
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -27,13 +27,16 @@ unit fDescrEdit;
 interface
 
 uses
-  Classes, SysUtils, Forms, Controls, StdCtrls, Buttons, uDescr;
+  Classes, SysUtils, Forms, Controls, StdCtrls, Buttons, ActnList, uDescr,
+  uFormCommands;
 
 type
 
   { TfrmDescrEdit }
 
-  TfrmDescrEdit = class(TForm)
+  TfrmDescrEdit = class(TForm, IFormCommands)
+    actSaveDescription: TAction;
+    ActionList: TActionList;
     btnOK: TBitBtn;
     btnCancel: TBitBtn;
     cbEncoding: TComboBox;
@@ -41,13 +44,18 @@ type
     lblEncoding: TLabel;
     lblEditCommentFor: TLabel;
     memDescr: TMemo;
+    procedure actExecute(Sender: TObject);
     procedure cbEncodingChange(Sender: TObject);
     procedure FormCreate(Sender: TObject);
   private
     FDescr: TDescription;
+    FCommands: TFormCommands;
     procedure DisplayEncoding;
+    property Commands: TFormCommands read FCommands implements IFormCommands;
   public
-    { public declarations }
+    constructor Create(TheOwner: TComponent); override;
+  published
+    procedure cm_SaveDescription(const Params: array of string);
   end; 
 
 function ShowDescrEditDlg(sFileName: String): Boolean;
@@ -57,7 +65,10 @@ implementation
 {$R *.lfm}
 
 uses
-  LConvEncoding;
+  LConvEncoding, DCStrUtils, uHotkeyManager, uLng, uGlobs;
+
+const
+  HotkeysCategory = 'Edit Comment Dialog';
 
 function ShowDescrEditDlg(sFileName: String): Boolean;
 const
@@ -85,10 +96,19 @@ end;
 { TfrmDescrEdit }
 
 procedure TfrmDescrEdit.FormCreate(Sender: TObject);
+var
+  HMForm: THMForm;
+  Hotkey: THotkey;
 begin
   // fill encoding combobox
   cbEncoding.Clear;
   GetSupportedEncodings(cbEncoding.Items);
+
+  HMForm := HotMan.Register(Self, HotkeysCategory);
+  Hotkey := HMForm.Hotkeys.FindByCommand('cm_SaveDescription');
+
+  if Assigned(Hotkey) then
+    btnOK.Caption := btnOK.Caption + ' (' + ShortcutsToText(Hotkey.Shortcuts) + ')';
 end;
 
 procedure TfrmDescrEdit.DisplayEncoding;
@@ -103,11 +123,34 @@ begin
       end;
 end;
 
+constructor TfrmDescrEdit.Create(TheOwner: TComponent);
+begin
+  inherited Create(TheOwner);
+  FCommands := TFormCommands.Create(Self, actionList);
+end;
+
+procedure TfrmDescrEdit.cm_SaveDescription(const Params: array of string);
+begin
+  ModalResult:= btnOK.ModalResult;
+end;
+
 procedure TfrmDescrEdit.cbEncodingChange(Sender: TObject);
 begin
   FDescr.Encoding:= cbEncoding.Text;
   memDescr.Lines.Text:= FDescr.ReadDescription(lblFileName.Caption);
 end;
 
+procedure TfrmDescrEdit.actExecute(Sender: TObject);
+var
+  cmd: string;
+begin
+  cmd := (Sender as TAction).Name;
+  cmd := 'cm_' + Copy(cmd, 4, Length(cmd) - 3);
+  Commands.ExecuteCommand(cmd, []);
+end;
+
+initialization
+  TFormCommands.RegisterCommandsForm(TfrmDescrEdit, HotkeysCategory, @rsHotkeyCategoryEditCommentDialog);
+
 end.
 

+ 7 - 1
src/uglobs.pas

@@ -93,7 +93,7 @@ type
 
 const
   { Default hotkey list version number }
-  hkVersion     = 19;
+  hkVersion     = 20;
 
   // Previously existing names if reused must check for ConfigVersion >= X.
   // History:
@@ -766,6 +766,12 @@ begin
       AddIfNotExists(['F2'],[],'cm_AddToQueue');
     end;
 
+  HMForm := HotMan.Forms.FindOrCreate('Edit Comment Dialog');
+  with HMForm.Hotkeys do
+    begin
+      AddIfNotExists(['F2'],[],'cm_SaveDescription');
+    end;
+
   if not mbFileExists(gpCfgDir + gNameSCFile) then
     gNameSCFile := 'shortcuts.scf';
   HotMan.Save(gpCfgDir + gNameSCFile);

+ 1 - 0
src/ulng.pas

@@ -475,6 +475,7 @@ resourcestring
   rsHotkeyCategoryViewer = 'Viewer';
   rsHotkeyCategoryDiffer = 'Differ';
   rsHotkeyCategoryCopyMoveDialog = 'Copy/Move Dialog';
+  rsHotkeyCategoryEditCommentDialog = 'Edit Comment Dialog';
   // Plugins
   rsOptPluginsActive = 'Active';
   rsOptPluginsName = 'Name';