Beispiel #1
0
        /// <summary>
        /// Create a remote agent with the given name
        /// </summary>
        public static RemoteAgentTag CreateRemoteAgent(string agentName, ITextView view, IEditorFormatMap formatMap)
        {
            Dictionary <string, RemoteAgentTag> existingAgents = GetExistingAgents(view);

            RemoteAgentTag agent;

            if (existingAgents.TryGetValue(agentName, out agent))
            {
                return(agent);
            }

            var brushes = _brushes[existingAgents.Count % _brushes.Count];

            ResourceDictionary agentDictionary = new ResourceDictionary();

            agentDictionary.Add(MarkerFormatDefinition.BorderId, brushes.Item1);
            agentDictionary.Add(MarkerFormatDefinition.FillId, brushes.Item2);

            formatMap.AddProperties(agentName, agentDictionary);

            agent = new RemoteAgentTag(agentName);
            existingAgents[agentName] = agent;

            return(agent);
        }
Beispiel #2
0
        public TypingAgent(RemoteAgentTag tag, string textToType, SnapshotPoint insertionPoint, Dispatcher dispatcher)
        {
            Tag = tag;

            _textToType = textToType;
            _insertionPoint = insertionPoint.Snapshot.CreateTrackingPoint(insertionPoint, PointTrackingMode.Positive);
            _dispatcher = dispatcher;
        }
Beispiel #3
0
        public TypingAgent(RemoteAgentTag tag, string textToType, SnapshotPoint insertionPoint, Dispatcher dispatcher)
        {
            Tag = tag;

            _textToType     = textToType;
            _insertionPoint = insertionPoint.Snapshot.CreateTrackingPoint(insertionPoint, PointTrackingMode.Positive);
            _dispatcher     = dispatcher;
        }
Beispiel #4
0
        /// <summary>
        /// Create a remote agent with the given name
        /// </summary>
        public static RemoteAgentTag CreateRemoteAgent(string agentName, ITextView view, IEditorFormatMap formatMap)
        {
            Dictionary<string, RemoteAgentTag> existingAgents = GetExistingAgents(view);

            RemoteAgentTag agent;
            if (existingAgents.TryGetValue(agentName, out agent))
                return agent;

            var brushes = _brushes[existingAgents.Count % _brushes.Count];

            ResourceDictionary agentDictionary = new ResourceDictionary();
            agentDictionary.Add(MarkerFormatDefinition.BorderId, brushes.Item1);
            agentDictionary.Add(MarkerFormatDefinition.FillId, brushes.Item2);

            formatMap.AddProperties(agentName, agentDictionary);

            agent = new RemoteAgentTag(agentName);
            existingAgents[agentName] = agent;

            return agent;
        }
        public void TextViewCreated(IWpfTextView textView)
        {
            string desiredStartText = @"using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;";

            string desiredEndText = @"{
	class Program
	{
		static void Main(string[] args)
		{
		}
	}
}
";
            string snapshotText   = textView.TextBuffer.CurrentSnapshot.GetText();

            if (!snapshotText.StartsWith(desiredStartText) || !snapshotText.EndsWith(desiredEndText))
            {
                return;
            }

            var formatMap = FormatMapService.GetEditorFormatMap(textView);

            // Create a visual manager for the agent names
            var layer = textView.GetAdornmentLayer("AgentNameLayer");
            AgentBadgeVisualManager manager = new AgentBadgeVisualManager(textView, layer, TagAggregatorService.CreateTagAggregator <RemoteAgentTag>(textView), formatMap);

            Dispatcher dispatcher = textView.VisualElement.Dispatcher;

            // First agent, typing some text in Main
            ThreadPool.QueueUserWorkItem((state) =>
            {
                Thread.Sleep(2000);

                ITextSnapshot snapshot = textView.TextBuffer.CurrentSnapshot;

                SnapshotPoint insertionPoint = snapshot.GetLineFromLineNumber(10).End;

                // Type something with errors, to show that the user can fix it while this agent is typing
                string text = @"
            string foo = args.Count.ToString();
            Console.WriteLine(""Foo is {1}"", foos);
            Thread.Sleep(10000000);
            Console.WriteLine(""I win!!!"");";

                RemoteAgentTag tag = RemoteAgentTag.CreateRemoteAgent("Chris", textView, formatMap);

                TypingAgent agent = new TypingAgent(tag, text, insertionPoint, dispatcher);

                var tagger = AgentTaggerProvider.GetTaggerForView(textView);
                tagger.AddAgent(agent);

                agent.Start();
            });

            // Second agent, typing a comment above the namespace
            ThreadPool.QueueUserWorkItem((state) =>
            {
                Thread.Sleep(3000);

                ITextSnapshot snapshot = textView.TextBuffer.CurrentSnapshot;

                SnapshotPoint insertionPoint = snapshot.GetLineFromLineNumber(4).End;
                string text = @"
/// <summary>
/// This is a namespace!
/// I really like namespaces :)
/// </summary>";

                RemoteAgentTag tag = RemoteAgentTag.CreateRemoteAgent("Michael", textView, formatMap);

                TypingAgent agent = new TypingAgent(tag, text, insertionPoint, dispatcher);

                var tagger = AgentTaggerProvider.GetTaggerForView(textView);
                tagger.AddAgent(agent);

                agent.Start();
            });
        }