Beispiel #1
0
        private void button5_AddNewString_Click(object sender, EventArgs e)
        {
            int max = 0;

            foreach (Stringrec sr in items)
            {
                max = Math.Max(max, sr.Id);
            }

            Stringrec nr = new Stringrec();

            nr.Id = max + 1;
            items.Add(nr);

            ListViewItem lvi = new ListViewItem();

            lvi.Text = nr.Id.ToString();
            lvi.Tag  = nr;
            lvi.SubItems.Add("");
            lvi.SubItems.Add("");
            lvi.SubItems.Add("");
            lvi.SubItems.Add("");
            nr.lvi = lvi;
            updateHighlight(lvi);
            listView1.Items.Add(lvi);
            listView1.EnsureVisible(lvi.Index);
            lvi.Selected = true;
            loadItem();
            richTextBox1.Focus();
        }
Beispiel #2
0
        private void readFile(string fileName)
        {
            label3.Text = fileName;
            string bakPath = fileName + ".bak";
            string bakText = File.ReadAllText(fileName);

            File.WriteAllText(bakPath, bakText);
            using (StreamReader sr = new StreamReader(fileName))
            {
                string s = sr.ReadLine();
                while (s != null)
                {
                    string [] parts = s.Split('\t');
                    if (parts.Length > 1)
                    {
                        if (parts[0] == "lang")
                        {
                            textBox1.Text = Stringrec.getUnicodeFromHtml(parts[1]);
                        }
                        else if (parts[0] == "langid")
                        {
                            textBox3.Text = parts[1];
                        }
                        else
                        {
                            setItem(new Stringrec(parts));
                        }
                    }
                    s = sr.ReadLine();
                }
            }
        }
Beispiel #3
0
 private void setItem(Stringrec sr)
 {
     while (items.Count <= sr.Id)
     {
         items.Add(new Stringrec());
     }
     items[sr.Id] = sr;
 }
Beispiel #4
0
 private void loadItem()
 {
     if (currItem != null)
     {
         Stringrec sr = currItem.Tag as Stringrec;
         richTextBox1.Text = sr.Text;
         richTextBox2.Text = sr.OriginalText;
         richTextBox3.Text = sr.Description;
         textBox2.Text     = sr.Key;
     }
 }
Beispiel #5
0
 private void listView2_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listView2.SelectedItems.Count > 0)
     {
         ListViewItem lvi = listView2.SelectedItems[0];
         Stringrec    sr  = lvi.Tag as Stringrec;
         if (sr != null)
         {
             listView1.EnsureVisible(sr.lvi.Index);
         }
     }
 }
Beispiel #6
0
 private void saveFile()
 {
     saveItem();
     using (StreamWriter sw = new StreamWriter(label3.Text))
     {
         sw.WriteLine("lang\t{0}", Stringrec.getHtmlFromUnicode(textBox1.Text));
         sw.WriteLine("langid\t{0}", textBox3.Text);
         foreach (Stringrec sr in items)
         {
             if (sr.Id >= 0)
             {
                 sw.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", sr.Id, sr.TextHtml, sr.KeyHtml, sr.DescriptionHtml, sr.OriginalTextHtml);
             }
         }
     }
 }
Beispiel #7
0
        private void saveItem()
        {
            if (currItem != null)
            {
                Stringrec sr = currItem.Tag as Stringrec;
                sr.Text         = richTextBox1.Text;
                sr.OriginalText = richTextBox2.Text;
                sr.Description  = richTextBox3.Text;
                sr.Key          = textBox2.Text;

                if (sr.OriginalText.Length == 0)
                {
                    sr.OriginalText = sr.Text;
                }

                currItem.SubItems[1].Text = sr.Text;
                currItem.SubItems[2].Text = sr.Key;
                currItem.SubItems[3].Text = sr.Description;
                currItem.SubItems[4].Text = sr.OriginalText;
                updateHighlight(currItem);
            }
        }
Beispiel #8
0
 private void button3_Click(object sender, EventArgs e)
 {
     // import english original from file
     if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         using (StreamReader sr = new StreamReader(openFileDialog1.FileName))
         {
             string s = sr.ReadLine();
             while (s != null)
             {
                 string[] parts = s.Split('\t');
                 if (parts.Length > 1)
                 {
                     if (parts[0] == "lang")
                     {
                     }
                     else if (parts[0] == "langid")
                     {
                     }
                     else
                     {
                         Stringrec nx = new Stringrec(parts);
                         Stringrec ex = findItem(items, nx.Id);
                         if (ex != null)
                         {
                             ex.OriginalText = nx.Text;
                             if (ex.lvi != null)
                             {
                                 ex.lvi.SubItems[4].Text = nx.Text;
                             }
                         }
                     }
                 }
                 s = sr.ReadLine();
             }
         }
     }
 }
Beispiel #9
0
 private void button6_Click(object sender, EventArgs e)
 {
     // import english original from file
     if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         saveItem();
         currItem = null;
         using (StreamReader sr = new StreamReader(openFileDialog1.FileName))
         {
             string s = sr.ReadLine();
             while (s != null)
             {
                 string[] parts = s.Split('\t');
                 if (parts.Length > 1)
                 {
                     if (parts[0] == "lang")
                     {
                     }
                     else if (parts[0] == "langid")
                     {
                     }
                     else
                     {
                         Stringrec nx = new Stringrec(parts);
                         Stringrec ex = findItem(items, nx.Id);
                         if (ex == null)
                         {
                             setItem(nx);
                         }
                     }
                 }
                 s = sr.ReadLine();
             }
         }
         updateListView();
     }
 }