Java Code Examples for org.eclipse.swt.custom.StyledText#getOffsetAtLine()

The following examples show how to use org.eclipse.swt.custom.StyledText#getOffsetAtLine() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompositeTabFolder.java    From ldparteditor with MIT License 6 votes vote down vote up
public void cut() {
    CompositeTab selection = (CompositeTab) this.getSelection();
    if (selection != null && !selection.getState().getFileNameObj().isReadOnly()) {
        final StyledText ct = selection.getTextComposite();
        if (!selection.getState().getFileNameObj().getVertexManager().isUpdated()){
            ct.copy();
            return;
        }
        final int x = ct.getSelection().x;
        if (ct.getSelection().y == x) {
            final int start = ct.getOffsetAtLine(ct.getLineAtOffset(x));
            ct.setSelection(start, start + ct.getLine(ct.getLineAtOffset(x)).length());
        }
        final int x2 = ct.getSelection().x;
        if (ct.getSelection().y == x2) {
            ct.forceFocus();
            return;
        }
        ct.cut();
        ct.forceFocus();
    }
}
 
Example 2
Source File: CompositeTabFolder.java    From ldparteditor with MIT License 6 votes vote down vote up
public void delete() {
    CompositeTab selection = (CompositeTab) this.getSelection();
    if (selection != null && !selection.getState().getFileNameObj().isReadOnly()) {
        if (!selection.getState().getFileNameObj().getVertexManager().isUpdated()){
            return;
        }
        final StyledText ct = selection.getTextComposite();
        final int x = ct.getSelection().x;
        if (ct.getSelection().y == x) {
            final int start = ct.getOffsetAtLine(ct.getLineAtOffset(x));
            ct.setSelection(start, start + ct.getLine(ct.getLineAtOffset(x)).length());
        }
        final int x2 = ct.getSelection().x;
        if (ct.getSelection().y == x2) {
            ct.forceFocus();
            return;
        }
        ct.insert(""); //$NON-NLS-1$
        ct.setSelection(new Point(x, x));
        ct.forceFocus();
    }
}
 
Example 3
Source File: CompositeTabFolder.java    From ldparteditor with MIT License 5 votes vote down vote up
public void copy() {
    CompositeTab selection = (CompositeTab) this.getSelection();
    if (selection != null) {
        final StyledText ct = selection.getTextComposite();
        final int x = ct.getSelection().x;
        if (ct.getSelection().y == x) {
            final int start = ct.getOffsetAtLine(ct.getLineAtOffset(x));
            ct.setSelection(start, start + ct.getLine(ct.getLineAtOffset(x)).length());
        }
        ct.copy();
        ct.forceFocus();
    }
}
 
Example 4
Source File: InteractiveConsoleView.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private void insertHistory(final boolean back) {

		if (history.size() == 0) {
			ViewsHelper.requestUserAttention(this, "No history");
			return;
		}
		if (indexInHistory <= 0) {
			if (back) {
				ViewsHelper.requestUserAttention(this, "No more history");
			}
			indexInHistory = 0;
		} else if (indexInHistory >= history.size() - 1) {
			if (!back) {
				ViewsHelper.requestUserAttention(this, "No more history");
			}
			indexInHistory = history.size() - 1;
		}
		try {
			final StyledText text = viewer.getTextWidget();
			final int lineIndex = text.getLineCount() - 1;
			final int nbChars = text.getCharCount();
			final int firstOffset = text.getOffsetAtLine(lineIndex) + PROMPT.length();
			viewer.getDocument().replace(firstOffset, nbChars - firstOffset, history.get(indexInHistory));
			text.setCaretOffset(text.getCharCount());
			if (back) {
				indexInHistory--;
			} else {
				indexInHistory++;
			}
		} catch (final org.eclipse.jface.text.BadLocationException e1) {}

	}
 
Example 5
Source File: MainShell.java    From RepDev with GNU General Public License v3.0 5 votes vote down vote up
public void setLineColumn() {
	int line, col;

	if (mainfolder.getSelection() != null && mainfolder.getSelection().getControl() instanceof TabTextView) {
		StyledText txt = ((TabTextView) mainfolder.getSelection().getControl()).getStyledText();
		line = txt.getLineAtOffset(txt.getCaretOffset());
		col = txt.getCaretOffset() - txt.getOffsetAtLine(line) + 1;

		lineColumn.setText("Location: " + (line + 1) + " : " + col);
		statusBar.pack();
	} else
		lineColumn.setText("");
}
 
