first commit
This commit is contained in:
@@ -0,0 +1,439 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
using Codice.Client.Common;
|
||||
using Codice.Client.Common.Threading;
|
||||
using Codice.CM.Common;
|
||||
using PlasticGui;
|
||||
using PlasticGui.WorkspaceWindow.Home.Repositories;
|
||||
using PlasticGui.WebApi;
|
||||
using PlasticGui.WorkspaceWindow.Servers;
|
||||
using Unity.PlasticSCM.Editor.Tool;
|
||||
using Unity.PlasticSCM.Editor.UI;
|
||||
using Unity.PlasticSCM.Editor.UI.Progress;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.Views.CreateWorkspace.Dialogs
|
||||
{
|
||||
internal class CreateRepositoryDialog :
|
||||
PlasticDialog,
|
||||
KnownServersListOperations.IKnownServersList
|
||||
{
|
||||
protected override Rect DefaultRect
|
||||
{
|
||||
get
|
||||
{
|
||||
var baseRect = base.DefaultRect;
|
||||
return new Rect(baseRect.x, baseRect.y, 600, 340);
|
||||
}
|
||||
}
|
||||
|
||||
internal static RepositoryCreationData CreateRepository(
|
||||
EditorWindow parentWindow,
|
||||
IPlasticWebRestApi plasticWebRestApi,
|
||||
string proposedRepositoryName,
|
||||
string proposedServer,
|
||||
string lastUsedRepServer,
|
||||
string clientConfServer)
|
||||
{
|
||||
string server = CreateRepositoryDialogUserAssistant.GetProposedServer(
|
||||
proposedServer, lastUsedRepServer, clientConfServer);
|
||||
|
||||
CreateRepositoryDialog dialog = Create(
|
||||
plasticWebRestApi,
|
||||
new ProgressControlsForDialogs(),
|
||||
proposedRepositoryName,
|
||||
server);
|
||||
|
||||
ResponseType dialogResult = dialog.RunModal(parentWindow);
|
||||
bool dialogResultOk = dialogResult == ResponseType.Ok;
|
||||
|
||||
RepositoryCreationData result = dialogResultOk ? dialog.BuildCreationData() : new RepositoryCreationData();
|
||||
result.Result = dialogResultOk;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override void OnModalGUI()
|
||||
{
|
||||
Title(PlasticLocalization.Name.NewRepositoryTitle.GetString());
|
||||
|
||||
Paragraph(PlasticLocalization.Name.NewRepositoryExplanation.GetString());
|
||||
|
||||
Paragraph(PlasticLocalization.Name.CreateRepositoryDialogDetailedExplanation.GetString());
|
||||
|
||||
if (Event.current.type == EventType.Layout)
|
||||
{
|
||||
mProgressControls.ProgressData.CopyInto(mProgressData);
|
||||
}
|
||||
|
||||
GUILayout.Space(5);
|
||||
|
||||
DoEntriesArea();
|
||||
|
||||
DrawProgressForDialogs.For(mProgressControls.ProgressData);
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
DoButtonsArea();
|
||||
|
||||
mProgressControls.ForcedUpdateProgress(this);
|
||||
}
|
||||
|
||||
protected override string GetTitle()
|
||||
{
|
||||
return PlasticLocalization.Name.NewRepositoryTitle.GetString();
|
||||
}
|
||||
|
||||
void KnownServersListOperations.IKnownServersList.FillValues(List<string> knownServers)
|
||||
{
|
||||
// Filter out local server if there is no local installation
|
||||
// TODO Remove if a unified solution is applied to the unityplastic library
|
||||
if (knownServers.Contains(LocalOnlyServer.Alias) && !IsExeAvailable.ForLocalServer())
|
||||
{
|
||||
knownServers.Remove(LocalOnlyServer.Alias);
|
||||
}
|
||||
|
||||
mKnownServers = knownServers.Select(ResolveServer.ToDisplayString).ToList();
|
||||
mKnownServers.Sort();
|
||||
|
||||
OnServerSelected(mSelectedServer);
|
||||
}
|
||||
|
||||
void DoEntriesArea()
|
||||
{
|
||||
mRepositoryName = TextEntry(
|
||||
PlasticLocalization.Name.RepositoryNameShortLabel.GetString(),
|
||||
mRepositoryName,
|
||||
REPONAME_CONTROL_NAME,
|
||||
ENTRY_WIDTH,
|
||||
ENTRY_X);
|
||||
|
||||
if (!mFocusIsAreadySet)
|
||||
{
|
||||
mFocusIsAreadySet = true;
|
||||
GUI.FocusControl(REPONAME_CONTROL_NAME);
|
||||
}
|
||||
|
||||
GUILayout.Space(5);
|
||||
|
||||
mSelectedServer = ComboBox(
|
||||
PlasticLocalization.Name.RepositoryServerOrOrganizationLabel.GetString(),
|
||||
mSelectedServer,
|
||||
mKnownServers,
|
||||
OnServerSelected,
|
||||
ENTRY_WIDTH,
|
||||
ENTRY_X);
|
||||
|
||||
if (OrganizationsInformation.IsUnityOrganization(mSelectedServer) && mKnownServers.Contains(mSelectedServer))
|
||||
{
|
||||
GUILayout.Space(5);
|
||||
|
||||
DoOrganizationProjectsDropdown();
|
||||
DoCreateOrganizationProjectLink();
|
||||
}
|
||||
else
|
||||
{
|
||||
mSelectedProject = null;
|
||||
mCurrentServerProjects = null;
|
||||
}
|
||||
}
|
||||
|
||||
void DoOrganizationProjectsDropdown()
|
||||
{
|
||||
if (mIsLoadingProjects || mSelectedProject == null)
|
||||
{
|
||||
GUI.enabled = false;
|
||||
}
|
||||
|
||||
ComboBox(
|
||||
PlasticLocalization.Name.OrganizationProjectLabel.GetString(),
|
||||
mSelectedProject,
|
||||
mCurrentServerProjects,
|
||||
OnProjectSelected,
|
||||
ENTRY_WIDTH,
|
||||
ENTRY_X);
|
||||
|
||||
GUI.enabled = true;
|
||||
}
|
||||
|
||||
void DoCreateOrganizationProjectLink()
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
if (GUILayout.Button(
|
||||
PlasticLocalization.Name.CreateOrganizationProjectLabel.GetString(),
|
||||
UnityStyles.LinkLabel,
|
||||
GUILayout.Height(20)))
|
||||
{
|
||||
string resolvedServer = OrganizationsInformation.TryResolveServerFromInput(mSelectedServer);
|
||||
|
||||
if (!string.IsNullOrEmpty(resolvedServer))
|
||||
{
|
||||
string organizationName = ServerOrganizationParser.GetOrganizationFromServer(resolvedServer);
|
||||
Application.OpenURL(UnityUrl.UnityDashboard.UnityOrganizations.GetProjectsUrl(organizationName));
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
void OnServerSelected(object server)
|
||||
{
|
||||
((IProgressControls) mProgressControls).HideProgress();
|
||||
mProgressControls.ProgressData.StatusMessage = string.Empty;
|
||||
mProgressControls.ProgressData.StatusType = MessageType.None;
|
||||
|
||||
mIsLoadingProjects = false;
|
||||
|
||||
if (server == null || string.IsNullOrEmpty(server.ToString()))
|
||||
{
|
||||
mSelectedServer = null;
|
||||
mSelectedProject = null;
|
||||
mCurrentServerProjects = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
mSelectedServer = server.ToString();
|
||||
|
||||
// We need to ensure it is a known server because the dropdown is editable
|
||||
if (OrganizationsInformation.IsUnityOrganization(mSelectedServer) && mKnownServers.Contains(mSelectedServer))
|
||||
{
|
||||
LoadServerProjects(mSelectedServer);
|
||||
}
|
||||
else
|
||||
{
|
||||
mSelectedProject = null;
|
||||
}
|
||||
|
||||
Repaint();
|
||||
}
|
||||
|
||||
void OnFocus()
|
||||
{
|
||||
OnServerSelected(mSelectedServer);
|
||||
}
|
||||
|
||||
void OnProjectSelected(object project)
|
||||
{
|
||||
mSelectedProject = project.ToString();
|
||||
|
||||
Repaint();
|
||||
}
|
||||
|
||||
void LoadServerProjects(string server)
|
||||
{
|
||||
mIsLoadingProjects = true;
|
||||
mCurrentServerProjects = null;
|
||||
|
||||
((IProgressControls) mProgressControls).ShowProgress(
|
||||
PlasticLocalization.Name.RetrievingServerProjects.GetString());
|
||||
|
||||
List<string> serverProjects = null;
|
||||
|
||||
IThreadWaiter waiter = ThreadWaiter.GetWaiter();
|
||||
waiter.Execute(
|
||||
/*threadOperationDelegate*/ delegate
|
||||
{
|
||||
string serverName = ResolveServer.FromUserInput(server, CmConnection.Get().UnityOrgResolver);
|
||||
|
||||
serverProjects = OrganizationsInformation.GetOrganizationProjects(serverName);
|
||||
},
|
||||
/*afterOperationDelegate*/ delegate
|
||||
{
|
||||
mIsLoadingProjects = false;
|
||||
|
||||
if (waiter.Exception != null)
|
||||
{
|
||||
((IProgressControls) mProgressControls).ShowError(
|
||||
PlasticLocalization.Name.ErrorRetrievingServerProjects.GetString());
|
||||
}
|
||||
|
||||
mCurrentServerProjects = serverProjects;
|
||||
|
||||
if (mCurrentServerProjects == null || mCurrentServerProjects.Count == 0)
|
||||
{
|
||||
mSelectedProject = null;
|
||||
mProposedProject = null;
|
||||
|
||||
((IProgressControls) mProgressControls).ShowError(
|
||||
PlasticLocalization.Name.NoServerProjectsFound.GetString());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(mProposedProject))
|
||||
{
|
||||
mSelectedProject = mProposedProject;
|
||||
mProposedProject = null;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(mSelectedProject) || !mCurrentServerProjects.Contains(mSelectedProject))
|
||||
{
|
||||
mSelectedProject = mCurrentServerProjects.First();
|
||||
}
|
||||
|
||||
((IProgressControls) mProgressControls).HideProgress();
|
||||
});
|
||||
}
|
||||
|
||||
void DoButtonsArea()
|
||||
{
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
if (Application.platform == RuntimePlatform.WindowsEditor)
|
||||
{
|
||||
DoOkButton();
|
||||
DoCancelButton();
|
||||
return;
|
||||
}
|
||||
|
||||
DoCancelButton();
|
||||
DoOkButton();
|
||||
}
|
||||
}
|
||||
|
||||
void DoOkButton()
|
||||
{
|
||||
if (mIsLoadingProjects ||
|
||||
(OrganizationsInformation.IsUnityOrganization(mSelectedServer) && string.IsNullOrEmpty(mSelectedProject)))
|
||||
{
|
||||
GUI.enabled = false;
|
||||
}
|
||||
|
||||
if (AcceptButton(PlasticLocalization.Name.OkButton.GetString()))
|
||||
{
|
||||
OkButtonWithValidationAction();
|
||||
}
|
||||
|
||||
GUI.enabled = true;
|
||||
}
|
||||
|
||||
void DoCancelButton()
|
||||
{
|
||||
if (!NormalButton(PlasticLocalization.Name.CancelButton.GetString()))
|
||||
return;
|
||||
|
||||
CancelButtonAction();
|
||||
}
|
||||
|
||||
void OkButtonWithValidationAction()
|
||||
{
|
||||
// If the validation goes OK, this method closes the dialog
|
||||
RepositoryCreationValidation.AsyncValidation(
|
||||
BuildCreationData(),
|
||||
this,
|
||||
mProgressControls);
|
||||
}
|
||||
|
||||
void OnEnterKeyAction()
|
||||
{
|
||||
if (!OrganizationsInformation.IsUnityOrganization(mSelectedServer))
|
||||
{
|
||||
OkButtonWithValidationAction();
|
||||
return;
|
||||
}
|
||||
|
||||
if (mKnownServers.Contains(mSelectedServer))
|
||||
{
|
||||
if (string.IsNullOrEmpty(mSelectedProject))
|
||||
{
|
||||
OnServerSelected(mSelectedServer);
|
||||
}
|
||||
else
|
||||
{
|
||||
OkButtonWithValidationAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RepositoryCreationData BuildCreationData()
|
||||
{
|
||||
string resolvedServer = OrganizationsInformation.TryResolveServerFromInput(mSelectedServer);
|
||||
|
||||
string repositoryName = mSelectedProject != null
|
||||
? string.Format("{0}/{1}", mSelectedProject, mRepositoryName)
|
||||
: mRepositoryName;
|
||||
|
||||
return new RepositoryCreationData(
|
||||
repositoryName,
|
||||
resolvedServer != null ? resolvedServer : mSelectedServer);
|
||||
}
|
||||
|
||||
static CreateRepositoryDialog Create(
|
||||
IPlasticWebRestApi plasticWebRestApi,
|
||||
ProgressControlsForDialogs progressControls,
|
||||
string proposedRepositoryName,
|
||||
string proposedServer)
|
||||
{
|
||||
var instance = CreateInstance<CreateRepositoryDialog>();
|
||||
instance.mEnterKeyAction = instance.OnEnterKeyAction;
|
||||
instance.mEscapeKeyAction = instance.CancelButtonAction;
|
||||
instance.mPlasticWebRestApi = plasticWebRestApi;
|
||||
instance.mProgressControls = progressControls;
|
||||
instance.BuildComponents(proposedRepositoryName, proposedServer);
|
||||
return instance;
|
||||
}
|
||||
|
||||
void BuildComponents(string proposedRepositoryName, string proposedServer)
|
||||
{
|
||||
mSelectedServer = ResolveServer.ToDisplayString(proposedServer);
|
||||
mRepositoryName = proposedRepositoryName;
|
||||
|
||||
if (OrganizationsInformation.IsUnityOrganization(proposedServer))
|
||||
{
|
||||
string[] repositoryNameParts = proposedRepositoryName.Split('/');
|
||||
|
||||
if (repositoryNameParts.Length > 1)
|
||||
{
|
||||
mProposedProject = repositoryNameParts[0].Trim();
|
||||
mRepositoryName = repositoryNameParts[repositoryNameParts.Length - 1].Trim();
|
||||
}
|
||||
}
|
||||
|
||||
KnownServersListOperations.GetCombinedServers(
|
||||
true,
|
||||
GetExtraServers(proposedServer),
|
||||
mProgressControls,
|
||||
this,
|
||||
mPlasticWebRestApi,
|
||||
CmConnection.Get().GetProfileManager());
|
||||
}
|
||||
|
||||
static List<string> GetExtraServers(string proposedServer)
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
if (!string.IsNullOrEmpty(proposedServer))
|
||||
result.Add(proposedServer);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
IPlasticWebRestApi mPlasticWebRestApi;
|
||||
bool mFocusIsAreadySet;
|
||||
|
||||
string mRepositoryName;
|
||||
string mSelectedServer;
|
||||
string mSelectedProject;
|
||||
string mProposedProject;
|
||||
bool mIsLoadingProjects;
|
||||
List<string> mCurrentServerProjects;
|
||||
|
||||
List<string> mKnownServers = new List<string>();
|
||||
|
||||
ProgressControlsForDialogs.Data mProgressData = new ProgressControlsForDialogs.Data();
|
||||
|
||||
ProgressControlsForDialogs mProgressControls;
|
||||
|
||||
const float ENTRY_WIDTH = 400;
|
||||
const float ENTRY_X = 175f;
|
||||
const string REPONAME_CONTROL_NAME = "CreateRepositoryDialog.RepositoryName";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61f74d0a8a3f1f542b8afe99e65686df
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
using PlasticGui;
|
||||
using Unity.PlasticSCM.Editor.UI.Tree;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.Views.CreateWorkspace.Dialogs
|
||||
{
|
||||
internal enum RepositoriesListColumn
|
||||
{
|
||||
Name,
|
||||
Server
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class RepositoriesListHeaderState : MultiColumnHeaderState, ISerializationCallbackReceiver
|
||||
{
|
||||
internal static RepositoriesListHeaderState GetDefault()
|
||||
{
|
||||
return new RepositoriesListHeaderState(BuildColumns());
|
||||
}
|
||||
|
||||
internal static List<string> GetColumnNames()
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.NameColumn));
|
||||
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.ServerColumn));
|
||||
return result;
|
||||
}
|
||||
|
||||
static string GetColumnName(RepositoriesListColumn column)
|
||||
{
|
||||
switch (column)
|
||||
{
|
||||
case RepositoriesListColumn.Name:
|
||||
return PlasticLocalization.GetString(PlasticLocalization.Name.NameColumn);
|
||||
case RepositoriesListColumn.Server:
|
||||
return PlasticLocalization.GetString(PlasticLocalization.Name.ServerColumn);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void ISerializationCallbackReceiver.OnAfterDeserialize()
|
||||
{
|
||||
if (mHeaderTitles != null)
|
||||
TreeHeaderColumns.SetTitles(columns, mHeaderTitles);
|
||||
}
|
||||
|
||||
void ISerializationCallbackReceiver.OnBeforeSerialize()
|
||||
{
|
||||
}
|
||||
|
||||
static Column[] BuildColumns()
|
||||
{
|
||||
return new Column[]
|
||||
{
|
||||
new Column()
|
||||
{
|
||||
width = 320,
|
||||
headerContent = new GUIContent(
|
||||
GetColumnName(RepositoriesListColumn.Name)),
|
||||
minWidth = 200,
|
||||
allowToggleVisibility = false,
|
||||
sortingArrowAlignment = TextAlignment.Right
|
||||
},
|
||||
new Column()
|
||||
{
|
||||
width = 200,
|
||||
headerContent = new GUIContent(
|
||||
GetColumnName(RepositoriesListColumn.Server)),
|
||||
minWidth = 200,
|
||||
allowToggleVisibility = false,
|
||||
sortingArrowAlignment = TextAlignment.Right
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
RepositoriesListHeaderState(Column[] columns)
|
||||
: base(columns)
|
||||
{
|
||||
if (mHeaderTitles == null)
|
||||
mHeaderTitles = TreeHeaderColumns.GetTitles(columns);
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
string[] mHeaderTitles;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da6a50477d2d7ff4f81d1c21c58a5b0e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,252 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Codice.Client.Common;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
using Codice.CM.Common;
|
||||
using PlasticGui;
|
||||
using PlasticGui.WorkspaceWindow.Home.Repositories;
|
||||
using Unity.PlasticSCM.Editor.UI;
|
||||
using Unity.PlasticSCM.Editor.UI.Tree;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.Views.CreateWorkspace.Dialogs
|
||||
{
|
||||
internal class RepositoriesListView :
|
||||
TreeView,
|
||||
IPlasticTable<RepositoryInfo>
|
||||
{
|
||||
internal RepositoriesListView(
|
||||
RepositoriesListHeaderState headerState,
|
||||
List<string> columnNames,
|
||||
Action doubleClickAction)
|
||||
: base(new TreeViewState())
|
||||
{
|
||||
mColumnNames = columnNames;
|
||||
mDoubleClickAction = doubleClickAction;
|
||||
|
||||
multiColumnHeader = new MultiColumnHeader(headerState);
|
||||
multiColumnHeader.canSort = true;
|
||||
multiColumnHeader.sortingChanged += SortingChanged;
|
||||
|
||||
mColumnComparers = RepositoriesTableDefinition.BuildColumnComparers();
|
||||
|
||||
rowHeight = UnityConstants.TREEVIEW_ROW_HEIGHT;
|
||||
showAlternatingRowBackgrounds = false;
|
||||
}
|
||||
|
||||
public override IList<TreeViewItem> GetRows()
|
||||
{
|
||||
return mRows;
|
||||
}
|
||||
|
||||
protected override TreeViewItem BuildRoot()
|
||||
{
|
||||
return new TreeViewItem(0, -1, string.Empty);
|
||||
}
|
||||
|
||||
protected override IList<TreeViewItem> BuildRows(
|
||||
TreeViewItem rootItem)
|
||||
{
|
||||
RegenerateRows(
|
||||
this, mRepositories, rootItem, mRows);
|
||||
|
||||
return mRows;
|
||||
}
|
||||
|
||||
protected override void SearchChanged(string newSearch)
|
||||
{
|
||||
Refilter();
|
||||
|
||||
Sort();
|
||||
|
||||
Reload();
|
||||
|
||||
TableViewOperations.ScrollToSelection(this);
|
||||
}
|
||||
|
||||
protected override void DoubleClickedItem(int id)
|
||||
{
|
||||
mDoubleClickAction();
|
||||
}
|
||||
|
||||
protected override void BeforeRowsGUI()
|
||||
{
|
||||
int firstRowVisible;
|
||||
int lastRowVisible;
|
||||
GetFirstAndLastVisibleRows(out firstRowVisible, out lastRowVisible);
|
||||
|
||||
GUI.DrawTexture(new Rect(0,
|
||||
firstRowVisible * rowHeight,
|
||||
GetRowRect(0).width,
|
||||
(lastRowVisible * rowHeight) + 1000),
|
||||
Images.GetTreeviewBackgroundTexture());
|
||||
|
||||
DrawTreeViewItem.InitializeStyles();
|
||||
base.BeforeRowsGUI();
|
||||
}
|
||||
|
||||
protected override void RowGUI(RowGUIArgs args)
|
||||
{
|
||||
if (args.item is RepositoryListViewItem)
|
||||
{
|
||||
RepositoryListViewItemGUI(
|
||||
(RepositoryListViewItem)args.item,
|
||||
args,
|
||||
rowHeight);
|
||||
return;
|
||||
}
|
||||
|
||||
base.RowGUI(args);
|
||||
}
|
||||
|
||||
internal string GetSelectedRepository()
|
||||
{
|
||||
IList<TreeViewItem> selectedItems = FindRows(GetSelection());
|
||||
|
||||
if (selectedItems.Count == 0)
|
||||
return null;
|
||||
|
||||
return ((RepositoryListViewItem) selectedItems[0])
|
||||
.Repository.GetRepSpec().ToDisplayString();
|
||||
}
|
||||
|
||||
void IPlasticTable<RepositoryInfo>.FillEntriesAndSelectRows(
|
||||
IList<RepositoryInfo> entries,
|
||||
List<RepositoryInfo> entriesToSelect,
|
||||
string currentFilter)
|
||||
{
|
||||
mUnfilteredRepositories = entries;
|
||||
|
||||
Refilter();
|
||||
|
||||
Sort();
|
||||
|
||||
Reload();
|
||||
}
|
||||
|
||||
void Refilter()
|
||||
{
|
||||
mRepositories = RepositoriesTableDefinition.TableFilter.Filter(
|
||||
searchString,
|
||||
mUnfilteredRepositories);
|
||||
}
|
||||
|
||||
void Sort()
|
||||
{
|
||||
int sortedColumnIdx = multiColumnHeader.state.sortedColumnIndex;
|
||||
bool sortAscending = multiColumnHeader.IsSortedAscending(sortedColumnIdx);
|
||||
|
||||
IComparer<RepositoryInfo> comparer = mColumnComparers[
|
||||
mColumnNames[sortedColumnIdx]];
|
||||
|
||||
((List<RepositoryInfo>)mRepositories).Sort(new SortOrderComparer<RepositoryInfo>(
|
||||
comparer, sortAscending));
|
||||
}
|
||||
|
||||
void SortingChanged(MultiColumnHeader multiColumnHeader)
|
||||
{
|
||||
Sort();
|
||||
|
||||
Reload();
|
||||
}
|
||||
|
||||
static void RegenerateRows(
|
||||
RepositoriesListView listView,
|
||||
IList<RepositoryInfo> repositories,
|
||||
TreeViewItem rootItem,
|
||||
List<TreeViewItem> rows)
|
||||
{
|
||||
ClearRows(rootItem, rows);
|
||||
|
||||
if (repositories.Count == 0)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < repositories.Count; i++)
|
||||
{
|
||||
RepositoryListViewItem repositoryListViewItem =
|
||||
new RepositoryListViewItem(i + 1, (RepositoryInfo)repositories[i]);
|
||||
|
||||
rootItem.AddChild(repositoryListViewItem);
|
||||
rows.Add(repositoryListViewItem);
|
||||
}
|
||||
|
||||
listView.SetSelection(new List<int> { 1 });
|
||||
}
|
||||
|
||||
static void ClearRows(
|
||||
TreeViewItem rootItem,
|
||||
List<TreeViewItem> rows)
|
||||
{
|
||||
if (rootItem.hasChildren)
|
||||
rootItem.children.Clear();
|
||||
|
||||
rows.Clear();
|
||||
}
|
||||
|
||||
static void RepositoryListViewItemGUI(
|
||||
RepositoryListViewItem item,
|
||||
RowGUIArgs args,
|
||||
float rowHeight)
|
||||
{
|
||||
for (int visibleColumnIdx = 0; visibleColumnIdx < args.GetNumVisibleColumns(); visibleColumnIdx++)
|
||||
{
|
||||
Rect cellRect = args.GetCellRect(visibleColumnIdx);
|
||||
|
||||
RepositoriesListColumn column =
|
||||
(RepositoriesListColumn)args.GetColumn(visibleColumnIdx);
|
||||
|
||||
RepositoryListViewItemCellGUI(
|
||||
cellRect,
|
||||
item,
|
||||
column,
|
||||
rowHeight,
|
||||
args.selected,
|
||||
args.focused);
|
||||
}
|
||||
}
|
||||
|
||||
static void RepositoryListViewItemCellGUI(
|
||||
Rect rect,
|
||||
RepositoryListViewItem item,
|
||||
RepositoriesListColumn column,
|
||||
float rowHeight,
|
||||
bool isSelected,
|
||||
bool isFocused)
|
||||
{
|
||||
if (column == RepositoriesListColumn.Name)
|
||||
{
|
||||
DrawTreeViewItem.ForItemCell(
|
||||
rect,
|
||||
rowHeight,
|
||||
0,
|
||||
Images.GetRepositoryIcon(),
|
||||
null,
|
||||
item.Repository.Name,
|
||||
isSelected,
|
||||
isFocused,
|
||||
false,
|
||||
false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
DrawTreeViewItem.ForSecondaryLabel(
|
||||
rect,
|
||||
item.ServerDisplayName,
|
||||
isSelected,
|
||||
isFocused,
|
||||
false);
|
||||
}
|
||||
|
||||
List<TreeViewItem> mRows = new List<TreeViewItem>();
|
||||
|
||||
IList<RepositoryInfo> mUnfilteredRepositories = new List<RepositoryInfo>();
|
||||
IList<RepositoryInfo> mRepositories = new List<RepositoryInfo>();
|
||||
|
||||
readonly Dictionary<string, IComparer<RepositoryInfo>> mColumnComparers;
|
||||
readonly List<string> mColumnNames;
|
||||
readonly Action mDoubleClickAction;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c18598e9d808edb4583a6aa724ffc268
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,347 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
using Codice.Client.Common;
|
||||
using Codice.CM.Common;
|
||||
using PlasticGui;
|
||||
using PlasticGui.WorkspaceWindow.Home.Repositories;
|
||||
using PlasticGui.WebApi;
|
||||
using PlasticGui.WorkspaceWindow.Servers;
|
||||
using Unity.PlasticSCM.Editor.Tool;
|
||||
using Unity.PlasticSCM.Editor.UI;
|
||||
using Unity.PlasticSCM.Editor.UI.Progress;
|
||||
using Unity.PlasticSCM.Editor.UI.Tree;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.Views.CreateWorkspace.Dialogs
|
||||
{
|
||||
internal class RepositoryExplorerDialog :
|
||||
PlasticDialog,
|
||||
KnownServersListOperations.IKnownServersList,
|
||||
FillRepositoriesTable.IGetFilterText
|
||||
{
|
||||
protected override Rect DefaultRect
|
||||
{
|
||||
get
|
||||
{
|
||||
var baseRect = base.DefaultRect;
|
||||
return new Rect(baseRect.x, baseRect.y, 750, 450);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string BrowseRepository(
|
||||
EditorWindow parentWindow,
|
||||
IPlasticWebRestApi plasticWebRestApi,
|
||||
string defaultServer)
|
||||
{
|
||||
RepositoryExplorerDialog dialog = Create(
|
||||
plasticWebRestApi,
|
||||
new ProgressControlsForDialogs(),
|
||||
defaultServer,
|
||||
new UnityPlasticGuiMessage());
|
||||
|
||||
ResponseType dialogResult = dialog.RunModal(parentWindow);
|
||||
|
||||
if (dialogResult != ResponseType.Ok)
|
||||
return null;
|
||||
|
||||
return dialog.mRepositoriesListView.GetSelectedRepository();
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
mSearchField.downOrUpArrowKeyPressed -=
|
||||
SearchField_OnDownOrUpArrowKeyPressed;
|
||||
}
|
||||
|
||||
protected override void SaveSettings()
|
||||
{
|
||||
TreeHeaderSettings.Save(
|
||||
mRepositoriesListView.multiColumnHeader.state,
|
||||
UnityConstants.REPOSITORIES_TABLE_SETTINGS_NAME);
|
||||
}
|
||||
|
||||
protected override void OnModalGUI()
|
||||
{
|
||||
Title(PlasticLocalization.GetString(PlasticLocalization.Name.ChooseRepositoryTitle));
|
||||
|
||||
Paragraph(PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.SelectRepositoryBelow));
|
||||
|
||||
if (Event.current.type == EventType.Layout)
|
||||
{
|
||||
mProgressControls.ProgressData.CopyInto(
|
||||
mState.ProgressData);
|
||||
}
|
||||
|
||||
bool isEnabled = !mProgressControls.ProgressData.IsWaitingAsyncResult;
|
||||
|
||||
DoToolbarArea(
|
||||
mSearchField,
|
||||
mRepositoriesListView,
|
||||
isEnabled,
|
||||
Refresh,
|
||||
OnServerSelected,
|
||||
ref mState);
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
DoListArea(
|
||||
mRepositoriesListView,
|
||||
isEnabled);
|
||||
|
||||
DrawProgressForDialogs.For(
|
||||
mProgressControls.ProgressData);
|
||||
|
||||
DoButtonsArea();
|
||||
|
||||
mProgressControls.ForcedUpdateProgress(this);
|
||||
}
|
||||
|
||||
protected override string GetTitle()
|
||||
{
|
||||
return PlasticLocalization.GetString(PlasticLocalization.Name.ExploreRepositories);
|
||||
}
|
||||
|
||||
void SearchField_OnDownOrUpArrowKeyPressed()
|
||||
{
|
||||
mRepositoriesListView.SetFocusAndEnsureSelectedItem();
|
||||
}
|
||||
|
||||
void Refresh()
|
||||
{
|
||||
string resolvedServer = OrganizationsInformation.TryResolveServerFromInput(mState.SelectedServer);
|
||||
|
||||
// Even if the server input cannot be resolved, we still want to fill the table so it gets reset
|
||||
mFillRepositoriesTable.FillTable(
|
||||
mRepositoriesListView,
|
||||
null,
|
||||
mProgressControls,
|
||||
null,
|
||||
new FillRepositoriesTable.SaveLastUsedServer(true),
|
||||
mGuiMessage,
|
||||
null,
|
||||
null,
|
||||
this,
|
||||
resolvedServer != null ? resolvedServer : mState.SelectedServer,
|
||||
false,
|
||||
false,
|
||||
true);
|
||||
}
|
||||
|
||||
void KnownServersListOperations.IKnownServersList.FillValues(List<string> knownServers)
|
||||
{
|
||||
// Filter out local server if there is no local installation
|
||||
// TODO Remove if a unified solution is applied to the unityplastic library
|
||||
if (knownServers.Contains(LocalOnlyServer.Alias) && !IsExeAvailable.ForLocalServer())
|
||||
{
|
||||
knownServers.Remove(LocalOnlyServer.Alias);
|
||||
}
|
||||
|
||||
mState.AvailableServers = knownServers.Select(ResolveServer.ToDisplayString).ToList();
|
||||
mState.AvailableServers.Sort();
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
string FillRepositoriesTable.IGetFilterText.Get()
|
||||
{
|
||||
return mRepositoriesListView.searchString;
|
||||
}
|
||||
|
||||
void OnServerSelected(object server)
|
||||
{
|
||||
mState.SelectedServer = server.ToString();
|
||||
|
||||
Repaint();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
static void DoToolbarArea(
|
||||
SearchField searchField,
|
||||
RepositoriesListView listView,
|
||||
bool isEnabled,
|
||||
Action refreshAction,
|
||||
GenericMenu.MenuFunction2 selectServerAction,
|
||||
ref State state)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
GUILayout.Label(
|
||||
PlasticLocalization.GetString(PlasticLocalization.Name.RepositoryExplorerServerLabel));
|
||||
|
||||
GUI.enabled = isEnabled;
|
||||
|
||||
state.SelectedServer = DoDropDownTextField(
|
||||
state.SelectedServer,
|
||||
state.AvailableServers,
|
||||
selectServerAction,
|
||||
refreshAction);
|
||||
|
||||
var refreshText = PlasticLocalization.GetString(PlasticLocalization.Name.RefreshButton);
|
||||
if (GUILayout.Button(refreshText, EditorStyles.miniButton))
|
||||
refreshAction();
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
DrawSearchField.For(searchField, listView, SEARCH_FIELD_WIDTH);
|
||||
|
||||
GUI.enabled = true;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
static void DoListArea(
|
||||
RepositoriesListView listView,
|
||||
bool isEnabled)
|
||||
{
|
||||
GUI.enabled = isEnabled;
|
||||
|
||||
Rect treeRect = GUILayoutUtility.GetRect(0, 100000, 0, 100000);
|
||||
|
||||
listView.OnGUI(treeRect);
|
||||
|
||||
GUI.enabled = true;
|
||||
}
|
||||
|
||||
static string DoDropDownTextField(
|
||||
string text,
|
||||
List<string> options,
|
||||
GenericMenu.MenuFunction2 selectServerAction,
|
||||
Action enterKeyAction)
|
||||
{
|
||||
bool isEnterKeyPressed = false;
|
||||
|
||||
Event e = Event.current;
|
||||
|
||||
if (Keyboard.IsReturnOrEnterKeyPressed(e))
|
||||
{
|
||||
isEnterKeyPressed = true;
|
||||
}
|
||||
|
||||
string result = DropDownTextField.DoDropDownTextField(
|
||||
text,
|
||||
DROPDOWN_CONTROL_NAME,
|
||||
options,
|
||||
selectServerAction,
|
||||
GUILayout.Width(DROPDOWN_WIDTH));
|
||||
|
||||
if (isEnterKeyPressed && GUI.GetNameOfFocusedControl() == DROPDOWN_CONTROL_NAME)
|
||||
{
|
||||
e.Use();
|
||||
enterKeyAction();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void DoButtonsArea()
|
||||
{
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
if (Application.platform == RuntimePlatform.WindowsEditor)
|
||||
{
|
||||
DoOkButton();
|
||||
DoCancelButton();
|
||||
return;
|
||||
}
|
||||
|
||||
DoCancelButton();
|
||||
DoOkButton();
|
||||
}
|
||||
}
|
||||
|
||||
void DoOkButton()
|
||||
{
|
||||
if (!AcceptButton(PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.OkButton)))
|
||||
return;
|
||||
|
||||
OkButtonAction();
|
||||
}
|
||||
|
||||
void DoCancelButton()
|
||||
{
|
||||
if (!NormalButton(PlasticLocalization.GetString(
|
||||
PlasticLocalization.Name.CancelButton)))
|
||||
return;
|
||||
|
||||
CancelButtonAction();
|
||||
}
|
||||
|
||||
static RepositoryExplorerDialog Create(
|
||||
IPlasticWebRestApi plasticWebRestApi,
|
||||
ProgressControlsForDialogs progressControls,
|
||||
string defaultServer,
|
||||
GuiMessage.IGuiMessage guiMessage)
|
||||
{
|
||||
var instance = CreateInstance<RepositoryExplorerDialog>();
|
||||
instance.mGuiMessage = guiMessage;
|
||||
instance.mEscapeKeyAction = instance.CancelButtonAction;
|
||||
instance.mProgressControls = progressControls;
|
||||
instance.BuildComponents(defaultServer, plasticWebRestApi);
|
||||
return instance;
|
||||
}
|
||||
|
||||
void BuildComponents(
|
||||
string defaultServer,
|
||||
IPlasticWebRestApi plasticWebRestApi)
|
||||
{
|
||||
mSearchField = new SearchField();
|
||||
mSearchField.downOrUpArrowKeyPressed += SearchField_OnDownOrUpArrowKeyPressed;
|
||||
|
||||
RepositoriesListHeaderState headerState =
|
||||
RepositoriesListHeaderState.GetDefault();
|
||||
TreeHeaderSettings.Load(headerState,
|
||||
UnityConstants.REPOSITORIES_TABLE_SETTINGS_NAME,
|
||||
(int)RepositoriesListColumn.Name);
|
||||
|
||||
mRepositoriesListView = new RepositoriesListView(
|
||||
headerState,
|
||||
RepositoriesListHeaderState.GetColumnNames(),
|
||||
OkButtonAction);
|
||||
mRepositoriesListView.Reload();
|
||||
|
||||
mFillRepositoriesTable = new FillRepositoriesTable(
|
||||
new LocalRepositoriesProvider());
|
||||
|
||||
mState = new State()
|
||||
{
|
||||
SelectedServer = ResolveServer.ToDisplayString(defaultServer),
|
||||
ProgressData = new ProgressControlsForDialogs.Data()
|
||||
};
|
||||
|
||||
KnownServersListOperations.GetCombinedServers(
|
||||
true,
|
||||
new List<string>(),
|
||||
mProgressControls,
|
||||
this,
|
||||
plasticWebRestApi,
|
||||
CmConnection.Get().GetProfileManager());
|
||||
}
|
||||
|
||||
SearchField mSearchField;
|
||||
RepositoriesListView mRepositoriesListView;
|
||||
ProgressControlsForDialogs mProgressControls;
|
||||
FillRepositoriesTable mFillRepositoriesTable;
|
||||
State mState;
|
||||
GuiMessage.IGuiMessage mGuiMessage;
|
||||
|
||||
const string DROPDOWN_CONTROL_NAME = "RepositoryExplorerDialog.ServerDropdown";
|
||||
const float DROPDOWN_WIDTH = 250;
|
||||
const float SEARCH_FIELD_WIDTH = 450;
|
||||
|
||||
class State
|
||||
{
|
||||
internal List<string> AvailableServers { get; set; }
|
||||
internal string SelectedServer { get; set; }
|
||||
internal ProgressControlsForDialogs.Data ProgressData { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b29af44841cd6644e876233cd057bc18
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,23 @@
|
||||
using Codice.Client.Common;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
|
||||
using Codice.CM.Common;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.Views.CreateWorkspace.Dialogs
|
||||
{
|
||||
internal class RepositoryListViewItem : TreeViewItem
|
||||
{
|
||||
internal RepositoryInfo Repository { get; private set; }
|
||||
|
||||
internal string ServerDisplayName { get; private set; }
|
||||
|
||||
internal RepositoryListViewItem(int id, RepositoryInfo repository)
|
||||
: base(id, 0)
|
||||
{
|
||||
Repository = repository;
|
||||
ServerDisplayName = ResolveServer.ToDisplayString(repository.Server);
|
||||
|
||||
displayName = repository.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83882c7718d0fc34f8a05141328ceac1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user