[longomatch] Cache templates name to improve speed
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Cache templates name to improve speed
- Date: Thu, 23 Apr 2015 15:19:27 +0000 (UTC)
commit 9900bf5f5161a18fada08acb5ac09ca8376a18ff
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Thu Apr 16 18:36:15 2015 +0200
Cache templates name to improve speed
LongoMatch.GUI/Gui/Panel/SportsTemplatesPanel.cs | 48 ++++++++++---------
LongoMatch.GUI/Gui/Panel/TeamsTemplatesPanel.cs | 55 +++++++++++++--------
2 files changed, 59 insertions(+), 44 deletions(-)
---
diff --git a/LongoMatch.GUI/Gui/Panel/SportsTemplatesPanel.cs
b/LongoMatch.GUI/Gui/Panel/SportsTemplatesPanel.cs
index e5e0fb3..68e57f9 100644
--- a/LongoMatch.GUI/Gui/Panel/SportsTemplatesPanel.cs
+++ b/LongoMatch.GUI/Gui/Panel/SportsTemplatesPanel.cs
@@ -40,6 +40,8 @@ namespace LongoMatch.Gui.Panel
ListStore templates;
Dashboard loadedTemplate;
ICategoriesTemplatesProvider provider;
+ TreeIter selectedIter;
+ List<string> templatesNames;
public SportsTemplatesPanel ()
{
@@ -80,29 +82,24 @@ namespace LongoMatch.Gui.Panel
addcategorybutton.Entered += HandleEnterTagButton;
addcategorybutton.Left += HandleLeftTagButton;
- addcategorybutton.Clicked += (object sender, EventArgs e) => {
+ addcategorybutton.Clicked += (object sender, EventArgs e) =>
buttonswidget.AddButton ("Category");
- };
addtagbutton1.Entered += HandleEnterTagButton;
addtagbutton1.Left += HandleLeftTagButton;
- addtagbutton1.Clicked += (object sender, EventArgs e) => {
+ addtagbutton1.Clicked += (object sender, EventArgs e) =>
buttonswidget.AddButton ("Tag");
- };
scorebutton.Entered += HandleEnterTagButton;
scorebutton.Left += HandleLeftTagButton;
- scorebutton.Clicked += (object sender, EventArgs e) => {
+ scorebutton.Clicked += (object sender, EventArgs e) =>
buttonswidget.AddButton ("Score");
- };
cardbutton.Entered += HandleEnterTagButton;
cardbutton.Left += HandleLeftTagButton;
- cardbutton.Clicked += (object sender, EventArgs e) => {
+ cardbutton.Clicked += (object sender, EventArgs e) =>
buttonswidget.AddButton ("Card");
- };
timerbutton.Entered += HandleEnterTagButton;
timerbutton.Left += HandleLeftTagButton;
- timerbutton.Clicked += (object sender, EventArgs e) => {
+ timerbutton.Clicked += (object sender, EventArgs e) =>
buttonswidget.AddButton ("Timer");
- };
templates = new ListStore (typeof(Pixbuf), typeof(string), typeof(string),
typeof(bool));
@@ -147,7 +144,8 @@ namespace LongoMatch.Gui.Panel
{
TreeIter templateIter = TreeIter.Zero;
bool first = true;
-
+
+ templatesNames = new List<string> ();
templates.Clear ();
foreach (Dashboard template in provider.Templates) {
Pixbuf img;
@@ -157,11 +155,13 @@ namespace LongoMatch.Gui.Panel
if (template.Image != null)
img = template.Image.Value;
else
- img = Helpers.Misc.LoadIcon ("longomatch", 20,
IconLookupFlags.ForceSvg);
+ img = Helpers.Misc.LoadIcon ("longomatch", 20);
name = template.Name;
if (template.Static) {
name += " (" + Catalog.GetString ("System") + ")";
+ } else {
+ templatesNames.Add (name);
}
iter = templates.AppendValues (img, name, template.Name, !template.Static);
if (first || template.Name == templateName) {
@@ -196,7 +196,7 @@ namespace LongoMatch.Gui.Panel
loadedTemplate.Name + "_copy", this);
if (newName == null)
break;
- if (provider.TemplatesNames.Contains (newName)) {
+ if (templatesNames.Contains (newName)) {
msg = Catalog.GetString ("A dashboard with the same name
already exists");
Config.GUIToolkit.ErrorMessage (msg, this);
} else {
@@ -274,14 +274,13 @@ namespace LongoMatch.Gui.Panel
void HandleSelectionChanged (object sender, EventArgs e)
{
- TreeIter iter;
Dashboard selected;
- dashboardseditortreeview.Selection.GetSelected (out iter);
+ dashboardseditortreeview.Selection.GetSelected (out selectedIter);
try {
// Load using the template real name and not the display name
- selected = provider.Load (templates.GetValue (iter, 2) as string);
+ selected = provider.Load (templates.GetValue (selectedIter, 2) as string);
} catch (Exception ex) {
Config.GUIToolkit.ErrorMessage (Catalog.GetString ("Could not load
dashboard"));
return;
@@ -302,9 +301,13 @@ namespace LongoMatch.Gui.Panel
string msg = Catalog.GetString ("Do you really want to delete the dashboard:
") + loadedTemplate.Name;
if (MessagesHelpers.QuestionMessage (this, msg, null)) {
provider.Delete (loadedTemplate.Name);
+ templates.Remove (ref selectedIter);
+ templatesNames.Remove (loadedTemplate.Name);
+ selectedIter = TreeIter.Zero;
+ dashboardseditortreeview.Selection.SelectPath (new TreePath ("0"));
+ HandleSelectionChanged (null, null);
}
}
- Load (provider.TemplatesNames.FirstOrDefault ());
}
void HandleImportTemplateClicked (object sender, EventArgs e)
@@ -342,16 +345,13 @@ namespace LongoMatch.Gui.Panel
Pixbuf img;
provider.Save (new_dashboard);
-
if (new_dashboard.Image != null)
img = new_dashboard.Image.Value;
else
- img = Helpers.Misc.LoadIcon ("longomatch", 20,
IconLookupFlags.ForceSvg);
+ img = Helpers.Misc.LoadIcon ("longomatch", 20);
string name = new_dashboard.Name;
-
templates.AppendValues (img, name, name,
!new_dashboard.Static);
-
Load (new_dashboard.Name);
}
}
@@ -373,7 +373,7 @@ namespace LongoMatch.Gui.Panel
dialog.ShowCount = true;
dialog.Text = Catalog.GetString ("New dasboard");
dialog.CountText = Catalog.GetString ("Event types:");
- dialog.AvailableTemplates = provider.TemplatesNames;
+ dialog.AvailableTemplates = templatesNames;
while (dialog.Run () == (int)ResponseType.Ok) {
if (dialog.Text == "") {
@@ -429,7 +429,7 @@ namespace LongoMatch.Gui.Panel
string name = (string)templates.GetValue (iter, 2);
if (name != args.NewText) {
- if (provider.TemplatesNames.Contains (args.NewText)) {
+ if (templatesNames.Contains (args.NewText)) {
Config.GUIToolkit.ErrorMessage (Catalog.GetString ("A dashboard with
the same name already exists"), this);
args.RetVal = false;
} else {
@@ -438,6 +438,8 @@ namespace LongoMatch.Gui.Panel
dashboard.Name = args.NewText;
provider.Save (dashboard);
provider.Delete (name);
+ templatesNames.Remove (name);
+ templatesNames.Add (dashboard.Name);
// Change displayed name and template name in our store
templates.SetValue (iter, 1, args.NewText);
templates.SetValue (iter, 2, args.NewText);
diff --git a/LongoMatch.GUI/Gui/Panel/TeamsTemplatesPanel.cs b/LongoMatch.GUI/Gui/Panel/TeamsTemplatesPanel.cs
index 885a2ff..286a3fc 100644
--- a/LongoMatch.GUI/Gui/Panel/TeamsTemplatesPanel.cs
+++ b/LongoMatch.GUI/Gui/Panel/TeamsTemplatesPanel.cs
@@ -40,6 +40,8 @@ namespace LongoMatch.Gui.Panel
ListStore teams;
Team loadedTeam;
ITeamTemplatesProvider provider;
+ TreeIter selectedIter;
+ List<string> templatesNames;
public TeamsTemplatesPanel ()
{
@@ -121,13 +123,14 @@ namespace LongoMatch.Gui.Panel
{
TreeIter templateIter = TreeIter.Zero;
bool first = true;
-
+
+ templatesNames = new List<string> ();
teams.Clear ();
foreach (Team template in provider.Templates) {
Pixbuf img;
TreeIter iter;
string name = template.Name;
-
+
if (template.Shield != null) {
img = template.Shield.Scale (StyleConf.TeamsShieldIconSize,
StyleConf.TeamsShieldIconSize).Value;
@@ -137,6 +140,8 @@ namespace LongoMatch.Gui.Panel
}
if (template.Static) {
name += " (" + Catalog.GetString ("System") + ")";
+ } else {
+ templatesNames.Add (name);
}
iter = teams.AppendValues (img, name, template.Name);
if (first || template.Name == templateName) {
@@ -228,7 +233,7 @@ namespace LongoMatch.Gui.Panel
loadedTeam.Name + "_copy", this);
if (newName == null)
break;
- if (provider.TemplatesNames.Contains (newName)) {
+ if (templatesNames.Contains (newName)) {
msg = Catalog.GetString ("A team with the same name already
exists");
Config.GUIToolkit.ErrorMessage (msg, this);
} else {
@@ -252,15 +257,16 @@ namespace LongoMatch.Gui.Panel
{
if (loadedTeam != null && teamtemplateeditor1.Edited) {
if (loadedTeam.Static) {
- /* prompt=false when we click the save button */
if (!prompt) {
SaveStatic ();
}
- } else {
+ } else if (prompt) {
string msg = Catalog.GetString ("Do you want to save the current
template");
if (Config.GUIToolkit.QuestionMessage (msg, null, this)) {
SaveLoadedTeam ();
}
+ } else {
+ SaveLoadedTeam ();
}
}
}
@@ -277,11 +283,10 @@ namespace LongoMatch.Gui.Panel
void HandleSelectionChanged (object sender, EventArgs e)
{
Team selected;
- TreeIter iter;
- teamseditortreeview.Selection.GetSelected (out iter);
+ teamseditortreeview.Selection.GetSelected (out selectedIter);
try {
- selected = Config.TeamTemplatesProvider.Load (teams.GetValue (iter, 2) as
string);
+ selected = Config.TeamTemplatesProvider.Load (teams.GetValue (selectedIter,
2) as string);
} catch (Exception ex) {
Log.Exception (ex);
Config.GUIToolkit.ErrorMessage (Catalog.GetString ("Could not load team"));
@@ -297,17 +302,22 @@ namespace LongoMatch.Gui.Panel
void HandleDeleteTeamClicked (object sender, EventArgs e)
{
if (loadedTeam != null) {
- if (loadedTeam.Name == "default") {
- MessagesHelpers.ErrorMessage (this,
- Catalog.GetString ("The default team can't be deleted"));
+ if (loadedTeam.Static) {
+ string msg = Catalog.GetString ("System teams can't be deleted");
+ MessagesHelpers.WarningMessage (this, msg);
return;
- }
- string msg = Catalog.GetString ("Do you really want to delete the template:
") + loadedTeam.Name;
- if (MessagesHelpers.QuestionMessage (this, msg, null)) {
- provider.Delete (loadedTeam.Name);
+ } else {
+ string msg = Catalog.GetString ("Do you really want to delete the
template: ") + loadedTeam.Name;
+ if (MessagesHelpers.QuestionMessage (this, msg, null)) {
+ provider.Delete (loadedTeam.Name);
+ teams.Remove (ref selectedIter);
+ templatesNames.Remove (loadedTeam.Name);
+ selectedIter = TreeIter.Zero;
+ teamseditortreeview.Selection.SelectPath (new TreePath ("0"));
+ HandleSelectionChanged (null, null);
+ }
}
}
- Load ("default");
}
void HandleNewTeamClicked (object sender, EventArgs e)
@@ -319,7 +329,7 @@ namespace LongoMatch.Gui.Panel
dialog.TransientFor = (Gtk.Window)this.Toplevel;
dialog.ShowCount = true;
dialog.Text = Catalog.GetString ("New team");
- dialog.AvailableTemplates = provider.TemplatesNames;
+ dialog.AvailableTemplates = templatesNames;
while (dialog.Run () == (int)ResponseType.Ok) {
if (dialog.Text == "") {
@@ -369,13 +379,14 @@ namespace LongoMatch.Gui.Panel
void HandleEdited (object o, EditedArgs args)
{
- Gtk.TreeIter iter;
- teams.GetIter (out iter, new Gtk.TreePath (args.Path));
+ TreeIter iter;
+ teams.GetIter (out iter, new TreePath (args.Path));
string name = (string)teams.GetValue (iter, 2);
if (name != args.NewText) {
- if (provider.TemplatesNames.Contains (args.NewText)) {
- Config.GUIToolkit.ErrorMessage (Catalog.GetString ("A team with the
same name already exists"), this);
+ if (templatesNames.Contains (args.NewText)) {
+ Config.GUIToolkit.ErrorMessage (
+ Catalog.GetString ("A team with the same name already
exists"), this);
args.RetVal = false;
} else {
try {
@@ -383,6 +394,8 @@ namespace LongoMatch.Gui.Panel
team.Name = args.NewText;
provider.Save (team);
provider.Delete (name);
+ templatesNames.Remove (name);
+ templatesNames.Add (team.Name);
teams.SetValue (iter, 1, args.NewText);
teams.SetValue (iter, 2, args.NewText);
} catch (Exception ex) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]