public override async Task OnOpen(CancelEventArgs e) { await base.OnOpen(e); var settings = _settingsService.LoadSettings(); if (!Directory.Exists(settings.PrintsPath)) { MessageBox.Show(_translationManager.GetTranslation(nameof(StringTable.Msg_PrintProjectsFolderNotConfigured)), "CuraManager", AlertButton.Ok, AlertImage.Information); e.Cancel = true; } else { _cache ??= _cachingService.LoadCache(settings.PrintsPath); if (_currentPrintsPath != settings.PrintsPath) { _currentPrintsPath = settings.PrintsPath; PrintElements.ForEach(x => x.Dispose()); PrintElements.Clear(); } var newElements = await _printsService.GetNewPrintElements(_cache, PrintElements).ToListAsync(); newElements.ForEach(x => AvailableTags.AddIfNotExists(x.Tags)); PrintElements.Add(newElements); PrintElementsViewSource.View.Refresh(); } }
private async Task CreateProjectFromWeb(string url) { var settings = _settingsService.LoadSettings(); Func <Task <PrintElement> > getProjectFunc; string projectName; if (settings.ShowWebDialogWhenAddingLink) { var dialog = new CreateProjectFromWebDialog(settings.PrintsPath, url) { Owner = Application.Current.MainWindow }; if (dialog.ShowDialog() == true) { projectName = dialog.ProjectName; getProjectFunc = dialog.CreateProject; } else { return; } } else { projectName = string.Empty; await ExecuteLoadingAction( _translationManager.GetTranslation(nameof(StringTable.Prog_LoadProjectData)), async() => projectName = await _downloadService.GetProjectName(new Uri(url)), null, null); getProjectFunc = () => CreateProjectFromWebDialog.CreateProject(settings.PrintsPath, url, projectName); } await ExecuteLoadingAction( string.Format(_translationManager.GetTranslation(nameof(StringTable.Prog_CreateProject)), projectName), async() => { var project = await getProjectFunc(); if (project != null) { PrintElements.Add(project); SelectedElement = project; } return(project != null); }, _translationManager.GetTranslation(nameof(StringTable.Suc_CreateProject)), _translationManager.GetTranslation(nameof(StringTable.Fail_CreateProject))); }
private async Task ExecuteReloadModels() { await ExecuteLoadingAction( _translationManager.GetTranslation(nameof(StringTable.Prog_ReloadModels)), new Func <Task>(async() => { await Task.Run(() => { PrintElements.Add(_printsService.GetNewPrintElements(_cache, PrintElements)); PrintElements.ForEach(x => x.InitializeMetadata()); }); PrintElementsViewSource.View.Refresh(); }), _translationManager.GetTranslation(nameof(StringTable.Suc_ReloadModels)), _translationManager.GetTranslation(nameof(StringTable.Fail_ReloadModels))); }
private void ExecuteRenameProject(PrintElement project) { string Validation(string newName) { if (string.Equals(project.Name, newName, StringComparison.OrdinalIgnoreCase)) { return(null); } var path = Path.Combine(Path.GetDirectoryName(project.DirectoryLocation), newName); if (Directory.Exists(path)) { return(string.Format(_translationManager.GetTranslation(nameof(StringTable.Msg_ProjectAlreadyExists)), newName)); } return(null); } var dialog = new RenameDialog( _translationManager.GetTranslation(nameof(StringTable.Title_RenameProject)), string.Format(_translationManager.GetTranslation(nameof(StringTable.Desc_RenameProject)), project.Name), project.Name, Validation) { Owner = Application.Current.MainWindow, }; if (dialog.ShowDialog() == true) { var newPath = Path.Combine(Path.GetDirectoryName(project.DirectoryLocation), dialog.NewName); SelectedElement = null; PrintElements.Remove(project); project.Dispose(); Directory.Move(project.DirectoryLocation, newPath); var newProject = new PrintElement(newPath); PrintElements.Add(newProject); SelectedElement = newProject; } }
private async Task CreateProjectFromArchive(string archivePath) { var settings = _settingsService.LoadSettings(); var dialog = new CreateProjectFromArchiveDialog(settings.PrintsPath, archivePath) { Owner = Application.Current.MainWindow }; if (dialog.ShowDialog() == true) { await ExecuteLoadingAction( string.Format(_translationManager.GetTranslation(nameof(StringTable.Prog_CreateProject)), dialog.ProjectName), async() => { var project = await dialog.CreateProject(); PrintElements.Add(project); SelectedElement = project; }, _translationManager.GetTranslation(nameof(StringTable.Suc_CreateProject)), _translationManager.GetTranslation(nameof(StringTable.Fail_CreateProject))); } }