/// <summary>
        /// Criterion action combobox value changed
        /// </summary>
        private void Box_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox cBox = (sender as ComboBox);

            if (cBox.SelectedIndex == -1)
            {
                return;
            }
            if (ignoreLocRecalculation)
            {
                return;                         // ignore the change (set in ResetFilterSettings())
            }
            try {
                string critName = (string)cBox.Tag;
                if (Enum.IsDefined(typeof(LocalizationCriterionAction), cBox.SelectedIndex))   // it is a standard criterion action (Force localization, Ignore...)
                {
                    LocalizationCriterionAction newAction = (LocalizationCriterionAction)cBox.SelectedIndex;

                    filterCriteriaCopy[critName].Action = newAction;               // set the value in local copy of criteria
                    ToolGrid.RecalculateLocProbability(filterCriteriaCopy, false); // recalculate localization probability
                }
                else                                                               // it is a special action (Check, Uncheck, ...)
                {
                    LocalizationCriterionAction2 newAction = (LocalizationCriterionAction2)(cBox.SelectedIndex - Enum.GetValues(typeof(LocalizationCriterionAction)).Length);

                    ToolGrid.ApplyFilterAction(filterCriteriaCopy[critName], newAction); // apply the action
                }
            } catch (Exception ex) {
                VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                VisualLocalizer.Library.Components.MessageBox.ShowException(ex);
            }
        }
Exemple #2
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();
        }
        /// <summary>
        /// Returns human-readable representation of the criterion target
        /// </summary>
        public static string ToHumanForm(this LocalizationCriterionAction2 act)
        {
            switch (act)
            {
            case LocalizationCriterionAction2.CHECK:
                return("check rows");

            case LocalizationCriterionAction2.CHECK_REMOVE:
                return("check rows & remove the rest");

            case LocalizationCriterionAction2.UNCHECK:
                return("uncheck rows");

            case LocalizationCriterionAction2.REMOVE:
                return("remove rows");

            default:
                throw new Exception("Unknown LocalizationCriterionAction2: " + act);
            }
        }