Example #1
0
        public BatchMoveToResourcesToolGrid(BatchMoveToResourcesToolPanel panel)
            : base(SettingsObject.Instance.ShowContextColumn, new DestinationKeyValueConflictResolver(true, true))
        {
            this.parentToolPanel   = panel;
            this.MultiSelect       = true;
            this.ClipboardCopyMode = DataGridViewClipboardCopyMode.Disable;

            // used to modify "key" column combo box style
            this.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(BatchMoveToResourcesToolPanel_EditingControlShowing);

            // handles adding of new key in the "key" column combo box
            this.CellValidating += new DataGridViewCellValidatingEventHandler(BatchMoveToResourcesToolPanel_CellValidating);

            // triggers HighlightRequired event
            this.CellDoubleClick += new DataGridViewCellEventHandler(OnRowDoubleClick);

            // called during sorting - extracts data from cells
            this.SortCompare += new DataGridViewSortCompareEventHandler(BatchMoveToResourcesToolGrid_SortCompare);

            // displayes context menu
            this.MouseUp += new MouseEventHandler(OnContextMenuShow);

            DataGridViewKeyValueRow <CodeReferenceResultItem> template = new DataGridViewKeyValueRow <CodeReferenceResultItem>();

            template.MinimumHeight = 24;
            this.RowTemplate       = template;

            ContextMenu contextMenu = new ContextMenu();

            MenuItem stateMenu = new MenuItem("State");

            stateMenu.MenuItems.Add("Checked", new EventHandler((o, e) => {
                try {
                    SetCheckStateOfSelected(true);
                } catch (Exception ex) {
                    VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                    VisualLocalizer.Library.Components.MessageBox.ShowException(ex);
                }
            }));
            stateMenu.MenuItems.Add("Unchecked", new EventHandler((o, e) => {
                try {
                    SetCheckStateOfSelected(false);
                } catch (Exception ex) {
                    VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                    VisualLocalizer.Library.Components.MessageBox.ShowException(ex);
                }
            }));
            contextMenu.MenuItems.Add(stateMenu);

            destinationContextMenu = new MenuItem("Common destination");
            contextMenu.MenuItems.Add(destinationContextMenu);
            contextMenu.Popup += new EventHandler(ContextMenu_Popup);

            this.ContextMenu = contextMenu;

            SettingsObject.Instance.RevalidationRequested += new Action(Instance_RevalidationRequested);
        }
Example #2
0
        /// <summary>
        /// Validates the specified row
        /// </summary>
        protected override void Validate(DataGridViewKeyValueRow <ResXDataNode> r)
        {
            ResXOthersGridRow row       = (ResXOthersGridRow)r;
            TypeConverter     converter = null;

            try {
                row.ErrorMessages.Remove(TYPE_ERROR);

                converter = TypeDescriptor.GetConverter(row.DataType);
                converter.ConvertFromString((string)row.Cells[ValueColumnName].Value);
            } catch {
                row.ErrorMessages.Add(TYPE_ERROR);
            }

            base.Validate(row);
        }
Example #3
0
        /// <summary>
        /// Returns result item associated with the given row, initialized with row values
        /// </summary>
        protected override CodeStringResultItem GetResultItemFromRow(DataGridViewRow originalRow)
        {
            if (originalRow == null)
            {
                throw new ArgumentNullException("originalRow");
            }

            DataGridViewKeyValueRow <CodeStringResultItem> row = originalRow as DataGridViewKeyValueRow <CodeStringResultItem>;

            CodeStringResultItem item = row.DataSourceItem;

            if (CheckBoxColumnName != null && Columns.Contains(CheckBoxColumnName))
            {
                item.MoveThisItem = (bool)(row.Cells[CheckBoxColumnName].Value);
            }
            else
            {
                item.MoveThisItem = true;
            }

            item.Key   = row.Key;
            item.Value = row.Value;

            if (DestinationColumnName != null && Columns.Contains(DestinationColumnName))
            {
                string dest = (string)row.Cells[DestinationColumnName].Value;
                if (!string.IsNullOrEmpty(dest) && resxItemsCache.ContainsKey(dest))
                {
                    item.DestinationItem = resxItemsCache[dest];
                }
                else
                {
                    item.DestinationItem = null;
                }
            }
            else
            {
                item.DestinationItem = null;
            }

            item.ErrorText = row.ErrorText;

            row.DataSourceItem = item;
            return(item);
        }
        /// <summary>
        /// Validate the key/value pair of the row
        /// </summary>
        protected override void Validate(DataGridViewKeyValueRow <ResXDataNode> row)
        {
            if (row == null)
            {
                throw new ArgumentNullException("row");
            }

            string key   = row.Key;
            string value = row.Value;

            string originalValue = (string)row.Cells[KeyColumnName].Tag;

            editorControl.conflictResolver.TryAdd(originalValue, key, row, editorControl.Editor.ProjectItem, null);
            if (originalValue == null)
            {
                row.Cells[KeyColumnName].Tag = key;
            }

            row.UpdateErrorSetDisplay();
        }
