From 6c77cc430b1e78bd3d0acf1cc078e60775647956 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Mon, 17 Nov 2008 19:16:43 +0100 Subject: Implement Quick Connect feature --- UMain.pas | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 107 insertions(+), 9 deletions(-) (limited to 'UMain.pas') diff --git a/UMain.pas b/UMain.pas index c77ea4d..e799466 100644 --- a/UMain.pas +++ b/UMain.pas @@ -182,6 +182,7 @@ type procedure miPathBoxCopyPathClick(Sender: TObject); procedure miCopyNamesClick(Sender: TObject); procedure RightMouseSelectPopupTimerTimer(Sender: TObject); + procedure miQuickConnectClick(Sender: TObject); private LeftLastFocused, Editing, QuickFind, RedrawLeftInactive, RedrawRightInactive, StartUp, LeftTabPopup: boolean; LastWidth, RunningEscSensitive: integer; @@ -242,6 +243,7 @@ type function HandleKey(Key: Word; Shift: TShiftState; LeftPanel: boolean): boolean; function IsEditing(AListView: TGTKListView): boolean; function PanelFindEditableWidget(AListView: TGTKListView): PGtkWidget; + function CheckForUnsavedConnection(Engine: TVFSEngine; AllowCancel: boolean): boolean; // Returns False to Cancel public LeftPanelEngine, RightPanelEngine : TPanelEngine; ColumnSortIDs: array[1..ConstNumPanelColumns] of integer; @@ -260,7 +262,8 @@ uses ULibc, UFileTypeSettings, UFileAssoc, UChmod, UChown, USymlink, UPreferences, UViewer, UToolTips, UMounterPrefs, UColumns, UTestPlugin, UConnectionManager, USearch, UProperties, - URemoteWait, URunFromVFS, uVFSprototypes; + URemoteWait, URunFromVFS, uVFSprototypes, UQuickConnect, + UConnectionProperties; @@ -901,7 +904,7 @@ begin mnuNetwork.Add(miOpenConnection); miQuickConnect := TGTKMenuItem.CreateTyped(Self, itImageText); miQuickConnect.Caption := LANGmiQuickConnectCaption; - miQuickConnect.Enabled := False; + miQuickConnect.OnClick := miQuickConnectClick; miQuickConnect.ShortCuts.AddName('N'); mnuNetwork.Add(miQuickConnect); mnuNetwork.Add(TGTKMenuItem.CreateTyped(Self, itSeparator)); @@ -1118,6 +1121,7 @@ procedure TFMain.FormClose(Sender: TObject; var Action: TCloseAction); Result := FallbackEngine; if not Assigned(Engine.ParentEngine) or (not (Engine is TVFSEngine)) then Exit; Result := Engine.ParentEngine; + CheckForUnsavedConnection(Engine as TVFSEngine, False); if not TVFSEngine(Engine).VFSClose then DebugMsg(['Error closing the engine...']); Engine.Free; end; @@ -1170,8 +1174,10 @@ begin LeftPanelTabs[i] := s; end else while Assigned(LeftTabEngines[i]) and (TPanelEngine(LeftTabEngines[i]) is TVFSEngine) do begin - LeftPanelTabs[i] := TPanelEngine(LeftTabEngines[i]).SavePath; + s := TPanelEngine(LeftTabEngines[i]).SavePath; LeftTabEngines[i] := InternalCloseEngine(LeftTabEngines[i], LeftLocalEngine); + if s <> '' then LeftPanelTabs[i] := s + else LeftPanelTabs[i] := TPanelEngine(LeftTabEngines[i]).Path; end; except end; @@ -1187,8 +1193,10 @@ begin RightPanelTabs[i] := s; end else while Assigned(RightTabEngines[i]) and (TPanelEngine(RightTabEngines[i]) is TVFSEngine) do begin - RightPanelTabs[i] := TPanelEngine(RightTabEngines[i]).SavePath; + s := TPanelEngine(RightTabEngines[i]).SavePath; RightTabEngines[i] := InternalCloseEngine(RightTabEngines[i], RightLocalEngine); + if s <> '' then RightPanelTabs[i] := s + else RightPanelTabs[i] := TPanelEngine(RightTabEngines[i]).Path; end; except end; end; @@ -5627,6 +5635,12 @@ begin DebugMsg(['Couldn''t close tab: wrong TabNo']); Exit; end; + + if TabNo > 0 then begin + Engine := TabEngines[TabNo]; + if (Engine is TVFSEngine) and (not CheckForUnsavedConnection(Engine as TVFSEngine, True)) then Exit; + end; + if (ANotebook.ChildrenCount > 2) and (TabNo >= 0) then begin // Close one tab, leave tab bar visible Engine := TabEngines[TabNo]; @@ -5673,6 +5687,7 @@ begin Engine := TabEngines[i]; while Engine is TVFSEngine do try + if (i <> TabNo) and (not CheckForUnsavedConnection(Engine as TVFSEngine, False)) then Exit; xEngine := Engine; Engine := xEngine.ParentEngine; if not TVFSEngine(xEngine).VFSClose then DebugMsg(['Error closing the engine...']); @@ -5966,7 +5981,19 @@ var Engine: TPanelEngine; begin if LeftPanel then Engine := LeftPanelEngine else Engine := RightPanelEngine; - if not Assigned(Engine.ParentEngine) or (not (Engine is TVFSEngine)) then Exit; + if (not Assigned(Engine.ParentEngine)) or (not (Engine is TVFSEngine)) then begin + if LeftPanel then begin + LeftPanelEngine := LeftLocalEngine; + Result := LeftPanelEngine.Path; + end else begin + RightPanelEngine := RightLocalEngine; + Result := RightPanelEngine.Path; + end; + Exit; + end; + + if not CheckForUnsavedConnection(Engine as TVFSEngine, (not SuppressRefresh) and (not ApplicationShuttingDown)) then Exit; + if LeftPanel then LeftPanelEngine := Engine.ParentEngine else RightPanelEngine := Engine.ParentEngine; @@ -5978,6 +6005,55 @@ begin Engine.Free; end; +function TFMain.CheckForUnsavedConnection(Engine: TVFSEngine; AllowCancel: boolean): boolean; // Returns False to Cancel +var Buttons: TMessageButtons; + CancelButton: TMessageButton; + AFConnectionProperties: TFConnectionProperties; + URI: string; + ConnMgrItem: TConnMgrItem; +begin + Result := True; + URI := Engine.GetPathURI; + if Engine.OpenedFromQuickConnect and (Length(Trim(URI)) > 0) then begin + Buttons := [mbYes, mbNo]; + CancelButton := mbNo; + if AllowCancel then begin + Include(Buttons, mbCancel); + CancelButton := mbCancel; + end; + case Application.MessageBox('The active connection has not been saved. Do you want to save it to Connection Manager?', Buttons, mbWarning, mbYes, CancelButton) of + mbYes: begin + AFConnectionProperties := TFConnectionProperties.Create(Self); + try + AFConnectionProperties.URIEntry.Text := URI; + if AFConnectionProperties.Run = mbOK then begin + ReadConnections; + ConnMgrItem := TConnMgrItem.Create; + ConnMgrItem.ConnectionName := AFConnectionProperties.NameEntry.Text; + ConnMgrItem.ServiceType := AFConnectionProperties.GetService; + ConnMgrItem.Server := AFConnectionProperties.ServerEntry.Text; + ConnMgrItem.Username := AFConnectionProperties.UserNameEntry.Text; + ConnMgrItem.Password := AFConnectionProperties.PasswordEntry.Text; + ConnMgrItem.TargetDir := AFConnectionProperties.TargetDirEntry.Text; + ConnMgrItem.PluginID := ''; + if AFConnectionProperties.PluginOptionMenu.ItemIndex <> 0 then + ConnMgrItem.PluginID := TVFSPlugin(PluginList[AFConnectionProperties.PluginOptionMenu.ItemIndex - 1]).VFSName; + ConnectionMgrList.Add(ConnMgrItem); + WriteConnections; + end; + finally + AFConnectionProperties.Free; + end; + Result := True; + end; + mbNo: Result := True; + mbCancel: Result := False; + else {Cancel?} Result := not AllowCancel; + end; + end; +end; + + (********************************************************************************************************************************) (********************************************************************************************************************************) procedure TFMain.ShowBookmarkQuick(LeftPanel: boolean); @@ -6061,14 +6137,11 @@ var b: boolean; begin try InternalLock; - + ReadConnections; FConnectionManager := TFConnectionManager.Create(Self); if LeftLastFocused then FConnectionManager.SourcePanelEngine := LeftPanelEngine else FConnectionManager.SourcePanelEngine := RightPanelEngine; b := FConnectionManager.Run = mbOK; - if FConnectionManager.ListView.Selected <> nil then ConfConnMgrActiveItem := FConnectionManager.ListView.Selected.Index; - ConfConnMgrDoNotSavePasswords := FConnectionManager.DoNotSavePasswordsCheckBox.Checked; - ConfConnMgrDoNotSynchronizeKeyring := FConnectionManager.DoNotSynchronizeKeyringCheckBox.Checked; WriteConnections; // Save connection manager data if b and (FConnectionManager.ConnectedEngine <> nil) then begin @@ -6084,6 +6157,31 @@ begin end; end; +procedure TFMain.miQuickConnectClick(Sender: TObject); +var b: boolean; +begin + try + InternalLock; + ReadConnections; + FQuickConnect := TFQuickConnect.Create(Self); + if LeftLastFocused then FQuickConnect.SourcePanelEngine := LeftPanelEngine + else FQuickConnect.SourcePanelEngine := RightPanelEngine; + b := FQuickConnect.Run = mbOK; + WriteConnections; // Save connection manager data + + if b and (FQuickConnect.ConnectedEngine <> nil) then begin + if FQuickConnect.SourcePanelEngine is TVFSEngine then CloseVFS(LeftLastFocused, True); + if LeftLastFocused then LeftPanelEngine := FQuickConnect.ConnectedEngine + else RightPanelEngine := FQuickConnect.ConnectedEngine; + DoRefresh(LeftLastFocused, False, False); + end; + finally + FQuickConnect.Free; + Application.ProcessMessages; + InternalLockInit(False); + end; +end; + procedure TFMain.miDisconnectClick(Sender: TObject); begin CloseVFS(LeftLastFocused, False); -- cgit v1.2.3