Ejemplo n.º 1
0
 public static void OpenUndoHistory()
 {
     // Opens the window, otherwise focuses it if it’s already open.
     if (s_Instance == null)
     {
         s_Instance = GetWindow <UndoHistoryWindow>();
     }
     else
     {
         GetWindow <UndoHistoryWindow>();
     }
     s_Instance.ScrollToCurrent();
 }
Ejemplo n.º 2
0
        public void OnEnable()
        {
            if (s_Instance == null)
            {
                this.titleContent       = EditorGUIUtility.TrTextContentWithIcon("Undo History", "UnityEditor.HistoryWindow");
                Undo.undoRedoPerformed += OnUndoRedoPerformed;

                //root of the editorwindow
                VisualElement root = rootVisualElement;
                root.styleSheets.Add(EditorGUIUtility.Load(k_StyleCommon) as StyleSheet);
                root.styleSheets.Add(EditorGUIUtility.Load(EditorGUIUtility.isProSkin ? k_StyleDark : k_StyleLight) as StyleSheet);
                root.EnableInClassList("root", true);

                var theListView = EditorGUIUtility.Load("UXML/Undo/UndoListView.uxml") as VisualTreeAsset;
                theListView.CloneTree(root);

                var visualTree = EditorGUIUtility.Load("UXML/Undo/UndoListItem.uxml") as VisualTreeAsset;

                Func <VisualElement> makeItem = visualTree.Instantiate;

                Action <VisualElement, int> bindItem = (e, i) =>
                {
                    //get info on this action
                    var item = m_History[i];

                    //get the main container
                    var container = e.Q("HistoryItem");

                    //is this the the current state?
                    bool isCurrent = item.index == m_UndoCursor;

                    //set style class for the whole Container
                    container.EnableInClassList("current", isCurrent && m_ShowLatestFirst);
                    container.EnableInClassList("current-reverse", isCurrent && !m_ShowLatestFirst);
                    container.EnableInClassList("redo", !isCurrent && item.type == HistoryType.Redo);
                    container.EnableInClassList("undo", !isCurrent && (item.type == HistoryType.Undo || item.type == HistoryType.None));

                    //get the Action label and set it's text to this undo action
                    var label = e.Q("Text-Action") as Label;
                    label.text = item.undoName;

                    if (isCurrent)
                    {
                        m_HistoryListView.selectedIndex = i;
                    }
                };

                m_HistoryListView             = root.Q <ListView>();
                m_HistoryListView.bindItem    = bindItem;
                m_HistoryListView.makeItem    = makeItem;
                m_HistoryListView.itemsSource = m_History;
                m_HistoryListView.RefreshItems();

                m_HistoryListView.onSelectionChange += OnUndoSelectionChange;

                m_LastUndos.Clear();

                s_Instance = this;
            }
            wantsLessLayoutEvents = true;
        }