[longomatch] Improve Projects Manager. Added edition event to prompt for saving if a project is edited



commit acca6bed6df8e329669dba6856cca974d61d1d17
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Wed Sep 23 15:13:30 2009 +0200

    Improve Projects Manager. Added edition event to prompt for saving if a project is edited

 LongoMatch/Gui/Component/ProjectDetailsWidget.cs   |   61 ++++++++++++-------
 LongoMatch/Gui/Dialog/ProjectsManager.cs           |   47 +++++++++------
 ...ongoMatch.Gui.Component.ProjectDetailsWidget.cs |    8 +++
 .../LongoMatch.Gui.Dialog.NewProjectDialog.cs      |    1 +
 .../LongoMatch.Gui.Dialog.ProjectsManager.cs       |   20 ++++---
 LongoMatch/gtk-gui/gui.stetic                      |   13 ++++-
 LongoMatch/gtk-gui/objects.xml                     |   27 +++++----
 7 files changed, 114 insertions(+), 63 deletions(-)
---
diff --git a/LongoMatch/Gui/Component/ProjectDetailsWidget.cs b/LongoMatch/Gui/Component/ProjectDetailsWidget.cs
index c19b033..be86e34 100644
--- a/LongoMatch/Gui/Component/ProjectDetailsWidget.cs
+++ b/LongoMatch/Gui/Component/ProjectDetailsWidget.cs
@@ -32,7 +32,7 @@ using LongoMatch.Video.Utils;
 
 namespace LongoMatch.Gui.Component
 {
-
+	
 	public enum UseType{
 		NewCaptureProject,
 		NewFromFileProject,
@@ -43,15 +43,17 @@ namespace LongoMatch.Gui.Component
 	[System.ComponentModel.ToolboxItem(true)]
 	public partial class ProjectDetailsWidget : Gtk.Bin
 	{
+		public event EventHandler EditedEvent;
 		private Project project;
 		private LongoMatch.Video.Utils.PreviewMediaFile mFile;
+		private bool edited;
 		private CalendarPopup cp;
 		private Win32CalendarDialog win32CP;
 		private Sections actualSection;
 		private TeamTemplate actualVisitorTeam;
 		private TeamTemplate actualLocalTeam;
 		private UseType useType;		
-		
+
 		public ProjectDetailsWidget()
 		{	
 				
@@ -89,6 +91,11 @@ namespace LongoMatch.Gui.Component
 			}				
 		}
 		
+		public bool Edited{
+			set{edited=value;}
+			get{return edited;}
+		}
+		
 		public string LocalName {
 			get { return localTeamEntry.Text; }
 			set { this.localTeamEntry.Text = value;}
@@ -124,7 +131,7 @@ namespace LongoMatch.Gui.Component
 			set { fileEntry.Text = value;}
 		}
 		
-		public DateTime Date{
+		public DateTime Date{  
 			get {
 				//HACK See bug http://bugzilla.gnome.org/show_bug.cgi?id=592934
 				//dateEntry is not editable and we set the date manually
@@ -135,15 +142,15 @@ namespace LongoMatch.Gui.Component
 				}
 				catch{
 					date = DateTime.Now;
-				}				
+				}                               
 				return date;
 			}
 			
 			set {
 				dateEntry.Text = value.ToString(Catalog.GetString("MM/dd/yyyy"));
 			}
-		}
-		
+		}			
+			
 		public Sections Sections{
 			get {return this.actualSection;}
 			set {actualSection = value;}
@@ -185,6 +192,7 @@ namespace LongoMatch.Gui.Component
 			Sections = project.Sections;
 			LocalTeamTemplate = project.LocalTeamTemplate;
 			VisitorTeamTemplate = project.VisitorTeamTemplate;
+			Edited = false;
 		}
 		
 		public void UpdateProject(){
@@ -350,19 +358,6 @@ namespace LongoMatch.Gui.Component
 			}
 		}
 
