@@ -8,6 +8,7 @@ import { DOCUMENT_ITEM } from './documentTreeItem';
88import { DOCUMENT_LIST_ITEM , CollectionTypes } from './documentListTreeItem' ;
99import EXTENSION_COMMANDS from '../commands' ;
1010import { sortTreeItemsByLabel } from './treeItemUtils' ;
11+ import type { LoadedConnection } from '../storage/connectionStorage' ;
1112
1213const log = createLogger ( 'explorer tree controller' ) ;
1314
@@ -130,6 +131,46 @@ export default class ExplorerTreeController
130131 return element ;
131132 }
132133
134+ private _getConnectionExpandedState ( connection : LoadedConnection ) : {
135+ collapsibleState : vscode . TreeItemCollapsibleState ;
136+ isExpanded : boolean ;
137+ } {
138+ const pastConnectionTreeItems = this . _connectionTreeItems ;
139+ const isActiveConnection =
140+ connection . id === this . _connectionController . getActiveConnectionId ( ) ;
141+ const isBeingConnectedTo =
142+ this . _connectionController . isConnecting ( ) &&
143+ connection . id === this . _connectionController . getConnectingConnectionId ( ) ;
144+
145+ let collapsibleState = isActiveConnection
146+ ? vscode . TreeItemCollapsibleState . Expanded
147+ : vscode . TreeItemCollapsibleState . Collapsed ;
148+
149+ if (
150+ pastConnectionTreeItems [ connection . id ] &&
151+ ! pastConnectionTreeItems [ connection . id ] . isExpanded
152+ ) {
153+ // Connection was manually collapsed while being active.
154+ collapsibleState = vscode . TreeItemCollapsibleState . Collapsed ;
155+ }
156+ if ( isActiveConnection && this . _connectionController . isDisconnecting ( ) ) {
157+ // Don't show a collapsable state when the connection is being disconnected from.
158+ collapsibleState = vscode . TreeItemCollapsibleState . None ;
159+ }
160+ if ( isBeingConnectedTo ) {
161+ // Don't show a collapsable state when the connection is being connected to.
162+ collapsibleState = vscode . TreeItemCollapsibleState . None ;
163+ }
164+ return {
165+ collapsibleState,
166+ // Set expanded when we're connecting to a connection so that it
167+ // expands when it's connected.
168+ isExpanded :
169+ isBeingConnectedTo ||
170+ collapsibleState === vscode . TreeItemCollapsibleState . Expanded ,
171+ } ;
172+ }
173+
133174 getChildren ( element ?: any ) : Thenable < any [ ] > {
134175 // When no element is present we are at the root.
135176 if ( ! element ) {
@@ -139,45 +180,14 @@ export default class ExplorerTreeController
139180
140181 // Create new connection tree items, using cached children wherever possible.
141182 connections . forEach ( ( connection ) => {
142- const isActiveConnection =
143- connection . id === this . _connectionController . getActiveConnectionId ( ) ;
144- const isBeingConnectedTo =
145- this . _connectionController . isConnecting ( ) &&
146- connection . id ===
147- this . _connectionController . getConnectingConnectionId ( ) ;
148-
149- let connectionExpandedState = isActiveConnection
150- ? vscode . TreeItemCollapsibleState . Expanded
151- : vscode . TreeItemCollapsibleState . Collapsed ;
152-
153- if (
154- pastConnectionTreeItems [ connection . id ] &&
155- ! pastConnectionTreeItems [ connection . id ] . isExpanded
156- ) {
157- // Connection was manually collapsed while being active.
158- connectionExpandedState = vscode . TreeItemCollapsibleState . Collapsed ;
159- }
160- if (
161- isActiveConnection &&
162- this . _connectionController . isDisconnecting ( )
163- ) {
164- // Don't show a collapsable state when the connection is being disconnected from.
165- connectionExpandedState = vscode . TreeItemCollapsibleState . None ;
166- }
167- if ( isBeingConnectedTo ) {
168- // Don't show a collapsable state when the connection is being connected to.
169- connectionExpandedState = vscode . TreeItemCollapsibleState . None ;
170- }
183+ const { collapsibleState, isExpanded } =
184+ this . _getConnectionExpandedState ( connection ) ;
171185
172186 this . _connectionTreeItems [ connection . id ] = new ConnectionTreeItem ( {
173187 connectionId : connection . id ,
174- collapsibleState : connectionExpandedState ,
175- // Set expanded when we're connecting to a connection so that it
176- // expands when it's connected.
177- isExpanded :
178- isBeingConnectedTo ||
179- connectionExpandedState ===
180- vscode . TreeItemCollapsibleState . Expanded ,
188+ collapsibleState,
189+ isExpanded,
190+ isMutable : connection . isMutable ?? true ,
181191 connectionController : this . _connectionController ,
182192 cacheIsUpToDate : pastConnectionTreeItems [ connection . id ]
183193 ? pastConnectionTreeItems [ connection . id ] . cacheIsUpToDate
0 commit comments