public MajorPage(MajorContext majorContext, AppConfig appConfig, Window window) { _majorContext = majorContext; _appConfig = appConfig; _window = window; InitializeComponent(); PrepareGrid(); PrepareGrid(this.ToolsGrid, this._majorContext.ResourceInfos); var majorBackgroundImagePath = appConfig.GetMajorBackgroundImagePath(_majorContext.MajorName); if (!string.IsNullOrWhiteSpace(majorBackgroundImagePath)) { GridUtility.SetBackGround(majorBackgroundImagePath, MainGrid); } else { GridUtility.SetBackGround(_majorContext.TopBackgroundImagePath, TopGrid); GridUtility.SetBackGround(_majorContext.BottomBackgroundImagePath, BottomGrid); } if (!string.IsNullOrWhiteSpace(_majorContext.MajorName) && appConfig.ShowMajorNameAtMajorPage) { Title = _majorContext.MajorName; var textBlock = new TextBlock { Text = _majorContext.MajorName }; PageTitleViewBox.Child = textBlock; } BarPageUtility.PrepareBarPage(this, _appConfig); }
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); }