# NetBeans IDE HG Patch # This patch file was generated by NetBeans IDE # Following Index: paths are relative to: D:\ws\core-main # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: editor.bookmarks/src/org/netbeans/lib/editor/bookmarks/actions/Bundle.properties --- editor.bookmarks/src/org/netbeans/lib/editor/bookmarks/actions/Bundle.properties +++ editor.bookmarks/src/org/netbeans/lib/editor/bookmarks/actions/Bundle.properties @@ -42,5 +42,4 @@ bookmark-next=Next B&ookmark bookmark-previous=Previo&us Bookmark -bookmark-toggle=Toggle Bookmar&k clear-document-bookmarks=Clear Document Bookmarks Index: editor.bookmarks/src/org/netbeans/lib/editor/bookmarks/actions/ToggleBookmarkAction.java --- editor.bookmarks/src/org/netbeans/lib/editor/bookmarks/actions/ToggleBookmarkAction.java +++ editor.bookmarks/src/org/netbeans/lib/editor/bookmarks/actions/ToggleBookmarkAction.java @@ -41,85 +41,59 @@ * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ - package org.netbeans.lib.editor.bookmarks.actions; -import java.awt.Component; import java.awt.event.ActionEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.lang.ref.Reference; -import java.lang.ref.WeakReference; -import javax.swing.AbstractAction; -import javax.swing.AbstractButton; import javax.swing.Action; -import javax.swing.ButtonModel; -import javax.swing.JButton; -import javax.swing.JToggleButton; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import javax.swing.text.BadLocationException; import javax.swing.text.Caret; -import javax.swing.text.Document; import javax.swing.text.JTextComponent; -import org.netbeans.api.editor.EditorRegistry; -import org.netbeans.editor.BaseDocument; -import org.netbeans.lib.editor.bookmarks.api.Bookmark; +import org.netbeans.api.editor.EditorActionRegistration; import org.netbeans.lib.editor.bookmarks.api.BookmarkList; -import org.openide.awt.Actions; +import org.netbeans.spi.editor.AbstractEditorAction; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; import org.openide.cookies.EditorCookie; import org.openide.text.NbDocument; -import org.openide.util.ContextAwareAction; import org.openide.util.ImageUtilities; import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.openide.util.Utilities; -import org.openide.util.WeakListeners; -import org.openide.util.actions.Presenter; - /** * Toggles a bookmark in a line in an opened document. * * @author Vita Stejskal */ -public final class ToggleBookmarkAction extends AbstractAction implements ContextAwareAction, Presenter.Toolbar { +@NbBundle.Messages({"bookmark-toggle=Toggle Bookmark", "CTL_ToggleBookmarkAction=Toggle Bookmar&k"}) +@ActionID(id = "org.netbeans.lib.editor.bookmarks.actions.ToggleBookmarkAction", category = "Edit") +@EditorActionRegistration( + name = "bookmark-toggle", noIconInMenu = true, + iconResource = "org/netbeans/modules/editor/bookmarks/resources/toggle_bookmark.png", + menuText = "#CTL_ToggleBookmarkAction") +@ActionRegistration( + lazy = false, + displayName = "#CTL_ToggleBookmarkAction", + menuText = "#CTL_ToggleBookmarkAction", + iconInMenu = false +//,iconBase = "org/netbeans/modules/editor/bookmarks/resources/toggle_bookmark.png" +) +@ActionReferences({ + @ActionReference(path = "Menu/GoTo", position = 1900),} +) +public final class ToggleBookmarkAction extends AbstractEditorAction { - private static final String ACTION_NAME = "bookmark-toggle"; // NOI18N - private static final String ACTION_ICON = "org/netbeans/modules/editor/bookmarks/resources/toggle_bookmark.png"; // NOI18N - - private final JTextComponent component; - public ToggleBookmarkAction() { - this(null); + super(); + putValue(Action.SMALL_ICON, ImageUtilities.loadImageIcon("org/netbeans/modules/editor/bookmarks/resources/toggle_bookmark.png", false)); + putValue(Action.NAME, Bundle.CTL_ToggleBookmarkAction()); + putValue(Action.LONG_DESCRIPTION, Bundle.CTL_ToggleBookmarkAction()); + putValue(Action.SHORT_DESCRIPTION, Bundle.CTL_ToggleBookmarkAction()); } - public ToggleBookmarkAction(JTextComponent component) { - super( - NbBundle.getMessage(ToggleBookmarkAction.class, ACTION_NAME),ImageUtilities.loadImageIcon(ACTION_ICON, false)); - putValue(SHORT_DESCRIPTION, Actions.cutAmpersand((String) getValue(NAME))); - putValue("noIconInMenu", Boolean.TRUE); // NOI18N - - this.component = component; - updateEnabled(); - PropertyChangeListener editorRegistryListener = new EditorRegistryListener(this); - EditorRegistry.addPropertyChangeListener(editorRegistryListener); - } - - private void updateEnabled() { - setEnabled(isEnabled()); - } - @Override - public Action createContextAwareInstance(Lookup actionContext) { - JTextComponent jtc = findComponent(actionContext); - ToggleBookmarkAction toggleBookmarkAction = new ToggleBookmarkAction(jtc); - toggleBookmarkAction.putValue(ACCELERATOR_KEY, this.getValue(ACCELERATOR_KEY)); - return toggleBookmarkAction; - } - - @Override - public void actionPerformed(ActionEvent arg0) { + protected void actionPerformed(ActionEvent arg0, JTextComponent component) { if (component != null) { // cloned action with context actionPerformed(component); @@ -132,41 +106,11 @@ } } - @Override - public boolean isEnabled() { - if (component != null) { - return true; - } else { - if (EditorRegistry.lastFocusedComponent() == null) { - return false; - } else { - return true; - } - } - } - - @Override - public Component getToolbarPresenter() { - AbstractButton b; - - if (component != null) { - b = new MyGaGaButton(); - b.setModel(new BookmarkButtonModel(component)); - } else { - b = new JButton(); - } - - b.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N - b.setAction(this); - - return b; - } - public static JTextComponent findComponent(Lookup lookup) { EditorCookie ec = lookup.lookup(EditorCookie.class); return ec == null ? null : NbDocument.findRecentEditorPane(ec); } - + private static void actionPerformed(JTextComponent target) { if (target != null) { if (org.netbeans.editor.Utilities.getEditorUI(target).isGlyphGutterVisible()) { @@ -179,170 +123,5 @@ } } } - - private static final class BookmarkButtonModel extends JToggleButton.ToggleButtonModel implements PropertyChangeListener, ChangeListener { - - private final JTextComponent component; - private Caret caret; - private BookmarkList bookmarks; - private int lastCurrentLineStartOffset = -1; - - private PropertyChangeListener bookmarksListener = null; - private ChangeListener caretListener = null; - - @SuppressWarnings("LeakingThisInConstructor") - public BookmarkButtonModel(JTextComponent component) { - this.component = component; - this.component.addPropertyChangeListener(WeakListeners.propertyChange(this, this.component)); - rebuild(); - } - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName() == null || - "document".equals(evt.getPropertyName()) || //NOI18N - "caret".equals(evt.getPropertyName()) //NOI18N - ) { - rebuild(); - } else if ("bookmarks".equals(evt.getPropertyName())) { //NOI18N - lastCurrentLineStartOffset = -1; - updateState(); - } - } - - @Override - public void stateChanged(ChangeEvent evt) { - updateState(); - } - - private static boolean isBookmarkOnTheLine(BookmarkList bookmarks, int lineStartOffset) { - Bookmark bm = bookmarks.getNextBookmark(lineStartOffset - 1, false); -// System.out.println("offset: " + lineStartOffset + " -> " + bm + (bm == null ? "" : "; bm.getOffset() = " + bm.getOffset())); - return bm == null ? false : lineStartOffset == bm.getOffset(); - } - - private void rebuild() { - // Hookup the bookmark list - BookmarkList newBookmarks = BookmarkList.get(component.getDocument()); - if (newBookmarks != bookmarks) { - if (bookmarksListener != null) { - bookmarks.removePropertyChangeListener (bookmarksListener); - bookmarksListener = null; - } - - bookmarks = newBookmarks; - - if (bookmarks != null) { - bookmarksListener = WeakListeners.propertyChange(this, bookmarks); - bookmarks.addPropertyChangeListener (bookmarksListener); - } - } - - // Hookup the caret - Caret newCaret = component.getCaret(); - if (newCaret != caret) { - if (caretListener != null) { - caret.removeChangeListener(caretListener); - caretListener = null; - } - - caret = newCaret; - - if (caret != null) { - caretListener = WeakListeners.change(this, caret); - caret.addChangeListener(caretListener); - } - } - - lastCurrentLineStartOffset = -1; - updateState(); - } - - private void updateState() { - Document doc = component.getDocument(); - if (caret != null && bookmarks != null && doc instanceof BaseDocument) { - try { - int currentLineStartOffset = org.netbeans.editor.Utilities.getRowStart((BaseDocument) doc, caret.getDot()); - if (currentLineStartOffset != lastCurrentLineStartOffset) { - lastCurrentLineStartOffset = currentLineStartOffset; - boolean selected = isBookmarkOnTheLine(bookmarks, currentLineStartOffset); - -// System.out.println("updateState: offset=" + currentLineStartOffset + ", hasBookmark=" + selected); - - setSelected(selected); - } - } catch (BadLocationException e) { - // ignore - lastCurrentLineStartOffset = -1; - } - } - } - } // End of BookmarkButtonModel class - - private static final class MyGaGaButton extends JToggleButton implements ChangeListener { - - public MyGaGaButton() { - - } - - @Override - public void setModel(ButtonModel model) { - ButtonModel oldModel = getModel(); - if (oldModel != null) { - oldModel.removeChangeListener(this); - } - - super.setModel(model); - - ButtonModel newModel = getModel(); - if (newModel != null) { - newModel.addChangeListener(this); - } - - stateChanged(null); - } - - @Override - public void stateChanged(ChangeEvent evt) { - boolean selected = isSelected(); - super.setContentAreaFilled(selected); - super.setBorderPainted(selected); - } - - @Override - public void setBorderPainted(boolean arg0) { - if (!isSelected()) { - super.setBorderPainted(arg0); - } - } - - @Override - public void setContentAreaFilled(boolean arg0) { - if (!isSelected()) { - super.setContentAreaFilled(arg0); - } - } - } // End of MyGaGaButton class - - private static final class EditorRegistryListener implements PropertyChangeListener { - - private final Reference actionRef; - - EditorRegistryListener(ToggleBookmarkAction action) { - actionRef = new WeakReference(action); - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - ToggleBookmarkAction action = actionRef.get(); - if (action != null) { - action.updateEnabled(); - } else { - EditorRegistry.removePropertyChangeListener(this); // EditorRegistry fires frequently so remove this way - } - } - - } - } - Index: editor.bookmarks/src/org/netbeans/modules/editor/bookmarks/resources/layer.xml --- editor.bookmarks/src/org/netbeans/modules/editor/bookmarks/resources/layer.xml +++ editor.bookmarks/src/org/netbeans/modules/editor/bookmarks/resources/layer.xml @@ -60,9 +60,6 @@ - - - @@ -77,11 +74,6 @@ - - - - - @@ -118,6 +110,7 @@ +