public static void RefreshEverything() { using (new ProfileSection("Refresh everything")) { CacheManager.ClearAll(); MainWindowHelper.RefreshInstaller(); MainWindowHelper.RefreshInstances(); } }
private void RefreshInstances() { try { MainWindowHelper.RefreshInstances(); } catch (Exception ex) { WindowHelper.HandleError("Failed to refresh instances", true, ex); } }
private void RefreshInstances() { try { MainWindowHelper.RefreshInstances(); } catch (Exception ex) { this.HandleError(ex); } }
public static void Initialize() { using (new ProfileSection("Initialize main window")) { if (WindowsSettings.AppUiMainWindowWidth.Value > 0) { double d = WindowsSettings.AppUiMainWindowWidth.Value; MainWindow.Instance.MaxWidth = Screen.PrimaryScreen.Bounds.Width; MainWindow.Instance.Width = d; } MainWindowHelper.RefreshInstances(); MainWindowHelper.RefreshInstaller(); } }
public static void Initialize() { using (new ProfileSection("Initialize main window", typeof(MainWindowHelper))) { if (WindowsSettings.AppUiMainWindowWidth.Value > 0) { double d = WindowsSettings.AppUiMainWindowWidth.Value; MainWindow.Instance.MaxWidth = Screen.PrimaryScreen.Bounds.Width; MainWindow.Instance.Width = d; } MainWindowHelper.RefreshInstances(); PluginManager.ExecuteMainWindowLoadedProcessors(MainWindow.Instance); MainWindowHelper.RefreshInstaller(); } }
private static RoutedEventHandler GetClickHandler(IMainWindowButton mainWindowButton) { var clickHandler = new RoutedEventHandler(delegate { try { if (mainWindowButton != null && mainWindowButton.IsEnabled(MainWindow.Instance, SelectedInstance)) { mainWindowButton.OnClick(MainWindow.Instance, SelectedInstance); MainWindowHelper.RefreshInstances(); } } catch (Exception ex) { WindowHelper.HandleError(ex.Message, true); } }); return(clickHandler); }
private static void InitializeContextMenuItem(XmlElement menuItemElement, ItemCollection itemCollection, MainWindow window, Func <string, ImageSource> getImage) { try { if (menuItemElement.Name.EqualsIgnoreCase("separator")) { itemCollection.Add(new Separator()); return; } if (!menuItemElement.Name.EqualsIgnoreCase("item")) { Assert.IsTrue(false, "The element is not supported: {0}".FormatWith(menuItemElement.OuterXml)); } // create handler var mainWindowButton = (IMainWindowButton)Plugin.CreateInstance(menuItemElement); // create Context Menu Item var menuItem = new System.Windows.Controls.MenuItem { Header = menuItemElement.GetNonEmptyAttribute("header"), Icon = new Image { Source = getImage(menuItemElement.GetNonEmptyAttribute("image")), Width = 16, Height = 16 }, IsEnabled = mainWindowButton == null || mainWindowButton.IsEnabled(window, SelectedInstance), Tag = mainWindowButton }; if (mainWindowButton != null) { menuItem.Click += (obj, e) => { try { if (mainWindowButton.IsEnabled(MainWindow.Instance, SelectedInstance)) { mainWindowButton.OnClick(MainWindow.Instance, SelectedInstance); MainWindowHelper.RefreshInstances(); } } catch (Exception ex) { WindowHelper.HandleError(ex.Message, true); } }; SetIsEnabledProperty(menuItem, mainWindowButton); } foreach (var childElement in menuItemElement.ChildNodes.OfType <XmlElement>()) { InitializeContextMenuItem(childElement, menuItem.Items, window, getImage); } itemCollection.Add(menuItem); } catch (Exception ex) { Log.Error(ex, string.Format("Plugin Menu Item caused an exception")); } }
private static FrameworkElement GetRibbonButton(MainWindow window, Func <string, ImageSource> getImage, XmlElement button, RibbonGroupBox ribbonGroup, IMainWindowButton mainWindowButton) { var header = button.GetNonEmptyAttribute("label"); var clickHandler = GetClickHandler(mainWindowButton); if (button.ChildNodes.Count == 0) { // create Ribbon Button var imageSource = getImage(button.GetNonEmptyAttribute("largeImage")); var fluentButton = new Fluent.Button { Icon = imageSource, LargeIcon = imageSource, Header = header }; fluentButton.Click += clickHandler; ribbonGroup.Items.Add(fluentButton); return(fluentButton); } // create Ribbon Button var splitButton = ribbonGroup.Items.OfType <SplitButton>().SingleOrDefault(x => Extensions.EqualsIgnoreCase(x.Header.ToString().Trim(), header.Trim())); if (splitButton == null) { var imageSource = getImage(button.GetNonEmptyAttribute("largeImage")); splitButton = new Fluent.SplitButton { Icon = imageSource, LargeIcon = imageSource, Header = header }; if (mainWindowButton != null) { splitButton.Click += clickHandler; } else { var childrenButtons = new List <KeyValuePair <string, IMainWindowButton> >(); splitButton.Tag = childrenButtons; splitButton.Click += (sender, args) => splitButton.IsDropDownOpen = true; } ribbonGroup.Items.Add(splitButton); } var items = splitButton.Items; Assert.IsNotNull(items, nameof(items)); foreach (var menuItem in button.ChildNodes.OfType <XmlElement>()) { if (menuItem == null) { continue; } try { var name = menuItem.Name; if (name.EqualsIgnoreCase("separator")) { items.Add(new Separator()); continue; } if (!name.EqualsIgnoreCase("button")) { Log.Error($"This element is not supported as SplitButton element: {menuItem.OuterXml}"); continue; } var menuHeader = menuItem.GetAttribute("label"); var largeImage = menuItem.GetAttribute("largeImage"); var menuIcon = string.IsNullOrEmpty(largeImage) ? null : getImage(largeImage); var menuHandler = (IMainWindowButton)Plugin.CreateInstance(menuItem); Assert.IsNotNull(menuHandler, nameof(menuHandler)); var childrenButtons = splitButton.Tag as ICollection <KeyValuePair <string, IMainWindowButton> >; if (childrenButtons != null) { childrenButtons.Add(new KeyValuePair <string, IMainWindowButton>(menuHeader, menuHandler)); } var menuButton = new Fluent.MenuItem() { Header = menuHeader, IsEnabled = menuHandler.IsEnabled(window, SelectedInstance) }; if (menuIcon != null) { menuButton.Icon = menuIcon; } // bind IsEnabled event SetIsEnabledProperty(menuButton, menuHandler); menuButton.Click += delegate { try { if (menuHandler.IsEnabled(MainWindow.Instance, SelectedInstance)) { menuHandler.OnClick(MainWindow.Instance, SelectedInstance); MainWindowHelper.RefreshInstances(); } } catch (Exception ex) { WindowHelper.HandleError("Error during handling menu button click: " + menuHandler.GetType().FullName, true, ex); } }; items.Add(menuButton); } catch (Exception ex) { WindowHelper.HandleError("Error during initializing ribbon button: " + menuItem.OuterXml, true, ex); } } return(splitButton); }