Browse Source

Preference option "Show Login dialog on startup and when the last session is closed" + When the option is off and automatic saving of workspace is enabled, the workspace automatically opens (with no session connected)

Source commit: 311e05551f72edad4a2e129d9aaeccc865b05c6f
Martin Prikryl 6 years ago
parent
commit
6bfdad1828

+ 36 - 10
source/forms/CustomScpExplorer.cpp

@@ -4698,7 +4698,7 @@ void __fastcall TCustomScpExplorerForm::ApplicationRestore(TObject * /*Sender*/)
     NonVisualDataModule->StartBusy();
     try
     {
-      NeedSession(false);
+      NeedSession(true);
     }
     __finally
     {
@@ -4865,6 +4865,20 @@ void __fastcall TCustomScpExplorerForm::OpenStoredSession(TSessionData * Data)
   }
 }
 //---------------------------------------------------------------------------
+void __fastcall TCustomScpExplorerForm::DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal)
+{
+  TTerminalManager * Manager = TTerminalManager::Instance();
+  std::unique_ptr<TObjectList> DataList(new TObjectList());
+  StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
+  TManagedTerminal * FirstTerminal = Manager->NewTerminals(DataList.get());
+  if (!ConnectFirstTerminal)
+  {
+    FirstTerminal->Disconnected = true;
+    FirstTerminal->DisconnectedTemporarily = true;
+  }
+  Manager->ActiveTerminal = FirstTerminal;
+}
+//---------------------------------------------------------------------------
 void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeString & Name)
 {
   if (OpenInNewWindow())
@@ -4873,10 +4887,7 @@ void __fastcall TCustomScpExplorerForm::OpenFolderOrWorkspace(const UnicodeStrin
   }
   else
   {
-    TTerminalManager * Manager = TTerminalManager::Instance();
-    std::unique_ptr<TObjectList> DataList(new TObjectList());
-    StoredSessions->GetFolderOrWorkspace(Name, DataList.get());
-    Manager->ActiveTerminal = Manager->NewTerminals(DataList.get());
+    DoOpenFolderOrWorkspace(Name, true);
   }
 }
 //---------------------------------------------------------------------------
@@ -6503,20 +6514,35 @@ void __fastcall TCustomScpExplorerForm::LastTerminalClosed(TObject * /*Sender*/)
   UpdateControls();
   SessionColor = TColor(0);
   UpdateRemotePathComboBox(false);
-  NeedSession(true);
+  NeedSession(false);
 }
 //---------------------------------------------------------------------------
