/// ------------------------------------------------------------------------------------ /// <summary> /// Checks if the specified class name already exists. /// </summary> /// ------------------------------------------------------------------------------------ public bool DoesClassNameExist(string className, ClassListViewItem origClassInfo, bool showMsg) { if (className != null) { className = className.Trim(); } // Ensure the new class doesn't have a duplicate class name if (Items.Cast <ClassListViewItem>() .Any(item => item.Text.Trim().ToLower() == className.ToLower() && item != origClassInfo)) { if (showMsg) { var msg = LocalizationManager.GetString("CommonControls.ClassesList.DuplicateClassNameErrorMsg", "Class '{0}' already exists. Choose a different name.", "Error message when attempting to create class with duplicate name."); App.NotifyUserOfProblem(msg, className); } return(true); } return(false); }
/// ------------------------------------------------------------------------------------ public void Show(ClassListViewItem item) { ErasePrevItemDottedLine(item); if (item.ClassType == SearchClassType.Phones) { m_tipText = item.FormattedMembersString; } else { string[] features = item.FeatureNames; m_tipText = (features != null ? string.Join(Environment.NewLine, features) : string.Empty); } m_item = item; Point pt = m_ctrl.PointToClient(Control.MousePosition); if (!(m_ctrl is ListView)) { pt.Y += (int)(Cursor.Current.Size.Height * 0.7); } else { Rectangle rc = (m_ctrl as ListView).GetItemRect(item.Index, ItemBoundsPortion.Label); pt.Y = rc.Bottom + 3; } Show(m_tipText, m_ctrl, pt); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ private static void GetMasksFromPattern(ClassListViewItem item, string pattern) { item.Mask.Clear(); pattern = pattern.Replace("][", ","); pattern = pattern.Replace("],]", ","); pattern = pattern.Replace("[", string.Empty); pattern = pattern.Replace("]", string.Empty); pattern = pattern.Replace("{", string.Empty); pattern = pattern.Replace("}", string.Empty); pattern = pattern.ToLower(); string[] features = pattern.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string feature in features) { Feature feat = (item.ClassType == SearchClassType.Articulatory ? App.AFeatureCache[feature] : App.BFeatureCache[feature]); if (feat != null) { item.Mask[feat.Bit] = true; } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a new list resultView item for the specified search class. /// </summary> /// ------------------------------------------------------------------------------------ public static ClassListViewItem Create(SearchClass srchClass, bool addMembersAndClassTypeColumns) { ClassListViewItem item = new ClassListViewItem(srchClass.Name); item.Name = kClassNameSubitem; item.ClassType = srchClass.Type; if (addMembersAndClassTypeColumns) { item.SubItems.Add(srchClass.Pattern); item.SubItems.Add(item.ClassTypeText); } item.ANDFeatures = (string.IsNullOrEmpty(srchClass.Pattern) || srchClass.Pattern[0] == '['); if (srchClass.Type == SearchClassType.Articulatory) { item.Mask = App.AFeatureCache.GetEmptyMask(); GetMasksFromPattern(item, srchClass.Pattern); } else if (srchClass.Type == SearchClassType.Binary) { item.Mask = App.BFeatureCache.GetEmptyMask(); GetMasksFromPattern(item, srchClass.Pattern); } return(item); }
/// ------------------------------------------------------------------------------------ private void ErasePrevItemDottedLine(ClassListViewItem item) { if (m_prevItem != null && m_prevItem.ListView != null) { Rectangle rc = m_prevItem.GetBounds(ItemBoundsPortion.Label); m_prevItem.ListView.Invalidate(rc); } m_prevItem = item; }
/// ------------------------------------------------------------------------------------ public void Hide() { ErasePrevItemDottedLine(null); if (m_ctrl != null) { Hide(m_ctrl); } m_item = null; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Copy Constructor for a ClassListViewItem /// </summary> /// <param name="item">Item being copied.</param> /// ------------------------------------------------------------------------------------ public ClassListViewItem(ClassListViewItem item) : base(item.Text) { // Create subitems to copy into. Start at 1 because the subitem collection // always includes the item that owns the subitems. I don't know why. for (int i = 1; i < item.SubItems.Count; i++) { SubItems.Add(new ListViewSubItem()); } Copy(item); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Loads the list with classes and their members. /// </summary> /// ------------------------------------------------------------------------------------ public void Load() { if (App.DesignMode) { return; } Items.Clear(); foreach (var srchClass in App.Project.SearchClasses) { Items.Add(ClassListViewItem.Create(srchClass, m_showMembersAndClassTypeColumns)); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Removes the specified item from the list and keeps track of its Id so the class /// will be deleted from the database when the SaveChanges method is called. /// </summary> /// ------------------------------------------------------------------------------------ public void DeleteItem(ClassListViewItem item) { int prevIndex = item.Index; m_deletedClass = true; Items.Remove(item); while (prevIndex >= Items.Count) { prevIndex--; } if (Items.Count > 0) { Items[prevIndex].Selected = true; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Copies the information from the specified ClassListViewItem and its subitems. /// </summary> /// <param name="item">Item being copied</param> /// ------------------------------------------------------------------------------------ public void Copy(ClassListViewItem item) { Text = item.Text; ClassType = item.ClassType; ANDFeatures = item.ANDFeatures; AllowEdit = item.AllowEdit; Pattern = item.Pattern; Tag = item.Tag; if (item.Mask != null) { Mask = item.Mask.Clone(); } else if (item.ClassType == SearchClassType.Articulatory) { Mask = App.AFeatureCache.GetEmptyMask(); } else if (item.ClassType == SearchClassType.Binary) { Mask = App.BFeatureCache.GetEmptyMask(); } for (int i = 0; i < item.SubItems.Count; i++) { SubItems[i].Name = item.SubItems[i].Name; if (i == 1) { SubItems[1].Font = ClassMembersFont; SubItems[1].Text = Pattern; } else if (i == 2) { SubItems[2].Text = ClassTypeText; } } }