Beispiel #1
0
        protected void KeepCursorScrolledInView()
        {
            // It's utterly ridiculous that Unity's TextArea widget doesn't
            // just do this automatically.  It's basic behavior for a scrolling
            // text widget that when the text cursor moves out of the viewport you
            // scroll to keep it in view.  Oh well, have to do it manually:
            //
            // NOTE: This method is what is interferring with the scrollbar's ability
            // to scroll with the mouse - this routine is locking the scrollbar
            // to only be allowed to move as far as the cursor is still in view.
            // Fixing that would take a bit of work.
            //

            UnityEngine.TextEditor editor = GetWidgetController();
            Vector2 pos          = editor.graphicalCursorPos;
            float   usableHeight = innerCoords.height - 2.5f * FONT_HEIGHT;

            if (pos.y < scrollPosition.y)
            {
                scrollPosition.y = pos.y;
            }
            else if (pos.y > scrollPosition.y + usableHeight)
            {
                scrollPosition.y = pos.y - usableHeight;
            }
        }
Beispiel #2
0
 public void OnGUI()
 {
     EditorGUILayout.LabelField(new GUIContent("Insert Thai message here."));
     EditorGUI.BeginChangeCheck();
     message = EditorGUILayout.TextArea(message);
     if (EditorGUI.EndChangeCheck())
     {
         if (!string.IsNullOrEmpty(message))
         {
             thaiMessage = ThaiFontAdjuster.Adjust(message);
         }
         else
         {
             thaiMessage = "";
         }
     }
     EditorGUILayout.LabelField(new GUIContent("Output."));
     EditorGUILayout.TextArea(thaiMessage);
     if (GUILayout.Button("Copy"))
     {
         UnityEngine.TextEditor t = new UnityEngine.TextEditor();
         t.text = thaiMessage;
         t.SelectAll();
         t.Copy();
     }
 }
 /// <summary>
 /// Copies the string to the OS buffer.
 /// </summary>
 /// <param name="copyString">String to copy.</param>
 public static void CopyStringToBuffer(string copyString)
 {
     TextEditor te = new TextEditor();
     te.text = copyString;
     te.SelectAll();
     te.Copy();
 }
 public void CopyToClipboard(string value)
 {
   TextEditor textEditor = new TextEditor();
   textEditor.text = value;
   textEditor.SelectAll();
   textEditor.Copy();
 }
Beispiel #5
0
        /// <summary>
        ///     Draws a button that when clicked copies game and add-on details to the clipboard.
        /// </summary>
        private static void CopyToClipboardButton()
        {
            // Draw a GUI button.
            if (GUILayout.Button("Copy to Clipboard"))
            {
                // Create a text string and populate the first line with the game details.
                string copyText = "KSP: " + VersionObject.KspVersion + " - " +
                                  "Unity: " + Application.unityVersion + " - " +
                                  "OS: " + SystemInfo.operatingSystem;

                // Iterate over all the loaded add-ons.
                for (int i = 0; i < AddonLibrary.LoadedAddons.Count; ++i)
                {
                    Addon addon = AddonLibrary.LoadedAddons[i];
                    if (addon != null)
                    {
                        // Append the add-on details to the clipboard string.
                        copyText = copyText + Environment.NewLine + addon.Name + " - " + addon.LocalVersionString;
                    }
                }

                // Create a text editor for use with copying the copy text onto the clipboard.
                TextEditor textEditor = new TextEditor
                {
                    // Set the content of the text editor to the copy text.
                    content = new GUIContent(copyText)
                };

                // Copy text to the clipboard.
                textEditor.SelectAll();
                textEditor.Copy();
            }
        }
Beispiel #6
0
        public static string GetText()
        {
            var ed = new TextEditor();
            ed.Paste();

            return ed.content.text;
        }
 internal static void CopyTextToClipboard(String CopyText)
 {
     TextEditor t = new TextEditor();
     t.content = new GUIContent(CopyText);
     t.SelectAll();
     t.Copy();
 }
Beispiel #8
0
    public static string GetTextFromClipboard()
    {
        var te = new UnityEngine.TextEditor();

        te.Paste();
        return(te.text);
    }
Beispiel #9
0
    public static void PutTextToClipboard(string str)
    {
        var te = new UnityEngine.TextEditor();

        te.text = str;
        te.SelectAll();
        te.Copy();
    }
Beispiel #10
0
 public void CopyToClipboard(string value)
 {
     TextEditor editor = new TextEditor {
         content = new GUIContent(value)
     };
     editor.SelectAll();
     editor.Copy();
 }
 public void CopyToClipboard(string value)
 {
     TextEditor editor = new TextEditor {
         text = value
     };
     editor.SelectAll();
     editor.Copy();
 }
