/// <summary> /// Modifies conflict relation between two items /// </summary> protected override void SetConflictedItems(IKeyValueSource row1, IKeyValueSource row2, bool p) { BatchMoveToResourcesToolGrid grid = (row1 as DataGridViewRow).DataGridView as BatchMoveToResourcesToolGrid; object dest1 = (row1 as DataGridViewRow).Cells[grid.DestinationColumnName].Value; object dest2 = (row2 as DataGridViewRow).Cells[grid.DestinationColumnName].Value; // items are in conflict only if their destination files are the same p = p && (dest1 == null || dest2 == null || dest1.ToString() == dest2.ToString()); base.SetConflictedItems(row1, row2, p); }
/// <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); }