コード例 #1
0
        private void DrawPersonalPreferences()
        {
            EditorGUILayout.HelpBox("These are personal preferences stored in the registry.\nHint: check the the tooltips.", MessageType.Info);

            m_PersonalPrefs.EnableCoreIntegration = EditorGUILayout.Toggle("Enable SVN integration", m_PersonalPrefs.EnableCoreIntegration);

            EditorGUI.BeginDisabledGroup(!m_PersonalPrefs.EnableCoreIntegration);

            m_PersonalPrefs.PopulateStatusesDatabase = EditorGUILayout.Toggle(new GUIContent("Enable overlay icons", "Enables overlay icons in the project windows.\nPopulates internal cache with statuses of changed entities.\nFile changes may trigger repopulation of the cache."), m_PersonalPrefs.PopulateStatusesDatabase);
            EditorGUI.BeginDisabledGroup(!m_PersonalPrefs.PopulateStatusesDatabase);

            m_PersonalPrefs.ShowNormalStatusOverlayIcon = EditorGUILayout.Toggle(new GUIContent("Show Normal Status Green Icon", "Normal status is versioned asset that doesn't have any changes."), m_PersonalPrefs.ShowNormalStatusOverlayIcon);
            m_PersonalPrefs.AutoRefreshDatabaseInterval = EditorGUILayout.IntField(new GUIContent("Overlay icons refresh interval", "How much seconds to wait for the next overlay icons refresh.\nNOTE: -1 will deactivate it - only file changes will trigger refresh."), m_PersonalPrefs.AutoRefreshDatabaseInterval);

            m_PersonalPrefs.DownloadRepositoryChanges =
                (SVNPreferencesManager.BoolPreference)EditorGUILayout.EnumPopup(
                    new GUIContent("Check for repository changes", m_DownloadRepositoryChangesHint + "\n\nNOTE: this will override the project setting. Coordinate this with your team.")
                    , m_PersonalPrefs.DownloadRepositoryChanges);

            EditorGUI.EndDisabledGroup();

            m_PersonalPrefs.ContextMenusClient = (ContextMenusClient)EditorGUILayout.EnumPopup(new GUIContent("Context menus client", "Select what client should be used with the context menus."), m_PersonalPrefs.ContextMenusClient);
            if (GUI.changed)
            {
                var errorMsg = SVNContextMenusManager.IsCurrentlySupported(m_PersonalPrefs.ContextMenusClient);
                if (!string.IsNullOrEmpty(errorMsg))
                {
                    EditorUtility.DisplayDialog("Context Menus Client Issue", errorMsg, "Ok");
                }
            }

            m_PersonalPrefs.TraceLogs = (SVNTraceLogs)EditorGUILayout.EnumFlagsField(new GUIContent("Trace logs", "Logs for nerds and debugging."), m_PersonalPrefs.TraceLogs);

            EditorGUI.EndDisabledGroup();
        }
コード例 #2
0
        public void SavePreferences(PersonalPreferences personalPrefs, ProjectPreferences projectPrefs)
        {
            PersonalPrefs = personalPrefs.Clone();
            ProjectPrefs  = projectPrefs.Clone();

            EditorPrefs.SetString(PERSONAL_PREFERENCES_KEY, JsonUtility.ToJson(PersonalPrefs));

            File.WriteAllText(PROJECT_PREFERENCES_PATH, JsonUtility.ToJson(ProjectPrefs, true));

            SVNContextMenusManager.SetupContextType(PersonalPrefs.ContextMenusClient);

            PreferencesChanged?.Invoke();
        }
