/// <summary> /// Changes visibility of InnerLog tab /// </summary> /// <param name="b"></param> internal void SwitchInnerLogTabVisibility(bool b) { Log9KTab t = GetTab(INNER_LOG_TAB); if (t == null) { Error("Не найдена вкладка для внутреннего логирования контрола логов"); return; } if (b) { if (!Log9KTabsCollection.Contains(t)) { Log9KTabsCollection.Add(t); _isInnerLogTabVisible = true; } } else { if (Log9KTabsCollection.Contains(t)) { Log9KTabsCollection.Remove(t); _isInnerLogTabVisible = false; } } }
/// <summary> /// Initializes tabs by given tab order (adding tabs to TabControl, binding with Log9KTabs) /// </summary> /// <param name="types"></param> private void InitTabs(Log9KCore.LogEntryType[] types) { /* Creating tabs for predefined types, custom types */ Log9KTabAll tabAll = (Log9KTabAll)_log9KCore.Log9KTabsDictionary[Log9KCore.ALL_LOG_TAB_S]; AddTab(tabAll); /* Generate list of strings, which are names of tabs*/ List <string> logEntryTypeStrings; if (types == null) { logEntryTypeStrings = new List <string>(Enum.GetNames(typeof(Log9KCore.LogEntryType))); } else { logEntryTypeStrings = new List <string>(); foreach (Log9KCore.LogEntryType t in types) { logEntryTypeStrings.Add(t.ToString()); } } /* Adding list of custom types to tab names */ logEntryTypeStrings.AddRange(_log9KCore.CustomTypesList); foreach (string logEntryType in logEntryTypeStrings) { if (logEntryType == Log9KCore.LogEntryType.CUSTOM.ToString() || logEntryType == Log9KCore.ALL_LOG_TAB_S) { continue; } Log9KTab currentTab = _log9KCore.Log9KTabsDictionary[logEntryType]; AddTab(currentTab); } }
/// <summary> /// Callback, that adds new tab of custom (user's) type to TabControl. /// </summary> /// <param name="e"></param> private void c_CustomTypeAdded(Log9KCore.CustomTypeAddedEventArgs e) { if (_log9KCore.Log9KTabsDictionary.ContainsKey(e.Name)) { Log9KTab customTab = _log9KCore.Log9KTabsDictionary[e.Name]; AddTab(customTab); } }
private static Uri IconForDefaultTabs(Log9KTab log9KTab) { if (log9KTab.IsAllTab()) { return(new Uri("pack://application:,,,/img/" + Log9KCore.ALL_LOG_TAB_S + ".png")); } return(new Uri("pack://application:,,,/img/" + log9KTab.TabType.ToString().ToLower() + ".png")); }
/// <summary> /// Create mixed tab /// </summary> /// <param name="types"></param> /// <returns></returns> // public bool CreateMixedTab(params object[] types) { // if (types.Length == 0) { // InnerLog("Ошибка: аргумента — длина массива равна нулю"); // return false; // } // List<Log9KTab> tabsList = new List<Log9KTab>(); // foreach (object type in types) { // bool isTabTypes = type is TabTypes; // bool isString = type is string; // if (!(isTabTypes || isString)) { // InnerLog("Ошибка: в метод был передан объект не являющийся строкой/TabTypes"); // return false; // } // if (isTabTypes) { // TabTypes tabType = (TabTypes) (type as TabTypes?); // if (tabType == TabTypes.CUSTOM) { // InnerLog("Для установки положения пользовательской вкладки передавайте имя вкладки в метод, а не тип CUSTOM"); // continue; // } // Log9KTab log9Ktab = GetTab(tabType); // if (log9Ktab == null) { // InnerLog("Не найдено вкладки с типом: " + tabType); // } else { // tabsList.Add(log9Ktab); // } // } // if (isString) { // string tabType = type as string; // Log9KTab log9Ktab = GetTab(tabType); // if (log9Ktab != null) { // tabsList.Add(log9Ktab); // } else { // InnerLog("Ошибка: вкладки с типом: " + tabType + " не найдено"); // } // } // } // // if (tabsList.Count == 0) { // InnerLog("Ошибка: при формировании списка вкладок был получен пустой список"); // return false; // } // // StringBuilder mixedTabType = new StringBuilder(); // foreach (Log9KTab tab in tabsList) { // mixedTabType.Append(tab.TabTypeString); // } // string mixedTabTypeName = mixedTabType.ToString(); // Log9KTab t = new Log9KTab(mixedTabType.ToString()); // if (_log9KTabsDictionary.ContainsKey(mixedTabTypeName)) { // InnerLog("Уже есть такая миксованая вкладка: " + mixedTabTypeName); // return false; // } // // _log9KTabsDictionary.Add(mixedTabTypeName, t); // // return true; // } /// <summary> /// Set header for tab which will be displayed in control /// </summary> /// <param name="tabType"></param> /// <param name="header"></param> public void SetTabHeader(TabTypes tabType, string header) { Log9KTab tab = GetTab(tabType); if (tab != null) { tab.TabHeader = header; } }
/// <summary> /// Set maximal size for observable collection (which is displayed in DataGrid) of given tab /// </summary> /// <param name="tabType"></param> /// <param name="maxCollectionSize"></param> public void SetMaxCollectionSizeForTab(TabTypes tabType, uint maxCollectionSize) { Log9KTab log9KTab = GetTab(tabType); if (log9KTab == null) { return; } log9KTab.LogEntryCollection.MaxCollectionSize = maxCollectionSize; }
/// <summary> /// Add entry to tab of it's type /// </summary> /// <param name="entry"></param> private void AddToConcreteTypeTab(Log9KEntry entry) { Log9KTab entryTypeTab = GetTab(entry.TypeString); if (entryTypeTab == null) { InnerLog("Ошибка: при добавлении лога — вкладка " + entry.TypeString + " равна null"); return; } entryTypeTab.AddLogEntry(entry); }
/// <summary> /// Method that creates TabItem for Log9KTab and filling it with ui elements. /// </summary> /// <param name="log9KTab"></param> /// <returns></returns> private static TabItem CreateTabItem(Log9KTab log9KTab) { string name = log9KTab.TabName; Log9KCore.LogEntryType type = log9KTab.TabType; ObservableCollection <Log9KEntry> logEntryCollection = log9KTab.LogEntryCollection; TabItem tabItem = new TabItem { Header = name }; /* Header of Tab: text and icon */ StackPanel headerStackPanel = new StackPanel { Orientation = Orientation.Horizontal }; headerStackPanel.Children.Add(new TextBlock { Text = name, HorizontalAlignment = HorizontalAlignment.Left, Foreground = _typeToColorConverter.Convert(type) }); try { BitmapImage iconBitmapImage = new BitmapImage(IconForDefaultTabs(log9KTab)); Image icon = new Image { Source = iconBitmapImage, Width = ICON_WIDTH, Height = ICON_HEIGHT, HorizontalAlignment = HorizontalAlignment.Right }; headerStackPanel.Children.Add(icon); } catch (IOException) { Debug.WriteLine("Can't find icon for: " + name); } tabItem.Header = headerStackPanel; /*------------------------------------------------------------ */ /*------------------------------------------------------------ */ /* * <Style TargetType="DataGridRow"> * <Style.Triggers> * <DataTrigger Binding="{Binding Path=City_name}" Value="SomeCity"> * <Setter Property="Background" Value="{StaticResource SomeCityBackground}"/> * </DataTrigger> * </Style.Triggers> * </Style> */ return(tabItem); }
/// <summary> /// Adds new TabItem to the TabControl (by given Log9KTab) /// </summary> /// <param name="log9KTab"></param> private void AddTab(Log9KTab log9KTab) { AddEventsToTab(log9KTab); string name = log9KTab.TabName; TabItem tabItem = CreateTabItem(log9KTab); Log9KTabGrid l = new Log9KTabGrid(); l.DataGrid9K.ItemsSource = log9KTab.LogEntryCollection; l.Width = 1000; tabItem.Content = l; _tabItemDictionary.Add(name, tabItem); TabControl.Items.Add(tabItem); }
/// <summary> /// Make the tab with given type active /// </summary> public void SetActiveTab(string tabType) { Log9KTab tab = GetTab(tabType); if (tab != null) { if (!Log9KTabsCollection.Contains(tab)) { return; } Log9KUtil.BeginInvokeInUiThread(() => { CurrentTab = tab; }); } }
/// <summary> /// <para>Callback for event when log entry duplication occured.</para> /// <para>Adds new TreeViewItem to TreeView, if that duplication is new.</para> /// <para>Otherwise it refreshes number of occurs in TreeViewItem header /// (number in parenthesis).</para> /// </summary> /// <param name="e"></param> private void c_DuplicationEntryAdded(Log9KTab.DuplicationEntryAddedEventArgs e) { if (e.TabName == null || e.Message == null) { return; } if (!_tabItemDictionary.ContainsKey(e.TabName)) { return; } Util9K.InvokeInUiThread(() => { Log9KTab log9KTab = _log9KCore.Log9KTabsDictionary[e.TabName]; Log9KEntry log9KEntry = log9KTab.DuplicationsDictionary[e.DuplicationKey].Item1; ObservableCollection <Log9KTime> timesList = log9KTab.DuplicationsDictionary[e.DuplicationKey].Item2; TabItem tabItem = _tabItemDictionary[e.TabName]; try { Grid tabGrid = (Grid)tabItem.Content; TreeView treeView = (TreeView)tabGrid.Children[_treeViewIndex]; if (e.IsNewDuplication) { /* Adding new TreeViewItem */ StackPanel headerStackPanel = new StackPanel { Orientation = Orientation.Horizontal }; /* --- TYPE Message (number of duplications) --- */ /* Foreground color for TYPE */ Brush foreground = _typeToColorConverter.Convert(e.TabType); /* Type TextBlock */ string type; if (e.TabType == Log9KCore.LogEntryType.CUSTOM) { type = e.EntryCustomType; } else { type = e.TabType.ToString(); } headerStackPanel.Children.Add(new TextBlock { Text = type, Foreground = foreground, FontWeight = FontWeights.Bold }); /* Message TextBlock */ headerStackPanel.Children.Add(new TextBlock { Text = e.Message, Margin = new Thickness(5, 0, 0, 0) }); /* Number of duplications TextBlock */ headerStackPanel.Children.Add(new TextBlock { Text = "(2)", FontWeight = FontWeights.Bold, Margin = new Thickness(5, 0, 0, 0) }); TreeViewItem treeViewItem = new TreeViewItem { Header = headerStackPanel, ItemsSource = timesList }; treeView.Items.Add(treeViewItem); } else { /* Updating number of duplications in parenthesis */ foreach (TreeViewItem treeViewItem in treeView.Items) { StackPanel headerStackPanel = (StackPanel)treeViewItem.Header; TextBlock typeTextBlock = (TextBlock)headerStackPanel.Children[0]; TextBlock messageTextBlock = (TextBlock)headerStackPanel.Children[1]; if (messageTextBlock.Text.Equals(e.Message) && typeTextBlock.Text.Equals(log9KEntry.TypeString)) { TextBlock numberOfDuplicationTextBlock = (TextBlock)headerStackPanel.Children[2]; int numberOfDuplication = timesList.Count; numberOfDuplicationTextBlock.Text = "(" + numberOfDuplication + ")"; } } } } catch (InvalidCastException) { } }); }
private void AddEventsToTab(Log9KTab log9KTab) { log9KTab.DuplicationEntryAdded -= c_DuplicationEntryAdded; log9KTab.DuplicationEntryAdded += c_DuplicationEntryAdded; }
/// <summary> /// <para>Set order of tabs in tabs collection</para> /// <para>Arguments should be TabTypes and strings (for custom tabs)</para> /// </summary> /// <param name="types">Types of tabs in desired order (TabTypes and strings)</param> public bool SetTabOrder(params object[] types) { if (types.Length == 0) { InnerLog("Ошибка: аргумент функции SetTabOrder — длина массива равна нулю"); return(false); } List <Log9KTab> tabsList = new List <Log9KTab>(); foreach (object type in types) { bool isTabTypes = type is TabTypes; bool isString = type is string; if (!(isTabTypes || isString)) { InnerLog("Ошибка: в метод SetTabOrder был передан объект не являющийся строкой/TabTypes"); return(false); } if (isTabTypes) { TabTypes tabType = type as TabTypes? ?? TabTypes.INFO; if (tabType == TabTypes.CUSTOM) { InnerLog("Для установки положения пользовательской вкладки передавайте имя вкладки в метод, а не тип CUSTOM"); continue; } Log9KTab log9Ktab = GetTab(tabType); if (log9Ktab == null) { InnerLog("Не найдено вкладки с типом: " + tabType); } else { tabsList.Add(log9Ktab); } } if (isString) { string tabType = type as string; Log9KTab log9Ktab = GetTab(tabType); if (log9Ktab != null) { tabsList.Add(log9Ktab); } else { InnerLog("Ошибка: вкладки с типом: " + tabType + " не найдено"); } } } if (tabsList.Count == 0) { InnerLog("Ошибка: в методе SetTabOrder при формировании списка вкладок был получен пустой список"); return(false); } else { Log9KTabsCollection.Clear(); foreach (Log9KTab log9KTab in tabsList) { Log9KTabsCollection.Add(log9KTab); } if (_isInnerLogTabVisible) { Log9KTab innerTab = GetTab(INNER_LOG_TAB); if (innerTab != null) { Log9KTabsCollection.Add(innerTab); } else { Error("Не найдена вкладка для логирования LogControl9K:" + INNER_LOG_TAB); } } return(true); } }
/// <summary> /// <para>Add new CUSTOM tab to Core's tab's collections, it also used by non-custom tab method</para> /// <para>Use this method for adding new CUSTOM tabs instead of directly changing collections</para> /// </summary> /// <param name="tabType"></param> /// <param name="tab"></param> private void AddNewTab(string tabType, Log9KTab tab) { _log9KTabsDictionary.Add(tabType, tab); Log9KTabsCollection.Add(tab); }
/// <summary> /// <para>Add new tab to Core's tab's collections, </para> /// <para>Use this method for adding new tabs instead of directly changing collections</para> /// </summary> /// <param name="tabType"></param> /// <param name="tab"></param> private void AddNewTab(TabTypes tabType, Log9KTab tab) { AddNewTab(tabType.ToString(), tab); }