public void OnImport() { //get ISE window Func <MainWindow> fnc = delegate() { return(Application.Current.Windows.Cast <MainWindow>().FirstOrDefault(wnd => wnd is MainWindow) as MainWindow); }; window = Application.Current.Dispatcher.Invoke(fnc) as MainWindow; tabCollection = window.GetPowerShellTabCollection(); appFileManager = new AppFileManager(); appFileManager.Add(breakPointsFileName); appFileManager.Add(openFilesFileName); appFileManager.Add(debugLogfileName); solutionManager = new SolutionManager(window, appFileManager.Get(openFilesFileName).FullName); addonManager = new AddOnManager(window, tabCollection); SetupMenu(); SetupToolbar(); //add handler to Event StateChanged var executionStateChangedEvent = tabCollection.SelectedPowerShellTab.GetType().GetEvent("ExecutionStateChanged", BindingFlags.NonPublic | BindingFlags.Instance); var handler = new EventHandler <PSInvocationStateChangedEventArgs>(StateChanged); executionStateChangedEvent.GetAddMethod(true).Invoke(tabCollection.SelectedPowerShellTab, new[] { handler }); tabCollection.SelectedPowerShellTab.PropertyChanged += SelectedPowerShellTab_PropertyChanged_ImportBreakpoints; //executed once tabCollection.SelectedPowerShellTab.PropertyChanged += solutionManager.SelectedPowerShellTab_PropertyChanged_OpenFiles; //executed once AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit_ExportBreakpoints; //executed once AppDomain.CurrentDomain.ProcessExit += solutionManager.CurrentDomain_ProcessExit_SaveFiles; //executed once tabCollection.SelectedPowerShellTab.PropertyChanged += SelectedPowerShellTab_PropertyChanged; }
public static PowerShellTabCollection GetPowerShellTabCollection(this MainWindow window) { FieldInfo tabControlField = window.GetType().GetField("runspaceTabControl", BindingFlags.Instance | BindingFlags.NonPublic); RunspaceTabControl tabControl = (RunspaceTabControl)tabControlField.GetValue(window); PowerShellTabCollection tabCollection = tabControl.ItemsSource as PowerShellTabCollection; return(tabCollection); }
public AddOnManager(Window window, PowerShellTabCollection tabCollection) { this.window = window; this.tabCollection = tabCollection; FunctionExplorerParameter = new AddOnParameter(); RegisterCommands(); }
public SolutionManager(MainWindow window, string filesXmlFilePath) { this.window = window; tabCollection = window.GetPowerShellTabCollection(); this.openFilesFileName = filesXmlFilePath; SolutionParameter = new CommandParameter(); RegisterCommands(); }
public FunctionExplorer() { InitializeComponent(); var iseWindow = Application.Current.MainWindow; FieldInfo tabControlField = iseWindow.GetType().GetField("runspaceTabControl", BindingFlags.Instance | BindingFlags.NonPublic); RunspaceTabControl tabControl = (RunspaceTabControl)tabControlField.GetValue(iseWindow); PowerShellTabCollection tabCollection = tabControl.ItemsSource as PowerShellTabCollection; ISEFile file = tabCollection.SelectedPowerShellTab.Files.SelectedFile; ISEEditor editor = file.Editor; var mainMenuField = iseWindow.GetType().GetField("mainMenu", BindingFlags.Instance | BindingFlags.NonPublic); var mainMenu = (Menu)mainMenuField.GetValue(iseWindow); var newItem = new MenuItem(); newItem.Header = "Open Solution"; //((MenuItem)mainMenu.Items[0]).Items.Add(newItem); ((MenuItem)mainMenu.Items[0]).Items.Insert(2, newItem); var x = hostObject; fileManager.Add(functionsFileName); fileManager.Add(openFilesFileName); fileManager.Add(breakPointsFileName); fileManager.Add(debugLogfileName); AppDomain.CurrentDomain.DomainUnload += CurrentDomain_ProcessExit; AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException; try { sw = new System.IO.StreamWriter(fileManager.Get(debugLogfileName).FullName, true); } catch { } statusBarMessage = (System.Windows.Controls.Primitives.StatusBarItem) this.stbBottom.Items[1]; statusBarContent = (System.Windows.Controls.Primitives.StatusBarItem) this.stbBottom.Items[0]; timer = new DispatcherTimer(); timer.Tick += new EventHandler(timer_Tick); updateTimer = new DispatcherTimer(); updateTimer.Tick += new EventHandler(updateTimer_Tick); txtUpdateInterval_LostFocus(null, null); //start the timer with the value set in the form }
public void SaveSolution_Executed(object sender, ExecutedRoutedEventArgs e) { if (module == null) { return; } FieldInfo tabControlField = window.GetType().GetField("runspaceTabControl", BindingFlags.Instance | BindingFlags.NonPublic); RunspaceTabControl tabControl = (RunspaceTabControl)tabControlField.GetValue(window); PowerShellTabCollection tabCollection = tabControl.ItemsSource as PowerShellTabCollection; foreach (var file in module.IseFileList()) { tabCollection.SelectedPowerShellTab.Files.Where(f => f.FullPath == file).FirstOrDefault().Save(); } }
public void CloseSolution_Executed(object sender, ExecutedRoutedEventArgs e) { window.Title = "Windows PowerShell ISE"; if (module == null) { return; } FieldInfo tabControlField = window.GetType().GetField("runspaceTabControl", BindingFlags.Instance | BindingFlags.NonPublic); RunspaceTabControl tabControl = (RunspaceTabControl)tabControlField.GetValue(window); PowerShellTabCollection tabCollection = tabControl.ItemsSource as PowerShellTabCollection; var solutionIseFiles = tabCollection.SelectedPowerShellTab.Files.Where(f => module.IseFileList().Contains(f.FullPath)); if (solutionIseFiles.Where(f => f.IsSaved == false).Count() > 0) { var answer = MessageBox.Show("There are unsaved files in the solution. Do you want to save them before closing?", "Save Changes?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); if (answer == MessageBoxResult.Cancel) { return; } else if (answer == MessageBoxResult.Yes) { SaveSolution_Executed(sender, e); } } foreach (var file in module.IseFileList()) { tabCollection.SelectedPowerShellTab.Files.Remove(tabCollection.SelectedPowerShellTab.Files.Where(f => f.FullPath == file).FirstOrDefault(), true); } CommandParameter parameter = e.Parameter as CommandParameter; if (parameter != null) { parameter.CanBeExecuted = false; } }