Lines 15-20
Link Here
|
15 |
|
15 |
|
16 |
import java.lang.reflect.InvocationTargetException; |
16 |
import java.lang.reflect.InvocationTargetException; |
17 |
import java.lang.reflect.Method; |
17 |
import java.lang.reflect.Method; |
|
|
18 |
import java.text.CharacterIterator; |
18 |
import java.util.Iterator; |
19 |
import java.util.Iterator; |
19 |
|
20 |
|
20 |
import org.eclipse.cdt.core.CCorePlugin; |
21 |
import org.eclipse.cdt.core.CCorePlugin; |
Lines 38-43
Link Here
|
38 |
import org.eclipse.cdt.internal.ui.text.CPairMatcher; |
39 |
import org.eclipse.cdt.internal.ui.text.CPairMatcher; |
39 |
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration; |
40 |
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration; |
40 |
import org.eclipse.cdt.internal.ui.text.CTextTools; |
41 |
import org.eclipse.cdt.internal.ui.text.CTextTools; |
|
|
42 |
import org.eclipse.cdt.internal.ui.text.CWordIterator; |
43 |
import org.eclipse.cdt.internal.ui.text.DocumentCharacterIterator; |
41 |
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference; |
44 |
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference; |
42 |
import org.eclipse.cdt.internal.ui.util.CUIHelp; |
45 |
import org.eclipse.cdt.internal.ui.util.CUIHelp; |
43 |
import org.eclipse.cdt.ui.CUIPlugin; |
46 |
import org.eclipse.cdt.ui.CUIPlugin; |
Lines 52-57
Link Here
|
52 |
import org.eclipse.core.runtime.Preferences; |
55 |
import org.eclipse.core.runtime.Preferences; |
53 |
import org.eclipse.core.runtime.content.IContentType; |
56 |
import org.eclipse.core.runtime.content.IContentType; |
54 |
import org.eclipse.jface.action.Action; |
57 |
import org.eclipse.jface.action.Action; |
|
|
58 |
import org.eclipse.jface.action.IAction; |
55 |
import org.eclipse.jface.action.IMenuManager; |
59 |
import org.eclipse.jface.action.IMenuManager; |
56 |
import org.eclipse.jface.action.IStatusLineManager; |
60 |
import org.eclipse.jface.action.IStatusLineManager; |
57 |
import org.eclipse.jface.preference.IPreferenceStore; |
61 |
import org.eclipse.jface.preference.IPreferenceStore; |
Lines 86-91
Link Here
|
86 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
90 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
87 |
import org.eclipse.jface.viewers.StructuredSelection; |
91 |
import org.eclipse.jface.viewers.StructuredSelection; |
88 |
import org.eclipse.search.ui.actions.TextSearchGroup; |
92 |
import org.eclipse.search.ui.actions.TextSearchGroup; |
|
|
93 |
import org.eclipse.swt.SWT; |
94 |
import org.eclipse.swt.custom.ST; |
89 |
import org.eclipse.swt.custom.StyledText; |
95 |
import org.eclipse.swt.custom.StyledText; |
90 |
import org.eclipse.swt.graphics.Image; |
96 |
import org.eclipse.swt.graphics.Image; |
91 |
import org.eclipse.swt.graphics.Point; |
97 |
import org.eclipse.swt.graphics.Point; |
Lines 113-123
Link Here
|
113 |
import org.eclipse.ui.texteditor.IEditorStatusLine; |
119 |
import org.eclipse.ui.texteditor.IEditorStatusLine; |
114 |
import org.eclipse.ui.texteditor.ITextEditorActionConstants; |
120 |
import org.eclipse.ui.texteditor.ITextEditorActionConstants; |
115 |
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; |
121 |
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; |
|
|
122 |
import org.eclipse.ui.texteditor.IUpdate; |
116 |
import org.eclipse.ui.texteditor.MarkerAnnotation; |
123 |
import org.eclipse.ui.texteditor.MarkerAnnotation; |
117 |
import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; |
124 |
import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; |
|
|
125 |
import org.eclipse.ui.texteditor.TextNavigationAction; |
118 |
import org.eclipse.ui.texteditor.TextOperationAction; |
126 |
import org.eclipse.ui.texteditor.TextOperationAction; |
119 |
import org.eclipse.ui.views.contentoutline.IContentOutlinePage; |
127 |
import org.eclipse.ui.views.contentoutline.IContentOutlinePage; |
120 |
|
128 |
|
|
|
129 |
import com.ibm.icu.text.BreakIterator; |
130 |
|
121 |
|
131 |
|
122 |
/** |
132 |
/** |
123 |
* C specific text editor. |
133 |
* C specific text editor. |
Lines 1175-1180
Link Here
|
1175 |
return store.getBoolean(SPACES_FOR_TABS); |
1185 |
return store.getBoolean(SPACES_FOR_TABS); |
1176 |
} |
1186 |
} |
1177 |
|
1187 |
|
|
|
1188 |
/* |
1189 |
* @see org.eclipse.ui.texteditor.AbstractTextEditor#createNavigationActions() |
1190 |
*/ |
1191 |
protected void createNavigationActions() { |
1192 |
super.createNavigationActions(); |
1193 |
|
1194 |
final StyledText textWidget = getSourceViewer().getTextWidget(); |
1195 |
|
1196 |
IAction action = new NavigatePreviousSubWordAction(); |
1197 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_PREVIOUS); |
1198 |
setAction(ITextEditorActionDefinitionIds.WORD_PREVIOUS, action); |
1199 |
textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_LEFT, SWT.NULL); |
1200 |
|
1201 |
action = new NavigateNextSubWordAction(); |
1202 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.WORD_NEXT); |
1203 |
setAction(ITextEditorActionDefinitionIds.WORD_NEXT, action); |
1204 |
textWidget.setKeyBinding(SWT.CTRL | SWT.ARROW_RIGHT, SWT.NULL); |
1205 |
|
1206 |
action = new SelectPreviousSubWordAction(); |
1207 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS); |
1208 |
setAction(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS, action); |
1209 |
textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_LEFT, SWT.NULL); |
1210 |
|
1211 |
action = new SelectNextSubWordAction(); |
1212 |
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT); |
1213 |
setAction(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT, action); |
1214 |
textWidget.setKeyBinding(SWT.CTRL | SWT.SHIFT | SWT.ARROW_RIGHT, SWT.NULL); |
1215 |
} |
1216 |
|
1178 |
interface ITextConverter { |
1217 |
interface ITextConverter { |
1179 |
void customizeDocumentCommand(IDocument document, DocumentCommand command); |
1218 |
void customizeDocumentCommand(IDocument document, DocumentCommand command); |
1180 |
} |
1219 |
} |
Lines 1472-1475
Link Here
|
1472 |
System.arraycopy(parentPrefPageIds, 0, prefPageIds, nIds, parentPrefPageIds.length); |
1511 |
System.arraycopy(parentPrefPageIds, 0, prefPageIds, nIds, parentPrefPageIds.length); |
1473 |
return prefPageIds; |
1512 |
return prefPageIds; |
1474 |
} |
1513 |
} |
|
|
1514 |
|
1515 |
/** |
1516 |
* Text navigation action to navigate to the next sub-word. |
1517 |
* |
1518 |
* @since 3.0 |
1519 |
*/ |
1520 |
protected abstract class NextSubWordAction extends TextNavigationAction { |
1521 |
|
1522 |
protected CWordIterator fIterator = new CWordIterator(); |
1523 |
|
1524 |
/** |
1525 |
* Creates a new next sub-word action. |
1526 |
* |
1527 |
* @param code Action code for the default operation. Must be an action code from @see org.eclipse.swt.custom.ST. |
1528 |
*/ |
1529 |
protected NextSubWordAction(int code) { |
1530 |
super(getSourceViewer().getTextWidget(), code); |
1531 |
} |
1532 |
|
1533 |
/* |
1534 |
* @see org.eclipse.jface.action.IAction#run() |
1535 |
*/ |
1536 |
public void run() { |
1537 |
// TODO Add EDITOR_SUB_WORD_NAVIGATION preference. |
1538 |
// Check whether sub word navigation is enabled. |
1539 |
// final IPreferenceStore store = getPreferenceStore(); |
1540 |
// if (!store.getBoolean(PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION)) { |
1541 |
// super.run(); |
1542 |
// return; |
1543 |
// } |
1544 |
|
1545 |
final ISourceViewer viewer = getSourceViewer(); |
1546 |
final IDocument document = viewer.getDocument(); |
1547 |
fIterator.setText((CharacterIterator) new DocumentCharacterIterator(document)); |
1548 |
int position = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset()); |
1549 |
if (position == -1) |
1550 |
return; |
1551 |
|
1552 |
int next = findNextPosition(position); |
1553 |
if (next != BreakIterator.DONE) { |
1554 |
setCaretPosition(next); |
1555 |
getTextWidget().showSelection(); |
1556 |
fireSelectionChanged(); |
1557 |
} |
1558 |
|
1559 |
} |
1560 |
|
1561 |
/** |
1562 |
* Finds the next position after the given position. |
1563 |
* |
1564 |
* @param position the current position |
1565 |
* @return the next position |
1566 |
*/ |
1567 |
protected int findNextPosition(int position) { |
1568 |
ISourceViewer viewer = getSourceViewer(); |
1569 |
int widget = -1; |
1570 |
while (position != BreakIterator.DONE && widget == -1) { // TODO: optimize |
1571 |
position = fIterator.following(position); |
1572 |
if (position != BreakIterator.DONE) |
1573 |
widget = modelOffset2WidgetOffset(viewer, position); |
1574 |
} |
1575 |
return position; |
1576 |
} |
1577 |
|
1578 |
/** |
1579 |
* Sets the caret position to the sub-word boundary given with <code>position</code>. |
1580 |
* |
1581 |
* @param position Position where the action should move the caret |
1582 |
*/ |
1583 |
protected abstract void setCaretPosition(int position); |
1584 |
} |
1585 |
|
1586 |
/** |
1587 |
* Text navigation action to navigate to the next sub-word. |
1588 |
* |
1589 |
* @since 3.0 |
1590 |
*/ |
1591 |
protected class NavigateNextSubWordAction extends NextSubWordAction { |
1592 |
|
1593 |
/** |
1594 |
* Creates a new navigate next sub-word action. |
1595 |
*/ |
1596 |
public NavigateNextSubWordAction() { |
1597 |
super(ST.WORD_NEXT); |
1598 |
} |
1599 |
|
1600 |
/* |
1601 |
* @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int) |
1602 |
*/ |
1603 |
protected void setCaretPosition(final int position) { |
1604 |
getTextWidget().setCaretOffset(modelOffset2WidgetOffset(getSourceViewer(), position)); |
1605 |
} |
1606 |
} |
1607 |
|
1608 |
/** |
1609 |
* Text operation action to delete the next sub-word. |
1610 |
* |
1611 |
* @since 3.0 |
1612 |
*/ |
1613 |
protected class DeleteNextSubWordAction extends NextSubWordAction implements IUpdate { |
1614 |
|
1615 |
/** |
1616 |
* Creates a new delete next sub-word action. |
1617 |
*/ |
1618 |
public DeleteNextSubWordAction() { |
1619 |
super(ST.DELETE_WORD_NEXT); |
1620 |
} |
1621 |
|
1622 |
/* |
1623 |
* @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int) |
1624 |
*/ |
1625 |
protected void setCaretPosition(final int position) { |
1626 |
if (!validateEditorInputState()) |
1627 |
return; |
1628 |
|
1629 |
final ISourceViewer viewer = getSourceViewer(); |
1630 |
final int caret, length; |
1631 |
Point selection = viewer.getSelectedRange(); |
1632 |
if (selection.y != 0) { |
1633 |
caret = selection.x; |
1634 |
length = selection.y; |
1635 |
} else { |
1636 |
caret = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset()); |
1637 |
length = position - caret; |
1638 |
} |
1639 |
|
1640 |
try { |
1641 |
viewer.getDocument().replace(caret, length, ""); //$NON-NLS-1$ |
1642 |
} catch (BadLocationException exception) { |
1643 |
// Should not happen |
1644 |
} |
1645 |
} |
1646 |
|
1647 |
/* |
1648 |
* @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#findNextPosition(int) |
1649 |
*/ |
1650 |
protected int findNextPosition(int position) { |
1651 |
return fIterator.following(position); |
1652 |
} |
1653 |
|
1654 |
/* |
1655 |
* @see org.eclipse.ui.texteditor.IUpdate#update() |
1656 |
*/ |
1657 |
public void update() { |
1658 |
setEnabled(isEditorInputModifiable()); |
1659 |
} |
1660 |
} |
1661 |
|
1662 |
/** |
1663 |
* Text operation action to select the next sub-word. |
1664 |
* |
1665 |
* @since 3.0 |
1666 |
*/ |
1667 |
protected class SelectNextSubWordAction extends NextSubWordAction { |
1668 |
|
1669 |
/** |
1670 |
* Creates a new select next sub-word action. |
1671 |
*/ |
1672 |
public SelectNextSubWordAction() { |
1673 |
super(ST.SELECT_WORD_NEXT); |
1674 |
} |
1675 |
|
1676 |
/* |
1677 |
* @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.NextSubWordAction#setCaretPosition(int) |
1678 |
*/ |
1679 |
protected void setCaretPosition(final int position) { |
1680 |
final ISourceViewer viewer = getSourceViewer(); |
1681 |
|
1682 |
final StyledText text = viewer.getTextWidget(); |
1683 |
if (text != null && !text.isDisposed()) { |
1684 |
|
1685 |
final Point selection = text.getSelection(); |
1686 |
final int caret = text.getCaretOffset(); |
1687 |
final int offset = modelOffset2WidgetOffset(viewer, position); |
1688 |
|
1689 |
if (caret == selection.x) |
1690 |
text.setSelectionRange(selection.y, offset - selection.y); |
1691 |
else |
1692 |
text.setSelectionRange(selection.x, offset - selection.x); |
1693 |
} |
1694 |
} |
1695 |
} |
1696 |
|
1697 |
/** |
1698 |
* Text navigation action to navigate to the previous sub-word. |
1699 |
* |
1700 |
* @since 3.0 |
1701 |
*/ |
1702 |
protected abstract class PreviousSubWordAction extends TextNavigationAction { |
1703 |
|
1704 |
protected CWordIterator fIterator = new CWordIterator(); |
1705 |
|
1706 |
/** |
1707 |
* Creates a new previous sub-word action. |
1708 |
* |
1709 |
* @param code Action code for the default operation. Must be an action code from @see org.eclipse.swt.custom.ST. |
1710 |
*/ |
1711 |
protected PreviousSubWordAction(final int code) { |
1712 |
super(getSourceViewer().getTextWidget(), code); |
1713 |
} |
1714 |
|
1715 |
/* |
1716 |
* @see org.eclipse.jface.action.IAction#run() |
1717 |
*/ |
1718 |
public void run() { |
1719 |
// TODO Add EDITOR_SUB_WORD_NAVIGATION preference. |
1720 |
// Check whether sub word navigation is enabled. |
1721 |
// final IPreferenceStore store = getPreferenceStore(); |
1722 |
// if (!store.getBoolean(PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION)) { |
1723 |
// super.run(); |
1724 |
// return; |
1725 |
// } |
1726 |
|
1727 |
final ISourceViewer viewer = getSourceViewer(); |
1728 |
final IDocument document = viewer.getDocument(); |
1729 |
fIterator.setText((CharacterIterator) new DocumentCharacterIterator(document)); |
1730 |
int position = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset()); |
1731 |
if (position == -1) |
1732 |
return; |
1733 |
|
1734 |
int previous = findPreviousPosition(position); |
1735 |
if (previous != BreakIterator.DONE) { |
1736 |
setCaretPosition(previous); |
1737 |
getTextWidget().showSelection(); |
1738 |
fireSelectionChanged(); |
1739 |
} |
1740 |
|
1741 |
} |
1742 |
|
1743 |
/** |
1744 |
* Finds the previous position before the given position. |
1745 |
* |
1746 |
* @param position the current position |
1747 |
* @return the previous position |
1748 |
*/ |
1749 |
protected int findPreviousPosition(int position) { |
1750 |
ISourceViewer viewer = getSourceViewer(); |
1751 |
int widget = -1; |
1752 |
while (position != BreakIterator.DONE && widget == -1) { // TODO: optimize |
1753 |
position = fIterator.preceding(position); |
1754 |
if (position != BreakIterator.DONE) |
1755 |
widget = modelOffset2WidgetOffset(viewer, position); |
1756 |
} |
1757 |
return position; |
1758 |
} |
1759 |
|
1760 |
/** |
1761 |
* Sets the caret position to the sub-word boundary given with <code>position</code>. |
1762 |
* |
1763 |
* @param position Position where the action should move the caret |
1764 |
*/ |
1765 |
protected abstract void setCaretPosition(int position); |
1766 |
} |
1767 |
|
1768 |
/** |
1769 |
* Text navigation action to navigate to the previous sub-word. |
1770 |
* |
1771 |
* @since 3.0 |
1772 |
*/ |
1773 |
protected class NavigatePreviousSubWordAction extends PreviousSubWordAction { |
1774 |
|
1775 |
/** |
1776 |
* Creates a new navigate previous sub-word action. |
1777 |
*/ |
1778 |
public NavigatePreviousSubWordAction() { |
1779 |
super(ST.WORD_PREVIOUS); |
1780 |
} |
1781 |
|
1782 |
/* |
1783 |
* @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int) |
1784 |
*/ |
1785 |
protected void setCaretPosition(final int position) { |
1786 |
getTextWidget().setCaretOffset(modelOffset2WidgetOffset(getSourceViewer(), position)); |
1787 |
} |
1788 |
} |
1789 |
|
1790 |
/** |
1791 |
* Text operation action to delete the previous sub-word. |
1792 |
* |
1793 |
* @since 3.0 |
1794 |
*/ |
1795 |
protected class DeletePreviousSubWordAction extends PreviousSubWordAction implements IUpdate { |
1796 |
|
1797 |
/** |
1798 |
* Creates a new delete previous sub-word action. |
1799 |
*/ |
1800 |
public DeletePreviousSubWordAction() { |
1801 |
super(ST.DELETE_WORD_PREVIOUS); |
1802 |
} |
1803 |
|
1804 |
/* |
1805 |
* @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int) |
1806 |
*/ |
1807 |
protected void setCaretPosition(int position) { |
1808 |
if (!validateEditorInputState()) |
1809 |
return; |
1810 |
|
1811 |
final int length; |
1812 |
final ISourceViewer viewer = getSourceViewer(); |
1813 |
Point selection = viewer.getSelectedRange(); |
1814 |
if (selection.y != 0) { |
1815 |
position = selection.x; |
1816 |
length = selection.y; |
1817 |
} else { |
1818 |
length = widgetOffset2ModelOffset(viewer, viewer.getTextWidget().getCaretOffset()) - position; |
1819 |
} |
1820 |
|
1821 |
try { |
1822 |
viewer.getDocument().replace(position, length, ""); //$NON-NLS-1$ |
1823 |
} catch (BadLocationException exception) { |
1824 |
// Should not happen |
1825 |
} |
1826 |
} |
1827 |
|
1828 |
/* |
1829 |
* @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#findPreviousPosition(int) |
1830 |
*/ |
1831 |
protected int findPreviousPosition(int position) { |
1832 |
return fIterator.preceding(position); |
1833 |
} |
1834 |
|
1835 |
/* |
1836 |
* @see org.eclipse.ui.texteditor.IUpdate#update() |
1837 |
*/ |
1838 |
public void update() { |
1839 |
setEnabled(isEditorInputModifiable()); |
1840 |
} |
1841 |
} |
1842 |
|
1843 |
/** |
1844 |
* Text operation action to select the previous sub-word. |
1845 |
* |
1846 |
* @since 3.0 |
1847 |
*/ |
1848 |
protected class SelectPreviousSubWordAction extends PreviousSubWordAction { |
1849 |
|
1850 |
/** |
1851 |
* Creates a new select previous sub-word action. |
1852 |
*/ |
1853 |
public SelectPreviousSubWordAction() { |
1854 |
super(ST.SELECT_WORD_PREVIOUS); |
1855 |
} |
1856 |
|
1857 |
/* |
1858 |
* @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.PreviousSubWordAction#setCaretPosition(int) |
1859 |
*/ |
1860 |
protected void setCaretPosition(final int position) { |
1861 |
final ISourceViewer viewer = getSourceViewer(); |
1862 |
|
1863 |
final StyledText text = viewer.getTextWidget(); |
1864 |
if (text != null && !text.isDisposed()) { |
1865 |
|
1866 |
final Point selection = text.getSelection(); |
1867 |
final int caret = text.getCaretOffset(); |
1868 |
final int offset = modelOffset2WidgetOffset(viewer, position); |
1869 |
|
1870 |
if (caret == selection.x) |
1871 |
text.setSelectionRange(selection.y, offset - selection.y); |
1872 |
else |
1873 |
text.setSelectionRange(selection.x, offset - selection.x); |
1874 |
} |
1875 |
} |
1876 |
} |
1475 |
} |
1877 |
} |