Procházet zdrojové kódy

ADD: Viewer - enable printing from plugins

Alexander Koblov před 6 roky
rodič
revize
9f479a0155

+ 27 - 0
components/doublecmd/dcxmlconfig.pas

@@ -73,6 +73,7 @@ type
     function GetValue(const RootNode: TDOMNode; const Path: DOMString; const ADefault: Integer): Integer;
     function GetValue(const RootNode: TDOMNode; const Path: DOMString; const ADefault: Int64): Int64;
     function GetValue(const RootNode: TDOMNode; const Path: DOMString; const ADefault: Double): Double;
+    function GetValue(const RootNode: TDOMNode; const Path: DOMString; constref ADefault: TRect): TRect;
 
     // The Try... functions return True if the attribute/node was found and only then set AValue.
     function TryGetAttr(const RootNode: TDOMNode; const Path: DOMString; out AValue: String): Boolean;
@@ -111,6 +112,7 @@ type
     procedure SetValue(const RootNode: TDOMNode; const Path: DOMString; const AValue: Integer);
     procedure SetValue(const RootNode: TDOMNode; const Path: DOMString; const AValue: Int64);
     procedure SetValue(const RootNode: TDOMNode; const Path: DOMString; const AValue: Double);
+    procedure SetValue(const RootNode: TDOMNode; const Path: DOMString; constref AValue: TRect);
 
     // ------------------------------------------------------------------------
 
@@ -317,6 +319,21 @@ begin
   Result := StrToFloatDef(GetValue(RootNode, Path, ''), ADefault);
 end;
 
+function TXmlConfig.GetValue(const RootNode: TDOMNode; const Path: DOMString;
+  constref ADefault: TRect): TRect;
+var
+  I: Integer;
+  ARect: TStringArray;
+begin
+  ARect:= GetValue(RootNode, Path, '').Split(['|']);
+  if Length(ARect) <> 4 then
+    Result:= ADefault
+  else begin
+    for I:= 0 to 3 do
+      Result.Vector[I]:= StrToIntDef(ARect[I], ADefault.Vector[I]);
+  end;
+end;
+
 function TXmlConfig.TryGetValue(const RootNode: TDOMNode; const Path: DOMString; out AValue: String): Boolean;
 var
   Node: TDOMNode;
@@ -487,6 +504,16 @@ begin
   SetValue(RootNode, Path, FloatToStr(AValue));
 end;
 
+procedure TXmlConfig.SetValue(const RootNode: TDOMNode; const Path: DOMString;
+  constref AValue: TRect);
+var
+  S: String;
+begin
+  S:= IntToStr(AValue.Vector[0]) + '|' + IntToStr(AValue.Vector[1]) + '|' +
+      IntToStr(AValue.Vector[2]) + '|' + IntToStr(AValue.Vector[3]);
+  SetValue(RootNode, Path, S);
+end;
+
 // ----------------------------------------------------------------------------
 
 procedure TXmlConfig.ReadFromFile(const AFilename: String);

+ 18 - 5
src/doublecmd.lpi

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <CONFIG>
   <ProjectOptions>
-    <Version Value="10"/>
+    <Version Value="11"/>
     <PathDelim Value="\"/>
     <General>
       <Flags>
@@ -229,14 +229,19 @@ end;"/>
     </BuildModes>
     <PublishOptions>
       <Version Value="2"/>
-      <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
-      <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
     </PublishOptions>
     <RunParams>
       <local>
-        <FormatVersion Value="1"/>
         <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
       </local>
+      <FormatVersion Value="2"/>
+      <Modes Count="1">
+        <Mode0 Name="default">
+          <local>
+            <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
+          </local>
+        </Mode0>
+      </Modes>
     </RunParams>
     <RequiredPackages Count="12">
       <Item1>
@@ -284,7 +289,7 @@ end;"/>
         <MinVersion Minor="3" Valid="True"/>
       </Item12>
     </RequiredPackages>
-    <Units Count="257">
+    <Units Count="258">
       <Unit0>
         <Filename Value="doublecmd.lpr"/>
         <IsPartOfProject Value="True"/>
@@ -1856,6 +1861,14 @@ end;"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="uLuaPas"/>
       </Unit256>
+      <Unit257>
+        <Filename Value="fprintsetup.pas"/>
+        <IsPartOfProject Value="True"/>
+        <ComponentName Value="frmPrintSetup"/>
+        <HasResources Value="True"/>
+        <ResourceBaseClass Value="Form"/>
+        <UnitName Value="fPrintSetup"/>
+      </Unit257>
     </Units>
   </ProjectOptions>
   <CompilerOptions>

