diff --git a/src/AddIn/AddIn.cs b/src/AddIn/AddIn.cs index ad77247..b532bfb 100644 --- a/src/AddIn/AddIn.cs +++ b/src/AddIn/AddIn.cs @@ -5,7 +5,6 @@ using Microsoft.Office.Interop.Excel; using System.Net.Http; using System.Runtime.Caching; - namespace RehauSku { enum ResponseOrder @@ -27,34 +26,18 @@ namespace RehauSku { httpClient = new HttpClient(); memoryCache = new MemoryCache("RehauSku"); + Excel = (Application)ExcelDnaUtil.Application; RegisterFunctions(); IntelliSenseServer.Install(); RegistryUtil.Initialize(); - Excel = (Application)ExcelDnaUtil.Application; - AddEvents(); - } - - private void AddEvents() - { - Excel.SheetSelectionChange += RefreshExportButton; - Excel.SheetActivate += RefreshConvertButton; - Excel.WorkbookActivate += RefreshConvertButton; - } - - private void RefreshConvertButton(object sh) - { - Interface.RibbonController.RefreshControl("convertPrice"); - } - - private void RefreshExportButton(object sh, Range target) - { - Interface.RibbonController.RefreshControl("exportToPrice"); + EventsUtil.Initialize(); } public void AutoClose() { IntelliSenseServer.Uninstall(); RegistryUtil.Uninitialize(); + EventsUtil.Uninitialize(); memoryCache.Dispose(); } diff --git a/src/AddIn/EventsUtil.cs b/src/AddIn/EventsUtil.cs new file mode 100644 index 0000000..102e12e --- /dev/null +++ b/src/AddIn/EventsUtil.cs @@ -0,0 +1,33 @@ +using Microsoft.Office.Interop.Excel; + +namespace RehauSku +{ + internal static class EventsUtil + { + private static Application Excel = AddIn.Excel; + + public static void Initialize() + { + Excel.SheetSelectionChange += RefreshExportButton; + Excel.SheetActivate += RefreshConvertButton; + Excel.WorkbookActivate += RefreshConvertButton; + } + + public static void Uninitialize() + { + Excel.SheetSelectionChange -= RefreshExportButton; + Excel.SheetActivate -= RefreshConvertButton; + Excel.WorkbookActivate -= RefreshConvertButton; + } + + private static void RefreshConvertButton(object sh) + { + Interface.RibbonController.RefreshControl("convertPrice"); + } + + private static void RefreshExportButton(object sh, Range target) + { + Interface.RibbonController.RefreshControl("exportToPrice"); + } + } +} diff --git a/src/RehauSku.Assist.csproj b/src/RehauSku.Assist.csproj index 9ffc4c4..76bd243 100644 --- a/src/RehauSku.Assist.csproj +++ b/src/RehauSku.Assist.csproj @@ -115,6 +115,7 @@ +