Esempio n. 1
0
        /// <summary>
        /// sets the objects that would be accessed later by other classes
        /// </summary>
        /// <param name="h">iwpftextviewhost of the textview</param>
        /// <param name="cb">the client network object</param>
        /// <param name="cpe">the explorer management object</param>
        public GraphicObjects(IWpfTextViewHost h, CoProNetwork cb, CoProExplorer cpe)
        {
            coproExplorer = cpe;
            if (DTE2.ActiveWindow != null)
            {
                iwpf    = h;
                we      = ((Events2)DTE2.Events).WindowEvents;
                this.cb = cb;
                //pie.ItemAdded += ItemAdded;
                //((Events2)DTE2.Events).WindowEvents.WindowClosing += new _dispWindowEvents_WindowClosingEventHandler(ClosedWindow);
                //cb = new MyCallBack();
                //cb.ChangeCaret += new ChangeCaretEventHandler(my_CaretChange);
                //twice = false;
                //TODO: register to cb's events
                //TODO: add a different handler function for each of the events
                // examples: http://www.codeproject.com/Articles/20550/C-Event-Implementation-Fundamentals-Best-Practices

                //ts.NewLine();
                //ts.Insert("a");
                //tde = ((Events2)DTE2.Events).TextDocumentKeyPressEvents;
                //tde.BeforeKeyPress += new _dispTextDocumentKeyPressEvents_BeforeKeyPressEventHandler(KeyPress_EventHandler);

                //te.LineChanged += new _dispTextEditorEvents_LineChangedEventHandler(EnterFix);
                //DTE2.Events.CommandEvents.BeforeExecute+= new _dispCommandEvents_BeforeExecuteEventHandler()
                //te.LineChanged += new _dispTextEditorEvents_LineChangedEventHandler(IntelisenseFix);
            }
        }
 /// <summary>
 /// reseting the package objects
 /// </summary>
 private void ShutDown()
 {
     if (cb != null)
     {
         //FileStream fs = File.Create(cb.ProjPath + "\\CoProFiles\\timestamps.txt");
         //fs.Close();
         //StreamWriter sw = new StreamWriter(cb.ProjPath + "\\CoProFiles\\timestamps.txt");
         //sw.Write(TimeStampDirectory(cb.ProjPath, 1, cb.ProjPath.Substring(cb.ProjPath.LastIndexOf('\\'))));
         //sw.Close();
         if (cb.IsAdmin)
         {
             XElement      xe  = CreateFileSystemXmlTree(cb.ProjPath, 1, cb.ProjPath.Substring(cb.ProjPath.LastIndexOf('\\') + 1));
             XmlTextWriter xwr = new XmlTextWriter(cb.ProjPath + "\\CoProFiles\\timestamps.xml", System.Text.Encoding.UTF8);
             xwr.Formatting = Formatting.Indented;
             xe.WriteTo(xwr);
             xwr.Close();
         }
         cb.Abort();
         cb = null;
         CoProFilterProvider.isFirst = true;
     }
     if (CoProgrammerPackage.service != null)
     {
         CoProgrammerPackage.service.Close();
         CoProgrammerPackage.service = null;
     }
 }
        /// <summary>
        /// These functions are the callbacks used to execute commands when the a menu items are clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        ///

        /// <summary>
        /// Callback function for connection option on the menu to open the window
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ConnectCallback(object sender, EventArgs e)
        {
            cb = new CoProNetwork();
            CoProWindow c = new CoProWindow(cb);

            c.Show();
            //Carets cs = new Carets(GetCurrentViewHost());
        }
