Ejemplo n.º 1
0
        internal void RowClicked(int i, object item, MouseEventArgs args)
        {
            //If user clicked on a row withouth Control key, unselect all rows
            if ((Grid.ModifierKey == ModifierKey.CtrlKey && !args.CtrlKey) ||
                (Grid.ModifierKey == ModifierKey.AltKey && !args.AltKey) ||
                (Grid.ModifierKey == ModifierKey.ShiftKey && !args.ShiftKey) ||
                (Grid.ModifierKey == ModifierKey.MetaKey && !args.MetaKey))
            {
                SelectedRows.Clear();
                Grid.SelectedItems = new List <object>();
            }

            //If Grid is MultiSelectable, add selected row to list of rows
            if (Grid.ComponentOptions.MultiSelectable)
            {
                SelectedRow = -1;
                //If selected row is already part of collection, remove it
                if (SelectedRows.Contains(i))
                {
                    SelectedRows.Remove(i);
                    Grid.SelectedItems = Grid.SelectedItems.Except(new[] { item });
                }
                else
                {
                    SelectedRows.Add(i);
                    Grid.SelectedItems = Grid.SelectedItems.Concat(new[] { item });
                }
            }
            else
            {
                SelectedRow        = i;
                Grid.SelectedItems = Grid.SelectedItems.Concat(new[] { item });
            }
            if (OnRowClicked != null)
            {
                OnRowClicked.Invoke(item);
            }

            _shouldRender = true;
            StateHasChanged();
        }
        private void SelectedRows_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (TransactionGridRowViewModel row in e.NewItems)
                {
                    row.IsSelected = true;
                }
            }

            if (e.OldItems != null)
            {
                foreach (TransactionGridRowViewModel row in e.OldItems)
                {
                    row.IsSelected = false;
                }
            }

            SelectedCount = SelectedRows.Count;
            SelectedSum   = SelectedRows.Sum(r => r.Transaction.Amount);
        }
Ejemplo n.º 3
0
        private void Copy()
        {
            var sb = new StringBuilder();

            var rows = new DataGridViewRow[SelectedRows.Count];

            SelectedRows.CopyTo(rows, 0);

            foreach (var row in rows.OrderBy(r => r.Index))
            {
                if (!row.IsNewRow)
                {
                    for (var i = 0; i < row.Cells.Count; i++)
                    {
                        sb.Append(row.Cells[i].Value + Environment.NewLine);
                    }
                }
            }

            Clipboard.SetText(sb.ToString());
        }
Ejemplo n.º 4
0
        public override void RightMouseDown(NSEvent theEvent)
        {
            base.RightMouseDown(theEvent);

            var row = GetRowByMouseEventArgs(theEvent);

            if (row > -1)
            {
                var selectedRowIndexes = SelectedRows.AsEnumerable().ToList();

                if (!selectedRowIndexes.Contains((nuint)row))
                {
                    var extendSelection = UiStateHelper.CommandKeyDown;
                    SelectRow(row, extendSelection);
                    selectedRowIndexes = SelectedRows.AsEnumerable().ToList();
                }

                var menuItems = new List <NSMenuItem>();
                var arguments = new ContextMenuArguments(menuItems, selectedRowIndexes);
                PrepareContextMenu?.Invoke(this, arguments);

                if (menuItems.Any())
                {
                    var menu = new NSMenu {
                        AutoEnablesItems = false
                    };
                    menu.Delegate = new DeferredInitializerDelegate(arguments.Initializers);

                    foreach (var item in menuItems)
                    {
                        menu.AddItem(item);
                    }

                    var locationInView = this.ConvertPointToView(theEvent.LocationInWindow, null);
                    locationInView.X -= 26;

                    menu.PopUpMenu(null, locationInView, this);
                }
            }
        }
Ejemplo n.º 5
0
    /// <summary>
    /// 点击 Header 选择复选框时触发此方法
    /// </summary>
    /// <param name="state"></param>
    /// <param name="val"></param>
    protected virtual async Task OnHeaderCheck(CheckboxState state, TItem val)
    {
        switch (state)
        {
        case CheckboxState.Checked:
            // select all
            SelectedRows.Clear();
            SelectedRows.AddRange(Rows);
            await OnSelectedRowsChanged();

            StateHasChanged();
            break;

        case CheckboxState.UnChecked:
        default:
            // unselect all
            SelectedRows.Clear();
            await OnSelectedRowsChanged();

            StateHasChanged();
            break;
        }
    }
Ejemplo n.º 6
0
        /// <summary>
        /// Moves the <paramref name="rows"/> to the top of the tree.
        /// </summary>
        /// <param name="rows">the rows to be moved</param>
        public void MoveToTop(Row[] rows)
        {
            if (rows == null)
            {
                throw new ArgumentNullException("rows");
            }
            if (IsWorkpad && RootRow != null && RootRow.NumChildren > 0)
            {
                IResultNode root  = RootItem as IResultNode;
                int         index = 0;

                foreach (Row row in UniqueSelectedRowsInGuiOrder)
                {
                    IResultNode resultNode = (IResultNode)row.Item;
                    resultNode.Parent.RemoveChild(resultNode);
                    root.InsertChild(index++, resultNode);
                }

                SelectedRows.SuspendChangeNotification();
                RootRow.UpdateChildren(false, true);
                SelectedRows.ResumeChangeNotification();
            }
        }