Example 6
Source File: MainShell.java    From RepDev with GNU General Public License v3.0 5 votes vote down vote up
private void openFileGotoLine(SymitarFile file, int line){
	Object o;
	o = openFile(file);
	
	EditorComposite editor = null;
	if (o instanceof EditorComposite)
		editor = (EditorComposite) o;

	try {
		if(editor == null)
			return;
		StyledText newTxt = editor.getStyledText();
		//newTxt.setCaretOffset(newTxt.getText().length());
		newTxt.showSelection();


		int offset = newTxt.getOffsetAtLine(line);
		newTxt.setSelection(offset,offset);
		
		editor.handleCaretChange();
		// Drop Navigation Position
		newTxt.showSelection();
		editor.lineHighlight();
	} catch (IllegalArgumentException ex) {
		// Just ignore it
	}
}
 
Example 7
Source File: SearchMinibuffer.java    From e4macs with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Find the next instance of the search string in the buffer
 * 
 * @param searchStr
 * @param addit - true when just added text to search string
 * @return true if we found a match
 */
protected boolean findNext(String searchStr,boolean addit) {
	if (isSearchEnabled()) {
		setRegexLD(false);
		StyledText text = getTextWidget();
		IFindReplaceTarget target = getTarget();
		if (text != null && target != null) {
			int searchIndex = getSearchOffset();
			if (searchIndex != WRAP_INDEX) {
				Point p = getSelection();
				// if not building the string (or wrapping) search from caret position
				if (!addit) {
					if (isFound() && p != null) {
						searchIndex = p.x;
						if (isForward()) {
							// increment index by (actual or implicit) selection width
							searchIndex += (p.y == 0 ? getEol().length() : p.y); 
						}
					} else {
						// Cannot use target.getSelection since that does not return which side of the
						// selection the caret is on.
						searchIndex = text.getCaretOffset();
					}
				}
				if (!forward && p != null) {
					// if at beginning of line, back up by full eol, else just 1
					searchIndex -= ((p.x == text.getOffsetAtLine(text.getLineAtOffset(p.x))) ? getEol().length() : 1);
				}
			}
			int index = findTarget(target,searchStr,searchIndex, forward);
			boolean justFound = (index != WRAP_INDEX);
			if (isFound() && !justFound && (addit && !isRegexp())) {
				beep();
			} else if (!addit) {
				setSearchOffset(index);
			}
			setFound(justFound);
		}
	}
	return isFound();
}
 
Example 8
Source File: TextVerticalLinesIndentGuide.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
private void computeLine(String string, int firstCharPosition, StyledText styledText, int line, int lineHeight,
        SortedMap<Integer, List<VerticalLinesToDraw>> lineToVerticalLinesToDraw) {
    int lineOffset = -1;

    String spaces = string.substring(0, firstCharPosition);
    int level = 0;
    int whitespacesFound = 0;
    int tabWidthUsed = getTabWidth();
    for (int j = 0; j < firstCharPosition - 1; j++) { //-1 because we don't want to cover for the column where a non whitespace char is.
        char c = spaces.charAt(j);
        if (c == '\t') {
            level++;
            whitespacesFound = 0;
        } else {
            //whitespace (not tab)
            whitespacesFound++;
            if (whitespacesFound % tabWidthUsed == 0) {
                level++;
                whitespacesFound = 0;
            }
        }
        if (level > 0) {
            Point point1;

            if (lineOffset == -1) {
                lineOffset = styledText.getOffsetAtLine(line);
            }
            point1 = styledText.getLocationAtOffset(lineOffset + j + 1);
            int xCoord = point1.x + 3;

            VerticalLinesToDraw verticalLinesToDraw = new VerticalLinesToDraw(xCoord,
                    point1.y, xCoord, point1.y + lineHeight);

            List<VerticalLinesToDraw> lst = lineToVerticalLinesToDraw.get(line);
            if (lst == null) {
                lst = new ArrayList<VerticalLinesToDraw>();
                lineToVerticalLinesToDraw.put(line, lst);
            }
            lst.add(verticalLinesToDraw);

            level--;
        }
    }
}