xmldoubleclickstrategy.java
来自「一个eclipse插件源代码。用于web开发」· Java 代码 · 共 183 行
JAVA
183 行
/*
* $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/bind/editors/XMLDoubleClickStrategy.java,v 1.1.1.1 2004/07/01 09:07:41 wang_j Exp $
* $Revision: 1.1.1.1 $
* $Date: 2004/07/01 09:07:41 $
*
* ====================================================================
*
* The NanJing HopeRun(IT-FOREST) Software License, Version 2.0.0
*
* Copyright 2003-2004 by NanJing HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and
* IT Forest Corporation
* All rights reserved.
*
* This software is the confidential and proprietary information of
* HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
* You shall not disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into with
* HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
*/
package com.webpump.ui.bind.editors;
import org.eclipse.jface.text.*;
/**
* Class of the doubleclickstrategy which is used in the XMLEditor
*
* @author zhang_tx
* @version 2.0.0 2004-2-13
*/
public class XMLDoubleClickStrategy implements ITextDoubleClickStrategy {
protected ITextViewer fText;
public void doubleClicked(ITextViewer part) {
int pos = part.getSelectedRange().x;
if (pos < 0)
return;
fText = part;
int start = pos;
String editorText = part.getDocument().get();
String type = "";
if(editorText.substring(pos-5,pos).equals("] -->")||editorText.substring(pos-5,pos).equals("\" -->")){
int t = 0;
if(editorText.substring(pos-5,pos).equals("] -->")){
String tag = "";
while(!editorText.substring(pos-5-t-1,pos-5-t).equals("[")){
t++;
}
type = editorText.substring(pos-5-t,pos-5);
while(pos<editorText.length()){
t= 0;
while(!editorText.substring(pos+t,pos+t+4).equals("<!--")&&pos+t+4<editorText.length()){
t++;
}
tag = editorText.substring(pos+t+4,pos+t+4+1);
if(tag.equals("E")){
selectRange(start-1,pos+t);
break;
}
pos = pos+t+4;
int tee = 0;
}
}else{
String tag = "";
while(!editorText.substring(pos-5-t-1,pos-5-t).equals("\"")){
t++;
}
type = editorText.substring(pos-5-t,pos-5);
while(pos<editorText.length()){
t= 0;
while(!editorText.substring(pos+t,pos+t+4).equals("<!--")&&pos+t+4<editorText.length()){
t++;
}
tag = editorText.substring(pos+t+4,pos+t+4+1);
if(tag.equals("/")){
selectRange(start-1,pos+t);
break;
}
pos = pos+t+4;
int tee = 0;
}
}
}else{
if (!selectComment(pos)) {
selectWord(pos);
}
}
}
protected boolean selectComment(int caretPos) {
IDocument doc = fText.getDocument();
int startPos, endPos;
try {
int pos = caretPos;
char c = ' ';
while (pos >= 0) {
c = doc.getChar(pos);
if (c == '\\') {
pos -= 2;
continue;
}
if (c == Character.LINE_SEPARATOR || c == '\"')
break;
--pos;
}
if (c != '\"')
return false;
startPos = pos;
pos = caretPos;
int length = doc.getLength();
c = ' ';
while (pos < length) {
c = doc.getChar(pos);
if (c == Character.LINE_SEPARATOR || c == '\"')
break;
++pos;
}
if (c != '\"')
return false;
endPos = pos;
int offset = startPos + 1;
int len = endPos - offset;
fText.setSelectedRange(offset, len);
return true;
} catch (BadLocationException x) {
}
return false;
}
protected boolean selectWord(int caretPos) {
IDocument doc = fText.getDocument();
int startPos, endPos;
try {
int pos = caretPos;
char c;
while (pos >= 0) {
c = doc.getChar(pos);
if (!Character.isJavaIdentifierPart(c))
break;
--pos;
}
startPos = pos;
pos = caretPos;
int length = doc.getLength();
while (pos < length) {
c = doc.getChar(pos);
if (!Character.isJavaIdentifierPart(c))
break;
++pos;
}
endPos = pos;
selectRange(startPos, endPos);
return true;
} catch (BadLocationException x) {
}
return false;
}
private void selectRange(int startPos, int stopPos) {
int offset = startPos + 1;
int length = stopPos - offset;
fText.setSelectedRange(offset, length);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?