Multiple buttons refreshing

This commit is contained in:
Sergey Chebotar 2023-05-27 08:50:30 +03:00
parent 2aae1805c5
commit e67d94f199
2 changed files with 23 additions and 57 deletions

View File

@ -15,6 +15,7 @@ namespace RhSolutions.Controllers;
public class RibbonController : ExcelRibbon public class RibbonController : ExcelRibbon
{ {
private static IRibbonUI ribbonUi; private static IRibbonUI ribbonUi;
private static bool _workbookIsValid;
public override string GetCustomUI(string RibbonID) public override string GetCustomUI(string RibbonID)
{ {
@ -81,17 +82,9 @@ public class RibbonController : ExcelRibbon
} }
} }
public bool GetConvertEnabled(IRibbonControl control) public bool GetConvertEnabled(IRibbonControl control) => _workbookIsValid;
{ public bool GetDxfEnabled(IRibbonControl control) => _workbookIsValid;
if (RhSolutionsAddIn.Excel.ActiveWorkbook == null) public bool GetGuessEnabled(IRibbonControl control) => RhSolutionsAddIn.Excel.ActiveWorkbook == null ? false : !_workbookIsValid;
return false;
else
{
Worksheet worksheet = RhSolutionsAddIn.Excel.ActiveWorkbook.ActiveSheet;
return worksheet.IsValidSource();
}
}
public bool GetExportEnabled(IRibbonControl control) public bool GetExportEnabled(IRibbonControl control)
{ {
@ -105,30 +98,6 @@ public class RibbonController : ExcelRibbon
} }
} }
public bool GetDxfEnabled(IRibbonControl control)
{
if (RhSolutionsAddIn.Excel.ActiveWorkbook == null)
return false;
else
{
Worksheet worksheet = RhSolutionsAddIn.Excel.ActiveWorkbook.ActiveSheet;
return worksheet.IsValidSource();
}
}
public bool GetGuessEnabled(IRibbonControl control)
{
if (RhSolutionsAddIn.Excel.ActiveWorkbook == null)
return false;
else
{
Worksheet worksheet = RhSolutionsAddIn.Excel.ActiveWorkbook.ActiveSheet;
return !worksheet.IsValidSource();
}
}
public string GetVersionLabel(IRibbonControl control) public string GetVersionLabel(IRibbonControl control)
{ {
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
@ -140,4 +109,16 @@ public class RibbonController : ExcelRibbon
string name = RhSolutionsAddIn.Configuration.GetPriceListFileName(); string name = RhSolutionsAddIn.Configuration.GetPriceListFileName();
return string.IsNullOrEmpty(name) ? "Шаблонный файл" : name; return string.IsNullOrEmpty(name) ? "Шаблонный файл" : name;
} }
public static void UpdateWorkbookValidation()
{
if (RhSolutionsAddIn.Excel.ActiveWorkbook == null)
_workbookIsValid = false;
else
{
Worksheet worksheet = RhSolutionsAddIn.Excel.ActiveWorkbook.ActiveSheet;
_workbookIsValid = worksheet.IsValidSource();
}
}
} }

View File

@ -16,35 +16,25 @@ namespace RhSolutions.Tools
public static void Initialize() public static void Initialize()
{ {
RhSolutionsAddIn.Excel.SheetSelectionChange += RefreshExportButton; RhSolutionsAddIn.Excel.SheetSelectionChange += RefreshExportButton;
RhSolutionsAddIn.Excel.SheetActivate += RefreshConvertButton; RhSolutionsAddIn.Excel.SheetActivate += RefreshButtons;
RhSolutionsAddIn.Excel.SheetActivate += RefreshDxfButton; RhSolutionsAddIn.Excel.WorkbookActivate += RefreshButtons;
RhSolutionsAddIn.Excel.SheetActivate += RefreshGuessButton;
RhSolutionsAddIn.Excel.WorkbookActivate += RefreshConvertButton;
RhSolutionsAddIn.Excel.WorkbookActivate += RefreshDxfButton;
RhSolutionsAddIn.Excel.WorkbookActivate += RefreshGuessButton;
RhSolutionsAddIn.Configuration.OnSettingsChange += RefreshSettingTitle; RhSolutionsAddIn.Configuration.OnSettingsChange += RefreshSettingTitle;
} }
public static void Uninitialize() public static void Uninitialize()
{ {
RhSolutionsAddIn.Excel.SheetSelectionChange -= RefreshExportButton; RhSolutionsAddIn.Excel.SheetSelectionChange -= RefreshExportButton;
RhSolutionsAddIn.Excel.SheetActivate -= RefreshConvertButton; RhSolutionsAddIn.Excel.SheetActivate -= RefreshButtons;
RhSolutionsAddIn.Excel.SheetActivate -= RefreshDxfButton; RhSolutionsAddIn.Excel.WorkbookActivate -= RefreshButtons;
RhSolutionsAddIn.Excel.SheetActivate -= RefreshGuessButton;
RhSolutionsAddIn.Excel.WorkbookActivate -= RefreshConvertButton;
RhSolutionsAddIn.Excel.WorkbookActivate -= RefreshDxfButton;
RhSolutionsAddIn.Excel.WorkbookActivate -= RefreshGuessButton;
RhSolutionsAddIn.Configuration.OnSettingsChange -= RefreshSettingTitle; RhSolutionsAddIn.Configuration.OnSettingsChange -= RefreshSettingTitle;
} }
private static void RefreshConvertButton(object sh) private static void RefreshButtons(object sh)
{ {
RibbonController.UpdateWorkbookValidation();
RibbonController.RefreshControl("convert"); RibbonController.RefreshControl("convert");
}
private static void RefreshDxfButton(object sh)
{
RibbonController.RefreshControl("dxfexport"); RibbonController.RefreshControl("dxfexport");
RibbonController.RefreshControl("Guessexport");
} }
private static void RefreshExportButton(object sh, Range target) private static void RefreshExportButton(object sh, Range target)
@ -52,11 +42,6 @@ namespace RhSolutions.Tools
RibbonController.RefreshControl("export"); RibbonController.RefreshControl("export");
} }
private static void RefreshGuessButton(object sh)
{
RibbonController.RefreshControl("Guessexport");
}
private static void RefreshSettingTitle(object sender, SettingChangingEventArgs e) private static void RefreshSettingTitle(object sender, SettingChangingEventArgs e)
{ {
RibbonController.RefreshControl("setPriceList"); RibbonController.RefreshControl("setPriceList");