Example #5
0
        /// <summary>
        /// Recalculate localization probability for given row, using given criteria
        /// </summary>
        private void UpdateLocProbability(Dictionary <string, AbstractLocalizationCriterion> criteria, DataGridViewKeyValueRow <CodeStringResultItem> row, bool changeChecks)
        {
            int newLocProb = GetResultItemFromRow(row).GetLocalizationProbability(criteria);

            row.Cells[LocProbColumnName].Tag   = newLocProb;
            row.Cells[LocProbColumnName].Value = newLocProb + "%";

            if (changeChecks)   // row should be (un)checked according to localization probability
            {
                bool isChecked     = (bool)row.Cells[CheckBoxColumnName].Value;
                bool willBeChecked = (newLocProb >= AbstractLocalizationCriterion.TRESHOLD_LOC_PROBABILITY);
                row.Cells[CheckBoxColumnName].Tag = row.Cells[CheckBoxColumnName].Value = willBeChecked;

                ChangeRowCheckState(row, isChecked, willBeChecked);
            }
        }
Example #6
0
        /// <summary>
        /// Validates given row and updates its error messages
        /// </summary>
        protected override void Validate(DataGridViewKeyValueRow <CodeStringResultItem> row)
        {
            object dest            = row.Cells[DestinationColumnName].Value;
            bool   existsSameValue = false;

            if (dest == null)   // no destination file was selected
            {
                row.ErrorMessages.Add(NoDestinationFileError);
            }
            else
            {
                row.ErrorMessages.Remove(NoDestinationFileError);

                ResXProjectItem resxItem = resxItemsCache[dest.ToString()];
                if (!resxItem.IsLoaded)
                {
                    resxItem.Load();                                                                          // load the ResX file
                    VLDocumentViewsManager.SetFileReadonly(resxItem.InternalProjectItem.GetFullPath(), true); // lock it
                    loadedItems.Add(resxItem);
                }

                string key   = row.Key;
                string value = row.Value;

                CONTAINS_KEY_RESULT keyConflict = resxItem.GetKeyConflictType(key, value, true); // get conflict type
                switch (keyConflict)
                {
                case CONTAINS_KEY_RESULT.EXISTS_WITH_SAME_VALUE:
                    row.ErrorMessages.Remove(DuplicateKeyError);
                    existsSameValue = true;
                    break;

                case CONTAINS_KEY_RESULT.EXISTS_WITH_DIFF_VALUE:
                    row.ErrorMessages.Add(DuplicateKeyError);
                    break;

                case CONTAINS_KEY_RESULT.DOESNT_EXIST:
                    row.ErrorMessages.Remove(DuplicateKeyError);
                    break;
                }

                string originalValue = (string)row.Cells[KeyColumnName].Tag;
                ((DestinationKeyValueConflictResolver)ConflictResolver).TryAdd(originalValue, key, row, resxItem, row.DataSourceItem.Language);
                if (originalValue == null)
                {
                    row.Cells[KeyColumnName].Tag = key;
                }
            }

            row.UpdateErrorSetDisplay(); // update error messages

            if (row.ErrorMessages.Count == 0)
            {
                if (existsSameValue)   // set background color according to conflict type
                {
                    row.DefaultCellStyle.BackColor = ExistingKeySameValueColor;
                }
                else
                {
                    row.DefaultCellStyle.BackColor = Color.White;
                }
            }
        }
