From bce88a008c85e24da6c0398eedd41f9e492b8d39 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Thu, 7 Mar 2019 18:41:17 +0100 Subject: [PATCH] wip --- .../reader/tui/TuiReaderApplication.java | 10 +++ .../reader/tui/TuiReaderMainWindow.java | 82 +++++++++++-------- 2 files changed, 60 insertions(+), 32 deletions(-) diff --git a/src/be/nikiroo/fanfix/reader/tui/TuiReaderApplication.java b/src/be/nikiroo/fanfix/reader/tui/TuiReaderApplication.java index b85bb86..c08b6c2 100644 --- a/src/be/nikiroo/fanfix/reader/tui/TuiReaderApplication.java +++ b/src/be/nikiroo/fanfix/reader/tui/TuiReaderApplication.java @@ -13,6 +13,7 @@ import jexer.TMessageBox; import jexer.TStatusBar; import jexer.TWidget; import jexer.TWindow; +import jexer.event.TCommandEvent; import jexer.event.TMenuEvent; import jexer.menu.TMenu; import be.nikiroo.fanfix.Instance; @@ -210,6 +211,15 @@ class TuiReaderApplication extends TApplication implements Reader { getBackend().setTitle("Fanfix"); } + @Override + protected boolean onCommand(TCommandEvent command) { + if (command.getCmd().equals(TuiReaderMainWindow.CMD_SEARCH)) { + messageBox("title", "caption"); + return true; + } + return super.onCommand(command); + } + @Override protected boolean onMenu(TMenuEvent menu) { // TODO: i18n diff --git a/src/be/nikiroo/fanfix/reader/tui/TuiReaderMainWindow.java b/src/be/nikiroo/fanfix/reader/tui/TuiReaderMainWindow.java index b54d2cb..f2167a6 100644 --- a/src/be/nikiroo/fanfix/reader/tui/TuiReaderMainWindow.java +++ b/src/be/nikiroo/fanfix/reader/tui/TuiReaderMainWindow.java @@ -6,10 +6,15 @@ import java.util.Arrays; import java.util.List; import jexer.TAction; +import jexer.TCommand; +import jexer.TField; import jexer.TFileOpenBox.Type; +import jexer.TKeypress; import jexer.TList; +import jexer.TStatusBar; import jexer.TWindow; import jexer.event.TCommandEvent; +import jexer.event.TKeypressEvent; import jexer.event.TMenuEvent; import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.data.MetaData; @@ -24,11 +29,16 @@ import be.nikiroo.fanfix.reader.Reader; * @author niki */ class TuiReaderMainWindow extends TWindow { + public static final int MENU_SEARCH = 1100; + public static final TCommand CMD_SEARCH = new TCommand(MENU_SEARCH) { + }; + private TList list; private List listKeys; private List listItems; private Reader reader; private String source; + private String filter = ""; /** * Create a new {@link TuiReaderMainWindow} without any stories in the list. @@ -48,21 +58,31 @@ class TuiReaderMainWindow extends TWindow { // TODO size + onResize - - addLabel("Search: ", 5, 3); - addField(15, 3, 5, true); - + @SuppressWarnings("unused") + TField field = new TField(this, 15, 3, 5, true) { + @Override + public void onKeypress(TKeypressEvent keypress) { + super.onKeypress(keypress); + TKeypress key = keypress.getKey(); + if (key.isFnKey() && key.getKeyCode() == TKeypress.ENTER) { + TuiReaderMainWindow.this.filter = getText(); + TuiReaderMainWindow.this.refreshStories(); + } + } + }; + addLabel("Sort by: ", 5, 1); // -1 = no default index (0 means first,...) 1=height when visible, null // = action - List data = Arrays.asList("(show all)", "Source", "Name", "Author"); + List data = Arrays.asList("(show all)", "Source", "Name", + "Author"); // must be last so to be able to draw over the rest // TODO: make it so we cannot add manual entries - // TODO: how to select the item via keyboard? why double-click via mouse? - addComboBox(15, 1, 12, - data, 0, Math.min(data.size()+1,getHeight()-1-1), - null); + // TODO: how to select the item via keyboard? why double-click via + // mouse? + addComboBox(15, 1, 12, data, 0, + Math.min(data.size() + 1, getHeight() - 1 - 1), null); list = addList(listItems, 0, 7, getWidth(), getHeight(), new TAction() { @Override @@ -74,8 +94,8 @@ class TuiReaderMainWindow extends TWindow { } }); - // TODO: add the current "source/type" or filter - reader.setStatusBar(this, "Library"); + TStatusBar statusBar = reader.setStatusBar(this, "Library"); + statusBar.addShortcutKeypress(TKeypress.kbCtrlF, CMD_SEARCH, "Search"); // TODO: remove when not used anymore @@ -109,38 +129,31 @@ class TuiReaderMainWindow extends TWindow { } /** - * Change the source filter and display all stories matching this source. - * - * @param source - * the new source or NULL for all sources + * Refresh the list of stories displayed in this library. + *

+ * Will take the current settings into account (filter, source...). */ - public void setSource(String source) { - this.source = source; - refreshStories(); - } - public void refreshStories() { List metas = reader.getLibrary().getListBySource(source); setMetas(metas); } /** - * Update the list of stories displayed in this {@link TWindow}. + * Change the source filter and display all stories matching this source. * - * @param meta - * the new (unique) story to display + * @param source + * the new source or NULL for all sources */ - public void setMeta(MetaData meta) { - List metas = new ArrayList(); - if (meta != null) { - metas.add(meta); - } - - setMetas(metas); + public void setSource(String source) { + this.source = source; + refreshStories(); } /** * Update the list of stories displayed in this {@link TWindow}. + *

+ * If a filter is set, only the stories which pass the filter will be + * displayed. * * @param metas * the new list of stories to display @@ -151,8 +164,12 @@ class TuiReaderMainWindow extends TWindow { if (metas != null) { for (MetaData meta : metas) { - listKeys.add(meta); - listItems.add(desc(meta)); + String desc = desc(meta); + if (filter.isEmpty() + || desc.toLowerCase().contains(filter.toLowerCase())) { + listKeys.add(meta); + listItems.add(desc); + } } } @@ -214,6 +231,7 @@ class TuiReaderMainWindow extends TWindow { } return; + case -1: try { reader.getLibrary().delete(meta.getLuid()); -- 2.27.0