public SubSettingsVM(Area area, SettingsViewMode viewMode) { SaveCommand = new DelegateCommand(Save, () => IsDirty); _area = area; _viewMode = viewMode; string error = null; switch (_viewMode) { case SettingsViewMode.Meta: _directives = DirectivesUtils.LoadVRMeta(_area, out error); break; case SettingsViewMode.UserGlobal: _directives = DirectivesUtils.LoadGlobalVRUser(out error); break; case SettingsViewMode.User: _directives = DirectivesUtils.LoadVRUser(_area, out error); break; case SettingsViewMode.Effective: default: _directives = _area.Directives; IsReadOnly = true; break; } Error = (String.IsNullOrEmpty(error)) ? String.Empty : String.Format("{0}\nSaving changes will create a new file", error); if (_directives == null) { _directives = new Directives(); } _ignores = new IgnoresVM(_directives.Ignore, IsReadOnly); _ignores.Dirtied += (s, e) => IsDirty = true; _includes = new IgnoresVM(_directives.Include, IsReadOnly); _includes.Dirtied += (s, e) => IsDirty = true; }
private void Save() { _directives.Ignore = (_ignores.IsEmpty) ? null : _ignores.Ignores; _directives.Include = (_includes.IsEmpty) ? null : _includes.Ignores; bool success = false; switch (_viewMode) { case SettingsViewMode.Meta: success = DirectivesUtils.WriteVRMeta(_area, _directives); break; case SettingsViewMode.UserGlobal: success = DirectivesUtils.WriteGlobalVRUser(_directives); break; case SettingsViewMode.User: success = DirectivesUtils.WriteVRUser(_area, _directives); break; case SettingsViewMode.Effective: default: break; } if (success) { IsDirty = false; Error = String.Empty; } else { Error = String.Format("Failed to write to {0}\n. This could be because the file is already in use.", FilePath); } }