Skip to content

Commit

Permalink
make ctrl+c just copy the value from row details
Browse files Browse the repository at this point in the history
  • Loading branch information
parg committed Dec 29, 2024
1 parent e87cf9b commit 7b64c54
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 32 deletions.
128 changes: 116 additions & 12 deletions uis/src/com/biglybt/ui/swt/views/columnsetup/ColumnTC_Sample.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ public void runSupport() {
TableColumnSetupWindow tvs = (TableColumnSetupWindow) tv.getParentDataSource();
TableRowCore sampleRow = (TableRowCore) tvs.getSampleRow();

cell.addListeners(new Cell(cell, column, tv.getTableComposite(), sampleRow));
Cell c = new Cell(cell, column, tv.getTableComposite(), sampleRow);

cell.addListeners(c);

cell.setData("Cell", c );
}
});
}
Expand All @@ -95,13 +99,12 @@ public Cell(TableCell parentCell, TableColumnCore column, Composite c, TableRowC
return;
}
Object ds = sampleRow.getDataSource(true);
Object pds = sampleRow.getDataSource(false);
if (column.handlesDataSourceType(pds.getClass())) {
sampleCell = new FakeTableCell(column, ds);

Rectangle bounds = ((TableCellSWT)parentCell).getBounds();
sampleCell.setControl(c, bounds, false);
}
sampleCell = new FakeTableCell(column, ds);

Rectangle bounds = ((TableCellSWT)parentCell).getBounds();

sampleCell.setControl(c, bounds, false);
}

