mirror of
				https://github.com/arduino/arduino-ide.git
				synced 2025-10-30 21:48:33 +00:00 
			
		
		
		
	Make tab width 2 spaces (#445)
This commit is contained in:
		| @@ -10,9 +10,9 @@ import { FrontendApplicationStateService } from '@theia/core/lib/browser/fronten | ||||
| import { WorkspaceService as TheiaWorkspaceService } from '@theia/workspace/lib/browser/workspace-service'; | ||||
| import { ConfigService } from '../../../common/protocol/config-service'; | ||||
| import { | ||||
|     SketchesService, | ||||
|     Sketch, | ||||
|     SketchContainer, | ||||
|   SketchesService, | ||||
|   Sketch, | ||||
|   SketchContainer, | ||||
| } from '../../../common/protocol/sketches-service'; | ||||
| import { ArduinoWorkspaceRootResolver } from '../../arduino-workspace-resolver'; | ||||
| import { BoardsServiceProvider } from '../../boards/boards-service-provider'; | ||||
| @@ -20,133 +20,131 @@ import { BoardsConfig } from '../../boards/boards-config'; | ||||
|  | ||||
| @injectable() | ||||
| export class WorkspaceService extends TheiaWorkspaceService { | ||||
|     @inject(SketchesService) | ||||
|     protected readonly sketchService: SketchesService; | ||||
|   @inject(SketchesService) | ||||
|   protected readonly sketchService: SketchesService; | ||||
|  | ||||
|     @inject(ConfigService) | ||||
|     protected readonly configService: ConfigService; | ||||
|   @inject(ConfigService) | ||||
|   protected readonly configService: ConfigService; | ||||
|  | ||||
|     @inject(LabelProvider) | ||||
|     protected readonly labelProvider: LabelProvider; | ||||
|   @inject(LabelProvider) | ||||
|   protected readonly labelProvider: LabelProvider; | ||||
|  | ||||
|     @inject(MessageService) | ||||
|     protected readonly messageService: MessageService; | ||||
|   @inject(MessageService) | ||||
|   protected readonly messageService: MessageService; | ||||
|  | ||||
|     @inject(ApplicationServer) | ||||
|     protected readonly applicationServer: ApplicationServer; | ||||
|   @inject(ApplicationServer) | ||||
|   protected readonly applicationServer: ApplicationServer; | ||||
|  | ||||
|     @inject(FrontendApplicationStateService) | ||||
|     protected readonly appStateService: FrontendApplicationStateService; | ||||
|   @inject(FrontendApplicationStateService) | ||||
|   protected readonly appStateService: FrontendApplicationStateService; | ||||
|  | ||||
|     @inject(BoardsServiceProvider) | ||||
|     protected readonly boardsServiceProvider: BoardsServiceProvider; | ||||
|   @inject(BoardsServiceProvider) | ||||
|   protected readonly boardsServiceProvider: BoardsServiceProvider; | ||||
|  | ||||
|     private application: FrontendApplication; | ||||
|     private workspaceUri?: Promise<string | undefined>; | ||||
|     private version?: string; | ||||
|   private application: FrontendApplication; | ||||
|   private workspaceUri?: Promise<string | undefined>; | ||||
|   private version?: string; | ||||
|  | ||||
|     async onStart(application: FrontendApplication): Promise<void> { | ||||
|         this.application = application; | ||||
|         const info = await this.applicationServer.getApplicationInfo(); | ||||
|         this.version = info?.version; | ||||
|         application.shell.onDidChangeCurrentWidget( | ||||
|             this.onCurrentWidgetChange.bind(this) | ||||
|   async onStart(application: FrontendApplication): Promise<void> { | ||||
|     this.application = application; | ||||
|     const info = await this.applicationServer.getApplicationInfo(); | ||||
|     this.version = info?.version; | ||||
|     application.shell.onDidChangeCurrentWidget( | ||||
|       this.onCurrentWidgetChange.bind(this) | ||||
|     ); | ||||
|     const newValue = application.shell.currentWidget | ||||
|       ? application.shell.currentWidget | ||||
|       : null; | ||||
|     this.onCurrentWidgetChange({ newValue, oldValue: null }); | ||||
|   } | ||||
|  | ||||
|   protected getDefaultWorkspaceUri(): Promise<string | undefined> { | ||||
|     if (this.workspaceUri) { | ||||
|       // Avoid creating a new sketch twice | ||||
|       return this.workspaceUri; | ||||
|     } | ||||
|     this.workspaceUri = (async () => { | ||||
|       try { | ||||
|         const hash = window.location.hash; | ||||
|         const [recentWorkspaces, recentSketches] = await Promise.all([ | ||||
|           this.server.getRecentWorkspaces(), | ||||
|           this.sketchService | ||||
|             .getSketches({}) | ||||
|             .then((container) => | ||||
|               SketchContainer.toArray(container).map((s) => s.uri) | ||||
|             ), | ||||
|         ]); | ||||
|         const toOpen = await new ArduinoWorkspaceRootResolver({ | ||||
|           isValid: this.isValid.bind(this), | ||||
|         }).resolve({ hash, recentWorkspaces, recentSketches }); | ||||
|         if (toOpen) { | ||||
|           const { uri } = toOpen; | ||||
|           await this.server.setMostRecentlyUsedWorkspace(uri); | ||||
|           return toOpen.uri; | ||||
|         } | ||||
|         return (await this.sketchService.createNewSketch()).uri; | ||||
|       } catch (err) { | ||||
|         this.appStateService | ||||
|           .reachedState('ready') | ||||
|           .then(() => this.application.shell.update()); | ||||
|         this.logger.fatal(`Failed to determine the sketch directory: ${err}`); | ||||
|         this.messageService.error( | ||||
|           'There was an error creating the sketch directory. ' + | ||||
|             'See the log for more details. ' + | ||||
|             'The application will probably not work as expected.' | ||||
|         ); | ||||
|         const newValue = application.shell.currentWidget | ||||
|             ? application.shell.currentWidget | ||||
|             : null; | ||||
|         this.onCurrentWidgetChange({ newValue, oldValue: null }); | ||||
|     } | ||||
|         return super.getDefaultWorkspaceUri(); | ||||
|       } | ||||
|     })(); | ||||
|     return this.workspaceUri; | ||||
|   } | ||||
|  | ||||
|     protected getDefaultWorkspaceUri(): Promise<string | undefined> { | ||||
|         if (this.workspaceUri) { | ||||
|             // Avoid creating a new sketch twice | ||||
|             return this.workspaceUri; | ||||
|         } | ||||
|         this.workspaceUri = (async () => { | ||||
|             try { | ||||
|                 const hash = window.location.hash; | ||||
|                 const [recentWorkspaces, recentSketches] = await Promise.all([ | ||||
|                     this.server.getRecentWorkspaces(), | ||||
|                     this.sketchService | ||||
|                         .getSketches({}) | ||||
|                         .then((container) => | ||||
|                             SketchContainer.toArray(container).map((s) => s.uri) | ||||
|                         ), | ||||
|                 ]); | ||||
|                 const toOpen = await new ArduinoWorkspaceRootResolver({ | ||||
|                     isValid: this.isValid.bind(this), | ||||
|                 }).resolve({ hash, recentWorkspaces, recentSketches }); | ||||
|                 if (toOpen) { | ||||
|                     const { uri } = toOpen; | ||||
|                     await this.server.setMostRecentlyUsedWorkspace(uri); | ||||
|                     return toOpen.uri; | ||||
|                 } | ||||
|                 return (await this.sketchService.createNewSketch()).uri; | ||||
|             } catch (err) { | ||||
|                 this.appStateService | ||||
|                     .reachedState('ready') | ||||
|                     .then(() => this.application.shell.update()); | ||||
|                 this.logger.fatal( | ||||
|                     `Failed to determine the sketch directory: ${err}` | ||||
|                 ); | ||||
|                 this.messageService.error( | ||||
|                     'There was an error creating the sketch directory. ' + | ||||
|                         'See the log for more details. ' + | ||||
|                         'The application will probably not work as expected.' | ||||
|                 ); | ||||
|                 return super.getDefaultWorkspaceUri(); | ||||
|             } | ||||
|         })(); | ||||
|         return this.workspaceUri; | ||||
|     } | ||||
|   protected openNewWindow(workspacePath: string): void { | ||||
|     const { boardsConfig } = this.boardsServiceProvider; | ||||
|     const url = BoardsConfig.Config.setConfig( | ||||
|       boardsConfig, | ||||
|       new URL(window.location.href) | ||||
|     ); // Set the current boards config for the new browser window. | ||||
|     url.hash = workspacePath; | ||||
|     this.windowService.openNewWindow(url.toString()); | ||||
|   } | ||||
|  | ||||
|     protected openNewWindow(workspacePath: string): void { | ||||
|         const { boardsConfig } = this.boardsServiceProvider; | ||||
|         const url = BoardsConfig.Config.setConfig( | ||||
|             boardsConfig, | ||||
|             new URL(window.location.href) | ||||
|         ); // Set the current boards config for the new browser window. | ||||
|         url.hash = workspacePath; | ||||
|         this.windowService.openNewWindow(url.toString()); | ||||
|   private async isValid(uri: string): Promise<boolean> { | ||||
|     const exists = await this.fileService.exists(new URI(uri)); | ||||
|     if (!exists) { | ||||
|       return false; | ||||
|     } | ||||
|     return this.sketchService.isSketchFolder(uri); | ||||
|   } | ||||
|  | ||||
|     private async isValid(uri: string): Promise<boolean> { | ||||
|         const exists = await this.fileService.exists(new URI(uri)); | ||||
|         if (!exists) { | ||||
|             return false; | ||||
|         } | ||||
|         return this.sketchService.isSketchFolder(uri); | ||||
|   protected onCurrentWidgetChange({ | ||||
|     newValue, | ||||
|   }: FocusTracker.IChangedArgs<Widget>): void { | ||||
|     if (newValue instanceof EditorWidget) { | ||||
|       const { uri } = newValue.editor; | ||||
|       if (Sketch.isSketchFile(uri.toString())) { | ||||
|         this.updateTitle(); | ||||
|       } else { | ||||
|         const title = this.workspaceTitle; | ||||
|         const fileName = this.labelProvider.getName(uri); | ||||
|         document.title = this.formatTitle( | ||||
|           title ? `${title} - ${fileName}` : fileName | ||||
|         ); | ||||
|       } | ||||
|     } else { | ||||
|       this.updateTitle(); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|     protected onCurrentWidgetChange({ | ||||
|         newValue, | ||||
|     }: FocusTracker.IChangedArgs<Widget>): void { | ||||
|         if (newValue instanceof EditorWidget) { | ||||
|             const { uri } = newValue.editor; | ||||
|             if (Sketch.isSketchFile(uri.toString())) { | ||||
|                 this.updateTitle(); | ||||
|             } else { | ||||
|                 const title = this.workspaceTitle; | ||||
|                 const fileName = this.labelProvider.getName(uri); | ||||
|                 document.title = this.formatTitle( | ||||
|                     title ? `${title} - ${fileName}` : fileName | ||||
|                 ); | ||||
|             } | ||||
|         } else { | ||||
|             this.updateTitle(); | ||||
|         } | ||||
|     } | ||||
|   protected formatTitle(title?: string): string { | ||||
|     const version = this.version ? ` ${this.version}` : ''; | ||||
|     const name = `${this.applicationName} ${version}`; | ||||
|     return title ? `${title} | ${name}` : name; | ||||
|   } | ||||
|  | ||||
|     protected formatTitle(title?: string): string { | ||||
|         const version = this.version ? ` ${this.version}` : ''; | ||||
|         const name = `${this.applicationName} ${version}`; | ||||
|         return title ? `${title} | ${name}` : name; | ||||
|     } | ||||
|  | ||||
|     protected get workspaceTitle(): string | undefined { | ||||
|         if (this.workspace) { | ||||
|             return this.labelProvider.getName(this.workspace.resource); | ||||
|         } | ||||
|   protected get workspaceTitle(): string | undefined { | ||||
|     if (this.workspace) { | ||||
|       return this.labelProvider.getName(this.workspace.resource); | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Francesco Stasi
					Francesco Stasi