diff --git a/zaaReloaded2/Controller/Settings.cs b/zaaReloaded2/Controller/Settings.cs index 46b1593..5691988 100755 --- a/zaaReloaded2/Controller/Settings.cs +++ b/zaaReloaded2/Controller/Settings.cs @@ -58,16 +58,12 @@ namespace zaaReloaded2.Controller #region Constructors public Settings() - { - Elements = new List(); - Uid = Guid.NewGuid(); - } + : this(string.Empty, new List()) + { } public Settings(string name) - : this() - { - Name = name; - } + : this(name, null) + { } /// /// Creates a new Settings object with an initial @@ -76,9 +72,8 @@ namespace zaaReloaded2.Controller /// Set of ElementBase /// object (or derived ones). public Settings(IList initialElements) - { - Elements = initialElements; - } + : this(String.Empty, initialElements) + { } /// /// Creates a new Settings object with an initial @@ -88,9 +83,10 @@ namespace zaaReloaded2.Controller /// object (or derived ones). /// Name of these settings. public Settings(string name, IList initialElements) - : this(initialElements) { + Uid = Guid.NewGuid(); Name = name; + Elements = initialElements; } #endregion diff --git a/zaaReloaded2/Properties/Settings.Designer.cs b/zaaReloaded2/Properties/Settings.Designer.cs index ec1e26e..902836a 100755 --- a/zaaReloaded2/Properties/Settings.Designer.cs +++ b/zaaReloaded2/Properties/Settings.Designer.cs @@ -233,5 +233,17 @@ namespace zaaReloaded2.Properties { return ((string)(this["DefaultItemsDrugs"])); } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("00000000-0000-0000-0000-000000000000")] + public global::System.Guid LastSettings { + get { + return ((global::System.Guid)(this["LastSettings"])); + } + set { + this["LastSettings"] = value; + } + } } } diff --git a/zaaReloaded2/Properties/Settings.settings b/zaaReloaded2/Properties/Settings.settings index 6d11aea..0fab6e4 100755 --- a/zaaReloaded2/Properties/Settings.settings +++ b/zaaReloaded2/Properties/Settings.settings @@ -71,5 +71,8 @@ Medikamente: TAC, CSA, SIR, Vancomycin, Gentamicin, Tobramicin + + 00000000-0000-0000-0000-000000000000 + \ No newline at end of file diff --git a/zaaReloaded2/Ribbon.cs b/zaaReloaded2/Ribbon.cs index 9e71ff3..f5428d8 100755 --- a/zaaReloaded2/Ribbon.cs +++ b/zaaReloaded2/Ribbon.cs @@ -26,6 +26,11 @@ using System.Windows; using System.Drawing; using System.Windows.Resources; using Office = Microsoft.Office.Core; +using zaaReloaded2.Views; +using zaaReloaded2.ViewModels; +using zaaReloaded2.Importer.ZaaImporter; +using zaaReloaded2.Formatter; +using zaaReloaded2.Controller; // TODO: Follow these steps to enable the Ribbon (XML) item: @@ -51,12 +56,14 @@ namespace zaaReloaded2 [ComVisible(true)] public class Ribbon : Office.IRibbonExtensibility { - private Office.IRibbonUI ribbon; + #region Constructor public Ribbon() { } + #endregion + #region IRibbonExtensibility Members public string GetCustomUI(string ribbonID) @@ -71,7 +78,8 @@ namespace zaaReloaded2 public void Ribbon_Load(Office.IRibbonUI ribbonUI) { - this.ribbon = ribbonUI; + _ribbon = ribbonUI; + Globals.ThisAddIn.Application.WindowSelectionChange += Application_WindowSelectionChange; } /// @@ -86,6 +94,12 @@ namespace zaaReloaded2 { switch (control.Id) { + case "zrlFormat": + DoFormat(); + break; + case "zrlSettings": + DoChooseSettings(); + break; case "zrlAbout": ViewModels.AboutViewModel vm = new ViewModels.AboutViewModel(); vm.InjectInto().ShowDialog(); @@ -138,6 +152,67 @@ namespace zaaReloaded2 } } + public bool CanFormat(Office.IRibbonControl control) + { + return Globals.ThisAddIn.Application.Selection.Paragraphs.Count > 0; + } + + #endregion + + #region Private methods + + void DoFormat() + { + if (CanFormat(null)) + { + SettingsRepository repository = SettingsRepository.Load(); + Guid lastSettingsUid = Properties.Settings.Default.LastSettings; + Settings lastSettings = repository.FindByGuid(lastSettingsUid); + if (lastSettings != null) + { + DoFormat(lastSettings); + } + else + { + DoChooseSettings(); + } + } + } + + void DoFormat(Settings settings) + { + ZaaImporter importer = new ZaaImporter(); + importer.Import(Globals.ThisAddIn.Application.Selection.Text); + Formatter.Formatter formatter =new Formatter.Formatter( + Globals.ThisAddIn.Application.ActiveDocument); + formatter.Settings = settings; + formatter.Laboratory = importer.Laboratory; + formatter.Run(); + } + + void DoChooseSettings() + { + SettingsRepository repository = SettingsRepository.Load(); + SettingsRepositoryViewModel vm = new SettingsRepositoryViewModel(repository); + vm.UseSettingsMessage.Sent += (sender, args) => + { + SettingsViewModel settingsVM = args.Content.ViewModel as SettingsViewModel; + Settings settings = settingsVM.RevealModelObject() as Settings; + DoFormat(settings); + Properties.Settings.Default.LastSettings = settings.Uid; + }; + vm.RequestCloseView += (sender, args) => + { + repository.Save(); + }; + vm.InjectInto().ShowDialog(); + } + + public void Application_WindowSelectionChange(Microsoft.Office.Interop.Word.Selection Sel) + { + _ribbon.Invalidate(); + } + #endregion #region Helpers @@ -163,5 +238,11 @@ namespace zaaReloaded2 } #endregion + + #region Fields + + private Office.IRibbonUI _ribbon; + + #endregion } } diff --git a/zaaReloaded2/Ribbon.xml b/zaaReloaded2/Ribbon.xml index a16f66e..6c83da5 100755 --- a/zaaReloaded2/Ribbon.xml +++ b/zaaReloaded2/Ribbon.xml @@ -25,8 +25,9 @@