public DebaterPatternEditor(string p) { this.Build(); this.ActionArea.Hide(); this.DestroyWithParent = true; this.Modal = true; this.Decorated = true; this.Title = "Press Esc to close"; alAdd = new Alignment(0, 0, 0, 0); Button btnAdd = new Button(); Image im = new Image(); im.Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-add", IconSize.Menu); btnAdd.Add(im); btnAdd.Clicked += OnBtnAddClicked; alAdd.Add(btnAdd); pattern = new DebaterPattern(); try { pattern = DebaterPattern.Parse(p); } catch { } UpdateGui(); }
public RemoveButton(DebaterPattern p, object i) : base() { Image im = new Image(); im.Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-remove", IconSize.Menu); Add(im); Clicked += delegate(object sender, EventArgs e) { if (i is string) { p.RemoveClub((string)i); } else if (i is Name) { p.RemoveDebater((Name)i); } }; }
void AppendCombobox(List <string> items) { ListStore store = new ListStore(typeof(string)); foreach (string i in items) { store.AppendValues(i); } ComboBoxEntry cb = new ComboBoxEntry(store, 0); HBox hbox = new HBox(); // btnOk Button btnOk = new Button(); Image im = new Image(); im.Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-apply", IconSize.Menu); btnOk.Add(im); btnOk.Clicked += delegate { try { pattern = DebaterPattern.Parse(pattern + "; " + cb.ActiveText); } catch (Exception ex) { MiscHelpers.ShowMessage(this, "Could not add pattern: " + ex.Message, MessageType.Error); return; } UpdateGui(); }; hbox.PackStart(btnOk, false, false, 0); // btnCancel Button btnCancel = new Button(); im = new Image(); im.Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-cancel", IconSize.Menu); btnCancel.Add(im); btnCancel.Clicked += delegate { UpdateGui(); }; hbox.PackStart(btnCancel, false, false, 0); // cb as last element hbox.PackStart(cb, false, false, 0); hbox.ShowAll(); vbox.PackStart(hbox, false, false, 0); }
protected virtual void OnBtnImportCSVClicked(object sender, System.EventArgs e) { if (cbOverwrite.Active) { if (MiscHelpers.AskYesNo(this, "This clears all " + "entered Data for " + "overwritten Debaters. " + "Continue?") == ResponseType.No) { return; } } // make a backup before! Tournament.I.Save(); // start import List <Debater> debaters = Tournament.I.Debaters; int line = 0; try { CsvReader csv = new CsvReader(new StreamReader(labelFile.Text), cbHasHeaders.Active, ',', '"', '\\', '#', ValueTrimmingOptions.All); int dups = 0; int ok = 0; while (csv.ReadNextRecord()) { line++; EditableDebater d = new EditableDebater(); d.Name = new Name(csv[sbFirstName.ValueAsInt], csv[sbLastName.ValueAsInt]); // Club try { if (cbCity.Active) { d.Club = new Club(csv[sbClub.ValueAsInt], csv[sbCity.ValueAsInt]); } else { d.Club = new Club(csv[sbClub.ValueAsInt]); } } catch { d.Club = new Club("None"); d.BlackList.RemoveClub("None"); } // Age or from Birthday try { if (cbAge.Active) { d.Age = uint.Parse(csv [sbAge.ValueAsInt]); } if (cbBirthday.Active) { DateTime bday = DateTime.ParseExact(csv[sbBirthday.ValueAsInt], entryBdayFormat.Text, null); DateTime now = DateTime.Today; int age = now.Year - bday.Year; if (bday > now.AddYears(-age)) { age--; } d.Age = (uint)age; } } catch {} // Role if (cbRole.Active) { if (rbTeamMember.Active) { d.Role = OPDtabData.Role.Parse(csv [sbRole.ValueAsInt]); } else if (rbJudge.Active) { int judgeQuality = 0; try { judgeQuality = (int)uint.Parse(csv[sbRole.ValueAsInt]); } catch {} d.Role.JudgeQuality = judgeQuality; } } // ExtraInfo d.ExtraInfo = entryExtraInfoDefault.Text; if (cbExtraInfo.Active) { d.ExtraInfo = csv[sbExtraInfo.ValueAsInt] == "" ? entryExtraInfoDefault.Text : csv[sbExtraInfo.ValueAsInt]; } // BlackList if (cbBlackList.Active) { d.BlackList = DebaterPattern.Parse(csv[sbBlackList.ValueAsInt]); } // save it int i = debaters.FindLastIndex(delegate(Debater de) { return(de.Equals(d)); }); if (i < 0) { debaters.Add(new Debater(d)); ok++; } else { Console.WriteLine("Duplicate: " + d + ", " + debaters[i]); dups++; if (cbOverwrite.Active) { debaters[i] = new Debater(d); ok++; } } } string action = cbOverwrite.Active ? "overwritten" : "discarded"; MiscHelpers.ShowMessage(this, "Imported " + ok + ", " + action + " " + dups + " duplicates.", MessageType.Info); } catch (Exception ex) { MiscHelpers.ShowMessage(this, "Error encountered in line " + line.ToString() + ": " + ex.Message, MessageType.Error); } }
protected void OnBtnAddClicked(object sender, System.EventArgs e) { // create combobox selection by aggregating clubs List <string> clubs = new List <string>(); List <string> debaters = new List <string>(); foreach (Debater d in Tournament.I.Debaters) { if (!clubs.Contains("@" + d.Club.Name)) { clubs.Add("@" + d.Club.Name); } debaters.Add(d.Name.ToString()); } clubs.Sort(); debaters.Sort(); ListStore store = new ListStore(typeof(string)); foreach (string c in clubs) { store.AppendValues(c); } foreach (string d in debaters) { store.AppendValues(d); } ComboBoxEntry cb = new ComboBoxEntry(store, 0); cb.Entry.Completion = new EntryCompletion(); cb.Entry.Completion.Model = store; cb.Entry.Completion.TextColumn = 0; cb.Entry.Completion.InlineCompletion = true; HBox hbox = new HBox(); // btnOk Button btnOk = new Button(); Image im = new Image(); im.Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-apply", IconSize.Menu); btnOk.Add(im); btnOk.Clicked += delegate { try { pattern = DebaterPattern.Parse(pattern + "; " + cb.ActiveText); } catch (Exception ex) { MiscHelpers.ShowMessage(this, "Could not add pattern: " + ex.Message, MessageType.Error); return; } UpdateGui(); }; hbox.PackStart(btnOk, false, false, 0); // btnCancel Button btnCancel = new Button(); im = new Image(); im.Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-cancel", IconSize.Menu); btnCancel.Add(im); btnCancel.Clicked += delegate { UpdateGui(); }; hbox.PackStart(btnCancel, false, false, 0); // cb as last element hbox.PackStart(cb, false, false, 0); hbox.ShowAll(); vbox.PackStart(hbox, false, false, 0); alAdd.Hide(); GtkScrolledWindow.Vadjustment.Value = GtkScrolledWindow.Vadjustment.Upper; }
// TODO Currently, all the parsing functions simply swallow errors, // doing nothing if an error is encountered. It might me nicer to // give some feedback to the user. public EditDebaters() : base(WindowType.Toplevel) { columns = new Dictionary <string, ColumnInfo> { { "Name", new ColumnInfo { cellRendererType = CellRendererTextAdv.Type.Entry, get = e => new DebaterProperty <Name>( e.Name, (e1, name) => e1.Name = name, (e1, name) => e1.Name = name), parseAndSet = (e, name) => { OPDtabData.Name.Parse(name).Do(n => e.Name = n); } } }, { "Club", new ColumnInfo { cellRendererType = CellRendererTextAdv.Type.EntryWithCompletion, get = e => new DebaterProperty <Club>( e.Club, (e1, club) => e1.Club = club, (e1, club) => e1.Club = club), parseAndSet = (e, club) => { Club.Parse(club).Do(c => e.Club = c); } } }, { "Age", new ColumnInfo { cellRendererType = CellRendererTextAdv.Type.Entry, get = e => new DebaterProperty <uint>( e.Age, (e1, age) => e1.Age = age, (e1, age) => e1.Age = age), parseAndSet = (e, age) => { try { e.Age = uint.Parse(age); } catch (FormatException) {} } } }, { "Role", new ColumnInfo { cellRendererType = CellRendererTextAdv.Type.EntryWithCompletion, get = e => new DebaterProperty <Role>( e.Role, (e1, role) => e1.Role = role, (e1, role) => e1.Role = role), parseAndSet = (e, role) => { e.Role = OPDtabData.Role.Parse(role); } } }, { "BlackList", new ColumnInfo { cellRendererType = CellRendererTextAdv.Type.DebaterPattern, get = e => new DebaterProperty <DebaterPattern>( e.BlackList, (e1, bl) => e1.BlackList = bl, (_, __) => { throw new Exception( "Attempt to set BlackList property of RoundDebater."); }), parseAndSet = (e, bl) => e.BlackList = DebaterPattern.Parse(bl) } }, { "WhiteList", new ColumnInfo { cellRendererType = CellRendererTextAdv.Type.DebaterPattern, get = e => new DebaterProperty <DebaterPattern>( e.WhiteList, (e1, wl) => e1.WhiteList = wl, (_, __) => { throw new Exception( "Attempt to set WhiteList property of RoundDebater."); }), parseAndSet = (e, wl) => e.WhiteList = DebaterPattern.Parse(wl) } }, { "ExtraInfo", new ColumnInfo { cellRendererType = CellRendererTextAdv.Type.Entry, get = e => new DebaterProperty <string>( e.ExtraInfo, (e1, info) => e1.ExtraInfo = info, (_, __) => { throw new Exception( "Attempt to set ExtraInfo property of RoundDebater."); }), parseAndSet = (e, info) => e.ExtraInfo = info.Trim() } } }; Build(); editDebatersSettings = AppSettings.I.EditDebaters; entryDebatersFilter = MiscHelpers.MakeFilterEntry(); entryDebatersFilter.Changed += OnEntryDebatersFilterChanged; cEntryFilter.Add(entryDebatersFilter); cEntryFilter.ShowAll(); InitTreeDebaters(); }