| View previous topic :: View next topic |
| Author |
Message |
kinka-dzs
Joined: 01 Jul 2010 Posts: 13
|
Posted: Thu May 31, 2012 3:01 pm Post subject: plugin and netbeans api get active file |
|
|
Hello everybody.... I am developing a plugin but i want to retrieve the file that is currently opened in the editor. I have been looking in the documentation on netbeans API but still have not found it. Anybody has any hints?
Thank you. |
|
| Back to top |
|
 |
Geertjan Wielenga Posted via mailing list.
|
Posted: Fri Jun 01, 2012 6:09 am Post subject: Re: plugin and netbeans api get active file |
|
|
On 05/31/2012 05:01 PM, kinka-dzs wrote:
| Quote: | Hello everybody.... I am developing a plugin but i want to retrieve the file
|
From where? From a node? From the editor itself? From an action in the
menu bar or toolbar?
In other words, please describe the workflow.
Gj
| Quote: | that is currently opened in the editor. I have been looking in the documentation on netbeans API but still have not found it. Anybody has any hints?
Thank you.
|
|
|
| Back to top |
|
 |
kinka-dzs
Joined: 01 Jul 2010 Posts: 13
|
Posted: Fri Jun 01, 2012 12:16 pm Post subject: |
|
|
Something like this, wandering if there is a better way to do it. At the moment i am getting the path from the tooltip:
| Code: | TopComponent topActive = TopComponent.getRegistry().getActivated();
if(WindowManager.getDefault().isOpenedEditorTopComponent(topActive)){
String path=topActive.getToolTipText();
return new File(path);
} | [/code] |
|
| Back to top |
|
 |
Geertjan Wielenga Posted via mailing list.
|
Posted: Fri Jun 01, 2012 8:44 pm Post subject: Re: plugin and netbeans api get active file |
|
|
On 06/01/2012 02:16 PM, kinka-dzs wrote:
| Quote: | Something like this, wandering if there is a better way to do it. At the moment i am getting the path from the tooltip:
Code:
TopComponent topActive = TopComponent.getRegistry().getActivated();
if(WindowManager.getDefault().isOpenedEditorTopComponent(topActive)){
String path=topActive.getToolTipText();
return new File(path);
}
[/code]
| From where? From a node? From the editor itself? From an action in the
menu bar or toolbar?
In other words, please describe the workflow.
Gj |
|
| Back to top |
|
 |
kinka-dzs
Joined: 01 Jul 2010 Posts: 13
|
Posted: Tue Jun 05, 2012 2:27 pm Post subject: |
|
|
What do you want to know more than this? " i want to retrieve the file that is currently opened in the editor."
in other words,
When the editor is the active top component I want to find the path of the file associated to it.
Which way it the best one to do it you should tell me, that was exactly my question. At the moment i am getting it from the tooltip of the topcontainer. Should i get it from a node? how? from the jeditorpane? how? ...
Thanks. |
|
| Back to top |
|
 |
Geertjan Wielenga Posted via mailing list.
|
Posted: Tue Jun 05, 2012 10:03 pm Post subject: Re: plugin and netbeans api get active file |
|
|
On 06/05/2012 04:27 PM, kinka-dzs wrote:
| Quote: | What do you want to know more than this? " i want to retrieve the file that is currently opened in the editor."
in other words,
When the editor is the active top component I want to find the path of the file associated to it.
Which way it the best one to do it you should tell me, that was exactly my question. At the moment i am getting it from the tooltip of the topcontainer. Should i get it from a node? how? from the jeditorpane? how? ...
|
It depends. Will the user by clicking a menu item in the menu bar? A
toolbar button in the toolbar? Will they be right-clicking inside the
editor?
What will the user be doing at the time when you need the file to be
retrieved?
Gj
|
|
| Back to top |
|
 |
Geertjan Wielenga Posted via mailing list.
|
Posted: Tue Jun 05, 2012 10:14 pm Post subject: Re: plugin and netbeans api get active file |
|
|
On 06/06/2012 12:02 AM, Geertjan Wielenga wrote:
| Quote: | On 06/05/2012 04:27 PM, kinka-dzs wrote:
| Quote: | What do you want to know more than this? " i want to retrieve the
file that is currently opened in the editor."
in other words,
When the editor is the active top component I want to find the path
of the file associated to it.
Which way it the best one to do it you should tell me, that was
exactly my question. At the moment i am getting it from the tooltip
of the topcontainer. Should i get it from a node? how? from the
jeditorpane? how? ...
|
It depends. Will the user by clicking a menu item in the menu bar? A
toolbar button in the toolbar? Will they be right-clicking inside the
editor?
What will the user be doing at the time when you need the file to be
retrieved?
Gj
| PS: And what kind of file is it? Any kind of file? A Java file? An HTML
file?
Also, what is the plugin you're trying to create going to be doing? What
is the functionality that you're trying to create? You can continue to
find these questions irrelevant to your question but if you don't want
to give a context for what you're trying to do, you're not going to get
any help. Not from me, anyway, I'm not able to help you without any
context. |
|
| Back to top |
|
 |
