me.dsnet.quickopener.prefs.PrefsUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nb-quickopener Show documentation
Show all versions of nb-quickopener Show documentation
<p>Sometimes while programming in NetBeans you want to explore a particular file that you are editing on the file
system browser, or maybe launch a command in a terminal to do something with it.</p>
<p>This plugins brings to your NetBeans six action, three of them always available and three of them available when
the selected node has a file assiociated with it.<br/>
In particular:<p><p><em>When the selection has a valid file</em></p>
<ul>
<li><strong>Open the default OS shell</strong> on the location of the file (or its folder) selected.</li>
<li><strong>Open the file system browser</strong> on the location of the file (or its folder) selected.</li>
<li><strong>Copy to the clipboard</strong> the path of the file selected.</li>
</ul>
<p><em>Always enabled:</em></p>
<ul>
<li><strong>Launch a shell command</strong> (with parameters, customizable on
preferences)</li>
<li><strong>FileSystem browser on any location</strong> (favorites, customizable on preferences)</li>
<li><strong>Open a shell on any location</strong> (favorites, customizable on preferences)</li>
</ul>
The newest version!
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package me.dsnet.quickopener.prefs;
import java.util.ArrayList;
import java.util.List;
import java.util.prefs.BackingStoreException;
import org.openide.util.NbPreferences;
/**
*
* @author SessonaD
*/
public class PrefsUtil {
public static void store(String key, String val){
NbPreferences.forModule(QuickOpenerPanel.class).put(key,val);
}
public static void removeSingleProperty(String key){
NbPreferences.forModule(QuickOpenerPanel.class).remove(key);
}
public static void remove(String key) throws BackingStoreException{
List commands = getAllMatching("command");
List folders = getAllMatching("folder");
NbPreferences.forModule(QuickOpenerPanel.class).clear();
for(QuickOpenerProperty p:commands){
String desc="command" + p.getDescription().replaceAll(" ", "_");
if(! desc.equals(key))
store(desc,p.getValue());
}
for(QuickOpenerProperty p:folders){
String desc="folder" + p.getDescription().replaceAll(" ", "_");
if(! desc.equals(key))
store(desc,p.getValue());
}
}
public static void removeAll(String prefix) throws BackingStoreException{
List commands = getAllMatching("command");
List folders = getAllMatching("folder");
NbPreferences.forModule(QuickOpenerPanel.class).clear();
if (prefix.equals("command")) {
for (QuickOpenerProperty p : folders) {
String desc = "folder" + p.getDescription().replaceAll(" ", "_");
store(desc, p.getValue());
}
} else if (prefix.equals("folder")) {
for (QuickOpenerProperty p : commands) {
String desc = "command" + p.getDescription().replaceAll(" ", "_");
store(desc, p.getValue());
}
}
}
public static QuickOpenerProperty load(String prefix,String key, String defaultVal){
String desc =(prefix==null)?key:key.replace(prefix, "");
desc =desc.replaceAll("_", " ");
return new QuickOpenerProperty(desc,NbPreferences.forModule(QuickOpenerPanel.class).get(key, defaultVal));
}
public static List getAllMatching(String prefix) throws BackingStoreException{
List list = new ArrayList<> ();
for(String key:NbPreferences.forModule(QuickOpenerPanel.class).keys()){
if(key.startsWith(prefix)){
String desc =key.replace(prefix, "");
desc =desc.replaceAll("_", " ");
String val=NbPreferences.forModule(QuickOpenerPanel.class).get(key, "");
list.add(new QuickOpenerProperty(desc,val));
}
}
return list;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy