Ejemplo n.º 1
0
        public void ProcessTest()
        {
            Agent.EnsureSolutionOpen();

            DTE2 DTE = Agent.GetDTE();
            BatchInlineCommand target = Agent.BatchInlineCommand;

            var window = DTE.OpenFile(null, Agent.VBReferencesTestFile1);

            window.Activate();

            target.Process(true);

            Assert.IsTrue(VLDocumentViewsManager.IsFileLocked(Agent.VBReferencesTestFile1));

            ValidateResults(GetExpectedResultsFor(Agent.VBReferencesTestFile1), target.Results);

            Assert.IsTrue(VLDocumentViewsManager.IsFileLocked(Agent.VBReferencesTestFile1));

            VLDocumentViewsManager.SetFileReadonly(Agent.VBReferencesTestFile1, false);
            Assert.IsFalse(VLDocumentViewsManager.IsFileLocked(Agent.VBReferencesTestFile1));

            window.Detach();
            window.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called from context menu of Solution Explorer, processes given list of ProjectItems
        /// </summary>
        /// <param name="selectedItems">Items selected in Solution Explorer - to be searched</param>
        /// <param name="verbose">True if processing info should be printed to the output</param>
        public override void Process(Array selectedItems, bool verbose)
        {
            if (verbose)
            {
                VLOutputWindow.VisualLocalizerPane.WriteLine("Batch Move to Resources command started on selected items from Solution Explorer");
            }
            if (verbose)
            {
                ProgressBarHandler.StartIndeterminate(Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_Find);
            }

            try {
                Results = new List <CodeStringResultItem>();

                base.Process(selectedItems, verbose);

                // remove empty strings
                Results.RemoveAll((item) => { return(item.Value.Trim().Length == 0); });

                // set each source file as readonly
                Results.ForEach((item) => {
                    VLDocumentViewsManager.SetFileReadonly(item.SourceItem.GetFullPath(), true);
                });
            } finally {
                if (verbose)
                {
                    ProgressBarHandler.StopIndeterminate(Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_Find);
                }
            }

            if (verbose)
            {
                VLOutputWindow.VisualLocalizerPane.WriteLine("Batch Move to Resources completed - found {0} items to be moved", Results.Count);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Called from context menu of a code file, processes selected block of code
        /// </summary>
        /// <param name="verbose">True if processing info should be printed to the output</param>
        public override void ProcessSelection(bool verbose)
        {
            base.ProcessSelection(verbose);

            if (verbose)
            {
                VLOutputWindow.VisualLocalizerPane.WriteLine("Batch Inline command started on text selection of active document ");
            }
            if (verbose)
            {
                ProgressBarHandler.StartIndeterminate(Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_Find);
            }

            try {
                Results = new List <CodeReferenceResultItem>();

                Process(currentlyProcessedItem, IntersectsWithSelection, verbose);

                // remove items laying outside the selection
                Results.RemoveAll((item) => {
                    return(IsItemOutsideSelection(item));
                });

                // set each source file as readonly
                Results.ForEach((item) => {
                    VLDocumentViewsManager.SetFileReadonly(item.SourceItem.GetFullPath(), true);
                });
            } finally {
                // clear cached data
                trieCache.Clear();
                trieCache.Clear();
                codeUsingsCache.Clear();

                if (verbose)
                {
                    ProgressBarHandler.StopIndeterminate(Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_Find);
                }
            }
            if (verbose)
            {
                VLOutputWindow.VisualLocalizerPane.WriteLine("Found {0} items to be moved", Results.Count);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Called from context menu of a code file, processes selected block of code
        /// </summary>
        /// <param name="verbose">True if processing info should be printed to the output</param>
        public override void ProcessSelection(bool verbose)
        {
            base.ProcessSelection(verbose); // initialize class variables

            if (verbose)
            {
                VLOutputWindow.VisualLocalizerPane.WriteLine("Batch Move to Resources command started on text selection of active document ");
            }
            if (verbose)
            {
                ProgressBarHandler.StartIndeterminate(Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_Find);
            }

            try {
                Results = new List <CodeStringResultItem>();

                Process(currentlyProcessedItem, IntersectsWithSelection, verbose); // process active document, leaving only those items that have non-empty intersection with the selection

                // remove empty strings and result items laying outside the selection
                Results.RemoveAll((item) => {
                    bool empty = item.Value.Trim().Length == 0;
                    return(empty || IsItemOutsideSelection(item));
                });

                // set each source file as readonly
                Results.ForEach((item) => {
                    VLDocumentViewsManager.SetFileReadonly(item.SourceItem.GetFullPath(), true);
                });
            } finally {
                if (verbose)
                {
                    ProgressBarHandler.StopIndeterminate(Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_Find);
                }
            }

            if (verbose)
            {
                VLOutputWindow.VisualLocalizerPane.WriteLine("Found {0} items to be moved", Results.Count);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Called from context menu of a code file, processes current document
        /// </summary>
        /// <param name="verbose">True if processing info should be printed to the output</param>
        public override void Process(bool verbose)
        {
            base.Process(verbose); // initialize class variables

            if (verbose)
            {
                VLOutputWindow.VisualLocalizerPane.WriteLine("Batch Inline command started on active document... ");
            }
            if (verbose)
            {
                ProgressBarHandler.StartIndeterminate(Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_Find);
            }

            try {
                Results = new List <CodeReferenceResultItem>();

                Process(currentlyProcessedItem, verbose);

                // set each source file as readonly
                Results.ForEach((item) => {
                    VLDocumentViewsManager.SetFileReadonly(item.SourceItem.GetFullPath(), true);
                });
            } finally {
                // clear cached data
                trieCache.Clear();
                codeUsingsCache.Clear();

                if (verbose)
                {
                    ProgressBarHandler.StopIndeterminate(Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_Find);
                }
            }
            if (verbose)
            {
                VLOutputWindow.VisualLocalizerPane.WriteLine("Found {0} items to be moved", Results.Count);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Called from context menu of a code file, processes current document
        /// </summary>
        /// <param name="verbose">True if processing info should be printed to the output</param>
        public override void Process(bool verbose)
        {
            base.Process(verbose); // initialize class variables

            if (verbose)
            {
                VLOutputWindow.VisualLocalizerPane.WriteLine("Batch Move to Resources command started on active document... ");
            }
            if (verbose)
            {
                ProgressBarHandler.StartIndeterminate(Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_Find);
            }

            try {
                Results = new List <CodeStringResultItem>();

                Process(currentlyProcessedItem, verbose);                                // process active document

                Results.RemoveAll((item) => { return(item.Value.Trim().Length == 0); }); // remove empty strings

                // set each source file as readonly
                Results.ForEach((item) => {
                    VLDocumentViewsManager.SetFileReadonly(item.SourceItem.GetFullPath(), true);
                });
            } finally {
                if (verbose)
                {
                    ProgressBarHandler.StopIndeterminate(Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_Find);
                }
            }

            if (verbose)
            {
                VLOutputWindow.VisualLocalizerPane.WriteLine("Found {0} items to be moved", Results.Count);
            }
        }
Ejemplo n.º 7
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;
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Sets grid content
        /// </summary>
        public override void SetData(List <CodeReferenceResultItem> value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            try {
                Rows.Clear();
                errorRows.Clear();
                this.SuspendLayout();

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

                // create new row for each result item
                foreach (var item in value)
                {
                    DataGridViewCheckedRow <CodeReferenceResultItem> row = new DataGridViewCheckedRow <CodeReferenceResultItem>();
                    row.DataSourceItem = item;

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

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

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

                    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);

                    DataGridViewTextBoxCell destinationCell = new DataGridViewTextBoxCell();
                    destinationCell.Value = item.DestinationItem.ToString();
                    if (LockFiles)
                    {
                        VLDocumentViewsManager.SetFileReadonly(item.DestinationItem.InternalProjectItem.GetFullPath(), true);            // lock selected destination file
                    }
                    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);

                    referenceCell.ReadOnly   = true;
                    valueCell.ReadOnly       = true;
                    sourceCell.ReadOnly      = true;
                    destinationCell.ReadOnly = true;
                    lineCell.ReadOnly        = true;
                    contextCell.ReadOnly     = true;
                }

                CheckedRowsCount    = Rows.Count;
                CheckHeader.Checked = true;
                this.ClearSelection();
                this.ResumeLayout(true);
                this.OnResize(null);
                NotifyErrorRowsChanged();

                // perform sorting
                if (SortedColumn != null)
                {
                    Sort(SortedColumn, SortOrder == SortOrder.Ascending ? ListSortDirection.Ascending : ListSortDirection.Descending);
                }
            } finally {
                SetDataFinished = true;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Executed on every change in window form
        /// </summary>
        private void ValidateData()
        {
            bool   existsFile = comboBox.Items.Count > 0; // there's at least one possible destination file
            string errorText  = null;
            bool   ok         = true;

            if (!existsFile)   // no destination file
            {
                ok        = false;
                errorText = "Project does not contain any useable resource files";
            }
            else
            {
                ResXProjectItem item = comboBox.SelectedItem as ResXProjectItem;
                if (!item.IsLoaded)
                {
                    item.Load();
                    VLDocumentViewsManager.SetFileReadonly(item.InternalProjectItem.GetFullPath(), true);
                }
                resultItem.DestinationItem = item;

                bool isKeyEmpty            = string.IsNullOrEmpty(keyBox.Text);
                bool isValidIdentifier     = keyBox.Text.IsValidIdentifier(resultItem.Language);
                bool hasOwnDesigner        = (item.DesignerItem != null || item.HasImplicitDesignerFile) && !item.IsCultureSpecific();
                bool identifierErrorExists = false;

                // determine whether current key name is valid
                switch (SettingsObject.Instance.BadKeyNamePolicy)
                {
                case BAD_KEY_NAME_POLICY.IGNORE_COMPLETELY:
                    identifierErrorExists = isKeyEmpty;     // only empty keys are invalid
                    break;

                case BAD_KEY_NAME_POLICY.IGNORE_ON_NO_DESIGNER:
                    identifierErrorExists = isKeyEmpty || (!isValidIdentifier && hasOwnDesigner);     // empty keys and invalid identifiers in ResX files with their own designer file
                    break;

                case BAD_KEY_NAME_POLICY.WARN_ALWAYS:
                    identifierErrorExists = isKeyEmpty || !isValidIdentifier;     // empty keys and invalid identifiers
                    break;
                }

                if (!identifierErrorExists)   // identifier ok - check for key name conflicts
                {
                    keyConflict = item.GetKeyConflictType(keyBox.Text, valueBox.Text, true);

                    Color backColor = Color.White;
                    switch (keyConflict)
                    {
                    case CONTAINS_KEY_RESULT.EXISTS_WITH_SAME_VALUE:     // key already exists and has the same value - ok
                        backColor = EXISTING_KEY_COLOR;
                        break;

                    case CONTAINS_KEY_RESULT.EXISTS_WITH_DIFF_VALUE:     // key exists with different value - error
                        errorText             = "Key is already present and has different value";
                        existingValueBox.Text = item.GetString(keyBox.Text);
                        backColor             = ERROR_COLOR;
                        break;

                    case CONTAINS_KEY_RESULT.DOESNT_EXIST:     // key doesn't exists - ok
                        backColor = Color.White;
                        break;
                    }

                    overwriteButton.Visible  = keyConflict == CONTAINS_KEY_RESULT.EXISTS_WITH_DIFF_VALUE;
                    inlineButton.Visible     = keyConflict == CONTAINS_KEY_RESULT.EXISTS_WITH_DIFF_VALUE;
                    existingValueBox.Visible = keyConflict == CONTAINS_KEY_RESULT.EXISTS_WITH_DIFF_VALUE;
                    existingLabel.Visible    = keyConflict == CONTAINS_KEY_RESULT.EXISTS_WITH_DIFF_VALUE;

                    keyBox.BackColor   = backColor;
                    valueBox.BackColor = backColor;
                }
                else
                {
                    errorText          = "Key is not a valid identifier";
                    keyBox.BackColor   = ERROR_COLOR;
                    valueBox.BackColor = Color.White;
                }

                ok = !identifierErrorExists && !overwriteButton.Visible;

                referenceText.ClassPart = item.Class;
                referenceText.KeyPart   = keyBox.Text;

                if (string.IsNullOrEmpty(item.Namespace))   // no namespace was found in designer file - error
                {
                    ok        = false;
                    errorText = "Cannot reference resources in this file, missing namespace";
                }
                else
                {
                    if (!usingBox.Checked || resultItem.MustUseFullName)   // force using full reference
                    {
                        referenceText.NamespacePart = item.Namespace;
                    }
                    else
                    {
                        referenceText.NamespacePart = null;
                    }
                }

                referenceLabel.Text = resultItem.GetReferenceText(referenceText);
            }

            okButton.Enabled = ok;
            if (ok)
            {
                errorLabel.Text = string.Empty;
            }
            else
            {
                errorLabel.Text = errorText;
            }
        }