Esempio n. 4
0
        DocumentEvents saveEvent;                                                                  //DocumentEvents object used for saving events

        /// <summary>
        /// Initialization of UI and editing related events and members
        /// </summary>
        /// <param name="textView"></param>
        /// <param name="mcb"></param>
        /// <param name="cs"></param>
        public CoProCommandFilter(IWpfTextView textView, CoProNetwork mcb, GraphicObjects cs)
        {
            m_textView                = textView;
            m_adornmentLayer          = m_textView.GetAdornmentLayer("MultiEditLayer");
            m_added                   = false;
            m_textView.LayoutChanged += m_textView_LayoutChanged;
            cb   = mcb;
            gobj = cs;
            //crts.DTE2.Events.TextEditorEvents.LineChanged += new _dispTextEditorEvents_LineChangedEventHandler();
            events    = gobj.DTE2.Events;
            saveEvent = events.DocumentEvents;
            saveEvent.DocumentSaved += new _dispDocumentEvents_DocumentSavedEventHandler(my_DocWasSaved);
            cb.NewCaret             += new NewCaretEventHandler(my_NewCaret);
            cb.ChangeCaret          += new ChangeCaretEventHandler(my_ChangedCaret);
            cb.EditorDisc           += new EditorDisconnectedEventHandler(my_EditorDisc);
            cb.NewText       += new NewTextEventHandler(my_AddedText);
            cb.RemovedText   += new RemovedTextEventHandler(my_RemovedText);
            cb.SaveEvent     += new SaveEventHandler(my_Save);
            cb.AddAllEditors += new AddCurrentEditorsEventHandler(my_AddEditors);
            cb.ItemRemoved   += new ItemRemovedEventHandler(my_RemovedItem);
            cb.ItemAdded     += new NewItemAddedEventHandler(my_ItemAdded);
            textView.Caret.PositionChanged += new EventHandler <CaretPositionChangedEventArgs>(my_PositionChanged);
            textView.TextBuffer.Changed    += TextBuffer_Changed;
            InitBrushes();
            uiDisp = Dispatcher.CurrentDispatcher;
            ITextDocument textDoc;
            var           rc = m_textView.TextBuffer.Properties.TryGetProperty <ITextDocument>(
                typeof(ITextDocument), out textDoc);

            filename = gobj.DTE2.Solution.FullName;
            filename = filename.Substring(filename.LastIndexOf('\\') + 1);
            filename = filename.Split('.')[0];
            filename = textDoc.FilePath.Substring(textDoc.FilePath.IndexOf(filename));
            if (cb.IsAdmin)
            {
                cb.AdminEvent += my_AdminCallback;
            }
            if (isFirstTime)
            {
                isFirstTime = false;
            }
            else
            {
                if (!cb.IsAdmin)
                {
                    cb.UpdateSpecificFile(filename);
                }
            }
            filename = filename.Substring(filename.LastIndexOf('\\') + 1);
            cb.IntializePosition(filename, m_textView.Caret.Position.BufferPosition.Position, cb.Name);

            currBufferSize = m_textView.TextSnapshot.Length;
        }
        DocumentEvents saveEvent;//DocumentEvents object used for saving events

        /// <summary>
        /// Initialization of UI and editing related events and members
        /// </summary>
        /// <param name="textView"></param>
        /// <param name="mcb"></param>
        /// <param name="cs"></param>
        public CoProCommandFilter(IWpfTextView textView, CoProNetwork mcb, GraphicObjects cs)
        {
            m_textView = textView;
            m_adornmentLayer = m_textView.GetAdornmentLayer("MultiEditLayer");
            m_added = false;
            m_textView.LayoutChanged += m_textView_LayoutChanged;
            cb = mcb;
            gobj = cs;
            //crts.DTE2.Events.TextEditorEvents.LineChanged += new _dispTextEditorEvents_LineChangedEventHandler();
            events = gobj.DTE2.Events;
            saveEvent = events.DocumentEvents;
            saveEvent.DocumentSaved += new _dispDocumentEvents_DocumentSavedEventHandler(my_DocWasSaved);
            cb.NewCaret += new NewCaretEventHandler(my_NewCaret);
            cb.ChangeCaret += new ChangeCaretEventHandler(my_ChangedCaret);
            cb.EditorDisc += new EditorDisconnectedEventHandler(my_EditorDisc);
            cb.NewText += new NewTextEventHandler(my_AddedText);
            cb.RemovedText += new RemovedTextEventHandler(my_RemovedText);
            cb.SaveEvent += new SaveEventHandler(my_Save);
            cb.AddAllEditors += new AddCurrentEditorsEventHandler(my_AddEditors);
            cb.ItemRemoved += new ItemRemovedEventHandler(my_RemovedItem);
            cb.ItemAdded += new NewItemAddedEventHandler(my_ItemAdded);
            textView.Caret.PositionChanged += new EventHandler<CaretPositionChangedEventArgs>(my_PositionChanged);
            textView.TextBuffer.Changed += TextBuffer_Changed;
            InitBrushes();
            uiDisp = Dispatcher.CurrentDispatcher;
            ITextDocument textDoc;
            var rc = m_textView.TextBuffer.Properties.TryGetProperty<ITextDocument>(
              typeof(ITextDocument), out textDoc);
            filename = gobj.DTE2.Solution.FullName;
            filename = filename.Substring(filename.LastIndexOf('\\') + 1);
            filename = filename.Split('.')[0];
            filename = textDoc.FilePath.Substring(textDoc.FilePath.IndexOf(filename));
            if (cb.IsAdmin)
            {
                cb.AdminEvent += my_AdminCallback;
            }
            if (isFirstTime)
            {
                isFirstTime = false;
            }
            else
            {
                if (!cb.IsAdmin)
                {
                    cb.UpdateSpecificFile(filename);
                }
            }
            filename = filename.Substring(filename.LastIndexOf('\\') + 1);
            cb.IntializePosition(filename, m_textView.Caret.Position.BufferPosition.Position, cb.Name);

            currBufferSize = m_textView.TextSnapshot.Length;
        }
 /// <summary>
 /// Sets the client network object
 /// </summary>
 /// <param name="cb"></param>
 /// 
 public void SetConnection(CoProNetwork cb)
 {
     this.cb=cb;
 }