コード例 #3
0
        public override void Initialize(bool freshlyCreated)
        {
            var lastModifiedDate = File.Exists(PROJECT_PREFERENCES_PATH)
                                ? File.GetLastWriteTime(PROJECT_PREFERENCES_PATH).Ticks
                                : 0
            ;

            if (freshlyCreated || m_ProjectPrefsLastModifiedTime != lastModifiedDate)
            {
                LoadPreferences();
            }

            if (freshlyCreated || m_RetryTextures)
            {
                LoadTextures();

                m_RetryTextures = false;

                // If WiseSVN was just added to the project, Unity won't manage to load the textures the first time. Try again next frame.
                if (FileStatusIcons[(int)VCFileStatus.Added].image == null)
                {
                    // We're using a flag as assembly reload may happen and update callback will be lost.
                    m_RetryTextures = true;

                    EditorApplication.CallbackFunction reloadTextures = null;
                    reloadTextures = () => {
                        LoadTextures();
                        m_RetryTextures           = false;
                        EditorApplication.update -= reloadTextures;
                    };

                    EditorApplication.update += reloadTextures;
                }

                Debug.Log($"Loaded WiseSVN Preferences. WiseSVN is turned {(PersonalPrefs.EnableCoreIntegration ? "on" : "off")}.");

                if (PersonalPrefs.EnableCoreIntegration)
                {
                    var svnError = WiseSVNIntegration.CheckForSVNErrors();

                    // svn: warning: W155007: '...' is not a working copy!
                    // This can be returned when project is not a valid svn checkout. (Probably)
                    if (svnError.Contains("W155007"))
                    {
                        Debug.LogError("This project is NOT under version control (not a proper SVN checkout).");

                        // System.ComponentModel.Win32Exception (0x80004005): ApplicationName='...', CommandLine='...', Native error= The system cannot find the file specified.
                        // Could not find the command executable. The user hasn't installed their CLI (Command Line Interface) so we're missing an "svn.exe" in the PATH environment.
                        // This is allowed only if there isn't ProjectPreference specified CLI path.
                    }
                    else if (svnError.Contains("0x80004005"))
                    {
                        Debug.LogError("SVN CLI (Command Line Interface) not found. You need to install it in order for the SVN integration to work properly.");

                        // Any other error.
                    }
                    else if (!string.IsNullOrEmpty(svnError))
                    {
                        Debug.LogError($"SVN command line interface returned this error:\n{svnError}");
                    }
                }
            }

            SVNContextMenusManager.SetupContextType(PersonalPrefs.ContextMenusClient);
        }
