Exemple #1
0
        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 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
        }
Exemple #3
0
        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();
            }
        }
Exemple #4
0
        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;
            }
        }