Exemple #1
0
        /// <summary>
        /// Adds given resource to the control
        /// </summary>
        public override IKeyValueSource Add(string key, ResXDataNode value)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            ResXOthersGridRow row = new ResXOthersGridRow();

            PopulateRow(row, value);

            Rows.Add(row);
            Validate(row);

            if (row.ErrorMessages.Count > 0)
            {
                row.Status = KEY_STATUS.ERROR;
            }
            else
            {
                row.Status       = KEY_STATUS.OK;
                row.LastValidKey = row.Key;
            }

            return(row);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResXOthersGrid"/> class.
        /// </summary>
        public ResXOthersGrid(ResXEditorControl editorControl)
            : base(editorControl)
        {
            ResXOthersGridRow rowTemplate = new ResXOthersGridRow();

            rowTemplate.MinimumHeight = 24;
            this.RowTemplate          = rowTemplate;
        }
Exemple #3
0
        /// <summary>
        /// Called after type was changed - adds undo unit
        /// </summary>
        private void TypeColumnChanged(ResXOthersGridRow row, Type oldValue, Type newValue)
        {
            string key = row.Status == KEY_STATUS.ERROR ? null : row.DataSourceItem.Name;
            OthersChangeTypeUndoUnit unit = new OthersChangeTypeUndoUnit(row, this, key, oldValue, newValue, (string)row.Cells[TypeColumnName].Value, row.DataSourceItem.Comment);

            editorControl.Editor.AddUndoUnit(unit);

            VLOutputWindow.VisualLocalizerPane.WriteLine("Edited type of \"{0}\"", key);
        }
Exemple #4
0
        /// <summary>
        /// Serializes resource data to a string
        /// </summary>
        protected override string CreateMangledComment(ResXStringGridRow r)
        {
            if (r == null)
            {
                throw new ArgumentNullException("row");
            }
            ResXOthersGridRow row = (ResXOthersGridRow)r;

            return(string.Format("@@@{0}-@-{1}-@-{2}-@-{3}-@-{4}", (int)row.Status, row.DataSourceItem.Name, row.DataSourceItem.Comment, row.Value, row.DataType.AssemblyQualifiedName));
        }
Exemple #5
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);
        }
Exemple #6
0
        /// <summary>
        /// Adds given clipboard text to the grid - values separated with , and rows separated with ; format is expected
        /// </summary>
        public override void AddClipboardText(List <List <string> > data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            List <ResXStringGridRow> addedRows = new List <ResXStringGridRow>();

            foreach (List <string> columns in data)
            {
                if (columns.Count < 2)
                {
                    continue;
                }

                string key = columns[0].CreateIdentifier(editorControl.Editor.ProjectItem.DesignerLanguage); // modify key so that is a valid identifier
                string assemblyQualifiedTypeName = columns[1];
                string value   = columns.Count >= 3 ? columns[2] : "";
                string comment = columns.Count >= 4 ? columns[3] : "";

                Type         type = Type.GetType(assemblyQualifiedTypeName);
                ResXDataNode node = new ResXDataNode(key, TypeDescriptor.GetConverter(type).ConvertFromString(value)); // create new resource
                node.Comment = comment;

                ResXOthersGridRow newRow = Add(key, node) as ResXOthersGridRow; // add a row with the resource
                newRow.DataType = type;
                addedRows.Add(newRow);
            }

            if (addedRows.Count > 0)
            {
                NewRowsAdded(addedRows);
                NotifyDataChanged();
                NotifyItemsStateChanged();

                VLOutputWindow.VisualLocalizerPane.WriteLine("Added {0} new rows from clipboard", addedRows.Count);
            }
        }