Geertjan Wielenga Posted via mailing list.
|
Posted: Tue Jun 05, 2012 10:23 pm Post subject: Re: plugin and netbeans api get active file |
|
|
But I'll help anyway. Below is an action that can be invoked from the
Tools menu in the main menu bar. It can also be invoked by
right-clicking inside any editor inside NetBeans IDE. Create a module,
set dependencies on Datasystems API, File System API, Lookup API, Nodes
API, UI Utilities API, and Utilities API. Then create a new Java class
and copy the code below into it.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.loaders.DataObject;
import org.openide.util.NbBundle.Messages;
@ActionID(
category = "Tools",
id = "org.show.current.ShowCurrentFileAction")
@ActionRegistration(
displayName = "#CTL_ShowCurrentFileAction")
@ActionReferences({
@ActionReference(path = "Menu/Tools", position = 0),
@ActionReference(path = "Editors/Popup", position = 10)
})
@Messages("CTL_ShowCurrentFileAction=Show Path to Current File")
public final class ShowCurrentFileAction implements ActionListener {
private final DataObject context;
public ShowCurrentFileAction(DataObject context) {
this.context = context;
}
@Override
public void actionPerformed(ActionEvent e) {
String path = context.getPrimaryFile().getPath();
JOptionPane.showMessageDialog(null, path);
}
}
Hope it helps you,
Gj
On 06/06/2012 12:14 AM, Geertjan Wielenga wrote:
| Quote: | On 06/06/2012 12:02 AM, Geertjan Wielenga wrote:
| Quote: | On 06/05/2012 04:27 PM, kinka-dzs wrote:
| Quote: | What do you want to know more than this? " i want to retrieve the
file that is currently opened in the editor."
in other words,
When the editor is the active top component I want to find the path
of the file associated to it.
Which way it the best one to do it you should tell me, that was
exactly my question. At the moment i am getting it from the tooltip
of the topcontainer. Should i get it from a node? how? from the
jeditorpane? how? ...
|
It depends. Will the user by clicking a menu item in the menu bar? A
toolbar button in the toolbar? Will they be right-clicking inside the
editor?
What will the user be doing at the time when you need the file to be
retrieved?
Gj
| PS: And what kind of file is it? Any kind of file? A Java file? An
HTML file?
Also, what is the plugin you're trying to create going to be doing?
What is the functionality that you're trying to create? You can
continue to find these questions irrelevant to your question but if
you don't want to give a context for what you're trying to do, you're
not going to get any help. Not from me, anyway, I'm not able to help
you without any context. |
|
|
| Back to top |
|
 |
kinka-dzs
Joined: 01 Jul 2010 Posts: 13
|
Posted: Wed Jun 06, 2012 11:18 pm Post subject: Thank you |
|
|
Thank you Geertjan, i was doing pretty much the same thing, also i was using JOptionPane to debug, so i think i am in the right way considering it is my first plugin..
I didn't know about the
| Code: | | String path = context.getPrimaryFile().getPath(); |
i was doing it in a very different way.... so thank you very much. You can see anyway how i was implementing it (still have to change it with your suggestion) on github. if you go to the downloads i uploaded the nbm for 7.1 , and you can understand what was the context!!! javascript:emoticon(' ')
The link is:
https://github.com/kinkadzs/QuickOpener-NetBeans
thanks again, d. |
|
| Back to top |
|
 |
Ernie Rael Posted via mailing list.
|
Posted: Thu Jun 07, 2012 9:15 pm Post subject: Re: plugin and netbeans api get active file |
|
|
BTW, I didn't realize how the constructor for a context aware action
worked,
http://bits.netbeans.org/dev/javadoc/org-openide-awt/org/openide/awt/Actions.html#context(java.lang.Class,%20boolean,%20boolean,%20org.openide.util.ContextAwareAction,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20boolean)
,
so thanks for the question and Gj's answer.
FYI, here's a few things about the current editor/file. There are a
variety of APIs that might be useful, for example
FileUtil.toFile(NbEditorUtilities.getFileObject(EditorRegistry.lastFocusedComponent().getDocument()))
but usually you don't need to look at the EditorRegistry.
-ernie
On 6/6/2012 4:18 PM, kinka-dzs wrote:
| Quote: | Thank you Geertjan, i was doing pretty much the same thing, also i was using JOptionPane to debug, so i think i am in the right way considering it is my first plugin..
I didn't know about the
Code:
String path = context.getPrimaryFile().getPath();
i was doing it in a very different way.... so thank you very much. You can see anyway how i was implementing it (still have to change it with your suggestion) on github. if you go to the downloads i uploaded the nbm for 7.1 , and you can understand what was the context!!! javascript:emoticon(' ')
The link is:
https://github.com/kinkadzs/QuickOpener-NetBeans
thanks again, d.
|
|
|
| Back to top |
|
 |
Adelabarbara
Joined: 20 Sep 2012 Posts: 3
|
Posted: Thu Sep 20, 2012 9:28 am Post subject: |
|
|
Thanks for sharing.Pls provide more related information.I will concern about it.
__________________________________________________________________
obd2 connector|obd ii codes |
|
| Back to top |
|
 |
|