土曜日, 1月 26, 2008

To implement Emacs styled "kill-line"

What I found out today is that emacs styled "kill-line" is really a thing that makes you feel you're in fact using the program like a part of you. Just because it will get you to a part of the program, it indeed is going to make you feel better using the software. That kind of application is something that all of us would have to want to program.

To look at what "kill-line" is, try the Java applet editor in my Zhuyin page. The popup menu of the Java applet editor shows the "Cut Line" that is much like "kill-line" and delete the text from where the caret is to the end of the line. "Copy Line" does just as you assume, it selects the portion of line to the end and that part is copied to the system clipboard.

In case you want to know the beautiful Java lines that can accomplish these tasks, here are the codes.


boolean isLineEnd(char ch)
{
return (ch=='\u2029'||ch=='\u2028'||ch=='\u0085'||ch=='\n'||ch=='\r');
}

public int getLineEndPosition()
{
int index=-1;
String text=textArea.getText();
if(!text.isEmpty())
{
int pos=textArea.getCaretPosition();
index=pos;
int len=text.length();
while(!isLineEnd(text.charAt(index)) && ++index<len);
}
return index;
}

void cutLine()
{
int start=textArea.getCaretPosition();
int end=getLineEndPosition();
textArea.setSelectionEnd(end);
textArea.replaceSelection("");
}

void copyLine()
{
int start=textArea.getCaretPosition();
int end=getLineEndPosition();
textArea.setSelectionEnd(end);
textArea.copy();
}

Qt: 外部プログラムを起動する

  Qt/C++ のアプリは、外部へ直接アクセスできます。これはネットアプリでは不可能な Qt のメリットです。 外部プログラムを起動することもできます。QProcess::startDetached() を使うと独立したプロセスを立ち上げることができます。 この QProces...