Browse Source

Command-line switch /refresh to refresh remote panel

Source commit: 48b486b63ad6e178bed8eac62460e75e3a17f4f7
Martin Prikryl 9 years ago
parent
commit
b144e34f25

+ 1 - 0
source/core/Interface.h

@@ -22,6 +22,7 @@
 #define NEWERONLY_SWICH L"neweronly"
 #define NONEWERONLY_SWICH L"noneweronly"
 #define DELETE_SWITCH L"delete"
+#define REFRESH_SWITCH L"refresh"
 extern const wchar_t * TransferModeNames[];
 extern const int TransferModeNamesCount;
 extern const wchar_t * ToggleNames[];

+ 42 - 0
source/forms/CustomScpExplorer.cpp

@@ -367,6 +367,44 @@ __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()
 
 }
 //---------------------------------------------------------------------------
+void __fastcall TCustomScpExplorerForm::RefreshPanel(const UnicodeString & Session, const UnicodeString & Path)
+{
+
+  std::unique_ptr<TSessionData> Data;
+  if (!Session.IsEmpty())
+  {
+    bool DefaultsOnly;
+    Data.reset(StoredSessions->ParseUrl(Session, NULL, DefaultsOnly));
+  }
+
+  TTerminalManager * Manager = TTerminalManager::Instance();
+  for (int Index = 0; Index < Manager->Count; Index++)
+  {
+    TTerminal * Terminal = Manager->Terminals[Index];
+    if (Session.IsEmpty() ||
+        Terminal->SessionData->IsSameSite(Data.get()))
+    {
+      if (Path.IsEmpty())
+      {
+        Terminal->ClearCaches();
+      }
+      else
+      {
+        Terminal->DirectoryModified(Path, true);
+      }
+    }
+  }
+
+  // We should flag a pending refresh for the background terminals or busy foreground terminals
+  if ((Terminal != NULL) && Terminal->Active &&
+      CanCommandLineFromAnotherInstance() &&
+      (Session.IsEmpty() || Terminal->SessionData->IsSameSite(Data.get())) &&
+      (Path.IsEmpty() || UnixIsChildPath(Path, Terminal->CurrentDirectory)))
+  {
+    Terminal->ReloadDirectory();
+  }
+}
+//---------------------------------------------------------------------------
 void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
 {
   PCOPYDATASTRUCT CopyData = reinterpret_cast<PCOPYDATASTRUCT>(Message.LParam);
@@ -394,6 +432,10 @@ void __fastcall TCustomScpExplorerForm::WMCopyData(TMessage & Message)
           }
           break;
 
+        case TCopyDataMessage::RefreshPanel:
+          RefreshPanel(Message.Refresh.Session, Message.Refresh.Path);
+          break;
+
         case TCopyDataMessage::MainWindowCheck:
           Result = true;
           break;

+ 1 - 0
source/forms/CustomScpExplorer.h

@@ -564,6 +564,7 @@ protected:
   bool __fastcall DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList);
   bool __fastcall SelectedAllFilesInDirView(TCustomDirView * DView);
   TSessionData * __fastcall SessionDataForCode();
+  void __fastcall RefreshPanel(const UnicodeString & Session, const UnicodeString & Path);
 
 public:
   virtual __fastcall ~TCustomScpExplorerForm();

+ 1 - 0
source/windows/ConsoleRunner.cpp

@@ -2109,6 +2109,7 @@ void __fastcall Usage(TConsole * Console)
     PrintUsageSyntax(Console, L"[mysession] /edit <path>");
     PrintUsageSyntax(Console, L"[mysession] /synchronize [local_dir] [remote_dir] [/defaults]");
     PrintUsageSyntax(Console, L"[mysession] /keepuptodate [local_dir] [remote_dir] [/defaults]");
+    PrintUsageSyntax(Console, FORMAT(L"[mysession] /%s [path]", (LowerCase(REFRESH_SWITCH))));
     PrintUsageSyntax(Console, L"[mysession] [/privatekey=<file>] [/hostkey=<fingerprint>]");
     PrintUsageSyntax(Console, L"[mysession] [/clientcert=<file>] [/certificate=<fingerprint>]");
     PrintUsageSyntax(Console, L"[mysession] [/passive[=on|off]] [/implicit|explicit]");

