178 lines
4.3 KiB
C#
Executable File
178 lines
4.3 KiB
C#
Executable File
/* PreferencesViewModel.cs
|
|
* part of zaaReloaded2
|
|
*
|
|
* Copyright 2015-2018 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.Linq;
|
|
using System.Text;
|
|
using Bovender.Mvvm;
|
|
using Bovender.Mvvm.ViewModels;
|
|
|
|
namespace zaaReloaded2.ViewModels
|
|
{
|
|
/// <summary>
|
|
/// View model for zaaReloaded2.Preferences.
|
|
/// </summary>
|
|
public class PreferencesViewModel : ViewModelBase
|
|
{
|
|
#region Properties
|
|
|
|
public bool SuppressItemCommentInteraction
|
|
{
|
|
get
|
|
{
|
|
return _suppressCommentInteraction;
|
|
}
|
|
set
|
|
{
|
|
if (value != _suppressCommentInteraction)
|
|
{
|
|
_suppressCommentInteraction = value;
|
|
OnPropertyChanged("SuppressItemCommentInteraction");
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool EnableLogging
|
|
{
|
|
get
|
|
{
|
|
return _enableLogging;
|
|
}
|
|
set
|
|
{
|
|
if (value != _enableLogging)
|
|
{
|
|
_enableLogging = value;
|
|
OnPropertyChanged("EnableLogging");
|
|
}
|
|
}
|
|
}
|
|
|
|
public string LogFolder
|
|
{
|
|
get
|
|
{
|
|
return LogFile.Default.LogFolder;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Command
|
|
|
|
public DelegatingCommand SaveCommand
|
|
{
|
|
get
|
|
{
|
|
if (_saveCommand == null)
|
|
{
|
|
_saveCommand = new DelegatingCommand(
|
|
param => DoSave(),
|
|
param => CanSave());
|
|
}
|
|
return _saveCommand;
|
|
}
|
|
}
|
|
|
|
public DelegatingCommand OpenLogFolderCommand
|
|
{
|
|
get
|
|
{
|
|
if (_openLogFolderCommand == null)
|
|
{
|
|
_openLogFolderCommand = new DelegatingCommand(
|
|
param => DoOpenLogFolder(),
|
|
param => CanOpenLogFolder());
|
|
}
|
|
return _openLogFolderCommand;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
public PreferencesViewModel()
|
|
{
|
|
_suppressCommentInteraction = UserSettings.Default.SuppressItemCommentInteraction;
|
|
_enableLogging = UserSettings.Default.EnableLogging;
|
|
PropertyChanged += (sender, args) =>
|
|
{
|
|
_dirty = true;
|
|
};
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Private methods
|
|
|
|
void DoSave()
|
|
{
|
|
if (_dirty)
|
|
{
|
|
UserSettings.Default.SuppressItemCommentInteraction = SuppressItemCommentInteraction;
|
|
UserSettings.Default.EnableLogging = EnableLogging;
|
|
}
|
|
DoCloseView();
|
|
}
|
|
|
|
bool CanSave()
|
|
{
|
|
return _dirty;
|
|
}
|
|
|
|
void DoOpenLogFolder()
|
|
{
|
|
if (CanOpenLogFolder())
|
|
{
|
|
System.Diagnostics.Process.Start(LogFolder);
|
|
if (!_dirty)
|
|
{
|
|
CloseViewCommand.Execute(null);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool CanOpenLogFolder()
|
|
{
|
|
return !String.IsNullOrEmpty(LogFolder);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Fields
|
|
|
|
DelegatingCommand _saveCommand;
|
|
DelegatingCommand _openLogFolderCommand;
|
|
bool _dirty;
|
|
bool _enableLogging;
|
|
bool _suppressCommentInteraction;
|
|
|
|
#endregion
|
|
|
|
#region ViewModelBase implementation
|
|
|
|
public override object RevealModelObject()
|
|
{
|
|
return UserSettings.Default;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|