using System; using System.IO; using Gtk; using Glade; namespace AmicEditor { public class NewCathegoryDialog : Dialog { [Widget] Gtk.Dialog NewCathegory; //[Widget] Gtk.Button BtOk; [Widget] Gtk.Entry CatName; [Widget] Gtk.ColorButton CatColor; [Widget] Gtk.Button BtCancel; [Widget] Gtk.Button BtOk; [Widget] Gtk.FontButton CatFont; [Widget] Gtk.ColorButton CatFontColor; //[Widget] Gtk.ComboBoxEntry comboboxLang; [Widget] Gtk.ComboBox comboboxLang; Gallery MyGallery {get;set;} public NewCathegoryDialog (string _CatName, Gdk.Color _color, string _fontname, Gdk.Color _fontColor) // Constructor per a la importació { Application.Init (); //RadioButton rb; //rb.Toggle(); //rb.Active Glade.XML gxml = new Glade.XML(null, "NewCathegoryDialog.glade", "NewCathegory", null); gxml.Autoconnect (this); // Assignem els valors que ens proporcionen CatName.Text=_CatName; CatColor.Color=_color; CatFont.FontName=_fontname; CatFontColor.Color=_fontColor; Console.WriteLine(_CatName); Console.WriteLine(_color.ToString()); Console.WriteLine(_fontname); Console.WriteLine(_fontColor); // Inicialitzem el Combo d'idiomes InitComboLang(); BtCancel.Clicked += ImportHandleBtCancelClicked; BtOk.Clicked += ImportHandleBtOkClicked; } public NewCathegoryDialog (Gallery Gal) /////////////// { Application.Init(); MyGallery=Gal; //Glade.XML gxml = new Glade.XML(null, AmicEditor.dir_rsrc +"/NewCathegoryDialog.glade", "NewCathegory", null); Glade.XML gxml = new Glade.XML(null, "NewCathegoryDialog.glade", "NewCathegory", null); gxml.Autoconnect (this); // Inicialitzem el combo d'idiomes... InitComboLang(); BtCancel.Clicked += HandleBtCancelClicked; BtOk.Clicked += HandleBtOkClicked; } public void InitComboLang(){ /* * Inicialitza el ComboBox dels idiomes * * */ ListStore store = new ListStore(typeof (string), typeof (string), typeof(string)); this.comboboxLang.Clear(); Gtk.CellRendererText cell=new Gtk.CellRendererText(); this.comboboxLang.PackStart(cell, true); this.comboboxLang.AddAttribute(cell, "text", 0); this.comboboxLang.Model = store; //this.comboboxLang.TextColumn=0; // comboboxLang.TextColumn=0; store.AppendValues( Mono.Unix.Catalog.GetString("Valencian"), "qcv_ES"); store.AppendValues( Mono.Unix.Catalog.GetString("Spanish"), "es_ES"); store.AppendValues( Mono.Unix.Catalog.GetString("English"), "en_GB"); //Cal buscar l'idioma en les preferències //TreeIter MyIter; //comboboxLang.Model.GetIterFirst (out MyIter); //comboboxLang.SetActiveIter(MyIter); TreeIter Myiter; comboboxLang.Model.GetIterFirst(out Myiter); Console.WriteLine("Lang: "+Preferences.lang_code); do { GLib.Value thisRow = new GLib.Value (); comboboxLang.Model.GetValue (Myiter, 1, ref thisRow); Console.WriteLine("-----------Lang: "+thisRow.Val.ToString()); if ((thisRow.Val as string).Equals(Preferences.lang_code)) { Console.WriteLine("Coincidelx!"); comboboxLang.SetActiveIter (Myiter); break; } } while (comboboxLang.Model.IterNext (ref Myiter)); } void HandleBtOkClicked (object sender, EventArgs e) { // Validacio del nom no nul if(CatName.Text==""){ MessageDialog md = new MessageDialog (NewCathegory, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok, Mono.Unix.Catalog.GetString("The Cathegory should have any name. Please, write it before saving.")); //ResponseType result = (ResponseType)md.Run(); md.Run(); md.Destroy(); }else{ // Validem que no existeix cap altra categoria amb el nom if(MyGallery.Exists(CatName.Text)) { MessageDialog md = new MessageDialog (NewCathegory, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok, Mono.Unix.Catalog.GetString("This Cathegory already exists. Please, select another name.")); //ResponseType result = (ResponseType)md.Run(); md.Run(); md.Destroy(); } else{ AmicEditor.CreateNewCat=true; AmicEditor.CreatedCathegoryColor=CatColor.Color; AmicEditor.CreatedCathegoryName=CatName.Text; AmicEditor.CreatedCathegoryFont=CatFont.FontName; AmicEditor.CreatedCathegoryFontColor=CatFontColor.Color; AmicEditor.CreatedCathegoryLang=comboboxLang.ActiveText; Application.Quit(); NewCathegory.Destroy(); } } } void HandleBtCancelClicked (object sender, EventArgs e) { AmicEditor.CreateNewCat=false; //AmicEditor.CreatedCathegoryColor=null; //AmicEditor.CreatedCathegoryName=null; Application.Quit(); NewCathegory.Destroy(); } void ImportHandleBtOkClicked (object sender, EventArgs e) { if (File.Exists(Preferences.dir_gallery+"/"+CatName.Text+".xml")) { MessageDialog md=new MessageDialog(null, DialogFlags.Modal, MessageType.Error, ButtonsType.Close, Mono.Unix.Catalog.GetString("File ")+Preferences.dir_gallery+"/"+CatName.Text+".xml"+ Mono.Unix.Catalog.GetString(" already exists. Please, select another name.")); md.Modal=true; md.Run(); md.Destroy(); } else{ // Si l'arxiu no està, passem els paràmetres i tanquem la finestra PlaConverter.OkPressed=true; PlaConverter.CatName=CatName.Text; PlaConverter.font_color=CatFontColor.Color; PlaConverter.background_color=CatColor.Color; PlaConverter.cadena_font=CatFont.FontName; Application.Quit(); NewCathegory.Destroy(); } } void ImportHandleBtCancelClicked (object sender, EventArgs e) { PlaConverter.OkPressed=false; Application.Quit(); NewCathegory.Destroy(); } public new void Show(){ NewCathegory.ShowAll(); Application.Run(); } } }