+ 7 - 1
source/windows/WinInterface.h

@@ -489,7 +489,7 @@ void __fastcall ForceTracing();
 //---------------------------------------------------------------------------
 struct TCopyDataMessage
 {
-  enum { CommandCanCommandLine, CommandCommandLine, MainWindowCheck };
+  enum { CommandCanCommandLine, CommandCommandLine, MainWindowCheck, RefreshPanel };
   static const unsigned int Version1 = 1;
 
   unsigned int Version;
@@ -498,6 +498,12 @@ struct TCopyDataMessage
   union
   {
     wchar_t CommandLine[10240];
+
+    struct
+    {
+      wchar_t Session[1024];
+      wchar_t Path[1024];
+    } Refresh;
   };
 
   TCopyDataMessage()

+ 37 - 3
source/windows/WinMain.cpp

@@ -566,6 +566,29 @@ bool __fastcall SendToAnotherInstance()
   return Result;
 }
 //---------------------------------------------------------------------------
+void __fastcall Refresh(const UnicodeString & Session, const UnicodeString & Path)
+{
+  THandles OtherInstances;
+  FindOtherInstances(OtherInstances);
+
+  THandles::const_iterator I = OtherInstances.begin();
+  while (I != OtherInstances.end())
+  {
+    HWND Handle = *I;
+
+    TCopyDataMessage Message;
+    Message.Command = TCopyDataMessage::RefreshPanel;
+    wcsncpy(Message.Refresh.Session, Session.c_str(), LENOF(Message.Refresh.Session));
+    NULL_TERMINATE(Message.Refresh.Session);
+    wcsncpy(Message.Refresh.Path, Path.c_str(), LENOF(Message.Refresh.Path));
+    NULL_TERMINATE(Message.Refresh.Path);
+
+    SendCopyDataMessage(Handle, Message);
+
+    I++;
+  }
+}
+//---------------------------------------------------------------------------
 bool __fastcall ShowUpdatesIfAvailable()
 {
   TUpdatesConfiguration Updates = WinConfiguration->Updates;
@@ -838,7 +861,7 @@ int __fastcall Execute()
     }
     else
     {
-      enum { pcNone, pcUpload, pcFullSynchronize, pcSynchronize, pcEdit } ParamCommand;
+      enum { pcNone, pcUpload, pcFullSynchronize, pcSynchronize, pcEdit, pcRefresh } ParamCommand;
       ParamCommand = pcNone;
       UnicodeString AutoStartSession;
       UnicodeString DownloadFile;
@@ -888,10 +911,17 @@ int __fastcall Execute()
         {
           ParamCommand = pcEdit;
         }
+        else if (Params->FindSwitch(REFRESH_SWITCH, CommandParams, 1))
+        {
+          ParamCommand = pcRefresh;
+        }
       }
 
       if (Params->ParamCount > 0)
       {
+        AutoStartSession = Params->Param[1];
+        Params->ParamsProcessed(1, 1);
+
         if ((ParamCommand == pcNone) &&
             (WinConfiguration->ExternalSessionInExistingInstance != OpenInNewWindow()) &&
             !Params->FindSwitch(NEWINSTANCE_SWICH) &&
@@ -900,8 +930,6 @@ int __fastcall Execute()
           Configuration->Usage->Inc(L"SendToAnotherInstance");
           return 0;
         }
-        AutoStartSession = Params->Param[1];
-        Params->ParamsProcessed(1, 1);
         UnicodeString CounterName;
         if (Params->FindSwitch(JUMPLIST_SWITCH))
         {
@@ -930,6 +958,12 @@ int __fastcall Execute()
         AutoStartSession = WinConfiguration->AutoStartSession;
       }
 
+      if (ParamCommand == pcRefresh)
+      {
+        Refresh(AutoStartSession, (CommandParams->Count > 0 ? CommandParams->Strings[0] : UnicodeString()));
+        return 0;
+      }
+
       // from now flash message boxes on background
       SetOnForeground(false);