Ejemplo n.º 7
0
        protected override void OnRowDrop(Row row, RowDropLocation dropLocation, IDataObject data, DragDropEffects dropEffect)
        {
            base.OnRowDrop(row, dropLocation, data, dropEffect);

            if (IsWorkpad)
            {
                Row[] rows = GetRows(data);

                if (rows == null)
                {
                    return;
                }

                // Delete rows from original location if dropped on the same tree
                List <IResultNode> results = new List <IResultNode>();

                foreach (Row r in rows.GetUniqueRowsInGuiOrder())
                {
                    IResultNode result = (IResultNode)r.Item;

                    if (r.Tree == this)
                    {
                        result.Parent.RemoveChild(result);

                        SelectedRows.SuspendChangeNotification();
                        r.ParentRow.UpdateChildren(false, true);
                        SelectedRows.ResumeChangeNotification();
                    }

                    results.Add(result);
                }

                // Adds the results in the given location
                AddResults(row, dropLocation, results.ToArray());
            }
        }
Ejemplo n.º 8
0
    /// <summary>
    /// 调用 OnQuery 回调方法获得数据源
    /// </summary>
    protected async Task QueryData()
    {
        // 目前设计使用 Items 参数后不回调 OnQueryAsync 方法
        if (Items == null)
        {
            if (OnQueryAsync == null && DynamicContext != null && typeof(TItem).IsAssignableTo(typeof(IDynamicObject)))
            {
                // 动态数据
                SelectedRows.Clear();
                QueryItems = DynamicContext.GetItems().Cast <TItem>();
                if (DynamicContext.OnGetSelectedRows != null)
                {
                    SelectedRows.AddRange(DynamicContext.OnGetSelectedRows().Cast <TItem>());
                }
                TotalCount = QueryItems.Count();
            }
            else
            {
                // 数据集合
                await OnQuery();
            }
        }
        else
        {
            RowsCache = null;
        }

        async Task OnQuery()
        {
            QueryData <TItem>?queryData = null;
            var queryOption             = new QueryPageOptions()
            {
                IsPage          = IsPagination,
                PageIndex       = PageIndex,
                PageItems       = PageItems,
                SearchText      = SearchText,
                SortOrder       = SortOrder,
                SortName        = SortName,
                SortList        = string.IsNullOrEmpty(SortString) ? null : new List <string>(SortString.Split(",", StringSplitOptions.RemoveEmptyEntries)),
                Filters         = Filters.Values,
                Searchs         = GetSearchs(),
                AdvanceSearchs  = GetAdvanceSearchs(),
                CustomerSearchs = GetCustomerSearchs(),
                SearchModel     = SearchModel,
                StartIndex      = StartIndex
            };

            if (CustomerSearchModel != null)
            {
                queryOption.SearchModel = CustomerSearchModel;
            }

            queryData = await InternalOnQueryAsync(queryOption);

            RowsCache       = null;
            Items           = null;
            QueryItems      = queryData.Items;
            TotalCount      = queryData.TotalCount;
            IsAdvanceSearch = queryData.IsAdvanceSearch;

            // 处理选中行逻辑
            ProcessSelectedRows();

            // 分页情况下内部不做处理防止页码错乱
            if (!queryOption.IsPage)
            {
                ProcessPageData(queryData, queryOption);
            }

            if (IsTree)
            {
                await ProcessTreeData();
            }

            void ProcessSelectedRows()
            {
                // 判断模型是否有 [Key] Id 等可识别字段尝试重构
                var rows = new List <TItem>();

                if (HasKeyAttribute)
                {
                    // 更新选中行逻辑
                    foreach (var item in SelectedRows)
                    {
                        var key = Utility.GetKeyValue <TItem, object>(item);
                        if (key != null)
                        {
                            var row = QueryItems.FirstOrDefault(i => Utility.GetKeyValue <TItem, object>(i).ToString() == key.ToString());
                            if (row != null)
                            {
                                rows.Add(row);
                            }
                        }
                    }
                }
                else
                {
                    foreach (var row in SelectedRows)
                    {
                        if (QueryItems.Any(i => i == row))
                        {
                            rows.Add(row);
                        }
                    }
                }
                SelectedRows = rows;
            }

            void ProcessPageData(QueryData <TItem> queryData, QueryPageOptions queryOption)
            {
                var filtered = queryData.IsFiltered;
                var sorted   = queryData.IsSorted;
                var searched = queryData.IsSearch;

                // 外部未处理 SearchText 模糊查询
                if (!searched && queryOption.Searchs.Any())
                {
                    QueryItems = QueryItems.Where(queryOption.Searchs.GetFilterFunc <TItem>(FilterLogic.Or));
                    TotalCount = QueryItems.Count();
                }

                // 外部未处理自定义高级搜索 内部进行高级自定义搜索过滤
                if (!IsAdvanceSearch && queryOption.CustomerSearchs.Any())
                {
                    QueryItems      = QueryItems.Where(queryOption.CustomerSearchs.GetFilterFunc <TItem>());
                    TotalCount      = QueryItems.Count();
                    IsAdvanceSearch = true;
                }

                // 外部未过滤,内部自行过滤
                if (!filtered && queryOption.Filters.Any())
                {
                    QueryItems = QueryItems.Where(queryOption.Filters.GetFilterFunc <TItem>());
                    TotalCount = QueryItems.Count();
                }

                // 外部未处理排序,内部自行排序
                // 先处理列头排序 再处理默认多列排序
                if (!sorted)
                {
                    if (queryOption.SortOrder != SortOrder.Unset && !string.IsNullOrEmpty(queryOption.SortName))
                    {
                        var invoker = Utility.GetSortFunc <TItem>();
                        QueryItems = invoker(QueryItems, queryOption.SortName, queryOption.SortOrder);
                    }
                    else if (queryOption.SortList != null && queryOption.SortList.Any())
                    {
                        var invoker = Utility.GetSortListFunc <TItem>();
                        QueryItems = invoker(QueryItems, queryOption.SortList);
                    }
                }
            }

            async Task ProcessTreeData()
            {
                KeySet.Clear();
                if (HasKeyAttribute)
                {
                    CheckExpandKeys(TreeRows);
                }
                if (KeySet.Count > 0)
                {
                    TreeRows = new List <TableTreeNode <TItem> >();
                    foreach (var item in QueryItems)
                    {
                        var node = new TableTreeNode <TItem>(item)
                        {
                            HasChildren = CheckTreeChildren(item),
                        };
                        node.IsExpand = IsExpandRow(node);
                        if (node.IsExpand)
                        {
                            await RestoreIsExpand(node);
                        }
                        TreeRows.Add(node);
                    }
                }
                else
                {
                    TreeRows = QueryItems.Select(item => new TableTreeNode <TItem>(item)
                    {
                        HasChildren = CheckTreeChildren(item)
                    }).ToList();
                }
            }
        }
    }
