Skip to content

Commit

Permalink
Add Changed event handler to the editor + Documentation updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel de Icaza authored and Miguel de Icaza committed May 15, 2010
1 parent c3b8866 commit 8a62aa8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
42 changes: 42 additions & 0 deletions MonoTouch.Dialog/DialogViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class DialogViewController : UITableViewController
bool dirty;
bool reloading;

/// <summary>
/// The root element displayed by the DialogViewController, the value can be changed during runtime to update the contents.
/// </summary>
public RootElement Root {
get {
return root;
Expand All @@ -42,6 +45,10 @@ public RootElement Root {
}

EventHandler refreshRequested;
/// <summary>
/// If you assign a handler to this event before the view is shown, the
/// DialogViewController will have support for pull-to-refresh UI.
/// </summary>
public event EventHandler RefreshRequested {
add {
if (tableView != null)
Expand All @@ -53,6 +60,14 @@ public event EventHandler RefreshRequested {
}
}

/// <summary>
/// Invoke this method to trigger a data refresh.
/// </summary>
/// <remarks>
/// This will invoke the RerfeshRequested event handler, the code attached to it
/// should start the background operation to fetch the data and when it completes
/// it should call ReloadComplete to restore the control state.
/// </remarks>
public void TriggerRefresh ()
{
if (refreshRequested == null)
Expand All @@ -74,6 +89,9 @@ public void TriggerRefresh ()
}
}

/// <summary>
/// Invoke this method to signal that a reload has completed, this will update the UI accordingly.
/// </summary>
public void ReloadComplete ()
{
if (refreshView != null)
Expand All @@ -94,6 +112,9 @@ public void ReloadComplete ()
UIView.CommitAnimations ();
}

/// <summary>
/// Controls whether the DialogViewController should auto rotate
/// </summary>
public bool Autorotate { get; set; }

public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
Expand Down Expand Up @@ -240,6 +261,12 @@ public override float GetHeightForRow (UITableView tableView, MonoTouch.Foundati
}
}

/// <summary>
/// Activates a nested view controller from the DialogViewController.
/// If the view controller is hosted in a UINavigationController it
/// will push the result. Otherwise it will show it as a modal
/// dialog
/// </summary>
public void ActivateController (UIViewController controller)
{
dirty = true;
Expand All @@ -254,6 +281,21 @@ public void ActivateController (UIViewController controller)
PresentModalViewController (controller, true);
}

/// <summary>
/// Dismisses the view controller. It either pops or dismisses
/// based on the kind of container we are hosted in.
/// </summary>
public void DeactivateController (bool animated)
{
var parent = ParentViewController;
var nav = parent as UINavigationController;

if (nav != null)
nav.PopViewControllerAnimated (animated);
else
DismissModalViewControllerAnimated (animated);
}

public override void LoadView ()
{
tableView = new UITableView (UIScreen.MainScreen.Bounds, Style) {
Expand Down
13 changes: 10 additions & 3 deletions MonoTouch.Dialog/Elements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,8 @@ public class EntryElement : Element {
UITextField entry;
string placeholder;
static UIFont font = UIFont.BoldSystemFontOfSize (17);
public Func<bool,string> Validator;

public event EventHandler Changed;

/// <summary>
/// Constructs an EntryElement with the given caption, placeholder and initial value.
Expand Down Expand Up @@ -1006,7 +1006,14 @@ public override UITableViewCell GetCell (UITableView tv)

public void FetchValue ()
{
Value = entry.Text;
var newValue = entry.Text;
var diff = newValue != Value;
Value = newValue;

if (diff){
if (Changed != null)
Changed (this, EventArgs.Empty);
}
}

protected override void Dispose (bool disposing)
Expand Down

0 comments on commit 8a62aa8

Please sign in to comment.