Skip to content

Commit bc3c50b

Browse files
committed
Added option to set table column defaults for new views
1 parent 31b996e commit bc3c50b

File tree

5 files changed

+110
-14
lines changed

5 files changed

+110
-14
lines changed

core/src/com/biglybt/internat/MessagesBundle.properties

+1
Original file line numberDiff line numberDiff line change
@@ -5546,6 +5546,7 @@ sb.dblclick.action=Entry double-click 'Pop Out' type
55465546
sb.dblclick.action.ontop=On Top
55475547
sb.dblclick.action.independent=Independent
55485548
ConfigView.section.file.always.create.sub.folder=Always create a sub-folder to contain torrent data files
5549+
label.set.as.default.for.new.views=Set as default for new views
55495550

55505551
#
55515552
#

core/src/com/biglybt/ui/common/table/impl/TableColumnManager.java

+77-2
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public static TableColumnManager getInstance() {
198198
public void addColumns(TableColumnCore[] itemsToAdd) {
199199
try {
200200
items_mon.enter();
201+
Map<String,Map> configCache = new HashMap<>();
201202
for (int i = 0; i < itemsToAdd.length; i++) {
202203
TableColumnCore item = itemsToAdd[i];
203204
if (item == null || item.isRemoved()){
@@ -213,7 +214,11 @@ public void addColumns(TableColumnCore[] itemsToAdd) {
213214
}
214215
if (!mTypes.containsKey(name)) {
215216
mTypes.put(name, item);
216-
Map mapColumnConfig = getTableConfigMap(sTableID);
217+
Map mapColumnConfig = configCache.get( sTableID );
218+
if (mapColumnConfig == null ){
219+
mapColumnConfig = getTableConfigMap(sTableID);
220+
configCache.put(sTableID, mapColumnConfig);
221+
}
217222
item.loadSettings(mapColumnConfig);
218223
}
219224
}
@@ -739,7 +744,13 @@ public Map getTableConfigMap(String sTableID) {
739744
Map mapTablesConfig = getTablesConfigMap();
740745

741746
Map mapTableConfig = (Map) mapTablesConfig.get(key);
747+
748+
if (mapTableConfig == null) {
749+
mapTableConfig = getTableConfigDefaultMap( sTableID );
750+
}
751+
742752
if (mapTableConfig == null) {
753+
743754
mapTableConfig = new HashMap();
744755
mapTablesConfig.put(key, mapTableConfig);
745756
} else {
@@ -767,9 +778,73 @@ public void setTableConfigMap(String sTableID, Map mapTableConfig ) {
767778
Map mapTablesConfig = getTablesConfigMap();
768779

769780
mapTablesConfig.put(key, mapTableConfig);
770-
markDirty();
781+
782+
markDirty();
783+
}
784+
}
785+
786+
public static String
787+
createSubViewID(
788+
String base,
789+
String sub )
790+
{
791+
return( base + "::" + sub );
792+
}
793+
794+
public static String
795+
getBaseViewID(
796+
String id )
797+
{
798+
int pos = id.lastIndexOf( "::" );
799+
800+
if ( pos == -1 ){
801+
802+
return( id );
803+
804+
}else{
805+
806+
return( id.substring( 0, pos ));
807+
}
808+
}
809+
810+
private Map
811+
getTableConfigDefaultMap(
812+
String sTableID)
813+
{
814+
sTableID = getBaseViewID( sTableID );
815+
synchronized (this) {
816+
String key = "TableDefault." + sTableID;
817+
818+
Map mapTablesConfig = getTablesConfigMap();
819+
820+
return((Map)mapTablesConfig.get(key));
771821
}
772822
}
823+
824+
private void
825+
setTableConfigDefaultMap(
826+
String sTableID,
827+
Map mapTableConfigDefault )
828+
{
829+
sTableID = getBaseViewID( sTableID );
830+
synchronized (this) {
831+
String key = "TableDefault." + sTableID;
832+
833+
Map mapTablesConfig = getTablesConfigMap();
834+
835+
mapTablesConfig.put(key, mapTableConfigDefault );
836+
837+
markDirty();
838+
}
839+
}
840+
841+
public void
842+
setTableConfigDefault(
843+
String sTableID,
844+
Map mapTableConfig )
845+
{
846+
setTableConfigDefaultMap( sTableID, mapTableConfig );
847+
}
773848

774849
public void setAutoHideOrder(String sTableID, String[] autoHideOrderColumnIDs) {
775850
ArrayList autoHideOrderList = new ArrayList(autoHideOrderColumnIDs.length);

uis/src/com/biglybt/ui/swt/Utils.java

+4-12
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import com.biglybt.ui.UIFunctions;
7979
import com.biglybt.ui.UIFunctionsManager;
8080
import com.biglybt.ui.UIFunctionsUserPrompter;
81+
import com.biglybt.ui.common.table.impl.TableColumnManager;
8182
import com.biglybt.ui.swt.components.BufferedTruncatedLabel;
8283
import com.biglybt.ui.swt.imageloader.ImageLoader;
8384
import com.biglybt.ui.swt.mainwindow.ClipboardCopy;
@@ -6337,25 +6338,16 @@ public static void dispose() {
63376338
String base,
63386339
String sub )
63396340
{
6340-
return( base + "::" + sub );
6341+
return( TableColumnManager.createSubViewID(base,sub));
63416342
}
63426343

63436344
public static String
63446345
getBaseViewID(
63456346
String id )
63466347
{
6347-
int pos = id.lastIndexOf( "::" );
6348-
6349-
if ( pos == -1 ){
6350-
6351-
return( id );
6352-
6353-
}else{
6354-
6355-
return( id.substring( 0, pos ));
6356-
}
6348+
return( TableColumnManager.getBaseViewID(id));
63576349
}
6358-
6350+
63596351
public static boolean
63606352
isDarkAppearanceNativeWindows()
63616353
{

uis/src/com/biglybt/ui/swt/views/columnsetup/TableColumnSetupWindow.java

+15
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,16 @@ public void widgetDisposed(DisposeEvent e) {
264264
fd.bottom = null;
265265
topInfo.setLayoutData(fd);
266266

267+
268+
final Button btnDefault = new Button(shell, SWT.PUSH);
269+
Messages.setLanguageText(btnDefault, "label.default");
270+
Utils.setTT(btnDefault, MessageText.getString( "label.set.as.default.for.new.views" ));
271+
btnDefault.addListener(SWT.Selection,(ev)->{
272+
tcm.saveTableColumns(forDataSourceType, forTableID);
273+
Map config = tcm.getTableConfigMap(forTableID);
274+
tcm.setTableConfigDefault(forTableID,config);
275+
});
276+
267277
Button btnOk = new Button(shell, SWT.PUSH);
268278
Messages.setLanguageText(btnOk, "Button.ok");
269279
btnOk.addSelectionListener(new SelectionAdapter() {
@@ -1022,6 +1032,11 @@ public void prompterClosed(int result) {
10221032
//fd.width = 64;
10231033
btnApply.setLayoutData(fd);
10241034

1035+
fd = new FormData();
1036+
fd.left = new FormAttachment(cPickArea, 3, SWT.RIGHT);
1037+
fd.bottom = new FormAttachment(100, -3);
1038+
btnDefault.setLayoutData(fd);
1039+
10251040
fd = new FormData();
10261041
fd.right = new FormAttachment(100, -8);
10271042
fd.bottom = new FormAttachment(100, -3);

uis/src/com/biglybt/ui/swt/views/table/painted/TableHeaderPainted.java

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.biglybt.core.internat.MessageText;
3434
import com.biglybt.ui.common.table.TableColumnCore;
3535
import com.biglybt.ui.common.table.TableStructureEventDispatcher;
36+
import com.biglybt.ui.common.table.impl.TableColumnManager;
3637
import com.biglybt.ui.swt.ConfigKeysSWT;
3738
import com.biglybt.ui.swt.Utils;
3839
import com.biglybt.ui.swt.imageloader.ImageLoader;
@@ -496,6 +497,12 @@ public void handleEvent(Event e) {
496497
} else {
497498
int diff = (e.x - columnSizingStart);
498499
columnSizing.setWidthPX(columnSizing.getWidth() + diff);
500+
501+
TableColumnManager tcm = TableColumnManager.getInstance();
502+
503+
String tableID = tv.getTableID();
504+
505+
tcm.saveTableColumns(tv.getDataSourceType(), tableID);
499506
}
500507
}
501508
columnSizing = null;
@@ -608,6 +615,12 @@ public void drop(final DropTargetEvent event) {
608615
}
609616
tv.setColumnsOrdered(visibleColumns);
610617

618+
TableColumnManager tcm = TableColumnManager.getInstance();
619+
620+
String tableID = tv.getTableID();
621+
622+
tcm.saveTableColumns(tv.getDataSourceType(), tableID);
623+
611624
TableStructureEventDispatcher.getInstance(
612625
tv.getTableID()).tableStructureChanged(columnAdded,
613626
tv.getDataSourceType());

0 commit comments

Comments
 (0)