Beispiel #12
0
        public static void SetText(string text)
        {
            if (string.IsNullOrEmpty(text)) return;

            var ed = new TextEditor();
            ed.content = new GUIContent(text);
            ed.SelectAll();
            ed.Copy();
        }
        private void CopyText(string pText)
        {
            TextEditor editor = new TextEditor();

            editor.content = new GUIContent(pText);

            editor.SelectAll();
            editor.Copy();
        }
        public void CopyText()
        {
            var copyString = "TestStrrrring";
            var expectedString = copyString;
            Utilities.CopyStringToBuffer(copyString);

            var editor = new TextEditor();
            editor.Paste();
            Assert.AreEqual(expectedString, editor.text);
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="textField"></param>
 /// <param name="value"></param>
 public static void OnCopy(InputTextField textField, string value)
 {
     TextEditor te = new TextEditor();
     #if UNITY_5_3_OR_NEWER
     te.text = value;
     #else
     te.content = new GUIContent(value);
     #endif
     te.OnFocus();
     te.Copy();
 }
Beispiel #16
0
 static void OnCopy(EventContext context)
 {
     TextEditor te = new TextEditor();
     #if (UNITY_5_3 || UNITY_5_4)
     te.text = (string)context.data;
     #else
     te.content = new GUIContent((string)context.data);
     #endif
     te.OnFocus();
     te.Copy();
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="textField"></param>
 public static void OnPaste(InputTextField textField)
 {
     TextEditor te = new TextEditor();
     te.Paste();
     #if UNITY_5_3_OR_NEWER
     string value = te.text;
     #else
     string value = te.content.text;
     #endif
     if (!string.IsNullOrEmpty(value))
         textField.ReplaceSelection(value);
 }
Beispiel #18
0
 static void OnPaste(EventContext context)
 {
     TextField target = (TextField)context.data;
     TextEditor te = new TextEditor();
     te.Paste();
     #if (UNITY_5_3 || UNITY_5_4)
     string value = te.text;
     #else
     string value = te.content.text;
     #endif
     if (!string.IsNullOrEmpty(value))
         target.ReplaceSelection(value);
 }
		public static void CopyTextToClipboard(string text)
		{
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER
			var textEditor = new TextEditor {content = new GUIContent(text)};
			textEditor.SelectAll();
			textEditor.Copy();
#elif UNITY_IOS 
			_opencodingConsoleCopyToClipboard(text);
#elif UNITY_ANDROID
			AndroidJavaClass androidJavaClass = new AndroidJavaClass("net.opencoding.console.NativeMethods");
			androidJavaClass.CallStatic("copyToClipboard", text);
#else
			Debug.LogError("Copy and paste isn't supported on this platform currently. Please contact [email protected] and I'll do my best to support it!");
#endif
		}
Beispiel #20
0
        protected void DoPageDown()
        {
            UnityEngine.TextEditor editor = GetWidgetController();

            // Seems to be no way to move more than one line at
            // a time - so have to do this:
            int pos  = Math.Min(editor.pos, contents.Length - 1);
            int rows = ((int)innerCoords.height) / FONT_HEIGHT;

            while (rows > 0 && pos < contents.Length)
            {
                if (contents[pos] == '\n')
                {
                    rows--;
                }
                pos++;
                editor.MoveRight(); // there is a MoveDown but it doesn't work.
            }
        }
 private string GetClipboard()
 {
     TextEditor te = new TextEditor();
     te.Paste();
     return te.content.text;
 }
		/// <summary>Pastes the text from the clipboard.</summary>
		public static string Paste(){
			TextEditor editor=new TextEditor();
			editor.content.text="";
			editor.Paste();
			return editor.content.text;
		}
Beispiel #23
0
		public void DblClickSnap(TextEditor.DblClickSnapping snapping)
		{
			this.m_DblClickSnap = snapping;
		}
// ReSharper disable UnusedMember.Local
        void OnGUI()
// ReSharper restore UnusedMember.Local
        {
            if (_doFocusOut)
            {
                _doFocusOut = false;
                GUIUtility.keyboardControl = 0;
            }

            EditorWindowContentWrapper.Start();

            if (null == PanelRenderer.ChromeStyle)
                PanelRenderer.ChromeStyle = StyleCache.Instance.PanelChromeSquared;

            PanelRenderer.RenderStart(GuiContentCache.Instance.PersistenceDebuggerPanelTitle, true);

            PanelContentWrapper.Start();

            if (PanelRenderer.ClickedTools.Count > 0)
            {
                if (PanelRenderer.ClickedTools.Contains("options"))
                {
                    PanelRenderer.ClickedTools.Remove("options");
                }
                ShowHelp = PanelRenderer.ClickedTools.Contains("help");
            }
            else
            {
                ShowHelp = false;
            }

            if (ShowHelp)
            {
                EditorGUILayout.HelpBox(Help.PersistenceDebugWindow, MessageType.Info, true);
            }

            EditorGUILayout.BeginHorizontal(StyleCache.Instance.Toolbar, GUILayout.Height(35));

            #region Refresh

            EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(false));
            GUILayout.FlexibleSpace();

            if (GUILayout.Button(GuiContentCache.Instance.Refresh, StyleCache.Instance.Button,
                GUILayout.ExpandWidth(false), GUILayout.Height(30)))
            {
                GUIUtility.keyboardControl = 0;
                ProcessInfo();
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();

            #endregion

            #region Abandon chages

            EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(false));
            GUILayout.FlexibleSpace();

            if (GUILayout.Button(GuiContentCache.Instance.AbandonChanges, StyleCache.Instance.Button,
                GUILayout.ExpandWidth(false), GUILayout.Height(30)))
            {
                PersistenceManager.Instance.AbandonChanges();
                HierarchyChangeProcessor.Instance.Reset();
                ProcessInfo();
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();

            #endregion

            #region Copy

            EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(false));
            GUILayout.FlexibleSpace();

            if (GUILayout.Button(GuiContentCache.Instance.CopyToClipboard, StyleCache.Instance.Button,
                GUILayout.ExpandWidth(false), GUILayout.Height(30)))
            {
                GUIUtility.keyboardControl = 0;
                TextEditor te = new TextEditor {content = new GUIContent(_text)};
                te.SelectAll();
                te.Copy();
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();

            #endregion

            GUILayout.FlexibleSpace();

            #region Auto-update

            EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(false));
            GUILayout.FlexibleSpace();

            bool oldAutoUpdate = GUILayout.Toggle(EditorSettings.PersistenceWindowAutoUpdate,
                EditorSettings.PersistenceWindowAutoUpdate ? GuiContentCache.Instance.AutoUpdateOn : GuiContentCache.Instance.AutoUpdateOff, 
                StyleCache.Instance.Toggle,
                GUILayout.ExpandWidth(false), GUILayout.Height(30));

            if (EditorSettings.PersistenceWindowAutoUpdate != oldAutoUpdate)
            {
                GUIUtility.keyboardControl = 0;
                EditorSettings.PersistenceWindowAutoUpdate = oldAutoUpdate;
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();

            #endregion

            #region Write to log

            EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(false));
            GUILayout.FlexibleSpace();

            bool oldWriteToLog = GUILayout.Toggle(EditorSettings.PersistenceWindowWriteToLog,
                GuiContentCache.Instance.WriteToLog, StyleCache.Instance.GreenToggle,
                GUILayout.ExpandWidth(false), GUILayout.Height(30));

            if (EditorSettings.PersistenceWindowWriteToLog != oldWriteToLog)
            {
                GUIUtility.keyboardControl = 0;
                EditorSettings.PersistenceWindowWriteToLog = oldWriteToLog;
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();

            #endregion
            
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(1);

            _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
            //GUILayout.Label(_text, StyleCache.Instance.NormalLabel, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));

            GUI.SetNextControlName(TextAreaControlName);
            _textToDisplay = EditorGUILayout.TextArea(_textToDisplay, StyleCache.Instance.RichTextLabel, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));

            bool isInFocus = GUI.GetNameOfFocusedControl() == TextAreaControlName;
            _textToDisplay = isInFocus ? _text : _richText;
            
            GUILayout.EndScrollView();
            
            RenderStatus(
                EditorSettings.WatchChanges ? 
                    (EditorApplication.isPlaying ? "Monitoring..." : "Will monitor in play mode.") : 
                    "Not monitoring.", 
                EditorSettings.WatchChanges && EditorApplication.isPlaying
            );

            PanelContentWrapper.End();

            PanelRenderer.RenderEnd();

            //GUILayout.Space(3);
            EditorWindowContentWrapper.End();
        }
Beispiel #25
0
		private static void HandleTextFieldEventForDesktop(Rect position, int id, GUIContent content, bool multiline, int maxLength, GUIStyle style, TextEditor editor)
		{
			Event current = Event.current;
			bool flag = false;
			switch (current.type)
			{
			case EventType.MouseDown:
				if (position.Contains(current.mousePosition))
				{
					GUIUtility.hotControl = id;
					GUIUtility.keyboardControl = id;
					editor.m_HasFocus = true;
					editor.MoveCursorToPosition(Event.current.mousePosition);
					if (Event.current.clickCount == 2 && GUI.skin.settings.doubleClickSelectsWord)
					{
						editor.SelectCurrentWord();
						editor.DblClickSnap(TextEditor.DblClickSnapping.WORDS);
						editor.MouseDragSelectsWholeWords(true);
					}
					if (Event.current.clickCount == 3 && GUI.skin.settings.tripleClickSelectsLine)
					{
						editor.SelectCurrentParagraph();
						editor.MouseDragSelectsWholeWords(true);
						editor.DblClickSnap(TextEditor.DblClickSnapping.PARAGRAPHS);
					}
					current.Use();
				}
				break;
			case EventType.MouseUp:
				if (GUIUtility.hotControl == id)
				{
					editor.MouseDragSelectsWholeWords(false);
					GUIUtility.hotControl = 0;
					current.Use();
				}
				break;
			case EventType.MouseDrag:
				if (GUIUtility.hotControl == id)
				{
					if (current.shift)
					{
						editor.MoveCursorToPosition(Event.current.mousePosition);
					}
					else
					{
						editor.SelectToPosition(Event.current.mousePosition);
					}
					current.Use();
				}
				break;
			case EventType.KeyDown:
				if (GUIUtility.keyboardControl != id)
				{
					return;
				}
				if (editor.HandleKeyEvent(current))
				{
					current.Use();
					flag = true;
					content.text = editor.content.text;
				}
				else
				{
					if (current.keyCode == KeyCode.Tab || current.character == '\t')
					{
						return;
					}
					char character = current.character;
					if (character == '\n' && !multiline && !current.alt)
					{
						return;
					}
					Font font = style.font;
					if (!font)
					{
						font = GUI.skin.font;
					}
					if (font.HasCharacter(character) || character == '\n')
					{
						editor.Insert(character);
						flag = true;
					}
					else
					{
						if (character == '\0')
						{
							if (Input.compositionString.Length > 0)
							{
								editor.ReplaceSelection(string.Empty);
								flag = true;
							}
							current.Use();
						}
					}
				}
				break;
			case EventType.Repaint:
				if (GUIUtility.keyboardControl != id)
				{
					style.Draw(position, content, id, false);
				}
				else
				{
					editor.DrawCursor(content.text);
				}
				break;
			}
			if (GUIUtility.keyboardControl == id)
			{
				GUIUtility.textFieldInput = true;
			}
			if (flag)
			{
				GUI.changed = true;
				content.text = editor.content.text;
				if (maxLength >= 0 && content.text.Length > maxLength)
				{
					content.text = content.text.Substring(0, maxLength);
				}
				current.Use();
			}
		}
Beispiel #26
0
		private static void MapKey(string key, TextEditor.TextEditOp action)
		{
			TextEditor.s_Keyactions[Event.KeyboardEvent(key)] = action;
		}
        private void BlockInfo(int id)
        {
            BlockBehaviour bb = block.GetComponent<BlockBehaviour>();
            GUILayout.Label("Name: " + block.name);
            GUILayout.Label("ID: " + bb.GetBlockID());
            GUILayout.Label("GUID: " + bb.Guid);
            GUILayout.Space(25.0f);

            if (GUILayout.Button(new GUIContent("Copy to Clipboard", "Copies the GUID to the Clipboard")))
            {
                TextEditor te = new TextEditor {content = new GUIContent(bb.Guid.ToString())};
                te.SelectAll();
                te.Copy();
            }

            if (GUILayout.Button(new GUIContent("Close", "Closes the Block Info Window")))
            {
                _bInfo = false;
            }
            LastTooltip = GUI.tooltip;
            GUI.DragWindow();
        }
 public string PasteFromClipboard()
 {
   TextEditor textEditor = new TextEditor();
   textEditor.Paste();
   return textEditor.text;
 }
Beispiel #29
0
// ReSharper disable UnusedMember.Local
        void OnGUI()
// ReSharper restore UnusedMember.Local
        {
            if (_doFocusOut)
            {
                _doFocusOut = false;
                GUIUtility.keyboardControl = 0;
            }

            EditorWindowContentWrapper.Start();

            if (null == PanelRenderer.ChromeStyle)
                PanelRenderer.ChromeStyle = StyleCache.Instance.PanelChromeSquared;

            PanelRenderer.RenderStart(GuiContentCache.Instance.HierarchyDebuggerPanelTitle, true);

            PanelContentWrapper.Start();

            if (PanelRenderer.ClickedTools.Count > 0)
            {
                if (PanelRenderer.ClickedTools.Contains("options"))
                {
                    PanelRenderer.ClickedTools.Remove("options");
                }
                ShowHelp = PanelRenderer.ClickedTools.Contains("help");
            }
            else
            {
                ShowHelp = false;
            }

            if (ShowHelp)
            {
                EditorGUILayout.HelpBox(Help.HierarchyDebugWindow, MessageType.Info, true);
            }

            EditorGUILayout.BeginHorizontal(StyleCache.Instance.Toolbar, GUILayout.Height(35));

            #region Refresh

            EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(false));
            GUILayout.FlexibleSpace();

            if (GUILayout.Button(GuiContentCache.Instance.Refresh, StyleCache.Instance.Button,
                GUILayout.ExpandWidth(false), GUILayout.Height(30)))
            {
                GUIUtility.keyboardControl = 0;
                ProcessInfo();
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();

            #endregion

            #region Fix

            EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(false));
            GUILayout.FlexibleSpace();

            /*bool oldEnabled = GUI.enabled;
            GUI.enabled = !Application.isPlaying;*/
            if (GUILayout.Button(GuiContentCache.Instance.FixHierarchy, StyleCache.Instance.GreenToggle,
                GUILayout.ExpandWidth(false), GUILayout.Height(30)))
            {
                var text =
                    @"eDriven will look for adapters present in the hierarchy but not listed in any of the order lists, and add them as list children.

It will also remove adapters not present in the hierarchy from all of the order lists.";

                if (EditorApplication.isPlaying)
                {
                    text += @"

Note: The play mode will be stopped in order to fix the hierarchy.";
                }

                text += @"

Are you sure you want to do this?";

                if (EditorUtility.DisplayDialog("Fix hierarchy?", text, "OK", "Cancel"))
                {
                    if (EditorApplication.isPlaying)
                    {
                        // 1. delay fixing to after the stop
                        EditorState.ShouldFixHierarchyAfterStop = true;
                        // 2. stop the play mode
                        EditorApplication.isPlaying = false;
                    }
                    else // fix immediatelly
                    {
                        FixHierarchy();
                    }
                }
            }
            /*GUI.enabled = oldEnabled;*/

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();

            #endregion

            #region Copy

            EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(false));
            GUILayout.FlexibleSpace();

            if (GUILayout.Button(GuiContentCache.Instance.CopyToClipboard, StyleCache.Instance.Button,
                GUILayout.ExpandWidth(false), GUILayout.Height(30)))
            {
                GUIUtility.keyboardControl = 0;
                TextEditor te = new TextEditor {content = new GUIContent(_description)};
                te.SelectAll();
                te.Copy();
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();

            #endregion

            GUILayout.FlexibleSpace();

            #region Auto-update

            EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(false));
            GUILayout.FlexibleSpace();

            bool oldAutoUpdate = GUILayout.Toggle(EditorSettings.HierarchyWindowAutoUpdate,
                EditorSettings.HierarchyWindowAutoUpdate ? GuiContentCache.Instance.AutoUpdateOn : GuiContentCache.Instance.AutoUpdateOff,
                StyleCache.Instance.Toggle,
                GUILayout.ExpandWidth(false), GUILayout.Height(30));

            if (EditorSettings.HierarchyWindowAutoUpdate != oldAutoUpdate)
            {
                GUIUtility.keyboardControl = 0;
                EditorSettings.HierarchyWindowAutoUpdate = oldAutoUpdate;
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();

            #endregion

            #region Write to log

            EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(false));
            GUILayout.FlexibleSpace();

            bool oldWriteToLog = GUILayout.Toggle(EditorSettings.HierarchyWindowWriteToLog,
                GuiContentCache.Instance.WriteToLog, StyleCache.Instance.GreenToggle,
                GUILayout.ExpandWidth(false), GUILayout.Height(30));

            if (EditorSettings.HierarchyWindowWriteToLog != oldWriteToLog)
            {
                GUIUtility.keyboardControl = 0;
                EditorSettings.HierarchyWindowWriteToLog = oldWriteToLog;
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();

            #endregion

            EditorGUILayout.EndHorizontal();

            GUILayout.Space(1);

            _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
            //GUILayout.Label(HierarchyState.Instance.State, StyleCache.Instance.NormalLabel, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
            //EditorGUILayout.TextArea("<color=#00ff00>miki</color>" + _description, StyleCache.Instance.RichTextLabel, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
            EditorGUILayout.TextArea(_descriptionRich, StyleCache.Instance.RichTextLabel, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
            GUILayout.EndScrollView();

            PanelContentWrapper.End();

            PanelRenderer.RenderEnd();

            //GUILayout.Space(3);
            EditorWindowContentWrapper.End();
        }
        private void CopyToClipboard()
        {
            if (!GUILayout.Button("Copy to Clipboard"))
            {
                return;
            }

            var kspVersion = AddonInfo.ActualKspVersion.ToString();
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                if (IntPtr.Size == 8)
                {
                    kspVersion += " (Win64)";
                }
                else
                {
                    kspVersion += " (Win32)";
                }
            }
            else
            {
                kspVersion += " (" + Environment.OSVersion.Platform + ")";
            }

            var copyText = "KSP: " + kspVersion +
                           " - Unity: " + Application.unityVersion +
                           " - OS: " + SystemInfo.operatingSystem +
                           this.addonList;

            var textEditor = new TextEditor
            {
                content = new GUIContent(copyText)
            };
            textEditor.SelectAll();
            textEditor.Copy();
        }