+ 152 - 0
src/fprintsetup.lfm

@@ -0,0 +1,152 @@
+object frmPrintSetup: TfrmPrintSetup
+  Left = 356
+  Height = 209
+  Top = 178
+  Width = 432
+  AutoSize = True
+  BorderStyle = bsDialog
+  Caption = 'Print configuration'
+  ChildSizing.LeftRightSpacing = 12
+  ChildSizing.TopBottomSpacing = 12
+  ClientHeight = 209
+  ClientWidth = 432
+  DesignTimePPI = 120
+  OnCloseQuery = FormCloseQuery
+  OnCreate = FormCreate
+  Position = poOwnerFormCenter
+  LCLVersion = '2.0.2.0'
+  object gbMargins: TGroupBox
+    AnchorSideLeft.Control = Owner
+    AnchorSideTop.Control = Owner
+    Left = 12
+    Height = 113
+    Top = 12
+    Width = 383
+    AutoSize = True
+    Caption = 'Margins (mm)'
+    ChildSizing.LeftRightSpacing = 8
+    ChildSizing.TopBottomSpacing = 10
+    ChildSizing.HorizontalSpacing = 8
+    ChildSizing.VerticalSpacing = 12
+    ChildSizing.Layout = cclLeftToRightThenTopToBottom
+    ChildSizing.ControlsPerLine = 4
+    ClientHeight = 88
+    ClientWidth = 379
+    ParentFont = False
+    TabOrder = 0
+    object lblLeft: TLabel
+      Left = 8
+      Height = 28
+      Top = 10
+      Width = 28
+      Caption = '&Left:'
+      FocusControl = seeLeft
+      ParentColor = False
+      ParentFont = False
+    end
+    object seeLeft: TFloatSpinEditEx
+      Left = 44
+      Height = 28
+      Top = 10
+      Width = 129
+      MaxLength = 0
+      ParentFont = False
+      TabOrder = 0
+      MinValue = 0
+      NullValue = 0
+      Value = 0
+    end
+    object lblRight: TLabel
+      Left = 181
+      Height = 28
+      Top = 10
+      Width = 53
+      Caption = '&Right:'
+      FocusControl = seeRight
+      ParentColor = False
+      ParentFont = False
+    end
+    object seeRight: TFloatSpinEditEx
+      Left = 242
+      Height = 28
+      Top = 10
+      Width = 129
+      MaxLength = 0
+      ParentFont = False
+      TabOrder = 1
+      MinValue = 0
+      NullValue = 0
+      Value = 0
+    end
+    object lblTop: TLabel
+      Left = 8
+      Height = 28
+      Top = 50
+      Width = 28
+      Caption = '&Top:'
+      FocusControl = seeTop
+      ParentColor = False
+      ParentFont = False
+    end
+    object seeTop: TFloatSpinEditEx
+      Left = 44
+      Height = 28
+      Top = 50
+      Width = 129
+      MaxLength = 0
+      ParentFont = False
+      TabOrder = 2
+      MinValue = 0
+      NullValue = 0
+      Value = 0
+    end
+    object lblBottom: TLabel
+      Left = 181
+      Height = 28
+      Top = 50
+      Width = 53
+      Caption = '&Bottom:'
+      FocusControl = seeBottom
+      ParentColor = False
+      ParentFont = False
+    end
+    object seeBottom: TFloatSpinEditEx
+      Left = 242
+      Height = 28
+      Top = 50
+      Width = 129
+      MaxLength = 0
+      ParentFont = False
+      TabOrder = 3
+      MinValue = 0
+      NullValue = 0
+      Value = 0
+    end
+  end
+  object ButtonPanel: TButtonPanel
+    AnchorSideLeft.Control = gbMargins
+    AnchorSideTop.Control = gbMargins
+    AnchorSideTop.Side = asrBottom
+    AnchorSideRight.Control = gbMargins
+    AnchorSideRight.Side = asrBottom
+    Left = 20
+    Height = 30
+    Top = 148
+    Width = 367
+    Align = alNone
+    Anchors = [akTop, akLeft, akRight]
+    BorderSpacing.Top = 15
+    BorderSpacing.Around = 8
+    OKButton.Name = 'OKButton'
+    OKButton.DefaultCaption = True
+    HelpButton.Name = 'HelpButton'
+    HelpButton.DefaultCaption = True
+    CloseButton.Name = 'CloseButton'
+    CloseButton.DefaultCaption = True
+    CancelButton.Name = 'CancelButton'
+    CancelButton.DefaultCaption = True
+    TabOrder = 1
+    ShowButtons = [pbOK, pbCancel]
+    ShowBevel = False
+  end
+end

