コード例 #1
0
        private GenericMenu CreateContextMenu(ChangesTreeNode node)
        {
            var genericMenu = new GenericMenu();

            if (discardGuiContent == null)
            {
                discardGuiContent = new GUIContent("Discard");
            }

            genericMenu.AddItem(discardGuiContent, false, () => {
                GitStatusEntry[] discardEntries;
                if (node.isFolder)
                {
                    discardEntries = treeChanges
                                     .GetLeafNodes(node)
                                     .Select(treeNode => treeNode.GitStatusEntry)
                                     .ToArray();
                }
                else
                {
                    discardEntries = new [] { node.GitStatusEntry };
                }

                Repository.DiscardChanges(discardEntries)
                .Start();
            });

            return(genericMenu);
        }
コード例 #2
0
ファイル: ChangesView.cs プロジェクト: ccf19881030/Unity-1
        private GenericMenu CreateContextMenu(ChangesTreeNode node)
        {
            var genericMenu = new GenericMenu();

            genericMenu.AddItem(new GUIContent("Show Diff"), false, () =>
            {
                ITask <NPath[]> calculateDiff = null;
                if (node.IsFolder)
                {
                    calculateDiff = CalculateFolderDiff(node);
                }
                else
                {
                    calculateDiff = CalculateFileDiff(node);
                }
                calculateDiff.FinallyInUI((s, ex, leftRight) =>
                {
                    if (s)
                    {
                        EditorUtility.InvokeDiffTool(
                            leftRight[0].IsInitialized ? leftRight[0].FileName : null,
                            leftRight[0].IsInitialized ? leftRight[0].MakeAbsolute().ToString() : null,
                            leftRight[1].IsInitialized ? leftRight[1].FileName : null,
                            leftRight[1].IsInitialized ? leftRight[1].MakeAbsolute().ToString() : null,
                            null, null);
                    }
                    else
                    {
                        throw ex;
                    }
                })
                .Start();
            });

            genericMenu.AddSeparator("");

            if (discardGuiContent == null)
            {
                discardGuiContent = new GUIContent("Discard");
            }

            genericMenu.AddItem(discardGuiContent, false, () =>
            {
                if (!EditorUtility.DisplayDialog(Localization.DiscardConfirmTitle,
                                                 Localization.DiscardConfirmDescription,
                                                 Localization.DiscardConfirmYes,
                                                 Localization.Cancel))
                {
                    return;
                }

                GitStatusEntry[] discardEntries;
                if (node.isFolder)
                {
                    discardEntries = treeChanges
                                     .GetLeafNodes(node)
                                     .Select(treeNode => treeNode.GitStatusEntry)
                                     .ToArray();
                }
                else
                {
                    discardEntries = new [] { node.GitStatusEntry };
                }

                Repository.DiscardChanges(discardEntries)
                .ThenInUI(AssetDatabase.Refresh)
                .Start();
            });

            return(genericMenu);
        }