简体   繁体   English

使用MVVM撤消/重做最佳实践

[英]Undo/Redo Best Practices with MVVM

I am working on essentially a drawing editor that allows you to define geometries based on key points on existing geometries. 我本质上是一个绘图编辑器,允许您根据现有几何上的关键点定义几何。 The user is then able to add some information about the thing they just added, such as name, expected size, etc. The API I am using to accomplish it is the awesome Reversible API, though I hope that the question extends beyond the API that I am using. 然后,用户可以添加一些关于他们刚刚添加的东西的信息,例如名称,预期大小等。我用来完成它的API是令人敬畏的Reversible API,尽管我希望问题超出API的范围。我在用。

There are basically a couple questions that I am seeking a little clarity on: 基本上有几个问题我想要澄清一下:

1) If you are supporting Undo/Redo with an application that supports selection in a Master/Detail manner, should changing the state of a drawing object also cause it to be selected? 1)如果您支持使用支持Master / Detail方式选择的应用程序的Undo / Redo,更改绘图对象的状态是否也会导致它被选中? The example being that an undo operation changed the name of an element, and that change would not be obvious unless the element was selected. 示例是撤消操作更改了元素的名称,除非选择了元素,否则该更改不会很明显。 Is there considered a standard behavior for something like this? 对于这样的事情,是否考虑过标准行为?

2) When dealing with certain types of incremental changes (Dragging box, or using a numeric spinner), it seems to be standard form for a set of changes to be grouped into a single user interaction (mouse swipe, or the act of releasing the spinner button), but when dealing with MVVM, I currently only know that the property has changed and not the source of the change. 2)当处理某些类型的增量更改(拖动框或使用数字微调器)时,它似乎是一组标准形式,可将一组更改分组为单个用户交互(鼠标滑动或释放旋转按钮),但在处理MVVM时,我目前只知道属性已更改,而不是更改的来源。 Is there a standard way for these types of interactions to propagate to the view model without completely disintegrating the pattern? 这些类型的交互是否有标准的方式传播到视图模型而不会完全分解模式?

When in doubt the best approach is to take a look at typical behaviour of OS controls and other applications on the platform in order to be consistent with what users will be familiar with. 如果有疑问,最好的方法是查看平台上OS控件和其他应用程序的典型行为,以便与用户熟悉的内容保持一致。 In particular, consistency with the most commonly-used applications. 特别是与最常用的应用程序的一致性。 If you examine how other apps approach a UI issue you can often learn a lot, especially about subtle cases you may not have considered in your own design. 如果您检查其他应用程序如何处理UI问题,您通常可以学到很多东西,特别是在您自己的设计中可能没有考虑过的微妙案例。

1) Conventionally, undoing tends to select the changed item(s), both to highlight what changed and to move the user's input focus back to the last edit so that they can continue. 1)传统上,撤消倾向于选择改变的项目,以突出显示改变的内容并将用户的输入焦点移回到上一次编辑,以便它们可以继续。 This works particularly well for content like text because if you undo/redo something you typed, chances are you want to continue editing in the area of the text you've just undone/redone. 这对于像文本这样的内容特别有效,因为如果你撤消/重做你输入的内容,你可能想要继续编辑你刚刚撤消/重做的文本区域。 The main choice for you to make with master/detail is whether to select the master object only, or to select the precise detail that changed. 使用主/细节进行制作的主要选择是,是仅选择主对象,还是选择更改的精确细节。

2) Your undo manager can use some intelligence to conglomerate similar actions into a single undo step. 2)您的撤消管理器可以使用一些智能将类似的操作集成到一个撤消步骤中。 For example, if the user types several characters in a row, it could notice that these actions are all alike and concatenate them into a single undo step. 例如,如果用户在一行中键入多个字符,则可能会注意到这些操作完全相同,并将它们连接到一个撤消步骤中。 Just how it does this depends on how you are storing and processing the undo, but with a decent object oriented design this should be an easy option to add (ie ask undo records themselves if they can be conglomerated so you can easily add new types of undo record in future). 它是如何做到这取决于你如何存储和处理撤消,但有一个体面的面向对象设计,这应该是一个简单的添加选项(即,如果它们可以集成,请询问撤消记录,以便您可以轻松添加新的类型将来撤消记录)。 Beware though that accumulating too many changes into one step can be intensely irritating, so you may find the lazier implementation of one action = 1 step actually achieves a better UX than trying to be too clever. 请注意,在一个步骤中累积太多更改可能会非常令人恼火,因此您可能会发现一个操作= 1步骤的更懒惰的实现实际上实现了比尝试过于聪明的更好的用户体验。 I'd start with brute force and add conglomeration only if you find you end up with lots of repetitive undo sequences (like 100 single pixel-left movements instead of just one 100-pixel jump) 只有当你发现最终有大量重复的撤销序列(比如100个单像素左移动而不是仅仅一个100像素的跳跃)时,我才会从蛮力开始并添加聚合

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM