1 /* 2 * LineEndingsSelectWidget.java 3 * 4 * Copyright (C) 2021 by RStudio, PBC 5 * 6 * Unless you have received this program directly from RStudio pursuant 7 * to the terms of a commercial license agreement with RStudio, then 8 * this program is licensed to you under the terms of version 3 of the 9 * GNU Affero General Public License. This program is distributed WITHOUT 10 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 12 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. 13 * 14 */ 15 16 package org.rstudio.studio.client.workbench.prefs.views; 17 18 import java.util.ArrayList; 19 20 import org.rstudio.core.client.widget.SelectWidget; 21 import org.rstudio.studio.client.workbench.prefs.model.UserPrefs; 22 23 public class LineEndingsSelectWidget extends SelectWidget 24 { LineEndingsSelectWidget()25 public LineEndingsSelectWidget() 26 { 27 this(false); 28 } 29 LineEndingsSelectWidget(boolean includeDefault)30 public LineEndingsSelectWidget(boolean includeDefault) 31 { 32 super("Line ending conversion:", 33 getLineEndingsCaptions(includeDefault), 34 getLineEndingsValues(includeDefault), 35 false, 36 true, 37 false); 38 } 39 getLineEndingsCaptions(boolean includeDefault)40 private static String[] getLineEndingsCaptions(boolean includeDefault) 41 { 42 ArrayList<String> captions = new ArrayList<>(); 43 if (includeDefault) 44 captions.add("(Use Default)"); 45 captions.add("None"); 46 captions.add("Platform Native"); 47 captions.add("Posix (LF)"); 48 captions.add("Windows (CR/LF)"); 49 50 return captions.toArray(new String[0]); 51 } 52 getLineEndingsValues(boolean includeDefault)53 private static String[] getLineEndingsValues(boolean includeDefault) 54 { 55 ArrayList<String> values = new ArrayList<>(); 56 if (includeDefault) 57 values.add(UserPrefs.LINE_ENDING_CONVERSION_DEFAULT); 58 values.add(UserPrefs.LINE_ENDING_CONVERSION_PASSTHROUGH); 59 values.add(UserPrefs.LINE_ENDING_CONVERSION_NATIVE); 60 values.add(UserPrefs.LINE_ENDING_CONVERSION_POSIX); 61 values.add(UserPrefs.LINE_ENDING_CONVERSION_WINDOWS); 62 63 return values.toArray(new String[0]); 64 } 65 66 } 67