Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [1.3.7] - 2020-01-30
## Changed
- Bulk revert is now supported.
- Collab is blocked in play mode.
## Fixed
- Fixed services window's links to open Collab.
  • Loading branch information
Unity Technologies committed Jan 30, 2020
1 parent d107960 commit fd397cb
Show file tree
Hide file tree
Showing 22 changed files with 248 additions and 107 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.3.7] - 2020-01-30
## Changed
- Bulk revert is now supported.
- Collab is blocked in play mode.
## Fixed
- Fixed services window's links to open Collab.

## [1.3.6] - 2020-01-21
### Fixed
- Fixed compile errors when removing the NUnit package by removing unnecessary references.
Expand Down
2 changes: 1 addition & 1 deletion Editor/Assets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ or `.light` to the line. For example:
```

Documentation about the two file types is provided within the Unity documentation for UiElements:
https://docs.unity3d.com/2019.1/Documentation/Manual/UIElements.html
https://docs.unity3d.com/2020.1/Documentation/Manual/UIElements.html

In general each Component and View will have its own layout file. When adding new components with their uxml factories
the UIElements schema will need to updated within the editor if you want auto completion in your editor. Click
Expand Down
11 changes: 9 additions & 2 deletions Editor/Models/Api/ISourceControlProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,19 @@ internal interface ISourceControlProvider
/// <param name="callback">Callback for the result.</param>
void RequestHistoryCount([NotNull] Action<int?> callback);

/// <summary>
/// Revert the specified file to the state of the current revision.
/// of the source control system, or delete it if it's a new file.
/// </summary>
/// <param name="entry">Entry to discard.</param>
void RequestDiscard([NotNull] IChangeEntry entry);

/// <summary>
/// Revert the specified files to the state of the current revision.
/// of the source control system.
/// </summary>
/// <param name="path">Path of the entry to discard.</param>
void RequestDiscard([NotNull] string path);
/// <param name="paths">List of entries to discard.</param>
void RequestBulkDiscard([NotNull] IReadOnlyList<IChangeEntry> entries);

/// <summary>
/// Diff the changes for the file at the given path.
Expand Down
10 changes: 8 additions & 2 deletions Editor/Models/ChangesModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,15 @@ public void RequestDiffChanges(string path)
}

/// <inheritdoc />
public void RequestDiscard(string path)
public void RequestDiscard(IChangeEntry entry)
{
m_Provider.RequestDiscard(path);
m_Provider.RequestDiscard(entry);
}

/// <inheritdoc />
public void RequestBulkDiscard(IReadOnlyList<IChangeEntry> entries)
{
m_Provider.RequestBulkDiscard(entries);
}

/// <inheritdoc />
Expand Down
12 changes: 9 additions & 3 deletions Editor/Models/IChangesModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,16 @@ internal interface IChangesModel : IModel
void RequestDiffChanges([NotNull] string path);

/// <summary>
/// Request discard of the file and the given path.
/// Request discard of the file at the given path.
/// </summary>
/// <param name="path">Path of the file to discard.</param>
void RequestDiscard([NotNull] string path);
/// <param name="entry">Entry to discard.</param>
void RequestDiscard([NotNull] IChangeEntry entry);

/// <summary>
/// Request discard of the given list of files.
/// </summary>
/// <param name="entries">List of entries to discard.</param>
void RequestBulkDiscard([NotNull] IReadOnlyList<IChangeEntry> entries);

/// <summary>
/// Request publish with the given message and list of files.
Expand Down
43 changes: 41 additions & 2 deletions Editor/Models/Providers/Collab.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
Expand Down Expand Up @@ -549,9 +550,47 @@ public void RequestHistoryCount(Action<int?> callback)
}

/// <inheritdoc />
public void RequestDiscard(string path)
public void RequestDiscard(IChangeEntry entry)
{
instance.RevertFile(path, true);
// Collab cannot revert a new file as it has nothing to go back to. So, instead we delete them.
if (entry.Status == ChangeEntryStatus.Added)
{
File.Delete(entry.Path);
// Notify ADB to refresh since a change has been made.
AssetDatabase.Refresh();
}
else
{
instance.RevertFile(entry.Path, true);
}
}

/// <inheritdoc />
public void RequestBulkDiscard(IReadOnlyList<IChangeEntry> entries)
{
var revertEntries = new List<ChangeItem>();
var deleteOccured = false;
foreach (var entry in entries)
{
// Collab cannot revert a new file as it has nothing to go back to. So, instead we delete them.
if (entry.Status == ChangeEntryStatus.Added)
{
File.Delete(entry.Path);
deleteOccured = true;
}
else
{
revertEntries.Add((ChangeItem)entry.Tag);
}
}

// If a change has been made, notify the ADB to refresh.
if (deleteOccured)
{
AssetDatabase.Refresh();
}

instance.RevertFiles(revertEntries.ToArray(), true);
}

/// <inheritdoc />
Expand Down
45 changes: 21 additions & 24 deletions Editor/Presenters/ChangesPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Unity.Cloud.Collaborate.Assets;
using Unity.Cloud.Collaborate.Components.Menus;
using Unity.Cloud.Collaborate.Models;
using Unity.Cloud.Collaborate.Models.Structures;
using Unity.Cloud.Collaborate.Utilities;
using Unity.Cloud.Collaborate.Views;
using UnityEngine;
Expand Down Expand Up @@ -174,34 +175,29 @@ public void RequestPublish()
}

/// <inheritdoc />
public void RequestDiscard(string path)
public void RequestDiscard(IChangeEntry entry)
{
if (m_View.DisplayDialogue(StringAssets.confirmDiscardChangesTitle,
StringAssets.confirmDiscardChangeMessage, StringAssets.discardChanges,
StringAssets.cancel))
{
m_Model.RequestDiscard(path);
m_Model.RequestDiscard(entry);
}
}

// /// <summary>
// /// Discard all toggled entries. Fire and forget method -- must be called on main thread.
// /// </summary>
// void RequestDiscardToggled()
// {
// Assert.IsTrue(Threading.IsMainThread, "Bulk discard must be down from the main thread.");
//
// // Get with a query can be long running, so run that on a separate thread.
// Task.Run(() => m_Model.GetToggledEntries(m_Model.SavedSearchQuery))
// .ContinueWith(r =>
// {
// // Loop through and discard each one.
// foreach (var entry in r.Result)
// {
// m_Model.RequestDiscard(entry.Entry.Path);
// }
// }, TaskScheduler.FromCurrentSynchronizationContext());
// }
/// <summary>
/// Discard all toggled entries. Fire and forget method -- must be called on main thread.
/// </summary>
void RequestDiscardToggled()
{
var entries = m_Model.GetToggledEntries(m_Model.SavedSearchQuery).Select(e => e.Entry).ToList();
if (m_View.DisplayDialogue(StringAssets.confirmDiscardChangesTitle,
string.Format(StringAssets.confirmDiscardChangesMessage, entries.Count), StringAssets.discardChanges,
StringAssets.cancel))
{
m_Model.RequestBulkDiscard(entries);
}
}

/// <summary>
/// Update the state of the publish button in the view based on the state of the model.
Expand Down Expand Up @@ -254,14 +250,15 @@ public void SetRevisionSummary(string message)
}

/// <inheritdoc />
public int GroupOverflowEntryCount => 0;
public int GroupOverflowEntryCount => 1;

/// <inheritdoc />
public void OnClickGroupOverflow(float x, float y)
{
// new FloatingMenu()
// .SetOpenDirection(MenuUtilities.OpenDirection.DownLeft)
// .Open(x, y);
new FloatingMenu()
.AddEntry(StringAssets.menuDiscardToggledChanges, RequestDiscardToggled, ToggledCount > 0)
.SetOpenDirection(MenuUtilities.OpenDirection.DownLeft)
.Open(x, y);
}

/// <inheritdoc />
Expand Down
5 changes: 3 additions & 2 deletions Editor/Presenters/IChangesPresenter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using JetBrains.Annotations;
using Unity.Cloud.Collaborate.Models.Structures;

namespace Unity.Cloud.Collaborate.Presenters
{
Expand Down Expand Up @@ -41,8 +42,8 @@ internal interface IChangesPresenter : IPresenter
/// <summary>
/// Request a discard for the file at the given path.
/// </summary>
/// <param name="path"></param>
void RequestDiscard([NotNull] string path);
/// <param name="entry">Entry to discard.</param>
void RequestDiscard([NotNull] IChangeEntry entry);

/// <summary>
/// Request a diff of the file at the given path.
Expand Down
15 changes: 14 additions & 1 deletion Editor/UserInterface/Bootstrap.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEditor;
using UnityEditor.Collaboration;
using UnityEngine;

using Unity.Cloud.Collaborate.UserInterface;
Expand All @@ -10,7 +11,19 @@ public class Bootstrap
{
static Bootstrap()
{
Toolbar.AddSubToolbar(new ToolbarButton { Width = 32f });
var toolbar = new ToolbarButton { Width = 32f };
Toolbar.AddSubToolbar(toolbar);
toolbar.Update();

Collab.ShowHistoryWindow += () =>
{
CollaborateWindow.Init(CollaborateWindow.FocusTarget.History);
};

Collab.ShowChangesWindow += () =>
{
CollaborateWindow.Init(CollaborateWindow.FocusTarget.Changes);
};
}
}
}
63 changes: 63 additions & 0 deletions Editor/UserInterface/CollaborateWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ internal class CollaborateWindow : EditorWindow

[MenuItem("Window/Collaborate")]
internal static void Init()
{
Init(FocusTarget.None);
}

internal static void Init(FocusTarget focusTarget)
{
var openLocation = CollabSettingsManager.Get(CollabSettings.settingDefaultOpenLocation, fallback: CollabSettings.OpenLocation.Docked);

Expand All @@ -67,10 +72,15 @@ internal static void Init()
// Display window
window.Show();
window.Focus();
if (focusTarget != FocusTarget.None)
{
window.RequestFocus(focusTarget);
}
}

void OnDisable()
{
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
AssemblyReloadEvents.beforeAssemblyReload -= OnBeforeAssemblyReload;
AssemblyReloadEvents.afterAssemblyReload -= OnAfterAssemblyReload;
m_Provider.UpdatedProjectStatus -= OnUpdatedProjectStatus;
Expand All @@ -79,6 +89,7 @@ void OnDisable()

void OnEnable()
{
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
AssemblyReloadEvents.beforeAssemblyReload += OnBeforeAssemblyReload;
AssemblyReloadEvents.afterAssemblyReload += OnAfterAssemblyReload;

Expand Down Expand Up @@ -116,6 +127,29 @@ void OnEnable()
OnUpdatedProjectStatus(m_Provider.GetProjectStatus());
}

/// <summary>
/// React to the play mode state changing. When in play mode, disable collab.
/// </summary>
/// <param name="state">Editor play mode state.</param>
void OnPlayModeStateChanged(PlayModeStateChange state)
{
bool enabled;
switch (state)
{
case PlayModeStateChange.EnteredEditMode:
case PlayModeStateChange.ExitingEditMode:
enabled = true;
break;
case PlayModeStateChange.EnteredPlayMode:
case PlayModeStateChange.ExitingPlayMode:
enabled = false;
break;
default:
throw new ArgumentOutOfRangeException(nameof(state), state, null);
}
m_ViewContainer.SetEnabled(enabled);
}

/// <summary>
/// Restore window state after assembly reload.
/// </summary>
Expand Down Expand Up @@ -151,6 +185,28 @@ void OnUpdatedProjectStatus(ProjectStatus status)
}
}

void RequestFocus(FocusTarget focusTarget)
{
if (m_ActivePage != m_MainView)
{
// Cannot focus changes or history pane if we're not already on mainview
return;
}

if (focusTarget == FocusTarget.Changes)
{
m_MainView.SetTab(MainPageView.ChangesTabIndex);
}
else if (focusTarget == FocusTarget.History)
{
m_MainView.SetTab(MainPageView.HistoryTabIndex);
}
else
{
Debug.LogError("Collab Error: Attempting to focus unknown target.");
}
}

/// <summary>
/// Switch the view displayed in the window.
/// </summary>
Expand Down Expand Up @@ -187,5 +243,12 @@ enum Display
Error,
Main
}

public enum FocusTarget
{
None,
History,
Changes
}
}
}
Loading

0 comments on commit fd397cb

Please sign in to comment.