private void listadecodigos(object sender, RoutedEventArgs e)
        {
            CodeWindow c = new CodeWindow();

            c.Show();
            this.Close();
        }
        private void Label_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            CodeWindow window = new CodeWindow();

            window.Show();
            Close();
        }
Esempio n. 3
0
    public static void CreateWindow()
    {
        // Create the window
        CodeWindow window = CreateInstance <CodeWindow>();

        // Set the window title
        window.SetTitle("Code Editor");

        // Set the window's minimum size and display it
        window.minSize = new Vector2(250, 250);
        window.Show();
    }
Esempio n. 4
0
 private void codeItem_Click(object sender, RoutedEventArgs e)
 {
     if (String.IsNullOrEmpty(intermediateCode))
     {
         run_Click(null, null);
     }
     if (String.IsNullOrEmpty(intermediateCode))
     {
         return;
     }
     codeWindow      = new CodeWindow();
     codeWindow.Text = intermediateCode;
     codeWindow.Show();
 }
Esempio n. 5
0
        private static void SoftwareCode(object sender, ExecutedRoutedEventArgs e)
        {
            MainWindow mainWindow = (MainWindow)sender;

            if (IsLicenseStateValid())
            {
                if (_codeWindow == null)
                {
                    _codeWindow = new CodeWindow(mainWindow);
                    _codeWindow.Show();
                }
                else
                {
                    _codeWindow.Close();
                    _codeWindow = new CodeWindow(mainWindow);
                    _codeWindow.Show();
                }
            }
        }
