public MajorsPage(MajorsContext majorsContext, AppConfig appConfig, Window window) { InitializeComponent(); _majorsContext = majorsContext; _appConfig = appConfig; _window = window; var majorsGrid = this.MajorsGrid; PrepareGrid(majorsGrid, this._majorsContext.MajorInfos, true); PrepareGrid(this.ToolsGrid, this._majorsContext.ResourceInfos, false); var backgroundImagePath = appConfig.GetAppBackgroundImagePath(); if (!string.IsNullOrWhiteSpace(backgroundImagePath)) { GridUtility.SetBackGround(backgroundImagePath, MainGrid); } else { GridUtility.SetBackGround(_majorsContext.TopBackgroundImagePath, TopGrid); GridUtility.SetBackGround(_majorsContext.BottomBackgroundImagePath, BottomGrid); } if (!string.IsNullOrWhiteSpace(_majorsContext.AppTitle)) { this.WindowTitle = _majorsContext.AppTitle; this.Title = _majorsContext.AppTitle; } BarPageUtility.PrepareBarPage(this, _appConfig); }
public MainWindow() { InitializeComponent(); var appConfig = new AppConfig(); var configFilePath = AppConfig.GetConfigFilePath(); Page expectPage = null; if (File.Exists(configFilePath)) { try { appConfig = PrepareAppConfig(configFilePath); } catch { appConfig = new AppConfig(); } } var majorNames = appConfig.GetMajorNames(); if (majorNames.Count <= 0) { expectPage = new MajorsPage(new MajorsContext(), appConfig, this); HomePageUtility.HomePageFunc = () => new MajorsPage(new MajorsContext(), appConfig, this); } else if (majorNames.Count == 1) { var majorsContext = PrepareMajorsContext(appConfig); var majorContext = MajorsContext.PrepareMajorContext(majorsContext, appConfig, majorsContext.MajorInfos.First()); expectPage = new MajorPage(majorContext, appConfig, this); HomePageUtility.HomePageFunc = () => new MajorPage(majorContext, appConfig, this); } else { var majorsContext = PrepareMajorsContext(appConfig); expectPage = new MajorsPage(majorsContext, appConfig, this); HomePageUtility.HomePageFunc = () => new MajorsPage(majorsContext, appConfig, this); } var icoPath = appConfig.GetIcoImagePath().GetExistPath(); if (!string.IsNullOrWhiteSpace(icoPath)) { Icon = new BitmapImage(new Uri(icoPath)); } if (!string.IsNullOrWhiteSpace(appConfig.AppTitle)) { this.Title = appConfig.AppTitle; } this.NavigationService.Navigate(expectPage); }
private static MajorsContext PrepareMajorsContext(AppConfig appConfig) { var majorsContext = new MajorsContext { AppTitle = appConfig.AppTitle, AppTitleImagePath = appConfig.GetAppTitleImagePath(), TopBackgroundImagePath = appConfig.GetAppTopBackgroundImagePath(), BottomBackgroundImagePath = appConfig.GetAppBottomBackgroundImagePath() }; foreach (var oneMajorName in appConfig.GetMajorNames()) { if (majorsContext.MajorInfos.ContainsKey(oneMajorName)) { continue; } var imagePath = appConfig.GetMajorFolderImagePath(oneMajorName); var imageMouseEnterPath = AppConfig.GetMouseEnterImagePath(imagePath); majorsContext.MajorInfos.Add(oneMajorName, new FolderInfo() { Name = oneMajorName, ImagePath = imagePath, MoveEnterImagePath = imageMouseEnterPath }); } foreach (var oneResourceFolderName in appConfig.GetResourceNames()) { if (majorsContext.ResourceInfos.ContainsKey(oneResourceFolderName)) { continue; } var resourcePath = AppConfig.GetResourceFolderPath(oneResourceFolderName); if (string.IsNullOrWhiteSpace(resourcePath)) { continue; } var imagePath = appConfig.GetResourceFolderImagePath(oneResourceFolderName); var imageMouseEnterPath = AppConfig.GetMouseEnterImagePath(imagePath); majorsContext.ResourceInfos.Add(oneResourceFolderName, new FolderInfo() { Name = oneResourceFolderName, ImagePath = imagePath, MoveEnterImagePath = imageMouseEnterPath, Path = resourcePath }); } return(majorsContext); }
private void PrepareGrid(Grid grid, IDictionary <string, FolderInfo> infos, bool isMajorRequest) { int columnCount, useRowIndex, useColumnIndex; GridUtility.PrepareBuutonGrid(grid, infos.Count, isMajorRequest, out columnCount, out useRowIndex, out useColumnIndex); foreach (var oneInfoPair in infos) { var button = ButtonUtility.CreateButton(oneInfoPair.Value.ImagePath, oneInfoPair.Key, oneInfoPair.Value.MoveEnterImagePath); if (isMajorRequest) { MajorContext majorContext = MajorsContext.PrepareMajorContext(_majorsContext, _appConfig, oneInfoPair); button.Tag = majorContext; button.Click += NavigateMajorPageButton_Click; } else { button.Tag = oneInfoPair.Value.Path; button.Click += OpenFolderButton_Click; } GridUtility.SetButton(grid, button, isMajorRequest, columnCount, ref useRowIndex, ref useColumnIndex); } }
public static MajorContext PrepareMajorContext(MajorsContext majorsContext, AppConfig appConfig, KeyValuePair <string, FolderInfo> oneInfoPair) { var majorName = oneInfoPair.Key; var majorContext = new MajorContext { MajorName = majorName, AppTitle = majorsContext.AppTitle, AppTitleImagePath = majorsContext.AppTitleImagePath }; var majorTopImagePath = appConfig.GetMajorTopBackgroundImagePath(majorName); var majorBottomPath = appConfig.GetMajorBottomBackgroundImagePath(majorName); majorContext.TopBackgroundImagePath = majorTopImagePath.GetExistPath(); majorContext.BottomBackgroundImagePath = majorBottomPath.GetExistPath(); foreach (var oneInfo in majorsContext.ResourceInfos) { var majorPath = Path.Combine(oneInfo.Value.Path, majorName); if (!Directory.Exists(majorPath)) { majorPath = oneInfo.Value.Path; } var majorToolImagePath = appConfig.GetMajorResourceImagePath(majorName, oneInfo.Key); majorToolImagePath = majorToolImagePath.GetExistPath(); majorToolImagePath = string.IsNullOrWhiteSpace(majorToolImagePath) ? oneInfo.Value.ImagePath : majorToolImagePath; var majorToolImageMouseEnterPath = AppConfig.GetMouseEnterImagePath(majorToolImagePath); majorContext.ResourceInfos.Add(oneInfo.Key, new FolderInfo() { Name = oneInfo.Key, Path = majorPath, ImagePath = majorToolImagePath, MoveEnterImagePath = majorToolImageMouseEnterPath }); } var videoFunctionDisplayName = string.IsNullOrWhiteSpace(appConfig.VideoFunctionDisplayName) ? "Video" : appConfig.VideoFunctionDisplayName; var majorVideoPath = appConfig.GetMajorVideoFolderPath(majorName); var videoImagePath = appConfig.GetMajorVideoImagePath(majorName).GetExistPath(); var mouseEnterImagePath = AppConfig.GetMouseEnterImagePath(videoImagePath); majorContext.FunctionInfos.Add(videoFunctionDisplayName, new FunctionInfo() { Kind = FunctionKind.Video, VideosPath = majorVideoPath, ImagePath = videoImagePath, MouseEnterImagePath = mouseEnterImagePath }); var openFileFunctionFile = appConfig.GetMajorOpeFileFunctionFilePath(majorName); if (!File.Exists(openFileFunctionFile)) { return(majorContext); } var jsonStr = File.ReadAllText(openFileFunctionFile); var listOpenFileRequest = new List <OpenFileFunctionRequest>(); try { listOpenFileRequest = JsonConvert.DeserializeObject <IEnumerable <OpenFileFunctionRequest> >(jsonStr).ToList(); } catch { ; } foreach (var oneRequest in listOpenFileRequest) { if (majorContext.FunctionInfos.ContainsKey(oneRequest.Name)) { continue; } if (string.IsNullOrWhiteSpace(oneRequest.ProgramName) && string.IsNullOrWhiteSpace(oneRequest.FileFullName)) { continue; } var functionImagePath = appConfig.GetMajorOpenFileFunctionImagePath(majorName, oneRequest.Name); functionImagePath = functionImagePath.GetExistPath(); var mouseImagePath = AppConfig.GetMouseEnterImagePath(functionImagePath); majorContext.FunctionInfos.Add(oneRequest.Name, new FunctionInfo() { Kind = FunctionKind.OpenFile, FunctionName = oneRequest.Name, ProgramName = oneRequest.ProgramName, FilePath = oneRequest.FileFullName, ImagePath = functionImagePath, MouseEnterImagePath = mouseImagePath, WorkDirection = oneRequest.WorkDirection }); } return(majorContext); }