From 0c6821caf3891837cc6ed33d7da8532c4901d15a Mon Sep 17 00:00:00 2001 From: Vladimir Markelov Date: Tue, 23 Jan 2018 13:59:25 -0800 Subject: [PATCH] #72 - introduce public function WindowManager to access internal Composer to call low level function to manipulate Windows --- changelog | 2 ++ composer.go | 6 +++++- dialog.go | 14 +++++++------- window.go | 6 +++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/changelog b/changelog index e5d4543..e1dfaec 100644 --- a/changelog +++ b/changelog @@ -4,6 +4,8 @@ [*] Fix TableView scrollbars: both scrollbars did not response mouse clicks if the last row or column were visible [*] Fix crash after clicking the first TableView column that shows row numbers +[*] Made function to get internal composer public for low level access to + function that manipulates Windows. Function name is WindowManager 2018-01-13 - version 0.6.4 [*] Add a workaround for 'false' key presses fired after clicking mouse on OSX diff --git a/composer.go b/composer.go index 9676f90..cf8f599 100644 --- a/composer.go +++ b/composer.go @@ -35,7 +35,11 @@ func initComposer() { comp.lastKey = term.KeyEsc } -func composer() *Composer { +// WindowManager returns main Window manager (that is Composer). Use it at +// your own risk because it provides an access to some low level Window +// manipulations. +// Note: Now it is not thread safe to call Composer methods from a few threads. +func WindowManager() *Composer { return comp } diff --git a/dialog.go b/dialog.go index badf09d..33701eb 100644 --- a/dialog.go +++ b/dialog.go @@ -70,7 +70,7 @@ func CreateConfirmationDialog(title, question string, buttons []string, defaultB btn1 := CreateButton(frm1, AutoSize, AutoSize, bText, Fixed) btn1.OnClick(func(ev Event) { dlg.result = DialogButton1 - composer().DestroyWindow(dlg.view) + WindowManager().DestroyWindow(dlg.view) if dlg.onClose != nil { go dlg.onClose() } @@ -82,7 +82,7 @@ func CreateConfirmationDialog(title, question string, buttons []string, defaultB btn2 = CreateButton(frm1, AutoSize, AutoSize, buttons[1], Fixed) btn2.OnClick(func(ev Event) { dlg.result = DialogButton2 - composer().DestroyWindow(dlg.view) + WindowManager().DestroyWindow(dlg.view) if dlg.onClose != nil { go dlg.onClose() } @@ -93,7 +93,7 @@ func CreateConfirmationDialog(title, question string, buttons []string, defaultB btn3 = CreateButton(frm1, AutoSize, AutoSize, buttons[2], Fixed) btn3.OnClick(func(ev Event) { dlg.result = DialogButton3 - composer().DestroyWindow(dlg.view) + WindowManager().DestroyWindow(dlg.view) if dlg.onClose != nil { go dlg.onClose() } @@ -114,7 +114,7 @@ func CreateConfirmationDialog(title, question string, buttons []string, defaultB if dlg.result == DialogAlive { dlg.result = DialogClosed if ev.X != 1 { - composer().DestroyWindow(dlg.view) + WindowManager().DestroyWindow(dlg.view) } if dlg.onClose != nil { go dlg.onClose() @@ -201,7 +201,7 @@ func CreateSelectDialog(title string, items []string, selectedItem int, typ Sele } else { dlg.value = dlg.rg.Selected() } - composer().DestroyWindow(dlg.view) + WindowManager().DestroyWindow(dlg.view) if dlg.onClose != nil { go dlg.onClose() } @@ -212,7 +212,7 @@ func CreateSelectDialog(title string, items []string, selectedItem int, typ Sele btn2.OnClick(func(ev Event) { dlg.result = DialogButton2 dlg.value = -1 - composer().DestroyWindow(dlg.view) + WindowManager().DestroyWindow(dlg.view) if dlg.onClose != nil { go dlg.onClose() } @@ -224,7 +224,7 @@ func CreateSelectDialog(title string, items []string, selectedItem int, typ Sele if dlg.result == DialogAlive { dlg.result = DialogClosed if ev.X != 1 { - composer().DestroyWindow(dlg.view) + WindowManager().DestroyWindow(dlg.view) } if dlg.onClose != nil { go dlg.onClose() diff --git a/window.go b/window.go index f1d2051..30f7b34 100644 --- a/window.go +++ b/window.go @@ -302,11 +302,11 @@ func (w *Window) SetVisible(visible bool) { w.hidden = !visible if w.hidden { w.SetModal(false) - if composer().topWindow() == w { - composer().moveActiveWindowToBottom() + if WindowManager().topWindow() == w { + WindowManager().moveActiveWindowToBottom() } } else { - composer().activateWindow(w) + WindowManager().activateWindow(w) } } }