From 30d8edcb20c7d57bba42b1dde454a55b2ddd1f8c Mon Sep 17 00:00:00 2001 From: Vladimir Markelov Date: Wed, 21 Oct 2015 09:38:43 -0700 Subject: [PATCH] closes #8 - modality --- composer.go | 10 ++++++++-- consts.go | 2 ++ interface.go | 2 ++ window.go | 10 ++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/composer.go b/composer.go index 171853e..c46bd9f 100644 --- a/composer.go +++ b/composer.go @@ -157,6 +157,10 @@ func (c *Composer) moveActiveWindowToBottom() bool { return false } + if c.topView().Modal() { + return false + } + event := Event{Type: EventActivate, X: 0} // send deactivated c.sendEventToActiveView(event) @@ -313,8 +317,7 @@ func (c *Composer) processKeySeq(ev term.Event) bool { if c.ctrlKey == term.KeyCtrlW { switch ev.Key { case term.KeyCtrlH: - c.moveActiveWindowToBottom() - return true + return c.moveActiveWindowToBottom() default: return false } @@ -361,6 +364,9 @@ func (c *Composer) processMouseClick(ev term.Event) { } if c.topView() != view { + if c.topView().Modal() { + return + } event := Event{Type: EventActivate, X: 0} // send 'deactivated' c.sendEventToActiveView(event) c.activateView(view) diff --git a/consts.go b/consts.go index 158b51a..95a68c2 100644 --- a/consts.go +++ b/consts.go @@ -208,6 +208,8 @@ const ( EventChanged // Button event - button was clicked EventClicked + // dialog closed + EventDialogClose // Close application EventQuit ) diff --git a/interface.go b/interface.go index c31b298..75a1c88 100644 --- a/interface.go +++ b/interface.go @@ -53,6 +53,8 @@ type View interface { Screen() Screen Parent() Control HitTest(int, int) HitResult + SetModal(bool) + Modal() bool Paddings() (int, int, int, int) SetPaddings(int, int, int, int) diff --git a/window.go b/window.go index 1df75b4..264551c 100644 --- a/window.go +++ b/window.go @@ -14,6 +14,8 @@ type Window struct { pack PackType children []Control controls []Control + // dialog support + modal bool } func NewWindow(parent Screen, x, y, w, h int, title string) *Window { @@ -460,3 +462,11 @@ func (w *Window) HitTest(x, y int) HitResult { return HitInside } + +func (w *Window) SetModal(modal bool) { + w.modal = modal +} + +func (w *Window) Modal() bool { + return w.modal +}