@@ -45,6 +45,7 @@ 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' ;
4849
4950function getCodeEditor ( editorWidget : IEditor ) : ICommonCodeEditor {
5051 if ( editorWidget ) {
@@ -681,7 +682,8 @@ export class ChangeModeAction extends Action {
681682 @IConfigurationEditingService private configurationEditingService : IConfigurationEditingService ,
682683 @IMessageService private messageService : IMessageService ,
683684 @IWorkspaceConfigurationService private configurationService : IWorkspaceConfigurationService ,
684- @IQuickOpenService private quickOpenService : IQuickOpenService
685+ @IQuickOpenService private quickOpenService : IQuickOpenService ,
686+ @IInstantiationService private instantiationService : IInstantiationService
685687 ) {
686688 super ( actionId , actionLabel ) ;
687689 }
@@ -740,12 +742,17 @@ export class ChangeModeAction extends Action {
740742
741743 // Offer action to configure via settings
742744 let configureModeAssociations : IPickOpenEntry ;
745+ let galleryAction : Action ;
743746 if ( fileinput ) {
744747 const resource = fileinput . getResource ( ) ;
745- configureModeAssociations = {
746- label : nls . localize ( 'configureAssociationsExt' , "Configure File Association for '{0}'..." , paths . extname ( resource . fsPath ) || paths . basename ( resource . fsPath ) )
747- } ;
748+ const ext = paths . extname ( resource . fsPath ) || paths . basename ( resource . fsPath ) ;
748749
750+ galleryAction = this . instantiationService . createInstance ( ShowLanguageExtensionsAction , ext ) ;
751+ if ( galleryAction . enabled ) {
752+ picks . unshift ( galleryAction ) ;
753+ }
754+
755+ configureModeAssociations = { label : nls . localize ( 'configureAssociationsExt' , "Configure File Association for '{0}'..." , ext ) } ;
749756 picks . unshift ( configureModeAssociations ) ;
750757 }
751758
@@ -757,45 +764,51 @@ export class ChangeModeAction extends Action {
757764 picks . unshift ( autoDetectMode ) ;
758765 }
759766
760- return this . quickOpenService . pick ( picks , { placeHolder : nls . localize ( 'pickLanguage' , "Select Language Mode" ) } ) . then ( language => {
761- if ( language ) {
767+ return this . quickOpenService . pick ( picks , { placeHolder : nls . localize ( 'pickLanguage' , "Select Language Mode" ) } ) . then ( pick => {
768+ if ( ! pick ) {
769+ return ;
770+ }
762771
763- // User decided to permanently configure associations, return right after
764- if ( language === configureModeAssociations ) {
765- this . configureFileAssociation ( fileinput . getResource ( ) ) ;
766- return ;
767- }
772+ if ( pick === galleryAction ) {
773+ galleryAction . run ( ) ;
774+ return ;
775+ }
768776
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 [ ] = [ ] ;
777+ // User decided to permanently configure associations, return right after
778+ if ( pick === configureModeAssociations ) {
779+ this . configureFileAssociation ( fileinput . getResource ( ) ) ;
780+ return ;
781+ }
774782
775- const textModel = getTextModel ( editorWidget ) ;
776- if ( textModel ) {
777- models . push ( textModel ) ;
778- }
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 [ ] = [ ] ;
779788
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- }
789+ const textModel = getTextModel ( editorWidget ) ;
790+ if ( textModel ) {
791+ models . push ( textModel ) ;
792+ }
785793
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- }
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+ }
793799
794- // Change mode
795- models . forEach ( textModel => {
796- this . modelService . setMode ( textModel , mode ) ;
797- } ) ;
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 ) ;
798806 }
807+
808+ // Change mode
809+ models . forEach ( textModel => {
810+ this . modelService . setMode ( textModel , mode ) ;
811+ } ) ;
799812 }
800813 } ) ;
801814 }
0 commit comments