소스 검색

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

Alexander Koblov 2 년 전
부모
커밋
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.
    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
    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
    it under the terms of the GNU General Public License as published by
@@ -348,6 +348,7 @@ type
     FWindowBounds: TRect;
     FWindowBounds: TRect;
 {$ENDIF}
 {$ENDIF}
     FThread: TThread;
     FThread: TThread;
+    FMode: Integer;
 
 
     FRegExp: TRegExprEx;
     FRegExp: TRegExprEx;
     FPluginEncoding: Integer;
     FPluginEncoding: Integer;
@@ -466,7 +467,8 @@ type
     procedure cm_WrapText(const Params: array of string);
     procedure cm_WrapText(const Params: array of string);
   end;
   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
 implementation
 
 
@@ -516,6 +518,12 @@ type
   end;
   end;
 
 
 procedure ShowViewer(const FilesToView: TStringList; WaitData: TWaitData);
 procedure ShowViewer(const FilesToView: TStringList; WaitData: TWaitData);
+begin
+  ShowViewer(FilesToView, 0, WaitData);
+end;
+
+procedure ShowViewer(const FilesToView: TStringList; AMode: Integer;
+  WaitData: TWaitData);
 var
 var
   Viewer: TfrmViewer;
   Viewer: TfrmViewer;
 begin
 begin
@@ -526,12 +534,18 @@ begin
   Viewer.actMoveFile.Enabled := FilesToView.Count > 1;
   Viewer.actMoveFile.Enabled := FilesToView.Count > 1;
   Viewer.actDeleteFile.Enabled := FilesToView.Count > 1;
   Viewer.actDeleteFile.Enabled := FilesToView.Count > 1;
   with Viewer.ViewerControl do
   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;
   end;
   Viewer.LoadFile(0);
   Viewer.LoadFile(0);
 
 
@@ -715,7 +729,13 @@ begin
     else begin
     else begin
       aName:= aFileName;
       aName:= aFileName;
     end;
     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)
       ActivatePanel(nil)
     else if FPS_ISDIR(dwFileAttributes) then
     else if FPS_ISDIR(dwFileAttributes) then
       begin
       begin
@@ -1921,12 +1941,8 @@ begin
     vcmText: gViewerMode := 1;
     vcmText: gViewerMode := 1;
     vcmBin : gViewerMode := 2;
     vcmBin : gViewerMode := 2;
     vcmHex : gViewerMode := 3;
     vcmHex : gViewerMode := 3;
-    vcmWrap: gViewerMode := 4;
-    vcmBook:
-      begin
-        gViewerMode := 4;
-        gTextPosition := ViewerControl.Position;
-      end;
+    vcmDec : gViewerMode := 6;
+    vcmBook: gTextPosition := ViewerControl.Position;
   end;
   end;
 
 
   if Assigned(WlxPlugins) then ExitPluginMode;
   if Assigned(WlxPlugins) then ExitPluginMode;

+ 36 - 2
src/umaincommands.pas

@@ -4,7 +4,7 @@
    This unit contains DC actions of the main form
    This unit contains DC actions of the main form
 
 
    Copyright (C) 2008  Dmitry Kolomiets ([email protected])
    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
    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
    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,
      fLinker, fSplitter, fDescrEdit, fCheckSumVerify, fCheckSumCalc, fSetFileProperties,
      uLng, uLog, uShowMsg, uOSForms, uOSUtils, uDCUtils, uBriefFileView, fSelectDuplicates,
      uLng, uLog, uShowMsg, uOSForms, uOSUtils, uDCUtils, uBriefFileView, fSelectDuplicates,
      uShowForm, uShellExecute, uClipboard, uHash, uDisplayFile, uLuaPas, uSysFolders,
      uShowForm, uShellExecute, uClipboard, uHash, uDisplayFile, uLuaPas, uSysFolders,
-     uFilePanelSelect, uFileSystemFileSource, uQuickViewPanel, Math,
+     uFilePanelSelect, uFileSystemFileSource, uQuickViewPanel, Math, fViewer,
      uOperationsManager, uFileSourceOperationTypes, uWfxPluginFileSource,
      uOperationsManager, uFileSourceOperationTypes, uWfxPluginFileSource,
      uFileSystemDeleteOperation, uFileSourceExecuteOperation, uSearchResultFileSource,
      uFileSystemDeleteOperation, uFileSourceExecuteOperation, uSearchResultFileSource,
      uFileSourceOperationMessageBoxesUI, uFileSourceCalcChecksumOperation,
      uFileSourceOperationMessageBoxesUI, uFileSourceCalcChecksumOperation,
@@ -1948,6 +1948,8 @@ procedure TMainCommands.cm_View(const Params: array of string);
 var
 var
   aFile: TFile;
   aFile: TFile;
   i, n: Integer;
   i, n: Integer;
+  AMode: Integer = 0;
+  Param, AValue: String;
   sl: TStringList = nil;
   sl: TStringList = nil;
   ActiveFile: TFile = nil;
   ActiveFile: TFile = nil;
   AllFiles: TFiles = nil;
   AllFiles: TFiles = nil;
@@ -1971,6 +1973,38 @@ begin
       Exit;
       Exit;
     end;
     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
     if SelectedFiles.Count = 0 then
     begin
     begin
       msgWarning(rsMsgNoFilesSelected);
       msgWarning(rsMsgNoFilesSelected);

+ 46 - 0
src/ushowform.pas

@@ -79,6 +79,17 @@ type
                                    State: TFileSourceOperationState);
                                    State: TFileSourceOperationState);
   end;
   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);
   TToolDataPreparedProc = procedure(const FileList: TStringList; WaitData: TWaitData; Modal: Boolean = False);
 
 
   // Callback may be called either asynchoronously or synchronously (for modal operations)
   // Callback may be called either asynchoronously or synchronously (for modal operations)
@@ -573,6 +584,41 @@ begin
     Result.Add(Files[I].FullPath);
     Result.Add(Files[I].FullPath);
 end;
 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 }
 { TExtToolWaitThread }
 
 
 procedure TExtToolWaitThread.RunEditDone;
 procedure TExtToolWaitThread.RunEditDone;