2
0
Эх сурвалжийг харах

ADD: Force text mode when open internal Viewer (fixes #745)

Alexander Koblov 2 жил өмнө
parent
commit
4e41285416
3 өөрчлөгдсөн 113 нэмэгдсэн , 17 устгасан
  1. 31 15
      src/fviewer.pas
  2. 36 2
      src/umaincommands.pas
  3. 46 0
      src/ushowform.pas

+ 31 - 15
src/fviewer.pas

@@ -3,7 +3,7 @@
    -------------------------------------------------------------------------
    Build-in File Viewer.
 
-   Copyright (C) 2007-2020  Alexander Koblov ([email protected])
+   Copyright (C) 2007-2023  Alexander Koblov ([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
@@ -348,6 +348,7 @@ type
     FWindowBounds: TRect;
 {$ENDIF}
     FThread: TThread;
+    FMode: Integer;
 
     FRegExp: TRegExprEx;
     FPluginEncoding: Integer;
@@ -466,7 +467,8 @@ type
     procedure cm_WrapText(const Params: array of string);
   end;
 
-procedure ShowViewer(const FilesToView:TStringList; WaitData: TWaitData = nil);
+procedure ShowViewer(const FilesToView: TStringList; WaitData: TWaitData = nil); overload;
+procedure ShowViewer(const FilesToView: TStringList; AMode: Integer; WaitData: TWaitData = nil); overload;
 
 implementation
 
@@ -516,6 +518,12 @@ type
   end;
 
 procedure ShowViewer(const FilesToView: TStringList; WaitData: TWaitData);
+begin
+  ShowViewer(FilesToView, 0, WaitData);
+end;
+
+procedure ShowViewer(const FilesToView: TStringList; AMode: Integer;
+  WaitData: TWaitData);
 var
   Viewer: TfrmViewer;
 begin
@@ -526,12 +534,18 @@ begin
   Viewer.actMoveFile.Enabled := FilesToView.Count > 1;
   Viewer.actDeleteFile.Enabled := FilesToView.Count > 1;
   with Viewer.ViewerControl do
-  case gViewerMode of
-    1: Mode:= vcmText;
-    2: Mode:= vcmBin;
-    3: Mode:= vcmHex;
-    4: Mode:= vcmWrap;
-    //5: Mode:= vcmBook;
+  begin
+    if (AMode = 0) then
+      AMode:= gViewerMode
+    else begin
+      Viewer.FMode:= AMode;
+    end;
+    case AMode of
+      1: Mode:= vcmText;
+      2: Mode:= vcmBin;
+      3: Mode:= vcmHex;
+      6: Mode:= vcmDec;
+    end;
   end;
   Viewer.LoadFile(0);
 
@@ -715,7 +729,13 @@ begin
     else begin
       aName:= aFileName;
     end;
-    if CheckPlugins(aName) then
+    if (FMode > 0) then
+    begin
+      ViewerControl.FileName := aFileName;
+      ActivatePanel(pnlText);
+      FMode:= 0;
+    end
+    else if CheckPlugins(aName) then
       ActivatePanel(nil)
     else if FPS_ISDIR(dwFileAttributes) then
       begin
@@ -1921,12 +1941,8 @@ begin
     vcmText: gViewerMode := 1;
     vcmBin : gViewerMode := 2;
     vcmHex : gViewerMode := 3;
-    vcmWrap: gViewerMode := 4;
-    vcmBook:
-      begin
-        gViewerMode := 4;
-        gTextPosition := ViewerControl.Position;
-      end;
+    vcmDec : gViewerMode := 6;
+    vcmBook: gTextPosition := ViewerControl.Position;
   end;
 
   if Assigned(WlxPlugins) then ExitPluginMode;

+ 36 - 2
src/umaincommands.pas

@@ -4,7 +4,7 @@
    This unit contains DC actions of the main form
 
    Copyright (C) 2008  Dmitry Kolomiets ([email protected])
-   Copyright (C) 2008-2021 Alexander Koblov ([email protected])
+   Copyright (C) 2008-2023 Alexander Koblov ([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
@@ -386,7 +386,7 @@ uses fOptionsPluginsBase, fOptionsPluginsDSX, fOptionsPluginsWCX,
      fLinker, fSplitter, fDescrEdit, fCheckSumVerify, fCheckSumCalc, fSetFileProperties,
      uLng, uLog, uShowMsg, uOSForms, uOSUtils, uDCUtils, uBriefFileView, fSelectDuplicates,
      uShowForm, uShellExecute, uClipboard, uHash, uDisplayFile, uLuaPas, uSysFolders,
-     uFilePanelSelect, uFileSystemFileSource, uQuickViewPanel, Math,
+     uFilePanelSelect, uFileSystemFileSource, uQuickViewPanel, Math, fViewer,
      uOperationsManager, uFileSourceOperationTypes, uWfxPluginFileSource,
      uFileSystemDeleteOperation, uFileSourceExecuteOperation, uSearchResultFileSource,
      uFileSourceOperationMessageBoxesUI, uFileSourceCalcChecksumOperation,
@@ -1948,6 +1948,8 @@ procedure TMainCommands.cm_View(const Params: array of string);
 var
   aFile: TFile;
   i, n: Integer;
+  AMode: Integer = 0;
+  Param, AValue: String;
   sl: TStringList = nil;
   ActiveFile: TFile = nil;
   AllFiles: TFiles = nil;
@@ -1971,6 +1973,38 @@ begin
       Exit;
     end;
 
+    if (SelectedFiles.Count = 1) and (Length(Params) > 0) then
+    begin
+      for Param in Params do
+      begin
+        if GetParamValue(Param, 'mode', AValue) then
+        begin
+          case LowerCase(AValue) of
+          'text': AMode:= 1;
+          'bin':  AMode:= 2;
+          'hex':  AMode:= 3;
+          'dec':  AMode:= 6;
+          end;
+          Break;
+        end;
+      end;
+      if (AMode > 0) then
+      begin
+        with TViewerModeData.Create(AMode) do
+        begin
+          if PrepareData(ActiveFrame.FileSource, SelectedFiles, @OnCopyOutStateChanged) = pdrInCallback then
+          begin
+            Exit;
+          end;
+          Free;
+        end;
+        sl := TStringList.Create;
+        sl.Add(SelectedFiles[0].FullPath);
+        ShowViewer(sl, AMode);
+        Exit;
+      end;
+    end;
+
     if SelectedFiles.Count = 0 then
     begin
       msgWarning(rsMsgNoFilesSelected);

+ 46 - 0
src/ushowform.pas

@@ -79,6 +79,17 @@ type
                                    State: TFileSourceOperationState);
   end;
 
+  { TViewerModeData }
+
+  TViewerModeData = class
+  private
+    FMode: Integer;
+  public
+    constructor Create(AMode: Integer);
+    procedure OnCopyOutStateChanged(Operation: TFileSourceOperation;
+                                    State: TFileSourceOperationState);
+  end;
+
   TToolDataPreparedProc = procedure(const FileList: TStringList; WaitData: TWaitData; Modal: Boolean = False);
 
   // Callback may be called either asynchoronously or synchronously (for modal operations)
@@ -573,6 +584,41 @@ begin
     Result.Add(Files[I].FullPath);
 end;
 
+{ TViewerModeData }
+
+constructor TViewerModeData.Create(AMode: Integer);
+begin
+  FMode:= AMode;
+end;
+
+procedure TViewerModeData.OnCopyOutStateChanged(
+  Operation: TFileSourceOperation; State: TFileSourceOperationState);
+var
+  aFileList: TStringList;
+  aFileSource: ITempFileSystemFileSource;
+  aCopyOutOperation: TFileSourceCopyOperation;
+begin
+  try
+    if (State = fsosStopped) and (Operation.Result = fsorFinished) then
+    begin
+      aFileList := TStringList.Create;
+      try
+        aCopyOutOperation := Operation as TFileSourceCopyOperation;
+        aFileSource := aCopyOutOperation.TargetFileSource as ITempFileSystemFileSource;
+        ChangeFileListRoot(aFileSource.FileSystemRoot, aCopyOutOperation.SourceFiles);
+
+        aFileList.Add(aCopyOutOperation.SourceFiles[0].FullPath);
+
+        ShowViewer(aFileList, FMode, TViewerWaitData.Create(aFileSource));
+      finally
+        aFileList.Free;
+      end;
+    end;
+  finally
+    Free;
+  end;
+end;
+
 { TExtToolWaitThread }
 
 procedure TExtToolWaitThread.RunEditDone;