Esempio n. 7
0
 public CoProWindow(CoProNetwork calb)
 {
     InitializeComponent();
     cb = calb;
 }
 /// <summary>
 /// Sets the client network object
 /// </summary>
 /// <param name="cb"></param>
 ///
 public void SetConnection(CoProNetwork cb)
 {
     this.cb = cb;
 }
Esempio n. 9
0
 public CloneWindow(CoProNetwork calb, string name)
 {
     InitializeComponent();
     cb = calb;
     m_name = name;
 }
Esempio n. 10
0
 public CoProWindow(CoProNetwork calb)
 {
     InitializeComponent();
     cb = calb;
 }
 /// <summary>
 /// reseting the package objects
 /// </summary>
 private void ShutDown()
 {
     if (cb != null)
     {
         //FileStream fs = File.Create(cb.ProjPath + "\\CoProFiles\\timestamps.txt");
         //fs.Close();
         //StreamWriter sw = new StreamWriter(cb.ProjPath + "\\CoProFiles\\timestamps.txt");
         //sw.Write(TimeStampDirectory(cb.ProjPath, 1, cb.ProjPath.Substring(cb.ProjPath.LastIndexOf('\\'))));
         //sw.Close();
         if (cb.IsAdmin)
         {
             XElement xe = CreateFileSystemXmlTree(cb.ProjPath, 1, cb.ProjPath.Substring(cb.ProjPath.LastIndexOf('\\') + 1));
             XmlTextWriter xwr = new XmlTextWriter(cb.ProjPath + "\\CoProFiles\\timestamps.xml", System.Text.Encoding.UTF8);
             xwr.Formatting = Formatting.Indented;
             xe.WriteTo(xwr);
             xwr.Close();
         }
         cb.Abort();
         cb = null;
         CoProFilterProvider.isFirst = true;
     }
     if (CoProgrammerPackage.service != null)
     {
         CoProgrammerPackage.service.Close();
         CoProgrammerPackage.service = null;
     }
 }
 /// <summary>
 /// These functions are the callbacks used to execute commands when the a menu items are clicked.
 /// See the Initialize method to see how the menu item is associated to this function using
 /// the OleMenuCommandService service and the MenuCommand class.
 /// </summary>
 /// 
 /// <summary>
 /// Callback function for connection option on the menu to open the window
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ConnectCallback(object sender, EventArgs e)
 {
     cb = new CoProNetwork();
     CoProWindow c = new CoProWindow(cb);
     c.Show();
     //Carets cs = new Carets(GetCurrentViewHost());
 }
