/// <summary> /// Remove the generator for this branch. Note that there is /// no checking here as to whether or not the generator is required /// in other places. Most uses will first call CanRemoveGenerator, but /// switching generators for a format will want to remove this blindly /// then toggle on the other format provider. /// </summary> /// <param name="formatBranch">The branch to remove from the generation process</param> private void RemoveGenerator(OutputFormatBranch formatBranch) { IORMGenerator removeGenerator = formatBranch.SelectedORMGenerator; if (removeGenerator.IsFormatModifier) { OutputFormatBranch primaryBranch = _branches[removeGenerator.ProvidesOutputFormat]; IORMGenerator primaryGenerator = primaryBranch.SelectedORMGenerator; if (primaryGenerator != null) { formatBranch.SelectedORMGenerator = null; PseudoBuildItem pseudoItem; // Turning off a format modifier can indirectly remove the generated target, so make // sure it is still there when the modifier itself is removed. if (_parent.PseudoItemsByOutputFormat.TryGetValue(primaryGenerator.ProvidesOutputFormat, out pseudoItem)) { pseudoItem.CurrentGeneratorNames = primaryBranch.SelectedGeneratorOfficialNames; } } } else { formatBranch.SelectedORMGenerator = null; _parent.RemovePseudoItem(removeGenerator.ProvidesOutputFormat); } }
public override string GetTipText(int row, int column, ToolTipType tipType) { if (column == ColumnNumber.GeneratedFormat && tipType == ToolTipType.StateIcon) { OutputFormatBranch currentBranch = (TranslateRow(ref row) == RowStyle.Generator) ? _branches.Values[row] : _modifiers[row]; IORMGenerator useGenerator = currentBranch.SelectedORMGenerator; if (useGenerator == null) { useGenerator = currentBranch.ORMGenerators[0]; } return(useGenerator.DisplayDescription); } return(base.GetTipText(row, column, tipType)); }
/// <summary> /// Remove the generator for this branch. Note that there is /// no checking here as to whether or not the generator is required /// in other places. Most uses will first call CanRemoveGenerator, but /// switching generators for a format will want to remove this blindly /// then toggle on the other format provider. /// </summary> /// <param name="formatBranch">The branch to remove from the generation process</param> private void RemoveGenerator(OutputFormatBranch formatBranch) { IORMGenerator removeGenerator = formatBranch.SelectedORMGenerator; #if VISUALSTUDIO_10_0 IDictionary <string, ProjectItemElement> buildItemsByGeneratorName #else IDictionary <string, BuildItem> buildItemsByGeneratorName #endif = _parent.BuildItemsByGenerator; if (removeGenerator.IsFormatModifier) { OutputFormatBranch primaryBranch = _branches[removeGenerator.ProvidesOutputFormat]; IORMGenerator primaryGenerator = primaryBranch.SelectedORMGenerator; if (primaryGenerator != null) { #if VISUALSTUDIO_10_0 ProjectItemElement updateBuildItem #else BuildItem updateBuildItem #endif = buildItemsByGeneratorName[primaryGenerator.OfficialName]; formatBranch.SelectedORMGenerator = null; SetItemMetaData(updateBuildItem, ITEMMETADATA_ORMGENERATOR, primaryBranch.SelectedGeneratorOfficialNames); } } else { string generatorKey = removeGenerator.OfficialName; formatBranch.SelectedORMGenerator = null; #if VISUALSTUDIO_10_0 ProjectItemElement removeBuildItem #else BuildItem removeBuildItem #endif = buildItemsByGeneratorName[generatorKey]; buildItemsByGeneratorName.Remove(generatorKey); #if VISUALSTUDIO_10_0 _parent._itemGroup.RemoveChild(removeBuildItem); #else _parent._itemGroup.RemoveItem(removeBuildItem); #endif _parent.AddRemovedItem(removeBuildItem); } }
public bool IsPrimaryDisplayItem(int index) { switch (TranslateRow(ref index)) { case RowStyle.Generator: OutputFormatBranch branch = _branches.Values[index]; IList <IORMGenerator> generators = branch.ORMGenerators; int generatorCount = generators.Count; bool retVal = true; for (int i = 0; i < generatorCount; ++i) { if (generators[i].GeneratesSupportFile) { retVal = false; break; } } return(retVal); default: // case RowStyle.Modifier: return(false); } }
public MainBranch(ORMGeneratorSelectionControl parent #if VISUALSTUDIO_15_0 , IServiceProvider serviceProvider #endif ) { SortedList <string, OutputFormatBranch> branches = new SortedList <string, OutputFormatBranch>(StringComparer.OrdinalIgnoreCase); List <OutputFormatBranch> modifiers = null; int modifierAsGeneratorCount = 0; IDictionary <string, IORMGenerator> generators = #if VISUALSTUDIO_15_0 ORMCustomTool.GetORMGenerators(serviceProvider); #else ORMCustomTool.ORMGenerators; #endif foreach (IORMGenerator ormGenerator in generators.Values) { string outputFormatName = ormGenerator.ProvidesOutputFormat; OutputFormatBranch formatBranch; if (ormGenerator.IsFormatModifier) { // Track modifiers separately if (modifiers == null) { modifiers = new List <OutputFormatBranch>(); } formatBranch = new OutputFormatBranch(this); formatBranch.ORMGenerators.Add(ormGenerator); OutputFormatBranch primaryFormatBranch; if (branches.TryGetValue(outputFormatName, out primaryFormatBranch)) { if (primaryFormatBranch.IsModifier) { if (primaryFormatBranch.ORMGenerators[0].FormatModifierPriority <= ormGenerator.FormatModifierPriority) { primaryFormatBranch.NextModifier = formatBranch; } else { formatBranch.NextModifier = primaryFormatBranch; branches[outputFormatName] = formatBranch; } } else { primaryFormatBranch.NextModifier = formatBranch; } } else { // We don't have a branch yet for a primary generator, track // the modifier by adding it here. We will verify later that // all modifiers have a non-modifier primary generator. branches.Add(outputFormatName, formatBranch); ++modifierAsGeneratorCount; } modifiers.Add(formatBranch); } else { if (branches.TryGetValue(outputFormatName, out formatBranch)) { if (formatBranch.IsModifier) { OutputFormatBranch modifierBranch = formatBranch; formatBranch = new OutputFormatBranch(this); formatBranch.NextModifier = modifierBranch; branches[outputFormatName] = formatBranch; --modifierAsGeneratorCount; } } else { formatBranch = new OutputFormatBranch(this); branches.Add(outputFormatName, formatBranch); } formatBranch.ORMGenerators.Add(ormGenerator); } } if (modifierAsGeneratorCount != 0) { // A modifier with no associated generator does not // make sense, but is currently stored as a branch. // Pull it out of the list. for (int i = modifiers.Count - 1; i >= 0; --i) { OutputFormatBranch testBranch; string outputFormat = modifiers[i].ORMGenerators[0].ProvidesOutputFormat; if (!branches.TryGetValue(outputFormat, out testBranch) || testBranch.IsModifier) { if (testBranch != null) { branches.Remove(outputFormat); } modifiers.RemoveAt(i); } } } _parent = parent; _branches = branches; int modifierCount; if (modifiers != null && 0 != (modifierCount = modifiers.Count)) { if (modifierCount > 1) { modifiers.Sort(delegate(OutputFormatBranch left, OutputFormatBranch right) { return(string.Compare(left.ORMGenerators[0].DisplayName, right.ORMGenerators[0].DisplayName)); }); } _modifiers = modifiers; } }
private StateRefreshChanges ToggleOnRequiredBranches(OutputFormatBranch formatBranch, int branchGeneratorIndex, bool testToggleOff) { StateRefreshChanges retVal = StateRefreshChanges.None; if (formatBranch.IsModifier) { if (formatBranch.SelectedORMGenerator == null) { // The build item is associated primarily with the primary generator, // not the modifier. We need to make sure that the primary generator // is turned on. IORMGenerator modifierGenerator = formatBranch.ORMGenerators[0]; OutputFormatBranch primaryBranch = _branches[modifierGenerator.ProvidesOutputFormat]; IORMGenerator primaryGenerator = primaryBranch.SelectedORMGenerator; if (primaryGenerator == null) { if (StateRefreshChanges.None != ToggleOnRequiredBranches(primaryBranch, 0, false)) { retVal = StateRefreshChanges.Entire; } primaryGenerator = primaryBranch.SelectedORMGenerator; if (primaryGenerator == null) { return(StateRefreshChanges.None); } } formatBranch.SelectedORMGenerator = modifierGenerator; SetItemMetaData(_parent.BuildItemsByGenerator[primaryGenerator.OfficialName], ITEMMETADATA_ORMGENERATOR, primaryBranch.SelectedGeneratorOfficialNames); retVal |= StateRefreshChanges.Children | StateRefreshChanges.Children; } else if (testToggleOff) { // Note that we can always remove a modifier, do not call CanRemoveGenerator RemoveGenerator(formatBranch); retVal |= StateRefreshChanges.Current | StateRefreshChanges.Children; } } else if (formatBranch.SelectedORMGenerator == null) { #if VISUALSTUDIO_10_0 string projectPath = Parent._project.FullPath; #else string projectPath = Parent._project.FullFileName; #endif EnvDTE.ProjectItem projectItem = Parent._projectItem; string sourceFileName = _parent._sourceFileName; string projectItemPath = (string)projectItem.Properties.Item("LocalPath").Value; string newItemDirectory = (new Uri(projectPath)).MakeRelativeUri(new Uri(projectItemPath)).ToString(); newItemDirectory = Path.GetDirectoryName(newItemDirectory); retVal = StateRefreshChanges.Current | StateRefreshChanges.Children; IORMGenerator useGenerator = formatBranch.ORMGenerators[branchGeneratorIndex]; string outputFileName = useGenerator.GetOutputFileDefaultName(sourceFileName); outputFileName = Path.Combine(newItemDirectory, outputFileName); #if VISUALSTUDIO_10_0 ProjectItemElement newBuildItem; #else BuildItem newBuildItem; #endif newBuildItem = useGenerator.AddGeneratedFileItem(_parent._itemGroup, sourceFileName, outputFileName); //string.Concat(newItemPath, Path.DirectorySeparatorChar, _parent._sourceFileName)); _parent.BuildItemsByGenerator[useGenerator.OfficialName] = newBuildItem; _parent.RemoveRemovedItem(newBuildItem); formatBranch.SelectedORMGenerator = useGenerator; IList <string> requiredFormats = useGenerator.RequiresInputFormats; int requiredFormatCount = requiredFormats.Count; IList <string> companionFormats = useGenerator.RequiresCompanionFormats; int companionFormatCount = companionFormats.Count; int totalCount = requiredFormatCount + companionFormatCount; for (int i = 0; i < totalCount; ++i) { OutputFormatBranch requiredBranch; if (_branches.TryGetValue(i < requiredFormatCount ? requiredFormats[i] : companionFormats[i - requiredFormatCount], out requiredBranch)) { if (StateRefreshChanges.None != ToggleOnRequiredBranches(requiredBranch, 0, false)) { retVal = StateRefreshChanges.Entire; } } } } else if (testToggleOff && CanRemoveGenerator(formatBranch)) { RemoveGenerator(formatBranch); retVal = StateRefreshChanges.Current | StateRefreshChanges.Children; } return(retVal); }
private StateRefreshChanges ToggleOnRequiredBranches(OutputFormatBranch formatBranch, int branchGeneratorIndex) { return(ToggleOnRequiredBranches(formatBranch, branchGeneratorIndex, true)); }
/// <summary> /// Test if a generator for an item can be removed /// </summary> /// <param name="branch">The branch to test.</param> /// <returns>true if the generator can be removed without removing a format required by another generator</returns> private bool CanRemoveGenerator(OutputFormatBranch branch) { return(!branch.IsDependency); }
public MainBranch(ORMGeneratorSelectionControl parent) { SortedList<string, OutputFormatBranch> branches = new SortedList<string, OutputFormatBranch>(StringComparer.OrdinalIgnoreCase); List<OutputFormatBranch> modifiers = null; int modifierAsGeneratorCount = 0; foreach (IORMGenerator ormGenerator in ORMCustomTool.ORMGenerators.Values) { string outputFormatName = ormGenerator.ProvidesOutputFormat; OutputFormatBranch formatBranch; if (ormGenerator.IsFormatModifier) { // Track modifiers separately if (modifiers == null) { modifiers = new List<OutputFormatBranch>(); } formatBranch = new OutputFormatBranch(this); formatBranch.ORMGenerators.Add(ormGenerator); OutputFormatBranch primaryFormatBranch; if (branches.TryGetValue(outputFormatName, out primaryFormatBranch)) { if (primaryFormatBranch.IsModifier) { if (primaryFormatBranch.ORMGenerators[0].FormatModifierPriority <= ormGenerator.FormatModifierPriority) { primaryFormatBranch.NextModifier = formatBranch; } else { formatBranch.NextModifier = primaryFormatBranch; branches[outputFormatName] = formatBranch; } } else { primaryFormatBranch.NextModifier = formatBranch; } } else { // We don't have a branch yet for a primary generator, track // the modifier by adding it here. We will verify later that // all modifiers have a non-modifier primary generator. branches.Add(outputFormatName, formatBranch); ++modifierAsGeneratorCount; } modifiers.Add(formatBranch); } else { if (branches.TryGetValue(outputFormatName, out formatBranch)) { if (formatBranch.IsModifier) { OutputFormatBranch modifierBranch = formatBranch; formatBranch = new OutputFormatBranch(this); formatBranch.NextModifier = modifierBranch; branches[outputFormatName] = formatBranch; --modifierAsGeneratorCount; } } else { formatBranch = new OutputFormatBranch(this); branches.Add(outputFormatName, formatBranch); } formatBranch.ORMGenerators.Add(ormGenerator); } } if (modifierAsGeneratorCount != 0) { // A modifier with no associated generator does not // make sense, but is currently stored as a branch. // Pull it out of the list. for (int i = modifiers.Count - 1; i >= 0; --i) { OutputFormatBranch testBranch; string outputFormat = modifiers[i].ORMGenerators[0].ProvidesOutputFormat; if (!branches.TryGetValue(outputFormat, out testBranch) || testBranch.IsModifier) { if (testBranch != null) { branches.Remove(outputFormat); } modifiers.RemoveAt(i); } } } _parent = parent; _branches = branches; int modifierCount; if (modifiers != null && 0 != (modifierCount = modifiers.Count)) { if (modifierCount > 1) { modifiers.Sort(delegate(OutputFormatBranch left, OutputFormatBranch right) { return string.Compare(left.ORMGenerators[0].DisplayName, right.ORMGenerators[0].DisplayName); }); } _modifiers = modifiers; } }
/// <summary> /// Remove the generator for this branch. Note that there is /// no checking here as to whether or not the generator is required /// in other places. Most uses will first call CanRemoveGenerator, but /// switching generators for a format will want to remove this blindly /// then toggle on the other format provider. /// </summary> /// <param name="formatBranch">The branch to remove from the generation process</param> private void RemoveGenerator(OutputFormatBranch formatBranch) { IORMGenerator removeGenerator = formatBranch.SelectedORMGenerator; #if VISUALSTUDIO_10_0 IDictionary<string, ProjectItemElement> buildItemsByGeneratorName #else IDictionary<string, BuildItem> buildItemsByGeneratorName #endif = _parent.BuildItemsByGenerator; if (removeGenerator.IsFormatModifier) { OutputFormatBranch primaryBranch = _branches[removeGenerator.ProvidesOutputFormat]; IORMGenerator primaryGenerator = primaryBranch.SelectedORMGenerator; if (primaryGenerator != null) { #if VISUALSTUDIO_10_0 ProjectItemElement updateBuildItem #else BuildItem updateBuildItem #endif = buildItemsByGeneratorName[primaryGenerator.OfficialName]; formatBranch.SelectedORMGenerator = null; updateBuildItem.SetMetadata(ITEMMETADATA_ORMGENERATOR, primaryBranch.SelectedGeneratorOfficialNames); } } else { string generatorKey = removeGenerator.OfficialName; formatBranch.SelectedORMGenerator = null; #if VISUALSTUDIO_10_0 ProjectItemElement removeBuildItem #else BuildItem removeBuildItem #endif = buildItemsByGeneratorName[generatorKey]; buildItemsByGeneratorName.Remove(generatorKey); #if VISUALSTUDIO_10_0 _parent._itemGroup.RemoveChild(removeBuildItem); #else _parent._itemGroup.RemoveItem(removeBuildItem); #endif _parent.AddRemovedItem(removeBuildItem); } }
private StateRefreshChanges ToggleOnRequiredBranches(OutputFormatBranch formatBranch, int branchGeneratorIndex, bool testToggleOff) { StateRefreshChanges retVal = StateRefreshChanges.None; if (formatBranch.IsModifier) { if (formatBranch.SelectedORMGenerator == null) { // The build item is associated primarily with the primary generator, // not the modifier. We need to make sure that the primary generator // is turned on. IORMGenerator modifierGenerator = formatBranch.ORMGenerators[0]; OutputFormatBranch primaryBranch = _branches[modifierGenerator.ProvidesOutputFormat]; IORMGenerator primaryGenerator = primaryBranch.SelectedORMGenerator; if (primaryGenerator == null) { if (StateRefreshChanges.None != ToggleOnRequiredBranches(primaryBranch, 0, false)) { retVal = StateRefreshChanges.Entire; } primaryGenerator = primaryBranch.SelectedORMGenerator; if (primaryGenerator == null) { return StateRefreshChanges.None; } } formatBranch.SelectedORMGenerator = modifierGenerator; _parent.BuildItemsByGenerator[primaryGenerator.OfficialName].SetMetadata(ITEMMETADATA_ORMGENERATOR, primaryBranch.SelectedGeneratorOfficialNames); retVal |= StateRefreshChanges.Children | StateRefreshChanges.Children; } else if (testToggleOff) { // Note that we can always remove a modifier, do not call CanRemoveGenerator RemoveGenerator(formatBranch); retVal |= StateRefreshChanges.Current | StateRefreshChanges.Children; } } else if (formatBranch.SelectedORMGenerator == null) { #if VISUALSTUDIO_10_0 string projectPath = Parent._project.FullPath; #else string projectPath = Parent._project.FullFileName; #endif EnvDTE.ProjectItem projectItem = Parent._projectItem; string sourceFileName = _parent._sourceFileName; string projectItemPath = (string)projectItem.Properties.Item("LocalPath").Value; string newItemDirectory = (new Uri(projectPath)).MakeRelativeUri(new Uri(projectItemPath)).ToString(); newItemDirectory = Path.GetDirectoryName(newItemDirectory); retVal = StateRefreshChanges.Current | StateRefreshChanges.Children; IORMGenerator useGenerator = formatBranch.ORMGenerators[branchGeneratorIndex]; string outputFileName = useGenerator.GetOutputFileDefaultName(sourceFileName); outputFileName = Path.Combine(newItemDirectory, outputFileName); #if VISUALSTUDIO_10_0 ProjectItemElement newBuildItem; #else BuildItem newBuildItem; #endif newBuildItem = useGenerator.AddGeneratedFileItem(_parent._itemGroup, sourceFileName, outputFileName); //string.Concat(newItemPath, Path.DirectorySeparatorChar, _parent._sourceFileName)); _parent.BuildItemsByGenerator[useGenerator.OfficialName] = newBuildItem; _parent.RemoveRemovedItem(newBuildItem); formatBranch.SelectedORMGenerator = useGenerator; IList<string> requiredFormats = useGenerator.RequiresInputFormats; int requiredFormatCount = requiredFormats.Count; IList<string> companionFormats = useGenerator.RequiresCompanionFormats; int companionFormatCount = companionFormats.Count; int totalCount = requiredFormatCount + companionFormatCount; for (int i = 0; i < totalCount; ++i) { OutputFormatBranch requiredBranch; if (_branches.TryGetValue(i < requiredFormatCount ? requiredFormats[i] : companionFormats[i - requiredFormatCount], out requiredBranch)) { if (StateRefreshChanges.None != ToggleOnRequiredBranches(requiredBranch, 0, false)) { retVal = StateRefreshChanges.Entire; } } } } else if (testToggleOff && CanRemoveGenerator(formatBranch)) { RemoveGenerator(formatBranch); retVal = StateRefreshChanges.Current | StateRefreshChanges.Children; } return retVal; }
private StateRefreshChanges ToggleOnRequiredBranches(OutputFormatBranch formatBranch, int branchGeneratorIndex) { return ToggleOnRequiredBranches(formatBranch, branchGeneratorIndex, true); }
/// <summary> /// Test if a generator for an item can be removed /// </summary> /// <param name="branch">The branch to test.</param> /// <returns>true if the generator can be removed without removing a format required by another generator</returns> private bool CanRemoveGenerator(OutputFormatBranch branch) { return !branch.IsDependency; }
private StateRefreshChanges ToggleOnRequiredBranches(OutputFormatBranch formatBranch, int branchGeneratorIndex, bool testToggleOff) { StateRefreshChanges retVal = StateRefreshChanges.None; if (formatBranch.IsModifier) { if (formatBranch.SelectedORMGenerator == null) { // The build item is associated primarily with the output format for // the primary generator, not the modifier. We need to make sure that // the primary generator is turned on. IORMGenerator modifierGenerator = formatBranch.ORMGenerators[0]; OutputFormatBranch primaryBranch = _branches[modifierGenerator.ProvidesOutputFormat]; IORMGenerator primaryGenerator = primaryBranch.SelectedORMGenerator; if (primaryGenerator == null) { if (StateRefreshChanges.None != ToggleOnRequiredBranches(primaryBranch, 0, false)) { retVal = StateRefreshChanges.Entire; } primaryGenerator = primaryBranch.SelectedORMGenerator; if (primaryGenerator == null) { return(StateRefreshChanges.None); } } formatBranch.SelectedORMGenerator = modifierGenerator; PseudoBuildItem pseudoItem = _parent.PseudoItemsByOutputFormat[primaryGenerator.ProvidesOutputFormat]; pseudoItem.CurrentGeneratorNames = primaryBranch.SelectedGeneratorOfficialNames; retVal |= StateRefreshChanges.Children | StateRefreshChanges.Children; } else if (testToggleOff) { // Note that we can always remove a modifier, do not call CanRemoveGenerator RemoveGenerator(formatBranch); retVal |= StateRefreshChanges.Current | StateRefreshChanges.Children; } } else if (formatBranch.SelectedORMGenerator == null) { IORMGenerator generator = formatBranch.ORMGenerators[branchGeneratorIndex]; retVal = StateRefreshChanges.Current | StateRefreshChanges.Children; formatBranch.SelectedORMGenerator = generator; _parent.AddPseudoItem(generator, formatBranch.SelectedGeneratorOfficialNames); // Notify related generator branches IList <string> requiredFormats = generator.RequiresInputFormats; int requiredFormatCount = requiredFormats.Count; IList <string> companionFormats = generator.RequiresCompanionFormats; int companionFormatCount = companionFormats.Count; int totalCount = requiredFormatCount + companionFormatCount; for (int i = 0; i < totalCount; ++i) { OutputFormatBranch requiredBranch; if (_branches.TryGetValue(i < requiredFormatCount ? requiredFormats[i] : companionFormats[i - requiredFormatCount], out requiredBranch)) { if (StateRefreshChanges.None != ToggleOnRequiredBranches(requiredBranch, 0, false)) { retVal = StateRefreshChanges.Entire; } } } } else if (testToggleOff && CanRemoveGenerator(formatBranch)) { RemoveGenerator(formatBranch); retVal = StateRefreshChanges.Current | StateRefreshChanges.Children; } return(retVal); }