Esempio n. 1
0
        private bool _isCurrentTabSelected()
        {
            TabControl tabControl  = WpfUtilities.FindParentControl <TabControl>(this);
            TabItem    selectedTab = tabControl.Items[tabControl.SelectedIndex] as TabItem;

            return(selectedTab != null && WpfUtilities.IsTab(this, selectedTab.Header.ToString()));
        }
Esempio n. 2
0
        public void ResetEnabled()
        {
            _stateBrush         = Application.Current.Resources["TabItemTextSelectedForeground"] as SolidColorBrush;
            _stateInactiveBrush = Application.Current.Resources["TabItemTextNormalForeground"] as SolidColorBrush;

            Grid presenter = WpfUtilities.FindParentControl <Grid>(this);

            if (presenter == null)
            {
                return;
            }

            if (!(presenter.Children[2] is TextBox))
            {
                return;
            }

            TextBox box = (TextBox)presenter.Children[2];

            if (box.Text == "Visible")
            {
                Foreground = _stateBrush;
            }
            else
            {
                Foreground = _stateInactiveBrush;
            }
        }
Esempio n. 3
0
        public void ResetEnabled()
        {
            _stateBrush         = Brushes.Black;
            _stateInactiveBrush = new SolidColorBrush(Color.FromArgb(255, 215, 215, 215));

            Grid presenter = WpfUtilities.FindParentControl <Grid>(this);

            if (presenter == null)
            {
                return;
            }

            if (!(presenter.Children[2] is TextBox))
            {
                return;
            }

            TextBox box = (TextBox)presenter.Children[2];

            if (box.Text == "Visible")
            {
                Foreground = _stateBrush;
            }
            else
            {
                Foreground = _stateInactiveBrush;
            }
        }
Esempio n. 4
0
        public DisplayLabel()
        {
            FocusVisualStyle = null;
            Margin           = new Thickness(-4, -4, 0, -4);
            Padding          = new Thickness(0);

            FontSize = 12;

            MouseEnter += delegate {
                if (_dbSource != null)
                {
                    if (FtpHelper.HasBeenMapped())
                    {
                        ToolTip = DbPathLocator.DetectPath(_dbSource);
                    }
                    else
                    {
                        ToolTip = "Directory has not been mapped yet. Load the database first.";
                    }
                }

                if (ToolTip == null)
                {
                    ToolTip = "File not found. This database will be disabled.";
                }
            };

            SizeChanged += delegate {
                if (!_isLoaded)
                {
                    Grid    presenter = WpfUtilities.FindParentControl <Grid>(this);
                    TextBox box       = (TextBox)presenter.Children[2];

                    if (box.Text == "Visible")
                    {
                        Foreground = _stateBrush;
                    }
                    else
                    {
                        Foreground = _stateInactiveBrush;
                    }

                    box.TextChanged += delegate {
                        if (box.Text == "Visible")
                        {
                            Foreground = _stateBrush;
                        }
                        else
                        {
                            Foreground = _stateInactiveBrush;
                        }
                    };

                    _isLoaded = true;
                }
            };
        }
        public override void ButtonClicked()
        {
            LevelEditDialog dialog = new LevelEditDialog(_textBox.Text, _maxVal, false, false, false);

            dialog.Owner = WpfUtilities.FindParentControl <Window>(_button);

            if (dialog.ShowDialog() == true)
            {
                _textBox.Text = dialog.Text;
            }
        }
        public override void ButtonClicked()
        {
            ScriptEditDialog dialog = new ScriptEditDialog(_textBox.Text);

            dialog.Owner = WpfUtilities.FindParentControl <Window>(_button);

            if (dialog.ShowDialog() == true)
            {
                _textBox.Text = dialog.Text;
            }
        }
Esempio n. 7
0
        private bool _isCurrentTabSelected()
        {
            return(this.Dispatch(() => {
                try {
                    TabControl tabControl = WpfUtilities.FindParentControl <TabControl>(this);
                    TabItem selectedTab = tabControl.Items[tabControl.SelectedIndex] as TabItem;

                    return selectedTab != null && WpfUtilities.IsTab(this, selectedTab.Header.ToString());
                }
                catch {
                    return false;
                }
            }));
        }
