Launch gui with files preloaded

Any questions? Need some help?
Post Reply
chronial
Power User
Posts: 9
Joined: 27 Aug 2014, 01:01

Launch gui with files preloaded

Post by chronial »

Is there a way to create a shortcut that starts the gui for a given folder / list of files?
I want to create an entry in my folder context menu that starts the gui for that folder. Just to be clear, I know how to create context menu entries, I just didn’t find any way to start the gui and scan a given a folder.
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Launch gui with files preloaded

Post by rednoah »

Nope, not supported.
:idea: Please read the FAQ and How to Request Help.
chronial
Power User
Posts: 9
Joined: 27 Aug 2014, 01:01

Re: Launch gui with files preloaded

Post by chronial »

Is there a specific reason for this or has it just not been done yet?
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Launch gui with files preloaded

Post by rednoah »

Just hasn't been done yet.

Mainly because you could just use cmdline scripts instead:
http://www.filebot.net/forums/viewtopic.php?f=3&t=1222
:idea: Please read the FAQ and How to Request Help.
chronial
Power User
Posts: 9
Joined: 27 Aug 2014, 01:01

Re: Launch gui with files preloaded

Post by chronial »

I did find that thread during my search, but from how I understand it those script will just perform the given action without me being able to check whether I like the results, right? That’s the main point why I would like to have a graphical interface here.

But I’ll have a look, maybe I’ll get around to implementing it.
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Launch gui with files preloaded

Post by rednoah »

The artwork.* scripts ask for user input (in strict mode), and building a custom script that requires user confirmation wouldn't be too hard. (e.g. run with --test once, then have the user confirm, and then run with --move again)

More important than just hacking it in, which would be easy, there's various issues:
* No more than 1 FileBot instance should be running at a time, so you can't just pass arguments
* On Windows you'll need to support events so already running applications can get file open events
* Mac OS X applications always run in background anyway, so you have to use events here as well
* Same for Linux with support for at least Unity, Gnome and KDE default filemanagers
:idea: Please read the FAQ and How to Request Help.
chronial
Power User
Posts: 9
Joined: 27 Aug 2014, 01:01

Re: Launch gui with files preloaded

Post by chronial »

There might be a misunderstanding about the point of such a feature. The idea is not to add a new way of how to use the gui, but just to create a more efficient way of starting it for simple tasks.

The feature in question is only useful and sensible if there is not already an instance of FileBot running. If there is and you start another one, I think the expected thing would be for another one to open – that’s also what happens at the moment, isn’t it?
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Launch gui with files preloaded

Post by rednoah »

1.
Mac OS X applications always run in background, even if the GUI is not visible at the time.

2.
On Windows, what do you do if one instance is already running? Ignore the context menu click? Start another? I might be forcing single-instance mode with the new exe launchers, but not sure about that. I think the executables at least allow multi-instance right now. In any case due to caching and other factors it's not recommended to run more than one instance at a time.

3,
Also if the feature is about adding a context menu for FileBot, then obviously there should be context menu support for all available platforms, and the installer should set it up, and and and... I'm not interested in a windows-only hack that would only be used by a very small number of users even within the windows group? If it gets done, it needs to get done universally well.
:idea: Please read the FAQ and How to Request Help.
chronial
Power User
Posts: 9
Joined: 27 Aug 2014, 01:01

Re: Launch gui with files preloaded

Post by chronial »

I just think the gui should do something sensible when it gets a list of files as arguments. On Windows and Linux that is definitely “use those files”. I have no experience at all with macs, though.

Anyways, here is a patch that preloads the rename list with any files that were given on the command line (and recurses into directories). From your previous commends I assume that you are not very interested in it, though :). But that’s fine – I mostly did this because I need it and my Java is also getting a little rusty.

I would nevertheless be grateful for any comments on the code. Especially how you would have handled the passing of the arguments to the RenamePanel. What I did there does feel like a dirty hack.

Code: Select all

Index: source/net/filebot/Main.java
===================================================================
--- source/net/filebot/Main.java	(revision 2523)
+++ source/net/filebot/Main.java	(working copy)
@@ -57,6 +57,7 @@
 import net.filebot.ui.MainFrame;
 import net.filebot.ui.PanelBuilder;
 import net.filebot.ui.SinglePanelFrame;
+import net.filebot.ui.rename.RenamePanel;
 import net.filebot.util.ByteBufferInputStream;
 import net.filebot.util.PreferencesMap.PreferencesEntry;
 import net.filebot.util.TeePrintStream;
