Skip to content

Instantly share code, notes, and snippets.

@dennis-garavsky
Last active February 9, 2017 14:49
Show Gist options
  • Select an option

  • Save dennis-garavsky/fdf5b89af07cabc4b030 to your computer and use it in GitHub Desktop.

Select an option

Save dennis-garavsky/fdf5b89af07cabc4b030 to your computer and use it in GitHub Desktop.
//With XAF v15.2.4+, this feature is already built-in (https://documentation.devexpress.com/#eXpressAppFramework/CustomDocument113141/ResetViewSettingsController).
//Do NOT use this controller if you are already on v15.2.4+.
using System;
using DevExpress.ExpressApp;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Model.Core;
namespace YourSolutionName.Module.Controllers {
public class S172628 : Controller {
private SimpleAction resetViewSettingsAction;
private void ObjectSpace_ModifiedChanged(Object sender, EventArgs e) {
UpdateActionState();
}
private void Frame_ViewChanging(Object sender, ViewChangingEventArgs e) {
if ((Frame != null) && (Frame.View is ObjectView)) {
((ObjectView)Frame.View).ObjectSpace.ModifiedChanged -= ObjectSpace_ModifiedChanged;
}
}
private void Frame_ViewChanged(Object sender, ViewChangedEventArgs e) {
//resetViewSettingsAction.RaiseChanged(ActionChangedType.ToolTip);
//resetViewSettingsAction.RaiseChanged(ActionChangedType.ConfirmationMessage);
if ((Frame != null) && (Frame.View is ObjectView)) {
((ObjectView)Frame.View).ObjectSpace.ModifiedChanged += ObjectSpace_ModifiedChanged;
}
UpdateActionState();
}
private void ResetViewSettingsAction_CustomGetTotalTooltip(Object sender, CustomGetTotalTooltipEventArgs e) {
if ((Frame != null) && (Frame.View != null)) {
e.Tooltip = String.Format(e.Tooltip, Frame.View.Caption);
}
}
//private void ResetViewSettingsAction_CustomGetFormattedConfirmationMessage(Object sender, CustomGetFormattedConfirmationMessageEventArgs e) {
// if ((Frame != null) && (Frame.View != null)) {
// e.ConfirmationMessage = String.Format(e.ConfirmationMessage, Frame.View.Caption);
// }
//}
private void ResetViewSettingsAction_Execute(Object sender, SimpleActionExecuteEventArgs e) {
ResetViewSettings();
}
protected virtual void UpdateActionState() {
String viewIsNotNullKey = "View is not null";
String viewIsNotModifiedKey = "View is not modified";
resetViewSettingsAction.Active.SetItemValue(viewIsNotNullKey, (Frame != null) && (Frame.View != null));
if ((Frame != null) && (Frame.View is ObjectView)) {
resetViewSettingsAction.Enabled.SetItemValue(viewIsNotModifiedKey, !((ObjectView)Frame.View).ObjectSpace.IsModified);
}
else {
resetViewSettingsAction.Enabled.RemoveItem(viewIsNotModifiedKey);
}
}
protected virtual void ResetViewSettings() {
if ((Frame != null) && (Frame.View != null)) {
IModelView viewModel1 = Frame.View.Model;
IModelView viewModel2 = null;
if ((Frame.View is ListView) && (((ListView)Frame.View).EditView != null)) {
viewModel2 = ((ListView)Frame.View).EditView.Model;
}
if (Frame.View.IsRoot) {
ViewShortcut viewShortcut = Frame.View.CreateShortcut();
if (Frame.SetView(null)) {
((ModelNode)viewModel1).Undo();
if (viewModel2 != null) {
((ModelNode)viewModel2).Undo();
}
Frame.SetView(Application.ProcessShortcut(viewShortcut));
}
}
else if ((Frame is NestedFrame)
&& (((NestedFrame)Frame).ViewItem is ListPropertyEditor)
&& (((ListPropertyEditor)((NestedFrame)Frame).ViewItem).ListView != null)) {
if (Frame.SetView(null)) {
((ModelNode)viewModel1).Undo();
if (viewModel2 != null) {
((ModelNode)viewModel2).Undo();
}
((NestedFrame)Frame).ViewItem.CreateControl();
}
}
else if ((Frame is NestedFrame)
&& (((NestedFrame)Frame).ViewItem is DetailPropertyEditor)
&& (((DetailPropertyEditor)((NestedFrame)Frame).ViewItem).DetailView != null)) {
if (Frame.SetView(null)) {
((ModelNode)viewModel1).Undo();
((NestedFrame)Frame).ViewItem.CreateControl();
}
}
}
}
protected override void OnActivated() {
base.OnActivated();
Frame.ViewChanging += Frame_ViewChanging;
Frame.ViewChanged += Frame_ViewChanged;
UpdateActionState();
}
protected override void OnDeactivated() {
base.OnDeactivated();
Frame.ViewChanging -= Frame_ViewChanging;
Frame.ViewChanged -= Frame_ViewChanged;
}
public S172628()
: base() {
//resetViewSettingsAction = new SimpleAction(this, "ResetViewSettings", PredefinedCategory.Tools);
resetViewSettingsAction = new SimpleAction(this, "S172628", PredefinedCategory.View);
resetViewSettingsAction.Caption = "Reset View Settings";
resetViewSettingsAction.ImageName = "ModelEditor_Action_ResetDifferences_Xml";
//resetViewSettingsAction.PaintStyle = DevExpress.ExpressApp.Templates.ActionItemPaintStyle.Image;
//resetViewSettingsAction.ToolTip = @"Resets all settings made for the ""{0}"" view.";
resetViewSettingsAction.ToolTip = @"Resets all settings made for the current view.";
//resetViewSettingsAction.ConfirmationMessage = @"You are about to reset all settings made for the ""{0}"" view. Do you want to proceed?";
resetViewSettingsAction.ConfirmationMessage = @"You are about to reset all settings made for the current view. Do you want to proceed?";
resetViewSettingsAction.CustomGetTotalTooltip += ResetViewSettingsAction_CustomGetTotalTooltip;
//resetViewSettingsAction.CustomGetFormattedConfirmationMessage += ResetViewSettingsAction_CustomGetFormattedConfirmationMessage;
resetViewSettingsAction.Execute += new SimpleActionExecuteEventHandler(ResetViewSettingsAction_Execute);
}
public SimpleAction ResetViewSettingsAction {
get { return resetViewSettingsAction; }
}
}
}
@kgreed
Copy link

kgreed commented Jan 13, 2016

I see this is now included in V15.2.4

@dennis-garavsky
Copy link
Author

@kgreed: Yes, it is built-in starting with XAF v15.2.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment