public void TestIsPrivateSelection()
        {
            try
            {
                PlasticApiMock apiMock = new PlasticApiMock();

                Plastic.InitializeAPIForTesting(apiMock);

                string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
                string barPath = Path.Combine(Path.GetTempPath(), "bar.c");

                Asset fooAsset = new Asset(fooPath);
                Asset barAsset = new Asset(barPath);

                apiMock.SetupGetWorkspaceTreeNode(fooPath, null);
                apiMock.SetupGetWorkspaceTreeNode(barPath, null);
                apiMock.SetupGetWorkingBranch(new BranchInfo());

                AssetList assetList = new AssetList();
                assetList.Add(fooAsset);
                assetList.Add(barAsset);

                SelectedAssetGroupInfo groupInfo =
                    SelectedAssetGroupInfo.BuildFromAssetList(
                        assetList,
                        new AssetStatusCacheMock());

                Assert.IsTrue(groupInfo.IsPrivateSelection);
            }
            finally
            {
                Plastic.InitializeAPIForTesting(new PlasticAPI());
            }
        }
Esempio n. 2
0
        static bool IsApplicableForOperation(
            string path,
            bool isDirectory,
            AssetMenuOperations operation,
            IAssetStatusCache assetStatusCache)
        {
            SelectedAssetGroupInfo info = SelectedAssetGroupInfo.BuildFromSingleFile(
                path, isDirectory, assetStatusCache);

            return(AssetMenuUpdater.GetAvailableMenuOperations(info).HasFlag(operation));
        }
        static void Editor_finishedDefaultHeaderGUI(UnityEditor.Editor obj)
        {
            if (!mIsEnabled)
            {
                return;
            }

            AssetList assetList = mAssetsSelection.GetSelectedAssets();

            if (mOperations == null ||
                assetList.Count == 0 ||
                string.IsNullOrEmpty(assetList[0].path))
            {
                return;
            }

            string selectionFullPath = Path.GetFullPath(assetList[0].path);

            AssetsOverlays.AssetStatus assetStatus = (assetList.Count > 1) ?
                                                     AssetsOverlays.AssetStatus.None :
                                                     mStatusCache.GetStatusForPath(selectionFullPath);

            LockStatusData lockStatusData = mStatusCache.GetLockStatusDataForPath(
                selectionFullPath);

            SelectedAssetGroupInfo selectedGroupInfo = SelectedAssetGroupInfo.
                                                       BuildFromAssetList(assetList, mStatusCache);

            AssetMenuOperations assetOperations =
                AssetMenuUpdater.GetAvailableMenuOperations(selectedGroupInfo);

            bool guiEnabledBck = GUI.enabled;

            GUI.enabled = true;
            try
            {
                DrawBackRectangle(guiEnabledBck);

                GUILayout.BeginHorizontal();

                DrawStatusLabel(assetStatus, lockStatusData);

                GUILayout.FlexibleSpace();

                DrawButtons(assetList, assetOperations);

                GUILayout.EndHorizontal();
            }
            finally
            {
                GUI.enabled = guiEnabledBck;
            }
        }
Esempio n. 4
0
        public void TestUndoMenuDisabledForNotControlledSelection()
        {
            SelectedAssetGroupInfo groupInfo = new SelectedAssetGroupInfo()
            {
                SelectedCount         = 5,
                IsControlledSelection = false,
            };

            Assert.IsFalse(
                AssetMenuUpdater.GetAvailableMenuOperations(groupInfo)
                .HasFlag(AssetMenuOperations.Undo));
        }
Esempio n. 5
0
        public void TestAddMenuDisabledForControlledFile()
        {
            SelectedAssetGroupInfo groupInfo = new SelectedAssetGroupInfo()
            {
                SelectedCount      = 1,
                IsPrivateSelection = false,
            };

            Assert.IsFalse(
                AssetMenuUpdater.GetAvailableMenuOperations(groupInfo)
                .HasFlag(AssetMenuOperations.Add));
        }
Esempio n. 6
0
        public void TestCheckinMenuDisabledForNotCheckedinFile()
        {
            SelectedAssetGroupInfo groupInfo = new SelectedAssetGroupInfo()
            {
                SelectedCount         = 1,
                IsControlledSelection = true,
                IsCheckedInSelection  = true,
            };

            Assert.IsFalse(
                AssetMenuUpdater.GetAvailableMenuOperations(groupInfo)
                .HasFlag(AssetMenuOperations.Checkin));
        }
Esempio n. 7
0
        public void TestAddMenuEnabledForMultiplePrivate()
        {
            SelectedAssetGroupInfo groupInfo = new SelectedAssetGroupInfo()
            {
                SelectedCount      = 5,
                IsPrivateSelection = true,
                IsFileSelection    = true,
            };

            Assert.IsTrue(
                AssetMenuUpdater.GetAvailableMenuOperations(groupInfo)
                .HasFlag(AssetMenuOperations.Add));
        }
Esempio n. 8
0
        public void TestUndoMenuDisabledForDirectory()
        {
            SelectedAssetGroupInfo groupInfo = new SelectedAssetGroupInfo()
            {
                SelectedCount         = 1,
                IsControlledSelection = true,
                IsCheckedInSelection  = false,
                IsFileSelection       = false,
            };

            Assert.IsFalse(
                AssetMenuUpdater.GetAvailableMenuOperations(groupInfo)
                .HasFlag(AssetMenuOperations.Undo));
        }
Esempio n. 9
0
        public void TestUndoMenuEnabledForNonCheckedInFile()
        {
            SelectedAssetGroupInfo groupInfo = new SelectedAssetGroupInfo()
            {
                SelectedCount         = 1,
                IsControlledSelection = true,
                IsCheckedOutSelection = true,
                IsFileSelection       = true,
            };

            Assert.IsTrue(
                AssetMenuUpdater.GetAvailableMenuOperations(groupInfo)
                .HasFlag(AssetMenuOperations.Undo));
        }
Esempio n. 10
0
        public void TestDiffMenuEnabledForCheckedInFile()
        {
            SelectedAssetGroupInfo groupInfo = new SelectedAssetGroupInfo()
            {
                SelectedCount          = 1,
                IsFileSelection        = true,
                IsCheckedInSelection   = true,
                IsControlledSelection  = true,
                HasAnyAddedInSelection = false,
            };

            Assert.IsTrue(
                AssetMenuUpdater.GetAvailableMenuOperations(groupInfo)
                .HasFlag(AssetMenuOperations.Diff));
        }
Esempio n. 11
0
        public void TestCheckoutMenuDisabledForAlreadyCheckedoutFiles()
        {
            SelectedAssetGroupInfo groupInfo = new SelectedAssetGroupInfo()
            {
                SelectedCount          = 1,
                IsFileSelection        = true,
                IsCheckedInSelection   = false,
                IsControlledSelection  = true,
                HasAnyAddedInSelection = false,
            };

            Assert.IsFalse(
                AssetMenuUpdater.GetAvailableMenuOperations(groupInfo)
                .HasFlag(AssetMenuOperations.Checkout));
        }
Esempio n. 12
0
        public void TestHistoryMenuDisabledForAddedFile()
        {
            SelectedAssetGroupInfo groupInfo = new SelectedAssetGroupInfo()
            {
                SelectedCount          = 1,
                IsFileSelection        = true,
                IsCheckedInSelection   = true,
                IsControlledSelection  = true,
                HasAnyAddedInSelection = true,
            };

            Assert.IsFalse(
                AssetMenuUpdater.GetAvailableMenuOperations(groupInfo)
                .HasFlag(AssetMenuOperations.History));
        }
Esempio n. 13
0
        public void TestIsNotFileSelection()
        {
            string barPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            try
            {
                PlasticApiMock apiMock = new PlasticApiMock();

                Plastic.InitializeAPIForTesting(apiMock);

                string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");

                Directory.CreateDirectory(barPath);

                Asset fooAsset = new Asset(fooPath);
                Asset barAsset = new Asset(barPath);

                WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Controlled();

                apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
                apiMock.SetupGetWorkingBranch(new BranchInfo());

                AssetList assetList = new AssetList();
                assetList.Add(fooAsset);
                assetList.Add(barAsset);

                SelectedAssetGroupInfo groupInfo =
                    SelectedAssetGroupInfo.BuildFromAssetList(
                        assetList,
                        new AssetStatusCacheMock());

                Assert.IsFalse(groupInfo.IsFileSelection);
            }
            finally
            {
                Plastic.InitializeAPIForTesting(new PlasticAPI());

                if (Directory.Exists(barPath))
                {
                    Directory.Delete(barPath);
                }
            }
        }
