From: Niki Roo Date: Sun, 24 Mar 2019 18:16:33 +0000 (+0100) Subject: gui: do not always refresh the books after an action X-Git-Tag: fanfix-2.0.1~3 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=2d56db730853fae42f5099cbca8cbed66129551c;p=fanfix.git gui: do not always refresh the books after an action --- diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java index 045bb46..9754102 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java @@ -410,7 +410,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { .getAbsolutePath() + type.getDefaultExtension(false); final Progress pg = new Progress(); - mainPanel.outOfUi(pg, new Runnable() { + mainPanel.outOfUi(pg, false, new Runnable() { @Override public void run() { try { @@ -465,7 +465,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { public void actionPerformed(ActionEvent e) { final GuiReaderBook selectedBook = mainPanel.getSelectedBook(); if (selectedBook != null) { - mainPanel.outOfUi(null, new Runnable() { + mainPanel.outOfUi(null, false, new Runnable() { @Override public void run() { reader.clearLocalReaderCache(selectedBook.getInfo() @@ -636,7 +636,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { } final String fChangeTo = changeTo; - mainPanel.outOfUi(null, new Runnable() { + mainPanel.outOfUi(null, true, new Runnable() { @Override public void run() { String luid = selectedBook.getInfo().getMeta() @@ -708,7 +708,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { public void actionPerformed(ActionEvent e) { final GuiReaderBook selectedBook = mainPanel.getSelectedBook(); if (selectedBook != null) { - mainPanel.outOfUi(null, new Runnable() { + mainPanel.outOfUi(null, true, new Runnable() { @Override public void run() { reader.delete(selectedBook.getInfo().getMeta() @@ -735,7 +735,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper { public void actionPerformed(ActionEvent e) { final GuiReaderBook selectedBook = mainPanel.getSelectedBook(); if (selectedBook != null) { - mainPanel.outOfUi(null, new Runnable() { + mainPanel.outOfUi(null, false, new Runnable() { @Override public void run() { new GuiReaderPropertiesFrame(reader.getLibrary(), diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java index 9a63f76..359ac92 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderMainPanel.java @@ -80,14 +80,12 @@ class GuiReaderMainPanel extends JPanel { /** * Create the main menu bar. *

- * Wil invalidate the layout. + * Will invalidate the layout. * * @param libOk * the library can be queried - * - * @return the bar */ - public void createMenu(boolean b); + public void createMenu(boolean libOk); /** * Create a popup menu for a {@link GuiReaderBook} that represents a @@ -124,9 +122,9 @@ class GuiReaderMainPanel extends JPanel { /** * Create a new {@link GuiReaderMainPanel}. * - * @param reader - * the associated {@link GuiReader} to forward some commands and - * access its {@link LocalLibrary} + * @param parent + * the associated {@link FrameHelper} to forward some commands + * and access its {@link LocalLibrary} * @param type * the type of {@link Story} to load, or NULL for all types */ @@ -183,7 +181,7 @@ class GuiReaderMainPanel extends JPanel { pane.setVisible(false); final Progress pg = new Progress(); final String typeF = type; - outOfUi(pg, new Runnable() { + outOfUi(pg, true, new Runnable() { @Override public void run() { final BasicLibrary lib = helper.getReader().getLibrary(); @@ -204,7 +202,6 @@ class GuiReaderMainPanel extends JPanel { addBookPane(typeF, true); } pane.setVisible(true); - refreshBooks(); } else { helper.createMenu(false); validate(); @@ -375,7 +372,7 @@ class GuiReaderMainPanel extends JPanel { */ public void openBook(final GuiReaderBook book) { final Progress pg = new Progress(); - outOfUi(pg, new Runnable() { + outOfUi(pg, false, new Runnable() { @Override public void run() { try { @@ -404,18 +401,26 @@ class GuiReaderMainPanel extends JPanel { * * @param progress * the {@link ProgressBar} or NULL + * @param refreshBooks + * TRUE to refresh the books after * @param run * the action to run */ - public void outOfUi(Progress progress, final Runnable run) { + public void outOfUi(Progress progress, final boolean refreshBooks, + final Runnable run) { final Progress pg = new Progress(); final Progress reload = new Progress("Reload books"); + if (progress == null) { progress = new Progress(); } - pg.addProgress(progress, 90); - pg.addProgress(reload, 10); + if (refreshBooks) { + pg.addProgress(progress, 100); + } else { + pg.addProgress(progress, 90); + pg.addProgress(reload, 10); + } invalidate(); pgBar.setProgress(pg); @@ -427,7 +432,9 @@ class GuiReaderMainPanel extends JPanel { public void run() { try { run.run(); - refreshBooks(); + if (refreshBooks) { + refreshBooks(); + } } finally { reload.done(); if (!pg.isDone()) { @@ -513,6 +520,8 @@ class GuiReaderMainPanel extends JPanel { * the {@link Story} to import by {@link URL} * @param onSuccess * Action to execute on success + * @param onSuccessPgName + * the name to use for the onSuccess progress bar */ public void imprt(final String url, final StoryRunnable onSuccess, String onSuccessPgName) { @@ -522,7 +531,7 @@ class GuiReaderMainPanel extends JPanel { pg.addProgress(pgImprt, 95); pg.addProgress(pgOnSuccess, 5); - outOfUi(pg, new Runnable() { + outOfUi(pg, true, new Runnable() { @Override public void run() { Exception ex = null;