diff options
author | Sergey Chebotar <s.chebotar@gmail.com> | 2022-02-04 17:13:47 +0300 |
---|---|---|
committer | Sergey Chebotar <s.chebotar@gmail.com> | 2022-02-04 17:13:47 +0300 |
commit | cc96e1ebe7255c7278c70cef0f951103e9844487 (patch) | |
tree | 85f8c6573b5c162c21a0adc192560a4e53732f69 /src/Interface | |
parent | 6e889419e2658a3a80fa00582314f1428f6052e5 (diff) |
Implement Enable/Disable tools buttons events
Diffstat (limited to 'src/Interface')
-rw-r--r-- | src/Interface/RibbonController.cs | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/src/Interface/RibbonController.cs b/src/Interface/RibbonController.cs index 822fe98..7d70391 100644 --- a/src/Interface/RibbonController.cs +++ b/src/Interface/RibbonController.cs @@ -1,4 +1,5 @@ using ExcelDna.Integration.CustomUI; +using Microsoft.Office.Interop.Excel; using RehauSku.PriceListTools; using System; using System.Runtime.InteropServices; @@ -9,16 +10,18 @@ namespace RehauSku.Interface [ComVisible(true)] public class RibbonController : ExcelRibbon { + private static IRibbonUI ribbonUi; + public override string GetCustomUI(string RibbonID) { return @" - <customUI xmlns='http://schemas.microsoft.com/office/2006/01/customui'> + <customUI onLoad='RibbonLoad' xmlns='http://schemas.microsoft.com/office/2006/01/customui'> <ribbon> <tabs> <tab id='rau' label='REHAU'> <group id='priceList' label='Прайс-лист'> - <button id='exportToPrice' label='Экспорт в новый файл' size='normal' imageMso='PivotExportToExcel' onAction='OnExportPressed'/> - <button id='convertPrice' label='Актуализировать' size='normal' imageMso='FileUpdate' onAction='OnConvertPressed'/> + <button id='exportToPrice' getEnabled='GetExportEnabled' label='Экспорт в новый файл' size='normal' imageMso='PivotExportToExcel' onAction='OnExportPressed'/> + <button id='convertPrice' getEnabled='GetConvertEnabled' label='Актуализировать' size='normal' imageMso='FileUpdate' onAction='OnConvertPressed'/> <menu id='conjoinMenu' label='Объединить' imageMso='Copy'> <button id='mergeFiles' label='Сложить' onAction='OnMergePressed'/> <button id='combineFiles' label='По колонкам' onAction='OnCombinePressed'/> @@ -33,6 +36,19 @@ namespace RehauSku.Interface </customUI>"; } + public void RibbonLoad(IRibbonUI sender) + { + ribbonUi = sender; + } + + public static void RefreshControl(string id) + { + if (ribbonUi != null) + { + ribbonUi.InvalidateControl(id); + } + } + public void OnMergePressed(IRibbonControl control) { MergeTool mergeTool = new MergeTool(); @@ -59,6 +75,19 @@ namespace RehauSku.Interface } } + public bool GetConvertEnabled(IRibbonControl control) + { + if (AddIn.Excel.ActiveWorkbook == null) + return false; + + else + { + Worksheet worksheet = AddIn.Excel.ActiveWorkbook.ActiveSheet; + return worksheet.IsRehauSource(); + } + } + + public void OnExportPressed(IRibbonControl control) { try @@ -79,6 +108,18 @@ namespace RehauSku.Interface } } + public bool GetExportEnabled(IRibbonControl control) + { + if (AddIn.Excel.ActiveWorkbook == null) + return false; + + else + { + Range selection = AddIn.Excel.Selection; + return selection.Columns.Count == 2; + } + } + public void OnConvertPressed(IRibbonControl control) { ConvertTool convertTool = new ConvertTool(); |