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; }
private void NewFile_OnClick(object sender, RoutedEventArgs e) { EditorTabs.Add(CreateEditorTab()); TabControl.SelectedIndex = (EditorTabs.Count - 1); }
private void Initialize(bool newInstance, string[] args) { ShowEndOfLine = AppSettings.Settings.ShowEndOfLine; ShowSpaces = AppSettings.Settings.ShowSpaces; ShowTabs = AppSettings.Settings.ShowTabs; var entryAssembly = Assembly.GetEntryAssembly(); Title = "LSLCCEditor v" + entryAssembly.GetName().Version; var assembly = entryAssembly.Location; var appDirectory = Path.GetDirectoryName(assembly); _libraryDataProvider = new LSLXmlLibraryDataProvider(new[] { "lsl" }); try { _libraryDataProvider.FillFromXmlDirectory(Path.Combine(appDirectory, "library_data")); } catch (LSLLibraryDataXmlSyntaxException err) { MessageBox.Show(this, "There is a syntax error in one of your XML library data files and the application must close." + LSLFormatTools.CreateNewLinesString(2) + err.Message, "Library Data Syntax Error", MessageBoxButton.OK, MessageBoxImage.Error); Application.Current.Shutdown(); } _codeValidatorStrategies = new LSLCodeValidatorStrategies { ExpressionValidator = new LSLDefaultExpressionValidator(), StringLiteralPreProcessor = new LSLDefaultStringPreProcessor(), SyntaxErrorListener = new WindowSyntaxErrorListener(this), SyntaxWarningListener = new WindowSyntaxWarningListener(this), LibraryDataProvider = _libraryDataProvider }; foreach (var dataMenuItem in _libraryDataProvider.SubsetDescriptions.Select(subset => new MenuItem { StaysOpenOnClick = true, IsCheckable = true, Header = subset.Value.FriendlyName, Tag = subset.Value.Subset, ToolTip = new ToolTip { Content = new TextBlock { Text = subset.Value.Description } } })) { dataMenuItem.Checked += DataMenuItemOnChecked; dataMenuItem.Unchecked += DataMenuItemOnUnChecked; TabLibraryDataMenu.Items.Add(dataMenuItem); } FindDialogManager = new FindReplaceMgr { OwnerWindow = this, InterfaceConverter = new IEditorConverter(), ShowSearchIn = false }; if (args.Length > 0) { foreach (string arg in args) { var tab = CreateEditorTab(); if (tab.OpenFileInteractive(arg)) { EditorTabs.Add(tab); } } } else { EditorTabs.Add(CreateEditorTab()); } if (!newInstance) { StartOpenTabPipeServer(); } _selectingStartupTabDuringWindowLoad = true; TabControl.SelectedIndex = 0; var initialTab = (EditorTab)TabControl.SelectedItem; initialTab.IsSelected = true; SetLibraryMenuFromTab(initialTab); FindDialogManager.CurrentEditor = initialTab.Content.EditControl.Editor; initialTab.Content.EditControl.Editor.TextChanged += Editor_OnTextChanged; EditRedoMenuItem.IsEnabled = initialTab.Content.EditControl.Editor.CanRedo; EditUndoMenuItem.IsEnabled = initialTab.Content.EditControl.Editor.CanUndo; _selectingStartupTabDuringWindowLoad = false; }
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); }