Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the InitializationState class.
 /// </summary>
 /// <param name="session"></param>
 internal InitializationState(SessionContext session)
     : base(session)
 {
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new member of the SessionState class, associated
 /// with a provided <see cref="SessionContext">SessionContext</see>.
 /// </summary>
 /// <param name="session">The session this state will be operating on.</param>
 internal SessionState(SessionContext session)
 {
     this.session = session;
 }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the SessionViewForm class, creating
        /// an empty SessionContext and subscribing to its events.
        /// </summary>
        /// <param name="applicationViewForm">The parent application view.</param>
        /// <param name="tabPage">The TabPage this control is placed in.</param>
        public SessionViewForm(ApplicationViewForm applicationViewForm, TabPage tabPage)
        {
            InitializeComponent();

            // User not allowed to close the source code tab
            TabControl.FirstClosableTabIndex = 1;

            this.ApplicationViewForm = applicationViewForm;
            this.tabPage = tabPage;
            this.OnDisk = false;
            this.FileModified = false;

            ChatText.Enabled = false;

            splitContainer.Panel2Collapsed = true;

            // Create a text context for the source code editor
            Context = new TextEditorTextContext(SourceCode);

            SessionContext = new SessionContext(Context);

            // Register to events
            SessionContext.StateChanged += delegate(object sender, EventArgs e)
            {
                Context.Invoke((Action)delegate
                {
                    SessionContextStateChanged(sender, e);
                });
            };

            SessionContext.FileNameChanged += delegate{
                UpdateGuiState();
            };

            SessionContext.Context.Changed += delegate
            {
                FileModified = true;
                UpdateGuiState();
            };

            SessionContext.Closing += delegate
            {
                if (FileModified)
                {
                    string msg = string.Format(TranslationUtil.GetString(ApplicationUtil.LanguageResources, "_MessageBoxOnCloseMessage"), SessionContext.FileName);
                    if (MessageBox.Show(msg, TranslationUtil.GetString(ApplicationUtil.LanguageResources, "_MessageBoxOnCloseCaption"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        applicationViewForm.SaveRequest(this);
                    }
                }
            };

            SessionContext.FileTypeChanged += delegate
            {
                Context.Invoke((Action)delegate
                {
                    SourceCode.SetHighlighting(SessionContext.FileType.Name);
                    tabPage.ImageKey = SessionContext.FileType.Name + "Image";
                });
            };

            SessionContext.StartedExecution +=
                delegate(object sender, StartedExecutionEventArgs e)
                {
                    Context.Invoke((Action)
                        delegate
                        {
                            if (!executionViewForms.ContainsKey(e.SiteId))
                            {
                                string tabTitle = string.Format("Execution (Site {0})", e.SiteId);
                                if (e.SiteId == SessionContext.SiteId)
                                {
                                    tabTitle = "Execution (Me)";
                                }

                                TabPage newPage = new TabPage(tabTitle);
                                ExecutionViewForm executionView = new ExecutionViewForm(e.ExecutionResult);
                                newPage.Controls.Add(executionView);
                                executionViewForms[e.SiteId] = executionView;
                                executionView.Dock = DockStyle.Fill;
                                TabControl.TabPages.Add(newPage);
                                newPage.Tag = e.SiteId;
                                newPage.ImageKey = "ExecutionImage";
                                TabControl.SelectedTab = newPage;
                                executionTabs[e.SiteId] = newPage;
                            }
                            else
                            {
                                executionViewForms[e.SiteId].ExecutionResult = e.ExecutionResult;
                            }

                            // For own execution, let's jump to execution tab
                            if(e.SiteId == SessionContext.SiteId)
                            {
                                TabControl.SelectedTab = executionTabs[e.SiteId];
                            }

                            // TODO: we should have some indicator so the local user
                            // is aware when the a remote user sends a new execution,
                            // but automatically opening the tab is to intrusive.
                        }
                    );
                };

            SessionContext.ReceiveChatMessage += SessionContextReceiveChatMessage;

            TabControl.TabClosed += delegate(object sender, TabClosedEventArgs e)
            {
                int siteId = (int)TabControl.TabPages[e.TabIndex].Tag;
                executionViewForms.Remove(siteId);
                executionTabs.Remove(siteId);
                TabControl.TabPages.RemoveAt(e.TabIndex);
            };

            this.SetState(SessionStates.Disconnected);

            // Load ImageList for tabs
            var rm = new System.Resources.ResourceManager("TwinEditor.Resources", System.Reflection.Assembly.GetExecutingAssembly());

            ImageList imageList = new ImageList();
            imageList.Images.Add("TextImage", (System.Drawing.Image)rm.GetObject("TextImage"));
            imageList.Images.Add("ExecutionImage", (System.Drawing.Image)rm.GetObject("ExecutionImage"));
            TabControl.ImageList = imageList;
            tabPage3.ImageKey = "TextImage";
        }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the ShareSessionEventArgs with the session
 /// to be shared and the communication protocol to be used.
 /// </summary>
 /// <param name="session"></param>
 /// <param name="protocol"></param>
 public ShareSessionEventArgs(SessionContext session, ICommunicationProtocol protocol)
 {
     Protocol = protocol;
     Session = session;
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the SynchronizationState class.
 /// </summary>
 /// <param name="session">The session this instance is operating on.</param>
 internal SynchronizationState(SessionContext session)
     : base(session)
 {
 }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the CloseFileEventArgs.
 /// </summary>
 /// <param name="session">See <see cref="Session" />.</param>
 public CloseFileEventArgs(SessionContext session)
 {
     Session = session;
 }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance of the BootstrappingState class.
 /// </summary>
 /// <param name="session">The session this instance will be operating on.</param>
 internal BootstrappingState(SessionContext session)
     : base(session)
 {
 }
Esempio n. 8
0
 /// <summary>
 /// Initializes a new instance of the SaveFileEventArgs class with
 /// a session and the path where it should be stored.
 /// </summary>
 /// <param name="session">See <see cref="Session" />.</param>
 /// <param name="fileName">See <see cref="FileName" />.</param>
 public SaveFileEventArgs(SessionContext session, string fileName)
 {
     Session = session;
     FileName = fileName;
 }