Пример #1
0
        public IMenu BuildEditorContextMenu()
        {
            var menuBuilder = new MenuBuilder(_menuBarDefinitions.ToArray(), _menuDefinitions.ToArray(), _menuItemGroupDefinitions.ToArray(), _menuItemDefinitions.ToArray(), new ExcludeMenuDefinition[0], new ExcludeMenuItemGroupDefinition[0], new ExcludeMenuItemDefinition[0]);

            var mainMenu = new Extensibility.MainMenu.ViewModels.MainMenuViewModel(menuBuilder);

            menuBuilder.BuildMenuBar(TextEditorContextMenu.EditorContextMenu, mainMenu.Model);

            return(mainMenu);
        }
Пример #2
0
        public ShellViewModel([ImportMany] IEnumerable <IExtension> extensions, [ImportMany] IEnumerable <ICodeTemplate> codeTemplates)
        {
            _languageServices            = new List <ILanguageService>();
            _projectTemplates            = new List <IProjectTemplate>();
            _debugger2s                  = new List <IDebugger>();
            _codeTemplates               = new List <ICodeTemplate>();
            _projectTypes                = new List <IProjectType>();
            _solutionTypes               = new List <ISolutionType>();
            _testFrameworks              = new List <ITestFramework>();
            _toolChains                  = new List <IToolChain>();
            _menuBarDefinitions          = new List <MenuBarDefinition>();
            _menuDefinitions             = new List <MenuDefinition>();
            _menuItemGroupDefinitions    = new List <MenuItemGroupDefinition>();
            _menuItemDefinitions         = new List <MenuItemDefinition>();
            _commandDefinitions          = new List <CommandDefinition>();
            _keyBindings                 = new List <KeyBinding>();
            _toolBarDefinitions          = new List <ToolBarDefinition>();
            _toolBarItemGroupDefinitions = new List <ToolBarItemGroupDefinition>();
            _toolBarItemDefinitions      = new List <ToolBarItemDefinition>();

            IoC.RegisterConstant(this, typeof(IShell));

            foreach (var extension in extensions)
            {
                extension.BeforeActivation();
            }

            _codeTemplates.AddRange(codeTemplates);

            CurrentPerspective = Perspective.Editor;

            StatusBar    = new StatusBarViewModel();
            DocumentTabs = new DocumentTabControlViewModel();

            Console   = IoC.Get <IConsole>();
            ErrorList = IoC.Get <IErrorList>();

            tools = new ObservableCollection <object>();

            LeftTabs        = new TabControlViewModel();
            RightTabs       = new TabControlViewModel();
            BottomTabs      = new TabControlViewModel();
            BottomRightTabs = new TabControlViewModel();
            RightBottomTabs = new TabControlViewModel();
            RightMiddleTabs = new TabControlViewModel();
            RightTopTabs    = new TabControlViewModel();
            MiddleTopTabs   = new TabControlViewModel();

            ModalDialog = new ModalDialogViewModelBase("Dialog");

            OnSolutionChanged = Observable.FromEventPattern <SolutionChangedEventArgs>(this, nameof(SolutionChanged)).Select(s => s.EventArgs.NewValue);

            _taskRunner = new WorkspaceTaskRunner();

            foreach (var extension in extensions)
            {
                extension.Activation();

                _languageServices.ConsumeExtension(extension);
                _toolChains.ConsumeExtension(extension);
                _projectTemplates.ConsumeExtension(extension);
                _debugger2s.ConsumeExtension(extension);
                _solutionTypes.ConsumeExtension(extension);
                _projectTypes.ConsumeExtension(extension);
                _testFrameworks.ConsumeExtension(extension);

                _commandDefinitions.ConsumeExtension(extension);
            }

            _menuBarDefinitions.AddRange(IoC.GetServices <MenuBarDefinition>(typeof(MenuBarDefinition)));
            _menuDefinitions.AddRange(IoC.GetServices <MenuDefinition>(typeof(MenuDefinition)));
            _menuItemGroupDefinitions.AddRange(IoC.GetServices <MenuItemGroupDefinition>(typeof(MenuItemGroupDefinition)));
            _menuItemDefinitions.AddRange(IoC.GetServices <MenuItemDefinition>(typeof(MenuItemDefinition)));

            _toolBarDefinitions.AddRange(IoC.GetServices <ToolBarDefinition>(typeof(ToolBarDefinition)));
            _toolBarItemDefinitions.AddRange(IoC.GetServices <ToolBarItemDefinition>(typeof(ToolBarItemDefinition)));
            _toolBarItemGroupDefinitions.AddRange(IoC.GetServices <ToolBarItemGroupDefinition>(typeof(ToolBarItemGroupDefinition)));

            foreach (var definition in _toolBarItemDefinitions)
            {
                definition.Activation();
            }

            foreach (var menuItemDefinition in _menuDefinitions)
            {
                menuItemDefinition.Activation();
            }

            foreach (var menuItemDefinition in _menuItemGroupDefinitions)
            {
                menuItemDefinition.Activation();
            }

            foreach (var extension in _menuItemDefinitions)
            {
                extension.Activation();
            }

            var menuBar = IoC.Get <MenuBarDefinition>("MainMenu");

            foreach (var commandDefinition in _commandDefinitions)
            {
                if (commandDefinition.Command != null && commandDefinition.Gesture != null)
                {
                    _keyBindings.Add(new KeyBinding {
                        Gesture = commandDefinition.Gesture, Command = commandDefinition.Command
                    });
                }
            }

            ToolBarDefinition = ToolBarDefinitions.MainToolBar;

            var menuBuilder = new MenuBuilder(_menuBarDefinitions.ToArray(), _menuDefinitions.ToArray(), _menuItemGroupDefinitions.ToArray(), _menuItemDefinitions.ToArray(), new ExcludeMenuDefinition[0], new ExcludeMenuItemGroupDefinition[0], new ExcludeMenuItemDefinition[0]);

            var mainMenu = new Extensibility.MainMenu.ViewModels.MainMenuViewModel(menuBuilder);

            menuBuilder.BuildMenuBar(menuBar, mainMenu.Model);

            MainMenu = mainMenu;

            foreach (var tool in extensions.OfType <ToolViewModel>())
            {
                tools.Add(tool);

                switch (tool.DefaultLocation)
                {
                case Location.Bottom:
                    BottomTabs.Tools.Add(tool);
                    break;

                case Location.BottomRight:
                    BottomRightTabs.Tools.Add(tool);
                    break;

                case Location.RightBottom:
                    RightBottomTabs.Tools.Add(tool);
                    break;

                case Location.RightMiddle:
                    RightMiddleTabs.Tools.Add(tool);
                    break;

                case Location.RightTop:
                    RightTopTabs.Tools.Add(tool);
                    break;

                case Location.MiddleTop:
                    MiddleTopTabs.Tools.Add(tool);
                    break;

                case Location.Left:
                    LeftTabs.Tools.Add(tool);
                    break;

                case Location.Right:
                    RightTabs.Tools.Add(tool);
                    break;
                }
            }

            LeftTabs.SelectedTool        = LeftTabs.Tools.FirstOrDefault();
            RightTabs.SelectedTool       = RightTabs.Tools.FirstOrDefault();
            BottomTabs.SelectedTool      = BottomTabs.Tools.FirstOrDefault();
            BottomRightTabs.SelectedTool = BottomRightTabs.Tools.FirstOrDefault();
            RightTopTabs.SelectedTool    = RightTopTabs.Tools.FirstOrDefault();
            RightMiddleTabs.SelectedTool = RightMiddleTabs.Tools.FirstOrDefault();
            RightBottomTabs.SelectedTool = RightBottomTabs.Tools.FirstOrDefault();
            MiddleTopTabs.SelectedTool   = MiddleTopTabs.Tools.FirstOrDefault();

            StatusBar.LineNumber     = 1;
            StatusBar.Column         = 1;
            StatusBar.PlatformString = Platform.OSDescription + " " + Platform.AvalonRID;

            ProcessCancellationToken = new CancellationTokenSource();

            CurrentPerspective = Perspective.Editor;

            var editorSettings = Settings.GetSettings <EditorSettings>();

            _globalZoomLevel = editorSettings.GlobalZoomLevel;

            IoC.RegisterConstant(this);

            this.WhenAnyValue(x => x.GlobalZoomLevel).Subscribe(zoomLevel =>
            {
                foreach (var document in DocumentTabs.Documents.OfType <EditorViewModel>())
                {
                    document.ZoomLevel = zoomLevel;
                }
            });

            this.WhenAnyValue(x => x.GlobalZoomLevel).Throttle(TimeSpan.FromSeconds(2)).Subscribe(zoomLevel =>
            {
                var settings = Settings.GetSettings <EditorSettings>();

                settings.GlobalZoomLevel = zoomLevel;

                Settings.SetSettings(settings);
            });

            EnableDebugModeCommand = ReactiveCommand.Create(() =>
            {
                DebugMode = !DebugMode;
            });
        }
