public void DoBlame(CommandEventArgs e, SvnOrigin origin, SvnRevision revisionStart, SvnRevision revisionEnd, bool ignoreEols, SvnIgnoreSpacing ignoreSpacing, bool retrieveMergeInfo) { // There are two SVN related operations: // [1] Getting the file at revisionEnd, which will be displayed in the editor // [2] Getting the blame information, which will be displayed in the margin // This is the parameter structure for [1] getting the file SvnWriteArgs wa = new SvnWriteArgs(); wa.Revision = revisionEnd; // This is the parameter structure for [2] getting the blame information SvnBlameArgs ba = new SvnBlameArgs(); ba.Start = revisionStart; ba.End = revisionEnd; ba.IgnoreLineEndings = ignoreEols; ba.IgnoreSpacing = ignoreSpacing; ba.RetrieveMergedRevisions = retrieveMergeInfo; SvnTarget target = origin.Target; // Can we make this an MEF service? IAnkhTempFileManager tempMgr = e.GetService <IAnkhTempFileManager>(); string tempFile = tempMgr.GetTempFileNamed(target.FileName); Collection <SvnBlameEventArgs> blameResult = null; bool retry = false; ProgressRunnerResult r = e.GetService <IProgressRunner>().RunModal("Annotating", delegate(object sender, ProgressWorkerArgs ee) { // Here we [1] get the file at revisionEnd using (FileStream fs = File.Create(tempFile)) { ee.Client.Write(target, fs, wa); } // Here we [2] get the blame information ba.SvnError += delegate(object errorSender, SvnErrorEventArgs errorEventArgs) { if (errorEventArgs.Exception is SvnClientBinaryFileException) { retry = true; errorEventArgs.Cancel = true; } }; ee.Client.GetBlame(target, ba, out blameResult); }); if (retry) { using (AnkhMessageBox mb = new AnkhMessageBox(e.Context)) { // Move to resources later :) if (DialogResult.Yes != mb.Show("You are trying to annotate a binary file. Are you sure you want to continue?", "Binary file detected", MessageBoxButtons.YesNo, MessageBoxIcon.Information)) { return; } r = e.GetService <IProgressRunner>() .RunModal("Annotating", delegate(object sender, ProgressWorkerArgs ee) { ba.IgnoreMimeType = true; ee.Client.GetBlame(target, ba, out blameResult); }); } } if (!r.Succeeded) { return; } // Create a parameter struture and add it to our internal map. // Creating the actual view model class is now deferred to the GetModel method. var annParam = new AnnotateMarginParameters { Context = e.Context, Origin = origin, BlameResult = blameResult }; _ViewModelMap.Add(tempFile, annParam); // Open the editor. // ToDo: Open files like resx as code. var dte = e.GetService <DTE> (typeof(SDTE)); dte.ItemOperations.OpenFile(tempFile, EnvDTE.Constants.vsViewKindTextView); }
/*private void TryObtainBlock(CommandEventArgs e) * { * ISelectionContextEx ex = e.GetService<ISelectionContextEx>(typeof(ISelectionContext)); * * if (ex == null) * return; * * IVsTextView view = ex.ActiveDocumentFrameTextView; * IVsTextLines lines; * Guid languageService; * IVsLanguageInfo info; * * if (view != null * && VSErr.Succeeded(view.GetBuffer(out lines)) * && VSErr.Succeeded(lines.GetLanguageServiceID(out languageService)) * && null != (info = e.QueryService<IVsLanguageInfo>(languageService))) * { * GC.KeepAlive(info); * IVsLanguageBlock b = info as IVsLanguageBlock; * if (b != null) * { * GC.KeepAlive(b); * } * } * //IVsLanguageBlock * * * GC.KeepAlive(ex); * }*/ static void DoBlame(CommandEventArgs e, SvnOrigin item, SvnRevision revisionStart, SvnRevision revisionEnd, bool ignoreEols, SvnIgnoreSpacing ignoreSpacing, bool retrieveMergeInfo) { SvnWriteArgs wa = new SvnWriteArgs(); wa.Revision = revisionEnd; SvnBlameArgs ba = new SvnBlameArgs(); ba.Start = revisionStart; ba.End = revisionEnd; ba.IgnoreLineEndings = ignoreEols; ba.IgnoreSpacing = ignoreSpacing; ba.RetrieveMergedRevisions = retrieveMergeInfo; SvnTarget target = item.Target; IAnkhTempFileManager tempMgr = e.GetService <IAnkhTempFileManager>(); string tempFile = tempMgr.GetTempFileNamed(target.FileName); Collection <SvnBlameEventArgs> blameResult = null; bool retry = false; ProgressRunnerResult r = e.GetService <IProgressRunner>().RunModal(CommandStrings.Annotating, delegate(object sender, ProgressWorkerArgs ee) { using (FileStream fs = File.Create(tempFile)) { ee.Client.Write(target, fs, wa); } ba.SvnError += delegate(object errorSender, SvnErrorEventArgs errorEventArgs) { if (errorEventArgs.Exception is SvnClientBinaryFileException) { retry = true; errorEventArgs.Cancel = true; } }; ee.Client.GetBlame(target, ba, out blameResult); }); if (retry) { using (AnkhMessageBox mb = new AnkhMessageBox(e.Context)) { if (DialogResult.Yes != mb.Show( CommandStrings.AnnotateBinaryFileContinueAnywayText, CommandStrings.AnnotateBinaryFileContinueAnywayTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information)) { return; } r = e.GetService <IProgressRunner>() .RunModal(CommandStrings.Annotating, delegate(object sender, ProgressWorkerArgs ee) { ba.IgnoreMimeType = true; ee.Client.GetBlame(target, ba, out blameResult); }); } } if (!r.Succeeded) { return; } AnnotateEditorControl annEditor = new AnnotateEditorControl(); IAnkhEditorResolver er = e.GetService <IAnkhEditorResolver>(); annEditor.Create(e.Context, tempFile); annEditor.LoadFile(tempFile); annEditor.AddLines(item, blameResult); // Detect and set the language service Guid language; if (er.TryGetLanguageService(Path.GetExtension(target.FileName), out language)) { // Extension is mapped -> user annEditor.SetLanguageService(language); } else if (blameResult != null && blameResult.Count > 0 && blameResult[0].Line != null) { // Extension is not mapped -> Check if this is xml (like project files) string line = blameResult[0].Line.Trim(); if (line.StartsWith("<?xml") || (line.StartsWith("<") && line.Contains("xmlns=\"http://schemas.microsoft.com/developer/msbuild/"))) { if (er.TryGetLanguageService(".xml", out language)) { annEditor.SetLanguageService(language); } } } }
public override void OnExecute(CommandEventArgs e) { List <SvnOrigin> targets = new List <SvnOrigin>(); SvnRevision startRev = SvnRevision.Zero; SvnRevision endRev = null; switch (e.Command) { case AnkhCommand.ItemAnnotate: endRev = SvnRevision.Working; foreach (SvnItem i in e.Selection.GetSelectedSvnItems(false)) { if (i.IsFile && i.IsVersioned && i.HasCopyableHistory) { targets.Add(new SvnOrigin(i)); } } break; case AnkhCommand.LogAnnotateRevision: foreach (ISvnLogChangedPathItem logItem in e.Selection.GetSelection <ISvnLogChangedPathItem>()) { targets.Add(logItem.Origin); endRev = logItem.Revision; } break; case AnkhCommand.SvnNodeAnnotate: foreach (ISvnRepositoryItem item in e.Selection.GetSelection <ISvnRepositoryItem>()) { targets.Add(item.Origin); endRev = item.Revision; } break; case AnkhCommand.DocumentAnnotate: //TryObtainBlock(e); targets.Add(new SvnOrigin(e.GetService <ISvnStatusCache>()[e.Selection.ActiveDocumentFilename])); endRev = SvnRevision.Working; break; } if (targets.Count == 0) { return; } bool ignoreEols = true; SvnIgnoreSpacing ignoreSpacing = SvnIgnoreSpacing.IgnoreSpace; bool retrieveMergeInfo = false; SvnOrigin target; if ((!e.DontPrompt && !Shift) || e.PromptUser) { using (AnnotateDialog dlg = new AnnotateDialog()) { dlg.SetTargets(targets); dlg.StartRevision = startRev; dlg.EndRevision = endRev; if (dlg.ShowDialog(e.Context) != DialogResult.OK) { return; } target = dlg.SelectedTarget; startRev = dlg.StartRevision; endRev = dlg.EndRevision; ignoreEols = dlg.IgnoreEols; ignoreSpacing = dlg.IgnoreSpacing; retrieveMergeInfo = dlg.RetrieveMergeInfo; } } else { SvnItem one = EnumTools.GetFirst(e.Selection.GetSelectedSvnItems(false)); if (one == null) { return; } target = new SvnOrigin(one); } if (startRev == SvnRevision.Working || endRev == SvnRevision.Working && target.Target is SvnPathTarget) { IAnkhOpenDocumentTracker tracker = e.GetService <IAnkhOpenDocumentTracker>(); if (tracker != null) { tracker.SaveDocument(((SvnPathTarget)target.Target).FullPath); } } DoBlame(e, target, startRev, endRev, ignoreEols, ignoreSpacing, retrieveMergeInfo); }
static void DoBlame(CommandEventArgs e, SvnOrigin item, SvnRevision revisionStart, SvnRevision revisionEnd, bool ignoreEols, SvnIgnoreSpacing ignoreSpacing, bool retrieveMergeInfo) { SvnWriteArgs wa = new SvnWriteArgs(); wa.Revision = revisionEnd; SvnBlameArgs ba = new SvnBlameArgs(); ba.Start = revisionStart; ba.End = revisionEnd; ba.IgnoreLineEndings = ignoreEols; ba.IgnoreSpacing = ignoreSpacing; ba.RetrieveMergedRevisions = retrieveMergeInfo; SvnTarget target = item.Target; IAnkhTempFileManager tempMgr = e.GetService<IAnkhTempFileManager>(); string tempFile = tempMgr.GetTempFileNamed(target.FileName); Collection<SvnBlameEventArgs> blameResult = null; Dictionary<long, string> logMessages = new Dictionary<long, string>(); ba.Notify += delegate(object sender, SvnNotifyEventArgs ee) { if (ee.Action == SvnNotifyAction.BlameRevision && ee.RevisionProperties != null) { if (ee.RevisionProperties.Contains(SvnPropertyNames.SvnLog)) logMessages[ee.Revision] = ee.RevisionProperties[SvnPropertyNames.SvnLog].StringValue; } }; bool retry = false; ProgressRunnerResult r = e.GetService<IProgressRunner>().RunModal(CommandStrings.Annotating, delegate(object sender, ProgressWorkerArgs ee) { using (FileStream fs = File.Create(tempFile)) { ee.Client.Write(target, fs, wa); } ba.SvnError += delegate(object errorSender, SvnErrorEventArgs errorEventArgs) { if (errorEventArgs.Exception is SvnClientBinaryFileException) { retry = true; errorEventArgs.Cancel = true; } }; ee.Client.GetBlame(target, ba, out blameResult); }); if (retry) { using (AnkhMessageBox mb = new AnkhMessageBox(e.Context)) { if (DialogResult.Yes == mb.Show( CommandStrings.AnnotateBinaryFileContinueAnywayText, CommandStrings.AnnotateBinaryFileContinueAnywayTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information)) { r = e.GetService<IProgressRunner>() .RunModal(CommandStrings.Annotating, delegate(object sender, ProgressWorkerArgs ee) { ba.IgnoreMimeType = true; ee.Client.GetBlame(target, ba, out blameResult); }); } } } if (!r.Succeeded) return; AnnotateEditorControl annEditor = new AnnotateEditorControl(); IAnkhEditorResolver er = e.GetService<IAnkhEditorResolver>(); annEditor.Create(e.Context, tempFile); annEditor.LoadFile(tempFile); annEditor.AddLines(item, blameResult, logMessages); // Detect and set the language service Guid language; if (er.TryGetLanguageService(Path.GetExtension(target.FileName), out language)) { // Extension is mapped -> user annEditor.SetLanguageService(language); } else if (blameResult != null && blameResult.Count > 0 && blameResult[0].Line != null) { // Extension is not mapped -> Check if this is xml (like project files) string line = blameResult[0].Line.Trim(); if (line.StartsWith("<?xml") || (line.StartsWith("<") && line.Contains("xmlns=\"http://schemas.microsoft.com/developer/msbuild/"))) { if (er.TryGetLanguageService(".xml", out language)) { annEditor.SetLanguageService(language); } } } }