/// ------------------------------------------------------------------------------------ /// <summary> /// Make sure the cells for fields that can't be parsed or interlinear are set to /// readonly. /// </summary> /// ------------------------------------------------------------------------------------ protected override void OnCellFormatting(DataGridViewCellFormattingEventArgs e) { if (e.RowIndex >= 0 && e.ColumnIndex >= 0) { var mapping = m_mappings[e.RowIndex]; var type = GetTypeAtOrDefault(e.RowIndex); var readOnly = false; switch (Columns[e.ColumnIndex].Name) { case "fieldtype": readOnly = mapping.Field != null && m_defaultFields.Any(f => f.Name == mapping.Field.Name); break; case "parsed": readOnly = (!PaField.GetIsTypeParsable(type) || (mapping.Field != null && mapping.Field.Type == FieldType.Phonetic)); break; case "interlinear": readOnly = !PaField.GetIsTypeInterlinearizable(type); break; } this[e.ColumnIndex, e.RowIndex].ReadOnly = readOnly; } base.OnCellFormatting(e); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the writing systems appropriate for the specified field. /// </summary> /// ------------------------------------------------------------------------------------ private KeyValuePair <object, IEnumerable <object> > GetFieldsDropDownItems(PaField field) { var fieldsAlreadyMapped = new List <PaField>(); for (int i = 0; i < NewRowIndex; i++) { fieldsAlreadyMapped.Add(GetFieldAt(i)); } if (field != null) { fieldsAlreadyMapped.Remove(field); } var fldList = from fld in m_potentialFields where !fieldsAlreadyMapped.Any(f => f.Name == fld.Name) && (Fw7DataSourcePropertiesDlg.m_selectedvernacularItem.Name == FwDBUtils.PhoneticStorageMethod.LexemeForm.ToString() || fld.Name != Fw7DataSourcePropertiesDlg.m_selectedvernacularItem.Name) orderby fld.DisplayName select fld.DisplayName; return(new KeyValuePair <object, IEnumerable <object> >( field == null ? null : field.DisplayName, fldList.Cast <object>())); }
/// ------------------------------------------------------------------------------------ public void Read(RecordCache recCache) { var allLexEntries = FwDBUtils.GetLexEntriesFromFw7Project(m_fwDsInfo).ToArray(); if (allLexEntries == null) { return; } m_worker.ReportProgress(allLexEntries.Length, m_dataSource.DisplayTextWhenReading); var customnames = m_customfield.FieldNames(); foreach (var lxEntry in allLexEntries) { m_worker.ReportProgress(0); var entry = ReadSingleLexEntry(lxEntry); if (entry != null) { var customvalues = m_customfield.CustomValues.FindAll(m => m.Guid == lxEntry.Guid.ToString()); SetCustomFieldsforEntry(customnames, customvalues, entry); if (m_dataSource.FwDataSourceInfo != null && m_dataSource.FwDataSourceInfo.PhoneticSourceField != null) { var vernacularMapping = new PaField(m_dataSource.FwDataSourceInfo.PhoneticSourceField); entry.SetValue(PaField.kPhoneticSourceFieldName.ToString(CultureInfo.InvariantCulture), m_fwDsInfo.PhoneticStorageMethod != FwDBUtils.PhoneticStorageMethod.PronunciationField && m_fwDsInfo.PhoneticStorageMethod != FwDBUtils.PhoneticStorageMethod.AllPronunciationFields ? vernacularMapping.Name : m_fwDsInfo.PhoneticStorageMethod.ToString()); } recCache.Add(entry); } } m_dataSource.UpdateLastModifiedTime(); }
/// ------------------------------------------------------------------------------------ private void HandleVernacularOptionsChanged(object sender, EventArgs e) { m_dirty = true; if (!cboPronunciationOptions.Enabled) { m_selectedvernacularItem = m_potentialVernacularFields.First(f => f.Name == cboVernacularOptions.SelectedItem); } }
/// ------------------------------------------------------------------------------------ protected override void AddColumns() { m_displayableFieldTypes = PaField.GetDisplayableFieldTypes().ToDictionary(kvp => kvp.Key, kvp => kvp.Value); // Create source field column. DataGridViewColumn col = CreateTextBoxColumn("srcfield"); col.ReadOnly = true; Columns.Add(col); if (m_sourceFieldColumnHeadingTextHandler != null) { col.HeaderText = m_sourceFieldColumnHeadingTextHandler(); } if (m_sourceFieldColumnHeadingTextHandler == null || string.IsNullOrEmpty(col.HeaderText)) { col.HeaderText = LocalizationManager.GetString( "DialogBoxes.SfmDataSourcePropertiesDlg.FieldMappingGrid.ColumnHeadings.Field", "Field in Source Data", null, col); } // Create the column for the arrow. col = CreateImageColumn("arrow"); col.HeaderText = string.Empty; col.ReadOnly = true; col.Width = Properties.Resources.FieldMappingArrow.Width + 6; col.Resizable = DataGridViewTriState.False; col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; Columns.Add(col); base.AddColumns(); // Create field type column. col = CreateDropDownListComboBoxColumn("fieldtype", m_displayableFieldTypes.Values); int i = FontColumnIndex; Columns.Insert(FontColumnIndex, col); col.HeaderText = LocalizationManager.GetString( "DialogBoxes.SfmDataSourcePropertiesDlg.FieldMappingGrid.ColumnHeadings.Type", "Type", null, col); // Create the parsed column. col = CreateCheckBoxColumn("parsed"); Columns.Insert(i, col); col.HeaderText = LocalizationManager.GetString( "DialogBoxes.SfmDataSourcePropertiesDlg.FieldMappingGrid.ColumnHeadings.IsParsed", "Is Parsed?", null, col); // Create the interlinear column. col = CreateCheckBoxColumn("interlinear"); Columns.Insert(i, col); col.HeaderText = LocalizationManager.GetString( "DialogBoxes.SfmDataSourcePropertiesDlg.FieldMappingGrid.ColumnHeadings.CanBeInterlinear", "Is Interlinear?", null, col); }
/// ------------------------------------------------------------------------------------ public void SetFieldWorksDefaults(string fwProject) { txtProjName.Text = Path.GetFileNameWithoutExtension(fwProject); var isoCode = new ParseFwXml(fwProject).Code; txtLanguageCode.Text = isoCode; txtLanguageName.Text = new WritingSystemDefinition(isoCode).Language.Name; _dataSources.Add(new PaDataSource(PaField.GetDefaultFields(new Fw7CustomField(null)), new FwDataSourceInfo(fwProject, null, DataSourceType.FW7))); LoadGrid(-1); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Verify everything. /// </summary> /// ------------------------------------------------------------------------------------ protected override bool Verify() { // Commit pending changes in the grid. m_fieldsGrid.CommitEdit(DataGridViewDataErrorContexts.Commit); // Make sure the record marker was specified. if (cboRecordMarkers.SelectedItem == null) { return(ShowError(cboRecordMarkers, LocalizationManager.GetString( "DialogBoxes.SFDataSourcePropertiesDlg.MissingRecordMarkerSpecificationMsg", "You must specify a record marker to identify the beginning of each record."))); } // Make sure a phonetic mapping is specified. if (!FieldMapping.IsPhoneticMapped(m_fieldsGrid.Mappings, true)) { m_fieldsGrid.Focus(); return(false); } // Make sure no field is mapped more than once. if (m_fieldsGrid.GetAreAnyFieldsMappedMultipleTimes()) { return(ShowError(m_fieldsGrid, LocalizationManager.GetString( "DialogBoxes.SFDataSourcePropertiesDlg.MultipleMappingsForSingleFieldMsg", "Each field may only be mapped once."))); } // Make sure the phonetic field is not mapped more than once. if (m_fieldsGrid.GetIsPhoneticMappedMultipleTimes()) { return(ShowError(m_fieldsGrid, LocalizationManager.GetString( "DialogBoxes.SFDataSourcePropertiesDlg.MultiplePhoneticMappingsMsg", "You may only map the phonetic field once.\nA phonetic mapping is specified using the field type."))); } // Make sure the field specified as the toolbox sort field is mapped to a marker. if (ToolBoxSortField != null && !m_fieldsGrid.GetIsSourceFieldMapped(ToolBoxSortField)) { return(ShowError(cboToolboxSortField, LocalizationManager.GetString( "DialogBoxes.SFDataSourcePropertiesDlg.InvalidToolboxSortFieldSpecifiedMsg", "The first Toolbox sort field marker specified was\nnot mapped. It must have a mapping."))); } foreach (var mapping in m_fieldsGrid.Mappings.Where(m => PaField.GetIsReservedFieldName(m.Field.Name))) { return(ShowError(m_fieldsGrid, string.Format(LocalizationManager.GetString( "DialogBoxes.SFDataSourcePropertiesDlg.InvalidFieldNameSpecifiedMsg", "The field name '{0}' is reserved and cannot be used.\nEnter a different name."), mapping.Field.DisplayName))); } return(VerifyInterlinearInfo()); }
/// ------------------------------------------------------------------------------------ public SfmFieldMappingGrid(IEnumerable <PaField> potentialFields, IEnumerable <FieldMapping> mappings, Func <string> srcFldColHdgTextHandler, Func <string> tgtFldColHdgTextHandler) { m_sourceFieldColumnHeadingTextHandler = srcFldColHdgTextHandler; m_targetFieldColumnHeadingTextHandler = tgtFldColHdgTextHandler; m_potentialFields = potentialFields; m_mappings = mappings.ToList(); m_defaultFields = PaField.GetDefaultFields(); ShowFontColumn(false); RowCount = m_mappings.Count; }
public override void FixtureSetup() { base.FixtureSetup(); _dataSource = new PaDataSource(); _dataSource.Type = DataSourceType.Toolbox; _phoneticField = _prj.Fields.Single(f => f.Type == FieldType.Phonetic); _cvField = _prj.Fields.Single(f => f.Name == PaField.kCVPatternFieldName); _dataSource.FieldMappings = new System.Collections.Generic.List <FieldMapping>(); _dataSource.FieldMappings.Add(new FieldMapping("\\ph", _phoneticField, true)); _dataSource.FieldMappings.Add(new FieldMapping("\\cv", _cvField, true)); }
/// ------------------------------------------------------------------------------------ protected override IEnumerable <string> GetWritingSystemsForField(PaField field) { if (field.FwWsType == FwDBUtils.FwWritingSystemType.None || field.FwWsType == FwDBUtils.FwWritingSystemType.CmPossibility) { yield return(GetNoWritingSystemText()); } else { foreach (var wsName in m_writingSystems.Where(ws => ws.Type == field.FwWsType).Select(ws => ws.Name)) { yield return(wsName); } } }
/// ------------------------------------------------------------------------------------ protected virtual IEnumerable <string> GetWritingSystemsForField(PaField field) { if (field.Type != FieldType.Phonetic) { yield return(GetNoWritingSystemText()); } var wsValidType = (field.FwWsType == FwDBUtils.FwWritingSystemType.Vernacular ? FwDBUtils.FwWritingSystemType.Vernacular : FwDBUtils.FwWritingSystemType.Analysis); foreach (var wsName in m_writingSystems.Where(ws => ws.Type == wsValidType).Select(ws => ws.Name)) { yield return(wsName); } }
/// ------------------------------------------------------------------------------------ private void InitializePhoneticAndAudioFieldInfo() { var vernOptions = m_potentialVernacularFields.Select(f => f.Name).ToArray(); cboVernacularOptions.Items.AddRange(vernOptions); cboVernacularOptions.SelectedItem = null; if (m_vernacularMapping != null) { cboVernacularOptions.SelectedItem = vernOptions.FirstOrDefault(v => v == m_vernacularMapping.NameInDataSource); m_selectedvernacularItem = m_vernacularMapping.Field; } if (cboVernacularOptions.SelectedItem == null) { cboVernacularOptions.SelectedItem = vernOptions.Contains("LexemeForm") ? "LexemeForm" : cboVernacularOptions.Items[0]; m_selectedvernacularItem = m_potentialVernacularFields.FirstOrDefault(v => v.Name == "LexemeForm"); } cboPhoneticWritingSystem.Items.AddRange(m_datasource.FwDataSourceInfo.GetWritingSystems() .Where(ws => ws.Type == FwDBUtils.FwWritingSystemType.Vernacular) .Select(ws => ws.Name).ToArray()); // Set the phonetic writing system combo's initial value. var writingSystems = m_datasource.FwDataSourceInfo.GetWritingSystems().ToArray(); var fwws = writingSystems.SingleOrDefault(ws => ws.Id == m_phoneticMapping.FwWsId); cboPhoneticWritingSystem.SelectedItem = (fwws != null ? fwws.Name : cboPhoneticWritingSystem.Items[0]); InitializePronunciationCombo(); if (m_datasource.FwDataSourceInfo.PhoneticStorageMethod == FwDBUtils.PhoneticStorageMethod.PronunciationField) { cboPronunciationOptions.SelectedIndex = 0; } else if (m_datasource.FwDataSourceInfo.PhoneticStorageMethod == FwDBUtils.PhoneticStorageMethod.AllPronunciationFields) { cboPronunciationOptions.SelectedIndex = 1; } rbVernForm.Checked = (m_datasource.FwDataSourceInfo.PhoneticStorageMethod == FwDBUtils.PhoneticStorageMethod.LexemeForm); rbPronunField.Checked = (m_datasource.FwDataSourceInfo.PhoneticStorageMethod != FwDBUtils.PhoneticStorageMethod.LexemeForm); // update audio WS in case it changed or has now been defined var audioWs = FwDBUtils.GetDefaultAudioWritingSystem(writingSystems); m_audioFileMapping.FwWsId = audioWs != null ? audioWs.Id : null; }
/// ------------------------------------------------------------------------------------ private void SaveAudioFileInfo(RecordCacheEntry recCacheEntry, PaField audioFilefield, string fieldData) { long start, end; var fileName = GetAudioFileInfo(fieldData, out start, out end); if (fileName == null) { return; } var length = end - start; recCacheEntry.AudioOffset = start; recCacheEntry.AudioLength = length; recCacheEntry.SetValue(audioFilefield.Name, fileName); }
/// ------------------------------------------------------------------------------------ protected ExporterBase(PaProject project, string outputFileName, OutputFormat outputFormat, DataGridView dgrid) : this(project) { m_outputFileName = outputFileName; m_outputFormat = outputFormat; m_grid = dgrid; var grid = m_grid as PaWordListGrid; if (grid == null) { return; } if (grid.Cache.IsMinimalPair || grid.Cache.IsSimilarEnvironment) { m_groupByColumn = grid.PhoneticColumn; } else if (grid.IsGroupedByField) { m_groupByColumn = grid.GroupByColumn; } m_isGridGrouped = (grid.Columns[0] is SilHierarchicalGridColumn && m_groupByColumn != null); if (m_isGridGrouped) { int groupByColIndex = m_groupByColumn.DisplayIndex; // Subtract on at the end to account for the column containing the // expand/collapse glyph. That doesn't count in the col. span. m_leftColSpanForGroupedList = (from x in m_grid.Columns.Cast <DataGridViewColumn>() where x.Visible && x.DisplayIndex < groupByColIndex select x).Count() - 1; m_rightColSpanForGroupedList = (from x in m_grid.Columns.Cast <DataGridViewColumn>() where x.Visible && x.DisplayIndex > groupByColIndex select x).Count(); var field = project.GetPhoneticField(); m_groupByField = (grid.Cache.IsMinimalPair || grid.Cache.IsSimilarEnvironment ? field : ((PaWordListGrid)m_grid).GroupByField); m_groupedFieldName = ProcessHelper.MakeAlphaNumeric(m_groupByField.DisplayName); } }
/// ------------------------------------------------------------------------------------ private void fldSelGridSrchCols_AfterUserChangedValue(PaField field, bool selectAllValueChanged, bool newValue) { if (selectAllValueChanged || field.Type == FieldType.Phonetic) { // Disable chkMatchCase if the "Select All" or phonetic field is checked. chkMatchCase.Enabled = !newValue; if (chkMatchCase.Enabled) { chkMatchCase.Checked = m_prevMatchCaseValue; } else { m_prevMatchCaseValue = chkMatchCase.Checked; chkMatchCase.Checked = false; } } // Enable the Find button if any columns are checked btnFind.Enabled = (fldSelGridSrchCols.CheckedItemCount > 0); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Make sure any field that can't be marked as parsed or interlinear has it's check /// box painted over so the check box cannot be seen. /// </summary> /// ------------------------------------------------------------------------------------ protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e) { base.OnCellPainting(e); if (e.RowIndex < 0 || e.ColumnIndex < 0) { return; } var colName = Columns[e.ColumnIndex].Name; var type = GetTypeAtOrDefault(e.RowIndex); if (!("parsed interlinear").Contains(colName) || (colName == "parsed" && PaField.GetIsTypeParsable(type)) || (colName == "interlinear" && PaField.GetIsTypeInterlinearizable(type))) { return; } var parts = e.PaintParts & ~DataGridViewPaintParts.ContentForeground; e.Paint(e.ClipBounds, parts); e.Handled = true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the value for the field specified by fieldInfo /// </summary> /// ------------------------------------------------------------------------------------ public string this[PaField field] { get { return(field == null ? null : this[field.Name]); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the writing systems appropriate for the specified field. /// </summary> /// ------------------------------------------------------------------------------------ protected virtual KeyValuePair <object, IEnumerable <object> > GetWritingSystemDropDownItems(PaField field) { var wslist = (field == null ? new List <string>(0) : GetWritingSystemsForField(field)); var currWs = (m_mappings.Count == CurrentCellAddress.Y) ? null : m_writingSystems.SingleOrDefault(ws => ws.Id == m_mappings[CurrentCellAddress.Y].FwWsId); object currValue = 0; if (currWs != null) { currValue = currWs.Name; } return(new KeyValuePair <object, IEnumerable <object> >(currValue, wslist.Cast <object>())); }
/// ------------------------------------------------------------------------------------ private void UpdateFields() { var fldInfoFilePath = _projectPathPrefix + "FieldInfo.xml"; if (!File.Exists(fldInfoFilePath)) { return; } var xmlFieldInfo = XElement.Load(fldInfoFilePath); foreach (var element in xmlFieldInfo.Elements()) { string newName = null; switch (element.Attribute("Name").Value) { case "Secondary Gloss": newName = "Gloss-Secondary"; break; case "Other Gloss": newName = "Gloss-Other"; break; case "Part of Speech": newName = "PartOfSpeech"; break; case "CV Pattern": newName = PaField.kCVPatternFieldName; break; case "Free Translation": newName = "FreeFormTranslation"; break; case "Notebook Ref.": newName = "NoteBookReference"; break; case "Ethnologue Id": newName = "EthnologueId"; break; case "Language Name": newName = "LanguageName"; break; case "Speaker": newName = "SpeakerName"; break; case "Speaker's Gender": newName = "SpeakerGender"; break; case "Comment": newName = "Note"; break; case "Data Source": newName = PaField.kDataSourceFieldName; break; case "Data Source Path": newName = PaField.kDataSourcePathFieldName; break; case "Audio File": newName = "AudioFile"; break; } if (newName != null) { element.Attribute("Name").Value = newName; } } xmlFieldInfo.Save(fldInfoFilePath); UpdateProjectMappingsIsParsedValuesFromOldFieldInfo(xmlFieldInfo); CreateFieldDisplayPropsFile(fldInfoFilePath); var newFieldsFilePath = PaField.GetFileForProject(_projectPathPrefix); File.Move(fldInfoFilePath, newFieldsFilePath); var error = TransformFile(newFieldsFilePath, "SIL.Pa.Model.Migration.UpdateFieldInfo.xslt"); if (error != null) { throw error; } try { File.Delete(newFieldsFilePath); } catch { } }