Exemplo n.º 1
0
        protected void RemoveSelectedRows()
        {
            if (Grid.SelectedRows.Count == 0)
            {
                return;
            }
            WaitForRefillTask();
            bool oldListen = listen;

            listen = false;
            List <DataGridViewRow>    rows              = new List <DataGridViewRow>();
            List <IElement>           elements          = new List <IElement>();
            IList <IContainerElement> containerElements = ElementsContainer.GetGeneralElements();
            List <DataGridViewRow>    selectedRows      = new List <DataGridViewRow>();
            int minIndex = Grid.Rows.Count;

            foreach (DataGridViewRow row in Grid.SelectedRows)
            {
                selectedRows.Add(row);
                int elementIndex = GetElementIndex(row);
                if (elementIndex < minIndex)
                {
                    minIndex = elementIndex;
                }
            }
            foreach (DataGridViewRow row in selectedRows.OrderBy(row => GetElementIndex(row)))
            {
                elements.Add(containerElements[GetElementIndex(row)]);
                rows.Add(row);
            }
            Actions.Actions.Instance.AddNew(new Actions.RemoveContainerElementsAction(mMassOperationControl, ElementsContainer, elements, minIndex), m_Project);
            RefillGrid();
            listen = oldListen;
        }
Exemplo n.º 2
0
        protected void RefillGrid()
        {
            CancelRefillTask();
            StartRefillTask();

            Grid.SuspendLayout();
            Grid.Rows.Clear();
            foreach (int key in m_ElementsToRows.Keys)
            {
                Actions.ElementChanges.Instance.RemoveListener(key, Update);
            }
            m_ElementsToRows.Clear();
            int row = 0;

            foreach (IContainerElement element in ElementsContainer.GetGeneralElements())
            {
                AddElementToGrid(element);
                foreach (int id in GetInterestingElementIds(element))
                {
                    if (!m_ElementsToRows.ContainsKey(id))
                    {
                        m_ElementsToRows[id] = new List <int>();
                        Actions.ElementChanges.Instance.AddListener(id, Update);
                    }
                    m_ElementsToRows[id].Add(row);
                }
                SetElementAttributes(Grid, element, row);
                ++row;
            }
            Grid.ResumeLayout();
        }
Exemplo n.º 3
0
        protected String SerializeSelectedRows()
        {
            if (Grid.SelectedRows.Count == 0)
            {
                return(String.Empty);
            }
            WaitForRefillTask();
            List <IXmlWritable>       elements          = new List <IXmlWritable>();
            IList <IContainerElement> containerElements = ElementsContainer.GetGeneralElements();
            List <int> selectedIndices = new List <int>();

            foreach (DataGridViewRow row in Grid.SelectedRows)
            {
                selectedIndices.Add(GetElementIndex(row));
            }
            selectedIndices.Sort();
            foreach (int rowIndex in selectedIndices)
            {
                elements.Add(containerElements[rowIndex]);
            }
            StringBuilder builder = new StringBuilder();

            Data.DataModule.ProjectManager.ExportElements(elements, builder);
            return(builder.ToString());
        }
Exemplo n.º 4
0
        public void AddElements(IList <IElement> elements, int insertionRow)
        {
            bool oldListen = listen;

            listen = false;
            int index = ElementsContainer.GetGeneralElements().Count;

            Actions.Actions.Instance.AddNew(new Actions.AddContainerElementsAction(mMassOperationControl, ElementsContainer, elements, insertionRow), m_Project);
            RefillGrid();
            if (Grid.Rows.Count > 0)
            {
                if (insertionRow < 0)
                {
                    Grid.FirstDisplayedScrollingRowIndex = 0;
                }
                else if (insertionRow < Grid.Rows.Count)
                {
                    Grid.FirstDisplayedScrollingRowIndex = insertionRow;
                }
                else
                {
                    Grid.FirstDisplayedScrollingRowIndex = Grid.Rows.Count - 1;
                }
            }
            listen = oldListen;
        }
Exemplo n.º 5
0
 protected void StartRefillTask()
 {
     if (HasAdditionalElementData())
     {
         tokenSource = new CancellationTokenSource();
         var token = tokenSource.Token;
         refillGridTask = Task.Factory.StartNew(() =>
         {
             List <Object> ret = new List <object>();
             foreach (IContainerElement element in ElementsContainer.GetGeneralElements())
             {
                 token.ThrowIfCancellationRequested();
                 ret.Add(GetElementData(element));
             }
             return(ret);
         });
         refillGridTask.ContinueWith((result) =>
         {
             if (result.Status == TaskStatus.RanToCompletion)
             {
                 bool cancel    = tokenSource.IsCancellationRequested;
                 refillGridTask = null;
                 tokenSource.Dispose();
                 tokenSource = null;
                 if (!cancel)
                 {
                     SetAdditionalGridData(result.Result);
                 }
             }
         }, TaskScheduler.FromCurrentSynchronizationContext());
     }
 }
