private void btnSubEdit_Click(object sender, EventArgs e)
 {
     using (Forms.SubstitutionForm sf = new Forms.SubstitutionForm())
     {
         DataGridViewRow            r   = dgvSubstitutions.SelectedRows[0];
         Configuration.Substitution sub = subs[r.Index];
         sf.SettingsFromSubstitution(sub);
         sf.Text       = I18n.Translate("internal/UserInterface/editsubstitution", "Edit substitution '{0}'", sub.SearchFor);
         sf.btnOk.Text = I18n.Translate("internal/UserInterface/savechanges", "Save changes");
         if (sf.ShowDialog() == DialogResult.OK)
         {
             sf.SettingsToSubstitution(sub);
             subs.Sort();
             dgvSubstitutions.Refresh();
             for (int i = 0; i < subs.Count; i++)
             {
                 if (subs[i].CompareTo(sub) == 0)
                 {
                     dgvSubstitutions.ClearSelection();
                     dgvSubstitutions.Rows[i].Selected = true;
                     break;
                 }
             }
         }
     }
 }
 private void btnSubAdd_Click(object sender, EventArgs e)
 {
     using (Forms.SubstitutionForm sf = new Forms.SubstitutionForm())
     {
         sf.SettingsFromSubstitution(null);
         sf.Text       = I18n.Translate("internal/UserInterface/addsubstitution", "Add new substitution");
         sf.btnOk.Text = I18n.Translate("internal/UserInterface/add", "Add");
         if (sf.ShowDialog() == DialogResult.OK)
         {
             Configuration.Substitution sub = new Configuration.Substitution();
             sf.SettingsToSubstitution(sub);
             subs.Add(sub);
             subs.Sort();
             dgvSubstitutions.RowCount = subs.Count;
             dgvSubstitutions.Refresh();
             for (int i = 0; i < subs.Count; i++)
             {
                 if (subs[i].CompareTo(sub) == 0)
                 {
                     dgvSubstitutions.ClearSelection();
                     dgvSubstitutions.Rows[i].Selected = true;
                     break;
                 }
             }
         }
     }
 }
Esempio n. 3
0
 internal void SettingsFromSubstitution(Configuration.Substitution sub)
 {
     if (sub == null)
     {
         txtReplaceWith.Text = "";
         txtSearchFor.Text   = "";
         clbScope.ClearSelected();
     }
     else
     {
         txtReplaceWith.Text = sub.ReplaceWith;
         txtSearchFor.Text   = sub.SearchFor;
         if ((sub.Scope & Configuration.Substitution.SubstitutionScopeEnum.CaptureGroup) == Configuration.Substitution.SubstitutionScopeEnum.CaptureGroup)
         {
             clbScope.SetItemChecked(0, true);
         }
         if ((sub.Scope & Configuration.Substitution.SubstitutionScopeEnum.NumericExpression) == Configuration.Substitution.SubstitutionScopeEnum.NumericExpression)
         {
             clbScope.SetItemChecked(1, true);
         }
         if ((sub.Scope & Configuration.Substitution.SubstitutionScopeEnum.StringExpression) == Configuration.Substitution.SubstitutionScopeEnum.StringExpression)
         {
             clbScope.SetItemChecked(2, true);
         }
         if ((sub.Scope & Configuration.Substitution.SubstitutionScopeEnum.TextToSpeech) == Configuration.Substitution.SubstitutionScopeEnum.TextToSpeech)
         {
             clbScope.SetItemChecked(3, true);
         }
     }
 }
        private void dgvSubstitutions_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
        {
            if (e.RowIndex >= subs.Count)
            {
                return;
            }
            Configuration.Substitution sub = subs.ElementAt(e.RowIndex);
            switch (e.ColumnIndex)
            {
            case 0:
                e.Value = sub.SearchFor;
                break;

            case 1:
                e.Value = sub.ReplaceWith;
                break;

            case 2:
            {
                List <string> items = new List <string>();
                if ((sub.Scope & Configuration.Substitution.SubstitutionScopeEnum.CaptureGroup) == Configuration.Substitution.SubstitutionScopeEnum.CaptureGroup)
                {
                    items.Add(I18n.Translate("internal/ConfigurationForm/subsregexgroup", "capture groups"));
                }
                if ((sub.Scope & Configuration.Substitution.SubstitutionScopeEnum.NumericExpression) == Configuration.Substitution.SubstitutionScopeEnum.NumericExpression)
                {
                    items.Add(I18n.Translate("internal/ConfigurationForm/subsnumexpr", "numeric expressions"));
                }
                if ((sub.Scope & Configuration.Substitution.SubstitutionScopeEnum.StringExpression) == Configuration.Substitution.SubstitutionScopeEnum.StringExpression)
                {
                    items.Add(I18n.Translate("internal/ConfigurationForm/subsstrexpr", "string expressions"));
                }
                if ((sub.Scope & Configuration.Substitution.SubstitutionScopeEnum.TextToSpeech) == Configuration.Substitution.SubstitutionScopeEnum.TextToSpeech)
                {
                    items.Add(I18n.Translate("internal/ConfigurationForm/substts", "text to speech"));
                }
                if (items.Count > 0)
                {
                    e.Value = Capitalize(String.Join(", ", items));
                }
                else
                {
                    e.Value = I18n.Translate("internal/ConfigurationForm/subsnone", "None (inactive)");
                }
            }
            break;
            }
        }
Esempio n. 5
0
 internal void SettingsToSubstitution(Configuration.Substitution sub)
 {
     sub.ReplaceWith = txtReplaceWith.Text;
     sub.SearchFor   = txtSearchFor.Text;
     Configuration.Substitution.SubstitutionScopeEnum scope = 0;
     if (clbScope.GetItemChecked(0) == true)
     {
         scope |= Configuration.Substitution.SubstitutionScopeEnum.CaptureGroup;
     }
     if (clbScope.GetItemChecked(1) == true)
     {
         scope |= Configuration.Substitution.SubstitutionScopeEnum.NumericExpression;
     }
     if (clbScope.GetItemChecked(2) == true)
     {
         scope |= Configuration.Substitution.SubstitutionScopeEnum.StringExpression;
     }
     if (clbScope.GetItemChecked(3) == true)
     {
         scope |= Configuration.Substitution.SubstitutionScopeEnum.TextToSpeech;
     }
     sub.Scope = scope;
 }