-		protected virtual void OnEditbuttonClicked (object sender, System.EventArgs e)
-		{			
-			ProjectTemplateEditorDialog ted = new ProjectTemplateEditorDialog();
-			ted.TransientFor = (Window)Toplevel;
-			ted.Sections = Sections;
-			ted.Project = project;
-			
-			if (ted.Run() == (int)ResponseType.Apply){
-				this.Sections = ted.Sections;
-			}			
-			ted.Destroy();
-		}
-		
 		protected virtual void OnCombobox1Changed (object sender, System.EventArgs e)
 		{
 			SectionsReader reader = new SectionsReader(System.IO.Path.Combine(MainClass.TemplatesDir(),SectionsFile));			
@@ -380,6 +375,19 @@ namespace LongoMatch.Gui.Component
 			LocalTeamTemplate = TeamTemplate.LoadFromFile(System.IO.Path.Combine(MainClass.TemplatesDir(), LocalTeamTemplateFile));
 		}
 		
+		protected virtual void OnEditbuttonClicked (object sender, System.EventArgs e)
+		{			
+			ProjectTemplateEditorDialog ted = new ProjectTemplateEditorDialog();
+			ted.TransientFor = (Window)Toplevel;
+			ted.Sections = Sections;
+			ted.Project = project;
+			
+			if (ted.Run() == (int)ResponseType.Apply){
+				this.Sections = ted.Sections;
+			}			
+			ted.Destroy();
+			OnEdited(this,null);
+		}
 			
 		protected virtual void OnLocaltemplatebuttonClicked (object sender, System.EventArgs e){			
 			TeamTemplateEditor tted = new TeamTemplateEditor();
@@ -389,7 +397,8 @@ namespace LongoMatch.Gui.Component
 			if (tted.Run() == (int)ResponseType.Apply){
 				LocalTeamTemplate = tted.GetTeamTemplate();
 			}			
-			tted.Destroy();			
+			tted.Destroy();	
+			OnEdited(this,null);
 		}		
 
 		protected virtual void OnVisitorbuttonClicked (object sender, System.EventArgs e){
@@ -400,7 +409,13 @@ namespace LongoMatch.Gui.Component
 			if (tted.Run() == (int)ResponseType.Apply){
 				VisitorTeamTemplate = tted.GetTeamTemplate();
 			}			
-			tted.Destroy();			
-		}	
+			tted.Destroy();	
+			OnEdited(this,null);
+		}
+		protected virtual void OnEdited (object sender, System.EventArgs e){
+			Edited = true;
+			if (EditedEvent != null)
+				EditedEvent(this,null);
+		}
 	}			
-}
+}
\ No newline at end of file
diff --git a/LongoMatch/Gui/Dialog/ProjectsManager.cs b/LongoMatch/Gui/Dialog/ProjectsManager.cs
index 0fce51c..1bf34d0 100644
--- a/LongoMatch/Gui/Dialog/ProjectsManager.cs
+++ b/LongoMatch/Gui/Dialog/ProjectsManager.cs
@@ -40,39 +40,41 @@ namespace LongoMatch.Gui.Dialog
 		{
 			this.Build();
 			this.Fill();
-			this.filedescriptionwidget3.Use = LongoMatch.Gui.Component.UseType.EditProject;
+			this.projectdetails.Use = LongoMatch.Gui.Component.UseType.EditProject;
+			projectdetails.Edited = false;
 		}
 		
 		public void Fill(){
 			ArrayList allDB = MainClass.DB.GetAllDB();
 			projectlistwidget1.Fill(allDB);
 			projectlistwidget1.ClearSearch();
-			filedescriptionwidget3.Clear();
-			filedescriptionwidget3.Sensitive = false;
+			projectdetails.Clear();
+			projectdetails.Sensitive = false;
 			saveButton.Sensitive = false;
 			deleteButton.Sensitive = false;
 			originalFilePath=null;	
 		}
 		
 		private void SaveProject(){
-			Project project = filedescriptionwidget3.GetProject();
+			Project project = projectdetails.GetProject();
 						
 			if (project == null)
 				return;
 							
-			if (project.File.FilePath == originalFilePath)
+			if (project.File.FilePath == originalFilePath){
 				MainClass.DB.UpdateProject(project);
+				saveButton.Sensitive = false;
+			}
 			else{
 				try{
 					MainClass.DB.UpdateProject(project,originalFilePath);
+					saveButton.Sensitive = false;
 				}
 				catch{
 					MessagePopup.PopupMessage(this, MessageType.Warning, 
 					                          Catalog.GetString("A Project is already using this file."));
 				}
 			}
-			Fill();
-			
 		}
 
 
