private void btn_ApplyBoilerplate_Click(object sender, RibbonControlEventArgs e) { //get the text from the settings Boilerplate bp = Properties.Settings.Default.newboiler; //Find out which option is selected RibbonDropDownItem item = this.dd_Boilerplate.SelectedItem; if (bp.Dict.ContainsKey(item.Label)) { Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument; Word.Selection selection = Globals.ThisAddIn.Application.Selection; if (selection != null && selection.Range != null) { selection.Comments.Add(selection.Range, bp.Dict[item.Label].Text); } else { MessageBox.Show("Could not find any selected text or valid insertion point. Please let Aaron know!"); } } else { MessageBox.Show("An error occurred when finding your boilerplate. Please let Aaron know!"); return; } }
private Boilerplate ConvertRows() { Boilerplate bp = new Boilerplate(); foreach (DataGridViewRow row in dgv_Boiler.Rows) { if (row.IsNewRow) { continue; } string key = ""; if (row.Cells["Label"].Value == null) { throw new InvalidOperationException("Each row must have a unique name."); } else { key = row.Cells["Label"].Value.ToString(); } Comment comment = new Comment(); if ((row.Cells["Comment"].Value == null) || (String.IsNullOrEmpty(row.Cells["Comment"].Value.ToString()))) { throw new InvalidOperationException("Each row must have something in the 'Comment' field."); } else { comment.Text = row.Cells["Comment"].Value.ToString(); } bp.Dict.Add(key, comment); } return(bp); }
private void btn_BoilerSave_Click(object sender, EventArgs e) { Boilerplate bp = ConvertRows(); Properties.Settings.Default.newboiler = bp; Properties.Settings.Default.Save(); }
private void ManageBoiler_FormClosing(object sender, FormClosingEventArgs e) { Boilerplate bp = ConvertRows(); Properties.Settings.Default.newboiler = bp; Properties.Settings.Default.Save(); }
private void btn_BoilerImport_Click(object sender, EventArgs e) { Boilerplate bp = Properties.Settings.Default.newboiler; ImportDialog id = new ImportDialog(); var result = id.ShowDialog(); if (result == DialogResult.OK) { string injson = File.ReadAllText(id.GetFileName()); Boilerplate inbp = new Boilerplate(); inbp.Dict = JsonConvert.DeserializeObject <Dictionary <string, Comment> >(injson); switch (id.GetMode()) { case ImportDialog.Modes.MERGE: foreach (var kvpair in inbp.Dict) { if (bp.Dict.ContainsKey(kvpair.Key)) { bp.Dict[kvpair.Key] = kvpair.Value; } else { bp.Dict.Add(kvpair.Key, kvpair.Value); } } break; case ImportDialog.Modes.NEW: foreach (var kvpair in inbp.Dict) { if (bp.Dict.ContainsKey(kvpair.Key)) { continue; } else { bp.Dict.Add(kvpair.Key, kvpair.Value); } } break; case ImportDialog.Modes.REPLACE: bp = inbp; break; default: throw new ArgumentOutOfRangeException("Unrecognized import mode. Aborting."); } Properties.Settings.Default.newboiler = bp; Properties.Settings.Default.Save(); RefreshDisplay(); MessageBox.Show("Import complete."); } else { MessageBox.Show("Import cancelled."); } }
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value is string) { Dictionary <string, Comment> lst = JsonConvert.DeserializeObject <Dictionary <string, Comment> >(value.ToString()); Boilerplate bp = new Boilerplate(); bp.Dict = lst; return(bp); } return(base.ConvertFrom(context, culture, value)); }
private void Ribbon1_Load(object sender, RibbonUIEventArgs e) { // Check for old boilerplate and migrate it over if it exists. // This check will likely go away with the next major release. StringCollection oldbp = Properties.Settings.Default.boilerplate; if (oldbp.Count > 0) { Boilerplate bp = new Boilerplate(); Debug.WriteLine("Found old boilerplate. Moving them over."); for (int i = 0; i < oldbp.Count - 1; i += 2) { Comment c = new Comment(); c.Text = oldbp[i + 1]; bp.Dict.Add(oldbp[i], c); } Properties.Settings.Default.newboiler = bp; oldbp.Clear(); Properties.Settings.Default.boilerplate = oldbp; Properties.Settings.Default.Save(); } loadBoilerplate(); loadSearches(); //Languages Word.Languages langs = Globals.ThisAddIn.Application.Languages; List <Tuple <string, Word.Language> > langlist = new List <Tuple <string, Word.Language> >(); foreach (Word.Language lang in langs) { langlist.Add(new Tuple <string, Word.Language>(lang.NameLocal, lang)); } langlist.Sort((x, y) => x.Item1.CompareTo(y.Item1)); foreach (Tuple <string, Word.Language> lang in langlist) { RibbonDropDownItem item = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem(); item.Label = lang.Item1; item.Tag = lang.Item2.ID; dd_Langs.Items.Add(item); if (lang.Item1 == Properties.Settings.Default.lastlang) { dd_Langs.SelectedItem = item; } } uint minlen = Properties.Settings.Default.minphraselen; uint maxlen = Properties.Settings.Default.maxphraselen; edit_MinPhraseLen.Text = minlen.ToString(); edit_MaxPhraseLen.Text = maxlen.ToString(); }
public void loadBoilerplate() { dd_Boilerplate.Items.Clear(); Boilerplate bp = Properties.Settings.Default.newboiler; List <string> keys = bp.Dict.Keys.ToList(); keys.Sort(); foreach (string key in keys) { RibbonDropDownItem item = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem(); item.Label = key; dd_Boilerplate.Items.Add(item); } }
private void RefreshDisplay() { dgv_Boiler.Rows.Clear(); Boilerplate bp = Properties.Settings.Default.newboiler; if (bp != null) { foreach (KeyValuePair <string, Comment> boiler in bp.Dict) { int idx = dgv_Boiler.Rows.Add(); DataGridViewRow row = dgv_Boiler.Rows[idx]; row.Cells["Label"].Value = boiler.Key; row.Cells["Comment"].Value = boiler.Value.Text; } } }