From 685b9755b9d058ff8c262f18662103694dea2e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 2 Mar 2018 10:40:31 +0100 Subject: [PATCH] Optimize tab switching: saving only happens if state is 'DIRTY' --- src/app/webide/webide.component.html | 2 +- src/app/webide/webide.component.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/app/webide/webide.component.html b/src/app/webide/webide.component.html index 5a2a2a6..37f1f25 100644 --- a/src/app/webide/webide.component.html +++ b/src/app/webide/webide.component.html @@ -3,7 +3,7 @@ class="btn btn-secondary" [class.active]="filename === file" [class.disabled]="filename === file" - (click)="sendCodeContents(); selectCode(file); requestCode()" + (click)="tabSwitchButtonHandler(file)" [disabled]="filename === file"> {{file}} diff --git a/src/app/webide/webide.component.ts b/src/app/webide/webide.component.ts index 2180d8e..a0d76bd 100644 --- a/src/app/webide/webide.component.ts +++ b/src/app/webide/webide.component.ts @@ -76,6 +76,14 @@ export class WebideComponent implements OnInit { this.updateFileData(data); } + tabSwitchButtonHandler(file) { + if (this.saveButtonState === 'DIRTY') { + this.sendCodeContents(); + } + this.selectCode(file); + this.requestCode(); + } + setButtonStateSaved() { this.saveButtonState = 'SAVED'; }