@@ -245,6 +246,8 @@
 	private static void startUserInterface(ArgumentBean args) {
 		JFrame frame = null;
 
+		RenamePanel.setFilesFromCli(args.getFiles(false));
+
 		if (args.mode == null) {
 			// default frame
 			frame = new MainFrame();
Index: source/net/filebot/ui/rename/RenamePanel.java
===================================================================
--- source/net/filebot/ui/rename/RenamePanel.java	(revision 2523)
+++ source/net/filebot/ui/rename/RenamePanel.java	(working copy)
@@ -61,6 +61,8 @@
 import net.filebot.ui.rename.FormatDialog.Mode;
 import net.filebot.ui.rename.RenameModel.FormattedFuture;
 import net.filebot.ui.transfer.BackgroundFileTransferablePolicy;
+import net.filebot.ui.transfer.FileTransferable;
+import net.filebot.ui.transfer.TransferablePolicy.TransferAction;
 import net.filebot.util.PreferencesMap.PreferencesEntry;
 import net.filebot.util.ui.ActionPopup;
 import net.filebot.util.ui.LoadingOverlayPane;
@@ -90,6 +92,8 @@
 
 	protected final RenameList<File> filesList = new RenameList<File>(renameModel.files());
 
+	protected static final List<File> filesFromCli = new ArrayList<File>();
+
 	protected final MatchAction matchAction = new MatchAction(renameModel);
 
 	protected final RenameAction renameAction = new RenameAction(renameModel);
@@ -109,8 +113,20 @@
 		namesList.setTransferablePolicy(new NamesListTransferablePolicy(renameModel.values()));
 
 		filesList.setTitle("Original Files");
-		filesList.setTransferablePolicy(new FilesListTransferablePolicy(renameModel.files()));
+		FilesListTransferablePolicy fltp = new FilesListTransferablePolicy(renameModel.files());
+		filesList.setTransferablePolicy(fltp);
 
+		// add files given via CLI
+		try {
+			FileTransferable transferable = new FileTransferable(filesFromCli);
+			if (fltp.accept(transferable)) {
+				fltp.handleTransferable(transferable, TransferAction.ADD);
+			}
+		} catch (Exception e) {
+			UILogger.log(Level.WARNING, e.toString(), e);
+		}
+
+
 		// restore icon indicating current match mode
 		matchAction.setMatchMode(isMatchModeStrict());
 
@@ -360,6 +376,11 @@
 		});
 	}
 
+	public static void setFilesFromCli(List<File> files){
+		filesFromCli.clear();
+		filesFromCli.addAll(files);
+	}
+
 	private boolean isMatchModeStrict() {
 		return MATCH_MODE_STRICT.equalsIgnoreCase(persistentPreferredMatchMode.getValue());
 	}
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Launch gui with files preloaded

Post by rednoah »

Ha! :D Looks like I almost implemented that years ago.

Try this with r2524:

Code: Select all

filebot --mode rename <file>
:idea: Please read the FAQ and How to Request Help.
chronial
Power User
Posts: 9
Joined: 27 Aug 2014, 01:01

Re: Launch gui with files preloaded

Post by chronial »

Ah, there it was :). Surprising that I missed that code. But are you sure about the true parameter for getFiles here?

Code: Select all

frame = new SinglePanelFrame(it).publish(new FileTransferable(args.getFiles(true)));
As recursive (-r) is probably not set, this will just recurse once. But since the FileTransferable will recurse again, the result is a full recursion anyways. But it seems rather confusing to pass true here, as now there is recursion going on in two different places.
chronial
Power User
Posts: 9
Joined: 27 Aug 2014, 01:01

Re: Launch gui with files preloaded

Post by chronial »

OT, but my ocd forced me ;): Applying this patch will center the text at the top of the screen:

Code: Select all

Index: source/net/filebot/ui/HeaderPanel.java
===================================================================
--- source/net/filebot/ui/HeaderPanel.java	(revision 2524)
+++ source/net/filebot/ui/HeaderPanel.java	(working copy)
@@ -37,7 +37,7 @@
 		titleLabel.setForeground(new Color(0x101010));
 		titleLabel.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 24));
 
-		centerPanel.setBorder(new EmptyBorder(0, 78, 0, 0));
+		centerPanel.setBorder(new EmptyBorder(0, 0, 0, 0));
 		centerPanel.add(titleLabel, BorderLayout.CENTER);
 
 		add(centerPanel, BorderLayout.CENTER);
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Launch gui with files preloaded

Post by rednoah »

1.
Doesn't matter in most cases. Depends on wether you want the special handling of disk folders or not. I'll just set it to true then so it's exactly like if you dropped a file/folder. Can't control recursion via cmdline flags anymore now though.

2.
Odd misalignment. Some other change messed that up.
:idea: Please read the FAQ and How to Request Help.
Post Reply