Fixed Save As when overwriting existing sketch.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2020-12-11 11:40:35 +01:00 committed by Akos Kitta
parent 3191a09562
commit f1bffaab2d
4 changed files with 54 additions and 4 deletions

View File

@ -128,6 +128,8 @@ import { EditorCommandContribution } from './theia/editor/editor-command';
import { NavigatorTabBarDecorator as TheiaNavigatorTabBarDecorator } from '@theia/navigator/lib/browser/navigator-tab-bar-decorator'; import { NavigatorTabBarDecorator as TheiaNavigatorTabBarDecorator } from '@theia/navigator/lib/browser/navigator-tab-bar-decorator';
import { NavigatorTabBarDecorator } from './theia/navigator/navigator-tab-bar-decorator'; import { NavigatorTabBarDecorator } from './theia/navigator/navigator-tab-bar-decorator';
import { Debug } from './contributions/debug'; import { Debug } from './contributions/debug';
import { DebugSessionManager } from './theia/debug/debug-session-manager';
import { DebugSessionManager as TheiaDebugSessionManager } from '@theia/debug/lib/browser/debug-session-manager';
const ElementQueries = require('css-element-queries/src/ElementQueries'); const ElementQueries = require('css-element-queries/src/ElementQueries');
@ -355,4 +357,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
// Silent the badge decoration in the Explorer view. // Silent the badge decoration in the Explorer view.
bind(NavigatorTabBarDecorator).toSelf().inSingletonScope(); bind(NavigatorTabBarDecorator).toSelf().inSingletonScope();
rebind(TheiaNavigatorTabBarDecorator).toService(NavigatorTabBarDecorator); rebind(TheiaNavigatorTabBarDecorator).toService(NavigatorTabBarDecorator);
// To avoid running `Save All` when there are no dirty editors before starting the debug session.
bind(DebugSessionManager).toSelf().inSingletonScope();
rebind(TheiaDebugSessionManager).toService(DebugSessionManager);
}); });

View File

@ -68,9 +68,6 @@ export class ApplicationShell extends TheiaApplicationShell {
} }
async saveAll(): Promise<void> { async saveAll(): Promise<void> {
if (!this.canSaveAll()) { // This is a quick fix for not saving the editor when there are no dirty editors.
return; // https://github.com/bcmi-labs/arduino-editor/pull/172#issuecomment-741831888
}
if (this.connectionStatusService.currentStatus === ConnectionStatus.OFFLINE) { if (this.connectionStatusService.currentStatus === ConnectionStatus.OFFLINE) {
this.messageService.error('Could not save the sketch. Please copy your unsaved work into your favorite text editor, and restart the IDE.'); this.messageService.error('Could not save the sketch. Please copy your unsaved work into your favorite text editor, and restart the IDE.');
return; // Theia does not reject on failed save: https://github.com/eclipse-theia/theia/pull/8803 return; // Theia does not reject on failed save: https://github.com/eclipse-theia/theia/pull/8803

View File

@ -0,0 +1,45 @@
import { injectable } from 'inversify';
import { DebugError } from '@theia/debug/lib/common/debug-service';
import { DebugSession } from '@theia/debug/lib/browser/debug-session';
import { DebugSessionOptions } from '@theia/debug/lib/browser/debug-session-options';
import { DebugSessionManager as TheiaDebugSessionManager } from '@theia/debug/lib/browser/debug-session-manager';
@injectable()
export class DebugSessionManager extends TheiaDebugSessionManager {
async start(options: DebugSessionOptions): Promise<DebugSession | undefined> {
return this.progressService.withProgress('Start...', 'debug', async () => {
try {
// Only save when dirty. To avoid saving temporary sketches.
// This is a quick fix for not saving the editor when there are no dirty editors.
// // https://github.com/bcmi-labs/arduino-editor/pull/172#issuecomment-741831888
if (this.shell.canSaveAll()) {
await this.shell.saveAll();
}
await this.fireWillStartDebugSession();
const resolved = await this.resolveConfiguration(options);
// preLaunchTask isn't run in case of auto restart as well as postDebugTask
if (!options.configuration.__restart) {
const taskRun = await this.runTask(options.workspaceFolderUri, resolved.configuration.preLaunchTask, true);
if (!taskRun) {
return undefined;
}
}
const sessionId = await this.debug.createDebugSession(resolved.configuration);
return this.doStart(sessionId, resolved);
} catch (e) {
if (DebugError.NotFound.is(e)) {
this.messageService.error(`The debug session type "${e.data.type}" is not supported.`);
return undefined;
}
this.messageService.error('There was an error starting the debug session, check the logs for more details.');
console.error('Error starting the debug session', e);
throw e;
}
});
}
}

View File

@ -383,7 +383,9 @@ void loop() {
try { try {
const oldPath = path.join(destination, new URI(sketch.mainFileUri).path.base); const oldPath = path.join(destination, new URI(sketch.mainFileUri).path.base);
const newPath = path.join(destination, `${newName}.ino`); const newPath = path.join(destination, `${newName}.ino`);
await fs.rename(oldPath, newPath); if (oldPath !== newPath) {
await fs.rename(oldPath, newPath);
}
await this.loadSketch(destinationUri); // Sanity check. await this.loadSketch(destinationUri); // Sanity check.
resolve(); resolve();
} catch (e) { } catch (e) {