@@ -89,7 +91,7 @@ namespace LongoMatch.Gui.Dialog
 					MessageDialog md = new MessageDialog(this,DialogFlags.Modal,MessageType.Question,ButtonsType.YesNo,
 					                                     Catalog.GetString("Do yo really want to delete:")+"\n"+selectedProject.File.FilePath);
 					if (md.Run()== (int)ResponseType.Yes){
-						filedescriptionwidget3.Clear();
+						projectdetails.Clear();
 						MainClass.DB.RemoveProject(selectedProject);	
 						Fill();						
 					}
@@ -101,7 +103,8 @@ namespace LongoMatch.Gui.Dialog
 
 		protected virtual void OnSaveButtonPressed (object sender, System.EventArgs e)
 		{
-			SaveProject();			
+			SaveProject();		
+			projectdetails.Edited=false;
 		}		
 	
 
@@ -112,31 +115,37 @@ namespace LongoMatch.Gui.Dialog
 
 		protected virtual void OnProjectlistwidget1ProjectSelectedEvent (LongoMatch.DB.Project project)
 		{
-			if (edited){
+			if (projectdetails.Edited){
 				MessageDialog md = new MessageDialog((Window)this.Toplevel,DialogFlags.Modal,
 				                                     MessageType.Question, ButtonsType.YesNo,
 				                                     Catalog.GetString("The Project has been edited, do you want to save the changes?"));
-				if (md.Run() == (int)ResponseType.Yes)
+				if (md.Run() == (int)ResponseType.Yes){
 					SaveProject();
-				edited=false;
-					
+					projectdetails.Edited=false;	
+				}
+				md.Destroy();								
 			}
 			if (MainWindow.OpenedProject()!= null && project.Equals(MainWindow.OpenedProject())) {
 			
 				MessagePopup.PopupMessage(this, MessageType.Warning, 
 				                          Catalog.GetString("The Project you are trying to load is actually in use.")+"\n" +Catalog.GetString ("Close it first to edit it"));
-				filedescriptionwidget3.Clear();
-				filedescriptionwidget3.Sensitive = false;
+				projectdetails.Clear();
+				projectdetails.Sensitive = false;
 				saveButton.Sensitive = false;
 				deleteButton.Sensitive = false;				
 			}
 			else{
-				filedescriptionwidget3.Sensitive = true;
-				filedescriptionwidget3.SetProject(project);
+				projectdetails.Sensitive = true;
+				projectdetails.SetProject(project);
 				originalFilePath = project.File.FilePath;
-				saveButton.Sensitive = true;
-				deleteButton.Sensitive = true;
+				saveButton.Sensitive = false;
+				deleteButton.Sensitive = true;			
 			}
+		}
+
+		protected virtual void OnProjectdetailsEditedEvent (object sender, System.EventArgs e)
+		{
+			saveButton.Sensitive = true;
 		}		
 	}
 }
