PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/ViewModel/ComponentViewModel.cs

https://github.com/shader/QuickArch
C# | 92 lines | 82 code | 10 blank | 0 comment | 14 complexity | 75a06df7f44561386c154a540437551b MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Input;
  6. using QuickArch.Model;
  7. using QuickArch.Utilities;
  8. using QuickArch.Properties;
  9. namespace QuickArch.ViewModel
  10. {
  11. public delegate void ComponentSelectionHandler(ComponentViewModel sender, EventArgs e);
  12. public abstract class ComponentViewModel : ViewModelBase
  13. {
  14. #region Fields
  15. protected Component _component;
  16. bool _isSelected;
  17. #endregion
  18. public Component Component
  19. {
  20. get { return _component; }
  21. }
  22. public ComponentViewModel(Component component)
  23. {
  24. _component = component;
  25. }
  26. public Dictionary<String,String> Properties
  27. {
  28. get
  29. {
  30. return _component.Properties;
  31. }
  32. }
  33. public override string DisplayName
  34. {
  35. get
  36. {
  37. return _component.Name;
  38. }
  39. set
  40. {
  41. base.DisplayName = value;
  42. _component.Name = value;
  43. }
  44. }
  45. public bool IsSelected
  46. {
  47. get { return _isSelected; }
  48. set
  49. {
  50. if (value != _isSelected)
  51. {
  52. _isSelected = value;
  53. OnPropertyChanged("IsSelected");
  54. }
  55. if (true == value && Selected != null)
  56. {
  57. Selected(this, EventArgs.Empty);
  58. }
  59. }
  60. }
  61. public event ComponentSelectionHandler Selected;
  62. public void Save()
  63. {
  64. if (_component != null)
  65. {
  66. if (_component.Filename != null)
  67. _component.Save();
  68. else
  69. SaveAs();
  70. }
  71. }
  72. public void SaveAs()
  73. {
  74. if (_component != null)
  75. {
  76. string filename = FileManager.GetSaveFile(_component.Name, Resources.Extension, Resources.Filter);
  77. if (filename != null)
  78. _component.SaveAs(filename);
  79. }
  80. }
  81. }
  82. }