Пример #1
0
        async void LoadModuleFromFile(Object obj)
        {
            // method call from ICommand is allowed only when module selector is active
            // so skip checks.
            ClosableModuleItem previousTab = _mwvm.SelectedTab;
            OpenFileDialog     dlg         = new OpenFileDialog {
                DefaultExt = ".psm1",
                Filter     = "PowerShell module files (*.psm1, *.psd1)|*.psm1;*.psd1"
            };
            Boolean?result = dlg.ShowDialog();

            if (result != true)
            {
                return;
            }
            UIManager.ShowBusy(previousTab, Strings.InfoModuleLoading);
            try {
                ModuleObject module = await PowerShellProcessor.GetModuleFromFile(dlg.FileName);

                if (module != null && !_mwvm.Modules.Contains(module))
                {
                    _mwvm.Modules.Add(module);
                    module.ModulePath = dlg.FileName;
                }
            } catch (Exception e) {
                Utils.MsgBox("Import error", e.Message);
                previousTab.ErrorInfo = e.Message;
            }
            UIManager.ShowModuleList(previousTab);
        }
Пример #2
0
 public EditorVM(ClosableModuleItem parent)
 {
     ParamContext       = new ParamVM();
     RelatedLinkContext = new RelatedLinkVM();
     ExampleContext     = new ExampleVM();
     OutputContext      = new OutputVM(parent);
 }
Пример #3
0
        void AddTab(Object obj)
        {
            ClosableModuleItem tab = UIManager.GenerateTab();

            _mwvm.Tabs.Add(tab);
            tab.Focus();
        }
Пример #4
0
        async void LoadCmdletsForProject(ClosableModuleItem tab)
        {
            String cmd = Utils.GetCommandTypes();

            if (String.IsNullOrEmpty(cmd))
            {
                Utils.MsgBox("Error", Strings.E_EmptyCmds);
                return;
            }
            if (FileProcessor.FindModule(tab.Module.Name))
            {
                tab.Module.ModulePath = null;
            }
            tab.ErrorInfo = null;
            tab.EditorContext.CurrentCmdlet = null;
            List <CmdletObject> nativeCmdlets = new List <CmdletObject>();

            try {
                IEnumerable <CmdletObject> data = await PowerShellProcessor.EnumCmdlets(tab.Module, cmd, false);

                nativeCmdlets.AddRange(data);
                PowerShellProcessor.CompareCmdlets(tab.Module, nativeCmdlets);
            } catch (Exception e) {
                String message = e.Message + "\n\nYou still can use the module project in offline mode";
                message += "\nHowever certain functionality may not be available.";
                Utils.MsgBox("Error while loading cmdlets", message);
                tab.ErrorInfo = e.Message;
                foreach (CmdletObject cmdlet in tab.Module.Cmdlets)
                {
                    cmdlet.GeneralHelp.Status = ItemStatus.Missing;
                }
            } finally {
                UIManager.ShowEditor(tab);
            }
        }
Пример #5
0
        public async void LoadCmdlets(Object helpPath, Boolean importCBH)
        {
            ClosableModuleItem previousTab     = _mwvm.SelectedTab;
            UIElement          previousElement = ((Grid)previousTab.Content).Children[0];
            String             cmd             = Utils.GetCommandTypes();

            if (String.IsNullOrEmpty(cmd))
            {
                Utils.MsgBox("Error", Strings.E_EmptyCmds);
                return;
            }
            UIManager.ShowBusy(previousTab, Strings.InfoCmdletsLoading);
            try {
                IEnumerable <CmdletObject> data = await PowerShellProcessor.EnumCmdlets(_mwvm.SelectedModule, cmd, importCBH);

                _mwvm.SelectedModule.Cmdlets.Clear();
                foreach (CmdletObject item in data)
                {
                    _mwvm.SelectedModule.Cmdlets.Add(item);
                }
                if (helpPath != null)
                {
                    _mwvm.SelectedModule.ImportedFromHelp = true;
                    XmlProcessor.ImportFromXml((String)helpPath, _mwvm.SelectedModule);
                }
                previousTab.Module   = _mwvm.SelectedModule;
                _mwvm.SelectedModule = null;
                UIManager.ShowEditor(previousTab);
            } catch (Exception e) {
                Utils.MsgBox("Error while loading cmdlets", e.Message);
                _mwvm.SelectedTab.ErrorInfo = e.Message;
                UIManager.RestoreControl(previousTab, previousElement);
            }
        }
Пример #6
0
        public void OpenProject(Object obj)
        {
            String fileName;

            if (obj == null)
            {
                OpenFileDialog dlg = new OpenFileDialog {
                    DefaultExt = ".pshproj",
                    Filter     = "PowerShell Help Project file (.pshproj)|*.pshproj"
                };
                Boolean?result = dlg.ShowDialog();
                if (result != true)
                {
                    return;
                }
                fileName = dlg.FileName;
            }
            else
            {
                fileName = (String)obj;
            }
            AddTab(null);
            ClosableModuleItem tab = _mwvm.SelectedTab;

            UIManager.ShowBusy(tab, Strings.InfoCmdletsLoading);
            try {
                ModuleObject module = FileProcessor.ReadProjectFile(fileName);
                Debug.Assert(tab != null, "tab != null");
                tab.Module = module;
                LoadCmdletsForProject(tab);
            } catch (Exception e) {
                Utils.MsgBox("Read error", e.Message);
            }
        }
 public EditorControl(ClosableModuleItem tab)
 {
     if (tab != null)
     {
         DataContext = tab;
     }
     InitializeComponent();
 }
