Skip to content

Commit

Permalink
Issue 1: Replace EditorCookie.getOpenedPanes with NbDocument.findRece…
Browse files Browse the repository at this point in the history
…ntEditorPane

see #1
  • Loading branch information
markiewb committed Aug 31, 2013
1 parent bdd3da7 commit c92ddf6
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 112 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
/nbproject/private/
/build/
14 changes: 7 additions & 7 deletions manifest.mf
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
OpenIDE-Module: org.netbeans.modules.linetools/1
OpenIDE-Module-Layer: org/netbeans/modules/linetools/layer.xml
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/linetools/Bundle.properties
OpenIDE-Module-Requires: org.netbeans.api.javahelp.Help
OpenIDE-Module-Specification-Version: 1.20

Manifest-Version: 1.0
OpenIDE-Module: org.netbeans.modules.linetools/1
OpenIDE-Module-Layer: org/netbeans/modules/linetools/layer.xml
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/linetools/Bundle.properties
OpenIDE-Module-Requires: org.netbeans.api.javahelp.Help
OpenIDE-Module-Specification-Version: 1.21
16 changes: 8 additions & 8 deletions nbproject/project.properties
@@ -1,8 +1,8 @@
javac.compilerargs=-Xlint:unchecked
javac.source=1.5
license.file=CDDL-GPL-2-CP
nbm.homepage=https://github.com/markiewb/nb-sort-line-tools
nbm.module.author=Benno Markiewicz (markiewb@netbeans.org) / original author: Sandip V. Chitale (Sandip.Chitale@Sun.Com)
keystore=nbproject/private/keystore
nbm_alias=myself
javahelp.base=org/netbeans/modules/linetools/docs
javac.compilerargs=-Xlint:unchecked
javac.source=1.5
license.file=CDDL-GPL-2-CP
nbm.homepage=https://github.com/markiewb/nb-sort-line-tools
nbm.module.author=Benno Markiewicz (benno.markiewicz@googlemail.com) / original author: Sandip V. Chitale (Sandip.Chitale@Sun.Com)
keystore=nbproject/private/keystore
nbm_alias=myself
javahelp.base=org/netbeans/modules/linetools/docs
26 changes: 13 additions & 13 deletions src/org/netbeans/modules/linetools/Bundle.properties
@@ -1,13 +1,13 @@
OpenIDE-Module-Display-Category=Editing
OpenIDE-Module-Long-Description=\
Support following operations in text editors:\n<ol>\n<li>Sort lines spanned by selection in ascending/descending (in-)case-sensitive order</li>\n<li>Remove duplicate lines while sorting.\
</li>\n</ol>\n<p>\nYou can also assign shortcuts to these actions.\n\
</p>\n<p>\n(This plugin is based on the "Line Tools" plugin from sandipchitale @ <a href="http://plugins.netbeans.org/plugin/3857/line-tools">http://plugins.netbeans.org/plugin/3857/line-tools</a>. \
It is mainly a repackaging to be compatible with NetBeans 7.x. \
All features except sorting were disabled. \
No bugs were fixed or features added. \
Original sourcecode can be found at <a href="http://hg.netbeans.org/main/contrib/file/tip/linetools">http://hg.netbeans.org/main/contrib/file/tip/linetools</a>. \
License remains CDDL - <a href="http://www.netbeans.org/cddl-gplv2.html">http://www.netbeans.org/cddl-gplv2.html</a>. \
Compatible to NetBeans 7.0 and higher.\n)\n</p>
OpenIDE-Module-Name=Sort Line Tools
OpenIDE-Module-Short-Description=Adds a toolbar with texteditor operations for sorting
OpenIDE-Module-Display-Category=Editing
OpenIDE-Module-Long-Description=\
Support following operations in text editors:\n<ol>\n<li>Sort lines spanned by selection in ascending/descending (in-)case-sensitive order</li>\n<li>Remove duplicate lines while sorting.\
</li>\n</ol>\n<p>\nYou can also assign shortcuts to these actions.\n\
</p>\n\n<p>\nUpdates in 1.21:\n<ul>\n<li><a href="https://github.com/markiewb/nb-sort-line-tools/issues/1">Issue #1:</a> Performance issue (use NbDocument.findRecentEditorPane)</li>\n</ul>\n</p>\n\n<p>\n(This plugin is based on the "Line Tools" plugin from sandipchitale @ <a href="http://plugins.netbeans.org/plugin/3857/line-tools">http://plugins.netbeans.org/plugin/3857/line-tools</a>. \
It is mainly a repackaging to be compatible with NetBeans 7.x. \
All features except sorting were disabled. \
No bugs were fixed or features added. \
Original sourcecode can be found at <a href="http://hg.netbeans.org/main/contrib/file/tip/linetools">http://hg.netbeans.org/main/contrib/file/tip/linetools</a>. \
License remains CDDL - <a href="http://www.netbeans.org/cddl-gplv2.html">http://www.netbeans.org/cddl-gplv2.html</a>. \
Compatible to NetBeans 7.0 and higher.\n)\n</p>
OpenIDE-Module-Name=Sort Line Tools
OpenIDE-Module-Short-Description=Adds a toolbar with texteditor operations for sorting
28 changes: 8 additions & 20 deletions src/org/netbeans/modules/linetools/actions/AbstractLineAction.java
Expand Up @@ -45,28 +45,24 @@
import javax.swing.text.JTextComponent;
import org.openide.cookies.EditorCookie;
import org.openide.nodes.Node;
import org.openide.text.NbDocument;
import org.openide.util.HelpCtx;
import org.openide.util.actions.CookieAction;
import org.openide.windows.TopComponent;

