Moved up/down/pageup/pagedown/home/end key handling into

ScrollableWindow and out of the main loop.
This commit is contained in:
casey 2016-05-16 22:55:55 -07:00
parent 04a4c33ae0
commit 072aa94bc5
6 changed files with 37 additions and 50 deletions

View File

@ -187,56 +187,26 @@ int main(int argc, char* argv[])
else {
ch = getch();
}
if (ch == -1) {
/* idle timeout */
}
else if (ch == 9) { /* tab */
focusNextInLayout(state);
}
else if (ch >= KEY_F(0) && ch <= KEY_F(12)) {
if (ch == KEY_F(1)) {
changeLayout(state, &mainLayout);
if (ch != -1) { /* -1 = idle timeout */
if (ch == '\t') { /* tab */
focusNextInLayout(state);
}
else if (ch == KEY_F(2)) {
changeLayout(state, &libraryLayout);
else if (ch >= KEY_F(0) && ch <= KEY_F(12)) {
if (ch == KEY_F(1)) {
changeLayout(state, &mainLayout);
}
else if (ch == KEY_F(2)) {
changeLayout(state, &libraryLayout);
}
}
}
else if (ch == KEY_NPAGE) {
if (state.scrollable) {
state.scrollable->PageDown();
else if (state.input) {
state.input->WriteChar(ch);
}
}
else if (ch == KEY_PPAGE) {
if (state.scrollable) {
state.scrollable->PageUp();
else if (state.keyHandler) {
state.keyHandler->KeyPress(ch);
}
}
else if (ch == KEY_DOWN) {
if (state.scrollable) {
state.scrollable->ScrollDown();
}
}
else if (ch == KEY_UP) {
if (state.scrollable) {
state.scrollable->ScrollUp();
}
}
else if (ch == KEY_HOME) {
if (state.scrollable) {
state.scrollable->ScrollToTop();
}
}
else if (ch == KEY_END) {
if (state.scrollable) {
state.scrollable->ScrollToBottom();
}
}
else if (state.input) {
state.input->WriteChar(ch);
}
else if (state.keyHandler) {
state.keyHandler->KeyPress(ch);
}
Window::WriteToScreen();
WindowMessageQueue::Instance().Dispatch();

View File

@ -74,14 +74,14 @@ void CommandWindow::WriteChar(int64 ch) {
waddch(this->GetContent(), ch);
if (ch == 8) { /* backspace */
if (ch == '\b') { /* backspace */
wdelch(this->GetContent());
if (bufferPosition > 0) {
--bufferPosition;
}
}
else if (ch == 10) { /* return */
else if (ch == '\n') { /* return */
this->buffer[bufferPosition] = 0;
std::string cmd(buffer);

View File

@ -46,7 +46,7 @@ void TrackListView::OnQueryCompleted(QueryPtr query) {
}
void TrackListView::KeyPress(int64 ch) {
if (ch == 10) { /* return */
if (ch == '\n') { /* return */
size_t selected = this->GetSelectedIndex();
if (this->metadata->size() > selected) {
TrackPtr track = this->metadata->at(selected);
@ -55,6 +55,9 @@ void TrackListView::KeyPress(int64 ch) {
this->transport->Start(fn);
}
}
else {
ListWindow::KeyPress(ch);
}
}
void TrackListView::ProcessMessage(IWindowMessage &message) {

View File

@ -15,7 +15,7 @@ using musik::core::QueryPtr;
using musik::core::LibraryPtr;
using musik::core::audio::Transport;
class TrackListView : public ListWindow, public IKeyHandler, public sigslot::has_slots<> {
class TrackListView : public ListWindow, public sigslot::has_slots<> {
public:
TrackListView(Transport& transport, LibraryPtr library, IWindow *parent = NULL);
~TrackListView();

View File

@ -25,6 +25,17 @@ ScrollPos& ScrollableWindow::GetScrollPosition() {
return this->scrollPosition;
}
void ScrollableWindow::KeyPress(int64 ch) {
switch (ch) {
case KEY_NPAGE: this->PageDown(); break;
case KEY_PPAGE: this->PageUp(); break;
case KEY_DOWN: this->ScrollDown(); break;
case KEY_UP: this->ScrollUp(); break;
case KEY_HOME: this->ScrollToTop(); break;
case KEY_END: this->ScrollToBottom(); break;
}
}
void ScrollableWindow::OnAdapterChanged() {
IScrollAdapter *adapter = &GetScrollAdapter();

View File

@ -4,8 +4,9 @@
#include "Window.h"
#include "IScrollAdapter.h"
#include "IScrollable.h"
#include "IKeyHandler.h"
class ScrollableWindow : public IScrollable, public Window {
class ScrollableWindow : public IScrollable, public IKeyHandler, public Window {
public:
ScrollableWindow(IWindow *parent = NULL);
virtual ~ScrollableWindow();
@ -13,6 +14,8 @@ class ScrollableWindow : public IScrollable, public Window {
virtual void Show();
virtual void SetSize(int width, int height);
virtual void KeyPress(int64 ch);
virtual void ScrollToTop();
virtual void ScrollToBottom();
virtual void ScrollUp(int delta = 1);