void EditEvent(object sender, System.EventArgs e)
            {
                TreeIter selectedIter;
                TreeModel ls;
                if(((ListStore)templateListView.Model).GetIter(out selectedIter, (TreePath) templateListView.Selection.GetSelectedRows(out ls)[0])) {
                    CodeTemplate template = ls.GetValue(selectedIter, 0) as CodeTemplate;

                    using (EditTemplateDialog etd = new EditTemplateDialog(template)) {
                        if (etd.Run() == (int) Gtk.ResponseType.Ok) {
                            ls.SetValue(selectedIter, 0, template);
                            StoreTemplateGroup();
                        }
                    }

                    // select the newly edited item
                    templateListView.Selection.SelectIter(selectedIter);
                }
            }
            void AddEvent(object sender, System.EventArgs e)
            {
                CodeTemplate newTemplate = new CodeTemplate();
                using (EditTemplateDialog etd = new EditTemplateDialog(newTemplate)) {
                    if (etd.Run() == (int) Gtk.ResponseType.Ok) {
                        CurrentTemplateGroup.Templates.Add(newTemplate);
                        templateListView.Selection.UnselectAll();
                        BuildListView();

                        // select the newly added last one
                        TreeIter nextIter;
                        int maxIndex = templateListViewStore.IterNChildren() - 1;
                        if(templateListViewStore.GetIterFromString(out nextIter, (maxIndex).ToString())) {
                            templateListView.Selection.SelectIter(nextIter);
                        }
                    }
                }
            }