コード例 #4
0
        private void OnGUI()
        {
            var outputStyle = new GUIStyle(EditorStyles.textArea);

            outputStyle.wordWrap = false;

            var textSize = outputStyle.CalcSize(new GUIContent(m_CombinedOutput));

            m_OutputScroll = EditorGUILayout.BeginScrollView(m_OutputScroll);
            EditorGUILayout.LabelField(m_CombinedOutput, outputStyle, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true), GUILayout.MinWidth(textSize.x), GUILayout.MinHeight(textSize.y));
            EditorGUILayout.EndScrollView();

            EditorGUILayout.BeginHorizontal();
            {
                bool isWorking = m_SVNOperation == null || m_SVNOperation.HasFinished;

                EditorGUI.BeginDisabledGroup(isWorking);

                if (GUILayout.Button("Abort"))
                {
                    m_SVNOperation.Abort(false);
                    m_CombinedOutput += "Aborting...\n";
                    m_StateLabel      = "Aborting...";
                }

                if (GUILayout.Button("Kill"))
                {
                    m_SVNOperation.Abort(true);
                    m_CombinedOutput += "Killing...\n";
                    m_StateLabel      = "Killing...";
                }

                EditorGUI.EndDisabledGroup();

                GUILayout.FlexibleSpace();

                EditorGUILayout.LabelField(m_StateLabel);

                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Clear"))
                {
                    m_CombinedOutput = "";
                }

                EditorGUI.BeginDisabledGroup(!isWorking);

                if (GUILayout.Button("Get Status"))
                {
                    m_SVNOperation = WiseSVNIntegration.GetStatusesAsync(".", recursive: true, offline: false);

                    m_SVNOperation.AnyOutput += (line) => { m_CombinedOutput += line + "\n"; };

                    m_SVNOperation.Completed += (op) => {
                        m_StateLabel      = op.AbortRequested ? "Aborted!" : "Completed!";
                        m_CombinedOutput += m_StateLabel + "\n\n";
                        m_SVNOperation    = null;
                    };

                    m_StateLabel = "Working...";
                }

                EditorGUI.EndDisabledGroup();
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);
            {
                GUILayout.FlexibleSpace();

                GUILayout.Label("External SVN Client:");

                if (GUILayout.Button("Commit", GUILayout.ExpandWidth(false)))
                {
                    SVNContextMenusManager.CommitAll();
                }

                if (GUILayout.Button("Update", GUILayout.ExpandWidth(false)))
                {
                    SVNContextMenusManager.UpdateAll();
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
        }
コード例 #5
0
        private void DrawBranchesList()
        {
            using (var scrollView = new EditorGUILayout.ScrollViewScope(m_BranchesScroll)) {
                m_BranchesScroll = scrollView.scrollPosition;

                // For hover effects to work.
                if (Event.current.type == EventType.MouseMove)
                {
                    Repaint();
                }

                // TODO: Sort list by folder depths: compare by lastIndexOf('/'). If equal, by string.

                foreach (var branchProject in Database.BranchProjects)
                {
                    if (!string.IsNullOrEmpty(m_BranchFilter) && branchProject.BranchName.IndexOf(m_BranchFilter, System.StringComparison.OrdinalIgnoreCase) == -1)
                    {
                        continue;
                    }

                    // Apply setting only in Scanned mode since the thread will still be working otherwise and
                    // cause inconsistent GUILayout structure.
                    if (m_ConflictsScanState == ConflictsScanState.Scanned && !m_ConflictsShowNormal)
                    {
                        var conflictResult = m_ConflictsScanResults.First(r => r.UnityURL == branchProject.UnityProjectURL);
                        if (conflictResult.State == ConflictState.Normal)
                        {
                            continue;
                        }
                    }

                    using (new EditorGUILayout.HorizontalScope(/*BranchRowStyle*/)) {
                        float buttonSize   = 24f;
                        bool  repoBrowser  = GUILayout.Button(RepoBrowserContent, MiniIconButtonlessStyle, GUILayout.Height(buttonSize), GUILayout.Width(buttonSize));
                        bool  showLog      = GUILayout.Button(SelectShowLogContent(branchProject), MiniIconButtonlessStyle, GUILayout.Height(buttonSize), GUILayout.Width(buttonSize));
                        bool  switchBranch = GUILayout.Button(SwitchBranchContent, MiniIconButtonlessStyle, GUILayout.Height(buttonSize), GUILayout.Width(buttonSize));

                        bool branchSelected = GUILayout.Button(new GUIContent(branchProject.BranchRelativePath, branchProject.BranchURL), BranchLabelStyle);

                        if (repoBrowser)
                        {
                            SVNContextMenusManager.RepoBrowser(branchProject.UnityProjectURL + "/" + AssetDatabase.GetAssetPath(m_TargetAsset));
                        }

                        if (showLog)
                        {
                            SVNContextMenusManager.ShowLog(branchProject.UnityProjectURL + "/" + AssetDatabase.GetAssetPath(m_TargetAsset));
                        }

                        if (switchBranch)
                        {
                            bool confirm = EditorUtility.DisplayDialog("Switch Operation",
                                                                       "Unity needs to be closed while switching. Do you want to close it?\n\n" +
                                                                       "Reason: if Unity starts crunching assets while SVN is downloading files, the Library may get corrupted.",
                                                                       "Yes!", "No"
                                                                       );
                            if (confirm && UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
                            {
                                var localPath = WiseSVNIntegration.WorkingCopyRootPath();
                                var targetUrl = branchProject.BranchURL;

                                if (branchProject.BranchURL != branchProject.UnityProjectURL)
                                {
                                    bool useBranchRoot = EditorUtility.DisplayDialog("Switch what?",
                                                                                     "What do you want to switch?\n" +
                                                                                     "- Working copy root (the whole checkout)\n" +
                                                                                     "- Unity project folder",
                                                                                     "Working copy root", "Unity project");
                                    if (!useBranchRoot)
                                    {
                                        localPath = WiseSVNIntegration.ProjectRoot;
                                        targetUrl = branchProject.UnityProjectURL;
                                    }
                                }

                                SVNContextMenusManager.Switch(localPath, targetUrl);
                                EditorApplication.Exit(0);
                            }
                        }

                        if (branchSelected)
                        {
                            var menu = new GenericMenu();

                            var prevValue = BranchContextMenu.CopyBranchName;
                            foreach (var value in System.Enum.GetValues(typeof(BranchContextMenu)).OfType <BranchContextMenu>())
                            {
                                if ((int)value / 10 != (int)prevValue / 10)
                                {
                                    menu.AddSeparator("");
                                }

                                menu.AddItem(new GUIContent(ObjectNames.NicifyVariableName(value.ToString())), false, OnSelectBranchOption, new KeyValuePair <BranchContextMenu, BranchProject>(value, branchProject));
                                prevValue = value;
                            }

                            menu.ShowAsContext();
                        }
                    }

                    var rect = EditorGUILayout.GetControlRect(GUILayout.ExpandWidth(true), GUILayout.Height(1f));
                    EditorGUI.DrawRect(rect, Color.black);
                }
            }
        }
コード例 #6
0
        private void OnGUI()
        {
            string      downloadRepositoryChangesHint = "Work online - will ask the repository if there are any changes on the server.\nEnabling this will show locks and out of date additional icons.\nRefreshes might be slower due to the network communication, but shouldn't slow down your editor.";
            const float labelWidthAdd = 40;

            EditorGUIUtility.labelWidth += labelWidthAdd;

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField("Save changes:", EditorStyles.boldLabel);

                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Close", GUILayout.MaxWidth(60f)))
                {
                    GUI.FocusControl("");
                    Close();
                    EditorGUIUtility.ExitGUI();
                }

                var prevColor = GUI.backgroundColor;
                GUI.backgroundColor = Color.green / 1.2f;
                if (GUILayout.Button("Save All", GUILayout.MaxWidth(150f)))
                {
                    m_ProjectPrefs.SvnCLIPath      = m_ProjectPrefs.SvnCLIPath.Trim();
                    m_ProjectPrefs.SvnCLIPathMacOS = m_ProjectPrefs.SvnCLIPathMacOS.Trim();
                    m_ProjectPrefs.Exclude.RemoveAll(p => string.IsNullOrWhiteSpace(p));

                    SVNPreferencesManager.Instance.SavePreferences(m_PersonalPrefs, m_ProjectPrefs);

                    // When turning on the integration do instant refresh.
                    // Works when editor started with disabled integration. Doing it here to avoid circle dependency.
                    if (m_PersonalPrefs.EnableCoreIntegration)
                    {
                        SVNStatusesDatabase.Instance.InvalidateDatabase();
                    }
                }
                GUI.backgroundColor = prevColor;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Personal Preferences:", EditorStyles.boldLabel);
            {
                EditorGUILayout.HelpBox("Hint: check the the tooltips.", MessageType.Info);

                m_PersonalPrefs.EnableCoreIntegration = EditorGUILayout.Toggle("Enable SVN integration", m_PersonalPrefs.EnableCoreIntegration);

                EditorGUI.BeginDisabledGroup(!m_PersonalPrefs.EnableCoreIntegration);

                m_PersonalPrefs.PopulateStatusesDatabase = EditorGUILayout.Toggle(new GUIContent("Enable overlay icons", "Enables overlay icons in the project windows.\nPopulates internal cache with statuses of changed entities.\nFile changes may trigger repopulation of the cache."), m_PersonalPrefs.PopulateStatusesDatabase);
                EditorGUI.BeginDisabledGroup(!m_PersonalPrefs.PopulateStatusesDatabase);

                m_PersonalPrefs.AutoRefreshDatabaseInterval = EditorGUILayout.IntField(new GUIContent("Overlay icons refresh interval", "How much seconds to wait for the next overlay icons refresh.\nNOTE: -1 will deactivate it - only file changes will trigger refresh."), m_PersonalPrefs.AutoRefreshDatabaseInterval);

                m_PersonalPrefs.DownloadRepositoryChanges =
                    (SVNPreferencesManager.BoolPreference)EditorGUILayout.EnumPopup(
                        new GUIContent("Check for repository changes", downloadRepositoryChangesHint + "\n\nNOTE: this will override the project setting. Coordinate this with your team.")
                        , m_PersonalPrefs.DownloadRepositoryChanges);

                EditorGUI.EndDisabledGroup();

                m_PersonalPrefs.ContextMenusClient = (ContextMenusClient)EditorGUILayout.EnumPopup(new GUIContent("Context menus client", "Select what client should be used with the context menus."), m_PersonalPrefs.ContextMenusClient);
                if (GUI.changed)
                {
                    var errorMsg = SVNContextMenusManager.IsCurrentlySupported(m_PersonalPrefs.ContextMenusClient);
                    if (!string.IsNullOrEmpty(errorMsg))
                    {
                        EditorUtility.DisplayDialog("Context Menus Client Issue", errorMsg, "Ok");
                    }
                }

                m_PersonalPrefs.TraceLogs = (SVNTraceLogs)EditorGUILayout.EnumFlagsField(new GUIContent("Trace logs", "Logs for nerds and debugging."), m_PersonalPrefs.TraceLogs);

                EditorGUI.EndDisabledGroup();
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

            EditorGUILayout.LabelField("Project Preferences:", EditorStyles.boldLabel);
            {
                EditorGUILayout.HelpBox("These settings will be saved in the ProjectSettings folder.\nFeel free to add them to your version control system.\nCoordinate any changes here with your team.", MessageType.Warning);

                m_ProjectPreferencesScroll = EditorGUILayout.BeginScrollView(m_ProjectPreferencesScroll);

                var so = new SerializedObject(this);
                var sp = so.FindProperty("m_ProjectPrefs");

                m_ProjectPrefs.DownloadRepositoryChanges = EditorGUILayout.Toggle(new GUIContent("Check for repository changes", downloadRepositoryChangesHint), m_ProjectPrefs.DownloadRepositoryChanges);

                m_ProjectPrefs.SvnCLIPath      = EditorGUILayout.TextField(new GUIContent("SVN CLI Path", "If you desire to use specific SVN CLI (svn.exe) located in the project, write down its path relative to the root folder."), m_ProjectPrefs.SvnCLIPath);
                m_ProjectPrefs.SvnCLIPathMacOS = EditorGUILayout.TextField(new GUIContent("SVN CLI Path MacOS", "Same as above, but for MacOS."), m_ProjectPrefs.SvnCLIPathMacOS);

                EditorGUILayout.PropertyField(sp.FindPropertyRelative("Exclude"), new GUIContent("Exclude Paths", "Asset paths that will be ignored by the SVN integrations. Use with caution."), true);

                so.ApplyModifiedProperties();

                EditorGUILayout.EndScrollView();
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

            DrawAbout();

            //EditorGUILayout.Space();
            //EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);



            EditorGUILayout.Space();


            EditorGUIUtility.labelWidth -= labelWidthAdd;
        }
コード例 #7
0
        public override void Initialize(bool freshlyCreated)
        {
            var lastModifiedDate = File.Exists(PROJECT_PREFERENCES_PATH)
                                ? File.GetLastWriteTime(PROJECT_PREFERENCES_PATH).Ticks
                                : 0
            ;

            if (freshlyCreated || m_ProjectPrefsLastModifiedTime != lastModifiedDate)
            {
                LoadPreferences();
            }

            if (freshlyCreated || m_RetryTextures)
            {
                LoadTextures();

                m_RetryTextures = false;

                // If WiseSVN was just added to the project, Unity won't manage to load the textures the first time. Try again next frame.
                if (FileStatusIcons[(int)VCFileStatus.Modified].image == null)
                {
                    // We're using a flag as assembly reload may happen and update callback will be lost.
                    m_RetryTextures = true;

                    EditorApplication.CallbackFunction reloadTextures = null;
                    reloadTextures = () => {
                        LoadTextures();
                        m_RetryTextures           = false;
                        EditorApplication.update -= reloadTextures;

                        if (FileStatusIcons[(int)VCFileStatus.Modified].image == null)
                        {
                            Debug.LogWarning("SVN overlay icons are missing.");
                        }
                    };

                    EditorApplication.update += reloadTextures;
                }

                Debug.Log($"Loaded WiseSVN Preferences. WiseSVN is turned {(PersonalPrefs.EnableCoreIntegration ? "on" : "off")}.");

                if (PersonalPrefs.EnableCoreIntegration)
                {
                    var svnError = "";
                    try {
                        svnError = WiseSVNIntegration.CheckForSVNErrors();
                    } catch (Exception ex) {
                        PersonalPrefs.EnableCoreIntegration = false;

                        Debug.LogError($"Calling SVN CLI (Command Line Interface) caused fatal error!\nDisabling WiseSVN integration. Please fix the error and restart Unity.\n{ex}\n\n");
#if UNITY_EDITOR_OSX
                        if (ex is IOException)
                        {
                            Debug.LogError($"If you installed SVN via Brew or similar, you may need to add \"/usr/local/bin\" (or wherever svn binaries can be found) to your PATH environment variable. Example:\nsudo launchctl config user path /usr/local/bin\nAlternatively, you may add relative SVN CLI path in your WiseSVN preferences (\"Assets/SVN/SVN Preferences -> Project\")\n");
                        }
#endif
                    }

                    // svn: warning: W155007: '...' is not a working copy!
                    // This can be returned when project is not a valid svn checkout. (Probably)
                    if (svnError.Contains("W155007"))
                    {
                        Debug.LogError("This project is NOT under version control (not a proper SVN checkout).");

                        // System.ComponentModel.Win32Exception (0x80004005): ApplicationName='...', CommandLine='...', Native error= The system cannot find the file specified.
                        // Could not find the command executable. The user hasn't installed their CLI (Command Line Interface) so we're missing an "svn.exe" in the PATH environment.
                        // This is allowed only if there isn't ProjectPreference specified CLI path.
                    }
                    else if (svnError.Contains("0x80004005"))
                    {
                        Debug.LogError("SVN CLI (Command Line Interface) not found. You need to install it in order for the SVN integration to work properly.");

                        // Any other error.
                    }
                    else if (!string.IsNullOrEmpty(svnError))
                    {
                        Debug.LogError($"SVN command line interface returned this error:\n{svnError}");
                    }
                }
            }

            SVNContextMenusManager.SetupContextType(PersonalPrefs.ContextMenusClient);
        }