mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-10 16:58:55 -05:00
AutoSave setting is lost (fixes #1762)
This commit is contained in:
@@ -130,13 +130,25 @@ export class ElectronIntegration {
|
||||
ipc.on('vscode:showAutoSaveInfo', () => {
|
||||
this.messageService.show(
|
||||
Severity.Info, {
|
||||
message: nls.localize('autoSaveInfo', "The **File | Auto Save** option moved into settings. Please configure **files.autoSaveDelay: 1** to restore the old behavior."),
|
||||
message: nls.localize('autoSaveInfo', "The **File | Auto Save** option moved into settings and **files.autoSaveDelay: 1** will be added to preserve it."),
|
||||
actions: [
|
||||
CloseAction,
|
||||
this.instantiationService.createInstance(OpenGlobalSettingsAction, OpenGlobalSettingsAction.ID, OpenGlobalSettingsAction.LABEL)
|
||||
]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
ipc.on('vscode:showAutoSaveError', () => {
|
||||
this.messageService.show(
|
||||
Severity.Warning, {
|
||||
message: nls.localize('autoSaveError', "Unable to write to settings. Please add **files.autoSaveDelay: 1** to settings.json."),
|
||||
actions: [
|
||||
CloseAction,
|
||||
this.instantiationService.createInstance(OpenGlobalSettingsAction, OpenGlobalSettingsAction.ID, OpenGlobalSettingsAction.LABEL)
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private resolveKeybindings(actionIds: string[]): TPromise<{ id: string; binding: number; }[]> {
|
||||
|
||||
@@ -23,6 +23,7 @@ import window = require('vs/workbench/electron-main/window');
|
||||
import lifecycle = require('vs/workbench/electron-main/lifecycle');
|
||||
import nls = require('vs/nls');
|
||||
import paths = require('vs/base/common/paths');
|
||||
import json = require('vs/base/common/json');
|
||||
import arrays = require('vs/base/common/arrays');
|
||||
import objects = require('vs/base/common/objects');
|
||||
import storage = require('vs/workbench/electron-main/storage');
|
||||
@@ -175,10 +176,7 @@ export class WindowsManager {
|
||||
eventEmitter.emit(EventTypes.READY, win);
|
||||
|
||||
// TODO@Ben remove me in a couple of versions
|
||||
if (storage.getItem<number>('autoSaveDelay') === 1000) {
|
||||
storage.removeItem('autoSaveDelay');
|
||||
win.send('vscode:showAutoSaveInfo');
|
||||
}
|
||||
this.migrateAutoSave(win);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -342,6 +340,46 @@ export class WindowsManager {
|
||||
});
|
||||
}
|
||||
|
||||
private migrateAutoSave(win: window.VSCodeWindow): void {
|
||||
if (storage.getItem<number>('autoSaveDelay') === 1000) {
|
||||
storage.removeItem('autoSaveDelay');
|
||||
win.send('vscode:showAutoSaveInfo');
|
||||
|
||||
try {
|
||||
|
||||
// Initial settings file
|
||||
if (!fs.existsSync(env.appSettingsPath)) {
|
||||
fs.writeFileSync(env.appSettingsPath, JSON.stringify({ 'files.autoSaveDelay': 1 }, null, ' '));
|
||||
}
|
||||
|
||||
// Update existing settings file
|
||||
else {
|
||||
const settingsRaw = fs.readFileSync(env.appSettingsPath).toString();
|
||||
const lastClosing = settingsRaw.lastIndexOf('}');
|
||||
const errors = [];
|
||||
const res = json.parse(settingsRaw, errors);
|
||||
|
||||
// We found a closing '}' and the JSON does not contain errors
|
||||
if (lastClosing > 0 && !errors.length) {
|
||||
const hasOtherKeys = Object.getOwnPropertyNames(res).length > 0;
|
||||
|
||||
const migratedSettings = settingsRaw.substring(0, lastClosing) + '\n // Migrated from previous File | Auto Save setting:\n' + (hasOtherKeys ? ' , "files.autoSaveDelay": 1\n' : ' "files.autoSaveDelay": 1\n') + '}';
|
||||
|
||||
fs.writeFileSync(env.appSettingsPath, migratedSettings);
|
||||
}
|
||||
|
||||
// Otherwise inform user that we cannot migrate the settings
|
||||
else {
|
||||
win.send('vscode:showAutoSaveError');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
env.log(error);
|
||||
win.send('vscode:showAutoSaveError');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public reload(win: window.VSCodeWindow, cli?: env.ICommandLineArguments): void {
|
||||
|
||||
// Only reload when the window has not vetoed this
|
||||
@@ -600,7 +638,7 @@ export class WindowsManager {
|
||||
recentPaths.unshift(workspacePath);
|
||||
}
|
||||
|
||||
// Clear those dupes
|
||||
// Clear those dupes
|
||||
recentPaths = arrays.distinct(recentPaths);
|
||||
|
||||
// Make sure it is bounded
|
||||
|
||||
Reference in New Issue
Block a user