/// <summary> /// Method edits project. /// </summary> /// <param name="selectedItem"></param> private void _EditProject(ProjectDataWrapper selectedItem) { try { string nameOfEditedProject = selectedItem.Name; if (!string.IsNullOrEmpty(_projectNameBeforeEditing)) { nameOfEditedProject = _projectNameBeforeEditing; _projectNameBeforeEditing = string.Empty; } // Search project with necessary name in ProjectCatalog. var configs = from cfg in App.Current.ProjectCatalog.Projects where cfg.Name.Equals(nameOfEditedProject) select cfg; Debug.Assert(configs.ToList <ProjectConfiguration>().Count > 0); ProjectConfiguration editedProjectCfg = configs.First(); // ProjectConfiguration editedProjectCfg = App.Current.ProjectCatalog.Projects.ElementAt(XceedGrid.SelectedIndex); Logger.Info("////////// Edited project " + editedProjectCfg.Name); Logger.Info("////////// Selected project " + selectedItem.Name); if (selectedItem.Description != editedProjectCfg.Description) { editedProjectCfg.Description = selectedItem.Description; // in case of editing current project need to rename at project if (editedProjectCfg.Name.Equals(App.Current.Project.Name, StringComparison.OrdinalIgnoreCase)) { App.Current.Project.Description = selectedItem.Description; } } if (!selectedItem.Name.Equals(editedProjectCfg.Name, StringComparison.OrdinalIgnoreCase)) { string oldProjectName = editedProjectCfg.Name; ProjectFactory.RenameProject(editedProjectCfg, selectedItem.Name, App.Current.ProjectCatalog); if (oldProjectName.Equals(App.Current.Project.Name, StringComparison.OrdinalIgnoreCase)) { Settings settings = Settings.Default; settings.LastProjectName = System.IO.Path.GetFileName(editedProjectCfg.FilePath); settings.Save(); } } editedProjectCfg.Save(); App.Current.ProjectCatalog.Refresh(); } catch (Exception ex) { Logger.Info(ex); } }
/// <summary> /// Occurs when user press "enter" on edited grid row. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DataGridCollectionViewSource_CommittingEdit(object sender, DataGridItemCancelEventArgs e) { App.Current.MainWindow.StatusBar.SetStatus(this, null); Row parentRow = (Row)XceedGrid.GetContainerFromItem(e.Item); parentRow.Cells[IS_CURRENT_COLUMN_CAPTION].IsEnabled = true; ProjectDataWrapper editedItem = e.Item as ProjectDataWrapper; _EditProject(editedItem); e.Handled = true; }
/// <summary> /// Occurs when user press enter in inserion row. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DataGridCollectionViewSource_CommittingNewItem(object sender, DataGridCommittingNewItemEventArgs e) { try { WorkingStatusHelper.SetBusy((string)App.Current.FindResource("LoadingProjectStatus")); ProjectCatalog projectBrowser = App.Current.ProjectCatalog; List <ProjectDataWrapper> source = e.CollectionView.SourceCollection as List <ProjectDataWrapper>; ProjectDataWrapper projectDataTemplate = e.Item as ProjectDataWrapper; App.Current.NewProject(projectDataTemplate.Name, projectBrowser.FolderPath, projectDataTemplate.Description); source.Add(projectDataTemplate); // update layout UpdateView(); e.Index = source.Count - 1; e.NewCount = source.Count; e.Handled = true; } catch (ApplicationException ex) { Logger.Info(ex); App.Current.Messenger.AddWarning(ex.Message); } catch (Exception ex) { Logger.Info(ex); App.Current.Messenger.AddWarning(ex.Message); } finally { WorkingStatusHelper.SetReleased(); App.Current.MainWindow.StatusBar.SetStatus(this, null); } }
/// <summary> /// ExceedGrid Item Source Changed handler. /// </summary> private void XceedGrid_OnItemSourceChanged(object sender, EventArgs e) { // select item if (-1 != _itemIndexToSelection) { XceedGrid.SelectedIndex = Math.Min(_itemIndexToSelection, XceedGrid.Items.Count - 1); } else if (!string.IsNullOrEmpty(_selectedProjectName)) { for (int index = 0; index < _projectsDataCollection.Count; ++index) { ProjectDataWrapper wrapper = _projectsDataCollection[index]; if (_selectedProjectName == wrapper.Name) { XceedGrid.SelectedItem = wrapper; break; } } } XceedGrid.CurrentItem = XceedGrid.SelectedItem; _selectedProjectName = null; _itemIndexToSelection = -1; }
/// <summary> /// Occurs when user set focus to any grid cell. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DataCellGotFocus(object sender, RoutedEventArgs e) { if (CurrentProjectName != null) { ProjectDataWrapper selectedItem = (ProjectDataWrapper)XceedGrid.CurrentItem; if (selectedItem == null) { return; } DataCell cell = sender as DataCell; if (cell.ParentColumn == XceedGrid.Columns[IS_CURRENT_COLUMN_CAPTION]) // if user clicks to "IsCurrent" cell - don't show editing status. { return; } bool stopEdit = false; if (cell.ParentColumn == XceedGrid.Columns[NAME_COLUMN_CAPTION]) { stopEdit = (string.Compare(SelectedProjectName, CurrentProjectName, true) == 0); } cell.ReadOnly = stopEdit; if (stopEdit) { string status = (string)App.Current.FindResource("UnaEditCurrentProjectNameTooltip"); cell.ToolTip = status; cell.EndEdit(); cell.ParentRow.EndEdit(); _isForcingEndEdit = true; App.Current.MainWindow.StatusBar.SetStatus(this, status); _needToUpdateStatus = false; } } }
public override ValidationResult Validate(object value, CultureInfo culture, CellValidationContext context) { ValidationResult result = null; // not empty check bool isObjectEmpty = true; if (null != value) { isObjectEmpty = string.IsNullOrEmpty(value.ToString().Trim()); // project name cannot consist only in blanks } if (isObjectEmpty) { result = new ValidationResult(false, (string)Application.Current.FindResource("ProjectNameValidationRuleIncorrectNameError")); } if (null == result) { string name = value.ToString().Trim(); if (-1 != name.IndexOfAny(new char[] { '\\', '/', '*', ';', ',', ':', '|', '"' })) { result = new ValidationResult(false, (string)Application.Current.FindResource("ProjectNameValidationRuleIncorrectNameError")); } else { ProjectsPage projectsPage = (ProjectsPage)App.Current.MainWindow.GetPage(PagePaths.ProjectsPagePath); ProjectDataWrapper currentItem = (ProjectDataWrapper)projectsPage.XceedGrid.CurrentItem; // check duplicate ItemCollection wrappedCollection = projectsPage.XceedGrid.Items; foreach (ProjectDataWrapper wrapper in wrappedCollection) { if (name.Equals(wrapper.Name, StringComparison.InvariantCultureIgnoreCase) && (wrapper != currentItem)) { result = new ValidationResult(false, (string)App.Current.FindResource("ProjectNameValidationRuleDuplicateNameError")); break; // NOTE: exit - error founded } } if (null == result) { // normal length check string fileName = name + ProjectConfiguration.FILE_EXTENSION; // NOTE: check only one file name, // but real created two files: ProjectConfiguration.FILE_EXTENSION and DatabaseEngine.DATABASE_EXTENSION string filePath = null; try { filePath = _GetDatabaseAbsolutPath(App.Current.ProjectCatalog.FolderPath, fileName); } catch { } // valid name check if (!FileHelpers.IsFileNameCorrect(filePath) || !FileHelpers.ValidateFilepath(filePath)) { result = new ValidationResult(false, (string)Application.Current.FindResource("ProjectNameValidationRuleIncorrectNameError")); } } } } return((null == result)? ValidationResult.ValidResult : result); }