Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using SmartAddresser.Editor.Core.Models.Shared.AssetGroups;
using SmartAddresser.Editor.Foundation.CustomDrawers;
Expand All @@ -15,16 +16,20 @@ internal sealed class AssetFilterView : IDisposable
{
private const string RemoveMenuName = "Remove Filter";
private const string MoveUpMenuName = "Move Up Filter";
private const string MoveUpByMenuName = "Move Up Filter By";
private const string PasteMenuName = "Paste Filter As New";
private const string PasteValuesMenuName = "Paste Filter Values";
private const string MoveDownMenuName = "Move Down Filter";
private const string MoveDownByMenuName = "Move Down Filter By";
private const string CopyMenuName = "Copy Filter";

private readonly Subject<Empty> _copyMenuExecutedSubject = new Subject<Empty>();
private readonly ICustomDrawer _drawer;
private readonly Subject<Empty> _mouseButtonClickedSubject = new Subject<Empty>();
private readonly Subject<Empty> _moveDownMenuExecutedSubject = new Subject<Empty>();
private readonly Subject<int> _moveDownByMenuExecutedSubject = new Subject<int>();
private readonly Subject<Empty> _moveUpMenuExecutedSubject = new Subject<Empty>();
private readonly Subject<int> _moveUpByMenuExecutedSubject = new Subject<int>();
private readonly Subject<Empty> _pasteMenuExecutedSubject = new Subject<Empty>();
private readonly Subject<Empty> _pasteValuesMenuExecutedSubject = new Subject<Empty>();
private readonly Subject<Empty> _removeMenuExecutedSubject = new Subject<Empty>();
Expand All @@ -49,7 +54,9 @@ public AssetFilterView(IAssetFilter filter)

public IObservable<Empty> RemoveMenuExecutedAsObservable => _removeMenuExecutedSubject;
public IObservable<Empty> MoveUpMenuExecutedAsObservable => _moveUpMenuExecutedSubject;
public IObservable<int> MoveUpByMenuExecutedAsObservable => _moveUpByMenuExecutedSubject;
public IObservable<Empty> MoveDownMenuExecutedAsObservable => _moveDownMenuExecutedSubject;
public IObservable<int> MoveDownByMenuExecutedAsObservable => _moveDownByMenuExecutedSubject;
public IObservable<Empty> ValueChangedAsObservable => _valueChangedSubject;
public IObservable<Empty> CopyMenuExecutedAsObservable => _copyMenuExecutedSubject;
public IObservable<Empty> PasteMenuExecutedSubject => _pasteMenuExecutedSubject;
Expand All @@ -71,6 +78,9 @@ public void Dispose()
public event Func<bool> CanPaste;
public event Func<bool> CanPasteValues;

public event Func<ICollection<int>> GetMoveUpByOptions;
public event Func<ICollection<int>> GetMoveDownByOptions;

public void DoLayout()
{
var attribute = Filter.GetType().GetCustomAttribute<AssetFilterAttribute>();
Expand Down Expand Up @@ -115,8 +125,26 @@ public void DoLayout()
() => _removeMenuExecutedSubject.OnNext(Empty.Default));
menu.AddItem(new GUIContent(MoveUpMenuName), false,
() => _moveUpMenuExecutedSubject.OnNext(Empty.Default));

var moveUpByList = GetMoveUpByOptions?.Invoke();
if (moveUpByList == null || moveUpByList.Count == 0)
menu.AddDisabledItem(new GUIContent(MoveUpByMenuName), false);
else
foreach (var count in moveUpByList)
menu.AddItem(new GUIContent($"{MoveUpByMenuName}/{count}"), false,
() => _moveUpByMenuExecutedSubject.OnNext(count));

menu.AddItem(new GUIContent(MoveDownMenuName), false,
() => _moveDownMenuExecutedSubject.OnNext(Empty.Default));

var moveDownByList = GetMoveDownByOptions?.Invoke();
if (moveDownByList == null || moveDownByList.Count == 0)
menu.AddDisabledItem(new GUIContent(MoveDownByMenuName), false);
else
foreach (var count in moveDownByList)
menu.AddItem(new GUIContent($"{MoveDownByMenuName}/{count}"), false,
() => _moveDownByMenuExecutedSubject.OnNext(count));

menu.AddItem(new GUIContent(CopyMenuName), false,
() => _copyMenuExecutedSubject.OnNext(Empty.Default));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SmartAddresser.Editor.Core.Models.Shared.AssetGroups;
using SmartAddresser.Editor.Foundation.CommandBasedUndo;
using SmartAddresser.Editor.Foundation.TinyRx;
Expand Down Expand Up @@ -37,9 +38,13 @@ public AssetFilterViewPresenter(IList<IAssetFilter> filterCollection, AssetFilte

view.CanPaste += CanPaste;
view.CanPasteValues += CanPasteValues;
view.GetMoveUpByOptions += GetMoveUpByOptions;
view.GetMoveDownByOptions += GetMoveDownByOptions;
view.RemoveMenuExecutedAsObservable.Subscribe(_ => Remove()).DisposeWith(_disposable);
view.MoveUpMenuExecutedAsObservable.Subscribe(_ => MoveUp()).DisposeWith(_disposable);
view.MoveUpByMenuExecutedAsObservable.Subscribe(MoveUpBy).DisposeWith(_disposable);
view.MoveDownMenuExecutedAsObservable.Subscribe(_ => MoveDown()).DisposeWith(_disposable);
view.MoveDownByMenuExecutedAsObservable.Subscribe(MoveDownBy).DisposeWith(_disposable);
view.CopyMenuExecutedAsObservable.Subscribe(_ => Copy()).DisposeWith(_disposable);
view.PasteMenuExecutedSubject.Subscribe(_ => Paste()).DisposeWith(_disposable);
view.PasteValuesMenuExecutedSubject.Subscribe(_ => PasteValues()).DisposeWith(_disposable);
Expand All @@ -51,6 +56,8 @@ public void Dispose()
{
_view.CanPaste -= CanPaste;
_view.CanPasteValues -= CanPasteValues;
_view.GetMoveUpByOptions -= GetMoveUpByOptions;
_view.GetMoveDownByOptions -= GetMoveDownByOptions;
_disposable.Dispose();
}

Expand Down Expand Up @@ -92,38 +99,48 @@ private void Remove()
}

private void MoveUp()
{
MoveUpBy(1);
}

private void MoveUpBy(int d)
{
var index = _filterCollection.IndexOf(_filter);
if (index == 0)
if (index - d < 0)
return;

_history.Register($"Move Up Filter {_filter.Id} {index}", () =>
_history.Register($"Move Up Filter {_filter.Id} {index} By {d}", () =>
{
_filterCollection.RemoveAt(index);
_filterCollection.Insert(index - 1, _filter);
_filterCollection.Insert(index - d, _filter);
_saveService.Save();
}, () =>
{
_filterCollection.RemoveAt(index - 1);
_filterCollection.RemoveAt(index - d);
_filterCollection.Insert(index, _filter);
_saveService.Save();
});
}

private void MoveDown()
{
MoveDownBy(1);
}

private void MoveDownBy(int d)
{
var index = _filterCollection.IndexOf(_filter);
if (index == _filterCollection.Count - 1)
if (index + d >= _filterCollection.Count)
return;

_history.Register($"Move Down Filter {_filter.Id} {index}", () =>
_history.Register($"Move Down Filter {_filter.Id} {index} By {d}", () =>
{
_filterCollection.RemoveAt(index);
_filterCollection.Insert(index + 1, _filter);
_filterCollection.Insert(index + d, _filter);
_saveService.Save();
}, () =>
{
_filterCollection.RemoveAt(index + 1);
_filterCollection.RemoveAt(index + d);
_filterCollection.Insert(index, _filter);
_saveService.Save();
});
Expand Down Expand Up @@ -179,5 +196,17 @@ private void PasteValues()
_saveService.Save();
});
}

private ICollection<int> GetMoveUpByOptions()
{
var index = _filterCollection.IndexOf(_filter);
return index == 0 ? Array.Empty<int>() : Enumerable.Range(1, index).ToArray();
}

private ICollection<int> GetMoveDownByOptions()
{
var index = _filterCollection.IndexOf(_filter);
return index == _filterCollection.Count - 1 ? Array.Empty<int>() : Enumerable.Range(1, _filterCollection.Count - index - 1).ToArray();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,15 @@ private void SetupViewEventHandlers()
_view.CanPasteGroup += CanPasteGroup;
_view.CanPasteGroupValues += CanPasteGroupValues;
_view.CanPasteFilter += CanPasteFilter;
_view.GetMoveUpByOptions += GetMoveUpByOptions;
_view.GetMoveDownByOptions += GetMoveDownByOptions;
_view.NameChangedAsObservable.Subscribe(SetGroupName).DisposeWith(_viewEventDisposables);
_view.AddFilterButtonClickedAsObservable.Subscribe(_ => AddFilter()).DisposeWith(_viewEventDisposables);
_view.RemoveGroupMenuExecutedAsObservable.Subscribe(_ => RemoveGroup()).DisposeWith(_viewEventDisposables);
_view.MoveUpMenuExecutedAsObservable.Subscribe(_ => MoveUpGroup()).DisposeWith(_viewEventDisposables);
_view.MoveUpByMenuExecutedAsObservable.Subscribe(MoveUpByGroup).DisposeWith(_viewEventDisposables);
_view.MoveDownMenuExecutedAsObservable.Subscribe(_ => MoveDownGroup()).DisposeWith(_viewEventDisposables);
_view.MoveDownByMenuExecutedAsObservable.Subscribe(MoveDownByGroup).DisposeWith(_viewEventDisposables);
_view.CopyGroupMenuExecutedAsObservable.Subscribe(_ => CopyGroup()).DisposeWith(_viewEventDisposables);
_view.PasteGroupMenuExecutedSubject.Subscribe(_ => PasteGroup()).DisposeWith(_viewEventDisposables);
_view.PasteGroupValuesMenuExecutedSubject.Subscribe(_ => PasteGroupValues())
Expand Down Expand Up @@ -178,44 +182,54 @@ void RemoveGroup()
}

void MoveUpGroup()
{
MoveUpByGroup(1);
}

void MoveUpByGroup(int d)
{
if (!_didSetupView)
return;

var index = _groups.IndexOf(_group);
if (index == 0)
if (index - d < 0)
return;

_history.Register($"Move Up Group {_group.Id} {index}", () =>
_history.Register($"Move Up Group {_group.Id} {index} By {d}", () =>
{
_groups.RemoveAt(index);
_groups.Insert(index - 1, _group);
_groups.Insert(index - d, _group);
_saveService.Save();
}, () =>
{
_groups.RemoveAt(index - 1);
_groups.RemoveAt(index - d);
_groups.Insert(index, _group);
_saveService.Save();
});
}

void MoveDownGroup()
{
MoveDownByGroup(1);
}

void MoveDownByGroup(int d)
{
if (!_didSetupView)
return;

var index = _groups.IndexOf(_group);
if (index == _groups.Count - 1)
if (index + d >= _groups.Count)
return;

_history.Register($"Move Down Filter {_group.Id} {index}", () =>
_history.Register($"Move Down Group {_group.Id} {index} By {d}", () =>
{
_groups.RemoveAt(index);
_groups.Insert(index + 1, _group);
_groups.Insert(index + d, _group);
_saveService.Save();
}, () =>
{
_groups.RemoveAt(index + 1);
_groups.RemoveAt(index + d);
_groups.Insert(index, _group);
_saveService.Save();
});
Expand Down Expand Up @@ -337,6 +351,8 @@ private void CleanupViewEventHandlers()
_view.CanPasteGroup -= CanPasteGroup;
_view.CanPasteGroupValues -= CanPasteGroupValues;
_view.CanPasteFilter -= CanPasteFilter;
_view.GetMoveUpByOptions -= GetMoveUpByOptions;
_view.GetMoveDownByOptions -= GetMoveDownByOptions;
}

private bool CanPasteGroup()
Expand All @@ -362,5 +378,23 @@ private bool CanPasteFilter()

return typeof(IAssetFilter).IsAssignableFrom(ObjectCopyBuffer.Type);
}

private ICollection<int> GetMoveUpByOptions()
{
if (!_didSetupView)
return Array.Empty<int>();

var index = _groups.IndexOf(_group);
return index == 0 ? Array.Empty<int>() : Enumerable.Range(1, index).ToArray();
}

private ICollection<int> GetMoveDownByOptions()
{
if (!_didSetupView)
return Array.Empty<int>();

var index = _groups.IndexOf(_group);
return index == _groups.Count - 1 ? Array.Empty<int>() : Enumerable.Range(1, _groups.Count - index - 1).ToArray();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ internal sealed class AssetGroupPanelView : IDisposable
private const string RenameMenuName = "Rename";
private const string RemoveMenuName = "Remove";
private const string MoveUpMenuName = "Move Up";
private const string MoveUpByMenuName = "Move Up By";
private const string MoveDownMenuName = "Move Down";
private const string MoveDownByMenuName = "Move Down By";
private const string CopyMenuName = "Copy";
private const string PasteMenuName = "Paste As New";
private const string PasteValuesMenuName = "Paste Values";
Expand All @@ -32,7 +34,9 @@ internal sealed class AssetGroupPanelView : IDisposable
private readonly List<string> _filterViewsOrder = new List<string>();

private readonly Subject<Empty> _moveDownMenuExecutedSubject = new Subject<Empty>();
private readonly Subject<int> _moveDownByMenuExecutedSubject = new Subject<int>();
private readonly Subject<Empty> _moveUpMenuExecutedSubject = new Subject<Empty>();
private readonly Subject<int> _moveUpByMenuExecutedSubject = new Subject<int>();
private readonly Subject<string> _nameChangedSubject = new Subject<string>();
private readonly Subject<Empty> _pasteFilterMenuExecutedSubject = new Subject<Empty>();
private readonly Subject<Empty> _pasteGroupMenuExecutedSubject = new Subject<Empty>();
Expand All @@ -49,8 +53,12 @@ internal sealed class AssetGroupPanelView : IDisposable

public IObservable<Empty> MoveUpMenuExecutedAsObservable => _moveUpMenuExecutedSubject;

public IObservable<int> MoveUpByMenuExecutedAsObservable => _moveUpByMenuExecutedSubject;

public IObservable<Empty> MoveDownMenuExecutedAsObservable => _moveDownMenuExecutedSubject;

public IObservable<int> MoveDownByMenuExecutedAsObservable => _moveDownByMenuExecutedSubject;

public IObservable<Empty> CopyGroupMenuExecutedAsObservable => _copyGroupMenuExecutedSubject;

public IObservable<Empty> PasteGroupMenuExecutedSubject => _pasteGroupMenuExecutedSubject;
Expand All @@ -72,7 +80,9 @@ public void Dispose()
_nameChangedSubject.Dispose();
_addFilterButtonClickedSubject.Dispose();
_moveUpMenuExecutedSubject.Dispose();
_moveUpByMenuExecutedSubject.Dispose();
_moveDownMenuExecutedSubject.Dispose();
_moveDownByMenuExecutedSubject.Dispose();
_copyGroupMenuExecutedSubject.Dispose();
_pasteGroupMenuExecutedSubject.Dispose();
_pasteGroupValuesMenuExecutedSubject.Dispose();
Expand All @@ -84,6 +94,9 @@ public void Dispose()
public event Func<bool> CanPasteGroupValues;
public event Func<bool> CanPasteFilter;

public event Func<ICollection<int>> GetMoveUpByOptions;
public event Func<ICollection<int>> GetMoveDownByOptions;

public AssetFilterView AddFilterView(IAssetFilter filter, int index = -1)
{
var filterView = new AssetFilterView(filter);
Expand Down Expand Up @@ -162,10 +175,28 @@ public void DoLayout()
menu.AddItem(new GUIContent(MoveUpMenuName), false,
() => _moveUpMenuExecutedSubject.OnNext(Empty.Default));

// Move Up By
var moveUpByList = GetMoveUpByOptions?.Invoke();
if (moveUpByList == null || moveUpByList.Count == 0)
menu.AddDisabledItem(new GUIContent(MoveUpByMenuName), false);
else
foreach (var count in moveUpByList)
menu.AddItem(new GUIContent($"{MoveUpByMenuName}/{count}"), false,
() => _moveUpByMenuExecutedSubject.OnNext(count));

// Move Down
menu.AddItem(new GUIContent(MoveDownMenuName), false,
() => _moveDownMenuExecutedSubject.OnNext(Empty.Default));

// Move Down By
var moveDownByList = GetMoveDownByOptions?.Invoke();
if (moveDownByList == null || moveDownByList.Count == 0)
menu.AddDisabledItem(new GUIContent(MoveDownByMenuName), false);
else
foreach (var count in moveDownByList)
menu.AddItem(new GUIContent($"{MoveDownByMenuName}/{count}"), false,
() => _moveDownByMenuExecutedSubject.OnNext(count));

// Copy Group
menu.AddItem(new GUIContent(CopyMenuName), false,
() => _copyGroupMenuExecutedSubject.OnNext(Empty.Default));
Expand Down