public static int OpenCodeView(CodeUnit unit, bool focus = true) { int handle = -1; // Get the panel if it is already open MainPanel panel = GetCodeView(unit) as MainPanel; if (panel != null) { handle = codeViews[panel]; } App.MainWindow.InvokeMethod((Action)delegate { // Create a new panel if not already open if (handle == -1) { // Create panel var newPanel = new MainPanel() { Title = unit.Name, Content = new UnitCodeView(unit), IsOpen = true }; // De-register view on close newPanel.Closed += (sender) => codeViews.Remove((MainPanel)sender); // Add panel handle = App.MainWindow.AddMainPanel(newPanel, new PanelLocation()); codeViews.Add(newPanel, handle); } if (focus) App.MainWindow.FocusMainPanel(handle); }); return handle; }
public static int OpenCodeView(string sourceFilepath, bool focus = true) { int handle = -1; // Get a valid path in case it's Cygwin sourceFilepath = Utils.GetPlatformPath(sourceFilepath); // Get the panel if it is already open MainPanel panel = GetCodeView(sourceFilepath) as MainPanel; if (panel != null) { handle = codeViews[panel]; } App.MainWindow.InvokeMethod((Action)delegate { // Create a new panel if not already open if (handle == -1) { // Create panel var newPanel = new MainPanel() { Title = System.IO.Path.GetFileName(sourceFilepath), Content = new FileCodeView(sourceFilepath), IsOpen = true }; // De-register view on close newPanel.Closed += (sender) => codeViews.Remove((MainPanel)sender); // Add panel handle = App.MainWindow.AddMainPanel(newPanel, new PanelLocation(PanelSide.Right)); codeViews.Add(newPanel, handle); } if (focus) App.MainWindow.FocusMainPanel(handle); }); return handle; }
internal void RemoveMainPanel(MainPanel panel) { // Get the panel's ID var pairs = this.panels.Where((pair) => pair.Value == panel); if (pairs.Count() == 0) { return; } else if (pairs.Count() != 1) { throw new Exception("A MainPanel has been registered more than once with different IDs"); } else this.RemoveMainPanel(pairs.First().Key); }