Esempio n. 6
0
    /// <summary>
    /// Draws the elements within the window
    /// </summary>
    private void OnGUI()
    {
        // Load the text area font from the 'Editor Default Resources' folder
        if (!font)
        {
            font = (Font)EditorGUIUtility.Load("Code Editor/Inconsolata-Regular.ttf");
        }

        // If we have opened a file, set the window's title to the file name
        if (fileLoaded)
        {
            if (!string.IsNullOrEmpty(pathOpened))
            {
                SetTitle(System.IO.Path.GetFileName(pathOpened));
            }
            else
            {
                SetTitle("Code Editor");
            }
        }

        GUILayout.BeginHorizontal();

        // Draw the buttons across the top of the window
        if (GUILayout.Button("New"))
        {
            GUI.FocusControl(null); // << Loose focus of the text area so the text can be changed properly
            fileLoaded = true;

            // We are editing a blank file which has not been saved anywhere so keep these blank:
            pathOpened = "";
            fileText   = "";
        }
        if (GUILayout.Button("Open"))
        {
            // Show Dialogue to open file
            string path = EditorUtility.OpenFilePanel("Open Text File", UnityEngine.Application.dataPath, "");
            try
            {
                // Try to open the file
                StreamReader fileReader = new StreamReader(path);
                fileText = fileReader.ReadToEnd();
                fileReader.Close();

                GUI.FocusControl(null); // << Loose focus of the text area so the text can be changed properly

                // Remeber the path and set the text area text
                pathOpened = path;
                fileLoaded = true;
            } catch
            {
            }
        }
        if (GUILayout.Button("Save"))
        {
            if (pathOpened == "")
            {
                // If it is a new file we don't know the path so we need to display a dialogue to get one (same as save as)
                SaveAsStuff(false);
            }
            else
            {
                // We have the path so save the file there
                StreamWriter fileWriter = new StreamWriter(pathOpened, false);
                fileWriter.Write(fileText);
                fileWriter.Close();
            }
            // Recompile scripts if we should
            if (compileAfterSaving)
            {
                AssetDatabase.Refresh();
            }
        }
        if (GUILayout.Button("Save As"))
        {
            // Open the file dialogue to do a save as (within SaveAsStuff function)
            SaveAsStuff(false);
            if (compileAfterSaving)
            {
                AssetDatabase.Refresh();
            }
        }
        if (GUILayout.Button("Close"))
        {
            // Close the window. CloseRequest() shows 'Save Changes?' dialogue if required
            CloseRequest();
            Close();
        }

        // Draw the settings to be changed across the top of the window
        GUILayout.FlexibleSpace();
        GUILayout.Label("Wrap Text:");
        wrapText = EditorGUILayout.Toggle(wrapText);
        GUILayout.Label("Compile On Save:");
        compileAfterSaving = EditorGUILayout.Toggle(compileAfterSaving);
        GUILayout.Label("Line Nums:");
        lineNums = EditorGUILayout.Toggle(lineNums);

        // Draw button to open another Code Editor Window
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("+"))
        {
            CodeWindow window = CreateInstance <CodeWindow>();
            window.Show();
        }
        GUILayout.EndHorizontal();

        // We want the text area within a scroll view. (Always showing vertical scrollbar makes calculating line heights for wrapped text easier)
        scrollRect = GUILayout.BeginScrollView(scrollRect, false, true);

        if (fileLoaded)
        {
            // Get the default editor style and change it. Replace font, change font size and enable word wrap (if requried)
            GUIStyle editorStyle = new GUIStyle(EditorStyles.textArea);
            editorStyle.font     = font;
            editorStyle.fontSize = 16;
            if (wrapText)
            {
                editorStyle.wordWrap = true;
            }
            else
            {
                editorStyle.wordWrap = false;
            }

            // Make the text area take up the space of the rest of the window
            editorStyle.stretchHeight = true;
            editorStyle.stretchWidth  = true;

            GUILayout.BeginHorizontal();

            // Draw line numbers if required
            if (lineNums)
            {
                GUILayout.BeginVertical(GUILayout.Width(30));

                // Get the editor label style and adjust it for line numbers. We don't want any margins. Set font and font size
                GUIStyle lineNum = new GUIStyle(EditorStyles.label);
                lineNum.margin   = new RectOffset(0, 0, 0, 0);
                lineNum.border   = new RectOffset(0, 0, 0, 0);
                lineNum.padding  = new RectOffset(0, 0, 0, 0);
                lineNum.overflow = new RectOffset(0, 0, 0, 0);
                lineNum.font     = font;
                lineNum.fontSize = 16;

                // This lines it up with the text area lines as the text area has padding
                GUILayout.Space(3);

                // Split up the text into lines and iterate through them
                string[] lines = fileText.Split(new string[1] {
                    "\n"
                }, System.StringSplitOptions.None);
                for (int i = 0; i < lines.Length; i++)
                {
                    // Here we use the lineNum text style to calculate the height of each line in the text area. So we temporarily enable word wrap if required
                    if (wrapText)
                    {
                        lineNum.wordWrap = true;
                    }
                    GUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();

                    // Calculate the height of each line within the text area so we know where to position the line numbers. This is required in case word wrap is enabled and a single line in the file takes up multiple lines in the text area.
                    float size = lineNum.lineHeight;
                    if (i < lines.Length)
                    {
                        GUIContent content = new GUIContent(lines[i]);
                        size = lineNum.CalcHeight(content, position.width - 58.0f);
                    }

                    // Diable word wrap for displaying the line numbers
                    lineNum.wordWrap = false;

                    // Display the line number. The height property makes sure the next line number is drawn in the correct place
                    GUILayout.Label((i + 1) + ":", lineNum, GUILayout.Height(Mathf.Max(size, editorStyle.lineHeight)));
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndVertical();
            }

            // Draw the text area for editing the file's text
            GUI.SetNextControlName("MainTextArea"); // << This is needed so changing the editor window focus works
            fileText = EditorGUILayout.TextArea(fileText, editorStyle);

            GUILayout.EndHorizontal();
        }
        GUILayout.EndScrollView();
        Repaint(); // << Redraw the window immediatley instead of waiting for it to be focused on
    }