+ 8 - 0
src/fprintsetup.lrj

@@ -0,0 +1,8 @@
+{"version":1,"strings":[
+{"hash":56375182,"name":"tfrmprintsetup.caption","sourcebytes":[80,114,105,110,116,32,99,111,110,102,105,103,117,114,97,116,105,111,110],"value":"Print configuration"},
+{"hash":6979065,"name":"tfrmprintsetup.gbmargins.caption","sourcebytes":[77,97,114,103,105,110,115,32,40,109,109,41],"value":"Margins (mm)"},
+{"hash":45268346,"name":"tfrmprintsetup.lblleft.caption","sourcebytes":[38,76,101,102,116,58],"value":"&Left:"},
+{"hash":193978202,"name":"tfrmprintsetup.lblright.caption","sourcebytes":[38,82,105,103,104,116,58],"value":"&Right:"},
+{"hash":2864698,"name":"tfrmprintsetup.lbltop.caption","sourcebytes":[38,84,111,112,58],"value":"&Top:"},
+{"hash":158054570,"name":"tfrmprintsetup.lblbottom.caption","sourcebytes":[38,66,111,116,116,111,109,58],"value":"&Bottom:"}
+]}

+ 63 - 0
src/fprintsetup.pas

@@ -0,0 +1,63 @@
+unit fPrintSetup;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ButtonPanel,
+  SpinEx, uOSForms;
+
+type
+
+  { TfrmPrintSetup }
+
+  TfrmPrintSetup = class(TModalForm)
+    ButtonPanel: TButtonPanel;
+    gbMargins: TGroupBox;
+    lblLeft: TLabel;
+    lblRight: TLabel;
+    lblTop: TLabel;
+    lblBottom: TLabel;
+    seeLeft: TFloatSpinEditEx;
+    seeRight: TFloatSpinEditEx;
+    seeTop: TFloatSpinEditEx;
+    seeBottom: TFloatSpinEditEx;
+    procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
+    procedure FormCreate(Sender: TObject);
+  private
+
+  public
+
+  end;
+
+implementation
+
+{$R *.lfm}
+
+uses
+  uGlobs;
+
+{ TfrmPrintSetup }
+
+procedure TfrmPrintSetup.FormCloseQuery(Sender: TObject; var CanClose: boolean);
+begin
+  if ModalResult = mrOK then
+  begin
+    gPrintMargins.Left:= Round(seeLeft.Value * 10);
+    gPrintMargins.Top:= Round(seeTop.Value * 10);
+    gPrintMargins.Right:= Round(seeRight.Value * 10);
+    gPrintMargins.Bottom:= Round(seeBottom.Value * 10);
+  end;
+end;
+
+procedure TfrmPrintSetup.FormCreate(Sender: TObject);
+begin
+  seeLeft.Value:= gPrintMargins.Left / 10;
+  seeTop.Value:= gPrintMargins.Top / 10;
+  seeRight.Value:= gPrintMargins.Right / 10;
+  seeBottom.Value:= gPrintMargins.Bottom / 10;
+end;
+
+end.
+

+ 16 - 4
src/fviewer.lfm

@@ -270,7 +270,7 @@ object frmViewer: TfrmViewer
   SessionProperties = 'Height;Width;Left;Top;WindowState'
   ShowHint = True
   ShowInTaskBar = stAlways
-  LCLVersion = '1.8.4.0'
+  LCLVersion = '2.0.3.0'
   object pnlFolder: TPanel
     Left = 179
     Height = 435
@@ -2487,9 +2487,10 @@ object frmViewer: TfrmViewer
         Action = actSaveAs
       end
       object miPrint: TMenuItem
-        Caption = 'Print...'
-        Enabled = False
-        ShortCut = 16464
+        Action = actPrint
+      end
+      object miPrintSetup: TMenuItem
+        Action = actPrintSetup
       end
       object miReload: TMenuItem
         Action = actReload
@@ -2885,6 +2886,17 @@ object frmViewer: TfrmViewer
       Caption = 'Auto Reload'
       OnExecute = actExecute
     end
