예제 #1
0
 public void Test_DeleteNotEmptyAt0()
 {
     ICSharpCode.TextEditor.TextEditorControl textEditorControl = new ICSharpCode.TextEditor.TextEditorControl();
     textEditorControl.Text = "test content";
     textEditorTextContext = new TextEditorTextContext(textEditorControl);
     DeleteOperation delete = new DeleteOperation(0);
     textEditorTextContext.Delete(null, delete);
     Assert.AreEqual("est content", textEditorTextContext.Data, "Inconsistent state after deletion!");
 }
예제 #2
0
 public void Test_SetSelectionNotEmptyAtSame()
 {
     ICSharpCode.TextEditor.TextEditorControl textEditorControl = new ICSharpCode.TextEditor.TextEditorControl();
     textEditorControl.Text = "selection";
     textEditorTextContext = new TextEditorTextContext(textEditorControl);
     Assert.AreEqual(0, textEditorTextContext.SelectionStart, "Initial SelectionStart not 0!");
     Assert.AreEqual(0, textEditorTextContext.SelectionEnd, "Initial SelectionEnd not 0!");
     textEditorTextContext.SetSelection(2, 2);
     Assert.AreEqual(2, textEditorTextContext.SelectionStart, "SelectionStart not 2!");
     Assert.AreEqual(2, textEditorTextContext.SelectionEnd, "SelectionEnd not 2!");
     Assert.AreEqual("", textEditorTextContext.SelectedText, "SelectedText not ''");
 }
예제 #3
0
        public void Initialize()
        {
            ICSharpCode.TextEditor.TextEditorControl textEditorControl = new ICSharpCode.TextEditor.TextEditorControl();

            textEditorTextContext = new TextEditorTextContext(textEditorControl);
        }
예제 #4
0
 public void Test_SetSelectionNotEmptyAt1And5()
 {
     ICSharpCode.TextEditor.TextEditorControl textEditorControl = new ICSharpCode.TextEditor.TextEditorControl();
     textEditorControl.Text = "selection";
     textEditorTextContext = new TextEditorTextContext(textEditorControl);
     Assert.AreEqual(0, textEditorTextContext.SelectionStart, "Initial SelectionStart not 0!");
     Assert.AreEqual(0, textEditorTextContext.SelectionEnd, "Initial SelectionEnd not 0!");
     textEditorTextContext.SetSelection(1, 5);
     Assert.AreEqual(1, textEditorTextContext.SelectionStart, "SelectionStart not 1!");
     Assert.AreEqual(5, textEditorTextContext.SelectionEnd, "SelectionEnd not 5!");
     Assert.AreEqual("elec", textEditorTextContext.SelectedText, "SelectedText not elec");
 }
예제 #5
0
 public void Test_SetRemoteSelectionNotEmpty()
 {
     ICSharpCode.TextEditor.TextEditorControl textEditorControl = new ICSharpCode.TextEditor.TextEditorControl();
     textEditorControl.Text = "remote";
     textEditorTextContext = new TextEditorTextContext(textEditorControl);
     Assert.AreEqual("remote", textEditorTextContext.Data, "Initial Data is not equal to argument string!");
     Assert.AreEqual(0, textEditorTextContext.SelectionStart, "Initial SelectionStart not 0!");
     Assert.AreEqual(0, textEditorTextContext.SelectionEnd, "Initial SelectionEnd not 0!");
     Assert.AreEqual("", textEditorTextContext.SelectedText, "Initial SelectedText not empty!");
     textEditorTextContext.SetRemoteSelection(null, 2, 4);
     Assert.AreEqual("remote", textEditorTextContext.Data, "Initial Data is not empty after Refresh!");
     Assert.AreEqual(0, textEditorTextContext.SelectionStart, "SelectionStart not 0 after Refresh!");
     Assert.AreEqual(0, textEditorTextContext.SelectionEnd, "SelectionEnd not 0 after Refresh!");
     Assert.AreEqual("", textEditorTextContext.SelectedText, "Initial SelectedText not empty after Refresh!");
 }
예제 #6
0
 public void Test_RefreshNotEmptyAndSelected()
 {
     ICSharpCode.TextEditor.TextEditorControl textEditorControl = new ICSharpCode.TextEditor.TextEditorControl();
     textEditorControl.Text = "refresh";
     textEditorTextContext = new TextEditorTextContext(textEditorControl);
     textEditorTextContext.SetSelection(1,3);
     Assert.AreEqual("refresh", textEditorTextContext.Data, "Initial Data is not equal to argument string!");
     Assert.AreEqual(1, textEditorTextContext.SelectionStart, "SelectionStart not 1!");
     Assert.AreEqual(3, textEditorTextContext.SelectionEnd, "SelectionEnd not 3!");
     Assert.AreEqual("ef", textEditorTextContext.SelectedText, "Initial SelectedText not empty!");
     textEditorTextContext.Refresh();
     Assert.AreEqual("refresh", textEditorTextContext.Data, "Initial Data is not empty after Refresh!");
     Assert.AreEqual(1, textEditorTextContext.SelectionStart, "SelectionStart not 1 after Refresh!");
     Assert.AreEqual(3, textEditorTextContext.SelectionEnd, "SelectionEnd not 3 after Refresh!");
     Assert.AreEqual("ef", textEditorTextContext.SelectedText, "Initial SelectedText not empty after Refresh!");
 }
예제 #7
0
 public void Test_InitNotEmpty()
 {
     ICSharpCode.TextEditor.TextEditorControl textEditorControl = new ICSharpCode.TextEditor.TextEditorControl();
     textEditorControl.Text = "test content";
     textEditorTextContext = new TextEditorTextContext(textEditorControl);
     Assert.AreEqual("test content", textEditorTextContext.Data, "Initial Data is not equal to argument string!");
 }
예제 #8
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";
        }