예제 #1
0
파일: Program.cs 프로젝트: 424f/lebowski
        private void Run()
        {
            // initialize application utilities (e.g. language resources)
            ApplicationUtil.Initialize();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            SetupConfiguration();

            // Display main form
            IApplicationView applicationView = new ApplicationViewForm();
            ApplicationContext presenter = new ApplicationContext(applicationView);
            applicationView.ApplicationContext = presenter;

            applicationView.Show();

            Application.Run();
        }
예제 #2
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";
        }