Beispiel #31
0
        private static void HandleTextFieldEventForTouchscreen(Rect position, int id, GUIContent content, bool multiline, int maxLength, GUIStyle style, string secureText, char maskChar, TextEditor editor)
        {
            Event current = Event.current;
            switch (current.type)
            {
                case EventType.MouseDown:
                    if (position.Contains(current.mousePosition))
                    {
                        GUIUtility.hotControl = id;
                        if ((s_HotTextField != -1) && (s_HotTextField != id))
                        {
                            TextEditor stateObject = (TextEditor) GUIUtility.GetStateObject(typeof(TextEditor), s_HotTextField);
                            stateObject.keyboardOnScreen = null;
                        }
                        s_HotTextField = id;
                        if (GUIUtility.keyboardControl != id)
                        {
                            GUIUtility.keyboardControl = id;
                        }
                        editor.keyboardOnScreen = TouchScreenKeyboard.Open((secureText == null) ? content.text : secureText, TouchScreenKeyboardType.Default, true, multiline, secureText != null);
                        current.Use();
                    }
                    break;

                case EventType.Repaint:
                {
                    if (editor.keyboardOnScreen != null)
                    {
                        content.text = editor.keyboardOnScreen.text;
                        if ((maxLength >= 0) && (content.text.Length > maxLength))
                        {
                            content.text = content.text.Substring(0, maxLength);
                        }
                        if (editor.keyboardOnScreen.done)
                        {
                            editor.keyboardOnScreen = null;
                            changed = true;
                        }
                    }
                    string text = content.text;
                    if (secureText != null)
                    {
                        content.text = PasswordFieldGetStrToShow(text, maskChar);
                    }
                    style.Draw(position, content, id, false);
                    content.text = text;
                    break;
                }
            }
        }
 public void LatLonClipbardCopy()
 {
     if (GUILayout.Button("Copy Lat/Lon/Alt to Clipboard"))
     {
         TextEditor te = new TextEditor();
         string result = "latitude =  " + vesselState.latitude.ToString("F6") + "\nlongitude = " + vesselState.longitude.ToString("F6") +
                         "\naltitude = " + vessel.altitude.ToString("F2") + "\n";
         te.content = new GUIContent(result);
         te.SelectAll();
         te.Copy();
     }
 }
