ConfigViewModel.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "pch.h"
  2. #include "ConfigViewModel.h"
  3. #include "ConfigViewModel.g.cpp"
  4. namespace winrt::Maple_App::implementation
  5. {
  6. IAsyncOperation<Maple_App::ConfigViewModel> ConfigViewModel::FromFile(const StorageFile& file, bool isDefault) {
  7. const auto& properties = co_await file.GetBasicPropertiesAsync();
  8. const auto& modified = properties.DateModified();
  9. co_return winrt::make<ConfigViewModel>(file, modified, isDefault);
  10. }
  11. ConfigViewModel::ConfigViewModel(const StorageFile& file, DateTime dateUpdated, bool isDefault)
  12. : m_file(file), m_dateUpdated(dateUpdated), m_isDefault(isDefault)
  13. {
  14. }
  15. StorageFile ConfigViewModel::File()
  16. {
  17. return m_file;
  18. }
  19. hstring ConfigViewModel::Name()
  20. {
  21. return m_file.Name();
  22. }
  23. Windows::Foundation::DateTime ConfigViewModel::DateUpdated()
  24. {
  25. return m_dateUpdated;
  26. }
  27. bool ConfigViewModel::IsDefault()
  28. {
  29. return m_isDefault;
  30. }
  31. void ConfigViewModel::IsDefault(bool value)
  32. {
  33. m_isDefault = value;
  34. m_propertyChanged(*this, PropertyChangedEventArgs(L"IsDefault"));
  35. }
  36. winrt::event_token ConfigViewModel::PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& handler)
  37. {
  38. return m_propertyChanged.add(handler);
  39. }
  40. void ConfigViewModel::PropertyChanged(winrt::event_token const& token) noexcept
  41. {
  42. m_propertyChanged.remove(token);
  43. }
  44. IAsyncAction ConfigViewModel::Delete() {
  45. return m_file.DeleteAsync();
  46. }
  47. IAsyncAction ConfigViewModel::Rename(hstring const& newName) {
  48. co_await m_file.RenameAsync(newName, NameCollisionOption::GenerateUniqueName);
  49. m_propertyChanged(*this, PropertyChangedEventArgs(L"Name"));
  50. }
  51. }