void OnEnable()
        {
            hideFlags = HideFlags.HideAndDontSave;

            if (_compileEngine == null)
            {
                _compileEngine = RexCompileEngine.Instance;
            }

            if (_texts == null)
            {
                _texts = RexStaticTextCollection.Instance;
            }

            if (_macros == null)
            {
                _macros = RexMacroHandler.LoadMacros();
            }

            RexISM.Repaint     = Repaint;
            RexISM.DebugLog    = Debug.Log;
            RexISM.ExecuteCode = Execute;
            RexISM.Enter_NoInput();

            updateSkins = true;
            minSize     = new Vector2(450f, 350f);
            autoRepaintOnSceneChange = true;
            titleContent.text        = "REX";
            titleContent.tooltip     = "Runtime Expressions";
        }
        /// <summary>
        /// Display the <see cref="Macros"/> window at the given width using the given style.
        /// </summary>
        private void DisplayMacros()
        {
            showMacros = RexUIUtils.Toggle(showMacros, _texts["macros_header"]);

            if (showMacros)
            {
                // box begins
                EditorGUILayout.BeginVertical(slimBox);
                {
                    // scroll begins
                    scroll4 = EditorGUILayout.BeginScrollView(scroll4);
                    {
                        string deleted = null;
                        foreach (var macro in _macros)
                        {
                            EditorGUILayout.BeginHorizontal();
                            {
                                // Draw the RUN button
                                if (GUILayout.Button(_texts.GetText("macro_go", tooltipFormat: macro), GUILayout.Width(30)))
                                {
                                    // parse, compile & execute
                                    Execute(macro);
                                }

                                // Remove the macro if the X button is pressed
                                if (GUILayout.Button(_texts["macro_remove"], GUILayout.Width(20)))
                                {
                                    deleted = macro;
                                }

                                // if the label is pressed... then run this code..?
                                // TODO: Highlight this...
                                if (GUILayout.Button(_texts.GetText("select_macro", macro, macro), GUI.skin.label))
                                {
                                    RexISM.Code        = macro;
                                    RexISM.DisplayHelp = false;
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                        if (deleted != null)
                        {
                            _macros = RexMacroHandler.Remove(deleted);
                        }
                    }
                    EditorGUILayout.EndScrollView();
                }
                EditorGUILayout.EndVertical();
            }
        }
 /// <summary>
 /// Draws the selection dropdown for the given <see cref="HistoryItem"/>
 /// </summary>
 /// <param name="code"></param>
 /// <param name="deleted"></param>
 private void DisplayHistorySelectionToggle(string code, out bool deleted)
 {
     deleted = false;
     GUILayout.BeginHorizontal();
     {
         GUILayout.Space(10f);
         if (GUILayout.Button(_texts["history_item_run"], GUILayout.Height(16)))
         {
             Execute(code);
         }
         if (GUILayout.Button(_texts["history_item_macro"], GUILayout.Height(16)))
         {
             _macros = RexMacroHandler.Save(code);
         }
         if (GUILayout.Button(_texts["history_item_delete"], GUILayout.Height(16)))
         {
             deleted = true;
         }
     }
     GUILayout.EndHorizontal();
 }
Exemple #4
0
        public void MacroTest()
        {
            var before = RexMacroHandler.LoadMacros();

            foreach (var item in before)
            {
                RexMacroHandler.Remove(item);
            }

            Assert.IsEmpty(RexMacroHandler.LoadMacros());
            Assert.AreEqual(new[] { "Lol" }, RexMacroHandler.Save("Lol"));
            Assert.AreEqual(new[] { "Lol" }, RexMacroHandler.LoadMacros());
            Assert.IsEmpty(RexMacroHandler.Remove("Lol"));
            Assert.IsEmpty(RexMacroHandler.LoadMacros());
            Assert.AreEqual(new[] { "Lol1" }, RexMacroHandler.Save("Lol1"));
            Assert.AreEqual(new[] { "Lol1", "Lol2" }, RexMacroHandler.Save("Lol2"));
            Assert.AreEqual(new[] { "Lol1", "Lol2", "Lol3" }, RexMacroHandler.Save("Lol3"));
            Assert.AreEqual(new[] { "Lol1", "Lol2", "Lol3" }, RexMacroHandler.LoadMacros());

            foreach (var item in before)
            {
                RexMacroHandler.Save(item);
            }
        }