33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import './media/changesViewActions.css' ;
7- import { $ , reset } from '../../../../base/browser/dom.js' ;
8- import { BaseActionViewItem , IBaseActionViewItemOptions } from '../../../../base/browser/ui/actionbar/actionViewItems.js' ;
96import { Codicon } from '../../../../base/common/codicons.js' ;
10- import { Disposable , DisposableStore } from '../../../../base/common/lifecycle.js' ;
11- import { autorun , observableFromEvent } from '../../../../base/common/observable.js' ;
12- import { ThemeIcon } from '../../../../base/common/themables.js' ;
13- import { localize , localize2 } from '../../../../nls.js' ;
14- import { IActionViewItemService } from '../../../../platform/actions/browser/actionViewItemService.js' ;
7+ import { Disposable } from '../../../../base/common/lifecycle.js' ;
8+ import { observableFromEvent } from '../../../../base/common/observable.js' ;
9+ import { localize2 } from '../../../../nls.js' ;
1510import { Action2 , IAction2Options , registerAction2 } from '../../../../platform/actions/common/actions.js' ;
16- import { IInstantiationService , ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js' ;
11+ import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js' ;
1712import { IWorkbenchContribution , registerWorkbenchContribution2 , WorkbenchPhase } from '../../../../workbench/common/contributions.js' ;
18- import { getAgentChangesSummary , hasValidDiff } from '../../../../workbench/contrib/chat/browser/agentSessions/agentSessionsModel.js' ;
13+ import { hasValidDiff } from '../../../../workbench/contrib/chat/browser/agentSessions/agentSessionsModel.js' ;
1914import { IAgentSessionsService } from '../../../../workbench/contrib/chat/browser/agentSessions/agentSessionsService.js' ;
2015import { IViewsService } from '../../../../workbench/services/views/common/viewsService.js' ;
21- import { Menus } from '../../../browser/menus.js' ;
2216import { ISessionsManagementService } from '../../sessions/browser/sessionsManagementService.js' ;
2317import { CHANGES_VIEW_ID } from './changesView.js' ;
24- import { IAction } from '../../../../base/common/actions.js' ;
25- import { getDefaultHoverDelegate } from '../../../../base/browser/ui/hover/hoverDelegateFactory.js' ;
26- import { IHoverService } from '../../../../platform/hover/browser/hover.js' ;
27- import { ContextKeyExpr , IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js' ;
18+ import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js' ;
2819import { bindContextKey } from '../../../../platform/observable/common/platformObservableUtils.js' ;
2920
3021import { activeSessionHasChangesContextKey } from '../common/changes.js' ;
@@ -34,12 +25,6 @@ const openChangesViewActionOptions: IAction2Options = {
3425 title : localize2 ( 'openChangesView' , "Changes" ) ,
3526 icon : Codicon . diffMultiple ,
3627 f1 : false ,
37- menu : {
38- id : Menus . TitleBarSessionMenu ,
39- group : 'navigation' ,
40- order : 1 ,
41- when : ContextKeyExpr . equals ( activeSessionHasChangesContextKey . key , true ) ,
42- } ,
4328} ;
4429
4530class OpenChangesViewAction extends Action2 {
@@ -58,111 +43,17 @@ class OpenChangesViewAction extends Action2 {
5843
5944registerAction2 ( OpenChangesViewAction ) ;
6045
61- /**
62- * Custom action view item that renders the changes summary as:
63- * [diff-icon] +insertions -deletions
64- */
65- class ChangesActionViewItem extends BaseActionViewItem {
66-
67- private _container : HTMLElement | undefined ;
68- private readonly _renderDisposables = this . _register ( new DisposableStore ( ) ) ;
69-
70- constructor (
71- action : IAction ,
72- options : IBaseActionViewItemOptions | undefined ,
73- @ISessionsManagementService private readonly sessionManagementService : ISessionsManagementService ,
74- @IAgentSessionsService private readonly agentSessionsService : IAgentSessionsService ,
75- @IHoverService private readonly hoverService : IHoverService ,
76- ) {
77- super ( undefined , action , options ) ;
78-
79- this . _register ( autorun ( reader => {
80- this . sessionManagementService . activeSession . read ( reader ) ;
81- this . _updateLabel ( ) ;
82- } ) ) ;
83-
84- this . _register ( this . agentSessionsService . model . onDidChangeSessions ( ( ) => {
85- this . _updateLabel ( ) ;
86- } ) ) ;
87- }
88-
89- override render ( container : HTMLElement ) : void {
90- super . render ( container ) ;
91- this . _container = container ;
92- container . classList . add ( 'changes-action-view-item' ) ;
93- this . _updateLabel ( ) ;
94- }
95-
96- private _updateLabel ( ) : void {
97- if ( ! this . _container ) {
98- return ;
99- }
100-
101- this . _renderDisposables . clear ( ) ;
102- reset ( this . _container ) ;
103-
104- const activeSession = this . sessionManagementService . getActiveSession ( ) ;
105- if ( ! activeSession ) {
106- this . _container . style . display = 'none' ;
107- return ;
108- }
109-
110- const agentSession = this . agentSessionsService . getSession ( activeSession . resource ) ;
111- const changes = agentSession ?. changes ;
112-
113- if ( ! changes || ! hasValidDiff ( changes ) ) {
114- this . _container . style . display = 'none' ;
115- return ;
116- }
117-
118- const summary = getAgentChangesSummary ( changes ) ;
119- if ( ! summary ) {
120- this . _container . style . display = 'none' ;
121- return ;
122- }
123-
124- this . _container . style . display = '' ;
125-
126- // Diff icon
127- const iconEl = $ ( 'span.changes-action-icon' + ThemeIcon . asCSSSelector ( Codicon . diffMultiple ) ) ;
128- this . _container . appendChild ( iconEl ) ;
129-
130- // Insertions
131- const addedEl = $ ( 'span.changes-action-added' ) ;
132- addedEl . textContent = `+${ summary . insertions } ` ;
133- this . _container . appendChild ( addedEl ) ;
134-
135- // Deletions
136- const removedEl = $ ( 'span.changes-action-removed' ) ;
137- removedEl . textContent = `-${ summary . deletions } ` ;
138- this . _container . appendChild ( removedEl ) ;
139-
140- // Hover
141- this . _renderDisposables . add ( this . hoverService . setupManagedHover (
142- getDefaultHoverDelegate ( 'mouse' ) ,
143- this . _container ,
144- localize ( 'agentSessions.viewChanges' , "View All Changes" )
145- ) ) ;
146- }
147- }
148-
14946class ChangesViewActionsContribution extends Disposable implements IWorkbenchContribution {
15047
15148 static readonly ID = 'workbench.contrib.changesViewActions' ;
15249
15350 constructor (
154- @IActionViewItemService actionViewItemService : IActionViewItemService ,
155- @IInstantiationService instantiationService : IInstantiationService ,
15651 @IContextKeyService contextKeyService : IContextKeyService ,
15752 @ISessionsManagementService sessionManagementService : ISessionsManagementService ,
15853 @IAgentSessionsService agentSessionsService : IAgentSessionsService ,
15954 ) {
16055 super ( ) ;
16156
162- this . _register ( actionViewItemService . register ( Menus . TitleBarSessionMenu , OpenChangesViewAction . ID , ( action , options ) => {
163- return instantiationService . createInstance ( ChangesActionViewItem , action , options ) ;
164- } ) ) ;
165-
16657 // Bind context key: true when the active session has changes
16758 const sessionsChanged = observableFromEvent ( this , agentSessionsService . model . onDidChangeSessions , ( ) => { } ) ;
16859 this . _register ( bindContextKey ( activeSessionHasChangesContextKey , contextKeyService , reader => {
0 commit comments