Esempio n. 1
0
        private static void updateWatch(IIde ide)
        {
            var env = ide.GetEnvironment() as HexagonyEnv;

            if (env != null)
            {
                env.UpdateWatch();
            }
        }
Esempio n. 2
0
 private EventHandler checkDebugging(IIde ide, Action <HexagonyEnv> action)
 {
     return((_, __) =>
     {
         var env = ide.GetEnvironment() as HexagonyEnv;
         if (env == null || env.State != ExecutionState.Debugging)
         {
             DlgMessage.Show("Program must be running but stopped in the debugger.", "Error", DlgType.Error);
         }
         else
         {
             action(env);
         }
     });
 }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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;
        }
Esempio n. 5
0
 private EventHandler checkDebugging(IIde ide, Action<HexagonyEnv> action)
 {
     return (_, __) =>
     {
         var env = ide.GetEnvironment() as HexagonyEnv;
         if (env == null || env.State != ExecutionState.Debugging)
             DlgMessage.Show("Program must be running but stopped in the debugger.", "Error", DlgType.Error);
         else
             action(env);
     };
 }
Esempio n. 6
0
 private static void updateWatch(IIde ide)
 {
     var env = ide.GetEnvironment() as HexagonyEnv;
     if (env != null)
         env.UpdateWatch();
 }