瀏覽代碼

Command-line switch /browse to either force opening the main window when a file URL is specified or to explicitly select a specified file in both file panels

To be used by Bug 1784

Source commit: c3858c36b938b52835cf4144ba9247c48b303fe8
Martin Prikryl 6 年之前
父節點
當前提交
9015d8106a

+ 8 - 0
source/forms/CustomScpExplorer.cpp

@@ -10689,3 +10689,11 @@ void __fastcall TCustomScpExplorerForm::RemoteDirViewResize(TObject *)
   CenterReconnectToolbar();
 }
 //---------------------------------------------------------------------------
+void __fastcall TCustomScpExplorerForm::BrowseFile()
+{
+  if (RemoteDirView->ItemFocused != NULL)
+  {
+    RemoteDirView->ItemFocused->Selected = true;
+  }
+}
+//---------------------------------------------------------------------------

+ 1 - 0
source/forms/CustomScpExplorer.h

@@ -817,6 +817,7 @@ public:
   void __fastcall PrivateKeyUpload();
   bool __fastcall IsComponentPossible(Byte Component);
   void __fastcall ReplaceTerminal(TManagedTerminal * value);
+  virtual void __fastcall BrowseFile();
 
   __property bool ComponentVisible[Byte Component] = { read = GetComponentVisible, write = SetComponentVisible };
   __property bool EnableFocusedOperation[TOperationSide Side] = { read = GetEnableFocusedOperation, index = 0 };

+ 20 - 0
source/forms/ScpCommander.cpp

@@ -2286,3 +2286,23 @@ void __fastcall TScpCommanderForm::FileColorsChanged()
   DoFileColorsChanged(LocalDirView);
 }
 //---------------------------------------------------------------------------
+void __fastcall TScpCommanderForm::BrowseFile()
+{
+  TCustomScpExplorerForm::BrowseFile();
+  if (LocalDirView->ItemFocused != NULL)
+  {
+    LocalDirView->ItemFocused->Selected = true;
+  }
+  TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
+  // Select the panel that has the file, with preference on the remote panel
+  if (RemoteDirView->ItemFocused->Selected)
+  {
+    ScpCommander.CurrentPanel = osRemote;
+  }
+  else if (LocalDirView->ItemFocused->Selected)
+  {
+    ScpCommander.CurrentPanel = osLocal;
+  }
+  WinConfiguration->ScpCommander = ScpCommander;
+}
+//---------------------------------------------------------------------------

+ 1 - 0
source/forms/ScpCommander.h

@@ -622,6 +622,7 @@ public:
   virtual void __fastcall GoToAddress();
   virtual void __fastcall CopyFilesToClipboard(TOperationSide Side, bool OnFocused);
   virtual void __fastcall PasteFromClipBoard();
+  virtual void __fastcall BrowseFile();
 
   __property double LeftPanelWidth = { read = GetLeftPanelWidth, write = SetLeftPanelWidth };
 };

+ 20 - 5
source/packages/filemng/CustomDirView.pas

@@ -504,6 +504,8 @@ resourcestring
   SDriveNotReady = 'Drive ''%s:'' is not ready.';
   SDirNotExists = 'Directory ''%s'' doesn''t exist.';
 
+function CreateDirViewStateForFocusedItem(FocusedItem: string): TObject;
+
 {Additional non-component specific functions:}
 
 {Create and resolve a shell link (file shortcut):}
@@ -621,6 +623,15 @@ begin
   inherited;
 end;
 
+function CreateDirViewStateForFocusedItem(FocusedItem: string): TObject;
+var
+  State: TDirViewState;
+begin
+  State := TDirViewState.Create;
+  State.FocusedItem := FocusedItem;
+  Result := State;
+end;
+
 function IsExecutable(FileName: string): Boolean;
 var
   FileExt: string;
@@ -3187,13 +3198,17 @@ begin
   State := AState as TDirViewState;
   Assert(Assigned(State));
 
-  FHistoryPaths.Assign(State.HistoryPaths);
+  if Assigned(State.HistoryPaths) then
+    FHistoryPaths.Assign(State.HistoryPaths);
   FBackCount := State.BackCount;
   DoHistoryChange;
-  // TCustomDirViewColProperties should not be here
-  DirColProperties := ColProperties as TCustomDirViewColProperties;
-  Assert(Assigned(DirColProperties));
-  DirColProperties.SortStr := State.SortStr;
+  if State.SortStr <> '' then
+  begin
+    // TCustomDirViewColProperties should not be here
+    DirColProperties := ColProperties as TCustomDirViewColProperties;
+    Assert(Assigned(DirColProperties));
+    DirColProperties.SortStr := State.SortStr;
+  end;
   Mask := State.Mask;
   if State.FocusedItem <> '' then
   begin

+ 1 - 0
source/resource/TextsWin.h

@@ -293,6 +293,7 @@
 #define CUSTOM_COMMAND_PATTERNS_HINT6 1583
 #define USAGE_PASSPHRASE        1584
 #define AUTO_WORKSPACE_ENABLE   1585
+#define USAGE_BROWSE            1586
 
 #define WIN_FORMS_STRINGS       1600
 #define COPY_FILE               1605

