private void treeViewLanguages_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { ContextMenu cm = new ContextMenu(); MenuItem mi = new MenuItem("Add languages", mi_addLanguages); cm.MenuItems.Add(mi); if (treeViewLanguages.Nodes.Count > 1) { TreeNode nd = treeViewLanguages.GetNodeAt(e.X, e.Y); if (nd != null) { TreeNodeCulture tnc = nd as TreeNodeCulture; if (tnc != null) { mi = new MenuItem(string.Format(CultureInfo.InvariantCulture, "Remove language {0} ({1})", tnc.Culture.Name, tnc.Culture.NativeName), mi_removeLanguage); mi.Tag = tnc; cm.MenuItems.Add(mi); if (treeViewLanguages.SelectedNode != nd) { treeViewLanguages.SelectedNode = nd; } } } } cm.Show(treeViewLanguages, new Point(e.X, e.Y)); } }
private void mi_removeLanguage(object sender, EventArgs e) { MenuItem mi = sender as MenuItem; if (mi != null) { TreeNodeCulture tnc = mi.Tag as TreeNodeCulture; if (tnc != null) { if (MessageBox.Show(this, string.Format(CultureInfo.InvariantCulture, "Do you want to remove language {0} ({1})", tnc.Culture.Name, tnc.Culture.NativeName), this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { XmlUtil.RemoveLanguage(_projectResourcesNode, tnc.Culture.Name); _changed = true; int n = tnc.Index; tnc.Remove(); if (n < treeViewLanguages.Nodes.Count) { treeViewLanguages.SelectedNode = treeViewLanguages.Nodes[n]; } else { if (treeViewLanguages.Nodes.Count > 0) { treeViewLanguages.SelectedNode = treeViewLanguages.Nodes[treeViewLanguages.Nodes.Count - 1]; } else { showData(); } } } } } }
private void buttonLanguage_Click(object sender, EventArgs e) { TreeNodeCulture tnc = treeViewLanguages.SelectedNode as TreeNodeCulture; CultureInfo current = null; if (tnc != null) { current = tnc.Culture; } StringCollection sc = DlgLanguages.SelectLanguages(this, XmlUtil.GetLanguages(_projectResourcesNode)); if (sc != null) { if (sc.Count == 0) { MessageBox.Show(this, "Do not remove all languages", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { XmlUtil.UpdateLanguages(_projectResourcesNode, sc); updateLanguagesNodes(current); _changed = true; } } }
private void updateLanguagesNodes(CultureInfo current) { treeViewLanguages.Nodes.Clear(); IList <string> lnames = XmlUtil.GetLanguages(_projectResourcesNode); foreach (string s in lnames) { try { CultureInfo ci = new CultureInfo(s); TreeNodeCulture tn = new TreeNodeCulture(ci, imageList1); treeViewLanguages.Nodes.Add(tn); if (current != null) { if (string.CompareOrdinal(ci.Name, current.Name) == 0) { treeViewLanguages.SelectedNode = tn; } } } catch { } } if (treeViewLanguages.SelectedNode == null) { if (treeViewLanguages.Nodes.Count > 0) { treeViewLanguages.SelectedNode = treeViewLanguages.Nodes[0]; } } }
private void treeViewLanguages_AfterSelect(object sender, TreeViewEventArgs e) { TreeNodeCulture tnc = e.Node as TreeNodeCulture; if (tnc != null) { showCulture(tnc.Culture); showData(); } else { Text = _baseCaption; } }
private void showData() { CultureInfo cultrue = null; WebDataTable table = null; TreeNodeCulture tnc = treeViewLanguages.SelectedNode as TreeNodeCulture; if (tnc != null) { cultrue = tnc.Culture; TreeNodeData tnd = treeViewDataSet.SelectedNode as TreeNodeData; if (tnd != null) { table = tnd.Table; } } _currentProperty = null; dataGridView1.DataSource = null; dataGridView1.DataBindings.Clear(); dataGridView1.Columns.Clear(); if (cultrue != null && table != null) { showCulture(cultrue); table.CurrentCulture = cultrue.Name; WebDataTableSingleRow singleRow = table as WebDataTableSingleRow; if (singleRow != null) { propertyGrid1.SelectedObject = singleRow; propertyGrid1.Visible = true; // dataGridView1.Visible = false; } else { dataGridView1.Visible = true; propertyGrid1.Visible = false; dataGridView1.DataSource = table.CreateDataTable(cultrue.Name); } } else { propertyGrid1.SelectedObject = null; } }