Skip to content

Commit

Permalink
Merge pull request #11 from CoryXie/features
Browse files Browse the repository at this point in the history
Support selecting any part of a log line (and enable in place editing).
  • Loading branch information
wangfei1975 authored Mar 30, 2017
2 parents a6b09ba + 6be015d commit 91d4b1d
Showing 1 changed file with 61 additions and 11 deletions.
72 changes: 61 additions & 11 deletions src/feiw/SlogTabFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
Expand All @@ -33,18 +34,11 @@
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.*;

import feiw.LogSource.LogFilter;
import feiw.LogSource.LogListener;
Expand All @@ -54,6 +48,7 @@
public class SlogTabFrame extends CTabItem implements LogListener {

private SlogTable mTable;
private TableEditor mTableEditor;
protected LogView mLogView = null;
protected LogSource mLogSrc;
private Label mLineCountLabel;
Expand Down Expand Up @@ -276,7 +271,7 @@ public void widgetSelected(SelectionEvent event) {
}

public SlogTabFrame(CTabFolder parent, String txt, int style, LogSource logsrc, LogFilter logFilter,
LogParser logParser, LogView parentLogView) {
LogParser logParser, LogView parentLogView) {
super(parent, style);

mLogSrc = logsrc;
Expand All @@ -294,6 +289,7 @@ public SlogTabFrame(CTabFolder parent, String txt, int style, LogSource logsrc,
SlogTable tb = new SlogTable(com, SWT.FLAT, mLogView);
tb.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
mTable = tb;
mTableEditor = new TableEditor(mTable);
mTable.setLogView(mLogView);
setLogFont();

Expand Down Expand Up @@ -334,6 +330,60 @@ public void widgetDefaultSelected(SelectionEvent e) {

});

mTableEditor.horizontalAlignment = SWT.LEFT;
mTableEditor.grabHorizontal = true;
mTable.addListener(SWT.MouseDoubleClick, new Listener() {
public void handleEvent(Event event) {
Rectangle clientArea = mTable.getClientArea();
Point pt = new Point(event.x, event.y);
int index = mTable.getTopIndex();
while (index < mTable.getItemCount()) {
boolean visible = false;
final TableItem item = mTable.getItem(index);
for (int i = 0; i < mTable.getColumnCount(); i++) {
Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) {
final int column = i;
final Text text = new Text(mTable, SWT.NONE);
Listener textListener = new Listener() {
public void handleEvent(final Event e) {
switch (e.type) {
case SWT.FocusOut:
item.setText(column, text.getText());
text.dispose();
break;
case SWT.Traverse:
switch (e.detail) {
case SWT.TRAVERSE_RETURN:
item.setText(column, text.getText());
// FALL THROUGH
case SWT.TRAVERSE_ESCAPE:
text.dispose();
e.doit = false;
}
break;
}
}
};
text.addListener(SWT.FocusOut, textListener);
text.addListener(SWT.Traverse, textListener);
mTableEditor.setEditor(text, item, i);
text.setText(item.getText(i));
text.selectAll();
text.setFocus();
return;
}
if (!visible && rect.intersects(clientArea)) {
visible = true;
}
}
if (!visible)
return;
index++;
}
}
});

com.addListener(SWT.Show, new Listener() {
@Override
public void handleEvent(Event event) {
Expand Down Expand Up @@ -507,7 +557,7 @@ void copyLog(boolean verbose) {
}
}
}
cb.setContents(new Object[] { txt.toString() }, new Transfer[] { TextTransfer.getInstance() });
cb.setContents(new Object[]{txt.toString()}, new Transfer[]{TextTransfer.getInstance()});
}

public void onCopyAll() {
Expand Down

0 comments on commit 91d4b1d

Please sign in to comment.