/// <summary>
        /// Called when Remove button was clicked in editor's toolbar
        /// </summary>
        /// <param name="flags">Bitmask of REMOVEKIND values, settings parameters for the action</param>
        /// <param name="addUndoUnit">True if undo unit should be added for the operation</param>
        /// <param name="undoUnit">Created undo unit (if any)</param>
        protected void EditorControl_RemoveRequested(REMOVEKIND flags, bool addUndoUnit, out RemoveStringsUndoUnit undoUnit)
        {
            undoUnit = null;
            try {
                if (!this.Visible)
                {
                    return;
                }
                if (this.SelectedRows.Count == 0)
                {
                    return;
                }
                if ((flags | REMOVEKIND.REMOVE) != REMOVEKIND.REMOVE)
                {
                    throw new ArgumentException("Cannot delete or exclude strings.");
                }

                if ((flags & REMOVEKIND.REMOVE) == REMOVEKIND.REMOVE)
                {
                    bool dataChanged = false;
                    List <ResXStringGridRow> copyRows = new List <ResXStringGridRow>(SelectedRows.Count);

                    foreach (ResXStringGridRow row in SelectedRows)
                    {
                        if (!row.IsNewRow)
                        {
                            // remove the row from the conflict resolver
                            editorControl.conflictResolver.TryAdd(row.Key, null, row, editorControl.Editor.ProjectItem, null);

                            row.Cells[KeyColumnName].Tag = null;
                            row.IndexAtDeleteTime        = row.Index;
                            copyRows.Add(row);
                            Rows.Remove(row);
                            dataChanged = true;
                        }
                    }

                    if (dataChanged)
                    {
                        // create and add the undo unit
                        undoUnit = new RemoveStringsUndoUnit(editorControl, copyRows, this, editorControl.conflictResolver);
                        if (addUndoUnit)
                        {
                            editorControl.Editor.AddUndoUnit(undoUnit);
                        }

                        NotifyItemsStateChanged();
                        NotifyDataChanged();

                        VLOutputWindow.VisualLocalizerPane.WriteLine("Removed {0} rows", copyRows.Count);
                    }
                }
            } catch (Exception ex) {
                VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                VisualLocalizer.Library.Components.MessageBox.ShowException(ex);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called from editor when Inline operation is requested
        /// </summary>
        /// <param name="kind">Bitmask of INLINEKIND parameters</param>
        private void EditorControl_InlineRequested(INLINEKIND kind)
        {
            bool readonlyExists = false;

            foreach (ResXStringGridRow row in SelectedRows)
            {
                if (row.IsNewRow)
                {
                    continue;
                }

                readonlyExists = readonlyExists || row.CodeReferenceContainsReadonly;
                if (readonlyExists)
                {
                    break;
                }
            }
            if (readonlyExists)
            {
                VisualLocalizer.Library.Components.MessageBox.ShowError("This operation cannot be executed, because some of the references are located in readonly files.");
                return;
            }

            // show confirmation
            DialogResult result = VisualLocalizer.Library.Components.MessageBox.Show("This operation is irreversible, cannot be undone globally, only using undo managers in open files. Do you want to proceed?",
                                                                                     null, OLEMSGBUTTON.OLEMSGBUTTON_YESNO, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND, OLEMSGICON.OLEMSGICON_WARNING);

            if (result == DialogResult.Yes)
            {
                try {
                    editorControl.ReferenceCounterThreadSuspended = true; // suspend reference lookuper thread

                    if ((kind & INLINEKIND.INLINE) == INLINEKIND.INLINE)
                    {
                        editorControl.UpdateReferencesCount((IEnumerable)SelectedRows); // update references for specified rows manually

                        List <CodeReferenceResultItem> totalList = new List <CodeReferenceResultItem>();

                        foreach (ResXStringGridRow row in SelectedRows)
                        {
                            if (!row.IsNewRow)
                            {
                                totalList.AddRange(row.CodeReferences);
                            }
                        }
                        BatchInliner inliner = new BatchInliner();

                        // run inliner
                        int errors = 0;
                        inliner.Inline(totalList, false, ref errors);
                        VLOutputWindow.VisualLocalizerPane.WriteLine("Inlining of selected rows finished - found {0} references, {1} finished successfuly", totalList.Count, totalList.Count - errors);
                    }

                    if ((kind & INLINEKIND.REMOVE) == INLINEKIND.REMOVE)
                    {
                        // remove the rows if requested
                        RemoveStringsUndoUnit removeUnit = null;
                        EditorControl_RemoveRequested(REMOVEKIND.REMOVE, false, out removeUnit);
                    }

                    StringInlinedUndoItem undoItem = new StringInlinedUndoItem(SelectedRows.Count);
                    editorControl.Editor.AddUndoUnit(undoItem);
                } catch (Exception ex) {
                    VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                    VisualLocalizer.Library.Components.MessageBox.ShowException(ex);
                } finally {
                    editorControl.ReferenceCounterThreadSuspended = false;
                }
            }
        }