zaaReloaded2/zaaReloaded2/ViewModels/FormatElementViewModel.cs

122 lines
3.0 KiB
C#
Raw Normal View History

/* FormatElementViewModel.cs
* part of zaaReloaded2
*
2017-02-23 15:44:07 +00:00
* 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;
2015-08-09 11:24:44 +00:00
using Bovender.Mvvm;
using zaaReloaded2.Controller.Elements;
namespace zaaReloaded2.ViewModels
{
public class FormatElementViewModel : ElementViewModel
{
#region Public properties
public string Content
{
[DebuggerStepThrough]
2015-08-09 11:24:44 +00:00
get { return _content; }
set
{
2015-08-09 11:24:44 +00:00
_content = value;
OnPropertyChanged("Content");
}
}
2015-08-05 18:28:09 +00:00
/// <summary>
/// Gets or sets the parent ControlElementViewModel, if
/// there is any.
/// </summary>
public ControlElementViewModel Parent { get; set; }
2015-08-12 15:54:23 +00:00
public override string ToolTip { get { return Element.Label; } }
#endregion
2015-08-09 11:24:44 +00:00
#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;
2015-08-09 11:24:44 +00:00
Content = ((FormatElementBase)Element).Content;
}
#endregion
2015-08-05 19:22:03 +00:00
2015-08-09 11:24:44 +00:00
#region Overrides
2015-08-05 19:22:03 +00:00
public override object Clone()
{
FormatElementViewModel clone = new FormatElementViewModel();
clone.Parent = Parent;
clone.Element = Element;
return clone;
}
2015-08-09 11:24:44 +00:00
#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
}
}