Esempio n. 13
0
 public CloneWindow(CoProNetwork calb, string name)
 {
     InitializeComponent();
     cb     = calb;
     m_name = name;
 }
        /// <summary>
        /// This function is called whenever a new item to edit is opened
        /// </summary>
        /// <param name="textViewAdapter">adapter of the text view (given by the VS itself [MEF] )</param>
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            if (!runFlag)
            {
                cb = CoProgrammerPackage.cb;// gets current network object
                if (cb == null)
                {
                    cb = new CoProNetwork();//if null create new
                    CoProgrammerPackage.cb = cb;
                }
                ToolWindowPane window = CoProgrammerPackage.currRunning.FindToolWindow(typeof(CoProToolWindow), 0, true);
                if ((null == window) || (null == window.Frame))
                {
                    throw new NotSupportedException(Resources.CanNotCreateWindow);
                }
                gobj = new GraphicObjects(GetCurrentViewHost(textViewAdapter), cb, (CoProExplorer)window.Content);
                gobj.CoProExplorer.SetConnection(cb); //updates co pro explorer window
                if (isFirst)                          // on opening the solution
                {
                    se                 = ((Events2)gobj.DTE2.Events).SolutionEvents;
                    de                 = ((Events2)gobj.DTE2.Events).DebuggerEvents;
                    se.Opened         += SubscribeGlobalEvents;                                     //solution opened event
                    de.OnEnterRunMode += new _dispDebuggerEvents_OnEnterRunModeEventHandler(OnRun); //when running the code event
                    bool setAdminConfiguraions = false;
                    var  slnName   = gobj.DTE2.Solution.FullName;
                    var  adminFile = slnName.Substring(0, slnName.Substring(0, slnName.LastIndexOf('\\')).LastIndexOf('\\')) + "\\admin.txt";
                    //IF THERE IS ADMIN INFO
                    if (File.Exists(adminFile))//internal file that was created
                    {
                        StreamReader sr  = new StreamReader(adminFile);
                        string       dir = sr.ReadToEnd();
                        if (dir.Split('\n')[0] == slnName.Substring(0, slnName.LastIndexOf('\\')))
                        {
                            CoProgrammerPackage.service = new CoProServer();// runs the server
                            string filesDir = slnName.Substring(0, slnName.LastIndexOf('\\')) + "\\CoProFiles";
                            if (!Directory.Exists(filesDir))
                            {
                                Directory.CreateDirectory(slnName.Substring(0, slnName.LastIndexOf('\\')) + "\\CoProFiles");
                            }
                            string        path = slnName.Substring(0, slnName.LastIndexOf('\\'));
                            XElement      xe   = CoProgrammerPackage.CreateFileSystemXmlTree(path, 1, path.Substring(path.LastIndexOf('\\') + 1));
                            XmlTextWriter xwr  = new XmlTextWriter(path + "\\CoProFiles\\timestamps.xml", System.Text.Encoding.UTF8);// timestamps file creation
                            xwr.Formatting = Formatting.Indented;
                            xe.WriteTo(xwr);
                            xwr.Close();
                            FileStream fs     = File.Create(slnName.Substring(0, slnName.LastIndexOf('\\')) + "\\CoProFiles\\client.txt");
                            string     ipPort = "localhost:" + (CoProgrammerPackage.service.PortOfService() + 10).ToString() + ":" + dir.Split('\n')[1];
                            fs.Write(Encoding.ASCII.GetBytes(ipPort), 0, ipPort.Length);// creating client file if there is no one exsisting
                            fs.Close();
                            setAdminConfiguraions = true;
                        }
                    }
                    //IF THERE IS A CLIENT INFO
                    if (File.Exists(slnName.Substring(0, slnName.LastIndexOf('\\')) + "\\CoProFiles\\client.txt"))// internal client info file
                    {
                        StreamReader sr        = new StreamReader(slnName.Substring(0, slnName.LastIndexOf('\\')) + "\\CoProFiles\\client.txt");
                        string       iportName = sr.ReadToEnd();
                        cb.SetIpPort(iportName.Split(':')[0], iportName.Split(':')[1]);
                        cb.Name = iportName.Split(':')[2]; // configurates the class accoridng to info in file
                        if (cb.Connect())                  // attempt to connect
                        {
                            cb.ProjPath = slnName.Substring(0, slnName.LastIndexOf('\\'));
                            if (setAdminConfiguraions)
                            {
                                if (cb.SetAdmin(true))
                                {
                                    cb.IsAdmin = true;// if is admin, he gets the access to some funcitons
                                    cb.SetProjectDir(slnName.Substring(0, slnName.LastIndexOf('\\')));
                                }
                            }
                            else
                            {
                                cb.IsAdmin = false;
                                cb.UpdateProject();// updates project for regular clients
                            }
                            if (cb.IsAdmin)
                            {
                                cb.ExpectedSequence++;       // +1 to current count toget next messages
                            }
                            gobj.CoProExplorer.UpdateInfo(); // updates window info
                        }
                    }
                    else
                    {
                        cb   = null;
                        gobj = null;
                    }
                    isFirst = false;
                }

                IWpfTextView textView = editorFactory.GetWpfTextView(textViewAdapter);//gets the text view
                if (textView == null)
                {
                    return;
                }
                AddCommandFilter(textViewAdapter, new CoProCommandFilter(textView, cb, gobj));//adds an instance of our command filter to the text view
            }
            runFlag = false;
        }