Esempio n. 8
0
        private void _tviItemDb_TextChanged(object sender, TextChangedEventArgs e)
        {
            try {
                _delayedReloadDatabase = true;

                TextViewItem item = WpfUtilities.FindParentControl <TextViewItem>(sender as TextBox);

                if (item != null)
                {
                    ProjectConfiguration.DatabasePath = _tviItemDb.TextBoxItem.Text;
                    item.CheckValid();
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
Esempio n. 9
0
        private void _copyToCallback(TKey oldkey, TKey newkey, bool executed)
        {
            if (executed)
            {
                Table.GetTuple(newkey).Added = true;

                TabControl tabControl  = WpfUtilities.FindParentControl <TabControl>(this);
                TabItem    selectedTab = tabControl.Items[tabControl.SelectedIndex] as TabItem;

                if (_isCurrentTabSelected())
                {
                    _listView.SelectedItem = Table.GetTuple(newkey);
                }

                _listView.ScrollToCenterOfView(_listView.SelectedItem);
            }
        }
Esempio n. 10
0
        public DisplayLabel(ServerDbs dbSource, BaseDb db) : this()
        {
            _dbSource = dbSource;
            _db       = db;
            _toString = dbSource.Filename;
            Content   = dbSource.DisplayName;

            if (_db != null)
            {
                _db.Attached.CollectionChanged += delegate(object sender, NotifyCollectionChangedEventArgs e) {
                    if (e.NewItems != null && e.NewItems.Count > 0 && e.Action == NotifyCollectionChangedAction.Replace || e.Action == NotifyCollectionChangedAction.Add)
                    {
                        if (e.NewItems[0] is KeyValuePair <string, object> )
                        {
                            var newItem = (KeyValuePair <string, object>)e.NewItems[0];

                            if (newItem.Key == "IsEnabled")
                            {
                                if (_db.Attached["IsEnabled"] == null || (bool)_db.Attached["IsEnabled"])
                                {
                                    _stateBrush         = Brushes.Black;
                                    _stateInactiveBrush = new SolidColorBrush(Color.FromArgb(255, 98, 98, 98));
                                }
                                else
                                {
                                    _stateBrush         = Brushes.Red;
                                    _stateInactiveBrush = Brushes.Red;
                                }

                                Grid    presenter = WpfUtilities.FindParentControl <Grid>(this);
                                TextBox box       = (TextBox)presenter.Children[2];

                                if (box.Text == "Visible")
                                {
                                    Foreground = _stateBrush;
                                }
                                else
                                {
                                    Foreground = _stateInactiveBrush;
                                }
                            }
                        }
                    }
                };
            }
        }
Esempio n. 11
0
        private void _tviItem_TextChanged(object sender, TextChangedEventArgs e)
        {
            try {
                _delayedReloadDatabase = true;

                TextViewItem item = WpfUtilities.FindParentControl <TextViewItem>(sender as TextBox);

                if (item != null)
                {
                    item.ForceSetSetting();
                    item.CheckValid();
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
Esempio n. 12
0
        public override void ButtonClicked()
        {
            var    db     = _tab.GetTable <int>(ServerDbs.Skills);
            object maxVal = 20;
            var    tuple  = db.TryGetTuple(((ReadableTuple <TKey>)_tab.List.SelectedItem).GetKey <int>());

            if (tuple != null)
            {
                maxVal = tuple.GetValue(ServerSkillAttributes.MaxLevel);
            }

            LevelEditDialog dialog = new LevelEditDialog(_textBox.Text, maxVal, false);

            dialog.Owner = WpfUtilities.FindParentControl <Window>(_button);

            if (dialog.ShowDialog() == true)
            {
                _textBox.Text = dialog.Text;
            }
        }
        private void _buttonQuickEdit_Click(object sender, RoutedEventArgs e)
        {
            _itemDescriptionDialog.LoadItem(_tab.List.SelectedItem as ReadableTuple <int>);
            WindowProvider.Show(_itemDescriptionDialog, (Control)sender, WpfUtilities.FindParentControl <Window>(_tab.Content as DependencyObject));

            _itemDescriptionDialog.Closed += delegate {
                if (_itemDescriptionDialog.Result == true && _itemDescriptionDialog.Item != null)
                {
                    _textBox.Text = _itemDescriptionDialog.Output;
                }
                _itemDescriptionDialog = new ItemDescriptionDialog();
            };

            _itemDescriptionDialog.Apply += delegate {
                if (_itemDescriptionDialog.Result == true && _itemDescriptionDialog.Item != null)
                {
                    _textBox.Text = _itemDescriptionDialog.Output;
                }
            };
        }
Esempio n. 14
0
        public DisplayLabel(ServerDbs dbSource, BaseDb db) : this()
        {
            _dbSource = dbSource;
            _db       = db;
            _toString = dbSource.Filename;
            Content   = dbSource.IsImport ? "imp" : dbSource.DisplayName;

            if (_db != null)
            {
                _db.IsEnabledChanged += (e, v) => {
                    this.Dispatch(delegate {
                        if (v)
                        {
                            _stateBrush         = Application.Current.Resources["TabItemTextSelectedForeground"] as SolidColorBrush;
                            _stateInactiveBrush = Application.Current.Resources["TabItemTextNormalForeground"] as SolidColorBrush;
                        }
                        else
                        {
                            _stateBrush         = Brushes.Red;
                            _stateInactiveBrush = Brushes.Red;
                        }

                        Grid presenter = WpfUtilities.FindParentControl <Grid>(this);
                        TextBox box    = (TextBox)presenter.Children[2];

                        if (box.Text == "Visible")
                        {
                            Foreground = _stateBrush;
                        }
                        else
                        {
                            Foreground = _stateInactiveBrush;
                        }
                    });
                };
            }
        }
Esempio n. 15
0
        public DisplayLabel(ServerDbs dbSource, BaseDb db) : this()
        {
            _dbSource = dbSource;
            _db       = db;
            _toString = dbSource.Filename;
            Content   = dbSource.IsImport ? "imp" : dbSource.DisplayName;

            if (_db != null)
            {
                _db.IsEnabledChanged += (e, v) => {
                    this.Dispatch(delegate {
                        if (v)
                        {
                            _stateBrush         = Brushes.Black;
                            _stateInactiveBrush = new SolidColorBrush(Color.FromArgb(255, 215, 215, 215));
                        }
                        else
                        {
                            _stateBrush         = Brushes.Red;
                            _stateInactiveBrush = Brushes.Red;
                        }

                        Grid presenter = WpfUtilities.FindParentControl <Grid>(this);
                        TextBox box    = (TextBox)presenter.Children[2];

                        if (box.Text == "Visible")
                        {
                            Foreground = _stateBrush;
                        }
                        else
                        {
                            Foreground = _stateInactiveBrush;
                        }
                    });
                };
            }
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        public void Initialize(GTabSettings <TKey, TValue> settings)
        {
            Settings = settings;
            _unclickableBorder.Init(_cbSubMenu);
            Database     = settings.ClientDatabase;
            DbComponent  = GenericDatabase.GetDb <TKey>(settings.DbData);
            Table        = Settings.Table;
            Header       = Settings.TabName;
            Style        = TryFindResource(settings.Style) as Style ?? Style;
            SearchEngine = settings.SearchEngine;
            SearchEngine.Init(_gridSearchContent, _searchTextBox, this);

            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 SDE_DEBUG
            CLHelper.WA = CLHelper.CP(-10);
#endif
            if (!Settings.CanBeDelayed || Settings.AttributeList.Attributes.Any(p => p.IsSkippable))
            {
                _deployTabControls();
            }
#if SDE_DEBUG
            CLHelper.WA = ", deploy time : " + CLHelper.CS(-10) + CLHelper.CD(-10) + "ms";
#endif
            _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, ((GenericDatabase)Database).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();
            };

            ApplicationShortcut.Link(ApplicationShortcut.Paste, () => ImportFromFile("clipboard"), _listView);
            ApplicationShortcut.Link(ApplicationShortcut.Cut, () => _miCut_Click(null, null), _listView);
        }
Esempio n. 18
0
        private void _addSearchAttribute(Grid searchGrid, DbAttribute attribute, int row, int column)
        {
            if (attribute.DataType.BaseType == typeof(Enum))
            {
                Grid grid = new Grid();

                Label display = new Label();
                display.Margin            = new Thickness(3);
                display.Padding           = new Thickness(0);
                display.Content           = attribute.DisplayName;
                display.VerticalAlignment = VerticalAlignment.Center;

                ComboBox box = new ComboBox();
                box.Margin = new Thickness(3);
                List <string> items = Enum.GetValues(attribute.DataType).Cast <Enum>().Select(Description.GetDescription).ToList();
                items.Insert(0, "All");
                box.ItemsSource   = items;
                box.SelectedIndex = 0;
                box.SetValue(Grid.ColumnProperty, 1);
                List <int> values = Enum.GetValues(attribute.DataType).Cast <int>().ToList();
                _itemsSearchSettings[attribute] = false;

                box.PreviewMouseDown += delegate(object sender, MouseButtonEventArgs args) {
                    ComboBoxItem item = WpfUtilities.FindParentControl <ComboBoxItem>((Mouse.DirectlyOver as DependencyObject));

                    if (item != null)
                    {
                        StackPanel panel = WpfUtilities.FindParentControl <StackPanel>(item);

                        if (panel != null)
                        {
                            if (panel.Children.Count == 1)
                            {
                                return;
                            }
                        }

                        item.IsSelected = true;
                        args.Handled    = true;
                    }
                };
                box.SelectionChanged += delegate {
                    if (box.SelectedIndex > 0)
                    {
                        attribute.AttachedAttribute = values[box.SelectedIndex - 1].ToString(CultureInfo.InvariantCulture);
                    }

                    _itemsSearchSettings[attribute] = box.SelectedIndex != 0;
                };

                WpfUtilities.SetGridPosition(grid, row, column);
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(-1, GridUnitType.Auto)
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition());

                grid.Children.Add(display);
                grid.Children.Add(box);

                searchGrid.Children.Add(grid);
            }
            else
            {
                _addSearchAttributeSub(searchGrid, attribute.DisplayName, row, column);
            }
        }
Esempio n. 19
0
        private void _load()
        {
            _searchDrop.Dispatch(delegate {
                try {
                    foreach (var attribute in _states)
                    {
                        _itemsSearchSettings[attribute.Key] = attribute.Value;
                    }

                    _tbSearchItems.TextChanged += _tbSearchItems_TextChanged;
                    int row    = 0;
                    int column = 0;

                    _addSearch(_searchDrop, "Search options", null, row, column, true);

                    _nextRow2(ref row, ref column);
                    column = -2;

                    foreach (DbAttribute attribute in _attributes)
                    {
                        _advance(ref row, ref column);

                        if (attribute == null)
                        {
                            continue;
                        }

                        DbAttribute attributeCopy = attribute;
                        _addSearchAttribute(_searchDrop, attributeCopy, row, column);
                    }

                    _attributes = _attributes.Where(p => p != null).ToArray();

                    _itemsSearchSettings[GSearchSettings.TupleAdded]    = false;
                    _itemsSearchSettings[GSearchSettings.TupleModified] = false;
                    _nextRow(ref row, ref column);
                    _addSearchAttributeSub(_searchDrop, GSearchSettings.TupleAdded, row, column);
                    _advance(ref row, ref column);
                    _addSearchAttributeSub(_searchDrop, GSearchSettings.TupleModified, row, column);

                    _tbItemsRange = new TextBox();

                    _cbSearchItemsMode          = new ComboBox();
                    _cbSearchItemsMode.MinWidth = 120;

                    _cbSearchItemsMode.PreviewMouseDown += delegate(object sender, MouseButtonEventArgs args) {
                        ComboBoxItem item = WpfUtilities.FindParentControl <ComboBoxItem>((Mouse.DirectlyOver as DependencyObject));

                        if (item != null)
                        {
                            StackPanel panel = WpfUtilities.FindParentControl <StackPanel>(item);

                            if (panel != null)
                            {
                                if (panel.Children.Count == 1)
                                {
                                    return;
                                }
                            }

                            item.IsSelected = true;
                            args.Handled    = true;
                        }
                    };

                    _cbSearchItemsMode.SelectionChanged += _cbSearchItemsMode_SelectionChanged;
                    _cbSearchItemsMode.Items.Add("Widen search");
                    _cbSearchItemsMode.Items.Add("Narrow search");
                    _advance(ref row, ref column);
                    _addSearch(_searchDrop, "Mode", _cbSearchItemsMode, row, column);
                    _nextRow2(ref row, ref column);

                    if (typeof(TKey) == typeof(int))
                    {
                        _addSearch(_searchDrop, "Range (5-10;-4;15+)", _tbItemsRange, row, column);
                    }

                    _itemsSearchSettings[GSearchSettings.TupleRange] = false;
                    //_itemsSearchSettings[] = false;
                    _tbItemsRange.TextChanged       += (sender, e) => _itemsSearchSettings[GSearchSettings.TupleRange] = _tbItemsRange.Text.Trim() != "";
                    _cbSearchItemsMode.SelectedIndex = 1;

                    _itemsSearchSettings.Modified += _filter;
                }
                catch (Exception err) {
                    ErrorHandler.HandleException(err);
                }
            });
        }
Esempio n. 20
0
        public static void Edit(Window dialog, TextBox tb, Button button)
        {
            IInputWindow inputWindow = (IInputWindow)dialog;

            bool isScript = dialog is ScriptEditDialog && SdeAppConfiguration.UseIntegratedDialogsForScripts;
            bool isLevel  = dialog is LevelEditDialog && SdeAppConfiguration.UseIntegratedDialogsForLevels;
            bool isFlag   = dialog is GenericFlagDialog && SdeAppConfiguration.UseIntegratedDialogsForFlags;
            bool isJob    = dialog is JobEditDialog && SdeAppConfiguration.UseIntegratedDialogsForJobs;
            bool isTime   = dialog is TimeEditDialog && SdeAppConfiguration.UseIntegratedDialogsForTime;
            bool isRate   = dialog is RateEditDialog;
            bool isOther  = !(dialog is ScriptEditDialog || dialog is LevelEditDialog || dialog is GenericFlagDialog || dialog is JobEditDialog || dialog is TimeEditDialog) && SdeAppConfiguration.UseIntegratedDialogsForFlags;

            if (isScript || isLevel || isFlag || isJob || isTime || isRate || isOther)
            {
                inputWindow.Footer.Visibility = Visibility.Collapsed;
                dialog.WindowStyle            = WindowStyle.None;
                var content = dialog.Content;

                Border border = new Border {
                    BorderBrush = Brushes.Black, BorderThickness = new Thickness(1)
                };
                dialog.Content = null;
                border.Child   = content as UIElement;
                dialog.Content = border;

                dialog.Owner = null;

                Extensions.SetMinimalSize(dialog);
                dialog.ResizeMode = ResizeMode.NoResize;

                Point p   = button.PointToScreen(new Point(0, 0));
                var   par = WpfUtilities.FindParentControl <Window>(button);

                dialog.Loaded += delegate {
                    if (dialog == null)
                    {
                        return;
                    }

                    button.IsEnabled             = false;
                    dialog.WindowStartupLocation = WindowStartupLocation.Manual;

                    dialog.Left = p.X - dialog.MinWidth + button.ActualWidth;
                    dialog.Top  = p.Y + button.ActualHeight;

                    if (dialog.Left < 0)
                    {
                        dialog.Left = 0;
                    }

                    if (dialog.Top + dialog.Height > SystemParameters.WorkArea.Bottom)
                    {
                        dialog.Top = p.Y - dialog.MinHeight;
                    }

                    if (dialog.Top < 0)
                    {
                        dialog.Top = 0;
                    }

                    dialog.Owner = par;
                };

                inputWindow.ValueChanged += () => tb.Text = inputWindow.Text;
                dialog.Closed            += delegate {
                    button.IsEnabled = true;
                };
                dialog.Deactivated += (sender, args) => GrfThread.Start(() => dialog.Dispatch(() => Debug.Ignore(dialog.Close)));

                dialog.Show();
            }
            else
            {
                dialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;

                Extensions.SetMinimalSize(dialog);

                dialog.Loaded += delegate {
                    dialog.SizeToContent = SizeToContent.Manual;
                    dialog.Left          = dialog.Owner.Left + (dialog.Owner.Width - dialog.MinWidth) / 2;
                    dialog.Top           = dialog.Owner.Top + (dialog.Owner.Height - dialog.MinHeight) / 2;
                };

                dialog.Owner = WpfUtilities.FindParentControl <Window>(button);

                if (dialog.ShowDialog() == true)
                {
                    tb.Text = ((IInputWindow)dialog).Text;
                }
            }
        }
        public void Init(GDbTabWrapper <TKey, TValue> tab, DisplayableProperty <TKey, TValue> dp)
        {
            _tab = tab;

            DisplayableProperty <TKey, TValue> .RemoveUndoAndRedoEvents(_textBox, _tab);

            //_autocompleteService = new AutocompleteService(_tab.List, _tbIdResource, _tbUnResource, _tbIdDisplayName, _tbUnDisplayName, _tbIdDesc, _tbUnDesc);

            dp.AddResetField(_textBox);
            dp.AddResetField(_realBox);

            Border border = new Border();

            border.BorderBrush     = SystemColors.ActiveBorderBrush;
            border.BorderThickness = new Thickness(1);
            border.Child           = _textBox;

            border.SetValue(Grid.RowProperty, _gridRow);
            border.SetValue(Grid.ColumnProperty, _gridColumn + 1);
            border.Margin = new Thickness(3);

            _tab.PropertiesGrid.Children.Add(border);

            StackPanel panel = new StackPanel();

            panel.SetValue(Grid.RowProperty, _gridRow);
            panel.SetValue(Grid.ColumnProperty, _gridColumn);

            Label label = new Label {
                Content = "Description"
            };

            label.SetValue(TextBlock.ForegroundProperty, Application.Current.Resources["TextForeground"] as Brush);

            Button button = new Button();

            button.Margin = new Thickness(3);

            panel.Children.Add(label);
            panel.Children.Add(button);
            _textBox.GotFocus += delegate { _lastAccessed = _textBox; };

            if (_quickEdit)
            {
                _tab.List.SelectionChanged += new SelectionChangedEventHandler(_list_SelectionChanged);
                button.Content              = "Quick edit...";
                button.Click += new RoutedEventHandler(_buttonQuickEdit_Click);

                TextEditorColorControl colorControl = new TextEditorColorControl();
                Label label2 = new Label {
                    Content = "Color picker"
                };
                label2.SetValue(TextBlock.ForegroundProperty, Application.Current.Resources["TextForeground"] as Brush);

                _tecc         = colorControl;
                _lastAccessed = _textBox;
                colorControl.Init(_getActive);

                Button itemScript = new Button {
                    Margin = new Thickness(3), Content = "Item bonus"
                };
                itemScript.Click += delegate {
                    itemScript.IsEnabled = false;

                    var meta = _tab.GetMetaTable <int>(ServerDbs.Items);
                    var item = _tab._listView.SelectedItem as ReadableTuple <int>;

                    _update = new Func <ReadableTuple <int>, string>(tuple => {
                        var output = new StringBuilder();

                        if (tuple != null)
                        {
                            var entry = meta.TryGetTuple(tuple.Key);

                            if (entry != null)
                            {
                                output.AppendLine("-- Script --");
                                output.AppendLine(entry.GetValue <string>(ServerItemAttributes.Script));
                                output.AppendLine("-- OnEquipScript --");
                                output.AppendLine(entry.GetValue <string>(ServerItemAttributes.OnEquipScript));
                                output.AppendLine("-- OnUnequipScript --");
                                output.AppendLine(entry.GetValue <string>(ServerItemAttributes.OnUnequipScript));
                            }
                            else
                            {
                                output.AppendLine("-- Not found in item_db_m --");
                            }
                        }
                        else
                        {
                            output.AppendLine("-- No entry selected --");
                        }

                        return(output.ToString());
                    });

                    _scriptEdit         = new ScriptEditDialog(_update(item));
                    _scriptEdit.Closed += delegate {
                        itemScript.IsEnabled = true;
                        _scriptEdit          = null;
                    };

                    _scriptEdit._textEditor.IsReadOnly = true;
                    _scriptEdit.DisableOk();
                    _scriptEdit.Show();
                    _scriptEdit.Owner = WpfUtilities.FindParentControl <Window>(_tab);
                };

                panel.Children.Add(itemScript);
                panel.Children.Add(label2);
                panel.Children.Add(colorControl);
            }
            else
            {
                if (_tecc != null)
                {
                    var t = _lastAccessed;
                    _lastAccessed = _textBox;
                    _tecc.Init(_getActive);
                    _lastAccessed = t;
                }

                button.Content = "Copy >";
                button.Click  += new RoutedEventHandler(_buttonAutocomplete_Click);
            }

            tab.PropertiesGrid.Children.Add(panel);

            dp.AddUpdateAction(new Action <TValue>(item => _textBox.Dispatch(delegate {
                Debug.Ignore(() => _realBox.Text = item.GetValue <string>(_attribute));
                //Debug.Ignore(() => _textBox.Text = item.GetValue<string>(_attribute));
                _realBox.UndoLimit = 0;
                _realBox.UndoLimit = int.MaxValue;

                //Debug.Ignore(() => _textBox.Text = item.GetValue<string>(_attribute));
                _textBox.Document.UndoStack.SizeLimit = 0;
                _textBox.Document.UndoStack.SizeLimit = int.MaxValue;
            })));

            _realBox.TextChanged += delegate {
                WpfUtilities.UpdateRtb(_previewTextBox, _realBox.Text, true);
                if (_avalonUpdate)
                {
                    return;
                }
                _textBox.Text = _realBox.Text;
            };
        }