public void OnExecute(CommandEventArgs e) { ISvnLogItem selectedLog = EnumTools.GetSingle(e.Selection.GetSelection <ISvnLogItem>()); if (selectedLog == null) { return; } using (PropertyEditorDialog dialog = new PropertyEditorDialog(selectedLog.RepositoryRoot, selectedLog.Revision, true)) { SvnRevisionPropertyListArgs args = new SvnRevisionPropertyListArgs(); args.ThrowOnError = false; SvnPropertyCollection properties = null; if (!e.GetService <IProgressRunner>().RunModal(LogStrings.RetrievingRevisionProperties, delegate(object sender, ProgressWorkerArgs wa) { if (!wa.Client.GetRevisionPropertyList(selectedLog.RepositoryRoot, selectedLog.Revision, args, out properties)) { properties = null; } }).Succeeded) { return; } else if (properties != null) { List <PropertyEditItem> propItems = new List <PropertyEditItem>(); foreach (SvnPropertyValue prop in properties) { PropertyEditItem pi = new PropertyEditItem(dialog.ListView, prop.Key); pi.OriginalValue = pi.Value = pi.BaseValue = prop; propItems.Add(pi); } dialog.PropertyValues = propItems.ToArray(); } if (dialog.ShowDialog(e.Context) != DialogResult.OK) { return; } PropertyEditItem[] finalItems = dialog.PropertyValues; bool hasChanges = false; foreach (PropertyEditItem ei in finalItems) { if (ei.ShouldPersist) { hasChanges = true; break; } } if (!hasChanges) { return; } IProgressRunner progressRunner = e.GetService <IProgressRunner>(); ProgressRunnerResult result = progressRunner.RunModal(LogStrings.UpdatingRevisionProperties, delegate(object sender, ProgressWorkerArgs ee) { foreach (PropertyEditItem ei in finalItems) { if (!ei.ShouldPersist) { continue; } if (ei.IsDeleted) { ee.Client.DeleteRevisionProperty(selectedLog.RepositoryRoot, selectedLog.Revision, ei.PropertyName); } else if (ei.Value.StringValue != null) { ee.Client.SetRevisionProperty(selectedLog.RepositoryRoot, selectedLog.Revision, ei.PropertyName, ei.Value.StringValue); } else { ee.Client.SetRevisionProperty(selectedLog.RepositoryRoot, selectedLog.Revision, ei.PropertyName, ei.Value.RawValue); } } }); if (result.Succeeded) { ILogControl logWindow = e.Selection.GetActiveControl <ILogControl>(); if (logWindow != null) { logWindow.Restart(); } } } // using }
public override void OnExecute(CommandEventArgs e) { SvnItem firstVersioned = null; ISvnStatusCache cache = e.GetService <ISvnStatusCache>(); switch (e.Command) { case AnkhCommand.ItemEditProperties: case AnkhCommand.ItemShowPropertyChanges: foreach (SvnItem i in e.Selection.GetSelectedSvnItems(false)) { if (i.IsVersioned) { firstVersioned = i; break; } } break; case AnkhCommand.ProjectEditProperties: // use project folder foreach (SccProject p in e.Selection.GetSelectedProjects(false)) { IProjectFileMapper pfm = e.GetService <IProjectFileMapper>(); if (pfm != null) { ISccProjectInfo info = pfm.GetProjectInfo(p); if (info != null && info.ProjectDirectory != null) { firstVersioned = cache[info.ProjectDirectory]; } if (firstVersioned != null) { break; } } } break; case AnkhCommand.SolutionEditProperties: // use solution folder IAnkhSolutionSettings solutionSettings = e.GetService <IAnkhSolutionSettings>(); if (solutionSettings != null) { firstVersioned = cache[solutionSettings.ProjectRoot]; } break; } if (firstVersioned == null) { return; // exceptional case } //using (SvnClient client = e.GetService<ISvnClientPool>().GetNoUIClient()) using (PropertyEditorDialog dialog = new PropertyEditorDialog(firstVersioned)) { dialog.Context = e.Context; SortedList <string, PropertyEditItem> editItems = new SortedList <string, PropertyEditItem>(); if (!e.GetService <IProgressRunner>().RunModal(CommandStrings.ReadingProperties, delegate(object Sender, ProgressWorkerArgs wa) { // Retrieve base properties wa.Client.PropertyList(new SvnPathTarget(firstVersioned.FullPath, SvnRevision.Base), delegate(object s, SvnPropertyListEventArgs la) { foreach (SvnPropertyValue pv in la.Properties) { PropertyEditItem ei; if (!editItems.TryGetValue(pv.Key, out ei)) { editItems.Add(pv.Key, ei = new PropertyEditItem(dialog.ListView, pv.Key)); } ei.BaseValue = pv; } }); // wa.Client.PropertyList(firstVersioned.FullPath, delegate(object s, SvnPropertyListEventArgs la) { foreach (SvnPropertyValue pv in la.Properties) { PropertyEditItem ei; if (!editItems.TryGetValue(pv.Key, out ei)) { editItems.Add(pv.Key, ei = new PropertyEditItem(dialog.ListView, pv.Key)); } ei.OriginalValue = ei.Value = pv; } }); }).Succeeded) { return; // Canceled } PropertyEditItem[] items = new PropertyEditItem[editItems.Count]; editItems.Values.CopyTo(items, 0); dialog.PropertyValues = items; if (dialog.ShowDialog(e.Context) == DialogResult.OK) { // Hack: Currently we save all properties, not only the in memory changed ones items = dialog.PropertyValues; bool hasChanges = false; foreach (PropertyEditItem i in items) { if (i.ShouldPersist) { hasChanges = true; break; } } if (!hasChanges) { return; } e.GetService <IProgressRunner>().RunModal(CommandStrings.StoringPropertyValues, delegate(object sender, ProgressWorkerArgs wa) { foreach (PropertyEditItem ei in items) { if (!ei.ShouldPersist) { continue; } if (ei.Value == null) { if (ei.OriginalValue != null) { wa.Client.DeleteProperty(firstVersioned.FullPath, ei.PropertyName); } } else if (!ei.Value.ValueEquals(ei.OriginalValue)) { if (ei.Value.StringValue != null) { wa.Client.SetProperty(firstVersioned.FullPath, ei.PropertyName, ei.Value.StringValue); } else { wa.Client.SetProperty(firstVersioned.FullPath, ei.PropertyName, ei.Value.RawValue); } } } }); } // if } }