예제 #1
0
        private void AddFilter(Window win)
        {
            _filterLabel = new Label(FILTER_LABEL)
            {
                X = MARGIN_LEFT
            };

            _filterField = new TextField(string.Empty)
            {
                X        = Pos.Right(_filterLabel) + 1,
                Y        = Pos.Top(_filterLabel),
                CanFocus = true,
                Width    = Dim.Fill() - _filterLabel.Text.Length
            };

            var filterErrorLabel = new Label(string.Empty)
            {
                X           = Pos.Right(_filterLabel) + 1,
                Y           = Pos.Top(_filterLabel) + 1,
                ColorScheme = Colors.Base,
                Width       = Dim.Fill() - _filterLabel.Text.Length
            };

            _filterField.TextChanged += (str) =>
            {
                // str is the OLD value
                string filterText = _filterField.Text?.ToString();
                try
                {
                    filterErrorLabel.Text        = " ";
                    filterErrorLabel.ColorScheme = Colors.Base;
                    filterErrorLabel.Redraw(filterErrorLabel.Bounds);

                    List <GridViewRow> itemList = GridViewHelpers.FilterData(_itemSource.GridViewRowList, filterText);
                    _listView.Source = new GridViewDataSource(itemList);
                }
                catch (Exception ex)
                {
                    filterErrorLabel.Text        = ex.Message;
                    filterErrorLabel.ColorScheme = Colors.Error;
                    filterErrorLabel.Redraw(filterErrorLabel.Bounds);
                    _listView.Source = _itemSource;
                }
            };

            win.Add(_filterLabel, _filterField, filterErrorLabel);
        }
예제 #2
0
        private void FilterField_Changed(object sender, ustring e)
        {
            // TODO: remove Apply button and code when this starts working
            try
            {
                _filterErrorLabel.Text        = " ";
                _filterErrorLabel.ColorScheme = Colors.Base;
                _filterErrorLabel.Redraw(_filterErrorLabel.Bounds);

                var itemList = GridViewHelpers.FilterData(_itemSource.GridViewRowList, e.ToString());
                _listView.Source = new GridViewDataSource(itemList);
            }
            catch (Exception ex)
            {
                _filterErrorLabel.Text        = ex.Message;
                _filterErrorLabel.ColorScheme = Colors.Error;
                _filterErrorLabel.Redraw(_filterErrorLabel.Bounds);
                _listView.Source = _itemSource;
            }
        }
예제 #3
0
        private void AddFilter(Window win)
        {
            var filterLabel = new Label(FILTER_LABEL)
            {
                X = 2
            };

            // 2 is for the square brackets added to buttons
            var filterFieldWidth = _gridViewDetails.UsableWidth - filterLabel.Text.Length - APPLY_LABEL.Length - 2;
            var filterField      = new TextField(string.Empty)
            {
                X        = Pos.Right(filterLabel) + 1,
                Y        = Pos.Top(filterLabel),
                CanFocus = true,
                Width    = filterFieldWidth
            };

            var filterErrorLabel = new Label(string.Empty)
            {
                X           = Pos.Right(filterLabel) + 1,
                Y           = Pos.Top(filterLabel) + 1,
                ColorScheme = Colors.Base,
                Width       = filterFieldWidth
            };

            EventHandler <ustring> filterChanged = (object sender, ustring e) =>
            {
                // TODO: remove Apply button and code when this starts working
                try
                {
                    filterErrorLabel.Text        = " ";
                    filterErrorLabel.ColorScheme = Colors.Base;
                    filterErrorLabel.Redraw(filterErrorLabel.Bounds);

                    var itemList = GridViewHelpers.FilterData(_itemSource.GridViewRowList, e.ToString());
                    _listView.Source = new GridViewDataSource(itemList);
                }
                catch (Exception ex)
                {
                    filterErrorLabel.Text        = ex.Message;
                    filterErrorLabel.ColorScheme = Colors.Error;
                    filterErrorLabel.Redraw(filterErrorLabel.Bounds);
                    _listView.Source = _itemSource;
                }
            };

            filterField.Changed += filterChanged;

            var filterApplyButton = new Button(APPLY_LABEL)
            {
                // Pos.Right(filterField) returns 0
                X       = Pos.Right(filterLabel) + filterFieldWidth + 2,
                Y       = Pos.Top(filterLabel),
                Clicked = () =>
                {
                    filterChanged.Invoke(null, filterField.Text);
                }
            };

            win.Add(filterLabel, filterField, filterErrorLabel, filterApplyButton);
        }