Ejemplo n.º 1
0
 private void OnIMGUIEvent(IMGUIEvent evt)
 {
     if (base.textInputField.hasFocus)
     {
         base.textInputField.SyncTextEngine();
         this.m_Changed = false;
         EventType type = evt.imguiEvent.type;
         if (type != EventType.ValidateCommand)
         {
             if (type == EventType.ExecuteCommand)
             {
                 bool   flag = false;
                 string text = base.editorEngine.text;
                 if (!base.textInputField.hasFocus)
                 {
                     return;
                 }
                 string commandName = evt.imguiEvent.commandName;
                 if (commandName != null)
                 {
                     if (commandName == "OnLostFocus")
                     {
                         evt.StopPropagation();
                         return;
                     }
                     if (!(commandName == "Cut"))
                     {
                         if (commandName == "Copy")
                         {
                             base.editorEngine.Copy();
                             evt.StopPropagation();
                             return;
                         }
                         if (!(commandName == "Paste"))
                         {
                             if (commandName == "SelectAll")
                             {
                                 base.editorEngine.SelectAll();
                                 evt.StopPropagation();
                                 return;
                             }
                             if (commandName == "Delete")
                             {
                                 if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX)
                                 {
                                     base.editorEngine.Delete();
                                 }
                                 else
                                 {
                                     base.editorEngine.Cut();
                                 }
                                 flag = true;
                             }
                         }
                         else
                         {
                             base.editorEngine.Paste();
                             flag = true;
                         }
                     }
                     else
                     {
                         base.editorEngine.Cut();
                         flag = true;
                     }
                 }
                 if (flag)
                 {
                     if (text != base.editorEngine.text)
                     {
                         this.m_Changed = true;
                     }
                     evt.StopPropagation();
                 }
             }
         }
         else
         {
             string commandName2 = evt.imguiEvent.commandName;
             if (commandName2 != null)
             {
                 if (!(commandName2 == "Cut") && !(commandName2 == "Copy"))
                 {
                     if (!(commandName2 == "Paste"))
                     {
                         if (!(commandName2 == "SelectAll") && !(commandName2 == "Delete"))
                         {
                             if (!(commandName2 == "UndoRedoPerformed"))
                             {
                             }
                         }
                     }
                     else if (!base.editorEngine.CanPaste())
                     {
                         return;
                     }
                 }
                 else if (!base.editorEngine.hasSelection)
                 {
                     return;
                 }
             }
             evt.StopPropagation();
         }
         if (this.m_Changed)
         {
             base.editorEngine.text = base.textInputField.CullString(base.editorEngine.text);
             base.textInputField.UpdateText(base.editorEngine.text);
             evt.StopPropagation();
         }
         base.editorEngine.UpdateScrollOffset();
     }
 }
Ejemplo n.º 2
0
        void OnIMGUIEvent(IMGUIEvent evt)
        {
            if (!textInputField.hasFocus)
            {
                return;
            }

            textInputField.SyncTextEngine();
            m_Changed = false;

            switch (evt.imguiEvent.type)
            {
            case EventType.ValidateCommand:
                switch (evt.imguiEvent.commandName)
                {
                case EventCommandNames.Cut:
                case EventCommandNames.Copy:
                    if (!editorEngine.hasSelection)
                    {
                        return;
                    }
                    break;

                case EventCommandNames.Paste:
                    if (!editorEngine.CanPaste())
                    {
                        return;
                    }
                    break;

                case EventCommandNames.SelectAll:
                case EventCommandNames.Delete:
                    break;

                case EventCommandNames.UndoRedoPerformed:
                    // TODO: ????? editor.text = text; --> see EditorGUI's DoTextField
                    break;
                }
                evt.StopPropagation();
                break;

            case EventType.ExecuteCommand:
                bool   mayHaveChanged = false;
                string oldText        = editorEngine.text;

                if (!textInputField.hasFocus)
                {
                    return;
                }

                switch (evt.imguiEvent.commandName)
                {
                case EventCommandNames.OnLostFocus:
                    evt.StopPropagation();
                    return;

                case EventCommandNames.Cut:
                    editorEngine.Cut();
                    mayHaveChanged = true;
                    break;

                case EventCommandNames.Copy:
                    editorEngine.Copy();
                    evt.StopPropagation();
                    return;

                case EventCommandNames.Paste:
                    editorEngine.Paste();
                    mayHaveChanged = true;
                    break;

                case EventCommandNames.SelectAll:
                    editorEngine.SelectAll();
                    evt.StopPropagation();
                    return;

                case EventCommandNames.Delete:
                    // This "Delete" command stems from a Shift-Delete in the text
                    // On Windows, Shift-Delete in text does a cut whereas on Mac, it does a delete.
                    if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX)
                    {
                        editorEngine.Delete();
                    }
                    else
                    {
                        editorEngine.Cut();
                    }
                    mayHaveChanged = true;
                    break;
                }

                if (mayHaveChanged)
                {
                    if (oldText != editorEngine.text)
                    {
                        m_Changed = true;
                    }

                    evt.StopPropagation();
                }
                break;
            }

            if (m_Changed)
            {
                editorEngine.text = textInputField.CullString(editorEngine.text);
                textInputField.UpdateText(editorEngine.text);
                evt.StopPropagation();
            }

            // Scroll offset might need to be updated
            editorEngine.UpdateScrollOffset();
        }