Skip to content

Commit

Permalink
Merge pull request #4512 from cra0zy/multundo
Browse files Browse the repository at this point in the history
[Win Pipeline] Fix Multiselect Undo/Redo
  • Loading branch information
tomspilman committed Feb 9, 2016
2 parents c82e79e + eaddf27 commit d7a383c
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 91 deletions.
4 changes: 2 additions & 2 deletions Build/Projects/Pipeline.definition
Expand Up @@ -54,6 +54,8 @@
<Compile Include="Common\PipelineController.NewAction.cs" />
<Compile Include="Common\PipelineController.ExcludeAction.cs" />
<Compile Include="Common\PipelineController.IncludeAction.cs" />
<Compile Include="Common\PipelineController.UpdateContentItemAction.cs" />
<Compile Include="Common\PipelineController.UpdateProjectAction.cs" />
<Compile Include="Common\PipelineSettings.cs" />
<Compile Include="Common\IController.cs" />
<Compile Include="Common\IProjectItem.cs" />
Expand All @@ -69,8 +71,6 @@
<Compile Include="Common\PipelineTypes.cs" />
<Compile Include="Common\Extensions.cs" />

<Compile Include="Windows\UpdateAction.cs" />

<!-- The Windows specific stuff -->
<Compile Include="Windows\BuildIcons.cs">
<Platforms>Windows</Platforms>
Expand Down
@@ -0,0 +1,53 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.

using System.Collections.Generic;
using System.Linq;

namespace MonoGame.Tools.Pipeline
{
internal class UpdateContentItemAction : IProjectAction
{
private readonly IView _view;
private readonly IController _con;
private List<ContentItemState> _states;

public UpdateContentItemAction(IView view, IController con, IEnumerable<ContentItemState> states)
{
_view = view;
_con = con;
_states = states.ToList();
}

public bool Do()
{
Toggle();
return true;
}

public bool Undo()
{
Toggle();
return true;
}

private void Toggle()
{
for (int i = 0; i < _states.Count; i++)
{
var item = (ContentItem)_con.GetItem(_states[i].SourceFile);
var state = ContentItemState.Get(item);
_states[i].Apply(item);
_states[i] = state;

item.ResolveTypes();

_view.BeginTreeUpdate();
_view.UpdateProperties(item);
_view.UpdateTreeItem(item);
_view.EndTreeUpdate();
}
}
}
}
@@ -1,90 +1,22 @@
using System;
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.

using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;

using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Graphics;

namespace MonoGame.Tools.Pipeline
{
internal class UpdateContentItemAction : IProjectAction
{
private readonly IView _view;
private readonly IController _con;
private ContentItemState _state;

public UpdateContentItemAction(IView view, IController con, ContentItem item, PropertyDescriptor property, object previousValue)
{
_view = view;
_con = con;

_state = ContentItemState.Get(item);

var name = property.Name;
var value = previousValue;

if (name == "Importer")
{
name = "ImporterName";
value = ((ImporterTypeDescription)value).TypeName;
}

if (name == "Processor")
{
name = "ProcessorName";
value = ((ProcessorTypeDescription)value).TypeName;
}

var field = _state.GetType().GetMember(name).SingleOrDefault() as FieldInfo;
if (field == null)
{
if (!_state.ProcessorParams.ContainsKey(name))
throw new Exception();

_state.ProcessorParams[name] = value;
}
else
{
field.SetValue(_state, value);
}
}

public bool Do()
{
Toggle();
return true;
}

public bool Undo()
{
Toggle();
return true;
}

private void Toggle()
{
var item = (ContentItem)_con.GetItem(_state.SourceFile);
var state = ContentItemState.Get(item);
_state.Apply(item);
_state = state;

item.ResolveTypes();

_view.BeginTreeUpdate();
_view.UpdateProperties(item);
_view.UpdateTreeItem(item);
_view.EndTreeUpdate();
}
}

internal class UpdateProjectAction : IProjectAction
{
private readonly IView _view;
private readonly IController _con;
private readonly bool _referencesChanged;

private ProjectState _state;
private ProjectState _state;

public UpdateProjectAction(IView view, IController con, PipelineProject item, PropertyDescriptor property, object previousValue)
{
Expand Down
33 changes: 18 additions & 15 deletions Tools/Pipeline/Windows/MainView.cs
Expand Up @@ -23,6 +23,7 @@ partial class MainView : Form, IView, IProjectObserver

public static IController _controller;
private ContentIcons _treeIcons;
private List<ContentItemState> _oldValues = new List<ContentItemState>();

private bool _treeUpdating;
private bool _treeSort;
Expand Down Expand Up @@ -160,27 +161,22 @@ private void OnPropertyGridPropertyValueChanged(object s, PropertyValueChangedEv
if (args.ChangedItem.Label == "References")
_controller.OnReferencesModified();

// TODO: This is the multi-select case which needs to be handled somehow to support undo.
if (args.OldValue == null)
return;

var obj = _propertyGrid.SelectedObject;
var obj = _propertyGrid.SelectedObject as PipelineProjectProxy;

if (obj is ContentItem)
if (obj != null)
{
var item = obj as ContentItem;
var action = new UpdateContentItemAction(this, _controller, item, args.ChangedItem.PropertyDescriptor, args.OldValue);
_controller.AddAction(action);
var item = (PipelineProject)_controller.GetItem(obj.OriginalPath);
var action = new UpdateProjectAction(this, _controller, item, args.ChangedItem.PropertyDescriptor, args.OldValue);
_controller.AddAction(action);

_controller.OnProjectModified();
}
else
{
var item = (PipelineProject)_controller.GetItem((obj as PipelineProjectProxy).OriginalPath);
var action = new UpdateProjectAction(this, _controller, item, args.ChangedItem.PropertyDescriptor, args.OldValue);
_controller.AddAction(action);

var action = new UpdateContentItemAction(this, _controller, _oldValues);
_controller.AddAction(action);
_controller.OnProjectModified();
}
}
}

private void TreeViewOnNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
Expand Down Expand Up @@ -666,9 +662,16 @@ private void TreeViewAfterSelect(object sender, TreeViewEventArgs e)
_controller.Selection.Clear(this);
_propertyGrid.SelectedObject = null;

_oldValues.Clear();

foreach (var node in _treeView.SelectedNodes)
{
_controller.Selection.Add(node.Tag as IProjectItem, this);
var item = node.Tag as IProjectItem;

if (item is ContentItem)
_oldValues.Add(ContentItemState.Get(item as ContentItem));

_controller.Selection.Add(item, this);
}

_propertyGrid.SelectedObjects = _controller.Selection.ToArray();
Expand Down

2 comments on commit d7a383c

@mgbot
Copy link
Member

@mgbot mgbot commented on d7a383c Feb 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity MonoGame :: Develop (Win) Build 3.5.0.1342 is now running

@mgbot
Copy link
Member

@mgbot mgbot commented on d7a383c Feb 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity MonoGame :: Develop (Win) Build 3.5.0.1342 outcome was SUCCESS
Summary: Tests passed: 584, ignored: 6 Build time: 00:20:05

Please sign in to comment.