private void RefreshButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            AllModulesViewModel viewModel = this.DataContext as AllModulesViewModel;

            if (viewModel == null)
            {
                return;
            }

            viewModel.OnRefresh();
        }
Example #2
0
        /// <summary>
        /// Compare two ModuleViewModel target and source.
        /// </summary>
        /// <param name="source">The source ModuleViewModel.</param>
        /// <param name="target">The target ModuleViewModel.</param>
        /// <returns>Compare result.</returns>
        private int Compare(ModuleViewModel source, ModuleViewModel target)
        {
            if (AllModulesViewModel.IsAll(source.Name) && !AllModulesViewModel.IsAll(target.Name))
            {
                return(-1);
            }

            if (!AllModulesViewModel.IsAll(source.Name) && AllModulesViewModel.IsAll(target.Name))
            {
                return(1);
            }

            return(string.Compare(source.Name, target.Name, StringComparison.OrdinalIgnoreCase));
        }
        /// <summary>
        /// Implements ZoomOut.
        /// </summary>
        /// <param name="sender">.</param>
        /// <param name="e">.</param>
        private void ZoomEventHandlerMinus(object sender, ExecutedRoutedEventArgs e)
        {
            AllModulesViewModel viewModel = this.DataContext as AllModulesViewModel;

            if (viewModel == null)
            {
                return;
            }

            if (this.zoomLevel >= ZOOM_MIN)
            {
                // ViewModel applies ZoomLevel after dividing it by 100, So multiply it by 100 and then later reset to normal by dividing it for next zoom
                this.zoomLevel      = (this.zoomLevel - ZOOM_INCREMENT) * 100;
                viewModel.ZoomLevel = this.zoomLevel;
                this.zoomLevel     /= 100;
            }
        }
Example #4
0
        private void ShowAllModulesWindow(PSCmdlet cmdlet, Dictionary<string, ShowCommandModuleInfo> importedModules, IEnumerable<ShowCommandCommandInfo> commands, bool noCommonParameter, double windowWidth, double windowHeight, bool passThrough)
        {
            this.methodThatReturnsDialog = new DispatcherOperationCallback(delegate(object ignored)
            {
                Diagnostics.Assert(commands.GetEnumerator().MoveNext(), "there is always at least one command");

                ShowAllModulesWindow allModulesWindow = new ShowAllModulesWindow();
                this.allModulesViewModel = new AllModulesViewModel(importedModules, commands, noCommonParameter);

                this.SetupButtonEvents(allModulesWindow.Run, allModulesWindow.Copy, allModulesWindow.Cancel, passThrough);
                this.SetupWindow(allModulesWindow);
                this.SetupViewModel();
                CommonHelper.SetStartingPositionAndSize(
                    allModulesWindow,
                    ShowCommandSettings.Default.ShowCommandsTop,
                    ShowCommandSettings.Default.ShowCommandsLeft,
                    windowWidth != 0.0 && windowWidth > allModulesWindow.MinWidth ? windowWidth : ShowCommandSettings.Default.ShowCommandsWidth,
                    windowHeight != 0.0 && windowHeight > allModulesWindow.MinHeight ? windowHeight : ShowCommandSettings.Default.ShowCommandsHeight,
                    allModulesWindow.Width,
                    allModulesWindow.Height,
                    ShowCommandSettings.Default.ShowCommandsWindowMaximized);

                return allModulesWindow;
            });

            this.CallShowDialog(cmdlet);
        }
