public override string SetText(string value, string subvalue) { string error; EncodingPair newValue = EncodingPair.ParseEncoding(value, out error); if (!newValue.IsNull) { this.value = newValue; } return(error); }
override public void SetTemp(SValue sValue) { if (sValue.IsString) { string error; EncodingPair newValue = EncodingPair.ParseEncoding(sValue.String, out error); if (!newValue.IsNull) { value = newValue; } } }
public void InitBytes(byte[] bytes, EncodingPair defaultEncoding, out string error) { error = null; string text = ""; encodingPair = defaultEncoding; if (bytes != null) { try { if (!settedEncodingPair.IsNull) { encodingPair = settedEncodingPair; } else { bool bom; Encoding encoding = TextFileEncodingDetector.DetectTextByteArrayEncoding(bytes, out bom); if (encoding != null) { encodingPair = new EncodingPair(encoding, bom); } } int bomLength = encodingPair.CorrectBomLength(bytes); if (encodingPair.bom && encodingPair.encoding == Encoding.UTF8 && bomLength == 0) { encodingPair = new EncodingPair(Encoding.UTF8, false); settedEncodingPair = encodingPair; if (error == null) { error = "Missing bom, loaded as without it"; } } text = encodingPair.GetString(bytes, bomLength); } catch (Exception e) { error = e.Message; } } if (encodingPair.IsNull) { encodingPair = new EncodingPair(Encoding.UTF8, false); } Controller.InitText(text); }
public static Encoding GetEncoding(MainForm mainForm, string parameters) { string rawEncoding = TryGetParameter(parameters, 'e'); if (!string.IsNullOrEmpty(rawEncoding)) { string error; EncodingPair newValue = EncodingPair.ParseEncoding(rawEncoding, out error); if (!newValue.IsNull) { return(newValue.encoding); } if (mainForm.Dialogs != null) { mainForm.Dialogs.ShowInfo("Shell encoding", error + ""); } } return(mainForm.Settings.shellEncoding.Value.encoding ?? Encoding.UTF8); }
public string GetHelpText() { StringBuilder builder = new StringBuilder(); builder.AppendLine("# Settings properties"); builder.AppendLine(); builder.AppendLine("- First col legend: C - loads from config on start, T - from temp settings, [EMPTY] - only from config"); builder.AppendLine("- Store here in config: xml: <item name=\"name\" value=\"value\"/>"); builder.AppendLine("- Make it store in temp settings: xml: <item name=\"name\"/>"); builder.AppendLine("- [:<filter>] using example: xml: <item name=\"name:*.cs;*.txt\" value=\"value for cs/txt file\"/>"); builder.AppendLine("- Set property by command dialog: name value (autocomplete supported by `Tab` or `Ctrl+Space`)"); builder.AppendLine("- Clear if several nodes allowed: xml: <item name=\"name\" value=\"\"/>"); builder.AppendLine(); TextTable table = new TextTable().SetMaxColWidth(33); Properties.AddHeadTo(table); table.AddLine(); bool first = true; Properties.Property prev = null; foreach (Properties.Property property in properties) { if (!first) { table.NewRow(); } first = false; if (prev != null && prev.Type != property.Type) { if (prev.GetHelpTypeText(table)) { table.NewRow(); } } property.GetHelpText(this, table); prev = property; } builder.Append(table); builder.AppendLine(); builder.Append(EncodingPair.GetEncodingsText()); return(builder.ToString()); }
public Repl(string rawCommand, MainForm mainForm) : base(RemoveParameters(rawCommand), "REPL: " + GetShortName(rawCommand), SettingsMode.EditableNotFile) { tags = BufferTag.NeedCorrectRemoving; onAdd = OnAdd; onRemove = OnRemove; additionKeyMap = new KeyMap(); additionKeyMap.AddItem(new KeyItem(Keys.Enter, null, new KeyAction("&Edit\\REPL\\Enter command", OnEnter, null, false))); additionKeyMap.AddItem(new KeyItem(Keys.Back, null, new KeyAction("&Edit\\REPL\\Backspace", OnBackspace, null, false))); additionBeforeKeyMap = new KeyMap(); additionBeforeKeyMap.AddItem(new KeyItem(Keys.Home, null, new KeyAction("&Edit\\REPL\\Home", OnHome, null, false))); additionBeforeKeyMap.AddItem(new KeyItem(Keys.Shift | Keys.Home, null, new KeyAction("&Edit\\REPL\\Home with selection", OnHomeWithSelection, null, false))); { KeyAction action = new KeyAction("&Edit\\REPL\\Prev command", DoMoveUp, null, false); additionKeyMap.AddItem(new KeyItem(Keys.Up, null, action)); additionKeyMap.AddItem(new KeyItem(Keys.Control | Keys.P, null, action)); additionKeyMap.AddItem(new KeyItem(Keys.Control | Keys.K, null, action)); } { KeyAction action = new KeyAction("&Edit\\REPL\\Next command", DoMoveDown, null, false); additionKeyMap.AddItem(new KeyItem(Keys.Control | Keys.N, null, action)); additionKeyMap.AddItem(new KeyItem(Keys.Down, null, action)); additionKeyMap.AddItem(new KeyItem(Keys.Control | Keys.J, null, action)); } { KeyAction action = new KeyAction("&Edit\\REPL\\Autocomplete path", DoAutocomplete, null, false); additionKeyMap.AddItem(new KeyItem(Keys.Control | Keys.Space, null, action)); additionKeyMap.AddItem(new KeyItem(Keys.Tab, null, action)); } string parameters = RunShellCommand.CutParametersFromLeft(ref rawCommand); int index = -1; for (int i = 0; i < rawCommand.Length; ++i) { if (rawCommand[i] == '"') { for (++i; i < rawCommand.Length; ++i) { if (rawCommand[i] == '"') { break; } } } else if (rawCommand[i] == ' ') { index = i; break; } } arguments = index != -1 ? rawCommand.Substring(index + 1) : ""; command = index != -1 ? rawCommand.Substring(0, index) : rawCommand; Encoding encoding = RunShellCommand.GetEncoding(mainForm, parameters); encodingPair = new EncodingPair(encoding, false); customSyntax = RunShellCommand.TryGetSyntax(parameters); string invitation = RunShellCommand.TryGetParameter(parameters, 'i'); if (invitation == null) { invitation = "$"; } if (invitation != "") { invitation += " "; } this.invitation = invitation; Controller.onBeforePaint = OnBeforePaint; }
public override void Reset() { value = defaultValue; }
public EncodingProperty(string name, EncodingPair defaultValue) : base(name, Constraints.None) { this.defaultValue = defaultValue; }