示例#1
0
        public override void Undo()
        {
            if (Grid.EditorControl.Editor.ReadOnly)
            {
                throw new Exception("Cannot perform this operation - the document is readonly.");
            }

            try {
                Grid.SuspendLayout();

                // remove the rows
                foreach (var Row in Rows)
                {
                    ConflictResolver.TryAdd(Row.Key, null, Row, Control.Editor.ProjectItem, null);
                    Row.Cells[Grid.KeyColumnName].Tag = null;
                    Grid.Rows.Remove(Row);
                }
                Grid.ResumeLayout();
                Grid.NotifyDataChanged();
                Grid.SetContainingTabPageSelected();
            } catch (Exception ex) {
                VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                VisualLocalizer.Library.Components.MessageBox.ShowException(ex);
            }
        }
        public override void Redo()
        {
            if (Grid.EditorControl.Editor.ReadOnly)
            {
                throw new Exception("Cannot perform this operation - the document is readonly.");
            }

            try {
                Grid.SuspendLayout();
                foreach (var element in Elements.Where((el) => { return(el != null); }).OrderByDescending((el) => { return(el.IndexAtDeleteTime); }))
                {
                    ResXStringGridRow row = Grid.Rows[element.IndexAtDeleteTime] as ResXStringGridRow;

                    // unregister from the conflict resolver
                    ConflictResolver.TryAdd(row.Key, null, row, Control.Editor.ProjectItem, null);
                    row.Cells[Grid.KeyColumnName].Tag = null;

                    // remvoe the row
                    Grid.Rows.RemoveAt(element.IndexAtDeleteTime);
                }
                Grid.ResumeLayout();
                Grid.NotifyDataChanged();

                VLOutputWindow.VisualLocalizerPane.WriteLine("Re-deleted {0} string rows", Elements.Count);
                Grid.SetContainingTabPageSelected();
            } catch (Exception ex) {
                VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                VisualLocalizer.Library.Components.MessageBox.ShowException(ex);
            }
        }
示例#3
0
        /// <summary>
        /// Applies given criterion action to rows satisfying given criterion
        /// </summary>
        public void ApplyFilterAction(AbstractLocalizationCriterion crit, LocalizationCriterionAction2 act)
        {
            if (crit == null)
            {
                throw new ArgumentNullException("crit");
            }

            List <DataGridViewRow> toBeDeletedRows = new List <DataGridViewRow>(); // list of rows to be deleted

            foreach (DataGridViewKeyValueRow <CodeStringResultItem> row in Rows)
            {
                bool oldCheckValue = (bool)row.Cells[CheckBoxColumnName].Value;
                bool newCheckValue = oldCheckValue;
                var  evalResult    = crit.Eval(row.DataSourceItem);                                                    // criterion evaluation result

                if (evalResult == true)                                                                                // row satisfies the criterion
                {
                    if (act == LocalizationCriterionAction2.CHECK || act == LocalizationCriterionAction2.CHECK_REMOVE) // check the row
                    {
                        row.Cells[CheckBoxColumnName].Tag = row.Cells[CheckBoxColumnName].Value = true;
                        newCheckValue = true;
                    }
                    else if (act == LocalizationCriterionAction2.UNCHECK)
                    {
                        row.Cells[CheckBoxColumnName].Tag = row.Cells[CheckBoxColumnName].Value = false; // uncheck the row
                        newCheckValue = false;
                    }
                    else if (act == LocalizationCriterionAction2.REMOVE)
                    {
                        row.Cells[CheckBoxColumnName].Tag = row.Cells[CheckBoxColumnName].Value = false;
                        toBeDeletedRows.Add(row); // add row to the list of rows to be deleted
                        newCheckValue = false;
                    }
                }
                else if (!oldCheckValue && evalResult == false && act == LocalizationCriterionAction2.CHECK_REMOVE)
                {
                    toBeDeletedRows.Add(row);
                    newCheckValue = false;
                }

                ChangeRowCheckState(row, oldCheckValue, newCheckValue); // change row check state
            }


            foreach (DataGridViewKeyValueRow <CodeStringResultItem> row in toBeDeletedRows)
            {
                ConflictResolver.TryAdd(row.Key, null, row); // remove the row from conflict resolver
                row.Cells[KeyColumnName].Tag = null;
                row.ErrorText = null;
                Rows.Remove(row);

                removedRows.Add(row); // add to the list of remebered rows
            }

            UpdateCheckHeader();
        }
        public override void Redo()
        {
            if (Control.Editor.ReadOnly)
            {
                throw new Exception("Cannot perform this operation - the document is readonly.");
            }

            try {
                HashSet <AbstractListView> usedLists = new HashSet <AbstractListView>();

                foreach (ListViewKeyItem item in Items)
                {
                    // re-exclude and re-delete the files
                    if (item.RemoveKind != REMOVEKIND.REMOVE && item.DataNode.FileRef != null && item.NeighborItems != null)
                    {
                        string      file     = item.DataNode.FileRef.FileName;
                        ProjectItem projItem = VisualLocalizerPackage.Instance.DTE.Solution.FindProjectItem(file);
                        if (projItem != null)
                        {
                            if ((item.RemoveKind & REMOVEKIND.EXCLUDE) == REMOVEKIND.EXCLUDE)
                            {
                                projItem.Remove();
                            }
                            else
                            {
                                projItem.Delete();
                                File.Delete(file);
                            }
                        }
                    }

                    AbstractListView ListView = item.AbstractListView;
                    usedLists.Add(ListView);

                    // unregister the item from the conflict resolver
                    ConflictResolver.TryAdd(item.Key, null, item, Control.Editor.ProjectItem, null);

                    // remove its image
                    if (!string.IsNullOrEmpty(item.ImageKey) && ListView.LargeImageList.Images.ContainsKey(item.ImageKey))
                    {
                        ListView.LargeImageList.Images.RemoveByKey(item.ImageKey);
                        ListView.SmallImageList.Images.RemoveByKey(item.ImageKey);
                    }

                    // remove the item from the list
                    ListView.Items.Remove(item);
                }

                // update state of list views
                foreach (var usedList in usedLists)
                {
                    usedList.NotifyDataChanged();
                    usedList.NotifyItemsStateChanged();
                }

                if (Items.Count > 0 && Items[0].AbstractListView != null)
                {
                    Items[0].AbstractListView.SetContainingTabPageSelected();
                }
            } catch (Exception ex) {
                VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                VisualLocalizer.Library.Components.MessageBox.ShowException(ex);
            }
        }