Beispiel #33
0
		private void Window (int id)
		{
			if (cfgWinData == false) {
				cfgWinData = true;
				newUseBlizzyToolbar = thisCI.configuration.useBlizzyToolbar;
				//newShowDrives = CI.configuration.showDrives;
				//newCkanExecPath = CI.configuration.ckanExecPath;
				craftURL = "";
				m_textPath = "";
				saveInSandbox = false;
				overwriteExisting = false;
				m_textPath = thisCI.configuration.lastImportDir;
				//		#if EXPORT
				//		for (int i = 0; i < actionGroups.Length; i++)
				//			actionGroups [i] = "";
				//		lastSelectedCraft = -1;
				//		#endif

//				byte[] colorPickerFileData = System.IO.File.ReadAllBytes (FileOperations.ROOT_PATH + "GameData/CraftImport/Textures/colorpicker_texture.jpg");

				byte[] colorPickerFileData = System.IO.File.ReadAllBytes (FileOperations.ROOT_PATH + "GameData/" + CI.TEXTURE_DIR + "/colorpicker_texture.jpg");
				colorPicker = new Texture2D (2, 2);
				colorPicker.LoadImage (colorPickerFileData); //..this will auto-resize the texture dimensions.

			} 

			SetVisible (true);
			GUI.enabled = true;

			GUILayout.BeginHorizontal ();
			GUILayout.EndHorizontal ();

			GUILayout.BeginVertical ();

			//	DrawTitle ("Craft Import");

			//Log.Info ("downloadState: " + downloadState.ToString ());
			switch (downloadState) {
#if EXPORT
			case downloadStateType.UPLOAD:
				uploadCase ();

				break;
			case downloadStateType.GET_DUP_CRAFT_LIST:
				getUpdateCraftList ();

				break;

			case downloadStateType.GET_THUMBNAIL:
				getThumbnailcase ();
				break;

			case downloadStateType.SELECT_DUP_CRAFT:
				selectDupCraftCase ();

				break;

			case downloadStateType.ACTIONGROUPS:
				GUILayout.BeginHorizontal ();
				GUILayout.Label ("Action Groups");
				GUILayout.FlexibleSpace ();
				GUILayout.EndHorizontal ();

				GUILayout.BeginHorizontal ();

				buildMenuScrollPosition = GUILayout.BeginScrollView (buildMenuScrollPosition, GUILayout.Width (WIDTH - 30), GUILayout.Height (HEIGHT * 2 / 3));
				GUILayout.BeginVertical ();


				for (int i = 0; i < 16; i++) {
					GUILayout.BeginHorizontal ();
					if (i < 10) {
						GUILayout.Label ((i + 1).ToString () + ":");
					} else {
						GUILayout.Label (fixedActions [i - 10]);
					}
					GUILayout.FlexibleSpace ();
					actionGroups [i] = GUILayout.TextField (actionGroups [i], GUILayout.MinWidth (50F), GUILayout.MaxWidth (300F));
					actionGroups [i] = actionGroups [i].Replace("\n", "").Replace("\r", "");
					GUILayout.EndHorizontal ();
				}
				GUILayout.EndVertical ();
				GUILayout.EndScrollView (); 
				GUILayout.EndHorizontal ();

				GUILayout.BeginHorizontal ();
				GUILayout.Label ("");
				GUILayout.EndHorizontal ();
				GUILayout.BeginHorizontal ();
				GUILayout.FlexibleSpace ();
				if (GUILayout.Button ("OK", GUILayout.Width (125.0f))) {
					
					downloadState = downloadStateType.UPLOAD;
				}
				GUILayout.FlexibleSpace ();

				GUILayout.EndHorizontal ();
				break;
#endif
				
			case downloadStateType.GUI:
				guiCase ();
				break;
#if EXPORT
			case downloadStateType.SHOW_WARNING:
				warningCase ();
				break;

//			case downloadStateType.FILESELECTION:
//				getFile ();
//				break;

			case downloadStateType.UPLOAD_IN_PROGRESS:
#endif
			case downloadStateType.IN_PROGRESS:
				Log.Info ("IN_PROGRESS");
				GUILayout.BeginHorizontal ();
				GUILayout.FlexibleSpace ();
				if (downloadState == downloadStateType.IN_PROGRESS)
					GUILayout.Label ("Download in progress");
				else
					GUILayout.Label ("Upload in progress");
				GUILayout.FlexibleSpace ();
				GUILayout.EndHorizontal ();

				GUILayout.BeginHorizontal ();
				GUILayout.Label ("");
				GUILayout.EndHorizontal ();

				GUILayout.BeginHorizontal ();
				GUILayout.FlexibleSpace ();
				if (downloadState == downloadStateType.IN_PROGRESS) {
					if (download != null)
						GUILayout.Label ("Progress: " + (100 * download.progress).ToString () + "%");
				}
				#if EXPORT
				else {
					if (Time.realtimeSinceStartup - lastUpdate > 1) {
						lastUpdate = Time.realtimeSinceStartup;
						uploadProgress++;
					}
					GUILayout.Label ("Upload progress: " + uploadProgress.ToString ());
				}
				#endif
				GUILayout.FlexibleSpace ();
				GUILayout.EndHorizontal ();

				GUILayout.BeginHorizontal ();
				GUILayout.Label ("");
				GUILayout.EndHorizontal ();

				GUILayout.BeginHorizontal ();
				GUILayout.FlexibleSpace ();
				if (GUILayout.Button ("Cancel", GUILayout.Width (125.0f))) {
					resetBeforeExit ();
				}
				GUILayout.FlexibleSpace ();
				GUILayout.EndHorizontal ();
				break;

				#if EXPORT
			case downloadStateType.UPLOAD_COMPLETED:
				#endif
			case downloadStateType.COMPLETED:
				GUILayout.BeginHorizontal ();
				GUILayout.FlexibleSpace ();
				if (downloadState == downloadStateType.COMPLETED)
					GUILayout.Label ("Download completed");
				else
					GUILayout.Label ("Upload completed");
				
				GUILayout.FlexibleSpace ();
				GUILayout.EndHorizontal ();
				GUILayout.BeginHorizontal ();
				GUILayout.Label ("", GUILayout.Height (10));
				GUILayout.EndHorizontal ();
				GUILayout.BeginHorizontal ();
				if (instructions.Trim () != "") {
					scrollPosition = GUILayout.BeginScrollView (
						scrollPosition, GUILayout.Width (WIDTH - 20), GUILayout.Height (HEIGHT - 100));
					GUILayout.Label (instructions);
					GUILayout.EndScrollView ();
				} else
					GUILayout.Label ("");
				GUILayout.EndHorizontal ();
				GUILayout.BeginHorizontal ();
				GUILayout.Label ("", GUILayout.Height (10));
				GUILayout.EndHorizontal ();
				GUILayout.BeginHorizontal ();
				GUILayout.FlexibleSpace ();
				if (GUILayout.Button ("OK", GUILayout.Width (125.0f))) {

					if (downloadState == downloadStateType.COMPLETED && loadAfterImport) {
						Log.Info ("saveFile: " + saveFile);
						if (!subassembly)
							EditorLogic.LoadShipFromFile (saveFile);
						else {
							if (EditorLogic.RootPart) 
								LoadCraftAsSubassembly (saveFile);
						//	ShipConstruct ship = ShipConstruction.LoadShip (craftURL);
						//	EditorLogic.SpawnConstruct (ship);
						}

					}
					resetBeforeExit ();
				}
				GUILayout.FlexibleSpace ();
				if (instructions != "") {
					if (GUILayout.Button ("Copy to clipboard")) {
						TextEditor te = new TextEditor ();
						te.text = instructions;
						te.SelectAll ();
						te.Copy ();
					}
					GUILayout.FlexibleSpace ();
				}
				GUILayout.EndHorizontal ();
				break;

			case downloadStateType.FILE_EXISTS:
				GUILayout.BeginHorizontal ();
				GUILayout.FlexibleSpace ();
				GUILayout.Label ("File Exists Error");
				GUILayout.FlexibleSpace ();
				GUILayout.EndHorizontal ();
				GUILayout.BeginHorizontal ();
				GUILayout.FlexibleSpace ();
				GUILayout.Label ("The craft file already exists, will NOT be overwritten");
				GUILayout.FlexibleSpace ();
				GUILayout.EndHorizontal ();
				GUILayout.BeginHorizontal ();
				if (GUILayout.Button ("OK", GUILayout.Width (125.0f))) {
					resetBeforeExit ();
				}
				GUILayout.EndHorizontal ();
				break;

				#if EXPORT
			case downloadStateType.UPLOAD_ERROR:
				#endif
			case downloadStateType.ERROR:
				GUILayout.BeginHorizontal ();
				GUILayout.FlexibleSpace ();
				if (downloadState == downloadStateType.ERROR)
					GUILayout.Label ("Download Error");
				else
					GUILayout.Label ("Upload Error");
				GUILayout.FlexibleSpace ();
				GUILayout.EndHorizontal ();
				GUILayout.BeginHorizontal ();
				GUILayout.FlexibleSpace ();
				#if EXPORT
				if (downloadState == downloadStateType.UPLOAD_ERROR)
					GUILayout.Label (uploadErrorMessage);
				else
				#endif
				GUILayout.Label (downloadErrorMessage);
				GUILayout.FlexibleSpace ();
				GUILayout.EndHorizontal ();
				GUILayout.BeginHorizontal ();
		#if EXPORT
				if (GUILayout.Button ("OK", GUILayout.Width (125.0f))) {
					downloadState = downloadStateType.UPLOAD;
				}
		#endif
				GUILayout.FlexibleSpace ();
				if (GUILayout.Button ("Cancel", GUILayout.Width (125.0f))) {
					resetBeforeExit ();
				}
				GUILayout.FlexibleSpace ();
				GUILayout.EndHorizontal ();
				break;

			default:
				break;
			}
			GUILayout.EndVertical ();
			GUI.DragWindow ();
		}
		/// <summary>Copies the given text onto the system clipboard.</summary>
		public static void Copy(string text){
			TextEditor editor=new TextEditor();
			editor.content.text=text;
			editor.SelectAll();
			editor.Copy();
		}