Example #5
0
        /// <summary>
        /// Called after a module in <paramref name="oldViewModel"/> is imported to refresh the view model.
        /// Gets a new AllModulesViewModel populated with <paramref name="importedModules"/> and <paramref name="commands"/>.
        /// The <paramref name="oldViewModel"/> is used to cleanup event listening in the old view model and to copy NoCommonParameters.
        /// The new ViewModel will have the command selected according to <paramref name="selectedModuleNeedingImportModule"/>, 
        /// <paramref name="parentModuleNeedingImportModule"/> and <paramref name="commandNeedingImportModule"/>.
        /// </summary>
        /// <param name="oldViewModel">the viewModel before the module was imported</param>
        /// <param name="importedModules">the list of imported modules</param>
        /// <param name="commands">the list of commands</param>
        /// <param name="selectedModuleNeedingImportModule">the name of the module that was selected in <paramref name="oldViewModel"/></param>
        /// <param name="parentModuleNeedingImportModule">the name of the module that was imported</param>
        /// <param name="commandNeedingImportModule">the name of the command that was selected in <paramref name="oldViewModel"/></param>
        /// <returns>The new ViewModel based on <paramref name="importedModules"/> and <paramref name="commands"/>.</returns>
        internal static AllModulesViewModel GetNewAllModulesViewModel(AllModulesViewModel oldViewModel, Dictionary<string, ShowCommandModuleInfo> importedModules, IEnumerable<ShowCommandCommandInfo> commands, string selectedModuleNeedingImportModule, string parentModuleNeedingImportModule, string commandNeedingImportModule)
        {
            string oldFilter = null;

            if (oldViewModel.SelectedModule != null)
            {
                // this will allow the old view model to stop listening for events before we 
                // replace it with a new view model
                oldViewModel.SelectedModule.SelectedCommand = null;
                oldViewModel.SelectedModule = null;
                oldFilter = oldViewModel.CommandNameFilter;
            }

            AllModulesViewModel returnValue = new AllModulesViewModel(importedModules, commands, oldViewModel.NoCommonParameter);
            if (!String.IsNullOrEmpty(oldFilter))
            {
                returnValue.CommandNameFilter = oldFilter;
            }

            if (selectedModuleNeedingImportModule == null || parentModuleNeedingImportModule == null)
            {
                return returnValue;
            }

            ModuleViewModel moduleToSelect = returnValue.Modules.Find(
                new Predicate<ModuleViewModel>(delegate(ModuleViewModel module)
                {
                    return module.Name.Equals(selectedModuleNeedingImportModule, StringComparison.OrdinalIgnoreCase) ? true : false;
                }));

            if (moduleToSelect == null)
            {
                return returnValue;
            }
            
            returnValue.SelectedModule = moduleToSelect;

            CommandViewModel commandToSelect = moduleToSelect.Commands.Find(
                new Predicate<CommandViewModel>(delegate(CommandViewModel command)
                {
                    return command.ModuleName.Equals(parentModuleNeedingImportModule, StringComparison.OrdinalIgnoreCase) &&
                        command.Name.Equals(commandNeedingImportModule, StringComparison.OrdinalIgnoreCase) ? true : false;
                }));

            if (commandToSelect == null)
            {
                return returnValue;
            }

            moduleToSelect.SelectedCommand = commandToSelect;
            return returnValue;
        }
Example #6
0
 private void ImportModuleDone(Dictionary<string, ShowCommandModuleInfo> importedModules, IEnumerable<ShowCommandCommandInfo> commands)
 {
     this.allModulesViewModel.WaitMessageDisplayed = false;
     if (this.window != null)
     {
         this.window.Dispatcher.Invoke(
             new SendOrPostCallback(
                 delegate(object ignored)
                 {
                     this.allModulesViewModel = ShowCommandHelper.GetNewAllModulesViewModel(
                         this.allModulesViewModel,
                         importedModules,
                         commands,
                         this.selectedModuleNeedingImportModule,
                         this.parentModuleNeedingImportModule,
                         this.commandNeedingImportModule);
                     this.SetupViewModel();
                 }),
                 String.Empty);
     }
 }
 /// <summary>
 /// Sets the AllModulesViewModel containing this.
 /// </summary>
 /// <param name="parentAllModules">The AllModulesViewModel containing this.</param>
 internal void SetAllModules(AllModulesViewModel parentAllModules)
 {
     this.allModules = parentAllModules;
 }
Example #8
0
 /// <summary>
 /// Sets the AllModulesViewModel containing this
 /// </summary>
 /// <param name="parentAllModules">the AllModulesViewModel containing this</param>
 internal void SetAllModules(AllModulesViewModel parentAllModules)
 {
     this.allModules = parentAllModules;
 }