private void ThisAddIn_Startup(object sender, System.EventArgs e) { //Cheks if the folder/file exists or not and if not creates them string strPath = System.AppDomain.CurrentDomain.BaseDirectory + "/templates"; string fname = System.AppDomain.CurrentDomain.BaseDirectory + "/templates/table.txt"; FileStream fs = null; if (!(Directory.Exists(strPath))) { Directory.CreateDirectory(strPath); fs = new FileStream(fname, FileMode.CreateNew); fs.Close(); } else if (!(File.Exists(fname))) { fs = new FileStream(fname, FileMode.CreateNew); fs.Close(); } string[] fn = { "Opening template", "Closing template" }; string temp1 = System.AppDomain.CurrentDomain.BaseDirectory + "/templates/id0.msg"; string temp2 = System.AppDomain.CurrentDomain.BaseDirectory + "/templates/id1.msg"; if (!(File.Exists(temp1)) && (!(File.Exists(temp2)))) { func f = new func(); f.writedefault(fn); f.writecont(fn[0]); f.writecont(fn[1]); } }
private void Delete_Click(object sender, EventArgs e) { if (textBox1.Text.Length == 0) { MessageBox.Show("Please enter the entry to be deleted", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { func f = new func(); f.deleteabbr(textBox1.Text); this.Close(); } }
//To add an autocorrect entry private void Add_Click(object sender, EventArgs e) { if (textBox1.Text.Equals("") || textBox2.Text.Equals("")) { MessageBox.Show("Please enter Abbreviation/expansion", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { string ab, ex; ab = textBox1.Text; ex = textBox2.Text; func f1 = new func(); f1.handleabbr(ab, ex); this.Close(); } }
//To create a new template. private void Create_Click(object sender, EventArgs e) { string fn; if (textBox1.Text.Equals("")) { MessageBox.Show("Please enter the File name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { fn = textBox1.Text; int flag = 0; string strPath = System.AppDomain.CurrentDomain.BaseDirectory; StreamReader rdr = new StreamReader(strPath + "/templates/table.txt"); string str, substr; while (rdr.EndOfStream != true) { str = rdr.ReadLine(); substr = str.Substring(str.IndexOf(',') + 1); if (fn.Equals(substr)) { flag = 1; break; } } rdr.Close(); //The typed in name is checked with the existing template names. if (flag == 1) { MessageBox.Show("A template already exists with the mentioned name. Change template name completely!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Type the contents of your template and click save template in the Templates tab to save the newly created template", "Information", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); this.Close(); func f = new func(); f.createmi(fn); } } }
//Create callback methods here. For more information about adding callback methods, visit http://go.microsoft.com/fwlink/?LinkID=271226 public void Ribbon_Load(Office.IRibbonUI ribbonUI) { this.ribbon = ribbonUI; f = new func(); }