예제 #1
0
        private void OpenInNewTab()
        {
            var openDialog = CreateOpenLSLDialog();


            var showDialog = openDialog.ShowDialog();

            if (showDialog == null || !showDialog.Value)
            {
                return;
            }
            var alreadyOpen = EditorTabs.FirstOrDefault(x => x.FilePath == openDialog.FileName);

            if (alreadyOpen != null)
            {
                TabControl.SelectedIndex = EditorTabs.IndexOf(alreadyOpen);
                return;
            }


            var tab = CreateEditorTab();

            if (!tab.OpenFileInteractive(openDialog.FileName))
            {
                return;
            }

            EditorTabs.Add(tab);
            TabControl.SelectedIndex = EditorTabs.Count - 1;
        }
예제 #2
0
        private NamedPipeServerStream CreateOpenTabPipeServer(string pipeName)
        {
            var ps = new PipeSecurity();

            ps.AddAccessRule(new PipeAccessRule("Users", PipeAccessRights.ReadWrite | PipeAccessRights.CreateNewInstance,
                                                AccessControlType.Allow));
            ps.AddAccessRule(new PipeAccessRule("SYSTEM", PipeAccessRights.FullControl, AccessControlType.Allow));

            var pipeClientConnection = new NamedPipeServerStream(pipeName, PipeDirection.In, 5,
                                                                 PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 1024, 1024, ps);


            pipeClientConnection.BeginWaitForConnection(asyncResult =>
            {
                using (var conn = (NamedPipeServerStream)asyncResult.AsyncState)
                {
                    conn.EndWaitForConnection(asyncResult);

                    var newServer = CreateOpenTabPipeServer(pipeName);

                    var streamReader = new StreamReader(conn);

                    while (true)
                    {
                        string file = streamReader.ReadLine();

                        if (file == ":KILL:")
                        {
                            if (pipeClientConnection.IsConnected)
                            {
                                pipeClientConnection.Disconnect();
                            }

                            pipeClientConnection.Close();
                            pipeClientConnection.Dispose();

                            if (newServer.IsConnected)
                            {
                                newServer.Disconnect();
                            }

                            newServer.Close();
                            newServer.Dispose();

                            Dispatcher.Invoke(Close);
                        }
                        if (file == ":EOF:")
                        {
                            break;
                        }

                        Dispatcher.Invoke(() =>
                        {
                            var alreadyOpen = EditorTabs.FirstOrDefault(x => x.FilePath == file);
                            if (alreadyOpen != null)
                            {
                                TabControl.SelectedIndex = EditorTabs.IndexOf(alreadyOpen);
                                return;
                            }

                            var tab = CreateEditorTab();
                            if (!tab.OpenFileInteractive(file))
                            {
                                return;
                            }
                            EditorTabs.Add(tab);
                            TabControl.SelectedIndex = EditorTabs.Count - 1;
                        });
                    }
                }
            }, pipeClientConnection);

            return(pipeClientConnection);
        }
예제 #3
0
        private void TabOnDrop(object sender, DragEventArgs e)
        {
            var textBlock = e.Source as TextBlock;

            if (textBlock == null)
            {
                return;
            }

            var stackPanel = textBlock.Parent as StackPanel;

            if (stackPanel == null)
            {
                return;
            }

            var contentPresenter = stackPanel.TemplatedParent as ContentPresenter;

            if (contentPresenter == null)
            {
                return;
            }


            var tabItemTarget = contentPresenter.Content as EditorTab;

            if (tabItemTarget == null)
            {
                return;
            }

            var tabItemSourceContentPresenter = e.Data.GetData(typeof(ContentPresenter)) as ContentPresenter;


            if (tabItemSourceContentPresenter == null)
            {
                return;
            }

            var tabItemSource = tabItemSourceContentPresenter.Content as EditorTab;

            if (tabItemSource == null)
            {
                return;
            }


            if (tabItemTarget.Equals(tabItemSource))
            {
                return;
            }


            _droppingTabAfterDragging = true;

            var sourceIndex = EditorTabs.IndexOf(tabItemSource);
            var targetIndex = EditorTabs.IndexOf(tabItemTarget);

            EditorTabs.Remove(tabItemSource);
            EditorTabs.Insert(targetIndex, tabItemSource);

            EditorTabs.Remove(tabItemTarget);
            EditorTabs.Insert(sourceIndex, tabItemTarget);

            TabControl.SelectedIndex = targetIndex;

            _droppingTabAfterDragging = false;
        }