/**
*
* @author Sandip V. Chitale (Sandip.Chitale@Sun.Com)
* @author markiewb@netbeans.org (applied fixes)
*/
public abstract class AbstractLineAction extends CookieAction {

protected void performAction(Node[] activatedNodes) {
EditorCookie ec = (EditorCookie) activatedNodes[0].getCookie(EditorCookie.class);
if (ec != null) {
JEditorPane[] panes = ec.getOpenedPanes();
if (panes != null) {
TopComponent activetc = TopComponent.getRegistry().getActivated();
for (int i = 0; i < panes.length; i++) {
if (activetc.isAncestorOf(panes[i])) {
doLineOperation(panes[i]);
break;
}
}
JEditorPane pane = NbDocument.findRecentEditorPane(ec);
if (null != pane) {
doLineOperation(pane);
}
}
}
Expand All @@ -77,17 +73,9 @@ protected boolean enable(Node[] activatedNodes) {
}
EditorCookie ec = (EditorCookie) activatedNodes[0].getCookie(EditorCookie.class);
if (ec != null) {
JEditorPane[] panes = ec.getOpenedPanes();
if (panes != null) {
TopComponent activetc = TopComponent.getRegistry().getActivated();
for (int i = 0; i < panes.length; i++) {
if (activetc.isAncestorOf(panes[i])) {
if (panes[i].isEditable()) {
return true;
}
break;
}
}
final JEditorPane pane = NbDocument.findRecentEditorPane(ec);
if (null != pane) {
return true;
}
}
return false;
Expand Down
71 changes: 8 additions & 63 deletions src/org/netbeans/modules/linetools/actions/ExchangeDotAndMark.java
Expand Up @@ -41,77 +41,22 @@

package org.netbeans.modules.linetools.actions;

import javax.swing.JEditorPane;
import org.openide.cookies.EditorCookie;
import org.openide.nodes.Node;
import org.openide.util.HelpCtx;
import javax.swing.text.JTextComponent;
import org.openide.util.NbBundle;
import org.openide.util.actions.CookieAction;
import org.openide.windows.TopComponent;

/**
*
* @author Sandip V. Chitale (Sandip.Chitale@Sun.Com)
* @author markiewb@netbeans.org (applied fixes)
*/
public class ExchangeDotAndMark extends CookieAction {

protected void performAction(Node[] activatedNodes) {
EditorCookie ec = (EditorCookie) activatedNodes[0].getCookie(EditorCookie.class);
if (ec != null) {
JEditorPane[] panes = ec.getOpenedPanes();
if (panes != null) {
TopComponent activetc = TopComponent.getRegistry().getActivated();
for (int i = 0; i < panes.length; i++) {
if (activetc.isAncestorOf(panes[i])) {
LineOperations.exchangeDotAndMark(panes[i]);
break;
}
}
}
}
}

protected boolean enable(Node[] activatedNodes) {
if (activatedNodes == null || activatedNodes.length == 0) {
return false;
}
EditorCookie ec = (EditorCookie) activatedNodes[0].getCookie(EditorCookie.class);
if (ec != null) {
JEditorPane[] panes = ec.getOpenedPanes();
if (panes != null) {
TopComponent activetc = TopComponent.getRegistry().getActivated();
for (int i = 0; i < panes.length; i++) {
if (activetc.isAncestorOf(panes[i])) {
if (panes[i].isEditable()) {
return true;
}
break;
}
}
}
}
return false;
}

protected int mode() {
return CookieAction.MODE_EXACTLY_ONE;
}

protected Class[] cookieClasses() {
return new Class[] {
EditorCookie.class
};
}

public HelpCtx getHelpCtx() {
return HelpCtx.DEFAULT_HELP;
}

protected boolean asynchronous() {
return false;
}
public class ExchangeDotAndMark extends AbstractLineAction {

public String getName() {
return NbBundle.getMessage(ExchangeDotAndMark.class, "CTL_ExchangeDotAndMark"); // NOI18N
}

@Override
protected void doLineOperation(JTextComponent textComponent) {
LineOperations.exchangeDotAndMark(textComponent);
}
}
Expand Up @@ -71,6 +71,7 @@
/**
*
* @author Sandip V. Chitale (Sandip.Chitale@Sun.Com)
* @author markiewb@netbeans.org (applied fixes)
*/
public class LineOperations {

Expand All @@ -81,7 +82,7 @@ public class LineOperations {
public static final String FILE_SEPARATOR_DOT_DASH = FILE_SEPARATOR_DOT + DASH;
public static final String FILE_SEPARATORS_DOT_DASH = FILE_SEPARATORS + DOT + DASH;

static void exchangeDotAndMark(JEditorPane textComponent) {
static void exchangeDotAndMark(JTextComponent textComponent) {
Caret caret = textComponent.getCaret();
// check if there is a selection
if (caret.isSelectionVisible()) {
Expand Down

0 comments on commit c92ddf6

Please sign in to comment.