Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
view FrmChangeGameSystem.cs @ 30:5fafbb1b4592
Re #145: Add UI to remove units from army
* Add initial right-click "remove unit" for GTK app
Existing problems:
* Right-click occurs before selection changes, so it can be a click out of synch
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 04 Sep 2009 20:11:02 +0000 |
parents | a191d0655f55 |
children |
line wrap: on
line source
// This file (FrmChangeGameSystem.cs) is a part of the IBBoard.WarFoundry.GTK project and is copyright 2008, 2009 IBBoard. // // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. using System; using IBBoard.WarFoundry.API; using IBBoard.WarFoundry.API.Objects; using Gtk; using log4net; namespace IBBoard.WarFoundry.GTK { public partial class FrmChangeGameSystem : Dialog { private ILog logger = LogManager.GetLogger(typeof(FrmChangeGameSystem)); //private AbstractNativeWarFoundryFactory factory; private GameSystem selectedSystem; public FrmChangeGameSystem(Window parent) : base("Change Game System", parent, DialogFlags.Modal) { this.Build(); lstGameSystems.Selection.Changed+= new EventHandler(OnSelectionChanged); TreeViewColumn gameSystemColumn = new TreeViewColumn (); gameSystemColumn.Title = "Game System"; CellRendererText gameSystemCell = new CellRendererText (); gameSystemColumn.PackStart (gameSystemCell, true); lstGameSystems.AppendColumn(gameSystemColumn); gameSystemColumn.SetCellDataFunc (gameSystemCell, new TreeCellDataFunc (RenderSystemName)); ListStore store = new ListStore(typeof(GameSystem)); foreach (GameSystem system in WarFoundryLoader.GetDefault().GetGameSystems()) { store.AppendValues(system); } lstGameSystems.Model = store; } private void RenderSystemName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) { GameSystem system = (GameSystem) model.GetValue(iter, 0); (cell as CellRendererText).Text = system.Name; } protected virtual void OnGameSystemOkayClicked(object sender, EventArgs e) { logger.Debug("Okay clicked"); SetReturnValue(); Respond(ResponseType.Ok); } private void SetReturnValue() { TreeModel model; TreeIter iter; lstGameSystems.Selection.GetSelected (out model, out iter); selectedSystem = (GameSystem) model.GetValue(iter, 0); } protected virtual void OnSelectionChanged(object o, EventArgs e) { logger.Debug("Selection changed"); buttonOk.Sensitive = (lstGameSystems.Selection.CountSelectedRows() > 0); } protected virtual void OnCancel (object sender, System.EventArgs e) { logger.Debug("Cancel clicked"); Respond(ResponseType.Cancel); } protected virtual void lstGameSystemsRowActivated (object o, Gtk.RowActivatedArgs args) { logger.Debug("List row double-clicked"); SetReturnValue(); Respond(ResponseType.Ok); } public GameSystem SelectedSystem { get { return selectedSystem; } } } }