diff --git a/LongoMatch/gtk-gui/LongoMatch.Gui.Component.ProjectDetailsWidget.cs b/LongoMatch/gtk-gui/LongoMatch.Gui.Component.ProjectDetailsWidget.cs
index 725d68f..5bbb162 100644
--- a/LongoMatch/gtk-gui/LongoMatch.Gui.Component.ProjectDetailsWidget.cs
+++ b/LongoMatch/gtk-gui/LongoMatch.Gui.Component.ProjectDetailsWidget.cs
@@ -494,7 +494,14 @@ namespace LongoMatch.Gui.Component {
             this.editbutton.Hide();
             this.videobitratelabel.Hide();
             this.Show();
+            this.visitorTeamEntry.Changed += new System.EventHandler(this.OnEdited);
+            this.visitorSpinButton.ValueChanged += new System.EventHandler(this.OnEdited);
+            this.seasonentry.Changed += new System.EventHandler(this.OnEdited);
+            this.localTeamEntry.Changed += new System.EventHandler(this.OnEdited);
+            this.localSpinButton.ValueChanged += new System.EventHandler(this.OnEdited);
+            this.dateEntry.Changed += new System.EventHandler(this.OnEdited);
             this.calendarbutton.Clicked += new System.EventHandler(this.OnCalendarbuttonClicked);
+            this.fileEntry.Changed += new System.EventHandler(this.OnEdited);
             this.openbutton.Clicked += new System.EventHandler(this.OnOpenbuttonClicked);
             this.tagscombobox.Changed += new System.EventHandler(this.OnCombobox1Changed);
             this.editbutton.Clicked += new System.EventHandler(this.OnEditbuttonClicked);
@@ -502,6 +509,7 @@ namespace LongoMatch.Gui.Component {
             this.visitorbutton.Clicked += new System.EventHandler(this.OnVisitorbuttonClicked);
             this.localcombobox.Changed += new System.EventHandler(this.OnLocalcomboboxChanged);
             this.localtemplatebutton.Clicked += new System.EventHandler(this.OnLocaltemplatebuttonClicked);
+            this.competitionentry.Changed += new System.EventHandler(this.OnEdited);
         }
     }
 }
