Skip to content

Commit

Permalink
Merge branch 'eclipse-theiagh-12557-workspace-save-fixes' of https://…
Browse files Browse the repository at this point in the history
  • Loading branch information
vladarama committed Aug 22, 2023
2 parents fee1706 + 88bc7d7 commit feaf963
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions packages/core/src/browser/common-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { OS, isOSX, isWindows, EOL } from '../common/os';
import { ResourceContextKey } from './resource-context-key';
import { UriSelection } from '../common/selection';
import { StorageService } from './storage-service';
import { Navigatable } from './navigatable';
import { Navigatable, NavigatableWidget } from './navigatable';
import { QuickViewService } from './quick-input/quick-view-service';
import { environment } from '@theia/application-package/lib/environment';
import { IconTheme, IconThemeService } from './icon-theme-service';
Expand All @@ -63,7 +63,7 @@ import { DecorationStyle } from './decoration-style';
import { isPinned, Title, togglePinned, Widget } from './widgets';
import { SaveResourceService } from './save-resource-service';
import { UserWorkingDirectoryProvider } from './user-working-directory-provider';
import { UntitledResourceResolver } from '../common';
import { UNTITLED_SCHEME, UntitledResourceResolver } from '../common';
import { LanguageQuickPickService } from './i18n/language-quick-pick-service';

export namespace CommonMenus {
Expand Down Expand Up @@ -1144,9 +1144,18 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
onWillStop(): OnWillStopAction | undefined {
try {
if (this.shouldPreventClose || this.shell.canSaveAll()) {
const captionsToSave = this.unsavedTabsCaptions();

return { reason: 'Dirty editors present', action: async () => confirmExitWithOrWithoutSaving(captionsToSave, async () => this.shell.saveAll()) };
return {
reason: 'Dirty editors present',
action: async () => {
const captionsToSave = this.unsavedTabsCaptions();
const untitledCaptionsToSave = this.unsavedUntitledTabsCaptions();
const result = await confirmExitWithOrWithoutSaving(captionsToSave, async () => {
await this.shell.saveAll();
await this.saveDirty(untitledCaptionsToSave);
});
return result;
}
};
}
} finally {
this.shouldPreventClose = false;
Expand All @@ -1157,6 +1166,11 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
.filter(widget => this.saveResourceService.canSave(widget))
.map(widget => widget.title.label);
}
protected unsavedUntitledTabsCaptions(): Widget[] {
return this.shell.widgets.filter(widget =>
NavigatableWidget.getUri(widget)?.scheme === UNTITLED_SCHEME && this.saveResourceService.canSaveAs(widget)
);
}
protected async configureDisplayLanguage(): Promise<void> {
const languageInfo = await this.languageQuickPickService.pickDisplayLanguage();
if (languageInfo && !nls.isSelectedLocale(languageInfo.languageId) && await this.confirmRestart(
Expand All @@ -1167,7 +1181,15 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
this.windowService.reload();
}
}

protected async saveDirty(toSave: Widget[]): Promise<void> {
for (const widget of toSave) {
const saveable = Saveable.get(widget);
if (saveable?.dirty) {
await this.saveResourceService.save(widget);
}
}
await this.shell.saveAll();
}
protected toggleBreadcrumbs(): void {
const value: boolean | undefined = this.preferenceService.get('breadcrumbs.enabled');
this.preferenceService.set('breadcrumbs.enabled', !value, PreferenceScope.User);
Expand Down

0 comments on commit feaf963

Please sign in to comment.