Exemple #7
0
        /// <summary>
        /// Called after editting a cell
        /// </summary>
        protected override void OnCellEndEdit(DataGridViewCellEventArgs e)
        {
            ResXOthersGridRow row = null;

            try {
                if (e.RowIndex == Rows.Count - 1)
                {
                    return;
                }

                base.OnCellEndEdit(e);

                if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
                {
                    row = Rows[e.RowIndex] as ResXOthersGridRow;

                    bool isNewRow = false;
                    if (row.DataSourceItem == null)   // last empty row was edited, new row has been added
                    {
                        isNewRow     = true;
                        row.DataType = typeof(string);
                        row.Cells[TypeColumnName].Value = row.DataType.FullName;
                        row.DataSourceItem = new ResXDataNode("(new)", string.Empty);
                    }
                    ResXDataNode node = row.DataSourceItem;

                    if (Columns[e.ColumnIndex].Name == KeyColumnName)   // key was edited
                    {
                        string newKey = (string)row.Cells[KeyColumnName].Value;

                        if (isNewRow)
                        {
                            SetNewKey(row, newKey);
                            row.Cells[ReferencesColumnName].Value = "?";
                            NewRowAdded(row);
                            NotifyDataChanged();
                        }
                        else if (string.Compare(newKey, node.Name) != 0)
                        {
                            // key has changed
                            KeyRenamed(row, newKey);
                            SetNewKey(row, newKey);
                            NotifyDataChanged();
                        }
                    }
                    else if (Columns[e.ColumnIndex].Name == ValueColumnName)     // value was edited
                    {
                        string newValue = (string)row.Cells[ValueColumnName].Value;
                        if (newValue == null)
                        {
                            newValue = string.Empty;
                        }

                        if (isNewRow)
                        {
                            row.Status = KEY_STATUS.ERROR;
                            row.Cells[ReferencesColumnName].Value = "?";
                            NewRowAdded(row);
                            NotifyDataChanged();
                        }
                        else if (string.Compare(newValue, node.GetValue <string>()) != 0)
                        {
                            // value has changed
                            ValueChanged(row, node.GetValue <string>(), newValue);
                            NotifyDataChanged();

                            string       key     = (string)row.Cells[KeyColumnName].Value;
                            ResXDataNode newNode = null;
                            try {
                                if (string.IsNullOrEmpty(key))
                                {
                                    newNode    = new ResXDataNode("A", TypeDescriptor.GetConverter(row.DataType).ConvertFromString(newValue));
                                    row.Status = KEY_STATUS.ERROR;
                                }
                                else
                                {
                                    newNode          = new ResXDataNode(key, TypeDescriptor.GetConverter(row.DataType).ConvertFromString(newValue));
                                    row.Status       = KEY_STATUS.OK;
                                    row.LastValidKey = key;
                                }
                            } catch {
                            }

                            if (newNode != null)
                            {
                                newNode.Comment    = (string)row.Cells[CommentColumnName].Value;
                                row.DataSourceItem = newNode;
                            }
                        }
                    }
                    else     // comment was edited
                    {
                        string newComment = (string)row.Cells[CommentColumnName].Value;
                        if (isNewRow)
                        {
                            row.Status = KEY_STATUS.ERROR;
                            row.Cells[ReferencesColumnName].Value = "?";
                            NewRowAdded(row);
                            NotifyDataChanged();
                        }
                        else if (string.Compare(newComment, node.Comment) != 0)
                        {
                            CommentChanged(row, node.Comment, newComment);
                            NotifyDataChanged();

                            node.Comment = newComment;
                        }
                    }
                }
            } catch (Exception ex) {
                VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                VisualLocalizer.Library.Components.MessageBox.ShowException(ex);
            } finally {
                editorControl.ReferenceCounterThreadSuspended = false;
                if (row != null)
                {
                    row.UpdateErrorSetDisplay();
                }
                NotifyItemsStateChanged();
            }
        }
Exemple #8
0
        /// <summary>
        /// Called before editting a cell - checks whether a type cell is edited and if so, displays dialog. Otherwise calls base.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnCellBeginEdit(DataGridViewCellCancelEventArgs e)
        {
            try {
                if (Columns[e.ColumnIndex].Name == TypeColumnName)   // type column is edited
                {
                    e.Cancel = true;
                    ResXOthersGridRow row = Rows[e.RowIndex] as ResXOthersGridRow;

                    // display type-selecting dialog
                    TypeSelectorForm form = new TypeSelectorForm();
                    form.OriginalType = row.DataType;

                    DialogResult result = form.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        // update underlying data
                        bool isNewRow = false;
                        if (row.DataSourceItem == null)   // last empty row was edited, new row has been added
                        {
                            isNewRow           = true;
                            row.DataSourceItem = new ResXDataNode("(new)", string.Empty);
                        }

                        if (isNewRow)
                        {
                            row.Status = KEY_STATUS.ERROR;
                            row.Cells[ReferencesColumnName].Value = "?";
                            row.DataType = form.ResultType;
                            row.Cells[TypeColumnName].Value = form.ResultType.FullName;

                            NotifyCurrentCellDirty(true);

                            NewRowAdded(row);
                            NotifyItemsStateChanged();
                            NotifyDataChanged();
                        }
                        else
                        {
                            Type oldType = row.DataType;
                            if (oldType != form.ResultType)
                            {
                                row.DataType = form.ResultType;
                                row.Cells[TypeColumnName].Value = form.ResultType.FullName;
                                TypeColumnChanged(row, oldType, row.DataType);

                                NotifyItemsStateChanged();
                                NotifyDataChanged();
                            }
                        }

                        // check for errors and update node
                        Validate(row);
                    }
                }
                else     // call standard cell edit procedure
                {
                    base.OnCellBeginEdit(e);
                }
            } catch (Exception ex) {
                VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                VisualLocalizer.Library.Components.MessageBox.ShowException(ex);
            }
        }