Opening A File Into An Editor By Double-Clicking It

Let's create a simple text editor and set up a file on disk to be double-clicked for opening into the simple text editor. So, a file will be on disk, I will double-click the file, the simple text editor will start up, and automatically my text file will be open in the simple text editor. I can then immediately start working with the file in the editor.

No coding will be required for all this functionality.

  1. Create the Application. Start NetBeans IDE, go to the New Project dialog (Ctrl-Shift-N), and choose "NetBeans Modules | NetBeans Platform Application". Click Next. Name the application "SimpleTextEditor" and click Finish.

  2. Add "Open File" Support to the Application. The NetBeans Platform includes an implementation of a command line parser that will enable you to bind a file to the application's executable. Using your operating system's tools, you'll use, e.g., "Open With" on Ubuntu, to make your executable the executable used to open the file of your choice. Then the NetBeans "OpenFile" command will take the file name you have provided and open the file into the application. This "OpenFile" command line parser is found in the "User Utilities" module in the "ide" cluster.

    To include this module in your application, right-click the "SimpleTextEditor" project node in the Projects window, choose "Properties", then select "Libraries" on the left in the Project Properties window, expand "ide", and go down the list of checkboxes until you see "User Utilities", which includes the "OpenFile" command line parser. Check that checkbox and then click the red "Resolve" button at the bottom of the dialog. Other modules will now automatically be selected and included in your application. These other modules provide a plain editor, otherwise you wouldn't be able to open a file into an editor, i.e., if you didn't have an editor in the first place.

  3. Create an Executable. Our simple text editor with "OpenFile" support is finished. Right-click the "SimpleTextEditor" project node in the Projects window and choose "Package as | ZIP Distribution". In the Files window, browse into the ZIP file that's been created in the "dist" folder and notice that "org-netbeans-modules-utilities.jar" includes a package named "openfile", as you can see below:



    Unzip the ZIP file and you have your full application available, including an executable in the "bin" folder.

  4. Bind a File to the Executable. How a file is bound to an executable depends on the operating system. On Ubuntu, I right-click a file, choose "Open With | Other Application", choose "Use a custom command" at the bottom of the dialog, and then browse to the executable. Then the file automatically opens in the editor, after the editor starts up. Subsequently, any double-click on the bound file will result in the executable starting up and the file opening within it.

I really don't think it could be any simpler than this.

Comments:

I have faced this Warning: Could not find file C:\Program Files\NetBeans 7.0\harness\launchers\app_w.exe to copy in Netbeans7.0.
But i have pre7_app_w.exe this file what will I do plz suggest me

Posted by guest on October 18, 2011 at 02:18 AM PDT #

When/how do you get that warning? Which step in the instructions above? What are you talking about?

Posted by Geertjan on October 18, 2011 at 02:52 AM PDT #

Geertjan, I also see the "Could not find file C:\Program Files\NetBeans 7.0.1\harness\launchers\app_w.exe to copy" warning

This occurs when running the build-launchers target.

It seems as if the binaries have been combined in later versions, but the build scripts not updated properly. The launcher seems to be working fine without app_w.exe.

Posted by guest on November 01, 2011 at 02:04 AM PDT #

Does the question have anything at all to do with this blog entry? I doubt it. Write to the mailing list instead, please.

Posted by Geertjan on November 01, 2011 at 02:35 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« July 2014
SunMonTueWedThuFriSat
  
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today