Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Open file from command line
Open file from command line [message #973716] Tue, 06 November 2012 15:11 Go to next message
Markus Wiederkehr is currently offline Markus WiederkehrFriend
Messages: 17
Registered: August 2012
Junior Member
I'd like to associate my E4 application with a certain file extension and open the specified file if a file name is given in the command line parameters.

Problem is I cannot find a good place to hook into for checking the command line arguments.

Has anyone ever done this with E4? Can someone give me a hint, please?
Re: Open file from command line [message #973723 is a reply to message #973716] Tue, 06 November 2012 15:18 Go to previous messageGo to next message
Eclipse UserFriend
Markus Wiederkehr wrote on Tue, 06 November 2012 16:11

Problem is I cannot find a good place to hook into for checking the command line arguments.


Tha't pretty easy. If you want to do it in a lifecycle handler or pretty much from anywhere you can inject the IApplicationContext (it is in the MApplication's context so anything below it can access it too)and get the args you want.

@Inject 
IApplicationContext applicationContext;


and
args = (String[]) applicationContext.getArguments().get(
				IApplicationContext.APPLICATION_ARGS);


Re: Open file from command line [message #973728 is a reply to message #973716] Tue, 06 November 2012 15:20 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Isn't there an event generated by the launcher when it detects this?

You can access the command line parameters through the IApplicatContext
which is pushed to the IEclipseContext of your application, so you have
access to it e.g. in addons.

Tom

Am 06.11.12 16:11, schrieb Markus Wiederkehr:
> I'd like to associate my E4 application with a certain file extension
> and open the specified file if a file name is given in the command line
> parameters.
>
> Problem is I cannot find a good place to hook into for checking the
> command line arguments.
>
> Has anyone ever done this with E4? Can someone give me a hint, please?
Re: Open file from command line [message #973734 is a reply to message #973728] Tue, 06 November 2012 15:22 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Am 06.11.12 16:20, schrieb Tom Schindl:
> Isn't there an event generated by the launcher when it detects this?

Just to make sure: This is needed only if your application is already
running and someone clicks on a file because then you certainly don't
want to open the file in the running application, instead of launching a
new one.

Tom
Re: Open file from command line [message #973736 is a reply to message #973723] Tue, 06 November 2012 15:29 Go to previous messageGo to next message
Markus Wiederkehr is currently offline Markus WiederkehrFriend
Messages: 17
Registered: August 2012
Junior Member
Sorry, I was unclear. Accessing the command line parameters is not the problems (and it also seems to be working with Platform.getCommandLineArgs()).

The problem is that I cannot find a place (or rather a point in the lifecycle) to hook into to actually open the file. I mean all the available lifecycle callbacks (@PostContextCreate, @ProcessAdditions) happen far too early for me to open the files. I need something that happens later, when everything is up and running. Right about the time the @CanExecute methods are invoked for the first time.
Re: Open file from command line [message #973753 is a reply to message #973736] Tue, 06 November 2012 15:41 Go to previous messageGo to next message
Phill Perryman is currently offline Phill PerrymanFriend
Messages: 214
Registered: July 2009
Senior Member
I also have a need to do this in an rcp app, I used to do it in the ApplicationWorkbenchAdvisor.postStartup() method in 3.x. Does 4 have an equivalent point in the lifecycle?
Re: Open file from command line [message #973758 is a reply to message #973736] Tue, 06 November 2012 15:45 Go to previous messageGo to next message
Markus Wiederkehr is currently offline Markus WiederkehrFriend
Messages: 17
Registered: August 2012
Junior Member
@Thomas, I'd like to open a file in a running application instead of launching a new instance if that is possible. If not I can also live with the error message about the workspace being already in use for now.

But first I have to deal with the simpler case where the application is not running and the user double-clicks a file. Is there a callback I can use?
Re: Open file from command line [message #973906 is a reply to message #973736] Tue, 06 November 2012 18:10 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
If you want to go with a command I think you should wait until the
window is renderered but at start up you could simply modify the model
directly, creating an MPart instance and adding it to the MPartStack.

Tom

Am 06.11.12 16:29, schrieb Markus Wiederkehr:
> Sorry, I was unclear. Accessing the command line parameters is not the
> problems (and it also seems to be working with
> Platform.getCommandLineArgs()).
>
> The problem is that I cannot find a place (or rather a point in the
> lifecycle) to hook into to actually open the file. I mean all the
> available lifecycle callbacks (@PostContextCreate, @ProcessAdditions)
> happen far too early for me to open the files. I need something that
> happens later, when everything is up and running. Right about the time
> the @CanExecute methods are invoked for the first time.
Previous Topic:Update site from archive over http
Next Topic:friends of e4.ui...?
Goto Forum:
  


Current Time: Fri Apr 19 10:40:25 GMT 2024

Powered by FUDForum. Page generated in 0.02085 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top