Skip to content

Commit

Permalink
Merge pull request #2574 from eng-myousif/mo_youssef/enable_styling_d…
Browse files Browse the repository at this point in the history
…ocument_control_tabs

Add capability for styling DocumentControl tabs
  • Loading branch information
cwensley authored Nov 17, 2023
2 parents 16f4a08 + 2b57282 commit adfa141
Show file tree
Hide file tree
Showing 4 changed files with 310 additions and 22 deletions.
6 changes: 6 additions & 0 deletions src/Eto.Gtk/Forms/Controls/DocumentControlHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ void SetShowTabs()

internal void ClosePage(Gtk.Widget control, DocumentPage page)
{
var args = new DocumentPageClosingEventArgs(page);
Callback.OnPageClosing(Widget, args);

if (args.Cancel)
return;

Control.RemovePage(Control.PageNum(control));
SetShowTabs();

Expand Down
54 changes: 54 additions & 0 deletions src/Eto/Forms/Controls/DocumentControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ public DocumentPageEventArgs(DocumentPage page)
}
}

/// <summary>
/// Arguments for the <see cref="DocumentControl"/> to get the current page.
/// </summary>
public class DocumentPageClosingEventArgs : CancelEventArgs
{
/// <summary>
/// Gets the document page.
/// </summary>
/// <value>The document page.</value>
public DocumentPage Page { get; private set; }

/// <summary>
/// Initializes a new instance of the <see cref="T:Eto.Forms.DocumentPageClosingEventArgs"/> class.
/// </summary>
/// <param name="page">Page.</param>
public DocumentPageClosingEventArgs(DocumentPage page)
{
Page = page;
}
}

/// <summary>
/// Arguments for the <see cref="DocumentControl"/> when reordering pages.
/// </summary>
Expand Down Expand Up @@ -70,6 +91,7 @@ public class DocumentControl : Container
public override IEnumerable<Control> Controls => pages ?? Enumerable.Empty<Control>();

static readonly object PageClosedEvent = new object();
static readonly object PageClosingEvent = new object();
static readonly object SelectedIndexChangedEvent = new object();

/// <summary>
Expand All @@ -86,6 +108,15 @@ public event EventHandler<DocumentPageEventArgs> PageClosed
remove { Properties.RemoveEvent(PageClosedEvent, value); }
}

/// <summary>
/// Occurs when the <see cref="DocumentPage"/> is closing.
/// </summary>
public event EventHandler<DocumentPageClosingEventArgs> PageClosing
{
add { Properties.AddEvent(PageClosingEvent, value); }
remove { Properties.RemoveEvent(PageClosingEvent, value); }
}

/// <summary>
/// Occurs when the <see cref="SelectedIndex"/> is changed.
/// </summary>
Expand Down Expand Up @@ -116,6 +147,15 @@ protected virtual void OnPageClosed(DocumentPageEventArgs e)
page.TriggerClose(e);
}

/// <summary>
/// Raises the <see cref="PageClosing"/> event.
/// </summary>
/// <param name="e">Event arguments.</param>
protected virtual void OnPageClosing(DocumentPageClosingEventArgs e)
{
Properties.TriggerEvent(PageClosingEvent, this, e);
}

/// <summary>
/// Raises the <see cref="SelectedIndexChanged"/> event.
/// </summary>
Expand Down Expand Up @@ -350,6 +390,11 @@ IEnumerator IEnumerable.GetEnumerator()
/// </summary>
void OnPageClosed(DocumentControl widget, DocumentPageEventArgs e);

/// <summary>
/// Raises the page closing event.
/// </summary>
void OnPageClosing(DocumentControl widget, DocumentPageClosingEventArgs e);

/// <summary>
/// Raises the selected index changed event.
/// </summary>
Expand All @@ -375,6 +420,15 @@ public void OnPageClosed(DocumentControl widget, DocumentPageEventArgs e)
widget.OnPageClosed(e);
}

/// <summary>
/// Raises the page closing event.
/// </summary>
public void OnPageClosing(DocumentControl widget, DocumentPageClosingEventArgs e)
{
using (widget.Platform.Context)
widget.OnPageClosing(e);
}

/// <summary>
/// Raises the page reordered event.
/// </summary>
Expand Down
Loading

0 comments on commit adfa141

Please sign in to comment.