Exemplo n.º 6
0
        private void Grid_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
        {
            if (!listen)
            {
                return;
            }
            bool c = CancelRefillTask();

            listen = false;
            List <IElement>           remaining         = new List <IElement>();
            IList <IContainerElement> containerElements = ElementsContainer.GetGeneralElements();

            foreach (DataGridViewRow row in Grid.Rows)
            {
                int index = GetElementIndex(row);

                if (index >= containerElements.Count)
                {
                    index = containerElements.Count - 1;
                }

                remaining.Add(containerElements[index]);
            }
            List <IElement> elements = (new List <IElement>(containerElements)).Except(remaining).ToList();

            Actions.Actions.Instance.AddNew(new Actions.RemoveContainerElementsAction(mMassOperationControl, ElementsContainer, elements,
                                                                                      containerElements.IndexOf(elements[0] as IContainerElement)), m_Project);
            listen = true;
            if (c)
            {
                StartRefillTask();
            }
        }
Exemplo n.º 7
0
 private void editMenuItem_Click(object sender, EventArgs e)
 {
     WaitForRefillTask();
     if (Grid.SelectedRows.Count > 0)
     {
         FireElementDoubleClick(ElementsContainer.GetGeneralElements()[GetElementIndex(Grid.SelectedRows[0])]);
     }
 }
Exemplo n.º 8
0
 private void Update(int elementID, Actions.ElementChanges.ChangeType changeType)
 {
     if (!listen)
     {
         return;
     }
     if (elementID == ElementsContainer.Id && changeType == Actions.ElementChanges.ChangeType.PreRemoved)
     {
         listen = false;
         return;
     }
     else if (elementID == ElementsContainer.Id && changeType == Actions.ElementChanges.ChangeType.Removed)
     {
         listen = true;
         return;
     }
     listen = false;
     CancelRefillTask();
     if (elementID == ElementsContainer.Id && changeType == Actions.ElementChanges.ChangeType.Changed)
     {
         RefillGrid();
     }
     else if (m_ElementsToRows.ContainsKey(elementID))
     {
         if (changeType == Actions.ElementChanges.ChangeType.Removed)
         {
             RefillGrid();
         }
         else if (changeType == Actions.ElementChanges.ChangeType.Renamed)
         {
             foreach (int row in m_ElementsToRows[elementID])
             {
                 ChangeElementDataInGrid(elementID, row);
             }
         }
         else if (changeType == Actions.ElementChanges.ChangeType.Changed)
         {
             foreach (int row in m_ElementsToRows[elementID])
             {
                 ChangeElementDataInGrid(elementID, row);
                 SetElementAttributes(Grid, ElementsContainer.GetGeneralElements()[row], row);
             }
         }
     }
     listen = true;
 }
Exemplo n.º 9
0
        private void Grid_UserDeletingRows(object sender, DataGridViewRowCancelEventArgs e)
        {
            if (!listen)
            {
                return;
            }
            bool c = CancelRefillTask();

            listen = false;
            List <IElement>           elements          = new List <IElement>();
            IList <IContainerElement> containerElements = ElementsContainer.GetGeneralElements();

            elements.Add(containerElements[GetElementIndex(e.Row)]);

            Actions.Actions.Instance.AddNew(new Actions.RemoveContainerElementsAction(mMassOperationControl, ElementsContainer, elements,
                                                                                      GetElementIndex(e.Row)), m_Project);
            listen = true;
            if (c)
            {
                StartRefillTask();
            }
        }
Exemplo n.º 10
0
        private void Grid_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
        {
            if (!listen)
            {
                return;
            }
            bool c = CancelRefillTask();

            listen = false;
            List <IElement>           elements          = new List <IElement>();
            IList <IContainerElement> containerElements = ElementsContainer.GetGeneralElements();

            for (int i = 0; i < e.RowCount; ++i)
            {
                elements.Add(containerElements[GetElementIndex(Grid.Rows[e.RowIndex]) + i]);
            }
            Actions.Actions.Instance.AddNew(new Actions.RemoveContainerElementsAction(mMassOperationControl, ElementsContainer, elements,
                                                                                      GetElementIndex(Grid.Rows[e.RowIndex])), m_Project);
            listen = true;
            if (c)
            {
                StartRefillTask();
            }
        }