diff --git a/LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.NewProjectDialog.cs b/LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.NewProjectDialog.cs
index fde80ab..8d4e917 100644
--- a/LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.NewProjectDialog.cs
+++ b/LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.NewProjectDialog.cs
@@ -38,6 +38,7 @@ namespace LongoMatch.Gui.Dialog {
             // Container child dialog1_VBox.Gtk.Box+BoxChild
             this.fdwidget = new LongoMatch.Gui.Component.ProjectDetailsWidget();
             this.fdwidget.Name = "fdwidget";
+            this.fdwidget.Edited = false;
             this.fdwidget.LocalGoals = 0;
             this.fdwidget.VisitorGoals = 0;
             this.fdwidget.Date = new System.DateTime(0);
diff --git a/LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.ProjectsManager.cs b/LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.ProjectsManager.cs
index 5ee421b..9e13137 100644
--- a/LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.ProjectsManager.cs
+++ b/LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.ProjectsManager.cs
@@ -27,7 +27,7 @@ namespace LongoMatch.Gui.Dialog {
         
         private Gtk.Alignment GtkAlignment2;
         
-        private LongoMatch.Gui.Component.ProjectDetailsWidget filedescriptionwidget3;
+        private LongoMatch.Gui.Component.ProjectDetailsWidget projectdetails;
         
         private Gtk.Label GtkLabel6;
         
@@ -88,14 +88,15 @@ namespace LongoMatch.Gui.Dialog {
             this.GtkAlignment2.Name = "GtkAlignment2";
             this.GtkAlignment2.LeftPadding = ((uint)(12));
             // Container child GtkAlignment2.Gtk.Container+ContainerChild
-            this.filedescriptionwidget3 = new LongoMatch.Gui.Component.ProjectDetailsWidget();
-            this.filedescriptionwidget3.Sensitive = false;
-            this.filedescriptionwidget3.Events = ((Gdk.EventMask)(256));
-            this.filedescriptionwidget3.Name = "filedescriptionwidget3";
-            this.filedescriptionwidget3.LocalGoals = 0;
-            this.filedescriptionwidget3.VisitorGoals = 0;
-            this.filedescriptionwidget3.Date = new System.DateTime(0);
-            this.GtkAlignment2.Add(this.filedescriptionwidget3);
+            this.projectdetails = new LongoMatch.Gui.Component.ProjectDetailsWidget();
+            this.projectdetails.Sensitive = false;
+            this.projectdetails.Events = ((Gdk.EventMask)(256));
+            this.projectdetails.Name = "projectdetails";
+            this.projectdetails.Edited = false;
+            this.projectdetails.LocalGoals = 0;
+            this.projectdetails.VisitorGoals = 0;
+            this.projectdetails.Date = new System.DateTime(0);
+            this.GtkAlignment2.Add(this.projectdetails);
             this.frame1.Add(this.GtkAlignment2);
             this.GtkLabel6 = new Gtk.Label();
             this.GtkLabel6.Name = "GtkLabel6";
@@ -175,6 +176,7 @@ namespace LongoMatch.Gui.Dialog {
             this.DefaultHeight = 550;
             this.Show();
             this.projectlistwidget1.ProjectSelectedEvent += new LongoMatch.Gui.Component.ProjectSelectedHandler(this.OnProjectlistwidget1ProjectSelectedEvent);
+            this.projectdetails.EditedEvent += new System.EventHandler(this.OnProjectdetailsEditedEvent);
             this.saveButton.Pressed += new System.EventHandler(this.OnSaveButtonPressed);
             this.deleteButton.Pressed += new System.EventHandler(this.OnDeleteButtonPressed);
             this.buttonOk.Clicked += new System.EventHandler(this.OnButtonOkClicked);
diff --git a/LongoMatch/gtk-gui/gui.stetic b/LongoMatch/gtk-gui/gui.stetic
index ae18218..2b39473 100644
--- a/LongoMatch/gtk-gui/gui.stetic
+++ b/LongoMatch/gtk-gui/gui.stetic
@@ -62,6 +62,7 @@
                 <property name="CanFocus">True</property>
                 <property name="IsEditable">True</property>
                 <property name="InvisibleChar">â??</property>
+                <signal name="Changed" handler="OnEdited" />
               </widget>
               <packing>
                 <property name="TopAttach">5</property>
@@ -262,6 +263,7 @@
                     <property name="CanFocus">True</property>
                     <property name="IsEditable">False</property>
                     <property name="InvisibleChar">â??</property>
+                    <signal name="Changed" handler="OnEdited" />
                   </widget>
                   <packing>
                     <property name="Position">0</property>
@@ -310,6 +312,7 @@
                     <property name="CanFocus">True</property>
                     <property name="IsEditable">False</property>
                     <property name="InvisibleChar">â??</property>
+                    <signal name="Changed" handler="OnEdited" />
                   </widget>
                   <packing>
                     <property name="Position">0</property>
@@ -489,6 +492,7 @@
                 <property name="StepIncrement">1</property>
                 <property name="ClimbRate">1</property>
                 <property name="Numeric">True</property>
+                <signal name="ValueChanged" handler="OnEdited" />
               </widget>
               <packing>
                 <property name="TopAttach">2</property>
@@ -512,6 +516,7 @@
                 <property name="CanFocus">True</property>
                 <property name="IsEditable">True</property>
                 <property name="InvisibleChar">â??</property>
+                <signal name="Changed" handler="OnEdited" />
               </widget>
               <packing>
                 <property name="LeftAttach">1</property>
@@ -550,6 +555,7 @@
                 <property name="CanFocus">True</property>
                 <property name="IsEditable">True</property>
                 <property name="InvisibleChar">â??</property>
+                <signal name="Changed" handler="OnEdited" />
               </widget>
               <packing>
                 <property name="TopAttach">4</property>
@@ -615,6 +621,7 @@
                 <property name="StepIncrement">1</property>
                 <property name="ClimbRate">1</property>
                 <property name="Numeric">True</property>
+                <signal name="ValueChanged" handler="OnEdited" />
               </widget>
               <packing>
                 <property name="TopAttach">3</property>
@@ -638,6 +645,7 @@
                 <property name="CanFocus">True</property>
                 <property name="IsEditable">True</property>
                 <property name="InvisibleChar">â??</property>
+                <signal name="Changed" handler="OnEdited" />
               </widget>
               <packing>
                 <property name="TopAttach">1</property>
@@ -926,13 +934,15 @@
                                 <property name="Yalign">0</property>
                                 <property name="LeftPadding">12</property>
                                 <child>
-                                  <widget class="LongoMatch.Gui.Component.ProjectDetailsWidget" id="filedescriptionwidget3">
+                                  <widget class="LongoMatch.Gui.Component.ProjectDetailsWidget" id="projectdetails">
                                     <property name="MemberName" />
                                     <property name="Sensitive">False</property>
                                     <property name="Events">ButtonPressMask</property>
+                                    <property name="Edited">False</property>
                                     <property name="LocalGoals">0</property>
                                     <property name="VisitorGoals">0</property>
                                     <property name="Date">0</property>
+                                    <signal name="EditedEvent" handler="OnProjectdetailsEditedEvent" />
                                   </widget>
                                 </child>
                               </widget>
@@ -1141,6 +1151,7 @@
         <child>
           <widget class="LongoMatch.Gui.Component.ProjectDetailsWidget" id="fdwidget">
             <property name="MemberName">fdwidget</property>
+            <property name="Edited">False</property>
             <property name="LocalGoals">0</property>
             <property name="VisitorGoals">0</property>
             <property name="Date">0</property>
diff --git a/LongoMatch/gtk-gui/objects.xml b/LongoMatch/gtk-gui/objects.xml
index 427a84f..8365497 100644
--- a/LongoMatch/gtk-gui/objects.xml
+++ b/LongoMatch/gtk-gui/objects.xml
@@ -205,9 +205,23 @@
     <itemgroups />
     <signals />
   </object>
+  <object type="LongoMatch.Gui.Component.PlaysListTreeWidget" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
+    <itemgroups />
+    <signals>
+      <itemgroup label="PlaysListTreeWidget Signals">
+        <signal name="TimeNodeSelected" />
+        <signal name="TimeNodeChanged" />
+        <signal name="TimeNodeDeleted" />
+        <signal name="PlayListNodeAdded" />
+        <signal name="SnapshotSeriesEvent" />
+        <signal name="PlayersTagged" />
+      </itemgroup>
+    </signals>
+  </object>
   <object type="LongoMatch.Gui.Component.ProjectDetailsWidget" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
     <itemgroups>
       <itemgroup label="ProjectDetailsWidget Properties">
+        <property name="Edited" />
         <property name="LocalName" />
         <property name="VisitorName" />
         <property name="Season" />
@@ -217,18 +231,9 @@
         <property name="Date" />
       </itemgroup>
     </itemgroups>
-    <signals />
-  </object>
-  <object type="LongoMatch.Gui.Component.PlaysListTreeWidget" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
-    <itemgroups />
     <signals>
-      <itemgroup label="PlaysListTreeWidget Signals">
-        <signal name="TimeNodeSelected" />
-        <signal name="TimeNodeChanged" />
-        <signal name="TimeNodeDeleted" />
-        <signal name="PlayListNodeAdded" />
-        <signal name="SnapshotSeriesEvent" />
-        <signal name="PlayersTagged" />
+      <itemgroup label="ProjectDetailsWidget Signals">
+        <signal name="EditedEvent" />
       </itemgroup>
     </signals>
   </object>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]