void UpdateList()
        {
            if (displayedHashCode == ComponentManager.Localization.GetCurrentHashcode())
            {
                return;
            }
            displayedHashCode = ComponentManager.Localization.GetCurrentHashcode();
            listStore.Clear();

            Dictionary <string, Localization.Node> dn = ComponentManager.Localization.GetDefaultNodes();

            foreach (Localization.Node node in dn.Values)
            {
                Gtk.TreeIter iter = listStore.Append();
                listStore.SetValue(iter, nodeIndex, node);
                listStore.SetValue(iter, keyIndex, node.Key);
                listStore.SetValue(iter, usValueIndex, node.Value);

                Localization.Node ln = ComponentManager.Localization.FindCurrentNode(node.Key);
                if (ln != null)
                {
                    listStore.SetValue(iter, localValueIndex, ln.Value);
                }
            }
        }
        void buttonTranslate_Clicked(object sender, EventArgs e)
        {
            Gtk.TreeSelection selection = treeview1.Selection;
            Gtk.TreeModel     model;
            Gtk.TreeIter      iter;
            if (selection.GetSelected(out model, out iter))
            {
                Localization.Node usNode      = listStore.GetValue(iter, nodeIndex) as Localization.Node;
                Localization.Node currentNode = ComponentManager.Localization.FindCurrentNode(usNode.Key);
                if (usNode == null)
                {
                    return;
                }

                string translation = TranslateGoogle(usNode.Value, ComponentManager.Localization.DefaultLanguageCode, ComponentManager.Localization.CurrentLanguageCode);
                if (string.IsNullOrWhiteSpace(translation))
                {
                    return;
                }
                string reverted = TranslateGoogle(translation, ComponentManager.Localization.CurrentLanguageCode, ComponentManager.Localization.DefaultLanguageCode);

                ComponentManager.MessageWriteLine("Translate {0}-{1} '{2}' -> '{3}'", ComponentManager.Localization.DefaultLanguageCode, ComponentManager.Localization.CurrentLanguageCode, usNode.Value, translation);
                ComponentManager.MessageWriteLine("Translate {0}-{1} '{2}' -> '{3}'", ComponentManager.Localization.CurrentLanguageCode, ComponentManager.Localization.DefaultLanguageCode, translation, reverted);

                if (currentNode != null && currentNode.Value.Length > 0)
                {
                    if (ResponseType.Yes != MessageBox.Show(null, MessageType.Question,
                                                            ButtonsType.YesNo,
                                                            "Overwrite value with new translation ?".FormatLocalizedWithPrefix(this)))
                    {
                        return;
                    }
                }

                listStore.SetValue(iter, localValueIndex, translation);

                if (currentNode != null)
                {
                    currentNode.Value = translation;
                }
                else
                {
                    Localization.Node newNode = new Localization.Node(usNode.Key, translation, "", usNode.Base, "", "");
                    ComponentManager.Localization.AddNewCurrentNode(newNode);
                }
                ComponentManager.UpdateLanguage(true);
                UpdateChangeCount();
            }
        }
        void buttonTranslateAll_Clicked(object sender, EventArgs e)
        {
            if (ResponseType.Yes != MessageBox.Show(null, MessageType.Question,
                                                    ButtonsType.YesNo,
                                                    "Sure to translate all empty resources?".FormatLocalizedWithPrefix(this)))
            {
                return;
            }

            TreeIter iter;

            for (bool ok = listStore.GetIterFirst(out iter); ok; ok = listStore.IterNext(ref iter))
            {
                Localization.Node usNode      = listStore.GetValue(iter, nodeIndex) as Localization.Node;
                Localization.Node currentNode = ComponentManager.Localization.FindCurrentNode(usNode.Key);
                if (currentNode != null && !string.IsNullOrWhiteSpace(currentNode.Value))
                {
                    continue; // translate only empty fields
                }
                string translation = TranslateGoogle(usNode.Value, ComponentManager.Localization.DefaultLanguageCode, ComponentManager.Localization.CurrentLanguageCode);
                if (string.IsNullOrWhiteSpace(translation))
                {
                    continue;
                }

                listStore.SetValue(iter, localValueIndex, translation);

                if (currentNode != null)
                {
                    currentNode.Value = translation;
                }
                else
                {
                    Localization.Node newNode = new Localization.Node(usNode.Key, translation, "", usNode.Base, "", "");
                    ComponentManager.Localization.AddNewCurrentNode(newNode);
                }
            }
            ComponentManager.UpdateLanguage(true);
            UpdateChangeCount();
        }
        void localValueCell_Edited(object o, EditedArgs args)
        {
            TreeIter iter;

            if (listStore.GetIter(out iter, new TreePath(args.Path)))
            {
                listStore.SetValue(iter, localValueIndex, args.NewText);

                Localization.Node node = listStore.GetValue(iter, nodeIndex) as Localization.Node;
                Localization.Node ln   = ComponentManager.Localization.FindCurrentNode(node.Key);
                if (ln != null)
                {
                    ln.Value = args.NewText;
                }
                else
                {
                    Localization.Node newNode = new Localization.Node(node.Key, args.NewText, "", node.Base, "", "");
                    ComponentManager.Localization.AddNewCurrentNode(newNode);
                }
                ComponentManager.UpdateLanguage(true);
                UpdateChangeCount();
            }
        }
        public LocalizationEditor()
        {
            this.Build();

            TreeViewColumn keyColumn = new TreeViewColumnLocalized()
            {
                Title = "Key", Sizing = TreeViewColumnSizing.Fixed, FixedWidth = 150, SortColumnId = keyIndex
            };
            TreeViewColumn usValueColumn = new TreeViewColumnLocalized()
            {
                Title = "US name", Sizing = TreeViewColumnSizing.Fixed, FixedWidth = 150, SortColumnId = usValueIndex
            };
            TreeViewColumn localValueColumn = new TreeViewColumnLocalized()
            {
                Title = "Current name", Sizing = TreeViewColumnSizing.Autosize, SortColumnId = localValueIndex
            };

            treeview1.AppendColumn(keyColumn);
            treeview1.AppendColumn(usValueColumn);
            treeview1.AppendColumn(localValueColumn);

            Gtk.CellRendererText keyCell        = new Gtk.CellRendererText();
            Gtk.CellRendererText usValueCell    = new Gtk.CellRendererText();
            Gtk.CellRendererText localValueCell = new Gtk.CellRendererText();

            localValueCell.Editable = true;
            localValueCell.Edited  += new EditedHandler(localValueCell_Edited);

            keyColumn.PackStart(keyCell, true);
            usValueColumn.PackStart(usValueCell, true);
            localValueColumn.PackStart(localValueCell, true);

            keyColumn.AddAttribute(keyCell, "text", keyIndex);
            usValueColumn.AddAttribute(usValueCell, "text", usValueIndex);
            localValueColumn.AddAttribute(localValueCell, "text", localValueIndex);

            // Create a model that will hold the content, assign the model to the TreeView
            listStore       = new Gtk.ListStore(typeof(Localization.Node), typeof(string), typeof(string), typeof(string));
            treeview1.Model = listStore;
            treeview1.GetColumn(0).Click(); // enable sorting 1st column ascending as default

            treeview1.SearchColumn    = 0;
            treeview1.SearchEqualFunc = (TreeModel model, int column, string key, TreeIter iter) =>
            {
                Localization.Node node = (Localization.Node)model.GetValue(iter, column);
                if (node != null)
                {
                    return(!node.Key.ToLower().Contains(key.ToLower()));
                }
                return(true);
            };

            button1.Clicked += (sender, e) =>
            {
                ComponentManager.Localization.WriteChangedResourceFiles();
                UpdateChangeCount();
            };

            buttonTranslate.Clicked    += new EventHandler(buttonTranslate_Clicked);
            buttonTranslateAll.Clicked += new EventHandler(buttonTranslateAll_Clicked);
        }
        void localValueCell_Edited(object o, EditedArgs args)
        {
            TreeIter iter;
             if (listStore.GetIter(out iter, new TreePath(args.Path)))
             {
            listStore.SetValue(iter, localValueIndex, args.NewText);

            Localization.Node node = listStore.GetValue(iter, nodeIndex) as Localization.Node;
            Localization.Node ln = ComponentManager.Localization.FindCurrentNode(node.Key);
            if (ln != null)
            {
               ln.Value = args.NewText;
            }
            else
            {
               Localization.Node newNode = new Localization.Node(node.Key, args.NewText, "", node.Base, "", "");
               ComponentManager.Localization.AddNewCurrentNode(newNode);
            }
            ComponentManager.UpdateLanguage(true);
            UpdateChangeCount();
             }
        }
        void buttonTranslate_Clicked(object sender, EventArgs e)
        {
            Gtk.TreeSelection selection = treeview1.Selection;
             Gtk.TreeModel model;
             Gtk.TreeIter iter;
             if (selection.GetSelected(out model, out iter))
             {
            Localization.Node usNode = listStore.GetValue(iter, nodeIndex) as Localization.Node;
            Localization.Node currentNode = ComponentManager.Localization.FindCurrentNode(usNode.Key);
            if (usNode == null)
               return;

            string translation = TranslateGoogle(usNode.Value, ComponentManager.Localization.DefaultLanguageCode, ComponentManager.Localization.CurrentLanguageCode);
            if (string.IsNullOrWhiteSpace(translation))
               return;
            string reverted = TranslateGoogle(translation, ComponentManager.Localization.CurrentLanguageCode, ComponentManager.Localization.DefaultLanguageCode);

            ComponentManager.MessageWriteLine("Translate {0}-{1} '{2}' -> '{3}'", ComponentManager.Localization.DefaultLanguageCode, ComponentManager.Localization.CurrentLanguageCode, usNode.Value, translation);
            ComponentManager.MessageWriteLine("Translate {0}-{1} '{2}' -> '{3}'", ComponentManager.Localization.CurrentLanguageCode, ComponentManager.Localization.DefaultLanguageCode, translation, reverted);

            if (currentNode != null && currentNode.Value.Length > 0)
            {
               if (ResponseType.Yes != MessageBox.Show(null, MessageType.Question,
                           ButtonsType.YesNo,
                           "Overwrite value with new translation ?".FormatLocalizedWithPrefix(this)))
                  return;
            }

            listStore.SetValue(iter, localValueIndex, translation);

            if (currentNode != null)
            {
               currentNode.Value = translation;
            }
            else
            {
               Localization.Node newNode = new Localization.Node(usNode.Key, translation, "", usNode.Base, "", "");
               ComponentManager.Localization.AddNewCurrentNode(newNode);
            }
            ComponentManager.UpdateLanguage(true);
            UpdateChangeCount();
             }
        }
        void buttonTranslateAll_Clicked(object sender, EventArgs e)
        {
            if (ResponseType.Yes != MessageBox.Show(null, MessageType.Question,
                     ButtonsType.YesNo,
                     "Sure to translate all empty resources?".FormatLocalizedWithPrefix(this)))
            return;

             TreeIter iter;
             for(bool ok = listStore.GetIterFirst(out iter); ok; ok = listStore.IterNext(ref iter))
             {
            Localization.Node usNode = listStore.GetValue(iter, nodeIndex) as Localization.Node;
            Localization.Node currentNode = ComponentManager.Localization.FindCurrentNode(usNode.Key);
            if (currentNode != null && !string.IsNullOrWhiteSpace(currentNode.Value))
               continue; // translate only empty fields

            string translation = TranslateGoogle(usNode.Value, ComponentManager.Localization.DefaultLanguageCode, ComponentManager.Localization.CurrentLanguageCode);
            if (string.IsNullOrWhiteSpace(translation))
               continue;

            listStore.SetValue(iter, localValueIndex, translation);

            if (currentNode != null)
            {
               currentNode.Value = translation;
            }
            else
            {
               Localization.Node newNode = new Localization.Node(usNode.Key, translation, "", usNode.Base, "", "");
               ComponentManager.Localization.AddNewCurrentNode(newNode);
            }
             }
             ComponentManager.UpdateLanguage(true);
             UpdateChangeCount();
        }