Skip to content

Commit

Permalink
Added command line option for opening UGS in fullscreen (#2471)
Browse files Browse the repository at this point in the history
  • Loading branch information
breiler authored Feb 29, 2024
1 parent eab6cbf commit 2dc4613
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ugs-platform/ugs-platform-ugscore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
<version>${netbeans.version}</version>
</dependency>

<!-- for being able to enter fullscreen -->
<dependency>
<groupId>org.netbeans.modules</groupId>
<artifactId>org-netbeans-core-windows</artifactId>
<version>${netbeans.version}</version>
<type>jar</type>
</dependency>

<!-- app netbeans dependencies -->
<dependency>
<groupId>org.netbeans.api</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2024 Will Winder
This file is part of Universal Gcode Sender (UGS).
UGS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
UGS 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 General Public License
along with UGS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.willwinder.ugs.nbp.core.lifecycle;

import java.util.logging.Logger;
import javax.swing.Action;
import org.openide.awt.Actions;
import org.openide.windows.OnShowing;

/**
* Makes the application enter full screen if the {@link #setUseFullScreen(boolean)} was set to true
* before the application was started
*
* @author Joacim Breiler
*/
@OnShowing
public class FullScreenOptionProcessor implements Runnable {
private static final Logger LOGGER = Logger.getLogger(StartupOptionProcessor.class.getName());

private static boolean useFullScreen = false;

@Override
public void run() {
if (useFullScreen) {
Action action = Actions.forID("Window", "org.netbeans.core.windows.actions.ToggleFullScreenAction");
if (action == null) {
LOGGER.info("Could not find the ToggleFullScreenAction to enter full screen");
return;
}
action.actionPerformed(null);
}
}

public static void setUseFullScreen(boolean useFullscreen) {
FullScreenOptionProcessor.useFullScreen = useFullscreen;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
Copyright 2024 Will Winder
This file is part of Universal Gcode Sender (UGS).
UGS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
UGS 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 General Public License
along with UGS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.willwinder.ugs.nbp.core.lifecycle;

import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -30,6 +48,7 @@ public class StartupOptionProcessor extends OptionProcessor {
private final Option openOption = Option.additionalArguments('o', "open");
private final Option defaultOpenOption = Option.defaultArguments();
private final Option clearCacheOption = Option.withoutArgument('c', "clearcache");
private final Option fullscreenOption = Option.withoutArgument(Option.NO_SHORT_NAME, "fullscreen");

/**
* Register interest in the "open" option.
Expand All @@ -40,6 +59,7 @@ public Set<Option> getOptions() {
set.add(openOption);
set.add(defaultOpenOption);
set.add(clearCacheOption);
set.add(fullscreenOption);
return set;
}

Expand All @@ -52,8 +72,12 @@ protected void process(Env env, Map<Option, String[]> optionsMap) throws Command
clearCache();
}

if (optionsMap.containsKey(fullscreenOption)) {
FullScreenOptionProcessor.setUseFullScreen(true);
}

Optional<String> fileToOpen = getFileToOpen(optionsMap, openOption);
if (!fileToOpen.isPresent()) {
if (fileToOpen.isEmpty()) {
fileToOpen = getFileToOpen(optionsMap, defaultOpenOption);
}

Expand Down

0 comments on commit 2dc4613

Please sign in to comment.