Esempio n. 14
0
        public void TestHasAnyLockedRemoteInSelection()
        {
            try
            {
                PlasticApiMock apiMock = new PlasticApiMock();

                Plastic.InitializeAPIForTesting(apiMock);

                string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
                string barPath = Path.Combine(Path.GetTempPath(), "bar.c");

                Asset fooAsset = new Asset(fooPath);
                Asset barAsset = new Asset(barPath);

                WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Controlled();
                WorkspaceTreeNode barNode = BuildWorkspaceTreeNode.Controlled();

                apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
                apiMock.SetupGetWorkspaceTreeNode(barPath, barNode);
                apiMock.SetupGetWorkingBranch(new BranchInfo());

                AssetList assetList = new AssetList();
                assetList.Add(fooAsset);
                assetList.Add(barAsset);

                AssetStatusCacheMock assetStatusCache = new AssetStatusCacheMock();

                assetStatusCache.SetStatus(fooPath, AssetStatus.LockedRemote);

                SelectedAssetGroupInfo groupInfo =
                    SelectedAssetGroupInfo.BuildFromAssetList(
                        assetList,
                        assetStatusCache);

                Assert.IsTrue(groupInfo.HasAnyRemoteLockedInSelection);
            }
            finally
            {
                Plastic.InitializeAPIForTesting(new PlasticAPI());
            }
        }
Esempio n. 15
0
        public void TestSelectedCount()
        {
            try
            {
                PlasticApiMock apiMock = new PlasticApiMock();

                Plastic.InitializeAPIForTesting(apiMock);

                string fooPath = Path.Combine(Path.GetTempPath(), "foo.c");
                string barPath = Path.Combine(Path.GetTempPath(), "bar.c");

                Asset fooAsset = new Asset(fooPath);
                Asset barAsset = new Asset(barPath);

                WorkspaceTreeNode fooNode = BuildWorkspaceTreeNode.Controlled();
                WorkspaceTreeNode barNode = BuildWorkspaceTreeNode.Controlled();

                apiMock.SetupGetWorkspaceTreeNode(fooPath, fooNode);
                apiMock.SetupGetWorkspaceTreeNode(barPath, barNode);
                apiMock.SetupGetWorkingBranch(new BranchInfo());

                AssetList assetList = new AssetList();
                assetList.Add(fooAsset);
                assetList.Add(barAsset);

                SelectedAssetGroupInfo groupInfo =
                    SelectedAssetGroupInfo.BuildFromAssetList(
                        assetList,
                        new AssetStatusCacheMock());

                Assert.AreEqual(2, groupInfo.SelectedCount);
            }
            finally
            {
                Plastic.InitializeAPIForTesting(new PlasticAPI());
            }
        }
Esempio n. 16
0
        static void Editor_finishedDefaultHeaderGUI(UnityEditor.Editor inspector)
        {
            if (!sIsEnabled)
            {
                return;
            }

            if (!FindWorkspace.HasWorkspace(Application.dataPath))
            {
                Disable();
                return;
            }

            sAssetSelection.SetActiveInspector(inspector);

            AssetList assetList = ((AssetOperations.IAssetSelection)
                                   sAssetSelection).GetSelectedAssets();

            if (assetList.Count == 0 ||
                string.IsNullOrEmpty(assetList[0].path))
            {
                return;
            }

            string selectionFullPath = Path.GetFullPath(assetList[0].path);

            AssetsOverlays.AssetStatus assetStatus = (assetList.Count > 1) ?
                                                     AssetsOverlays.AssetStatus.None :
                                                     PlasticPlugin.AssetStatusCache.GetStatusForPath(selectionFullPath);

            LockStatusData lockStatusData = PlasticPlugin.AssetStatusCache.GetLockStatusDataForPath(
                selectionFullPath);

            SelectedAssetGroupInfo selectedGroupInfo = SelectedAssetGroupInfo.
                                                       BuildFromAssetList(assetList, PlasticPlugin.AssetStatusCache);

            AssetMenuOperations assetOperations =
                AssetMenuUpdater.GetAvailableMenuOperations(selectedGroupInfo);

            bool guiEnabledBck = GUI.enabled;

            GUI.enabled = true;
            try
            {
                DrawBackRectangle(guiEnabledBck);

                GUILayout.BeginHorizontal();

                DrawStatusLabel(assetStatus, lockStatusData);

                GUILayout.FlexibleSpace();

                DrawButtons(assetList, assetOperations);

                GUILayout.EndHorizontal();
            }
            finally
            {
                GUI.enabled = guiEnabledBck;
            }
        }