Beispiel #35
0
		private bool PerformOperation(TextEditor.TextEditOp operation)
		{
			switch (operation)
			{
			case TextEditor.TextEditOp.MoveLeft:
				this.MoveLeft();
				return false;
			case TextEditor.TextEditOp.MoveRight:
				this.MoveRight();
				return false;
			case TextEditor.TextEditOp.MoveUp:
				this.MoveUp();
				return false;
			case TextEditor.TextEditOp.MoveDown:
				this.MoveDown();
				return false;
			case TextEditor.TextEditOp.MoveLineStart:
				this.MoveLineStart();
				return false;
			case TextEditor.TextEditOp.MoveLineEnd:
				this.MoveLineEnd();
				return false;
			case TextEditor.TextEditOp.MoveTextStart:
				this.MoveTextStart();
				return false;
			case TextEditor.TextEditOp.MoveTextEnd:
				this.MoveTextEnd();
				return false;
			case TextEditor.TextEditOp.MoveGraphicalLineStart:
				this.MoveGraphicalLineStart();
				return false;
			case TextEditor.TextEditOp.MoveGraphicalLineEnd:
				this.MoveGraphicalLineEnd();
				return false;
			case TextEditor.TextEditOp.MoveWordLeft:
				this.MoveWordLeft();
				return false;
			case TextEditor.TextEditOp.MoveWordRight:
				this.MoveWordRight();
				return false;
			case TextEditor.TextEditOp.MoveParagraphForward:
				this.MoveParagraphForward();
				return false;
			case TextEditor.TextEditOp.MoveParagraphBackward:
				this.MoveParagraphBackward();
				return false;
			case TextEditor.TextEditOp.MoveToStartOfNextWord:
				this.MoveToStartOfNextWord();
				return false;
			case TextEditor.TextEditOp.MoveToEndOfPreviousWord:
				this.MoveToEndOfPreviousWord();
				return false;
			case TextEditor.TextEditOp.SelectLeft:
				this.SelectLeft();
				return false;
			case TextEditor.TextEditOp.SelectRight:
				this.SelectRight();
				return false;
			case TextEditor.TextEditOp.SelectUp:
				this.SelectUp();
				return false;
			case TextEditor.TextEditOp.SelectDown:
				this.SelectDown();
				return false;
			case TextEditor.TextEditOp.SelectTextStart:
				this.SelectTextStart();
				return false;
			case TextEditor.TextEditOp.SelectTextEnd:
				this.SelectTextEnd();
				return false;
			case TextEditor.TextEditOp.ExpandSelectGraphicalLineStart:
				this.ExpandSelectGraphicalLineStart();
				return false;
			case TextEditor.TextEditOp.ExpandSelectGraphicalLineEnd:
				this.ExpandSelectGraphicalLineEnd();
				return false;
			case TextEditor.TextEditOp.SelectGraphicalLineStart:
				this.SelectGraphicalLineStart();
				return false;
			case TextEditor.TextEditOp.SelectGraphicalLineEnd:
				this.SelectGraphicalLineEnd();
				return false;
			case TextEditor.TextEditOp.SelectWordLeft:
				this.SelectWordLeft();
				return false;
			case TextEditor.TextEditOp.SelectWordRight:
				this.SelectWordRight();
				return false;
			case TextEditor.TextEditOp.SelectToEndOfPreviousWord:
				this.SelectToEndOfPreviousWord();
				return false;
			case TextEditor.TextEditOp.SelectToStartOfNextWord:
				this.SelectToStartOfNextWord();
				return false;
			case TextEditor.TextEditOp.SelectParagraphBackward:
				this.SelectParagraphBackward();
				return false;
			case TextEditor.TextEditOp.SelectParagraphForward:
				this.SelectParagraphForward();
				return false;
			case TextEditor.TextEditOp.Delete:
				return this.Delete();
			case TextEditor.TextEditOp.Backspace:
				return this.Backspace();
			case TextEditor.TextEditOp.DeleteWordBack:
				return this.DeleteWordBack();
			case TextEditor.TextEditOp.DeleteWordForward:
				return this.DeleteWordForward();
			case TextEditor.TextEditOp.DeleteLineBack:
				return this.DeleteLineBack();
			case TextEditor.TextEditOp.Cut:
				return this.Cut();
			case TextEditor.TextEditOp.Copy:
				this.Copy();
				return false;
			case TextEditor.TextEditOp.Paste:
				return this.Paste();
			case TextEditor.TextEditOp.SelectAll:
				this.SelectAll();
				return false;
			case TextEditor.TextEditOp.SelectNone:
				this.SelectNone();
				return false;
			}
			Debug.Log("Unimplemented: " + operation);
			return false;
		}