[longomatch/redesign2: 146/159] Check name of new templates in the GUI
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch/redesign2: 146/159] Check name of new templates in the GUI
- Date: Thu, 2 Jun 2011 00:22:38 +0000 (UTC)
commit d33badcddadedb0151a386ef3ad9b4abe766285c
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Thu Apr 28 20:54:11 2011 +0200
Check name of new templates in the GUI
LongoMatch/Gui/Component/CategoryProperties.cs | 19 +++++++++++++------
LongoMatch/Gui/Dialog/SubCategoryTagsEditor.cs | 23 +++++++++++++++++++++++
2 files changed, 36 insertions(+), 6 deletions(-)
---
diff --git a/LongoMatch/Gui/Component/CategoryProperties.cs b/LongoMatch/Gui/Component/CategoryProperties.cs
index bd091e9..34537a8 100644
--- a/LongoMatch/Gui/Component/CategoryProperties.cs
+++ b/LongoMatch/Gui/Component/CategoryProperties.cs
@@ -119,12 +119,17 @@ namespace LongoMatch.Gui.Component
(cell as Gtk.CellRendererText).Markup =(string)model.GetValue(iter, 0);
}
- private TagSubCategory EditSubCategoryTags (TagSubCategory template){
+ private TagSubCategory EditSubCategoryTags (TagSubCategory template, bool checkName){
SubCategoryTagsEditor se = new SubCategoryTagsEditor(template);
- se.Run();
+
+ se.CheckName = checkName;
+ int ret = se.Run();
var t = se.Template;
se.Destroy();
+
+ if (ret != (int)ResponseType.Ok)
+ return null;
return t;
}
@@ -169,7 +174,7 @@ namespace LongoMatch.Gui.Component
}
protected virtual void OnSubcategorySelected(ISubCategory subcat) {
- EditSubCategoryTags((TagSubCategory)subcat);
+ EditSubCategoryTags((TagSubCategory)subcat, false);
}
protected virtual void OnSubcategoriesDeleted (List<ISubCategory> subcats)
@@ -194,9 +199,11 @@ namespace LongoMatch.Gui.Component
TreeIter iter;
if (subcatcombobox.Active == 0) {
- var template = EditSubCategoryTags(new SubCategoryTemplate()) as SubCategoryTemplate;
- if (template.Count != 0)
- subcategoriesTemplates.Save(template);
+ var template = EditSubCategoryTags(new SubCategoryTemplate(), true) as SubCategoryTemplate;
+ if (template == null || template.Count == 0)
+ return;
+
+ subcategoriesTemplates.Save(template);
subcatcombobox.Active = 1;
return;
}
diff --git a/LongoMatch/Gui/Dialog/SubCategoryTagsEditor.cs b/LongoMatch/Gui/Dialog/SubCategoryTagsEditor.cs
index c9330a7..18001e3 100644
--- a/LongoMatch/Gui/Dialog/SubCategoryTagsEditor.cs
+++ b/LongoMatch/Gui/Dialog/SubCategoryTagsEditor.cs
@@ -17,6 +17,7 @@
//
using System;
using System.Collections.Generic;
+using Gdk;
using Gtk;
using LongoMatch.Store;
@@ -27,13 +28,18 @@ namespace LongoMatch.Gui.Dialog
{
private TagSubCategory template;
private Dictionary<string, Widget> tagsDict;
+ private List<string> templates;
+ private Color templateExistsColor;
public SubCategoryTagsEditor (TagSubCategory template)
{
this.Build ();
+ Gdk.Color.Parse("red", ref templateExistsColor);
+ templates = MainClass.ts.SubCategoriesTemplateProvider.TemplatesNames;
tagsDict = new Dictionary<string, Widget>();
addtagbutton.Clicked += OnAddTag;
tagentry.Activated += OnAddTag;
+ nameentry.Changed += OnNameChanged;
Template = template;
}
@@ -50,6 +56,11 @@ namespace LongoMatch.Gui.Dialog
}
}
+ public bool CheckName {
+ set;
+ get;
+ }
+
private void RemoveTag (string tag) {
tagsbox.Remove(tagsDict[tag]);
tagsDict.Remove(tag);
@@ -82,6 +93,18 @@ namespace LongoMatch.Gui.Dialog
template.Add(tag);
}
+ protected virtual void OnNameChanged (object sender, EventArgs e)
+ {
+ if ((CheckName && templates.Contains(nameentry.Text)) ||
+ nameentry.Text == "") {
+ nameentry.ModifyText(StateType.Normal, templateExistsColor);
+ buttonOk.Sensitive = false;
+ } else {
+ nameentry.ModifyText(StateType.Normal);
+ buttonOk.Sensitive = true;
+ }
+ }
+
protected virtual void OnAddTag (object sender, System.EventArgs e)
{
AddTag(tagentry.Text, true);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]