Skip to content

Commit

Permalink
editor: save dirty editors with auto-save on
Browse files Browse the repository at this point in the history
The following commit triggers a `saveAll` (for all dirty content), when
the `auto-save` is turned on.

Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed Jul 14, 2020
1 parent a1ea230 commit 42a09db
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/editor/src/browser/editor-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { inject, injectable } from 'inversify';
import { inject, injectable, postConstruct } from 'inversify';
import { CommandContribution, CommandRegistry, Command } from '@theia/core/lib/common';
import URI from '@theia/core/lib/common/uri';
import { CommonCommands, PreferenceService, QuickPickItem, QuickPickService, LabelProvider, QuickPickValue } from '@theia/core/lib/browser';
import { CommonCommands, PreferenceService, QuickPickItem, QuickPickService, LabelProvider, QuickPickValue, ApplicationShell } from '@theia/core/lib/browser';
import { Languages, Language } from '@theia/languages/lib/browser';
import { EditorManager } from './editor-manager';
import { EncodingMode } from './editor';
Expand Down Expand Up @@ -140,6 +140,9 @@ export class EditorCommandContribution implements CommandContribution {

public static readonly AUTOSAVE_PREFERENCE: string = 'editor.autoSave';

@inject(ApplicationShell)
protected readonly shell: ApplicationShell;

@inject(PreferenceService)
protected readonly preferencesService: PreferenceService;

Expand All @@ -163,6 +166,15 @@ export class EditorCommandContribution implements CommandContribution {
@inject(ResourceProvider)
protected readonly resourceProvider: ResourceProvider;

@postConstruct()
protected init(): void {
this.editorPreferences.onPreferenceChanged(e => {
if (e.preferenceName === 'editor.autoSave' && e.newValue === 'on') {
this.shell.saveAll();
}
});
}

registerCommands(registry: CommandRegistry): void {
registry.registerCommand(EditorCommands.SHOW_REFERENCES);
registry.registerCommand(EditorCommands.CONFIG_INDENTATION);
Expand Down

0 comments on commit 42a09db

Please sign in to comment.