/// <summary> /// Set the current theme /// </summary> /// <param name="name">The name of the theme</param> /// <returns>true if the new theme is set, false otherwise</returns> public bool SetCurrent(string name) { if (ThemeDictionary.ContainsKey(name)) { ITheme newTheme = ThemeDictionary[name]; CurrentTheme = newTheme; ResourceDictionary theme = Application.Current.MainWindow.Resources.MergedDictionaries[0]; ResourceDictionary appTheme = Application.Current.Resources.MergedDictionaries.Count > 0 ? Application.Current.Resources.MergedDictionaries[0] : null; theme.BeginInit(); theme.MergedDictionaries.Clear(); if (appTheme != null) { appTheme.BeginInit(); appTheme.MergedDictionaries.Clear(); } else { appTheme = new ResourceDictionary(); appTheme.BeginInit(); Application.Current.Resources.MergedDictionaries.Add(appTheme); } foreach (Uri uri in newTheme.UriList) { try { ResourceDictionary newDict = new ResourceDictionary { Source = uri }; /*AvalonDock and menu style needs to move to the application * 1. AvalonDock needs global styles as floatable windows can be created * 2. Menu's need global style as context menu can be created */ if (uri.ToString().Contains("AvalonDock") || uri.ToString().Contains("Mjolnir.IDE.Core;component/Styles/VS2013/Menu.xaml")) { appTheme.MergedDictionaries.Add(newDict); } else { theme.MergedDictionaries.Add(newDict); } } catch (Exception ex) { //TODO : Log error Debugger.Break(); } } appTheme.EndInit(); theme.EndInit(); _logger.LogOutput(new LogOutputItem("Theme set to " + name, OutputCategory.Info, OutputPriority.None)); _eventAggregator.GetEvent <ThemeChangeEvent>().Publish(newTheme); } return(false); }
public ContentViewModel NewContent(object parameter) { var vm = _container.Resolve <TextViewModel>(); var model = _container.Resolve <TextModel>(); var view = _container.Resolve <TextView>(); _outputService.LogOutput(new LogOutputItem("Creating a new simple file using AllFileHandler", OutputCategory.Info, OutputPriority.Low)); //Clear the undo stack model.Document.UndoStack.ClearAll(); //Set the model and view vm.Model = model; vm.View = view; vm.Title = "untitled"; vm.View.DataContext = model; vm.Handler = this; vm.Model.IsDirty = true; return(vm); }
/// <summary> /// Opens the object - if object is null, show a open file dialog to select a file to open /// </summary> /// <param name="location">The optional object to open</param> /// <returns>A document which was added to the workspace as a content view model</returns> public ContentViewModel Open(object location = null) { bool? result; ContentViewModel returnValue = null; if (location == null) { _dialog.Filter = ""; string sep = ""; var attributes = _handler.ContentHandlers.SelectMany( handler => (FileContentAttribute[]) (handler.GetType()).GetCustomAttributes(typeof(FileContentAttribute), true)).ToList(); attributes.Sort((attribute, contentAttribute) => attribute.Priority - contentAttribute.Priority); foreach (var contentAttribute in attributes) { _dialog.Filter = String.Format("{0}{1}{2} ({3})|{3}", _dialog.Filter, sep, contentAttribute.Display, contentAttribute.Extension); sep = "|"; } result = _dialog.ShowDialog(); location = _dialog.FileName; } else { result = true; } if (result == true && !string.IsNullOrWhiteSpace(location.ToString())) { //Let the handler figure out which view model to return if (_handler != null) { ContentViewModel openValue = _handler.GetViewModel(location); if (openValue != null) { //Check if the document is already open foreach (ContentViewModel contentViewModel in _workspace.Documents) { if (contentViewModel.Model.Location != null) { if (contentViewModel.Model.Location.Equals(openValue.Model.Location)) { _output.LogOutput(new LogOutputItem( "Document " + contentViewModel.Model.Location + "already open - making it active", OutputCategory.Info, OutputPriority.Low)); _workspace.ActiveDocument = contentViewModel; return(contentViewModel); } } } _output.LogOutput(new LogOutputItem("Opening file" + location + " !!", OutputCategory.Info, OutputPriority.Low)); // Publish the event to the Application - subscribers can use this object _eventAggregator.GetEvent <OpenContentEvent>().Publish(openValue); //Add it to the actual workspace _workspace.Documents.Add(openValue); //Make it the active document _workspace.ActiveDocument = openValue; //Add it to the recent documents opened _recentSettings.Update(openValue); returnValue = openValue; } else { _output.LogOutput(new LogOutputItem("Unable to find a IContentHandler to open " + location, OutputCategory.Error, OutputPriority.High)); } } } else { _output.LogOutput(new LogOutputItem("Canceled out of open file dialog", OutputCategory.Info, OutputPriority.Low)); } return(returnValue); }
public void Initialize() { _eventAggregator.GetEvent <SplashScreenUpdateEvent>().Publish(new SplashScreenUpdateEvent { Text = "Loading Components..." }); _container.RegisterType <IThemeSettings, ThemeSettings>(new ContainerControlledLifetimeManager()); _container.RegisterType <IRecentViewSettings, RecentViewSettings>(new ContainerControlledLifetimeManager()); _container.RegisterType <IWindowPositionSettings, WindowPositionSettings>(new ContainerControlledLifetimeManager()); _container.RegisterType <IToolbarPositionSettings, ToolbarPositionSettings>(new ContainerControlledLifetimeManager()); _container.RegisterType <ICommandManager, Mjolnir.IDE.Core.Services.CommandManager>(new ContainerControlledLifetimeManager()); _container.RegisterType <IContentHandlerRegistry, ContentHandlerRegistry>(new ContainerControlledLifetimeManager()); _container.RegisterType <IStatusbarService, MjolnirStatusbarViewModel>(new ContainerControlledLifetimeManager()); _container.RegisterType <IThemeManager, ThemeManager>(new ContainerControlledLifetimeManager()); _container.RegisterType <IShellToolbarService, ShellToolbarService>(new ContainerControlledLifetimeManager()); _container.RegisterType <IMenuService, MenuItemViewModel>(new ContainerControlledLifetimeManager(), new InjectionConstructor( new InjectionParameter(typeof(string), "$MAIN$"), new InjectionParameter(typeof(string), "$MAIN$"), new InjectionParameter(typeof(int), 1), new InjectionParameter( typeof(ImageSource), null), new InjectionParameter(typeof(ICommand), null), new InjectionParameter( typeof(KeyGesture), null), new InjectionParameter(typeof(bool), false), new InjectionParameter(typeof(bool), false), new InjectionParameter( typeof(IUnityContainer), _container), new InjectionParameter(typeof(bool), false), new InjectionParameter(typeof(bool), false))); _container.RegisterType <ToolbarViewModel>( new InjectionConstructor(new InjectionParameter(typeof(string), "$MAIN$"), new InjectionParameter(typeof(string), "$MAIN$"), new InjectionParameter(typeof(int), 1), new InjectionParameter(typeof(ImageSource), null), new InjectionParameter(typeof(ICommand), null), new InjectionParameter(typeof(bool), false), new InjectionParameter(typeof(IUnityContainer), _container))); _container.RegisterType <ISettingsManager, SettingsManager>(new ContainerControlledLifetimeManager()); _container.RegisterType <IOpenDocumentService, OpenDocumentService>(new ContainerControlledLifetimeManager()); _container.RegisterType <IMessageDialogService, DefaultMessageDialogService>(new TransientLifetimeManager()); _container.RegisterType <IFileDialogService, DefaultFileDialogService>(new TransientLifetimeManager()); AppCommands(); LoadSettings(); // Try resolving an output service - if not found, then register the NLog service var isDefaultOutputService = false; try { this._outputService = _container.Resolve <IOutputService>(); } catch { _container.RegisterType <IOutputService, DefaultLogService>(new ContainerControlledLifetimeManager()); this._outputService = _container.Resolve <IOutputService>(); isDefaultOutputService = true; } var app = _container.Resolve <MjolnirApp>(); if (app != null) { app.RegisterTypes(); } //Output OutputModule outputModule = _container.Resolve <OutputModule>(); outputModule.Initialize(); if (isDefaultOutputService) { _outputService.LogOutput(new LogOutputItem("DefaultLogService applied", OutputCategory.Info, OutputPriority.None)); } if (app != null) { app.InitalizeIDE(); } //Below ones can be loaded with solution, does not require immediate load //TODO : Console PropertiesModule propertiesModule = _container.Resolve <PropertiesModule>(); propertiesModule.Initialize(); if (app != null) { _eventAggregator.GetEvent <SplashScreenUpdateEvent>().Publish(new SplashScreenUpdateEvent { Text = "Loading Application UI..." }); app.LoadCommands(); app.LoadModules(); app.LoadTheme(); app.LoadMenus(); app.LoadToolbar(); app.LoadSettings(); } var shell = _container.Resolve <IShellView>(); shell.LoadLayout(); _eventAggregator.GetEvent <IDELoadedEvent>().Publish(); }
/// <summary> /// CloseDocument method that gets called when the Close command gets executed. /// </summary> private void CloseDocument(object obj) { IWorkspace workspace = _container.Resolve <DefaultWorkspace>(); IOutputService output = _container.Resolve <IOutputService>(); IMenuService menuService = _container.Resolve <IMenuService>(); CancelEventArgs e = obj as CancelEventArgs; ContentViewModel activeDocument = obj as ContentViewModel; if (activeDocument == null) { activeDocument = workspace.ActiveDocument; } if (activeDocument.Handler != null && activeDocument.Model.IsDirty) { //means the document is dirty - show a message box and then handle based on the user's selection var res = MessageBox.Show(string.Format("Save changes for document '{0}'?", activeDocument.Title), "Are you sure?", MessageBoxButton.YesNoCancel); //Pressed Yes if (res == MessageBoxResult.Yes) { if (!workspace.ActiveDocument.Handler.SaveContent(workspace.ActiveDocument)) { //Failed to save - return cancel res = MessageBoxResult.Cancel; //Cancel was pressed - so, we cant close if (e != null) { e.Cancel = true; } return; } } //Pressed Cancel if (res == MessageBoxResult.Cancel) { //Cancel was pressed - so, we cant close if (e != null) { e.Cancel = true; } return; } } if (e == null) { output.LogOutput(new LogOutputItem("Closing document " + activeDocument.Model.Location, OutputCategory.Info, OutputPriority.None)); workspace.Documents.Remove(activeDocument); _eventAggregator.GetEvent <ClosedContentEvent>().Publish(activeDocument); menuService.Refresh(); } else { // If the location is not there - then we can remove it. // This can happen when on clicking "No" in the popup and we still want to quit if (activeDocument.Model.Location == null) { workspace.Documents.Remove(activeDocument); _eventAggregator.GetEvent <ClosedContentEvent>().Publish(activeDocument); } } }