/// ------------------------------------------------------------------------------------ /// <summary> /// Makes the specified field the first, or primary, field on which to sort. /// </summary> /// ------------------------------------------------------------------------------------ public bool SetPrimarySortField(PaField field, bool changeDirection, bool ascending) { if (field == null) { return(ascending); } var sortInfo = SortFields.SingleOrDefault(si => si.Field.Name == field.Name); int index = (sortInfo == null ? -1 : SortFields.IndexOf(sortInfo)); // If the sort information list already contains an item for the specified field, // we need to remove it before reinserting it at the beginning of the list. if (index > -1) { if (changeDirection) { ascending = SortFields[index].Ascending; } SortFields.RemoveAt(index); } if (changeDirection) { ascending = !ascending; } // Now insert an item at the beginning of the list since the specified field // has now become the first (i.e. primary) field on which to sort. SortFields.Insert(0, new SortField(field, ascending)); return(ascending); }
public static void AddCustomFields(Fw7CustomField mCustomfields, List <PaField> list) { if (mCustomfields != null && mCustomfields.CustomFields.Count > 0) { foreach (var mFieldValue in mCustomfields.CustomFields.Select(s => s.Name)) { var fd = new PaField(mFieldValue, FieldType.GeneralText); if ( mFieldValue.Any( fieldName => mCustomfields.FwWritingSystemType(mFieldValue) == FwDBUtils.FwWritingSystemType.Vernacular)) { fd.FwWsType = FwDBUtils.FwWritingSystemType.Vernacular; } if (list.All(f => f.Name != mFieldValue)) { list.Add(fd); } if (!Properties.Settings.Default.DefaultVisibleFields.Contains(fd.Name)) { Properties.Settings.Default.DefaultVisibleFields.Add(fd.Name); } } } if (list.All(f => f.Name != kPhoneticSourceFieldName)) { list.Add(new PaField(kPhoneticSourceFieldName, default(FieldType))); } if (!Properties.Settings.Default.DefaultVisibleFields.Contains(kPhoneticSourceFieldName)) { Properties.Settings.Default.DefaultVisibleFields.Add(kPhoneticSourceFieldName); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Saves some of the specified grid's properties. /// </summary> /// ------------------------------------------------------------------------------------ public void Save(DataGridView grid) { if (grid == null || grid.Columns.Count == 0) { return; } GridLines = grid.CellBorderStyle; if (SaveAdjustedColHeaderHeight) { ColHeaderHeight = grid.ColumnHeadersHeight; } // Save the list of columns sorted by display index. var displayIndexes = new SortedList <int, PaField>(); // Save the specified grid's column properties. foreach (var col in grid.Columns.Cast <DataGridViewColumn>()) { var field = _project.GetFieldForName(col.Name); if (field != null) { if (SaveAdjustedColWidths) { field.WidthInGrid = col.Width; } if (SaveReorderedCols) { displayIndexes[col.DisplayIndex] = field; } } } if (displayIndexes.Count > 0) { // The display index order saved with the fields should begin with zero, but // since the grid may have some SilHerarchicalColumns showing, the first field's // display index may be greater than 1. Therefore, we adjust for that by setting // the display indexes in sequence beginning from zero. int i = 0; foreach (var field in displayIndexes.Values) { field.DisplayIndexInGrid = i++; } } var filename = _project.ProjectPathFilePrefix + kFiltersFilePrefix; XmlSerializationHelper.SerializeToFile(filename, this); PaField.SaveProjectFields(_project); }
/// ------------------------------------------------------------------------------------ /// <summary> /// This method returns the default FW6 writing system for the specified field. /// </summary> /// ------------------------------------------------------------------------------------ public static string GetDefaultFw6WsIdForField(PaField field, IEnumerable <FwWritingSysInfo> writingSystems) { var wsList = writingSystems.ToArray(); FwWritingSysInfo ws; if (field.FwWsType == FwDBUtils.FwWritingSystemType.Vernacular) { ws = wsList.SingleOrDefault(w => w.IsDefaultVernacular); return(ws != null ? ws.Id : wsList.First(w => w.Type == FwDBUtils.FwWritingSystemType.Vernacular).Id); } ws = wsList.SingleOrDefault(w => w.IsDefaultAnalysis); return(ws != null ? ws.Id : wsList.First(w => w.Type == FwDBUtils.FwWritingSystemType.Analysis).Id); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets all the values for an interlinear field. The values can be considered all /// the column values for the specified field. When the fieldInfo parameter is for /// the phonetic field, then useOriginalPhonetic tells the method to get the value /// of the phonetic as it was before applying any experimental transcriptions. /// </summary> /// ------------------------------------------------------------------------------------ public string[] GetParsedFieldValues(PaField field, bool useOriginalPhonetic) { if (field == null) { return(null); } bool getOrigPhonetic = (useOriginalPhonetic && field.Type == FieldType.Phonetic); // Go through the parsed word entries and get the values for the specified field. var values = WordEntries.Select(we => { var val = (getOrigPhonetic ? we.OriginalPhoneticValue : we.GetField(field.Name, false)); return(val != null ? val.Trim() : string.Empty); }).ToArray(); return(values.Length == 0 ? null : values.ToArray()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Parses a non interlinear field (if necessary) and saves the field contents in one /// or more word cache entries. Parsing will depend on the data source's parse type /// and the field being parsed. /// </summary> /// ------------------------------------------------------------------------------------ private static void ParseSingleFieldInEntry(RecordCacheEntry entry, PaField field) { entry.NeedsParsing = false; string unparsedData = entry[field.Name]; if (string.IsNullOrEmpty(unparsedData)) { return; } // If we're not dealing with the phonetic field then check if our parsing type is // only phonetic or none at all. If either casecase then do nothing which will cause // any reference to the word cache entry's value for the field to defer to the // value that's stored in the word cache entry's owning record entry. if (field.Type != FieldType.Phonetic && (entry.DataSource.ParseType == DataSourceParseType.PhoneticOnly || entry.DataSource.ParseType == DataSourceParseType.None)) { return; } // By this time we know we're dealing with one of three conditions: 1) the // field is phonetic or 2) the field should be parsed or 3) both 1 and // 2. When the field should be parsed then split it into individual words. string[] split = (entry.DataSource.ParseType == DataSourceParseType.None ? new[] { unparsedData } : unparsedData.Split(App.BreakChars.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); for (int i = 0; i < split.Length; i++) { // Expand the capacity for more word entries if necessary. if (i == entry.WordEntries.Count) { entry.WordEntries.Add(new WordCacheEntry(entry, i)); } entry.WordEntries[i].SetValue(field.Name, split[i]); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Makes the specified field the first, or primary, field on which to sort. /// </summary> /// ------------------------------------------------------------------------------------ public bool SetPrimarySortField(PaField field, bool changeDirection) { return(SetPrimarySortField(field, changeDirection, false)); }
/// ------------------------------------------------------------------------------------ public FieldMapping(string nameInSource, PaField field, bool isParsed) { NameInDataSource = nameInSource; Field = field; IsParsed = isParsed; }
/// ------------------------------------------------------------------------------------ public FieldMapping(PaField field, bool isParsed) : this(field.Name, field, isParsed) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// parsedFields is a delimited (e.g. comma or semi-colon) string of the parsed fields. /// </summary> /// ------------------------------------------------------------------------------------ public FieldMapping(PaField field, string parsedFields) : this(field.Name, field, parsedFields.Contains(field.Name)) { }
/// ------------------------------------------------------------------------------------ public FieldMapping(PaField field, IEnumerable <string> parsedFields) : this(field, parsedFields.Contains(field.Name)) { }
/// ------------------------------------------------------------------------------------ public static bool GetIsCalculatedField(PaField field) { return(field.Name == kCVPatternFieldName || field.Name == kDataSourceFieldName || field.Name == kDataSourcePathFieldName); }
/// ------------------------------------------------------------------------------------ public SortField(PaField field, bool sortDirection) { Field = field; Ascending = sortDirection; }