@@ -6,6 +6,7 @@ use edit::fuzzy::score_fuzzy;
66use edit:: helpers:: * ;
77use edit:: icu;
88use edit:: input:: vk;
9+ use edit:: lsh:: LANGUAGES ;
910use edit:: tui:: * ;
1011use stdext:: arena:: scratch_arena;
1112use stdext:: arena_format;
@@ -28,15 +29,21 @@ pub fn draw_statusbar(ctx: &mut Context, state: &mut State) {
2829
2930 ctx. table_next_row ( ) ;
3031
31- if ctx. button ( "newline" , if tb. is_crlf ( ) { "CRLF" } else { "LF" } , ButtonStyle :: default ( ) ) {
32- let is_crlf = tb. is_crlf ( ) ;
33- tb. normalize_newlines ( !is_crlf) ;
34- }
32+ state. wants_language_picker |= ctx. button (
33+ "language" ,
34+ tb. language ( ) . map_or ( "Plain Text" , |l| l. name ) ,
35+ ButtonStyle :: default ( ) ,
36+ ) ;
3537 if state. wants_statusbar_focus {
3638 state. wants_statusbar_focus = false ;
3739 ctx. steal_focus ( ) ;
3840 }
3941
42+ if ctx. button ( "newline" , if tb. is_crlf ( ) { "CRLF" } else { "LF" } , ButtonStyle :: default ( ) ) {
43+ let is_crlf = tb. is_crlf ( ) ;
44+ tb. normalize_newlines ( !is_crlf) ;
45+ }
46+
4047 state. wants_encoding_picker |=
4148 ctx. button ( "encoding" , tb. encoding ( ) , ButtonStyle :: default ( ) ) ;
4249 if state. wants_encoding_picker {
@@ -201,6 +208,55 @@ pub fn draw_statusbar(ctx: &mut Context, state: &mut State) {
201208 ctx. table_end ( ) ;
202209}
203210
211+ pub fn draw_dialog_language_change ( ctx : & mut Context , state : & mut State ) {
212+ let doc = state. documents . active_mut ( ) ;
213+ let mut done = doc. is_none ( ) ;
214+
215+ ctx. modal_begin ( "language" , loc ( LocId :: LanguageSelectMode ) ) ;
216+ if let Some ( doc) = doc {
217+ let width = ( ctx. size ( ) . width - 20 ) . max ( 10 ) ;
218+ let height = ( ctx. size ( ) . height - 10 ) . max ( 10 ) ;
219+
220+ ctx. scrollarea_begin ( "scrollarea" , Size { width, height } ) ;
221+ ctx. attr_background_rgba ( ctx. indexed_alpha ( IndexedColor :: Black , 1 , 4 ) ) ;
222+ ctx. inherit_focus ( ) ;
223+ {
224+ ctx. list_begin ( "languages" ) ;
225+ ctx. inherit_focus ( ) ;
226+
227+ let auto_detect = doc. language_override . is_none ( ) ;
228+ let selected = if auto_detect { None } else { doc. buffer . borrow ( ) . language ( ) } ;
229+
230+ if ctx. list_item ( auto_detect, loc ( LocId :: LanguageAutoDetect ) )
231+ == ListSelection :: Activated
232+ {
233+ doc. auto_detect_language ( ) ;
234+ done = true ;
235+ }
236+
237+ if ctx. list_item ( selected. is_none ( ) , "Plain Text" ) == ListSelection :: Activated {
238+ doc. override_language ( None ) ;
239+ done = true ;
240+ }
241+
242+ for lang in LANGUAGES {
243+ if ctx. list_item ( Some ( lang) == selected, lang. name ) == ListSelection :: Activated {
244+ doc. override_language ( Some ( lang) ) ;
245+ done = true ;
246+ }
247+ }
248+ ctx. list_end ( ) ;
249+ }
250+ ctx. scrollarea_end ( ) ;
251+ }
252+ done |= ctx. modal_end ( ) ;
253+
254+ if done {
255+ state. wants_language_picker = false ;
256+ ctx. needs_rerender ( ) ;
257+ }
258+ }
259+
204260pub fn draw_dialog_encoding_change ( ctx : & mut Context , state : & mut State ) {
205261 let encoding = state. documents . active_mut ( ) . map_or ( "" , |doc| doc. buffer . borrow ( ) . encoding ( ) ) ;
206262 let reopen = state. wants_encoding_change == StateEncodingChange :: Reopen ;
0 commit comments