+    object actPrintSetup: TAction
+      Category = 'File'
+      Caption = 'Print &setup...'
+      OnExecute = actExecute
+    end
+    object actPrint: TAction
+      Category = 'File'
+      Caption = 'P&rint...'
+      Enabled = False
+      OnExecute = actExecute
+    end
   end
   object TimerScreenshot: TTimer
     Enabled = False

+ 3 - 2
src/fviewer.lrj

@@ -20,7 +20,6 @@
 {"hash":175127959,"name":"tfrmviewer.gboxslideshow.caption","sourcebytes":[83,108,105,100,101,32,83,104,111,119],"value":"Slide Show"},
 {"hash":175127959,"name":"tfrmviewer.cbslideshow.caption","sourcebytes":[83,108,105,100,101,32,83,104,111,119],"value":"Slide Show"},
 {"hash":2805797,"name":"tfrmviewer.mifile.caption","sourcebytes":[38,70,105,108,101],"value":"&File"},
-{"hash":151352958,"name":"tfrmviewer.miprint.caption","sourcebytes":[80,114,105,110,116,46,46,46],"value":"Print..."},
 {"hash":2800388,"name":"tfrmviewer.miedit.caption","sourcebytes":[38,69,100,105,116],"value":"&Edit"},
 {"hash":2871239,"name":"tfrmviewer.miview.caption","sourcebytes":[38,86,105,101,119],"value":"&View"},
 {"hash":212198471,"name":"tfrmviewer.miencoding.caption","sourcebytes":[69,110,38,99,111,100,105,110,103],"value":"En&coding"},
@@ -83,5 +82,7 @@
 {"hash":73859572,"name":"tfrmviewer.actfindnext.caption","sourcebytes":[70,105,110,100,32,110,101,120,116],"value":"Find next"},
 {"hash":97034739,"name":"tfrmviewer.actfindprev.caption","sourcebytes":[70,105,110,100,32,112,114,101,118,105,111,117,115],"value":"Find previous"},
 {"hash":216568103,"name":"tfrmviewer.actchangeencoding.caption","sourcebytes":[67,104,97,110,103,101,32,101,110,99,111,100,105,110,103],"value":"Change encoding"},
-{"hash":96796260,"name":"tfrmviewer.actautoreload.caption","sourcebytes":[65,117,116,111,32,82,101,108,111,97,100],"value":"Auto Reload"}
+{"hash":96796260,"name":"tfrmviewer.actautoreload.caption","sourcebytes":[65,117,116,111,32,82,101,108,111,97,100],"value":"Auto Reload"},
+{"hash":216689422,"name":"tfrmviewer.actprintsetup.caption","sourcebytes":[80,114,105,110,116,32,38,115,101,116,117,112,46,46,46],"value":"Print &setup..."},
+{"hash":151339998,"name":"tfrmviewer.actprint.caption","sourcebytes":[80,38,114,105,110,116,46,46,46],"value":"P&rint..."}
 ]}

+ 26 - 3
src/fviewer.pas

@@ -92,6 +92,8 @@ type
     actCopyToClipboardFormatted: TAction;
     actChangeEncoding: TAction;
     actAutoReload: TAction;
+    actPrint: TAction;
+    actPrintSetup: TAction;
     actShowAsDec: TAction;
     actScreenShotDelay5sec: TAction;
     actScreenShotDelay3Sec: TAction;
@@ -142,6 +144,7 @@ type
     gboxSlideShow: TGroupBox;
     GifAnim: TGifAnim;
     memFolder: TMemo;
+    miPrintSetup: TMenuItem;
     miAutoReload: TMenuItem;
     pmiCopyFormatted: TMenuItem;
     miDec: TMenuItem;
@@ -427,6 +430,9 @@ type
 
     procedure cm_ExitViewer      (const Params: array of string);
 
+    procedure cm_Print(const Params:array of string);
+    procedure cm_PrintSetup(const Params:array of string);
+
   end;
 
 procedure ShowViewer(const FilesToView:TStringList; const aFileSource: IFileSource = nil);
@@ -438,7 +444,8 @@ implementation
 uses
   FileUtil, IntfGraphics, Math, uLng, uShowMsg, uGlobs, LCLType, LConvEncoding,
   DCClassesUtf8, uFindMmap, DCStrUtils, uDCUtils, LCLIntf, uDebug, uHotkeyManager,
