[longomatch/redesign3: 99/156] Add base class for the templates editor dialog
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch/redesign3: 99/156] Add base class for the templates editor dialog
- Date: Wed, 17 Aug 2011 22:24:30 +0000 (UTC)
commit 95ed24e8ee1386f0bc0b2dfa0e5c2a37e23df72b
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Wed Mar 30 22:19:45 2011 +0200
Add base class for the templates editor dialog
LongoMatch/Gui/Component/TeamTemplateWidget.cs | 83 ------
...lateEditorDialog.cs => TemplateEditorDialog.cs} | 56 +++--
LongoMatch/Gui/Dialog/TemplatesManager.cs | 269 ++++++++++++++++++++
.../LongoMatch.Gui.Dialog.TeamTemplateEditor.cs | 60 -----
... LongoMatch.Gui.Dialog.TemplateEditorDialog.cs} | 23 +-
5 files changed, 316 insertions(+), 175 deletions(-)
---
diff --git a/LongoMatch/Gui/Dialog/ProjectTemplateEditorDialog.cs b/LongoMatch/Gui/Dialog/TemplateEditorDialog.cs
similarity index 58%
rename from LongoMatch/Gui/Dialog/ProjectTemplateEditorDialog.cs
rename to LongoMatch/Gui/Dialog/TemplateEditorDialog.cs
index 7445443..cf3162a 100644
--- a/LongoMatch/Gui/Dialog/ProjectTemplateEditorDialog.cs
+++ b/LongoMatch/Gui/Dialog/TemplateEditorDialog.cs
@@ -18,6 +18,9 @@
//
//
using System;
+using Gtk;
+
+using LongoMatch.Interfaces;
using LongoMatch.Store;
using LongoMatch.Store.Templates;
@@ -26,38 +29,51 @@ namespace LongoMatch.Gui.Dialog
[System.ComponentModel.Category("LongoMatch")]
[System.ComponentModel.ToolboxItem(false)]
- public partial class ProjectTemplateEditorDialog : Gtk.Dialog
+ public abstract partial class TemplateEditorDialog: Gtk.Dialog
{
-
- public ProjectTemplateEditorDialog()
+ public TemplateEditorDialog()
{
this.Build();
- projecttemplatewidget.CanExport = true;
}
-
- public Project Project {
+
+ public void AddTemplateEditor (Widget w){
+ templateeditorbox.Add(w);
+ w.Show();
+ }
+ }
+
+ public class TemplateEditorDialog<T, U> : TemplateEditorDialog where T: ITemplate<U> {
+ ITemplateWidget<T, U> templateEditor;
+
+ public TemplateEditorDialog () {
+ templateEditor = MainClass.ts.GetTemplateEditor<T, U> ();
+ templateEditor.CanExport = true;
+ AddTemplateEditor ((Widget)templateEditor);
+
+ }
+
+ public bool CanExport {
set {
- projecttemplatewidget.Project = value;
+ templateEditor.CanExport = value;
}
}
-
- public Categories Categories {
- set {
- projecttemplatewidget.Categories =value;
+
+ public bool InProject {
+ set{
+ templateEditor.InProject = value;
}
- get {
- return projecttemplatewidget.Categories;
+ get{
+ return templateEditor.InProject;
}
}
-
- public bool CanExport {
+
+ public T Template {
set {
- projecttemplatewidget.CanExport = value;
+ templateEditor.Template =value;
+ }
+ get {
+ return templateEditor.Template;
}
- }
-
- protected virtual void OnButtonOkClicked(object sender, System.EventArgs e)
- {
}
}
diff --git a/LongoMatch/Gui/Dialog/TemplatesManager.cs b/LongoMatch/Gui/Dialog/TemplatesManager.cs
new file mode 100644
index 0000000..6501797
--- /dev/null
+++ b/LongoMatch/Gui/Dialog/TemplatesManager.cs
@@ -0,0 +1,269 @@
+// TemplatesManager.cs
+//
+// Copyright (C) 2007-2009 Andoni Morales Alastruey
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+//
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using Gtk;
+using Mono.Unix;
+
+using LongoMatch.Interfaces;
+using LongoMatch.Gui.Component;
+using LongoMatch.Store.Templates;
+using LongoMatch.Services;
+
+namespace LongoMatch.Gui.Dialog
+{
+
+ /* HACK: Stetic doesn't allow the use of generics, which is needed for
+ * the different types of Template classes */
+ [System.ComponentModel.Category("LongoMatch")]
+ [System.ComponentModel.ToolboxItem(false)]
+ public partial class TemplatesManager : Gtk.Dialog
+ {
+ protected virtual void OnSavebuttonClicked(object sender, System.EventArgs e) {}
+ protected virtual void OnNewbuttonClicked(object sender, System.EventArgs e) {}
+ protected virtual void OnDeletebuttonClicked(object sender, System.EventArgs e) {}
+ protected virtual void OnButtonCancelClicked(object sender, System.EventArgs e) {}
+ protected virtual void OnTreeviewCursorChanged(object sender, System.EventArgs e) {}
+ protected virtual void OnButtonOkClicked(object sender, System.EventArgs e) {}
+ protected virtual void OnTreeviewRowActivated(object o, Gtk.RowActivatedArgs args) {}
+
+ public TemplatesManager () {
+ this.Build();
+ }
+
+ public TreeView TreeView {
+ get {
+ return treeview;
+ }
+ }
+
+ public new bool Sensitive {
+ set{
+ savebutton.Sensitive = value;
+ deletebutton.Sensitive = value;
+ base.Sensitive = value;
+ }
+ }
+
+ public void AddTemplateEditor (Widget w) {
+ templateditorbox.Add(w);
+ w.Show();
+ }
+ }
+
+ public class TemplatesManager<T, U> : TemplatesManager where T: ITemplate<U>
+ {
+ private TreeView treeview;
+ private Gtk.ListStore dataFileListStore;
+ private ITemplateProvider<T, U> templatesProvider;
+ private T selectedTemplate;
+ private ITemplateWidget<T, U> templatesWidget;
+ private string templateName;
+
+ public TemplatesManager() : base()
+ {
+ treeview = this.TreeView;
+ templatesProvider = MainClass.ts.GetTemplateProvider<T, U> ();
+ templatesWidget = MainClass.ts.GetTemplateEditor <T, U> ();
+ AddTemplateEditor ((Widget) templatesWidget);
+
+ Gtk.TreeViewColumn templateFileColumn = new Gtk.TreeViewColumn();
+ templateFileColumn.Title = Catalog.GetString("Templates Files");
+ Gtk.CellRendererText templateFileCell = new Gtk.CellRendererText();
+ templateFileColumn.PackStart(templateFileCell, true);
+ templateFileColumn.SetCellDataFunc(templateFileCell, new Gtk.TreeCellDataFunc(RenderTemplateFile));
+ treeview.AppendColumn(templateFileColumn);
+ Fill();
+ }
+
+ public new bool Sensitive {
+ set{
+ (templatesWidget as Widget).Sensitive = value;
+ base.Sensitive = value;
+ }
+ }
+
+ public bool Edited {
+ set {
+ templatesWidget.Edited = value;
+ }
+ get {
+ return templatesWidget.Edited;
+ }
+ }
+ private void Fill() {
+ dataFileListStore = new Gtk.ListStore(typeof(string));
+
+ foreach(string filePath in templatesProvider.TemplatesNames) {
+ dataFileListStore.AppendValues(filePath);
+ }
+ treeview.Model = dataFileListStore;
+ }
+
+ private void RenderTemplateFile(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
+ {
+ (cell as Gtk.CellRendererText).Text = (string) model.GetValue(iter, 0);
+ }
+
+ public void SetTemplate (T template) {
+ templatesWidget.Template = template;
+ }
+
+ private void UpdateSelectedTemplate() {
+ templatesWidget.Template = templatesProvider.Load(templateName);
+ }
+
+ private void SaveTemplate() {
+ selectedTemplate = templatesWidget.Template;
+ templatesProvider.Save(selectedTemplate);
+ }
+
+ private void SelectTemplate(string name) {
+ TreeIter iter;
+ string tName;
+ ListStore model = (ListStore)treeview.Model;
+
+ model.GetIterFirst(out iter);
+ while(model.IterIsValid(iter)) {
+ tName = (string) model.GetValue(iter,0);
+ if(tName == name) {
+ this.templateName = tName;
+ treeview.SetCursor(model.GetPath(iter),null,false);
+ return;
+ }
+ model.IterNext(ref iter);
+ }
+ }
+
+ private void PromptForSave() {
+ MessageDialog mes = new MessageDialog(this,DialogFlags.Modal,
+ MessageType.Question,
+ ButtonsType.YesNo,
+ Catalog.GetString("The template has been modified. " +
+ "Do you want to save it? "));
+ if(mes.Run() == (int)ResponseType.Yes) {
+ SaveTemplate();
+ }
+ mes.Destroy();
+ }
+
+ protected override void OnSavebuttonClicked(object sender, System.EventArgs e)
+ {
+ SaveTemplate();
+ Edited = false;
+ }
+
+ protected override void OnNewbuttonClicked(object sender, System.EventArgs e)
+ {
+ string name;
+ int count;
+ List<string> availableTemplates = new List<string>();
+ EntryDialog ed = new EntryDialog{ShowCount = true,
+ Title = Catalog.GetString("Template name")};
+
+ foreach(string templateName in templatesProvider.TemplatesNames) {
+ if(templateName != "default")
+ availableTemplates.Add(templateName);
+ }
+ ed.AvailableTemplates = availableTemplates;
+
+ if(ed.Run() == (int)ResponseType.Ok) {
+ name = ed.Text;
+ count = ed.Count;
+ if(name == "") {
+ MessagePopup.PopupMessage(ed, MessageType.Warning,
+ Catalog.GetString("You cannot create a template with a void name"));
+ ed.Destroy();
+ return;
+ } else if (templatesProvider.Exists(name)) {
+ MessagePopup.PopupMessage(ed, MessageType.Warning,
+ Catalog.GetString("A template with this name already exists"));
+ ed.Destroy();
+ return;
+ }
+
+ /* Check if we are copying an existing template */
+ if(ed.SelectedTemplate != null)
+ templatesProvider.Copy(ed.SelectedTemplate, name);
+ else
+ templatesProvider.Create(name, count);
+
+ Fill();
+ SelectTemplate(name);
+ }
+ ed.Destroy();
+ }
+
+ protected override void OnDeletebuttonClicked(object sender, System.EventArgs e)
+ {
+ if(templateName =="default") {
+ MessagePopup.PopupMessage(this,MessageType.Warning,
+ Catalog.GetString("You can't delete the 'default' template"));
+ return;
+ }
+
+ MessageDialog mes = new MessageDialog(this,DialogFlags.Modal,MessageType.Warning,ButtonsType.YesNo,
+ Catalog.GetString("Do you really want to delete the template: ")+
+ templateName);
+ if(mes.Run() == (int)ResponseType.Yes) {
+ templatesProvider.Delete(templateName);
+ this.Fill();
+ //The default template is always there so we select this one.
+ //This allow to reset all the fields in the sections/players
+ //properties.
+ SelectTemplate("default");
+ }
+ mes.Destroy();
+ }
+
+ protected override void OnButtonCancelClicked(object sender, System.EventArgs e)
+ {
+ this.Destroy();
+ }
+
+ protected override void OnTreeviewCursorChanged(object sender, System.EventArgs e)
+ {
+ TreeIter iter;
+
+ if(Edited)
+ PromptForSave();
+
+ treeview.Selection.GetSelected(out iter);
+ templateName = (string) this.dataFileListStore.GetValue(iter, 0);
+
+ UpdateSelectedTemplate();
+ Sensitive = true;
+ }
+
+ protected override void OnButtonOkClicked(object sender, System.EventArgs e)
+ {
+ if(Edited)
+ PromptForSave();
+ this.Destroy();
+ }
+
+ protected override void OnTreeviewRowActivated(object o, Gtk.RowActivatedArgs args)
+ {
+ UpdateSelectedTemplate();
+ }
+ }
+}
diff --git a/LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.ProjectTemplateEditorDialog.cs b/LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.TemplateEditorDialog.cs
similarity index 68%
rename from LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.ProjectTemplateEditorDialog.cs
rename to LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.TemplateEditorDialog.cs
index 5205418..62abd23 100644
--- a/LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.ProjectTemplateEditorDialog.cs
+++ b/LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.TemplateEditorDialog.cs
@@ -2,17 +2,17 @@
// This file has been generated by the GUI designer. Do not modify.
namespace LongoMatch.Gui.Dialog
{
- public partial class ProjectTemplateEditorDialog
+ public partial class TemplateEditorDialog
{
- private global::LongoMatch.Gui.Component.ProjectTemplateWidget projecttemplatewidget;
+ private global::Gtk.HBox templateeditorbox;
private global::Gtk.Button buttonOk;
protected virtual void Build ()
{
global::Stetic.Gui.Initialize (this);
- // Widget LongoMatch.Gui.Dialog.ProjectTemplateEditorDialog
- this.Name = "LongoMatch.Gui.Dialog.ProjectTemplateEditorDialog";
+ // Widget LongoMatch.Gui.Dialog.TemplateEditorDialog
+ this.Name = "LongoMatch.Gui.Dialog.TemplateEditorDialog";
this.Title = global::Mono.Unix.Catalog.GetString ("Categories Template");
this.Icon = global::Stetic.IconLoader.LoadIcon (this, "longomatch", global::Gtk.IconSize.Dialog);
this.WindowPosition = ((global::Gtk.WindowPosition)(4));
@@ -20,19 +20,18 @@ namespace LongoMatch.Gui.Dialog
this.Gravity = ((global::Gdk.Gravity)(5));
this.SkipPagerHint = true;
this.SkipTaskbarHint = true;
- // Internal child LongoMatch.Gui.Dialog.ProjectTemplateEditorDialog.VBox
+ // Internal child LongoMatch.Gui.Dialog.TemplateEditorDialog.VBox
global::Gtk.VBox w1 = this.VBox;
w1.Name = "dialog1_VBox";
w1.BorderWidth = ((uint)(2));
// Container child dialog1_VBox.Gtk.Box+BoxChild
- this.projecttemplatewidget = new global::LongoMatch.Gui.Component.ProjectTemplateWidget ();
- this.projecttemplatewidget.Events = ((global::Gdk.EventMask)(256));
- this.projecttemplatewidget.Name = "projecttemplatewidget";
- this.projecttemplatewidget.Edited = false;
- w1.Add (this.projecttemplatewidget);
- global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(w1[this.projecttemplatewidget]));
+ this.templateeditorbox = new global::Gtk.HBox ();
+ this.templateeditorbox.Name = "templateeditorbox";
+ this.templateeditorbox.Spacing = 6;
+ w1.Add (this.templateeditorbox);
+ global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(w1[this.templateeditorbox]));
w2.Position = 0;
- // Internal child LongoMatch.Gui.Dialog.ProjectTemplateEditorDialog.ActionArea
+ // Internal child LongoMatch.Gui.Dialog.TemplateEditorDialog.ActionArea
global::Gtk.HButtonBox w3 = this.ActionArea;
w3.Name = "dialog1_ActionArea";
w3.Spacing = 6;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]