private void updateAnnotationSets(IIde ide) { _annotationSets.DropDownItems.Clear(); foreach (var kvp in _settings.MemoryAnnotations) { var setName = kvp.Key; var super = new ToolStripMenuItem(setName); _annotationSets.DropDownItems.Add(super); if (setName == _settings.LastMemoryAnnotationSet) { super.Checked = true; } super.DropDownItems.AddRange(Ut.NewArray( new ToolStripMenuItem("&Switch to this set", null, delegate { _settings.LastMemoryAnnotationSet = setName; updateAnnotationSets(ide); updateWatch(ide); }) { Checked = setName == _settings.LastMemoryAnnotationSet }, new ToolStripMenuItem("&Rename this set...", null, delegate { var newName = InputBox.GetLine("Enter new name for this annotation set:", setName, "Rename annotation set", "&OK", "&Cancel"); if (newName != null && newName != setName) { _settings.MemoryAnnotations[newName] = _settings.MemoryAnnotations[setName]; _settings.MemoryAnnotations.Remove(setName); if (_settings.LastMemoryAnnotationSet == setName) { _settings.LastMemoryAnnotationSet = newName; } updateAnnotationSets(ide); } }), new ToolStripMenuItem("&Delete this set", null, delegate { _settings.MemoryAnnotations.Remove(setName); _settings.LastMemoryAnnotationSet = _settings.MemoryAnnotations.Keys.FirstOrDefault("(default)"); if (!_settings.MemoryAnnotations.ContainsKey(_settings.LastMemoryAnnotationSet)) { _settings.MemoryAnnotations[_settings.LastMemoryAnnotationSet] = new Dictionary <Direction, Dictionary <PointAxial, string> >(); } updateAnnotationSets(ide); updateWatch(ide); }) )); } _annotationSets.DropDownItems.Add("-"); _annotationSets.DropDownItems.Add(new ToolStripMenuItem("&Create new annotation set...", null, delegate { createAnnotationSet(false, ide); })); _annotationSets.DropDownItems.Add(new ToolStripMenuItem("C&opy current annotation set...", null, delegate { createAnnotationSet(true, ide); })); }
/// <summary> /// Invoked by "Edit => Add a comment" or the relevant toolbar button. /// Allows the user to add a comment to the level list. /// </summary> private void addComment(object sender, EventArgs e) { if (!pnlLevelList.Visible) { toggleLevelList(sender, e); } string comment = InputBox.GetLine(Program.Tr.NewComment_Prompt, "", Program.Tr.NewComment_Title, Program.Tr.Dialogs_btnOK, Program.Tr.Dialogs_btnCancel); if (comment != null) { lstLevels.AddLevelListItem(comment); } }
private void insertByteArray(IIde ide) { string @default, selected = ide.GetSelectedText(); try { @default = ScliptingUtil.DecodeByteArray(selected).ToHex(); } catch { @default = ""; } var line = InputBox.GetLine("Type a byte array to insert (in hexdump format; two hexadecimal digits per byte):", @default, "Esoteric IDE", "&OK", "&Cancel"); if (line != null) { try { ide.InsertText(ScliptingUtil.EncodeByteArray(line.FromHex())); } catch { DlgMessage.Show("The text you entered is not valid hexadecimal. Please ensure that you enter an even number of characters 0-9/a-f.", "Esoteric IDE", DlgType.Error, "&OK"); } } }
public override ToolStripMenuItem[] CreateMenus(IIde ide) { var menuItems = new List <Tuple <ToolStripMenuItem, Func <bool> > >(); var ret = Ut.NewArray <ToolStripMenuItem>( new ToolStripMenuItem("&Insert", null, new ToolStripMenuItem("&Word from index", null, (_, __) => { var input = InputBox.GetLine("Index to look up?", caption: "Runic"); if (input == null || !int.TryParse(input, out var ix)) { return; } var word = WordDictionary.GetWord(ix); if (word == null) { DlgMessage.Show($"The specified index is out of range. Valid range is 0–{WordDictionary.List.Length - 1}.", "Runic", DlgType.Error); } else { ide.InsertText(word); } }), new ToolStripMenuItem("&Index from word", null, (_, __) => { var input = InputBox.GetLine("Word to look up?", caption: "Runic"); if (input == null) { return; } var index = WordDictionary.GetIndex(input.ToLowerInvariant().Trim()); if (index == -1) { DlgMessage.Show("The specified word is not in the dictionary.", "Runic", DlgType.Error); } else { ide.InsertText(index.ToString()); } }) ) ); return(ret); }
private void Compressor_Click(object sender, EventArgs e) { ToolStripMenuItem mi = (ToolStripMenuItem)sender; var compressorName = mi.Text.Replace("&", ""); Compressor compr = Program.GetCompressor(compressorName); var input = InputBox.GetLine("Please enter the arguments for this compressor:", Program.Settings.LastArgs.Get(compressorName, "")); if (input == null) { return; } Program.Settings.LastArgs[compressorName] = input; Program.Settings.Save(); var args = input.Split(' '); compr.Configure(args.Skip(1).Select(val => (RVariant)val).ToArray()); ThreadPool.QueueUserWorkItem(dummy => Program.CompressDecompressSingle(compr, args[0])); }
public override bool AskForValue(string parameterName, ref object value) { tryAgain: var result = InputBox.GetLine(Prompt, @default: value?.ToString() ?? "", caption: "Parameter"); if (result == null) { return(false); } if (!tryParse(result, ref value)) { var result2 = DlgMessage.Show("The value is not valid. Do you want to try again?", "Error", DlgType.Error, "&Yes", "&No"); if (result2 == 0) { goto tryAgain; } return(false); } return(true); }
/// <summary> /// Invoked if the user double-clicks in the level list. If the selected item /// is a comment, edits the comment. Otherwise opens the level for playing. /// </summary> private void doubleClick(object sender, EventArgs e) { // This does indeed happen - if you double-click an empty list for instance. if (SelectedIndex < 0) { return; } if (SelectedItem is SokobanLevel) { setActiveLevel(SelectedIndex, LevelListBoxState.Playing); } else { string newComment = InputBox.GetLine(Program.Tr.EditComment_Prompt, (string)SelectedItem, Program.Tr.EditComment_Title, Program.Tr.Dialogs_btnOK, Program.Tr.Dialogs_btnCancel); if (newComment != null) { Items[SelectedIndex] = newComment; _modified = true; } } }
private void insertInteger(IIde ide) { string @default, selected = ide.GetSelectedText(); try { if (selected.Length == 1 && selected[0] >= 0xbc00 && selected[0] <= 0xd7a3) { @default = (0xbbff - selected[0]).ToString(); } else { @default = new BigInteger(new byte[] { 0 }.Concat(ScliptingUtil.DecodeByteArray(selected)).Reverse().ToArray()).ToString(); } } catch { @default = "0"; } var line = InputBox.GetLine("Type an integer to insert (must be greater than −7077):", @default, "Esoteric IDE", "&OK", "&Cancel"); if (line != null) { BigInteger i; if (BigInteger.TryParse(line, out i) && (i >= -7076)) { if (i < 0) { ide.InsertText(((char)(0xbbff - i)).ToString()); } else { ide.InsertText(ScliptingUtil.EncodeByteArray(i.ToByteArray().Reverse().SkipWhile(b => b == 0).DefaultIfEmpty().ToArray())); } } else { DlgMessage.Show("The integer you typed is not a valid literal integer for Sclipting. Literal integers must be greater than −7077.", "Esoteric IDE", DlgType.Error, "&OK"); } } }
private void createAnnotationSet(bool copyFromCurrent, IIde ide) { string newName = copyFromCurrent ? _settings.LastMemoryAnnotationSet : null; while (true) { newName = InputBox.GetLine("Enter new name for this annotation set:", newName, "Create new annotation set", "&OK", "&Cancel"); if (newName == null) { break; } if (!_settings.MemoryAnnotations.ContainsKey(newName)) { _settings.MemoryAnnotations[newName] = copyFromCurrent ? _settings.MemoryAnnotations[_settings.LastMemoryAnnotationSet].ToDictionary(kvp => kvp.Key, kvp => new Dictionary <PointAxial, string>(kvp.Value)) : new Dictionary <Direction, Dictionary <PointAxial, string> >(); _settings.LastMemoryAnnotationSet = newName; updateAnnotationSets(ide); updateWatch(ide); return; } DlgMessage.Show("The specified annotation set name already exists. Annotation set names must be unique.", "Error", DlgType.Error); } }
private void insertString(IIde ide) { string @default, selected = ide.GetSelectedText(); try { if (selected.Length == 1 && selected[0] >= 0xbc00 && selected[0] <= 0xd7a3) { @default = (0xbbff - selected[0]).ToString(); } else { @default = ScliptingUtil.DecodeByteArray(selected).FromUtf8().CLiteralEscape(); } } catch { @default = "\\n"; } var line = InputBox.GetLine("Type a string to insert (in C-escaped format; backslashes must be escaped):", @default, "Esoteric IDE", "&OK", "&Cancel"); if (line != null) { try { ide.InsertText(ScliptingUtil.EncodeByteArray(line.CLiteralUnescape().ToUtf8())); } catch { DlgMessage.Show("The string you typed is not a valid C-escaped string. Please ensure that your backslashes are escaped.", "Esoteric IDE", DlgType.Error, "&OK"); } } }
public override ToolStripMenuItem[] CreateMenus(IIde ide) { var inputModes = EnumStrong.GetValues <InputMode>(); var inputModeItems = new ToolStripMenuItem[inputModes.Length]; var setInputMode = Ut.Lambda((InputMode mode) => { _settings.InputMode = mode; for (int i = 0; i < inputModes.Length; i++) { inputModeItems[i].Checked = (mode == inputModes[i]); } }); var ret = Ut.NewArray( new ToolStripMenuItem("&Memory visualization", null, Ut.NewArray( // Unused mnemonics: cdefhijkmqruwxy new ToolStripMenuItem("&Background color...", null, delegate { color(ide.GetEnvironment(), _settings.MemoryBackgroundColor, c => { _settings.MemoryBackgroundColor = c; }); }), new ToolStripMenuItem("Grid color (&zeros)...", null, delegate { color(ide.GetEnvironment(), _settings.MemoryGridZeroColor, c => { _settings.MemoryGridZeroColor = c; }); }), new ToolStripMenuItem("&Grid color (non-zeros)...", null, delegate { color(ide.GetEnvironment(), _settings.MemoryGridNonZeroColor, c => { _settings.MemoryGridNonZeroColor = c; }); }), new ToolStripMenuItem("&Pointer color...", null, delegate { color(ide.GetEnvironment(), _settings.MemoryPointerColor, c => { _settings.MemoryPointerColor = c; }); }), new ToolStripMenuItem("&Value font...", null, delegate { font(ide.GetEnvironment(), _settings.MemoryValueFont, Color.CornflowerBlue, f => { _settings.MemoryValueFont = f; _valueColorItem.Enabled = true; }); }), (_valueColorItem = new ToolStripMenuItem("Va&lue color...", null, delegate { color(ide.GetEnvironment(), _settings.MemoryValueFont.Color, c => { _settings.MemoryValueFont = _settings.MemoryValueFont.SetColor(c); }); }) { Enabled = _settings.MemoryValueFont != null }), new ToolStripMenuItem("Ann&otation font...", null, delegate { font(ide.GetEnvironment(), _settings.MemoryAnnotationFont, Color.ForestGreen, f => { _settings.MemoryAnnotationFont = f; _annotationColorItem.Enabled = true; }); }), (_annotationColorItem = new ToolStripMenuItem("Anno&tation color...", null, delegate { color(ide.GetEnvironment(), _settings.MemoryAnnotationFont.Color, c => { _settings.MemoryAnnotationFont = _settings.MemoryAnnotationFont.SetColor(c); }); }) { Enabled = _settings.MemoryAnnotationFont != null }), new ToolStripMenuItem("&Annotate current edge...", null, checkDebugging(ide, env => { var newAnnotation = InputBox.GetLine("Enter annotation:", env.GetCurrentAnnotation(), "Annotate edge", "&OK", "&Cancel"); if (newAnnotation != null) { env.Annotate(newAnnotation); env.UpdateWatch(); } })), (_annotationSets = new ToolStripMenuItem("A&nnotation sets")), new ToolStripMenuItem("&Save memory as PNG...", null, checkDebugging(ide, env => { using (var dlg = new SaveFileDialog { DefaultExt = "png", Filter = "PNG files (*.png)|*.png", OverwritePrompt = true, Title = "Save memory visualization to file" }) if (dlg.ShowDialog() == DialogResult.OK) { env.SaveMemoryVisualization(dlg.FileName); } })))), new ToolStripMenuItem("&Source", null, Ut.NewArray( new ToolStripMenuItem("Generate &blank source...", null, delegate { string inputStr = "10"; while (true) { inputStr = InputBox.GetLine("Enter size of hexagon:", inputStr, "Generate blank source", "&OK", "&Cancel"); if (inputStr == null) { return; } int input; if (int.TryParse(inputStr, out input)) { ide.ReplaceSource(Grid.Parse(new string('.', 3 * input * (input - 1) + 1)).ToString()); return; } DlgMessage.Show("Please enter an integer value.", "Error", DlgType.Error); } }), new ToolStripMenuItem("&Layout source", null, delegate { ide.ReplaceSource(Grid.Parse(ide.GetSource()).ToString()); }), new ToolStripMenuItem("&Minify source", null, delegate { ide.ReplaceSource(Regex.Replace(ide.GetSource(), @"[\s`]", "").TrimEnd('.')); }))), new ToolStripMenuItem("&Input semantics", null, Ut.NewArray( (inputModeItems[0] = new ToolStripMenuItem("Encode input as UTF-&8", null, (_, __) => setInputMode(InputMode.Utf8))), (inputModeItems[1] = new ToolStripMenuItem("Encode input as UTF-1&6 (little endian)", null, (_, __) => setInputMode(InputMode.Utf16))), (inputModeItems[2] = new ToolStripMenuItem("Input string is a list of &bytes", null, (_, __) => setInputMode(InputMode.Numbers)))))); updateAnnotationSets(ide); setInputMode(_settings.InputMode); return(ret); }
private void input(object _, EventArgs __) { _input = InputBox.GetLine("Please type the input to the program:", _input?.UnifyLineEndings(), "Esoteric IDE", "&OK", "&Cancel", useMultilineBox: true)?.Replace("\r", "") ?? _input; }