zaaReloaded2/zaaReloaded2/ViewModels/FormatElementViewModel.cs

122 lines
3.0 KiB
C#
Executable File

/* FormatElementViewModel.cs
* part of zaaReloaded2
*
* Copyright 2015-2017 Daniel Kraus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Bovender.Mvvm;
using zaaReloaded2.Controller.Elements;
namespace zaaReloaded2.ViewModels
{
public class FormatElementViewModel : ElementViewModel
{
#region Public properties
public string Content
{
[DebuggerStepThrough]
get { return _content; }
set
{
_content = value;
OnPropertyChanged("Content");
}
}
/// <summary>
/// Gets or sets the parent ControlElementViewModel, if
/// there is any.
/// </summary>
public ControlElementViewModel Parent { get; set; }
public override string ToolTip { get { return Element.Label; } }
#endregion
#region Commands
public DelegatingCommand SaveCommand
{
get
{
if (_saveCommand == null)
{
_saveCommand = new DelegatingCommand(
param => DoSave(),
param => CanSave());
}
return _saveCommand;
}
}
#endregion
#region Constructors
public FormatElementViewModel() : base() { }
public FormatElementViewModel(FormatElementBase formatElement)
: this()
{
Element = formatElement;
Content = ((FormatElementBase)Element).Content;
}
#endregion
#region Overrides
public override object Clone()
{
FormatElementViewModel clone = new FormatElementViewModel();
clone.Parent = Parent;
clone.Element = Element;
return clone;
}
#endregion
#region Private methods
void DoSave()
{
((FormatElementBase)Element).Content = _content;
// Writing the _content field to the model affects our
// DisplayString property; this is a hack to make it known.
OnPropertyChanged("DisplayString");
CloseViewCommand.Execute(null);
}
bool CanSave()
{
return !String.IsNullOrEmpty(Content);
}
#endregion
#region Fields
DelegatingCommand _saveCommand;
string _content;
#endregion
}
}