@@ -57,8 +57,7 @@ export class ComponentsPacksWebviewMain {
5757
5858 public static readonly WEBVIEW_COMMAND_ID = `${ manifest . PACKAGE_NAME } .manageComponentsPacks` ;
5959
60- private currentProject : CurrentProject ;
61-
60+ private project : CurrentProject ;
6261 private componentTree ! : CtRoot ;
6362 private validations ! : Results ;
6463 private selectedContext : TargetSetData | undefined ;
@@ -88,7 +87,6 @@ export class ComponentsPacksWebviewMain {
8887 new WebviewManager ( context , MANAGE_COMPONENTS_WEBVIEW_OPTIONS , commandsProvider ) ;
8988 this . manageComponentsActions . setCsolutionService ( this . csolutionService ) ;
9089 this . manageComponentsActions . setMessageProvider ( this . messageProvider ) ;
91- this . manageComponentsActions . setCurrentProject ( this . currentProject ) ;
9290 this . projectFileUpdater = new ProjectFileUpdaterImpl ( this . solutionManager ) ;
9391 }
9492
@@ -103,11 +101,58 @@ export class ComponentsPacksWebviewMain {
103101 await this . webviewManager . activate ( context ) ;
104102 }
105103
106- private dispose ( ) : void {
107- this . currentProject = undefined ;
108- this . componentTree = { success : false , classes : [ ] } ;
109- this . validations = { success : false , result : 'UNDEFINED' , validation : [ ] } ;
110- this . manageComponentsActions . setCurrentProject ( this . currentProject ) ;
104+ private async dispose ( ) : Promise < void > {
105+ const discardView = ( ) => {
106+ this . currentProject = undefined ;
107+ this . componentTree = { success : false , classes : [ ] } ;
108+ this . validations = { success : false , result : 'UNDEFINED' , validation : [ ] } ;
109+ this . usedItems = { components : [ ] , packs : [ ] , success : false } ;
110+ this . cachedTargetSetData = undefined ;
111+ this . availablePacksCache = { } ;
112+ this . unlinkRequests . clear ( ) ;
113+ this . isLoading = false ;
114+ this . scope = ComponentScope . Solution ;
115+ } ;
116+
117+ if ( await this . isDirty ( ) ) {
118+ const buttonOptions = [
119+ { title : 'Save' } ,
120+ { title : 'Discard' , isCloseAffordance : true } ,
121+ { title : 'Reopen' } ,
122+ ] ;
123+ const messageOptions : vscode . MessageOptions = { modal : true , detail : 'Do you want to save changes before closing?' } ;
124+
125+ const pick = ( await vscode . window . showWarningMessage (
126+ 'Unsaved changes will be lost.' ,
127+ messageOptions ,
128+ ...buttonOptions ,
129+ ) ) || { title : 'Cancel' } ;
130+
131+ switch ( pick . title ) {
132+ case 'Save' :
133+ await this . handleApplyComponentSet ( ) ;
134+ discardView ( ) ;
135+ break ;
136+ case 'Reopen' :
137+ this . webviewManager . createOrShowPanel ( ) ;
138+ break ;
139+ case 'Discard' :
140+ default :
141+ discardView ( ) ;
142+ break ;
143+ }
144+ } else {
145+ discardView ( ) ;
146+ }
147+ }
148+
149+ get currentProject ( ) : CurrentProject | undefined {
150+ return this . project ;
151+ }
152+
153+ set currentProject ( project : CurrentProject | undefined ) {
154+ this . project = project ;
155+ this . manageComponentsActions . setCurrentProject ( project ) ;
111156 }
112157
113158 private async handleWebviewCommand ( treeNode : COutlineItem | undefined ) {
@@ -265,7 +310,6 @@ export class ComponentsPacksWebviewMain {
265310 if ( csolution ) {
266311 this . clearTargetSetCache ( ) ;
267312 this . currentProject = { solutionPath : csolution . solutionPath , project : createProject ( projectId ) } ;
268- this . manageComponentsActions . setCurrentProject ( this . currentProject ) ;
269313 const actx = this . getActiveContext ( ) ;
270314
271315 const activeTs = csolution . getActiveTargetSetName ( ) ?? '' ;
@@ -294,11 +338,12 @@ export class ComponentsPacksWebviewMain {
294338 throw new Error ( `Failed loading solution: ${ solutionPath } due to previous errors` ) ;
295339 }
296340
297- await this . webviewManager . sendMessage ( { type : 'SET_SOLUTION_STATE' , stateMessage : 'Fetching Packs Info...' } ) ;
341+ await this . webviewManager . sendMessage ( { type : 'SET_SOLUTION_STATE' , stateMessage : 'Retrieving assigned items...' } ) ;
342+ this . usedItems = await this . csolutionService . getUsedItems ( { context : activeContext } ) ;
298343 }
299- this . usedItems = await this . csolutionService . getUsedItems ( { context : activeContext } ) ;
300344 await this . webviewManager . sendMessage ( { type : 'SET_UNLINKREQUESTS_STACK' , unlinkRequests : Array . from ( this . unlinkRequests ) } ) ;
301345 await this . sendSolutionData ( ) ;
346+ await this . sendDirtyState ( ) ;
302347 } catch ( error ) {
303348 const messages = await this . csolutionService . getLogMessages ( ) ;
304349
@@ -394,10 +439,12 @@ export class ComponentsPacksWebviewMain {
394439 } ;
395440
396441 private async handleRequestInitialData ( ) : Promise < void > {
397- const projectId = this . getValidProjectId ( ) ;
442+ const cprojectPath = this . getValidProjectId ( ) ;
398443 this . scope = ComponentScope . Solution ;
399- if ( projectId ) {
400- await this . debounce_load ( projectId , true ) ;
444+ if ( cprojectPath ) {
445+ const reload = this . projectFromPath ( this . currentProject ?. project . projectId ) !== this . projectFromPath ( cprojectPath ) ;
446+
447+ await this . debounce_load ( cprojectPath , reload ) ;
401448 }
402449 }
403450
0 commit comments