using JD.Fontastic.View; using JD.Fontastic.ViewModel; using JD.Fontastic.WPF.Configuration; using JD.FontGeneration.Service; using JD.MapFileFontDownloader.Service; using JD.MapFileFontReader.Service; using Newtonsoft.Json; using Plume.Icons; using Plume.Interfaces.Modules; using Plume.Interfaces.WPF.Menu; using Plume.Interfaces.WPF.Modules; using Plume.Interfaces.WPF.Notifications; using Plume.Interfaces.WPF.StatusBar; using Plume.Interfaces.WPF.ToolBar; using Plume.Interfaces.WPF.Window; using Plume.Perforce.Service.Api; using System; using System.IO; namespace JD.Fontastic { public class FontasticModule : IWpfModule { private IPerforceService _perforceService; private IMapFileFontReaderService _mapFileFontReaderService; private IMapFileFontDownloaderService _mapFileFontDownloaderService; private IFontGenerationService _fontGenerationService; private FontasticConfiguration _configuration; public void Dispose() { } public void Initialize(IWpfModuleContext context) { var logger = context.Logger ?? throw new ArgumentNullException(nameof(context.Logger)); IWindowManager windowManager = context.WindowManager ?? throw new ArgumentNullException(nameof(context.WindowManager)); IStatusBarManager statusBarManager = context.StatusBarManager ?? throw new ArgumentNullException(nameof(context.StatusBarManager)); INotificationManager notificationManager = context.NotificationManager ?? throw new ArgumentNullException(nameof(context.NotificationManager)); _perforceService = context.ServiceManager.Get(); _mapFileFontReaderService = context.ServiceManager.Get(); _mapFileFontDownloaderService = context.ServiceManager.Get(); _fontGenerationService = context.ServiceManager.Get(); InitializeConfiguration(); InitializeMenus(context); var generationParametersViewModel = new FontGenerationParametersViewModel(logger, _configuration, _perforceService); var generationParametersView = new FontGenerationParametersControl() { DataContext = generationParametersViewModel }; var fontFilesExplorerViewModel = new FontFilesExplorerViewModel(logger, _configuration, windowManager, _mapFileFontDownloaderService, _perforceService, generationParametersViewModel); var fontFilesExplorerView = new FontFilesExplorerControl() { DataContext = fontFilesExplorerViewModel }; var fontExplorerViewModel = new FontExplorerViewModel(logger, _configuration, _perforceService, _mapFileFontReaderService, _fontGenerationService, statusBarManager, notificationManager, windowManager, generationParametersViewModel, fontFilesExplorerViewModel); var fontExplorerView = new FontExplorerControl() { DataContext = fontExplorerViewModel }; // set the default values in UI generationParametersViewModel.SetDefaults(); // select all fonts by default fontFilesExplorerViewModel.SelectAllNodes(); windowManager.AddToolWindow("Font parameters", "Font generation parameters", StandardIcon.SettingsPanel, generationParametersView, DockingSide.Left, null); windowManager.AddToolWindow("Font explorer", "Localization files", StandardIcon.TreeView, fontFilesExplorerView, DockingSide.Top, null); windowManager.AddToolWindow("Font viewer", "Font viewer", StandardIcon.Visible, fontExplorerView, DockingSide.Right, null); } public void Setup(IModuleSetup setup) { } private void InitializeConfiguration() { var configFilePath = @"Configuration/FontasticConfiguration.json"; if (!File.Exists(configFilePath)) { throw new FileNotFoundException("Unable to load the configuration file", configFilePath); } _configuration = JsonConvert.DeserializeObject(File.ReadAllText(configFilePath)); } private void InitializeMenus(IWpfModuleContext context) { context.ToolBarManager.RemoveToolBar(ToolBarName.Standard); context.MenuManager.RemoveMenu(MenuPath.FileMenu); context.MenuManager.RemoveMenu(MenuPath.EditMenu); } } }