-void __fastcall TCustomScpExplorerForm::NeedSession(bool ReloadSessions)
+void __fastcall TCustomScpExplorerForm::NeedSession(bool Startup)
 {
   try
   {
+    // Cache, as the login dialog can change its value
+    bool ShowLogin = WinConfiguration->ShowLoginWhenNoSession;
     try
     {
-      TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
+      if (ShowLogin)
+      {
+        bool ReloadSessions = !Startup;
+        TTerminalManager::Instance()->NewSession(false, L"", ReloadSessions, this);
+      }
+      else if (Startup && WinConfiguration->AutoSaveWorkspace && !WinConfiguration->AutoWorkspace.IsEmpty() &&
+               // This detects if workspace was saved the last time the main widow was closed
+               SameText(WinConfiguration->LastStoredSession, WinConfiguration->AutoWorkspace))
+      {
+        DoOpenFolderOrWorkspace(WinConfiguration->AutoWorkspace, false);
+      }
     }
     __finally
     {
-      if (!WinConfiguration->KeepOpenWhenNoSession &&
+      // Do not terminate, if we are only starting up and we are not showing Login dialog
+      // (so there was no chance for the user to open any session yet)
+      if ((ShowLogin || !Startup) &&
+          !WinConfiguration->KeepOpenWhenNoSession &&
           ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
       {
         TerminateApplication();
@@ -9002,7 +9028,7 @@ void __fastcall TCustomScpExplorerForm::CMShowingChanged(TMessage & Message)
         // by TDriveView, but with Explorer interface, we need to call it explicily
         Application->ProcessMessages();
         // do not reload sessions, they have been loaded just now (optimization)
-        NeedSession(false);
+        NeedSession(true);
       }
       __finally
       {

+ 2 - 1
source/forms/CustomScpExplorer.h

@@ -643,7 +643,7 @@ protected:
   void __fastcall AnyInternalEditorModified(TObject * Sender, bool & Modified);
   virtual void __fastcall StartingDisconnected();
   void __fastcall DoTerminalListChanged();
-  void __fastcall NeedSession(bool ReloadSessions);
+  void __fastcall NeedSession(bool Startup);
   bool __fastcall DraggingAllFilesFromDirView(TOperationSide Side, TStrings * FileList);
   bool __fastcall SelectedAllFilesInDirView(TCustomDirView * DView);
   TSessionData * __fastcall SessionDataForCode();
@@ -685,6 +685,7 @@ protected:
   void __fastcall CMDialogKey(TWMKeyDown & Message);
   DYNAMIC void __fastcall Deactivate();
   void __fastcall CenterReconnectToolbar();
+  void __fastcall DoOpenFolderOrWorkspace(const UnicodeString & Name, bool ConnectFirstTerminal);
 
 public:
   virtual __fastcall ~TCustomScpExplorerForm();

+ 12 - 0
source/forms/Login.cpp

@@ -109,6 +109,12 @@ void __fastcall TLoginDialog::Init(TStoredSessionList *SessionList, TForm * Link
   UnicodeString Dummy;
   RunPageantAction->Visible = FindTool(PageantTool, Dummy);
   RunPuttygenAction->Visible = FindTool(PuttygenTool, Dummy);
+  // Bit of a hack: Assume an auto open, when we are linked to the main form
+  if (LinkedForm != NULL)
+  {
+    DebugAssert(WinConfiguration->ShowLoginWhenNoSession);
+    CloseButton->Style = TCustomButton::bsSplitButton;
+  }
   UpdateControls();
 }
 //---------------------------------------------------------------------
@@ -3075,3 +3081,9 @@ void __fastcall TLoginDialog::ButtonPanelMouseDown(TObject *, TMouseButton, TShi
   CountClicksForWindowPrint(this);
 }
 //---------------------------------------------------------------------------
+void __fastcall TLoginDialog::NeverShowAgainActionExecute(TObject *)
+{
+  WinConfiguration->ShowLoginWhenNoSession = false;
+  ModalResult = mrCancel;
+}
+//---------------------------------------------------------------------------

+ 24 - 0
source/forms/Login.dfm

@@ -391,6 +391,7 @@ object LoginDialog: TLoginDialog
         Anchors = [akRight, akBottom]
         Cancel = True
         Caption = 'Close'
+        DropDownMenu = CloseDropDownMenu
         ModalResult = 2
         TabOrder = 1
       end
@@ -671,6 +672,16 @@ object LoginDialog: TLoginDialog
       Caption = 'All &Major Site Fields'
       OnExecute = SearchSiteActionExecute
     end
+    object CloseAction: TAction
+      Category = 'Other'
+      Caption = 'Close'
+    end
+    object NeverShowAgainAction: TAction
+      Category = 'Other'
+      AutoCheck = True
+      Caption = 'Close and Do Not Show Automatically Again'
+      OnExecute = NeverShowAgainActionExecute
+    end
   end
   object ToolsPopupMenu: TPopupMenu
     Left = 144
@@ -4297,4 +4308,17 @@ object LoginDialog: TLoginDialog
     Top = 525
     Bitmap = {}
   end
+  object CloseDropDownMenu: TPopupMenu
+    Images = ActionImageList
+    Left = 36
+    Top = 397
+    object MenuItem15: TMenuItem
+      Action = CloseAction
+      Default = True
+    end
+    object MenuItem20: TMenuItem
+      Action = NeverShowAgainAction
+      AutoCheck = True
+    end
+  end
 end

+ 6 - 0
source/forms/Login.h

@@ -206,6 +206,11 @@ __published:
   TPngImageList *SessionImageList192;
   TPngImageList *ActionImageList144;
   TPngImageList *ActionImageList192;
+  TPopupMenu *CloseDropDownMenu;
+  TMenuItem *MenuItem15;
+  TMenuItem *MenuItem20;
+  TAction *CloseAction;
+  TAction *NeverShowAgainAction;
   void __fastcall DataChange(TObject *Sender);
   void __fastcall FormShow(TObject *Sender);
   void __fastcall SessionTreeDblClick(TObject *Sender);
@@ -283,6 +288,7 @@ __published:
   void __fastcall SearchSiteNameActionExecute(TObject *Sender);
   void __fastcall SearchSiteActionExecute(TObject *Sender);
   void __fastcall ButtonPanelMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
+  void __fastcall NeverShowAgainActionExecute(TObject *Sender);
 
 private:
   int NoUpdate;

+ 2 - 0
source/forms/Preferences.cpp

@@ -475,6 +475,7 @@ void __fastcall TPreferencesDialog::LoadConfiguration()
     }
     BOOLPROP(MinimizeToTray);
     BOOLPROP(ExternalSessionInExistingInstance);
+    BOOLPROP(ShowLoginWhenNoSession);
     BOOLPROP(KeepOpenWhenNoSession);
     BOOLPROP(ShowTips);
 
@@ -852,6 +853,7 @@ void __fastcall TPreferencesDialog::SaveConfiguration()
     }
     BOOLPROP(MinimizeToTray);
     BOOLPROP(ExternalSessionInExistingInstance);
+    BOOLPROP(ShowLoginWhenNoSession);
     BOOLPROP(KeepOpenWhenNoSession);
     BOOLPROP(ShowTips);
 

+ 17 - 6
source/forms/Preferences.dfm

@@ -2483,13 +2483,13 @@ object PreferencesDialog: TPreferencesDialog
           Left = 8
           Top = 231
           Width = 389
-          Height = 126
+          Height = 150
           Anchors = [akLeft, akTop, akRight]
           Caption = 'Miscellaneous'
           TabOrder = 2
           DesignSize = (
             389
-            126)
+            150)
           object MinimizeToTrayCheck: TCheckBox
             Left = 16
             Top = 21
@@ -2512,22 +2512,33 @@ object PreferencesDialog: TPreferencesDialog
           end
           object KeepOpenWhenNoSessionCheck: TCheckBox
             Left = 16
-            Top = 69
+            Top = 93
             Width = 361
             Height = 17
             Anchors = [akLeft, akTop, akRight]
             Caption = '&Keep main window open when the last session is closed'
-            TabOrder = 2
+            TabOrder = 3
             OnClick = ControlChange
           end
           object ShowTipsCheck: TCheckBox
             Left = 16
-            Top = 93
+            Top = 117
             Width = 361
             Height = 17
             Anchors = [akLeft, akTop, akRight]
             Caption = '&Display tips on startup'
-            TabOrder = 3
+            TabOrder = 4
+            OnClick = ControlChange
+          end
+          object ShowLoginWhenNoSessionCheck: TCheckBox
+            Left = 16
+            Top = 69
+            Width = 361
+            Height = 17
+            Anchors = [akLeft, akTop, akRight]
+            Caption = 
+              '&Show Login dialog on startup and when the last session is closed'
+            TabOrder = 2
             OnClick = ControlChange
           end
         end

+ 1 - 0
source/forms/Preferences.h

@@ -335,6 +335,7 @@ __published:
   TComboBox *ThemeCombo;
   TComboBox *PanelSearchCombo;
   TLabel *Label2;
+  TCheckBox *ShowLoginWhenNoSessionCheck;
   void __fastcall FormShow(TObject *Sender);
   void __fastcall ControlChange(TObject *Sender);
   void __fastcall EditorFontButtonClick(TObject *Sender);

+ 14 - 4
source/windows/TerminalManager.cpp

@@ -31,7 +31,7 @@ __fastcall TManagedTerminal::TManagedTerminal(TSessionData * SessionData,
   TConfiguration * Configuration) :
   TTerminal(SessionData, Configuration),
   LocalExplorerState(NULL), RemoteExplorerState(NULL),
-  ReopenStart(0), DirectoryLoaded(Now()), TerminalThread(NULL), Disconnected(false)
+  ReopenStart(0), DirectoryLoaded(Now()), TerminalThread(NULL), Disconnected(false), DisconnectedTemporarily(false)
 {
   StateData = new TSessionData(L"");
   StateData->Assign(SessionData);
@@ -273,6 +273,7 @@ void __fastcall TTerminalManager::DoConnectTerminal(TTerminal * Terminal, bool R
         }
 
         ManagedTerminal->Disconnected = false;
+        ManagedTerminal->DisconnectedTemporarily = false;
         DebugAssert(ManagedTerminal->TerminalThread == NULL);
         ManagedTerminal->TerminalThread = TerminalThread;
       }
@@ -654,7 +655,7 @@ void __fastcall TTerminalManager::DoSetActiveTerminal(TManagedTerminal * value,
     // here used to be call to TCustomScpExporer::UpdateSessionData (now UpdateTerminal)
     // but it seems to be duplicate to call from TCustomScpExporer::TerminalChanging
 
-    TTerminal * PActiveTerminal = ActiveTerminal;
+    TManagedTerminal * PActiveTerminal = ActiveTerminal;
     FActiveTerminal = value;
     // moved from else block of next if (ActiveTerminal) statement
     // so ScpExplorer can update its caption
@@ -672,9 +673,18 @@ void __fastcall TTerminalManager::DoSetActiveTerminal(TManagedTerminal * value,
       }
     }
 
-    if (PActiveTerminal && !PActiveTerminal->Active)
+    if (PActiveTerminal != NULL)
     {
-      SaveTerminal(PActiveTerminal);
+      if (PActiveTerminal->DisconnectedTemporarily && DebugAlwaysTrue(PActiveTerminal->Disconnected))
+      {
+        PActiveTerminal->Disconnected = false;
+        PActiveTerminal->DisconnectedTemporarily = false;
+      }
+
+      if (!PActiveTerminal->Active)
+      {
+        SaveTerminal(PActiveTerminal);
+      }
     }
 
     if (ActiveTerminal)

+ 1 - 0
source/windows/TerminalManager.h

@@ -31,6 +31,7 @@ public:
   // To distinguish sessions that were explicitly disconnected and
   // should not be reconnected when their tab is activated.
   bool Disconnected;
+  bool DisconnectedTemporarily;
   // Sessions that should not close when they fail to connect
   // (i.e. those that were ever connected or were opened as a part of a workspace)
   bool Permanent;

+ 7 - 0
source/windows/WinConfiguration.cpp

@@ -608,6 +608,7 @@ void __fastcall TWinConfiguration::Default()
   FGenerateUrlScriptFormat = sfScriptFile;
   FGenerateUrlAssemblyLanguage = alCSharp;
   FExternalSessionInExistingInstance = true;
+  FShowLoginWhenNoSession = true;
   FKeepOpenWhenNoSession = false;
   FLocalIconsByExt = false;
   FBidiModeOverride = lfoLanguageIfRecommended;
@@ -1010,6 +1011,7 @@ THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool & SessionList)
     KEY(Integer,  GenerateUrlScriptFormat); \
     KEY(Integer,  GenerateUrlAssemblyLanguage); \
     KEY(Bool,     ExternalSessionInExistingInstance); \
+    KEY(Bool,     ShowLoginWhenNoSession); \
     KEY(Bool,     KeepOpenWhenNoSession); \
     KEY(Bool,     LocalIconsByExt); \
     KEY(Integer,  BidiModeOverride); \
@@ -2287,6 +2289,11 @@ void __fastcall TWinConfiguration::SetExternalSessionInExistingInstance(bool val
   SET_CONFIG_PROPERTY(ExternalSessionInExistingInstance);
 }
 //---------------------------------------------------------------------------
+void __fastcall TWinConfiguration::SetShowLoginWhenNoSession(bool value)
+{
+  SET_CONFIG_PROPERTY(ShowLoginWhenNoSession);
+}
+//---------------------------------------------------------------------------
 void __fastcall TWinConfiguration::SetKeepOpenWhenNoSession(bool value)
 {
   SET_CONFIG_PROPERTY(KeepOpenWhenNoSession);

+ 3 - 0
source/windows/WinConfiguration.h

@@ -442,6 +442,7 @@ private:
   TScriptFormat FGenerateUrlScriptFormat;
   TAssemblyLanguage FGenerateUrlAssemblyLanguage;
   bool FExternalSessionInExistingInstance;
+  bool FShowLoginWhenNoSession;
   bool FKeepOpenWhenNoSession;
   bool FLocalIconsByExt;
   TLocaleFlagOverride FBidiModeOverride;
@@ -543,6 +544,7 @@ private:
   void __fastcall SetGenerateUrlScriptFormat(TScriptFormat value);
   void __fastcall SetGenerateUrlAssemblyLanguage(TAssemblyLanguage value);
   void __fastcall SetExternalSessionInExistingInstance(bool value);
+  void __fastcall SetShowLoginWhenNoSession(bool value);
   void __fastcall SetKeepOpenWhenNoSession(bool value);
   void __fastcall SetLocalIconsByExt(bool value);
   void __fastcall SetBidiModeOverride(TLocaleFlagOverride value);
@@ -731,6 +733,7 @@ public:
   __property TScriptFormat GenerateUrlScriptFormat = { read = FGenerateUrlScriptFormat, write = SetGenerateUrlScriptFormat };
   __property TAssemblyLanguage GenerateUrlAssemblyLanguage = { read = FGenerateUrlAssemblyLanguage, write = SetGenerateUrlAssemblyLanguage };
   __property bool ExternalSessionInExistingInstance = { read = FExternalSessionInExistingInstance, write = SetExternalSessionInExistingInstance };
+  __property bool ShowLoginWhenNoSession = { read = FShowLoginWhenNoSession, write = SetShowLoginWhenNoSession };
   __property bool KeepOpenWhenNoSession = { read = FKeepOpenWhenNoSession, write = SetKeepOpenWhenNoSession };
   __property bool LocalIconsByExt = { read = FLocalIconsByExt, write = SetLocalIconsByExt };
   __property TLocaleFlagOverride BidiModeOverride = { read = FBidiModeOverride, write = SetBidiModeOverride };