Пример #3
0
        public ShellViewModel([ImportMany] IEnumerable <IExtension> extensions, [ImportMany] IEnumerable <ICodeTemplate> codeTemplates)
        {
            _languageServices            = new List <ILanguageService>();
            _projectTemplates            = new List <IProjectTemplate>();
            _debugger2s                  = new List <IDebugger>();
            _codeTemplates               = new List <ICodeTemplate>();
            _projectTypes                = new List <IProjectType>();
            _solutionTypes               = new List <ISolutionType>();
            _testFrameworks              = new List <ITestFramework>();
            _toolChains                  = new List <IToolChain>();
            _menuBarDefinitions          = new List <MenuBarDefinition>();
            _menuDefinitions             = new List <MenuDefinition>();
            _menuItemGroupDefinitions    = new List <MenuItemGroupDefinition>();
            _menuItemDefinitions         = new List <MenuItemDefinition>();
            _commandDefinitions          = new List <CommandDefinition>();
            _keyBindings                 = new List <KeyBinding>();
            _toolBarDefinitions          = new List <ToolBarDefinition>();
            _toolBarItemGroupDefinitions = new List <ToolBarItemGroupDefinition>();
            _toolBarItemDefinitions      = new List <ToolBarItemDefinition>();

            IoC.RegisterConstant(this, typeof(IShell));

            foreach (var extension in extensions)
            {
                extension.BeforeActivation();
            }

            _codeTemplates.AddRange(codeTemplates);

            CurrentPerspective = Perspective.Editor;

            StatusBar    = new StatusBarViewModel();
            DocumentTabs = new DocumentTabControlViewModel();

            Console   = IoC.Get <IConsole>();
            ErrorList = IoC.Get <IErrorList>();

            tools = new ObservableCollection <object>();

            LeftTabs        = new TabControlViewModel();
            RightTabs       = new TabControlViewModel();
            BottomTabs      = new TabControlViewModel();
            BottomRightTabs = new TabControlViewModel();
            RightBottomTabs = new TabControlViewModel();
            RightMiddleTabs = new TabControlViewModel();
            RightTopTabs    = new TabControlViewModel();
            MiddleTopTabs   = new TabControlViewModel();

            ModalDialog = new ModalDialogViewModelBase("Dialog");

            foreach (var extension in extensions)
            {
                extension.Activation();

                _languageServices.ConsumeExtension(extension);
                _toolChains.ConsumeExtension(extension);
                _projectTemplates.ConsumeExtension(extension);
                _debugger2s.ConsumeExtension(extension);
                _solutionTypes.ConsumeExtension(extension);
                _projectTypes.ConsumeExtension(extension);
                _testFrameworks.ConsumeExtension(extension);

                _commandDefinitions.ConsumeExtension(extension);
            }

            _menuBarDefinitions.AddRange(IoC.GetServices <MenuBarDefinition>(typeof(MenuBarDefinition)));
            _menuDefinitions.AddRange(IoC.GetServices <MenuDefinition>(typeof(MenuDefinition)));
            _menuItemGroupDefinitions.AddRange(IoC.GetServices <MenuItemGroupDefinition>(typeof(MenuItemGroupDefinition)));
            _menuItemDefinitions.AddRange(IoC.GetServices <MenuItemDefinition>(typeof(MenuItemDefinition)));

            _toolBarDefinitions.AddRange(IoC.GetServices <ToolBarDefinition>(typeof(ToolBarDefinition)));
            _toolBarItemDefinitions.AddRange(IoC.GetServices <ToolBarItemDefinition>(typeof(ToolBarItemDefinition)));
            _toolBarItemGroupDefinitions.AddRange(IoC.GetServices <ToolBarItemGroupDefinition>(typeof(ToolBarItemGroupDefinition)));

            foreach (var definition in _toolBarItemDefinitions)
            {
                definition.Activation();
            }

            foreach (var menuItemDefinition in _menuDefinitions)
            {
                menuItemDefinition.Activation();
            }

            foreach (var menuItemDefinition in _menuItemGroupDefinitions)
            {
                menuItemDefinition.Activation();
            }

            foreach (var extension in _menuItemDefinitions)
            {
                extension.Activation();
            }

            var menuBar = IoC.Get <MenuBarDefinition>("MainMenu");

            foreach (var commandDefinition in _commandDefinitions)
            {
                if (commandDefinition.Command != null && commandDefinition.Gesture != null)
                {
                    _keyBindings.Add(new KeyBinding {
                        Gesture = commandDefinition.Gesture, Command = commandDefinition.Command
                    });
                }
            }

            ToolBarDefinition = ToolBarDefinitions.MainToolBar;

            var menuBuilder = new MenuBuilder(_menuBarDefinitions.ToArray(), _menuDefinitions.ToArray(), _menuItemGroupDefinitions.ToArray(), _menuItemDefinitions.ToArray(), new ExcludeMenuDefinition[0], new ExcludeMenuItemGroupDefinition[0], new ExcludeMenuItemDefinition[0]);

            var mainMenu = new Extensibility.MainMenu.ViewModels.MainMenuViewModel(menuBuilder);

            menuBuilder.BuildMenuBar(menuBar, mainMenu.Model);

            MainMenu = mainMenu;

            foreach (var tool in extensions.OfType <ToolViewModel>())
            {
                tools.Add(tool);

                switch (tool.DefaultLocation)
                {
                case Location.Bottom:
                    BottomTabs.Tools.Add(tool);
                    break;

                case Location.BottomRight:
                    BottomRightTabs.Tools.Add(tool);
                    break;

                case Location.RightBottom:
                    RightBottomTabs.Tools.Add(tool);
                    break;

                case Location.RightMiddle:
                    RightMiddleTabs.Tools.Add(tool);
                    break;

                case Location.RightTop:
                    RightTopTabs.Tools.Add(tool);
                    break;

                case Location.MiddleTop:
                    MiddleTopTabs.Tools.Add(tool);
                    break;

                case Location.Left:
                    LeftTabs.Tools.Add(tool);
                    break;

                case Location.Right:
                    RightTabs.Tools.Add(tool);
                    break;
                }
            }

            LeftTabs.SelectedTool        = LeftTabs.Tools.FirstOrDefault();
            RightTabs.SelectedTool       = RightTabs.Tools.FirstOrDefault();
            BottomTabs.SelectedTool      = BottomTabs.Tools.FirstOrDefault();
            BottomRightTabs.SelectedTool = BottomRightTabs.Tools.FirstOrDefault();
            RightTopTabs.SelectedTool    = RightTopTabs.Tools.FirstOrDefault();
            RightMiddleTabs.SelectedTool = RightMiddleTabs.Tools.FirstOrDefault();
            RightBottomTabs.SelectedTool = RightBottomTabs.Tools.FirstOrDefault();
            MiddleTopTabs.SelectedTool   = MiddleTopTabs.Tools.FirstOrDefault();

            StatusBar.LineNumber     = 1;
            StatusBar.Column         = 1;
            StatusBar.PlatformString = Platform.OSDescription + " " + Platform.AvalonRID;

            ProcessCancellationToken = new CancellationTokenSource();

            CurrentPerspective = Perspective.Editor;

            IoC.RegisterConstant(this);
        }