-  uConvEncoding, DCBasicTypes, DCOSUtils, uOSUtils, uFindByrMr, uFileViewWithGrid;
+  uConvEncoding, DCBasicTypes, DCOSUtils, uOSUtils, uFindByrMr, uFileViewWithGrid,
+  fPrintSetup;
 
 const
   HotkeysCategory = 'Viewer';
@@ -1298,7 +1305,7 @@ begin
         ActivePlugin:= I;
         FWlxModule:= WlxModule;
         WlxModule.ResizeWindow(GetListerRect);
-        miPrint.Enabled:= WlxModule.CanPrint;
+        actPrint.Enabled:= WlxModule.CanPrint;
         // Set focus to plugin window
         if not bQuickView then WlxModule.SetFocus;
         Exit(True);
@@ -1319,7 +1326,7 @@ begin
   bPlugin:= False;
   FWlxModule:= nil;
   ActivePlugin:= -1;
-  miPrint.Enabled:= False;
+  actPrint.Enabled:= False;
 end;
 
 procedure TfrmViewer.ShowTextViewer(AMode: TViewerControlMode);
@@ -2904,6 +2911,22 @@ begin
   Close;
 end;
 
+procedure TfrmViewer.cm_Print(const Params: array of string);
+begin
+  if bPlugin and actPrint.Enabled then
+    FWlxModule.CallListPrint(ExtractFileName(FileList.Strings[iActiveFile]), '', 0, gPrintMargins);
+end;
+
+procedure TfrmViewer.cm_PrintSetup(const Params: array of string);
+begin
+  with TfrmPrintSetup.Create(Self) do
+  try
+    ShowModal;
+  finally
+    Free;
+  end;
+end;
+
 initialization
   TFormCommands.RegisterCommandsForm(TfrmViewer, HotkeysCategory, @rsHotkeyCategoryViewer);
 

+ 6 - 1
src/uglobs.pas

@@ -163,7 +163,7 @@ type
 
 const
   { Default hotkey list version number }
-  hkVersion = 47;
+  hkVersion = 48;
   // 47 - In "Copy/Move Dialog" context, add the shortcuts "F5" and "F6" for "cm_ToggleSelectionInName".
   // 40 - In "Main" context, added the "Ctrl+Shift+F7" for "cm_AddNewSearch".
   //      In "Find Files" context, changed "cm_Start" that was "Enter" for "F9".
@@ -582,6 +582,7 @@ var
   gBookBackgroundColor,
   gBookFontColor: TColor;
   gTextPosition:PtrInt;
+  gPrintMargins: TRect;
 
   { Editor }
   gEditWaitTime: Integer;
@@ -1123,6 +1124,7 @@ begin
       //AddIfNotExists(['Up'],[],'cm_Rotate270');  // how at once add this keys only to Image control?
       //AddIfNotExists(['Down'],[],'cm_Rotate90');
 
+      AddIfNotExists(VK_P, [ssModifier], 'cm_Print');
       AddIfNotExists(VK_A, [ssModifier], 'cm_SelectAll');
       AddIfNotExists(VK_C, [ssModifier], 'cm_CopyToClipboard');
 
@@ -1802,6 +1804,7 @@ begin
   gBookFontColor := clWhite;
   gTextPosition:= 0;
   gViewerMode:= 0;
+  gPrintMargins:= Classes.Rect(200, 200, 200, 200);
 
   { Editor }
   gEditWaitTime := 2000;
@@ -2800,6 +2803,7 @@ begin
       gTabSpaces := GetValue(Node, 'TabSpaces', gTabSpaces);
       gMaxTextWidth := GetValue(Node, 'MaxTextWidth', gMaxTextWidth);
       gViewerMode  := GetValue(Node, 'ViewerMode'  , gViewerMode);
+      gPrintMargins := GetValue(Node, 'PrintMargins'  , gPrintMargins);
 
       gImagePaintColor := GetValue(Node, 'PaintColor', gImagePaintColor);
       gBookBackgroundColor := GetValue(Node, 'BackgroundColor', gBookBackgroundColor);
@@ -3338,6 +3342,7 @@ begin
     SetValue(Node, 'TabSpaces', gTabSpaces);
     SetValue(Node, 'MaxTextWidth', gMaxTextWidth);
     SetValue(Node, 'ViewerMode' , gViewerMode);
+    SetValue(Node, 'PrintMargins', gPrintMargins);
 
     SetValue(Node, 'PaintColor', gImagePaintColor);
     SetValue(Node, 'BackgroundColor', gBookBackgroundColor);