Skip to content

Commit

Permalink
added an application wide accelerator to fire the run button of the c…
Browse files Browse the repository at this point in the history
…urrently visible module. SHORTCUT_DOWN + X will now trigger the task
  • Loading branch information
torakiki committed Jan 21, 2021
1 parent 85d50ac commit 95aae61
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.function.Consumer;

import org.apache.commons.lang3.builder.Builder;
import org.pdfsam.eventstudio.annotation.EventListener;
import org.pdfsam.eventstudio.annotation.EventStation;
import org.pdfsam.i18n.DefaultI18nContext;
import org.pdfsam.module.Module;
import org.pdfsam.module.TaskExecutionRequestEvent;
Expand All @@ -31,8 +33,6 @@
import org.pdfsam.ui.support.Style;
import org.pdfsam.ui.workspace.LoadWorkspaceEvent;
import org.pdfsam.ui.workspace.SaveWorkspaceEvent;
import org.pdfsam.eventstudio.annotation.EventListener;
import org.pdfsam.eventstudio.annotation.EventStation;
import org.sejda.model.parameter.base.AbstractParameters;

import javafx.application.Platform;
Expand Down Expand Up @@ -83,6 +83,11 @@ public final void restoreState(LoadWorkspaceEvent event) {
Platform.runLater(() -> onLoadWorkspace(event.getData(id())));
}

@EventListener
public void onRunButtonAccelerator(RunButtonTriggerRequest request) {
footer.runButton().fire();
}

/**
* @param onError
* function to be called in case of error while building the task parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* This file is part of the PDF Split And Merge source code
* Created on 21 gen 2021
* Copyright 2019 by Sober Lemur S.a.s di Vacondio Andrea ([email protected]).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.pdfsam.ui.module;

/**
* Request to trigger the run button
*
* @author Andrea Vacondio
*
*/
public class RunButtonTriggerRequest {
public static final RunButtonTriggerRequest INSTANCE = new RunButtonTriggerRequest();

private RunButtonTriggerRequest() {
// hide
}
}
3 changes: 3 additions & 0 deletions pdfsam-gui/src/main/java/org/pdfsam/PdfsamApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.pdfsam.ui.log.LogMessageBroadcaster;
import org.pdfsam.ui.log.LoggerConfig;
import org.pdfsam.ui.module.OpenButton;
import org.pdfsam.ui.module.RunButtonTriggerRequest;
import org.pdfsam.ui.notification.NotificationsContainer;
import org.pdfsam.ui.workspace.LoadWorkspaceEvent;
import org.pdfsam.ui.workspace.SaveWorkspaceEvent;
Expand Down Expand Up @@ -221,6 +222,8 @@ private Scene initScene() {
() -> eventStudio().broadcast(ShowStageRequest.INSTANCE, "LogStage"));
mainScene.getAccelerators().put(new KeyCodeCombination(KeyCode.Q, KeyCombination.SHORTCUT_DOWN),
() -> Platform.exit());
mainScene.getAccelerators().put(new KeyCodeCombination(KeyCode.X, KeyCombination.SHORTCUT_DOWN),
() -> eventStudio().broadcast(RunButtonTriggerRequest.INSTANCE));
return mainScene;
}

Expand Down
10 changes: 9 additions & 1 deletion pdfsam-gui/src/main/java/org/pdfsam/ui/workarea/WorkArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@

import javax.inject.Inject;

import org.pdfsam.eventstudio.annotation.EventListener;
import org.pdfsam.module.Module;
import org.pdfsam.ui.commons.SetActiveModuleRequest;
import org.pdfsam.ui.event.SetTitleEvent;
import org.pdfsam.ui.module.RunButtonTriggerRequest;
import org.pdfsam.ui.quickbar.QuickbarPane;
import org.pdfsam.ui.support.Style;
import org.pdfsam.eventstudio.annotation.EventListener;

import javafx.animation.FadeTransition;
import javafx.scene.control.ScrollPane;
Expand Down Expand Up @@ -82,4 +83,11 @@ public void onSetActiveModule(SetActiveModuleRequest request) {
});
eventStudio().broadcast(new SetTitleEvent(current.map(m -> m.descriptor().getName()).orElse("")));
}

@EventListener
public void onRunButtonAccelerator(RunButtonTriggerRequest request) {
if (this.isVisible()) {
current.ifPresent(m -> eventStudio().broadcast(request, m.id()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.pdfsam.eventstudio.StaticStudio.eventStudio;

Expand All @@ -33,6 +34,8 @@
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.pdfsam.eventstudio.Listener;
import org.pdfsam.injector.Injector;
import org.pdfsam.injector.Provides;
import org.pdfsam.module.Module;
Expand All @@ -42,7 +45,7 @@
import org.pdfsam.test.InitializeAndApplyJavaFxThreadRule;
import org.pdfsam.ui.commons.SetActiveModuleRequest;
import org.pdfsam.ui.event.SetTitleEvent;
import org.pdfsam.eventstudio.Listener;
import org.pdfsam.ui.module.RunButtonTriggerRequest;

import javafx.scene.control.ScrollPane;
import javafx.scene.layout.HBox;
Expand Down Expand Up @@ -112,6 +115,30 @@ public void eventTitleIsSent() {
assertNotNull(((ScrollPane) victim.getCenter()).getContent());
}

@Test
public void runRequestIsSent() {
WorkArea victim = injector.instance(WorkArea.class);
assertNull(((ScrollPane) victim.getCenter()).getContent());
victim.onSetActiveModule(SetActiveModuleRequest.activeteModule(DefaultPriorityTestModule.ID));
victim.setVisible(true);
Listener<RunButtonTriggerRequest> listener = mock(Listener.class);
eventStudio().add(RunButtonTriggerRequest.class, listener, DefaultPriorityTestModule.ID);
victim.onRunButtonAccelerator(RunButtonTriggerRequest.INSTANCE);
verify(listener).onEvent(ArgumentMatchers.any());
}

@Test
public void runRequestIsNotSentIfNotVisible() {
WorkArea victim = injector.instance(WorkArea.class);
assertNull(((ScrollPane) victim.getCenter()).getContent());
victim.onSetActiveModule(SetActiveModuleRequest.activeteModule(DefaultPriorityTestModule.ID));
victim.setVisible(false);
Listener<RunButtonTriggerRequest> listener = mock(Listener.class);
eventStudio().add(RunButtonTriggerRequest.class, listener, DefaultPriorityTestModule.ID);
victim.onRunButtonAccelerator(RunButtonTriggerRequest.INSTANCE);
verify(listener, never()).onEvent(ArgumentMatchers.any());
}

@Test
public void emptyEventTitleIsSent() {
WorkArea victim = injector.instance(WorkArea.class);
Expand Down

0 comments on commit 95aae61

Please sign in to comment.