@@ -45,7 +45,6 @@ import { Selection } from 'vs/editor/common/core/selection';
4545import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService' ;
4646import { TabFocus } from 'vs/editor/common/config/commonEditorConfig' ;
4747import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles' ;
48- import { ShowLanguageExtensionsAction } from 'vs/workbench/parts/extensions/electron-browser/extensionsActions' ;
4948
5049function getCodeEditor ( editorWidget : IEditor ) : ICommonCodeEditor {
5150 if ( editorWidget ) {
@@ -682,8 +681,7 @@ export class ChangeModeAction extends Action {
682681 @IConfigurationEditingService private configurationEditingService : IConfigurationEditingService ,
683682 @IMessageService private messageService : IMessageService ,
684683 @IWorkspaceConfigurationService private configurationService : IWorkspaceConfigurationService ,
685- @IQuickOpenService private quickOpenService : IQuickOpenService ,
686- @IInstantiationService private instantiationService : IInstantiationService
684+ @IQuickOpenService private quickOpenService : IQuickOpenService
687685 ) {
688686 super ( actionId , actionLabel ) ;
689687 }
@@ -742,17 +740,12 @@ export class ChangeModeAction extends Action {
742740
743741 // Offer action to configure via settings
744742 let configureModeAssociations : IPickOpenEntry ;
745- let galleryAction : Action ;
746743 if ( fileinput ) {
747744 const resource = fileinput . getResource ( ) ;
748- const ext = paths . extname ( resource . fsPath ) || paths . basename ( resource . fsPath ) ;
749-
750- galleryAction = this . instantiationService . createInstance ( ShowLanguageExtensionsAction , ext ) ;
751- if ( galleryAction . enabled ) {
752- picks . unshift ( galleryAction ) ;
753- }
745+ configureModeAssociations = {
746+ label : nls . localize ( 'configureAssociationsExt' , "Configure File Association for '{0}'..." , paths . extname ( resource . fsPath ) || paths . basename ( resource . fsPath ) )
747+ } ;
754748
755- configureModeAssociations = { label : nls . localize ( 'configureAssociationsExt' , "Configure File Association for '{0}'..." , ext ) } ;
756749 picks . unshift ( configureModeAssociations ) ;
757750 }
758751
@@ -764,51 +757,45 @@ export class ChangeModeAction extends Action {
764757 picks . unshift ( autoDetectMode ) ;
765758 }
766759
767- return this . quickOpenService . pick ( picks , { placeHolder : nls . localize ( 'pickLanguage' , "Select Language Mode" ) } ) . then ( pick => {
768- if ( ! pick ) {
769- return ;
770- }
760+ return this . quickOpenService . pick ( picks , { placeHolder : nls . localize ( 'pickLanguage' , "Select Language Mode" ) } ) . then ( language => {
761+ if ( language ) {
771762
772- if ( pick === galleryAction ) {
773- galleryAction . run ( ) ;
774- return ;
775- }
763+ // User decided to permanently configure associations, return right after
764+ if ( language === configureModeAssociations ) {
765+ this . configureFileAssociation ( fileinput . getResource ( ) ) ;
766+ return ;
767+ }
776768
777- // User decided to permanently configure associations, return right after
778- if ( pick === configureModeAssociations ) {
779- this . configureFileAssociation ( fileinput . getResource ( ) ) ;
780- return ;
781- }
769+ // Change mode for active editor
770+ activeEditor = this . editorService . getActiveEditor ( ) ;
771+ if ( activeEditor instanceof BaseTextEditor ) {
772+ const editorWidget = activeEditor . getControl ( ) ;
773+ const models : IModel [ ] = [ ] ;
782774
783- // Change mode for active editor
784- activeEditor = this . editorService . getActiveEditor ( ) ;
785- if ( activeEditor instanceof BaseTextEditor ) {
786- const editorWidget = activeEditor . getControl ( ) ;
787- const models : IModel [ ] = [ ] ;
775+ const textModel = getTextModel ( editorWidget ) ;
776+ if ( textModel ) {
777+ models . push ( textModel ) ;
778+ }
788779
789- const textModel = getTextModel ( editorWidget ) ;
790- if ( textModel ) {
791- models . push ( textModel ) ;
792- }
780+ // Support for original side of diff
781+ const model = editorWidget . getModel ( ) ;
782+ if ( model && ! ! ( < IDiffEditorModel > model ) . original ) {
783+ models . push ( ( < IDiffEditorModel > model ) . original ) ;
784+ }
793785
794- // Support for original side of diff
795- const model = editorWidget . getModel ( ) ;
796- if ( model && ! ! ( < IDiffEditorModel > model ) . original ) {
797- models . push ( ( < IDiffEditorModel > model ) . original ) ;
798- }
786+ // Find mode
787+ let mode : TPromise < IMode > ;
788+ if ( language === autoDetectMode ) {
789+ mode = this . modeService . getOrCreateModeByFilenameOrFirstLine ( getUntitledOrFileResource ( activeEditor . input , true ) . fsPath , textModel . getLineContent ( 1 ) ) ;
790+ } else {
791+ mode = this . modeService . getOrCreateModeByLanguageName ( language . label ) ;
792+ }
799793
800- // Find mode
801- let mode : TPromise < IMode > ;
802- if ( pick === autoDetectMode ) {
803- mode = this . modeService . getOrCreateModeByFilenameOrFirstLine ( getUntitledOrFileResource ( activeEditor . input , true ) . fsPath , textModel . getLineContent ( 1 ) ) ;
804- } else {
805- mode = this . modeService . getOrCreateModeByLanguageName ( pick . label ) ;
794+ // Change mode
795+ models . forEach ( textModel => {
796+ this . modelService . setMode ( textModel , mode ) ;
797+ } ) ;
806798 }
807-
808- // Change mode
809- models . forEach ( textModel => {
810- this . modelService . setMode ( textModel , mode ) ;
811- } ) ;
812799 }
813800 } ) ;
814801 }
0 commit comments