Ejemplo n.º 9
0
 /// ------------------------------------------------------------------------------------
 public IEnumerable <ProjectElement> GetSelectedElements()
 {
     return(from row in SelectedRows.Cast <DataGridViewRow>()
            select _items.ElementAt(row.Index));
 }
Ejemplo n.º 10
0
        private void toolStripMenuItemSaveAsContiguousFile_Click(object sender, EventArgs e)
        {
            if (!HasSelectedRows)
            {
                MessageBox.Show(this, "No selection was made. Please make a selection in the file tree first.",
                                GetDisplayedText(toolStripMenuItemSaveAsContiguousFile),
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                return;
            }

            var fileDialog = new SaveFilePresenter();

            fileDialog.FilterAllFiles();
            fileDialog.Title = "Save As Contiguous File";

            // Using the GUI, it is only possible to select one file or one or more container and codec streams
            Row firstSelectedRow = SelectedRows[0];

            if (firstSelectedRow.Item is IInputFile)
            {
                if (SaveAsSingleFile != null)
                {
                    FileInfo contiguousFile;
                    if (fileDialog.ShowDialog(this, out contiguousFile))
                    {
                        RunBackgroundTask(toolStripMenuItemSaveAsContiguousFile, "Save as " + contiguousFile.Name,
                                          p => SaveAsSingleFile(this, new FileExportEventArgs <IInputFile>(firstSelectedRow.Item as IInputFile, contiguousFile.FullName, p)));
                    }
                }
            }
            else if (firstSelectedRow.Item is IFragment)
            {
                if (SaveAsContiguousFile != null)
                {
                    // Fill the SaveFileDialog filter
                    var       fragment = firstSelectedRow.Item as IFragment;
                    IDetector detector;
                    if ((fragment != null) &&
                        (fragment.Detectors != null) &&
                        (fragment.Detectors.Count() > 0) &&
                        ((detector = fragment.Detectors.FirstOrDefault()) != null))
                    {
                        string extension = detector.OutputFileExtension;
                        fileDialog.Filter = string.Format("{0} Files (*{1})|*{2}|All Files (*.*)|*.*", detector.Name, extension, extension);
                    }

                    FileInfo contiguousFile;
                    if (fileDialog.ShowDialog(this, out contiguousFile))
                    {
                        RunBackgroundTask(toolStripMenuItemSaveAsContiguousFile, "Save as " + contiguousFile.Name,
                                          p => SaveAsContiguousFile(this, new FileExportEventArgs <IEnumerable <IDataPacket> >(SelectedRows.GetSelectedFragmentsInGuiOrder(), contiguousFile.FullName, p)));
                    }
                }
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 检查当前行是否被选中方法
 /// </summary>
 /// <param name="val"></param>
 /// <returns></returns>
 protected virtual bool CheckActive(TItem val) => SelectedRows.Contains(val);
Ejemplo n.º 12
0
 private bool CanExecuteAddDependencyToManyProps()
 {
     return(SelectedRows.All(model => model is IPropertyEditorViewModel));
 }
Ejemplo n.º 13
0
 private void RowMultiSelected(TransactionGridRowViewModel row)
 {
     SelectedRows.Add(row);
 }
Ejemplo n.º 14
0
        void OnKeyDown(object sender, KeyRoutedEventArgs e)
        {
            if (SelectionMode == SelectionMode.Multiple || RootItems.Count == 0)
            {
                return;
            }

            TvItem row;

            switch (e.Key)
            {
            case VirtualKey.Down:
                row = SelectedRows.LastOrDefault();
                if (row == null)
                {
                    OnToggleSelected(RootItems[0]);
                }
                else
                {
                    using (var ls = RootItems.GetExpandedItems().GetEnumerator())
                    {
                        while (ls.MoveNext())
                        {
                            if (ls.Current == row)
                            {
                                if (ls.MoveNext())
                                {
                                    OnToggleSelected(ls.Current);
                                }
                                else
                                {
                                    OnToggleSelected(RootItems[0]);
                                }
                                break;
                            }
                        }
                    }
                }
                e.Handled = true;
                return;

            case VirtualKey.Up:
                row = SelectedRows.LastOrDefault();
                if (row == null)
                {
                    OnToggleSelected(RootItems[0]);
                }
                else
                {
                    using (var ls = RootItems.GetExpandedItems().GetEnumerator())
                    {
                        if (ls.MoveNext())
                        {
                            if (ls.Current == row)
                            {
                                SelectedItem = null;
                            }
                            else
                            {
                                while (true)
                                {
                                    TvItem lastRow = ls.Current;
                                    if (ls.MoveNext())
                                    {
                                        if (ls.Current == row)
                                        {
                                            OnToggleSelected(lastRow);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                e.Handled = true;
                return;

            case VirtualKey.Enter:
                row = SelectedRows.LastOrDefault();
                if (row != null)
                {
                    row.OnClick();
                }
                return;

            default:
                return;
            }
        }
Ejemplo n.º 15
0
 private void OnChangeAddress(bool isIncreasing)
 {
     SelectedRows.ForEach(model => (model as IAddressChangeable).ChangeAddress(AddressIteratorValue, isIncreasing));
 }
Ejemplo n.º 16
0
 /// <summary>
 /// 获得 当前行是否被选中
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 protected CheckboxState RowCheckState(TItem item) => SelectedRows.Contains(item) ? CheckboxState.Checked : CheckboxState.UnChecked;
Ejemplo n.º 17
0
 private void toolStripMenuItemMoveToTop_Click(object sender, EventArgs e)
 {
     MoveToTop(SelectedRows.GetRows());
 }
Ejemplo n.º 18
0
 private bool CanExecuteDeleteElement()
 {
     return(SelectedRows.All(model => model is IDeletable));
 }
Ejemplo n.º 19
0
 private void OnShowFormatterParametersExecute()
 {
     _formatterEditorFactory.EditFormatterByUser(SelectedRows.Cast <IUshortFormattableEditorViewModel>().ToList(), this.RootConfigurationItemViewModels.ToList());
 }
Ejemplo n.º 20
0
 private bool CanExecuteShowFormatterParameters()
 {
     return(SelectedRows.All(model => model is IUshortFormattableEditorViewModel));
 }
Ejemplo n.º 21
0
        public ConfigurationEditorViewModel(
            IApplicationGlobalCommands applicationGlobalCommands,
            Func <IElementAddingCommand> elementAddingCommandAddingFunc,
            IFormatterEditorFactory formatterEditorFactory, IFragmentSettingsViewModel fragmentSettingsViewModel,
            ISharedResourcesGlobalViewModel sharedResourcesGlobalViewModel, IDependenciesService dependenciesService,
            DependencyFillHelper dependencyFillHelper, BaseValuesFillHelper baseValuesFillHelper,
            ImportPropertiesFromExcelTypeAHelper importPropertiesFromExcelTypeAHelper
            )
        {
            _allRows = new ObservableCollection <IConfigurationItemViewModel>();
            _applicationGlobalCommands            = applicationGlobalCommands;
            _formatterEditorFactory               = formatterEditorFactory;
            _sharedResourcesGlobalViewModel       = sharedResourcesGlobalViewModel;
            _dependenciesService                  = dependenciesService;
            _dependencyFillHelper                 = dependencyFillHelper;
            _baseValuesFillHelper                 = baseValuesFillHelper;
            _importPropertiesFromExcelTypeAHelper = importPropertiesFromExcelTypeAHelper;
            FragmentSettingsViewModel             = fragmentSettingsViewModel;
            RootConfigurationItemViewModels       = new ObservableCollection <IConfigurationItemViewModel>();
            ElementsAddingCommandCollection       = new ObservableCollection <IElementAddingCommand>();
            AddRootElementCommand                 = new RelayCommand(OnAddRootElement);

            AddRootGroupElementCommand = new RelayCommand(OnAddRootGroupElementExecute);
            IElementAddingCommand command = elementAddingCommandAddingFunc();

            command.Name          = "AddChildElement";
            command.AddingCommand = new RelayCommand(OnAddChildElementExecute, CanExecuteAddChildElement);
            ElementsAddingCommandCollection.Add(command);
            command               = elementAddingCommandAddingFunc();
            command.Name          = "AddChildGroup";
            command.AddingCommand =
                new RelayCommand(OnAddChildGroupElementExecute, CanExecuteAddChildGroupElement);
            ElementsAddingCommandCollection.Add(command);


            EditElementCommand             = new RelayCommand(OnEditElementExecute, CanExecuteEditElement);
            DeleteElementCommand           = new RelayCommand(OnDeleteElementExecute, CanExecuteDeleteElement);
            ShowFormatterParametersCommand =
                new RelayCommand(OnShowFormatterParametersExecute, CanExecuteShowFormatterParameters);
            SetElementDownCommand            = new RelayCommand(OnSetElementDownExecute, CanExecuteSetElementDown);
            SetElementUpCommand              = new RelayCommand(OnSetElementUpExecute, CanExecuteSetElementUp);
            OpenConfigurationSettingsCommand = new RelayCommand(OnOpenConfigurationSettingsExecute);
            CopyElementCommand = new RelayCommand(OnCopyElementExecute, CanExecuteCopyElement);
            CutElementCommand  = new RelayCommand(OnCutElementExecute, CanExecuteCutElement);

            PasteAsChildElementCommand =
                new RelayCommand(OnPasteAsChildElementExecute, CanPasteAsChildElementElement);


            AddSelectedElementAsResourceCommand = new RelayCommand(OnAddSelectedElementAsResourceExecute,
                                                                   CanExecuteAddSelectedElementAsResource);
            ShowDependenciesCommand = new RelayCommand(OnShowDependenciesExecute, CanExecuteShowDependencies);
            ShowFiltersCommand      = new RelayCommand(OnShowFiltersExecute, CanExecuteShowFilters);
            EditDescriptionCommand  =
                new RelayCommand(OnEditDescriptionExecute, CanExecuteEditDescription);
            IncreaseAddressCommand = new RelayCommand(() => OnChangeAddress(true),
                                                      () => SelectedRows.All(model => model is IAddressChangeable));
            DecreaseAddressCommand = new RelayCommand(() => OnChangeAddress(false),
                                                      () => SelectedRows.All(model => model is IAddressChangeable));
            AddDependencyToManyProps         = new RelayCommand(OnAddDependencyToManyPropsExecute, CanExecuteAddDependencyToManyProps);
            TriggerAdditionalSettingsCommand = new RelayCommand(() => { IsAdditionalSettingsOpened = true; });
            AddressIteratorValue             = 1;
            OnSelectionChangedCommand        = new RelayCommand <object>(OnSelectionChangedExecute);
            SelectedRows                          = new List <IEditorConfigurationItemViewModel>();
            OpenBasicValuesCommand                = new RelayCommand(OnOpenBasicValuesExacute);
            MigrateComplexPropertiesCommand       = new RelayCommand(OnMigrateComplexPropertiesExecute);
            BaseValuesViewModel                   = new BaseValuesViewModel();
            ImportPropertiesFromExcelTypeACommand = new RelayCommand(OnImportPropertiesFromExcelTypeAExecute);
            EditCommand = new RelayCommand(OnEditExecute);
            SetIsFromBitsToManyPropsViewModel = new SetIsFromBitsToManyPropsViewModel(this);
        }
Ejemplo n.º 22
0
 private bool CanExecuteCutElement()
 {
     return(SelectedRows.All(model => model is IDeletable) &&
            SelectedRows.GroupBy(model => model.Parent).Count() == 1);
 }
        /// <summary>
        /// Process the selection while changing IsChecked state of the particular tree node.
        /// </summary>
        /// <param name="treeNode">treeNode - its IsChecked state is changed.</param>
        internal override void ProcessSelectionOnCheckedStateChange(TreeNode treeNode)
        {
            if (TreeGrid.SelectionMode == GridSelectionMode.None)
            {
                return;
            }
            var addedItems            = new List <object>();
            var removedItems          = new List <object>();
            var isChecked             = treeNode.IsChecked;
            var rowIndex              = TreeGrid.ResolveToRowIndex(treeNode);
            var currentRowColumnIndex = CurrentCellManager.CurrentRowColumnIndex;
            var rowColumnIndex        = new RowColumnIndex(rowIndex, CurrentCellManager.CurrentRowColumnIndex.ColumnIndex);

            if (TreeGrid.SelectionMode == GridSelectionMode.Single)
            {
                if (isChecked == true)
                {
                    if (SelectedRows.Any())
                    {
                        removedItems.Add(SelectedRows[0]);
                    }
                    addedItems.Add(GetTreeGridSelectedRow(rowIndex));

                    if (RaiseSelectionChanging(addedItems, removedItems))
                    {
                        return;
                    }
                    SetCurrentCellAndCurrentRowColumnIndex(rowColumnIndex, currentRowColumnIndex);
                    RemoveSelection(removedItems);
                    if (removedItems.Any())
                    {
                        UpdateCheckedStateForSelectionRemovedRow(removedItems[0] as TreeGridRowInfo);
                    }
                    AddSelection(addedItems);
                    RaiseSelectionChanged(addedItems, removedItems);
                }
                else
                {
                    if (!SelectedRows.Any())
                    {
                        return;
                    }
                    if (SelectedRows[0].RowIndex != rowIndex)
                    {
                        return;
                    }
                    removedItems.Add(SelectedRows[0]);
                    if (RaiseSelectionChanging(addedItems, removedItems))
                    {
                        return;
                    }
                    if (TreeGrid.NavigationMode == NavigationMode.Cell)
                    {
                        CurrentCellManager.RemoveCurrentCell(currentRowColumnIndex);
                    }
                    CurrentCellManager.ResetCurrentRowColumnIndex();

                    RemoveSelection(removedItems);
                    UpdateCheckedStateForSelectionRemovedRow(removedItems[0] as TreeGridRowInfo);
                    this.SuspendUpdates();
                    RefreshSelectedIndexAndItem();
                    this.ResumeUpdates();
                    RaiseSelectionChanged(addedItems, removedItems);
                }
            }
            // Multiple and Extended Cases
            else
            {
                if (TreeGrid.EnableRecursiveChecking)
                {
                    SelectRowsOnRecursiveCheck(treeNode, rowIndex);
                    return;
                }

                if (isChecked == true)
                {
                    addedItems.Add(GetTreeGridSelectedRow(rowIndex));
                    if (RaiseSelectionChanging(addedItems, removedItems))
                    {
                        return;
                    }
                    SetCurrentCellAndCurrentRowColumnIndex(rowColumnIndex, currentRowColumnIndex);
                    AddSelection(addedItems);
                    RaiseSelectionChanged(addedItems, removedItems);
                }
                else
                {
                    if (!SelectedRows.Any())
                    {
                        return;
                    }
                    var selectedRow = SelectedRows.FirstOrDefault(r => r.RowIndex == rowIndex);
                    if (selectedRow == null)
                    {
                        return;
                    }
                    removedItems.Add(selectedRow);
                    if (RaiseSelectionChanging(addedItems, removedItems))
                    {
                        return;
                    }
                    var needToSetCurrentCell = false;
                    if (TreeGrid.NavigationMode == NavigationMode.Cell && selectedRow.RowIndex == currentRowColumnIndex.RowIndex)
                    {
                        CurrentCellManager.RemoveCurrentCell(currentRowColumnIndex);
                        needToSetCurrentCell = (SelectedRows.Count > 1);
                    }
                    RemoveSelection(removedItems, needToSetCurrentCell);
                    if (!SelectedRows.Any() || TreeGrid.NavigationMode == NavigationMode.Row)
                    {
                        CurrentCellManager.ResetCurrentRowColumnIndex();
                    }
                    UpdateCheckedStateForSelectionRemovedRow(removedItems[0] as TreeGridRowInfo);
                    this.SuspendUpdates();
                    RefreshSelectedIndexAndItem();
                    this.ResumeUpdates();
                    RaiseSelectionChanged(addedItems, removedItems);
                }
            }
        }
Ejemplo n.º 24
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (!SuspendHotkeys)
            {
                if (e.Control && !e.Alt && e.Shift && e.KeyCode == Keys.F)                 // Ctrl+Shift+F
                {
                    //HorizontalOrientation ^= true;
                }
                // Scroll
                else if (!e.Control && !e.Alt && !e.Shift && e.KeyCode == Keys.PageUp)                 // Page Up
                {
                    if (FirstVisibleRow > 0)
                    {
                        LastVisibleRow = FirstVisibleRow;
                        Refresh();
                    }
                }
                else if (!e.Control && !e.Alt && !e.Shift && e.KeyCode == Keys.PageDown)                 // Page Down
                {
                    var totalRows = LastVisibleRow - FirstVisibleRow;
                    if (totalRows <= ItemCount)
                    {
                        var final = LastVisibleRow + totalRows;
                        if (final > ItemCount)
                        {
                            final = ItemCount;
                        }

                        LastVisibleRow = final;
                        Refresh();
                    }
                }
                else if (!e.Control && !e.Alt && !e.Shift && e.KeyCode == Keys.Home)                 // Home
                {
                    FirstVisibleRow = 0;
                    Refresh();
                }
                else if (!e.Control && !e.Alt && !e.Shift && e.KeyCode == Keys.End)                 // End
                {
                    LastVisibleRow = ItemCount;
                    Refresh();
                }
                else if (!e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.Up)                 // Up
                {
                    if (FirstVisibleRow > 0)
                    {
                        FirstVisibleRow--;
                        Refresh();
                    }
                }
                else if (!e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.Down)                 // Down
                {
                    if (FirstVisibleRow < ItemCount - 1)
                    {
                        FirstVisibleRow++;
                        Refresh();
                    }
                }
                // Selection courser
                else if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.Up)                 // Ctrl + Up
                {
                    if (SelectedRows.Any() && LetKeysModifySelection && SelectedRows.First() > 0)
                    {
                        foreach (var row in SelectedRows.ToList())
                        {
                            SelectItem(row - 1, true);
                            SelectItem(row, false);
                        }
                    }
                }
                else if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.Down)                 // Ctrl + Down
                {
                    if (SelectedRows.Any() && LetKeysModifySelection)
                    {
                        foreach (var row in SelectedRows.Reverse().ToList())
                        {
                            SelectItem(row + 1, true);
                            SelectItem(row, false);
                        }
                    }
                }
                else if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.Left)                 // Ctrl + Left
                {
                    if (SelectedRows.Any() && LetKeysModifySelection)
                    {
                        SelectItem(SelectedRows.Last(), false);
                    }
                }
                else if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.Right)                 // Ctrl + Right
                {
                    if (SelectedRows.Any() && LetKeysModifySelection && SelectedRows.Last() < _itemCount - 1)
                    {
                        SelectItem(SelectedRows.Last() + 1, true);
                    }
                }
                else if (e.Control && e.Shift && !e.Alt && e.KeyCode == Keys.Left)                 // Ctrl + Shift + Left
                {
                    if (SelectedRows.Any() && LetKeysModifySelection && SelectedRows.First() > 0)
                    {
                        SelectItem(SelectedRows.First() - 1, true);
                    }
                }
                else if (e.Control && e.Shift && !e.Alt && e.KeyCode == Keys.Right)                 // Ctrl + Shift + Right
                {
                    if (SelectedRows.Any() && LetKeysModifySelection)
                    {
                        SelectItem(SelectedRows.First(), false);
                    }
                }
                else if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.PageUp)                 // Ctrl + Page Up
                {
                    //jump to above marker with selection courser
                    if (LetKeysModifySelection)
                    {
                    }
                }
                else if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.PageDown)                 // Ctrl + Page Down
                {
                    //jump to below marker with selection courser
                    if (LetKeysModifySelection)
                    {
                    }
                }
                else if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.Home)                 // Ctrl + Home
                {
                    //move selection courser to frame 0
                    if (LetKeysModifySelection)
                    {
                        DeselectAll();
                        SelectItem(0, true);
                    }
                }
                else if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.End)                 // Ctrl + End
                {
                    //move selection courser to end of movie
                    if (LetKeysModifySelection)
                    {
                        DeselectAll();
                        SelectItem(ItemCount - 1, true);
                    }
                }
            }

            base.OnKeyDown(e);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Animation은 viewStatus에 새로운 컬럼이 추가되거나 해제될 때 마지막에 보이던 TableView와 현재 보일 TableView를 잇는데 사용된다.
        /// prevTableView와 currentTableView를 부드럽게 잇는 테이블 애니메이션이 가능한 경우와 불가능한 경우는 아래와 같다
        ///
        /// 가능한 경우:
        ///     allRows -> groupedRows: 항상 가능
        ///     groupedRows -> allRows: 항상 가능
        ///     groupedRows-> selectedRows: 항상 가능
        ///     selectedRows -> groupedRows: 항상 가능
        ///     groupedRows -> groupedRows: N -> CN 인 경우는 불가능함
        ///
        /// 불가능한 경우:
        ///     allRows -> allRows: 이런 상황이 일어나는 경우가 없음
        ///     selectedRows -> selectedRows: 셀렉션이 추가되거나 제거되는 경우인데 이건 현재 애니메이션을 지원하지 않음
        ///     allRows -> selectedRows: 스캐터플롯에서 셀렉션을 추가하는 경우가 있을 수 있는데 현재 애니메이션 지원하지 않음
        ///     selectedRows -> allRows: 스캐터플롯에서 셀렉션이 제거되는 경우가 있을 수 있는데 현재 애니메이션 지원하지 않음
        /// </summary>
        /// <param name="viewStatus"></param>
        /// <returns></returns>
        private AnimationScenario CreateTableAnimation(ViewStatus viewStatus)
        {
            if (!Settings.Instance.AnimationEnabled)
            {
                return(AnimationScenario.None);
            }

            if (stashedViewStatus == null)
            {
                return(AnimationScenario.None);
            }

            //AnimationHint hint = stashedViewStatus.AnimationHint;

            Canvas canvas = view.TableView.AnimatingRowCanvas;

            canvas.Children.Clear();

            TableViewState previousState = stashedViewStatus.TableViewState,
                           currentState  = viewStatus.TableViewState;

            switch (previousState)
            {
            case TableViewState.AllRow:
                switch (currentState)
                {
                case TableViewState.AllRow:
                    return(AnimationScenario.None);

                case TableViewState.GroupedRow:                                                                                              // 처음 그룹바이가 일어나는 경우
                    return(PlayCollapseAnimation(SheetViewModel.AllRowViewModels, viewStatus.GroupedRowViewModels, viewStatus.FirstColumn)); //, viewStatus);

                case TableViewState.SelectedRow:
                    return(AnimationScenario.None);
                }
                break;

            case TableViewState.GroupedRow:
                switch (currentState)
                {
                case TableViewState.AllRow:                                                                                                                     // 그룹바이가 풀리는 경우 (C -> Empty, CN -> CNN 등)
                    return(PlayExpandAnimation(stashedViewStatus.GroupedRowViewModels, SheetViewModel.AllRowViewModels,
                                               stashedViewStatus.CategoricalCount > 0 ? stashedViewStatus.LastCategorical : stashedViewStatus.FirstNumerical)); //, viewStatus);

                case TableViewState.GroupedRow:
                    // TODO

                    break;

                case TableViewState.SelectedRow:
                    IEnumerable <Row> selectedOnScreenRows = SheetViewModel.AllRowViewModels.Where(arvm => SelectedRows.Contains(arvm.Row) && arvm.Y < mainPageViewModel.Bounds.Height).Select(arvm => arvm.Row);

                    RowViewModel selectedRowViewModel = stashedViewStatus.GroupedRowViewModels
                                                        .OrderByDescending(rvm => rvm.Rows.Intersect(selectedOnScreenRows).Count())
                                                        .First();

                    return(PlayExpandAnimation(new List <RowViewModel>()
                    {
                        selectedRowViewModel
                    }, SheetViewModel.AllRowViewModels,
                                               stashedViewStatus.CategoricalCount > 0 ? stashedViewStatus.LastCategorical : stashedViewStatus.FirstNumerical)); //, viewStatus);
                }
                break;

            case TableViewState.SelectedRow:
                switch (currentState)
                {
                case TableViewState.AllRow:
                    return(AnimationScenario.None);

                case TableViewState.GroupedRow:
                    IEnumerable <Row> unselectedOnScreenRows = SheetViewModel.AllRowViewModels.Where(
                        arvm => stashedViewStatus.SelectedRows.Contains(arvm.Row) && arvm.StashedY < mainPageViewModel.Bounds.Height
                        ).Select(arvm => arvm.Row);

                    RowViewModel collapsingRowViewModel = viewStatus.GroupedRowViewModels.OrderByDescending(rvm => rvm.Rows.Intersect(unselectedOnScreenRows).Count()).First();

                    return(PlayCollapseAnimation(AllRowViewModels, new List <RowViewModel>()
                    {
                        collapsingRowViewModel
                    },
                                                 stashedViewStatus.CategoricalCount > 0 ? viewStatus.LastCategorical : viewStatus.FirstNumerical)); //, viewStatus);

                case TableViewState.SelectedRow:
                    return(AnimationScenario.None);
                }
                break;
            }

            return(AnimationScenario.None);
        }
Ejemplo n.º 26
0
 private void OnAddDependencyToManyPropsExecute()
 {
     _dependenciesService.AddDependencyToManyProps(SelectedRows.Cast <IDependenciesViewModelContainer>().ToList(),
                                                   GetDependencyConfigForProperties());
 }
Ejemplo n.º 27
0
 protected void InverTItemStatus(TItem row)
 {
     ChangeRowStatus(SelectedRows.Contains(row) ? CheckBoxStatus.UnChecked : CheckBoxStatus.Checked, row);
 }
Ejemplo n.º 28
0
        void PaintCells(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                using (SolidBrush
                       backbrush = new SolidBrush(e.CellStyle.BackColor),
                       selection = new SolidBrush(SystemColors.Highlight))
                {
                    if (SelectedRows.Contains(Rows[e.RowIndex]))
                    {
                        e.Graphics.FillRectangle(selection, e.CellBounds);
                    }
                    else
                    {
                        e.Graphics.FillRectangle(backbrush, e.CellBounds);
                    }
                }
                using (Pen gridLines = new Pen(this.GridColor))
                {
                    // Draw the grid lines (only the right and bottom lines)
                    e.Graphics.DrawLine(gridLines,
                                        e.CellBounds.Left, e.CellBounds.Bottom - 1,
                                        e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);
                    e.Graphics.DrawLine(gridLines,
                                        e.CellBounds.Right - 1, e.CellBounds.Top,
                                        e.CellBounds.Right - 1, e.CellBounds.Bottom);

                    // Draw the text content of the cell, ignoring alignment.
                    if (e.Value != null)
                    {
                        using (Brush brush = new SolidBrush(e.CellStyle.ForeColor))
                        {
                            if (e.Value is string)
                            {
                                e.Graphics.DrawString(
                                    (string)e.Value,
                                    e.CellStyle.Font,
                                    Brushes.Black,
                                    e.CellBounds.X + 2,
                                    e.CellBounds.Y);
                            }
                            else
                            {
                                string[] columns = (string[])e.Value;
                                int      width   = 0;
                                for (int i = 0; i < 5; i++)
                                {
                                    if (columns[i] != null)
                                    {
                                        e.Graphics.DrawString(
                                            columns[i],
                                            e.CellStyle.Font,
                                            Brushes.Black,
                                            e.CellBounds.X + width + 2,
                                            e.CellBounds.Y);
                                    }
                                    switch (i)
                                    {
                                    case 0: width += 50; break;

                                    case 1: width += 20; break;

                                    case 2: width += 20; break;

                                    case 3: width += 20; break;

                                    case 4: width += 90; break;
                                    }
                                    e.Graphics.DrawLine(gridLines,
                                                        e.CellBounds.Left + width, e.CellBounds.Top,
                                                        e.CellBounds.Left + width, e.CellBounds.Bottom);
                                }
                            }
                        }
                    }
                    e.Handled = true;
                }
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Dispatches appropriate events and performs row selection in the grid
        /// </summary>
        public virtual void DispatchCellSelection(CellElement cell)
        {
            if (cell.Row != null)
            {
                if (!m_MultiSelect)
                {
                    if ((Control.ModifierKeys & Keys.Control) > 0)
                    {
                        UnSelectRow(cell.Row);
                    }
                    else
                    {
                        SelectRow(cell.Row);
                    }
                }
                else //multiselect
                {
                    if ((Control.ModifierKeys & Keys.Shift) > 0)
                    {
                        if (!SelectedRows.Any())
                        {
                            SelectRow(cell.Row);
                            return;
                        }

                        var first = m_RowMap.FindIndex(re => re.Row == SelectedRows.First());
                        var last  = m_RowMap.FindIndex(re => re.Row == SelectedRows.Last());
                        var cur   = m_RowMap.FindIndex(re => re.Row == cell.Row);

                        if (cur < 0)
                        {
                            return;
                        }

                        UnSelectAllRows();

                        if (last <= cur)
                        {
                            for (var i = last; i <= cur; ++i)
                            {
                                SelectRow(m_RowMap[i].Row);
                            }
                        }
                        else if (cur <= first)
                        {
                            for (var i = cur; i <= first; ++i)
                            {
                                SelectRow(m_RowMap[i].Row);
                            }
                        }
                    }
                    else if (!m_MultiSelectWithCtrl || (Control.ModifierKeys & Keys.Control) > 0)
                    {
                        if (IsRowSelected(cell.Row))
                        {
                            UnSelectRow(cell.Row);
                        }
                        else
                        {
                            SelectRow(cell.Row);
                        }
                    }
                    else
                    {
                        UnSelectAllRows();
                        SelectRow(cell.Row);
                    }
                }
            }

            if (m_CellSelectionAllowed)
            {
                try
                {
                    rebuildAllCells(true);//must force the rebuild or event will be invalid
                    OnCellSelection(m_SelectedCell, cell);
                }finally{
                    m_SelectedCell = cell;
                }
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// 调用 OnQuery 回调方法获得数据源
        /// </summary>
        protected async Task QueryData()
        {
            // https://gitee.com/LongbowEnterprise/BootstrapBlazor/issues/I29YK1
            // 选中行目前不支持跨页 原因是选中行实例无法在翻页后保持
            SelectedItems.Clear();

            QueryData <TItem>?queryData = null;
            var queryOption             = new QueryPageOptions()
            {
                IsPage      = IsPagination,
                PageIndex   = PageIndex,
                PageItems   = PageItems,
                SearchText  = SearchText,
                SortOrder   = SortOrder,
                SortName    = SortName,
                Filters     = Filters.Values,
                Searchs     = GetSearchs(),
                SearchModel = SearchModel
            };

            if (OnQueryAsync != null)
            {
                queryData = await OnQueryAsync(queryOption);
            }
            else if (UseInjectDataService)
            {
                queryData = await GetDataService().QueryAsync(queryOption);
            }

            if (queryData != null)
            {
                Items = queryData.Items;
                if (IsTree)
                {
                    KeySet.Clear();
                    if (TableTreeNode <TItem> .HasKey)
                    {
                        CheckExpandKeys(TreeRows);
                    }
                    if (KeySet.Count > 0)
                    {
                        TreeRows = new List <TableTreeNode <TItem> >();
                        foreach (var item in Items)
                        {
                            var node = new TableTreeNode <TItem>(item)
                            {
                                HasChildren = CheckTreeChildren(item),
                            };
                            node.IsExpand = node.HasChildren && node.Key != null && KeySet.Contains(node.Key);
                            if (node.IsExpand)
                            {
                                await RestoreIsExpand(node);
                            }
                            TreeRows.Add(node);
                        }
                    }
                    else
                    {
                        TreeRows = Items.Select(item => new TableTreeNode <TItem>(item)
                        {
                            HasChildren = CheckTreeChildren(item)
                        }).ToList();
                    }
                }
                TotalCount = queryData.TotalCount;
                IsFiltered = queryData.IsFiltered;
                IsSorted   = queryData.IsSorted;
                IsSearch   = queryData.IsSearch;

                // 外部未过滤,内部自行过滤
                if (!IsFiltered && Filters.Any())
                {
                    Items      = Items.Where(Filters.Values.GetFilterFunc <TItem>());
                    TotalCount = Items.Count();
                }

                // 外部未处理排序,内部自行排序
                if (!IsSorted && SortOrder != SortOrder.Unset && !string.IsNullOrEmpty(SortName))
                {
                    var invoker = SortLambdaCache.GetOrAdd(typeof(TItem), key => LambdaExtensions.GetSortLambda <TItem>().Compile());
                    Items = invoker(Items, SortName, SortOrder);
                }
            }

            if (SelectedRows != null)
            {
                SelectedItems.AddRange(Items.Where(i => SelectedRows.Contains(i)));
            }
        }