public void Initialize(GTabSettings <TKey, TValue> settings) { Settings = settings; _displayGrid = new Grid(); _displayGrid.SetValue(Grid.ColumnProperty, 2); _displayGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }); _displayGrid.ColumnDefinitions.Add(new ColumnDefinition()); _displayGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(10) }); _displayGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }); _displayGrid.ColumnDefinitions.Add(new ColumnDefinition()); if (Settings.DbData == ServerDbs.ClientItems || Settings.DbData == ServerDbs.Pet || Settings.DbData == ServerDbs.Pet2 || Settings.DbData == ServerDbs.Mobs || Settings.DbData == ServerDbs.Mobs2 || Settings.DbData == ServerDbs.MobGroups || Settings.DbData == ServerDbs.Items || Settings.DbData == ServerDbs.Items2) { _viewGrid.Children.Add(_displayGrid); } else { ScrollViewer sv = new ScrollViewer(); sv.SetValue(Grid.ColumnProperty, 2); sv.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Auto); sv.Focusable = false; sv.Content = _displayGrid; _viewGrid.Children.Add(sv); } ProjectDatabase = settings.ClientDatabase; DbComponent = ProjectDatabase.GetDb <TKey>(settings.DbData); Table = Settings.Table; Header = Settings.TabName; Style = TryFindResource(settings.Style) as Style ?? Style; SearchEngine = settings.SearchEngine; SearchEngine.Init(_dbSearchPanel, this); Table.TableUpdated += new Table <TKey, TValue> .UpdateTableEventHandler(_table_TableUpdated); if (Settings.SearchEngine.SetupImageDataGetter != null) { ListViewDataTemplateHelper.GenerateListViewTemplateNew(_listView, new ListViewDataTemplateHelper.GeneralColumnInfo[] { new ListViewDataTemplateHelper.GeneralColumnInfo { Header = Settings.AttId.DisplayName, DisplayExpression = "[" + Settings.AttId.Index + "]", SearchGetAccessor = Settings.AttId.AttributeName, FixedWidth = Settings.AttIdWidth, TextAlignment = TextAlignment.Right, ToolTipBinding = "[" + Settings.AttId.Index + "]" }, new ListViewDataTemplateHelper.ImageColumnInfo { Header = "", DisplayExpression = "DataImage", SearchGetAccessor = Settings.AttId.AttributeName, FixedWidth = 26, MaxHeight = 24 }, new ListViewDataTemplateHelper.RangeColumnInfo { Header = Settings.AttDisplay.DisplayName, DisplayExpression = "[" + Settings.AttDisplay.Index + "]", SearchGetAccessor = Settings.AttDisplay.AttributeName, IsFill = true, ToolTipBinding = "[" + Settings.AttDisplay.Index + "]", MinWidth = 100, TextWrapping = TextWrapping.Wrap } }, new DatabaseItemSorter(Settings.AttributeList), new string[] { "Deleted", "{DynamicResource CellBrushRemoved}", "Modified", "{DynamicResource CellBrushModified}", "Added", "{DynamicResource CellBrushAdded}", "Normal", "{DynamicResource TextForeground}" }); } else { ListViewDataTemplateHelper.GenerateListViewTemplateNew(_listView, new ListViewDataTemplateHelper.GeneralColumnInfo[] { new ListViewDataTemplateHelper.GeneralColumnInfo { Header = Settings.AttId.DisplayName, DisplayExpression = "[" + Settings.AttId.Index + "]", SearchGetAccessor = Settings.AttId.AttributeName, FixedWidth = Settings.AttIdWidth, TextAlignment = TextAlignment.Right, ToolTipBinding = "[" + Settings.AttId.Index + "]" }, new ListViewDataTemplateHelper.RangeColumnInfo { Header = Settings.AttDisplay.DisplayName, DisplayExpression = "[" + Settings.AttDisplay.Index + "]", SearchGetAccessor = Settings.AttDisplay.AttributeName, IsFill = true, ToolTipBinding = "[" + Settings.AttDisplay.Index + "]", MinWidth = 100, TextWrapping = TextWrapping.Wrap } }, new DatabaseItemSorter(Settings.AttributeList), new string[] { "Deleted", "{DynamicResource CellBrushRemoved}", "Modified", "{DynamicResource CellBrushModified}", "Added", "{DynamicResource CellBrushAdded}", "Normal", "{DynamicResource TextForeground}" }); } if (!Settings.CanBeDelayed || Settings.AttributeList.Attributes.Any(p => p.IsSkippable)) { _deployTabControls(); } _initTableEvents(); if (Settings.ContextMenu != null) { if (Header is Control) { ((Control)Header).ContextMenu = Settings.ContextMenu; } } if (Settings.Loaded != null) { Settings.Loaded((GDbTabWrapper <TKey, ReadableTuple <TKey> >)(object) this, (GTabSettings <TKey, ReadableTuple <TKey> >)(object) Settings, ProjectDatabase.GetDb <TKey>(Settings.DbData)); } if (Settings.DisplayablePropertyMaker.OnTabVisible != null) { Settings.DisplayablePropertyMaker.OnTabVisible(this); } Loaded += delegate { TabControl parent = WpfUtilities.FindParentControl <TabControl>(this); if (parent != null) { parent.SelectionChanged += new SelectionChangedEventHandler(_parent_SelectionChanged); } }; _listView.PreviewMouseDown += delegate { _listView.Focus(); }; _listView.Loaded += delegate { try { if (IsVisible) { Keyboard.Focus(_listView); } } catch { } }; ApplicationShortcut.Link(ApplicationShortcut.Paste, () => ImportFromFile("clipboard"), _listView); ApplicationShortcut.Link(ApplicationShortcut.AdvancedPaste, () => ImportFromFile("clipboard", true), this); ApplicationShortcut.Link(ApplicationShortcut.AdvancedPaste2, () => ImportFromFile("clipboard", true), this); ApplicationShortcut.Link(ApplicationShortcut.Cut, () => _miCut_Click(null, null), _listView); ApplicationShortcut.Link(ApplicationShortcut.FromString("F3", "Search next empty ID"), () => { if (_listView.SelectedItems.Count > 0) { ReadableTuple <int> item = (_listView.SelectedItems[_listView.SelectedItems.Count - 1]) as ReadableTuple <int>; var original = item; if (item != null) { int id = item.Key; while (true) { id++; var idGeneric = (TKey)(object)id; var tuple = (ReadableTuple <int>)(object) Table.TryGetTuple(idGeneric); if (tuple == null && item != original && item != null) { TabNavigation.SelectList(DbComponent.DbSource, new TKey[] { item.GetKey <TKey>() }); break; } item = tuple; } } } }, _listView); }
public void Initialize(GTabSettings <TKey, TValue> settings) { Settings = settings; ProjectDatabase = settings.ClientDatabase; DbComponent = ProjectDatabase.GetDb <TKey>(settings.DbData); Table = Settings.Table; Header = Settings.TabName; Style = TryFindResource(settings.Style) as Style ?? Style; SearchEngine = settings.SearchEngine; SearchEngine.Init(_dbSearchPanel, this); Table.TableUpdated += new Table <TKey, TValue> .UpdateTableEventHandler(_table_TableUpdated); if (Settings.SearchEngine.SetupImageDataGetter != null) { Extensions.GenerateListViewTemplate(_listView, new ListViewDataTemplateHelper.GeneralColumnInfo[] { new ListViewDataTemplateHelper.GeneralColumnInfo { Header = Settings.AttId.DisplayName, DisplayExpression = "[" + Settings.AttId.Index + "]", SearchGetAccessor = Settings.AttId.AttributeName, FixedWidth = Settings.AttIdWidth, TextAlignment = TextAlignment.Right, ToolTipBinding = "[" + Settings.AttId.Index + "]" }, new ListViewDataTemplateHelper.ImageColumnInfo { Header = "", DisplayExpression = "DataImage", SearchGetAccessor = Settings.AttId.AttributeName, FixedWidth = 26, MaxHeight = 24 }, new ListViewDataTemplateHelper.RangeColumnInfo { Header = Settings.AttDisplay.DisplayName, DisplayExpression = "[" + Settings.AttDisplay.Index + "]", SearchGetAccessor = Settings.AttDisplay.AttributeName, IsFill = true, ToolTipBinding = "[" + Settings.AttDisplay.Index + "]", MinWidth = 100, TextWrapping = TextWrapping.Wrap } }, new DatabaseItemSorter(Settings.AttributeList), new string[] { "Deleted", "Red", "Modified", "Green", "Added", "Blue", "Normal", "Black" }, "generateStyle", "false"); } else { Extensions.GenerateListViewTemplate(_listView, new ListViewDataTemplateHelper.GeneralColumnInfo[] { new ListViewDataTemplateHelper.GeneralColumnInfo { Header = Settings.AttId.DisplayName, DisplayExpression = "[" + Settings.AttId.Index + "]", SearchGetAccessor = Settings.AttId.AttributeName, FixedWidth = Settings.AttIdWidth, TextAlignment = TextAlignment.Right, ToolTipBinding = "[" + Settings.AttId.Index + "]" }, new ListViewDataTemplateHelper.RangeColumnInfo { Header = Settings.AttDisplay.DisplayName, DisplayExpression = "[" + Settings.AttDisplay.Index + "]", SearchGetAccessor = Settings.AttDisplay.AttributeName, IsFill = true, ToolTipBinding = "[" + Settings.AttDisplay.Index + "]", MinWidth = 100, TextWrapping = TextWrapping.Wrap } }, new DatabaseItemSorter(Settings.AttributeList), new string[] { "Deleted", "Red", "Modified", "Green", "Added", "Blue", "Normal", "Black" }, "generateStyle", "false"); } if (!Settings.CanBeDelayed || Settings.AttributeList.Attributes.Any(p => p.IsSkippable)) { _deployTabControls(); } _initTableEvents(); if (Settings.ContextMenu != null) { if (Header is Control) { ((Control)Header).ContextMenu = Settings.ContextMenu; } } if (Settings.Loaded != null) { Settings.Loaded((GDbTabWrapper <TKey, ReadableTuple <TKey> >)(object) this, (GTabSettings <TKey, ReadableTuple <TKey> >)(object) Settings, ProjectDatabase.GetDb <TKey>(Settings.DbData)); } if (Settings.DisplayablePropertyMaker.OnTabVisible != null) { Settings.DisplayablePropertyMaker.OnTabVisible(this); } Loaded += delegate { TabControl parent = WpfUtilities.FindParentControl <TabControl>(this); if (parent != null) { parent.SelectionChanged += new SelectionChangedEventHandler(_parent_SelectionChanged); } }; _listView.PreviewMouseDown += delegate { _listView.Focus(); }; _listView.Loaded += delegate { try { if (IsVisible) { Keyboard.Focus(_listView); } } catch { } }; ApplicationShortcut.Link(ApplicationShortcut.Paste, () => ImportFromFile("clipboard"), _listView); ApplicationShortcut.Link(ApplicationShortcut.AdvancedPaste, () => ImportFromFile("clipboard", true), this); ApplicationShortcut.Link(ApplicationShortcut.AdvancedPaste2, () => ImportFromFile("clipboard", true), this); ApplicationShortcut.Link(ApplicationShortcut.Cut, () => _miCut_Click(null, null), _listView); }