示例#1
0
 public bool ReplaceOneCall(IWpfTextView atv)
 {
   Contract.Assume(atv != null);
   var caret = atv.Caret.Position.BufferPosition.Position;
   var tra = new TacticReplacerActor(atv.TextBuffer, caret);
   if (tra.LoadStatus != TacticReplaceStatus.Success)  return NotifyOfReplacement(tra.LoadStatus);
   var tedit = atv.TextBuffer.CreateEdit();
   var status = TacticReplaceStatus.TranslatorFail;
   try {
     status = tra.ReplaceSingleTacticCall(tedit);
     if (status == TacticReplaceStatus.Success) { tedit.Apply(); } else { tedit.Dispose(); }
   } catch {  tedit.Dispose(); }
   return NotifyOfReplacement(status);
 }
示例#2
0
        public bool ShowRot(IWpfTextView atv)
        {
            Contract.Assume(atv != null);

            string expanded;
            var    caret        = atv.Caret.Position.BufferPosition.Position;
            var    triggerPoint = atv.TextBuffer.CurrentSnapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive);
            var    tra          = new TacticReplacerActor(atv.TextBuffer, caret);

            if (tra.LoadStatus != TacticReplaceStatus.Success)
            {
                return(NotifyOfReplacement(tra.LoadStatus));
            }
            var status = tra.ExpandSingleTacticCall(caret, out expanded);

            if (status != TacticReplaceStatus.Success)
            {
                return(NotifyOfReplacement(status));
            }

            string file;
            var    fileLoaded = RefactoringUtil.LoadAndCheckDocument(atv.TextBuffer, out file);

            if (!fileLoaded)
            {
                return(NotifyOfReplacement(TacticReplaceStatus.NoDocumentPersistence));
            }

            var session = _pb.CreatePeekSession(new PeekSessionCreationOptions(atv, RotPeekRelationship.SName, triggerPoint, 0, false, null, false));

            _activePeekSession.Remove(file);
            _activePeekSession.Add(file, new ActivePeekSessionData {
                TriggerPoint   = triggerPoint,
                ExpandedTactic = expanded,
                ActiveTactic   = tra.GetActiveTacticName()
            });
            session.Start();
            return(NotifyOfReplacement(TacticReplaceStatus.Success));
        }
示例#3
0
        public static string GetExpandedForPreview(int position, ITextBuffer buffer, ref SnapshotSpan methodName)
        {
            Contract.Assume(buffer != null);
            var tra = new TacticReplacerActor(buffer, position);

            if (!tra.MemberReady)
            {
                return(null);
            }

            methodName = new SnapshotSpan(buffer.CurrentSnapshot, tra.MemberNameStart, tra.MemberName.Length);
            string expanded;

            if (position > tra.MemberBodyStart)
            {
                tra.ExpandSingleTacticCall(position, out expanded);
            }
            else
            {
                tra.ExpandTacticByMember(out expanded);
            }
            return(expanded);
        }
示例#4
0
    public bool ShowRot(IWpfTextView atv)
    {
      Contract.Assume(atv != null);

      string expanded;
      var caret = atv.Caret.Position.BufferPosition.Position;
      var triggerPoint = atv.TextBuffer.CurrentSnapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive);
      var tra = new TacticReplacerActor(atv.TextBuffer, caret);
      if (tra.LoadStatus != TacticReplaceStatus.Success) return NotifyOfReplacement(tra.LoadStatus);
      var status = tra.ExpandSingleTacticCall(caret, out expanded);
      if (status != TacticReplaceStatus.Success)
        return NotifyOfReplacement(status);
      
      string file;
      var fileLoaded = RefactoringUtil.LoadAndCheckDocument(atv.TextBuffer, out file);
      if (!fileLoaded) return NotifyOfReplacement(TacticReplaceStatus.NoDocumentPersistence);
      
      var session = _pb.CreatePeekSession(new PeekSessionCreationOptions(atv, RotPeekRelationship.SName, triggerPoint, 0, false, null, false));
      _activePeekSession.Remove(file);
      _activePeekSession.Add(file, new ActivePeekSessionData {
        TriggerPoint = triggerPoint,
        ExpandedTactic = expanded,
        ActiveTactic = tra.GetActiveTacticName()
      });
      session.Start();
      return NotifyOfReplacement(TacticReplaceStatus.Success);
    }
示例#5
0
    public static string GetExpandedForPreview(int position, ITextBuffer buffer, ref SnapshotSpan methodName)
    {
      Contract.Assume(buffer != null);
      var tra = new TacticReplacerActor(buffer, position);
      if (!tra.MemberReady) return null;

      methodName = new SnapshotSpan(buffer.CurrentSnapshot, tra.MemberNameStart, tra.MemberName.Length);
      string expanded;
      if (position > tra.MemberBodyStart)
        tra.ExpandSingleTacticCall(position, out expanded);
      else
        tra.ExpandTacticByMember(out expanded);
      return expanded;
    }
示例#6
0
 public bool UpdateRot(string file, ITextSnapshot snapshot)
 {
   if (String.IsNullOrEmpty(file) || _activePeekSession==null || !_activePeekSession.ContainsKey(file)) return false;
   var session = _activePeekSession[file];
   string expanded;
   var position = session.TriggerPoint.GetPosition(snapshot);
   var tra = new TacticReplacerActor(snapshot.TextBuffer, position);
   var name = tra.GetActiveTacticName();
   if(name!=session.ActiveTactic) session.Updater?.Invoke(null);
   if (tra.LoadStatus != TacticReplaceStatus.Success) return NotifyOfReplacement(tra.LoadStatus);
   var status = tra.ExpandSingleTacticCall(position, out expanded);
   if (status != TacticReplaceStatus.Success)
     return NotifyOfReplacement(status);
   session.ExpandedTactic = expanded;
   session.Updater?.Invoke(expanded);
   return true;
 }
示例#7
0
    public bool ReplaceAll(ITextBuffer tb) {
      Contract.Assume(tb != null);

      var tra = new TacticReplacerActor(tb);
      var isMoreMembers = tra.NextMemberInTld();
      var replaceStatus = TacticReplaceStatus.Success;
      var tedit = tb.CreateEdit();
      try
      {
        while (isMoreMembers && (replaceStatus == TacticReplaceStatus.Success || replaceStatus == TacticReplaceStatus.NoTactic))
        {
          var isMoreTactics = tra.NextTacticCallInMember();
          while (isMoreTactics && (replaceStatus == TacticReplaceStatus.Success || replaceStatus == TacticReplaceStatus.NoTactic))
          {
            replaceStatus = tra.ReplaceSingleTacticCall(tedit);
            isMoreTactics = tra.NextTacticCallInMember();
          }
          isMoreMembers = tra.NextMemberInTld();
        }

        if(replaceStatus==TacticReplaceStatus.Success || replaceStatus == TacticReplaceStatus.NoTactic)
          { tedit.Apply();} else { tedit.Dispose();}
      } catch { tedit.Dispose(); }
      return NotifyOfReplacement(replaceStatus);
    }