@Override
Expand Down Expand Up @@ -182,11 +185,112 @@ public void refresh(TableCell cell) {
@Override
public int
compare(
TableRowCore arg0,
TableRowCore arg1)
{
// can't sensibly compare the random cell sample values
TableRowCore row1,
TableRowCore row2)
{
final String IS_GRAPHIC = "GRAPHIC";

TableCell cell1 = row1.getTableCell( this );
TableCell cell2 = row2.getTableCell( this );

Cell c1 = (Cell)cell1.getData( "Cell" );
Cell c2 = (Cell)cell2.getData( "Cell" );

return( arg0.getIndex() - arg1.getIndex());
String str1 = null;
String str2 = null;

if ( c1 != null ){

FakeTableCell fc1 = c1.sampleCell;

str1 = fc1.getText();

if ( str1 == null ){

str1 = fc1.getTextEquivalent();
}

if ( str1 == null ){

str1 = fc1.getClipboardText();
}

if ( str1 == null || str1.isEmpty()){

if ( fc1.getIcon() != null || fc1.getGraphic() != null ){

str1 = IS_GRAPHIC;
}else{

str1 = "";
}
}

//System.out.println( fc1.getTableColumn().getName() + " -> " + str1 );
}else{

//System.out.println( "c1 is null" );
}

if ( c2 != null ){

FakeTableCell fc2 = c2.sampleCell;

str2 = fc2.getText();

if ( str2 == null ){

str2 = fc2.getTextEquivalent();
}

if ( str2 == null || str2.isEmpty()){

str2 = fc2.getClipboardText();
}

if ( str2 == null || str2.isEmpty()){

if ( fc2.getIcon() != null || fc2.getGraphic() != null ){

str2 = IS_GRAPHIC;
}else{

str2 = "";
}
}

//System.out.println( fc2.getTableColumn().getName() + " -> " + str2 );
}else{

//System.out.println( "c2 is null" );
}

if ( str1 == null ){

str1 = cell1.getClipboardText();
}

if ( str2 == null ){

str2 = cell2.getClipboardText();
}

int res = 0;

if ( str1 == IS_GRAPHIC && str2 == IS_GRAPHIC ){

}else if ( str1 == IS_GRAPHIC ){

res = 1;

}else if ( str2 == IS_GRAPHIC ){

res = -1;
}else{

res = str1.compareTo(str2 );

}
return((isSortAscending()?1:-1)*res );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public class TableColumnSetupWindow
private static final int RESULT_AREA_WIDTH = Constants.isWindows?250:280;
private static final int SHELL_WIDTH = RESULT_AREA_WIDTH + 600;

protected static final String TABLEID_AVAIL = "ColumnSetupAvail";
protected static final String TABLEID_ROW_DETAILS = "RowDetails";
public static final String TABLEID_AVAIL = "ColumnSetupAvail";
public static final String TABLEID_ROW_DETAILS = "RowDetails";

private static final String TABLEID_CHOSEN = "ColumnSetupChosen";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import com.biglybt.ui.swt.pif.UISWTView;
import com.biglybt.ui.swt.pif.UISWTViewEvent;
import com.biglybt.ui.swt.utils.*;
import com.biglybt.ui.swt.views.columnsetup.TableColumnSetupWindow;
import com.biglybt.ui.swt.views.table.*;
import com.biglybt.ui.swt.views.table.impl.TableTooltips;
import com.biglybt.ui.swt.views.table.impl.TableViewSWT_Common;
Expand All @@ -64,6 +65,7 @@
import com.biglybt.pif.download.Download;
import com.biglybt.pif.download.DownloadTypeComplete;
import com.biglybt.pif.download.DownloadTypeIncomplete;
import com.biglybt.pif.ui.tables.TableCell;
import com.biglybt.pif.ui.tables.TableRowMouseEvent;
import com.biglybt.pif.ui.tables.TableRowMouseListener;
import com.biglybt.pifimpl.local.ui.tables.TableContextMenuItemImpl;
Expand Down Expand Up @@ -799,32 +801,50 @@ protected TableRowCore getNextRow(TableRowCore relativeToRow) {
@Override
public void clipboardSelected() {
String sToClipboard = "";
TableColumnCore[] visibleColumns = getVisibleColumns();
for (int j = 0; j < visibleColumns.length; j++) {
if (j != 0) {
sToClipboard += "\t";

// hack to just copy the "value" cell...

if ( tableID.equals( TableColumnSetupWindow.TABLEID_ROW_DETAILS )){

com.biglybt.pif.ui.tables.TableColumn val = getTableColumn( "TableColumnSample" );

TableRowCore[] rows = getSelectedRows();
for (TableRowCore row : rows) {
TableCell cell = row.getTableCell(val);

if (cell != null) {
sToClipboard += ( sToClipboard.isEmpty()?"":"\n") + cell.getClipboardText();
}
}
String title = MessageText.getString(visibleColumns[j].getTitleLanguageKey());
sToClipboard += title;
}

TableRowCore[] rows = getSelectedRows();
for (TableRowCore row : rows) {
sToClipboard += "\n";
TableRowPainted p_row = (TableRowPainted)row;
p_row.setShown( true, true );
p_row.refresh( true, true );
}else{
TableColumnCore[] visibleColumns = getVisibleColumns();
for (int j = 0; j < visibleColumns.length; j++) {
TableColumnCore column = visibleColumns[j];
if (j != 0) {
sToClipboard += "\t";
}
TableCellCore cell = row.getTableCellCore(column.getName());
if (cell != null) {
sToClipboard += cell.getClipboardText();
String title = MessageText.getString(visibleColumns[j].getTitleLanguageKey());
sToClipboard += title;
}

TableRowCore[] rows = getSelectedRows();
for (TableRowCore row : rows) {
sToClipboard += "\n";
TableRowPainted p_row = (TableRowPainted)row;
p_row.setShown( true, true );
p_row.refresh( true, true );
for (int j = 0; j < visibleColumns.length; j++) {
TableColumnCore column = visibleColumns[j];
if (j != 0) {
sToClipboard += "\t";
}
TableCellCore cell = row.getTableCellCore(column.getName());
if (cell != null) {
sToClipboard += cell.getClipboardText();
}
}
}
}

new Clipboard(getComposite().getDisplay()).setContents(new Object[] {
sToClipboard
}, new Transfer[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public void cellPaint(GC gc, TableCellSWT cell) {
}

int sortVal = dm.getNumFileInfos();
cell.setTextEquivalent( String.valueOf( sortVal ));
Rectangle bounds = cell.getBounds();
Rectangle printArea = new Rectangle(bounds.x, bounds.y, bounds.width - 6,
bounds.height);
Expand Down

0 comments on commit 7b64c54

Please sign in to comment.