+ 1 - 0
source/resource/TextsWin1.rc

@@ -298,6 +298,7 @@ BEGIN
         CUSTOM_COMMAND_PATTERNS_HINT6, "!E expands to serialized connection data of current session"
         USAGE_PASSPHRASE, "A passphrase for an encrypted private key or a client certificate"
         AUTO_WORKSPACE_ENABLE, "Press 'No' to enable automatic saving of the workspace."
+        USAGE_BROWSE, "Selects the specified file in file panel(s)."
 
         WIN_FORMS_STRINGS, "WIN_FORMS_STRINGS"
         COPY_FILE, "%s file '%s' to %s:"

+ 2 - 0
source/windows/ConsoleRunner.cpp

@@ -2190,6 +2190,7 @@ void __fastcall Usage(TConsole * Console)
     PrintUsageSyntax(Console, FORMAT(L"[mysession] /%s=<name>", (LowerCase(SESSIONNAME_SWICH))));
     PrintUsageSyntax(Console, L"[mysession] /newinstance");
     PrintUsageSyntax(Console, L"[mysession] /edit <path>");
+    PrintUsageSyntax(Console, FORMAT(L"[mysession] /%s[=<file>]", (LowerCase(BROWSE_SWITCH))));
     PrintUsageSyntax(Console, FORMAT(L"[mysession] /%s [local_dir] [remote_dir] [/%s]", (LowerCase(SYNCHRONIZE_SWITCH), LowerCase(DEFAULTS_SWITCH))));
     PrintUsageSyntax(Console, FORMAT(L"[mysession] /%s [local_dir] [remote_dir] [/%s]", (LowerCase(KEEP_UP_TO_DATE_SWITCH), LowerCase(DEFAULTS_SWITCH))));
     PrintUsageSyntax(Console, FORMAT(L"[mysession] /%s [path]", (LowerCase(REFRESH_SWITCH))));
@@ -2230,6 +2231,7 @@ void __fastcall Usage(TConsole * Console)
     RegisterSwitch(SwitchesUsage, TProgramParams::FormatSwitch(SESSIONNAME_SWICH) + L"=", USAGE_SESSIONNAME);
     RegisterSwitch(SwitchesUsage, L"/newinstance", USAGE_NEWINSTANCE);
     RegisterSwitch(SwitchesUsage, L"/edit", USAGE_EDIT);
+    RegisterSwitch(SwitchesUsage, TProgramParams::FormatSwitch(BROWSE_SWITCH), USAGE_BROWSE);
     RegisterSwitch(SwitchesUsage, TProgramParams::FormatSwitch(SYNCHRONIZE_SWITCH), USAGE_SYNCHRONIZE);
     RegisterSwitch(SwitchesUsage, TProgramParams::FormatSwitch(KEEP_UP_TO_DATE_SWITCH), USAGE_KEEPUPTODATE);
     RegisterSwitch(SwitchesUsage, TProgramParams::FormatSwitch(REFRESH_SWITCH), USAGE_REFRESH);

+ 1 - 0
source/windows/WinInterface.h

@@ -48,6 +48,7 @@ const int mpAllowContinueOnError = 0x02;
 #define DUMPCALLSTACK_SWITCH L"DumpCallstack"
 #define INFO_SWITCH L"Info"
 #define COMREGISTRATION_SWITCH L"ComRegistration"
+#define BROWSE_SWITCH L"Browse"
 
 #define DUMPCALLSTACK_EVENT L"WinSCPCallstack%d"
 

+ 21 - 0
source/windows/WinMain.cpp

@@ -1098,9 +1098,25 @@ int __fastcall Execute()
               DebugAssert(!TerminalManager->ActiveTerminal);
 
               bool CanStart;
+              bool Browse = false;
               if (DataList->Count > 0)
               {
                 TManagedTerminal * Terminal = TerminalManager->NewTerminals(DataList.get());
+                UnicodeString BrowseFile;
+                if (Params->FindSwitch(BROWSE_SWITCH, BrowseFile) &&
+                    (!BrowseFile.IsEmpty() || !DownloadFile.IsEmpty()))
+                {
+                  if (BrowseFile.IsEmpty())
+                  {
+                    BrowseFile = DownloadFile;
+                  }
+                  DebugAssert(Terminal->RemoteExplorerState == NULL);
+                  Terminal->RemoteExplorerState = CreateDirViewStateForFocusedItem(BrowseFile);
+                  DebugAssert(Terminal->LocalExplorerState == NULL);
+                  Terminal->LocalExplorerState = CreateDirViewStateForFocusedItem(BrowseFile);
+                  DownloadFile = UnicodeString();
+                  Browse = true;
+                }
                 if (!DownloadFile.IsEmpty())
                 {
                   Terminal->AutoReadDirectory = false;
@@ -1166,6 +1182,11 @@ int __fastcall Execute()
                       UseDefaults);
                   }
 
+                  if (Browse)
+                  {
+                    ScpExplorer->BrowseFile();
+                  }
+
                   Application->Run();
                   // to allow dialog boxes show later (like from CheckConfigurationForceSave)
                   SetAppTerminated(False);