Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Rogier committed Sep 23, 2021
1 parent 54eb849 commit 3abfac0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 36 deletions.
80 changes: 45 additions & 35 deletions Project/Source/Forms/MainForm/MainForm.Initialize.Menus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,42 @@ public void CreateSystemInformationMenu()
/// </summary>
public void InitializeSpecialMenus()
{
CreateProvidersLinks();
CommonMenusControl.Instance.ActionViewStats.Enabled = Settings.UsageStatisticsEnabled;
CommonMenusControl.Instance.ActionViewLog.Enabled = DebugManager.TraceEnabled;
ActionWebLinks.Visible = Settings.WebLinksMenuEnabled;
if ( Settings.WebLinksMenuEnabled )
{
ActionWebLinks.InitializeFromWebLinks(InitializeSpecialMenus);
ActionWebLinks.DuplicateTo(MenuWebLinks);
}
MenuWebLinks.Visible = Settings.WebLinksMenuEnabled;
MenuWebLinks.Enabled = Settings.WebLinksMenuEnabled;
ActionLocalWeather.Visible = Settings.WeatherMenuItemsEnabled;
ActionOnlineWeather.Visible = Settings.WeatherMenuItemsEnabled;
SeparatorMenuWeather.Visible = Settings.WeatherMenuItemsEnabled;
ActionWebLinks.Enabled = Settings.WebLinksMenuEnabled;
ActionLocalWeather.Enabled = Settings.WeatherMenuItemsEnabled;
ActionOnlineWeather.Enabled = Settings.WeatherMenuItemsEnabled;
SeparatorMenuWeather.Enabled = Settings.WeatherMenuItemsEnabled;
var isVisible = Settings.WeatherMenuItemsEnabled ? (int?)null : int.MinValue;
ActionLocalWeather.Tag = isVisible;
ActionOnlineWeather.Tag = isVisible;
SeparatorMenuWeather.Tag = isVisible;
ActionTools.DuplicateTo(MenuTools);
ActionInformation.DuplicateTo(MenuInformation);
if ( !Settings.AllowSuspendReminder && ActionEnableReminder.Enabled )
ActionEnableReminder.PerformClick();
ActionDisableReminder.Enabled = Settings.AllowSuspendReminder;
MenuDisableReminder.Enabled = Settings.AllowSuspendReminder;
}

/// <summary>
/// Create providers links menu items.
/// </summary>
private void CreateProvidersLinks()
{
// Weekly parashah menu
ActionStudyOnline.InitializeFromProviders(HebrewGlobals.WebProvidersParashah, (sender, e) =>
{
var menuitem = (ToolStripMenuItem)sender;
Expand All @@ -55,6 +91,15 @@ public void InitializeSpecialMenus()
weekParashah.Factory,
weekParashah.Day.HasLinkedParashah);
});
ActionOpenVerseOnline.InitializeFromProviders(HebrewGlobals.WebProvidersBible, (sender, e) =>
{
var menuitem = (ToolStripMenuItem)sender;
var weekParashah = ApplicationDatabase.Instance.GetWeeklyParashah();
if ( weekParashah.Factory == null ) return;
string verse = $"{(int)weekParashah.Factory.Book}.{weekParashah.Factory.VerseBegin}";
HebrewTools.OpenBibleProvider((string)menuitem.Tag, verse);
});
// Visual month context menu
ContextMenuDayParashahStudy.InitializeFromProviders(HebrewGlobals.WebProvidersParashah, (sender, e) =>
{
var menuitem = (ToolStripMenuItem)sender;
Expand All @@ -64,14 +109,6 @@ public void InitializeSpecialMenus()
weekParashah,
ContextMenuDayCurrentEvent.HasLinkedParashah);
});
ActionOpenVerseOnline.InitializeFromProviders(HebrewGlobals.WebProvidersBible, (sender, e) =>
{
var menuitem = (ToolStripMenuItem)sender;
var weekParashah = ApplicationDatabase.Instance.GetWeeklyParashah();
if ( weekParashah.Factory == null ) return;
string verse = $"{(int)weekParashah.Factory.Book}.{weekParashah.Factory.VerseBegin}";
HebrewTools.OpenBibleProvider((string)menuitem.Tag, verse);
});
ContextMenuDayParashahRead.InitializeFromProviders(HebrewGlobals.WebProvidersBible, (sender, e) =>
{
var menuitem = (ToolStripMenuItem)sender;
Expand All @@ -80,33 +117,6 @@ public void InitializeSpecialMenus()
string verse = $"{(int)weekParashah.Book}.{weekParashah.VerseBegin}";
HebrewTools.OpenBibleProvider((string)menuitem.Tag, verse);
});
CommonMenusControl.Instance.ActionViewStats.Enabled = Settings.UsageStatisticsEnabled;
CommonMenusControl.Instance.ActionViewLog.Enabled = DebugManager.TraceEnabled;
ActionWebLinks.Visible = Settings.WebLinksMenuEnabled;
ActionLocalWeather.Visible = Settings.WeatherMenuItemsEnabled;
ActionOnlineWeather.Visible = Settings.WeatherMenuItemsEnabled;
SeparatorMenuWeather.Visible = Settings.WeatherMenuItemsEnabled;
ActionWebLinks.Enabled = Settings.WebLinksMenuEnabled;
ActionLocalWeather.Enabled = Settings.WeatherMenuItemsEnabled;
ActionOnlineWeather.Enabled = Settings.WeatherMenuItemsEnabled;
SeparatorMenuWeather.Enabled = Settings.WeatherMenuItemsEnabled;
var isVisible = Settings.WeatherMenuItemsEnabled ? (int?)null : int.MinValue;
ActionLocalWeather.Tag = isVisible;
ActionOnlineWeather.Tag = isVisible;
SeparatorMenuWeather.Tag = isVisible;
MenuWebLinks.Visible = Settings.WebLinksMenuEnabled;
MenuWebLinks.Enabled = Settings.WebLinksMenuEnabled;
if ( Settings.WebLinksMenuEnabled )
{
ActionWebLinks.InitializeFromWebLinks(InitializeSpecialMenus);
ActionWebLinks.DuplicateTo(MenuWebLinks);
}
ActionTools.DuplicateTo(MenuTools);
ActionInformation.DuplicateTo(MenuInformation);
if ( !Settings.AllowSuspendReminder && ActionEnableReminder.Enabled )
ActionEnableReminder.PerformClick();
ActionDisableReminder.Enabled = Settings.AllowSuspendReminder;
MenuDisableReminder.Enabled = Settings.AllowSuspendReminder;
}

}
Expand Down
2 changes: 1 addition & 1 deletion Project/Source/Program/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ void update(Form form)
});
}
MainForm.Instance.CalendarMonth._btnToday.ButtonText = AppTranslations.Today.GetLang();
task?.Wait();
MainForm.Instance.CreateSystemInformationMenu();
}
catch ( Exception ex )
Expand All @@ -327,7 +328,6 @@ void update(Form form)
}
finally
{
task?.Wait();
Globals.ChronoTranslate.Stop();
Settings.BenchmarkTranslate = Globals.ChronoTranslate.ElapsedMilliseconds;
}
Expand Down

0 comments on commit 3abfac0

Please sign in to comment.