[longomatch] Delete tag and subcategories when the template is edited
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Delete tag and subcategories when the template is edited
- Date: Sat, 27 Aug 2011 09:31:28 +0000 (UTC)
commit f4dbf4cf3d83f5857a8d2e74134db55f8bccd941
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Fri Aug 26 18:58:25 2011 +0200
Delete tag and subcategories when the template is edited
LongoMatch/Gui/Component/CategoryProperties.cs | 14 ++++++++
LongoMatch/Gui/Component/PlaysListTreeWidget.cs | 17 ++++++---
LongoMatch/Gui/Component/ProjectDetailsWidget.cs | 40 ++++++++++-----------
LongoMatch/Gui/Component/TemplatesEditorBase.cs | 9 +++--
LongoMatch/Gui/Dialog/EditCategoryDialog.cs | 6 +++
LongoMatch/Gui/Dialog/TemplateEditorDialog.cs | 6 ++--
LongoMatch/Gui/Popup/MessagePopup.cs | 7 +++-
LongoMatch/Gui/TreeView/PlaysTreeView.cs | 5 ++-
LongoMatch/Interfaces/ITemplates.cs | 3 +-
LongoMatch/Store/Project.cs | 16 ++++++++-
LongoMatch/Store/TagStore.cs | 4 ++
11 files changed, 88 insertions(+), 39 deletions(-)
---
diff --git a/LongoMatch/Gui/Component/CategoryProperties.cs b/LongoMatch/Gui/Component/CategoryProperties.cs
index 70eecb6..0a40b3d 100644
--- a/LongoMatch/Gui/Component/CategoryProperties.cs
+++ b/LongoMatch/Gui/Component/CategoryProperties.cs
@@ -30,6 +30,7 @@ using LongoMatch.Services;
using LongoMatch.Store;
using LongoMatch.Store.Templates;
using LongoMatch.Gui.Dialog;
+using LongoMatch.Gui.Popup;
namespace LongoMatch.Gui.Component
{
@@ -91,6 +92,11 @@ namespace LongoMatch.Gui.Component
return cat;
}
}
+
+ public Project Project {
+ set;
+ get;
+ }
private void UpdateGui() {
ListStore list;
@@ -179,6 +185,14 @@ namespace LongoMatch.Gui.Component
protected virtual void OnSubcategoriesDeleted (List<ISubCategory> subcats)
{
+ if (Project != null) {
+ int ret = MessagePopup.PopupMessage(this, MessageType.Question,
+ Catalog.GetString("If you delete this subcategory you will loose" +
+ "all the tags associated with it. Do you want to proceed?"));
+ if (ret == (int)ResponseType.No)
+ return;
+ Project.DeleteSubcategoryTags(Category, subcats);
+ }
Category.SubCategories.RemoveAll(s => subcats.Contains(s));
}
diff --git a/LongoMatch/Gui/Component/PlaysListTreeWidget.cs b/LongoMatch/Gui/Component/PlaysListTreeWidget.cs
index 9bac540..b8cd22d 100644
--- a/LongoMatch/Gui/Component/PlaysListTreeWidget.cs
+++ b/LongoMatch/Gui/Component/PlaysListTreeWidget.cs
@@ -54,6 +54,7 @@ namespace LongoMatch.Gui.Component
treeview.TimeNodeDeleted += OnTimeNodeDeleted;
treeview.PlayListNodeAdded += OnPlayListNodeAdded;
treeview.SnapshotSeriesEvent += OnSnapshotSeriesEvent;
+ treeview.EditProperties += OnEditProperties;
treeview.TagPlay += OnTagPlay;
}
@@ -135,14 +136,18 @@ namespace LongoMatch.Gui.Component
private string CategoryPath(Category cat) {
return project.Categories.IndexOf(cat).ToString();
}
+
+ protected virtual void OnEditProperties(TimeNode tNode, object val) {
+ EditCategoryDialog dialog = new EditCategoryDialog();
+ dialog.Category = tNode as Category;
+ dialog.Project = project;
+ dialog.Run();
+ dialog.Destroy();
+ if(TimeNodeChanged != null)
+ TimeNodeChanged(tNode, tNode.Name);
+ }
protected virtual void OnTimeNodeChanged(TimeNode tNode,object val) {
- if (tNode is Category) {
- EditCategoryDialog dialog = new EditCategoryDialog();
- dialog.Category = tNode as Category;
- dialog.Run();
- dialog.Destroy();
- }
if(TimeNodeChanged != null)
TimeNodeChanged(tNode,val);
}
diff --git a/LongoMatch/Gui/Component/ProjectDetailsWidget.cs b/LongoMatch/Gui/Component/ProjectDetailsWidget.cs
index 4d2e2e2..8402942 100644
--- a/LongoMatch/Gui/Component/ProjectDetailsWidget.cs
+++ b/LongoMatch/Gui/Component/ProjectDetailsWidget.cs
@@ -416,6 +416,13 @@ namespace LongoMatch.Gui.Component
videoformatcombobox.Model = encProfileList;
videoformatcombobox.Active = 0;
}
+
+ private void StartEditor(TemplateEditorDialog editor) {
+ editor.TransientFor = (Window)Toplevel;
+ editor.Run();
+ editor.Destroy();
+ OnEdited(this,null);
+ }
protected virtual void OnDateSelected(DateTime dateTime) {
Date = dateTime;
@@ -522,41 +529,32 @@ namespace LongoMatch.Gui.Component
protected virtual void OnEditbuttonClicked(object sender, System.EventArgs e)
{
var editor = new TemplateEditorDialog<Categories, Category>();
-
- editor.TransientFor = (Window)Toplevel;
editor.Template = Categories;
- editor.InProject = true;
- editor.CanExport = Use == ProjectType.EditProject;
- if(editor.Run() == (int)ResponseType.Apply) {
- Categories = editor.Template;
+ if (Use == ProjectType.EditProject) {
+ editor.Project = project;
+ editor.CanExport = true;
}
- editor.Destroy();
- OnEdited(this,null);
+ StartEditor(editor);
}
protected virtual void OnLocaltemplatebuttonClicked(object sender, System.EventArgs e) {
var editor = new TemplateEditorDialog<TeamTemplate, Player>();
- editor.TransientFor = (Window)Toplevel;
- editor.Title=Catalog.GetString("Local Team Template");
editor.Template = LocalTeamTemplate;
-
- if(editor.Run() == (int)ResponseType.Apply) {
- LocalTeamTemplate = editor.Template;
+ if (Use == ProjectType.EditProject) {
+ editor.Project = project;
+ editor.CanExport = true;
}
- editor.Destroy();
- OnEdited(this,null);
+ StartEditor(editor);
}
protected virtual void OnVisitorbuttonClicked(object sender, System.EventArgs e) {
var editor = new TemplateEditorDialog<TeamTemplate, Player>();
- editor.TransientFor = (Window)Toplevel;
- editor.Title=Catalog.GetString("Visitor Team Template");
editor.Template = VisitorTeamTemplate;
- if(editor.Run() == (int)ResponseType.Apply) {
- VisitorTeamTemplate = editor.Template;
+ if (Use == ProjectType.EditProject) {
+ editor.Project = project;
+ editor.CanExport = true;
}
- editor.Destroy();
- OnEdited(this,null);
+ StartEditor(editor);
}
protected virtual void OnEdited(object sender, System.EventArgs e) {
diff --git a/LongoMatch/Gui/Component/TemplatesEditorBase.cs b/LongoMatch/Gui/Component/TemplatesEditorBase.cs
index 9c43bb6..41a7da7 100644
--- a/LongoMatch/Gui/Component/TemplatesEditorBase.cs
+++ b/LongoMatch/Gui/Component/TemplatesEditorBase.cs
@@ -52,12 +52,13 @@ namespace LongoMatch.Gui.Component
exportbutton.Visible = value;
}
}
+
public bool Edited {
get;
set;
}
- public bool InProject {
+ public Project Project {
get;
set;
}
@@ -225,14 +226,14 @@ namespace LongoMatch.Gui.Component
protected override void RemoveSelected (){
- if(InProject) {
+ if(Project != null) {
MessageDialog dialog = new MessageDialog((Gtk.Window)this.Toplevel,DialogFlags.Modal,MessageType.Question,
ButtonsType.YesNo,true,
Catalog.GetString("You are about to delete a category and all the plays added to this category. Do you want to proceed?"));
if(dialog.Run() == (int)ResponseType.Yes) {
try {
- foreach(var item in selected)
- template.Remove(item);
+ foreach(var cat in selected)
+ Project.RemoveCategory (cat);
} catch {
MessagePopup.PopupMessage(this,MessageType.Warning,
Catalog.GetString("A template needs at least one category"));
diff --git a/LongoMatch/Gui/Dialog/EditCategoryDialog.cs b/LongoMatch/Gui/Dialog/EditCategoryDialog.cs
index 892302a..989eadc 100644
--- a/LongoMatch/Gui/Dialog/EditCategoryDialog.cs
+++ b/LongoMatch/Gui/Dialog/EditCategoryDialog.cs
@@ -44,6 +44,12 @@ namespace LongoMatch.Gui.Dialog
timenodeproperties2.Category = value;
}
}
+
+ public Project Project {
+ set {
+ timenodeproperties2.Project = value;
+ }
+ }
public List<HotKey> HotKeysList {
set {
diff --git a/LongoMatch/Gui/Dialog/TemplateEditorDialog.cs b/LongoMatch/Gui/Dialog/TemplateEditorDialog.cs
index cf3162a..236087e 100644
--- a/LongoMatch/Gui/Dialog/TemplateEditorDialog.cs
+++ b/LongoMatch/Gui/Dialog/TemplateEditorDialog.cs
@@ -58,12 +58,12 @@ namespace LongoMatch.Gui.Dialog
}
}
- public bool InProject {
+ public Project Project {
set{
- templateEditor.InProject = value;
+ templateEditor.Project = value;
}
get{
- return templateEditor.InProject;
+ return templateEditor.Project;
}
}
diff --git a/LongoMatch/Gui/Popup/MessagePopup.cs b/LongoMatch/Gui/Popup/MessagePopup.cs
index 5dd7b3b..0bcfe25 100644
--- a/LongoMatch/Gui/Popup/MessagePopup.cs
+++ b/LongoMatch/Gui/Popup/MessagePopup.cs
@@ -30,8 +30,10 @@ namespace LongoMatch.Gui
{
}
- public static void PopupMessage(Widget sender,MessageType type, String errorMessage) {
+ public static int PopupMessage(Widget sender,MessageType type, String errorMessage) {
Window toplevel;
+ int ret;
+
if(sender != null)
toplevel = (Window)sender.Toplevel;
else
@@ -43,8 +45,9 @@ namespace LongoMatch.Gui
ButtonsType.Ok,
errorMessage);
md.Icon=Stetic.IconLoader.LoadIcon(md, "longomatch", Gtk.IconSize.Dialog);
- md.Run();
+ ret = md.Run();
md.Destroy();
+ return ret;
}
}
}
diff --git a/LongoMatch/Gui/TreeView/PlaysTreeView.cs b/LongoMatch/Gui/TreeView/PlaysTreeView.cs
index 7baa1c4..c2e1767 100644
--- a/LongoMatch/Gui/TreeView/PlaysTreeView.cs
+++ b/LongoMatch/Gui/TreeView/PlaysTreeView.cs
@@ -21,6 +21,7 @@
using Gdk;
using Gtk;
using LongoMatch.Common;
+using LongoMatch.Handlers;
using LongoMatch.Gui.Dialog;
using LongoMatch.Store;
using System;
@@ -33,6 +34,8 @@ namespace LongoMatch.Gui.Component
[System.ComponentModel.ToolboxItem(true)]
public class PlaysTreeView : ListTreeViewBase
{
+
+ public event TimeNodeChangedHandler EditProperties;
//Categories menu
private Menu categoriesMenu;
@@ -108,7 +111,7 @@ namespace LongoMatch.Gui.Component
sortByStop.Activated += OnSortActivated;
sortByDuration.Activated += OnSortActivated;
editProp.Activated += delegate(object sender, EventArgs e) {
- EmitTimeNodeChanged(GetValueFromPath(Selection.GetSelectedRows()[0]) as Category);
+ EditProperties(GetValueFromPath(Selection.GetSelectedRows()[0]) as Category, null);
};
}
diff --git a/LongoMatch/Interfaces/ITemplates.cs b/LongoMatch/Interfaces/ITemplates.cs
index 1ea3743..4f054f6 100644
--- a/LongoMatch/Interfaces/ITemplates.cs
+++ b/LongoMatch/Interfaces/ITemplates.cs
@@ -17,6 +17,7 @@
//
using System;
using System.Collections.Generic;
+using LongoMatch.Store;
namespace LongoMatch.Interfaces
{
@@ -51,7 +52,7 @@ namespace LongoMatch.Interfaces
T Template {get; set;}
bool Edited {get; set;}
bool CanExport {get; set;}
- bool InProject {get; set;}
+ Project Project {get; set;}
}
}
diff --git a/LongoMatch/Store/Project.cs b/LongoMatch/Store/Project.cs
index fe3a2a8..65f8cdf 100644
--- a/LongoMatch/Store/Project.cs
+++ b/LongoMatch/Store/Project.cs
@@ -178,11 +178,25 @@ namespace LongoMatch.Store
/// </param>
public void RemoveCategory(Category category) {
if(Categories.Count == 1)
- throw new Exception("You can't remove the last Section");
+ throw new Exception("You can't remove the last Category");
Categories.Remove(category);
timeline.RemoveAll(p => p.Category.UUID == category.UUID);
}
+
+ public void DeleteSubcategoryTags(Category cat, List<ISubCategory> subcategories) {
+ foreach (var play in timeline.Where(p => p.Category == cat)) {
+ foreach (var subcat in subcategories) {
+ Log.Error(play.Name);
+ if (subcat is TagSubCategory)
+ play.Tags.RemoveBySubcategory(subcat);
+ else if (subcat is TeamSubCategory)
+ play.Teams.RemoveBySubcategory(subcat);
+ else if (subcat is PlayerSubCategory)
+ play.Players.RemoveBySubcategory(subcat);
+ }
+ }
+ }
public List<Play> PlaysInCategory(Category category) {
return timeline.Where(p => p.Category.UUID == category.UUID).ToList();
diff --git a/LongoMatch/Store/TagStore.cs b/LongoMatch/Store/TagStore.cs
index 7256db8..3310f52 100644
--- a/LongoMatch/Store/TagStore.cs
+++ b/LongoMatch/Store/TagStore.cs
@@ -60,6 +60,10 @@ namespace LongoMatch.Store
return tagsList.Contains(tag);
}
+ public void RemoveBySubcategory(ISubCategory subcat) {
+ tagsList.RemoveAll(t => t.SubCategory == subcat);
+ }
+
public List<T> AllUniqueElements {
get {
return (from tag in tagsList
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]