Example #7
0
        /// <summary>
        /// Sets content of the grid
        /// </summary>
        public override void SetData(List <CodeStringResultItem> value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            try {
                base.SetData(value);

                this.Rows.Clear();
                destinationItemsCache.Clear();
                resxItemsCache.Clear();
                loadedItems.Clear();
                CheckedRowsCount = 0;
                SuspendLayout();

                // set "context" column visibility according to settings
                if (Columns.Contains(ContextColumnName))
                {
                    Columns[ContextColumnName].Visible = SettingsObject.Instance.ShowContextColumn;
                }

                foreach (CodeStringResultItem item in value)
                {
                    DataGridViewKeyValueRow <CodeStringResultItem> row = new DataGridViewKeyValueRow <CodeStringResultItem>();
                    row.DataSourceItem = item;

                    DataGridViewCheckBoxCell checkCell = new DataGridViewCheckBoxCell();
                    checkCell.Value = false;
                    row.Cells.Add(checkCell);

                    DataGridViewTextBoxCell locProbCell = new DataGridViewTextBoxCell();
                    row.Cells.Add(locProbCell);

                    DataGridViewTextBoxCell lineCell = new DataGridViewTextBoxCell();
                    lineCell.Value = item.ReplaceSpan.iStartLine + 1;
                    row.Cells.Add(lineCell);

                    DataGridViewComboBoxCell keyCell = new DataGridViewComboBoxCell();

                    // add key name suggestions
                    foreach (string key in item.GetKeyNameSuggestions())
                    {
                        keyCell.Items.Add(key);
                        if (keyCell.Value == null) // add first suggestion as default value
                        {
                            keyCell.Value = key;
                        }
                    }

                    if (SettingsObject.Instance.SelectedKeyIndex >= 0 && SettingsObject.Instance.SelectedKeyIndex < keyCell.Items.Count)
                    {
                        keyCell.Value = keyCell.Items[SettingsObject.Instance.SelectedKeyIndex];
                    }

                    row.Cells.Add(keyCell);

                    DataGridViewTextBoxCell valueCell = new DataGridViewTextBoxCell();
                    valueCell.Value = item.Value;
                    row.Cells.Add(valueCell);

                    DataGridViewTextBoxCell sourceCell = new DataGridViewTextBoxCell();
                    sourceCell.Value = item.SourceItem.Name;
                    row.Cells.Add(sourceCell);

                    DataGridViewComboBoxCell destinationCell = new DataGridViewComboBoxCell();

                    // add possible ResX files as destinations
                    destinationCell.Items.AddRange(CreateDestinationOptions(destinationCell, item.SourceItem));
                    if (destinationCell.Items.Count > 0)
                    {
                        destinationCell.Value = destinationCell.Items[0].ToString();
                    }
                    row.Cells.Add(destinationCell);

                    DataGridViewDynamicWrapCell contextCell = new DataGridViewDynamicWrapCell();
                    contextCell.Value        = item.Context;
                    contextCell.RelativeLine = item.ContextRelativeLine;
                    contextCell.FullText     = item.Context;
                    contextCell.SetWrapContents(false);
                    row.Cells.Add(contextCell);

                    DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
                    row.Cells.Add(cell);
                    Rows.Add(row);

                    locProbCell.ReadOnly = true;
                    valueCell.ReadOnly   = false;
                    sourceCell.ReadOnly  = true;
                    lineCell.ReadOnly    = true;
                    contextCell.ReadOnly = true;

                    var x = row.Cells[ContextColumnName];

                    Validate(row);
                    keyCell.Tag = keyCell.Value;
                }

                this.ClearSelection();
                this.ResumeLayout();
                this.OnResize(null);

                parentToolPanel.ResetFilterSettings(); // reset filter according to settings
                UpdateCheckHeader();

                // perform sorting
                if (SortedColumn != null)
                {
                    Sort(SortedColumn, SortOrder == SortOrder.Ascending ? ListSortDirection.Ascending : ListSortDirection.Descending);
                }
            } finally {
                SetDataFinished = true;
            }
        }