Ejemplo n.º 1
0
        /// <summary>
        /// Sets destination file of selected rows to given ResX file
        /// </summary>
        private void SetDestinationOfSelected(ResXProjectItem item)
        {
            try {
                if (item == null)
                {
                    throw new ArgumentNullException("item");
                }

                foreach (DataGridViewKeyValueRow <CodeStringResultItem> row in SelectedRows)
                {
                    row.Cells[DestinationColumnName].Value = item.ToString();
                    Validate(row);
                }
            } catch (Exception ex) {
                VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                VisualLocalizer.Library.Components.MessageBox.ShowException(ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes "batch move to resources" tool window and grid
        /// </summary>
        /// <param name="resxItems">List of possible destination items</param>
        /// <param name="items">Result items</param>
        /// <param name="fullName">True if "use full name" policy should be applied</param>
        /// <param name="mark">True if "mark with VL_NO_LOC" policy should be applied</param>
        /// <param name="resxCounts">Number of resources determined to be moved to each ResX file</param>
        /// <param name="sourceItemCounts">Number of resource items for each source code file</param>
        /// <param name="expectedToBeMarked">Number of resources that are expected to be marked with VL_NO_LOC</param>
        /// <returns></returns>
        private BatchMoveToResourcesToolWindow_Accessor InitBatchToolWindow(List <ResXProjectItem> resxItems, List <CodeStringResultItem> items, bool fullName, bool mark, out Dictionary <ResXProjectItem, int> resxCounts, out Dictionary <ProjectItem, int> sourceItemCounts, out int expectedToBeMarked)
        {
            DTE2 dte = Agent.GetDTE();

            expectedToBeMarked = 0;
            sourceItemCounts   = new Dictionary <ProjectItem, int>();

            // init window
            BatchMoveToResourcesToolWindow_Accessor window = new BatchMoveToResourcesToolWindow_Accessor(new PrivateObject(new BatchMoveToResourcesToolWindow()));

            window.SetData(items);

            // init the policies
            window.currentNamespacePolicy = window.NAMESPACE_POLICY_ITEMS[fullName ? 1 : 0];
            window.currentRememberOption  = window.REMEMBER_OPTIONS[mark ? 1 : 0];

            BatchMoveToResourcesToolGrid grid = ((BatchMoveToResourcesToolGrid)window.panel.ToolGrid.Target);
            int x = 0;

            Random rnd = new Random();

            resxCounts = new Dictionary <ResXProjectItem, int>();

            // check/uncheck random rows
            foreach (DataGridViewKeyValueRow <CodeStringResultItem> row in grid.Rows)
            {
                bool check = rnd.Next(2) == 0;
                if (check)
                {
                    // set unique key
                    row.Cells[grid.KeyColumnName].Value = string.Format("xx{0}", x);

                    // select random destination item
                    ResXProjectItem destResX = resxItems[rnd.Next(resxItems.Count)];
                    row.Cells[grid.DestinationColumnName].Value = destResX.ToString();

                    if (!resxCounts.ContainsKey(destResX))
                    {
                        resxCounts.Add(destResX, 0);
                    }
                    resxCounts[destResX]++;
                    if (!sourceItemCounts.ContainsKey(row.DataSourceItem.SourceItem))
                    {
                        sourceItemCounts.Add(row.DataSourceItem.SourceItem, 0);
                    }
                    sourceItemCounts[row.DataSourceItem.SourceItem]++;
                }
                else
                {
                    AspNetStringResultItem aitem = row.DataSourceItem as AspNetStringResultItem;
                    if (((row.DataSourceItem is CSharpStringResultItem) || (aitem != null && aitem.ComesFromCodeBlock && aitem.Language == LANGUAGE.CSHARP)))
                    {
                        if (mark && !row.DataSourceItem.IsMarkedWithUnlocalizableComment)
                        {
                            if (!sourceItemCounts.ContainsKey(row.DataSourceItem.SourceItem))
                            {
                                sourceItemCounts.Add(row.DataSourceItem.SourceItem, 0);
                            }
                            sourceItemCounts[row.DataSourceItem.SourceItem]++;
                        }
                        expectedToBeMarked++;
                    }
                }

                row.Cells[grid.CheckBoxColumnName].Value = check;
                window.panel.ToolGrid.Validate(row);
                if (check)
                {
                    Assert.IsTrue(string.IsNullOrEmpty(row.ErrorText), row.ErrorText);
                }
                x++;
            }

            // randomly sort the grid
            grid.Sort(grid.Columns[rnd.Next(grid.Columns.Count)], rnd.Next(2) == 0 ? System.ComponentModel.ListSortDirection.Ascending : System.ComponentModel.ListSortDirection.Descending);

            return(window);
        }