Пример #8
0
        public static void ShowEditor(ClosableModuleItem tab)
        {
            MainWindowVM mwvm = (MainWindowVM)Application.Current.MainWindow.DataContext;

            mwvm.SelectedModule = null;
            ((Grid)tab.Content).Children.Clear();
            ((Grid)tab.Content).Children.Add(new EditorControl(tab));
        }
Пример #9
0
 public OutputVM(ClosableModuleItem parent)
 {
     BusyControlVisible = Visibility.Collapsed;
     RtbVisible         = Visibility.Collapsed;
     WebBrowserVisible  = Visibility.Collapsed;
     Tab = parent;
     GenerateOutputCommand = new RelayCommand(GenerateOutput, CanGenerateView);
 }
Пример #10
0
        public static ClosableModuleItem GenerateTab()
        {
            ClosableModuleItem cti = new ClosableModuleItem {
                Header     = "untitled",
                IsSaved    = true,
                IsClosable = true,
            };
            Panel content = new Grid();

            content.Children.Add(new StartUserControl());
            cti.Content       = content;
            cti.EditorContext = new EditorVM(cti);
            return(cti);
        }
Пример #11
0
        void initialize()
        {
            Panel content          = new Grid();
            ClosableModuleItem cti = new ClosableModuleItem {
                Header     = "untitled",
                IsSaved    = true,
                IsClosable = true,
                Content    = content
            };

            content.Children.Add(new StartUserControl());
            cti.Content       = content;
            cti.EditorContext = new EditorVM(cti);
            Tabs.Add(cti);
            SelectedTab = cti;
        }
Пример #12
0
        // toolbar/menu commands
        void NewProject(Object obj)
        {
            if (!testSaved(_mwvm.SelectedTab))
            {
                return;
            }
            if (_mwvm.SelectedTab == null)
            {
                AddTab(null);
            }
            ClosableModuleItem tab = _mwvm.SelectedTab;

            Debug.Assert(tab != null, "tab != null");
            tab.Module = null;
            LoadModules(true);
            tab.Header = "untitled";
        }
Пример #13
0
        // utility
        Boolean testSaved(ClosableModuleItem tab)
        {
            if (tab == null || tab.IsSaved || tab.Module == null)
            {
                return(true);
            }
            tab.Focus();
            MessageBoxResult mbxResult = Utils.MsgBox("PS Cmdlet Help Editor", Strings.InfoSaveRequired, MessageBoxImage.Warning, MessageBoxButton.YesNoCancel);

            switch (mbxResult)
            {
            case MessageBoxResult.Yes: SaveProjectFile(null); return(true);

            case MessageBoxResult.No: return(true);

            case MessageBoxResult.Cancel: return(false);
            }
            return(true);
        }
Пример #14
0
        public static void SaveProjectFile(ClosableModuleItem tab, String path)
        {
            FileStream fs = new FileStream(path, FileMode.Create);

            tab.Module.ProjectPath = path;
            Double oldVersion = tab.Module.FormatVersion;

            if (!tab.Module.IsOffline)
            {
                foreach (CmdletObject cmdlet in tab.Module.Cmdlets.ToArray())
                {
                    if (cmdlet.GeneralHelp.Status == ItemStatus.Missing)
                    {
                        tab.Module.Cmdlets.Remove(cmdlet);
                    }
                    else
                    {
                        foreach (ParameterDescription parameter in cmdlet.Parameters.ToArray().Where(x => x.Status == ItemStatus.Missing))
                        {
                            cmdlet.Parameters.Remove(parameter);
                        }
                    }
                }
            }
            tab.Module.FormatVersion = Utils.CurrentFormatVersion;
            XmlSerializer serializer = new XmlSerializer(typeof(ModuleObject));

            try {
                serializer.Serialize(fs, tab.Module);
                tab.Module.ProjectPath = path;
                tab.IsSaved            = true;
            } catch {
                tab.Module.FormatVersion = oldVersion;
                throw;
            } finally {
                fs.Close();
            }
        }
Пример #15
0
        async void LoadModules(Object obj)
        {
            // method call from ICommand is allowed only when module selector is active
            // so skip checks.
            ClosableModuleItem previousTab = _mwvm.SelectedTab;

            UIManager.ShowBusy(previousTab, Strings.InfoModuleListLoading);
            _mwvm.Modules.Clear();
            try {
                IEnumerable <ModuleObject> data = obj == null
                    ? await PowerShellProcessor.EnumModules(true)
                    : await PowerShellProcessor.EnumModules(false);

                foreach (ModuleObject item in data)
                {
                    _mwvm.Modules.Add(item);
                }
            } catch (Exception e) {
                Utils.MsgBox("Error", e.Message);
                previousTab.ErrorInfo = e.Message;
            }
            UIManager.ShowModuleList(previousTab);
        }