Skip to content

Commit

Permalink
Add transfer window search
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Apr 23, 2007
1 parent 79cffc0 commit 5bf3e19
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 71 deletions.
1 change: 1 addition & 0 deletions en.lproj/Queue.nib/classes.nib

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions en.lproj/Queue.nib/info.nib

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified en.lproj/Queue.nib/keyedobjects.nib
Binary file not shown.
13 changes: 9 additions & 4 deletions source/ch/cyberduck/core/AttributedList.java
Expand Up @@ -23,7 +23,14 @@
import com.apple.cocoa.foundation.NSObject;

import java.lang.reflect.Array;
import java.util.*;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.Set;

/**
* Facade for com.apple.cocoa.foundation.NSMutableArray
Expand Down Expand Up @@ -409,6 +416,4 @@ public void add(Object o) {
public List subList(int fromIndex, int toIndex) {
throw new UnsupportedOperationException("Not implemented");
}
}


}
28 changes: 28 additions & 0 deletions source/ch/cyberduck/core/NullTransferFilter.java
@@ -0,0 +1,28 @@
package ch.cyberduck.core;

/*
* Copyright (c) 2007 David Kocher. All rights reserved.
* http://cyberduck.ch/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Bug fixes, suggestions and comments should be sent to:
* dkocher@cyberduck.ch
*/

/**
* @version $Id$
*/
public class NullTransferFilter implements TransferFilter {
public boolean accept(Transfer transfer) {
return true;
}
}
26 changes: 26 additions & 0 deletions source/ch/cyberduck/core/TransferFilter.java
@@ -0,0 +1,26 @@
package ch.cyberduck.core;

/*
* Copyright (c) 2007 David Kocher. All rights reserved.
* http://cyberduck.ch/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Bug fixes, suggestions and comments should be sent to:
* dkocher@cyberduck.ch
*/

/**
* @version $Id$
*/
public interface TransferFilter {
public abstract boolean accept(Transfer transfer);
}
60 changes: 14 additions & 46 deletions source/ch/cyberduck/ui/cocoa/CDBookmarkTableDataSource.java
Expand Up @@ -20,8 +20,20 @@

import ch.cyberduck.core.*;

import com.apple.cocoa.application.*;
import com.apple.cocoa.foundation.*;
import com.apple.cocoa.application.NSApplication;
import com.apple.cocoa.application.NSDraggingInfo;
import com.apple.cocoa.application.NSDraggingSource;
import com.apple.cocoa.application.NSEvent;
import com.apple.cocoa.application.NSImage;
import com.apple.cocoa.application.NSPasteboard;
import com.apple.cocoa.application.NSTableColumn;
import com.apple.cocoa.application.NSTableView;
import com.apple.cocoa.foundation.NSArray;
import com.apple.cocoa.foundation.NSMutableArray;
import com.apple.cocoa.foundation.NSObject;
import com.apple.cocoa.foundation.NSPoint;
import com.apple.cocoa.foundation.NSRect;
import com.apple.cocoa.foundation.NSSize;

import org.apache.log4j.Logger;

Expand Down Expand Up @@ -79,50 +91,6 @@ public class CDBookmarkTableDataSource extends NSObject {
// }
// }
// return filtered;
// }
//
// /**
// * Overwritten returning filtered resultset
// * @param row
// * @return
// */
// public Object get(int row) {
// return this.filter(HostCollection.instance()).get(row);
// }
//
// /**
// * Overwritten returning filtered resultset
// * @param item
// * @return
// */
// public int indexOf(Host item) {
// return this.filter(HostCollection.instance()).indexOf(item);
// }
//
// /**
// * Overwritten returning filtered resultset
// * @param row
// */
// public void remove(int row) {
// HostCollection.instance().remove(
// HostCollection.instance().indexOf(this.filter(HostCollection.instance()).get(row)));
// }
//
// /**
// * Overwritten returning filtered resultset
// * @param item
// * @return
// */
// public int lastIndexOf(Host item) {
// return this.filter(HostCollection.instance()).lastIndexOf(item);
// }
//
// /**
// * Overwritten returning filtered resultset
// * @return
// */
// public int size() {
// return this.filter(HostCollection.instance()).size();
// }

/**
Expand Down
42 changes: 35 additions & 7 deletions source/ch/cyberduck/ui/cocoa/CDTransferController.java
Expand Up @@ -134,6 +134,28 @@ public void queueSizeStepperChanged(final Object sender) {
Queue.instance().notifyAll();
}
}

private NSTextField filterField; // IBOutlet

public void setFilterField(NSTextField filterField) {
this.filterField = filterField;
NSNotificationCenter.defaultCenter().addObserver(this,
new NSSelector("filterFieldTextDidChange", new Class[]{Object.class}),
NSControl.ControlTextDidChangeNotification,
this.filterField);
}

public void filterFieldTextDidChange(NSNotification notification) {
NSDictionary userInfo = notification.userInfo();
if(null != userInfo) {
Object o = userInfo.allValues().lastObject();
if(null != o) {
final String searchString = ((NSText) o).string();
transferModel.setFilter(searchString);
this.reloadData();
}
}
}

private NSPopUpButton bandwidthPopup;

Expand Down Expand Up @@ -378,7 +400,7 @@ private void updateHighlight() {
private void updateSelection() {
log.debug("updateSelection");
this.updateLabels();
this.updateIcon();
this.updateIcon(null);
this.updateBandwidthPopup();
toolbar.validateVisibleItems();
}
Expand Down Expand Up @@ -409,10 +431,6 @@ private void updateLabels() {
}
}

private void updateIcon() {
this.updateIcon(null);
}

/**
*
*/
Expand Down Expand Up @@ -592,7 +610,7 @@ public void finish() {

public void cleanup() {
window.toolbar().validateVisibleItems();
updateIcon();
updateIcon(null);
if(transfer.isComplete() && !transfer.isCanceled()) {
if(transfer instanceof DownloadTransfer) {
Growl.instance().notify("Download complete", transfer.getName());
Expand Down Expand Up @@ -647,6 +665,7 @@ public void pause(final Object lock) {
private static final String TOOLBAR_SHOW = "Show";
private static final String TOOLBAR_TRASH = "Trash";
private static final String TOOLBAR_QUEUE = "Maximum Transfers";
private static final String TOOLBAR_FILTER = "Search";

/**
* NSToolbar.Delegate
Expand Down Expand Up @@ -738,6 +757,14 @@ public NSToolbarItem toolbarItemForItemIdentifier(NSToolbar toolbar, String item
item.setMaxSize(this.queueSizeView.frame().size());
return item;
}
if(itemIdentifier.equals(TOOLBAR_FILTER)) {
item.setLabel(NSBundle.localizedString(TOOLBAR_FILTER, ""));
item.setPaletteLabel(NSBundle.localizedString(TOOLBAR_FILTER, ""));
item.setView(this.filterField);
item.setMinSize(this.filterField.frame().size());
item.setMaxSize(this.filterField.frame().size());
return item;
}
// itemIdent refered to a toolbar item that is not provide or supported by us or cocoa.
// Returning null will inform the toolbar this kind of item is not supported.
return null;
Expand Down Expand Up @@ -909,7 +936,7 @@ public void trashButtonClicked(final Object sender) {
}
}
}
this.updateIcon();
this.updateIcon(null);
}

/**
Expand Down Expand Up @@ -947,6 +974,7 @@ public NSArray toolbarAllowedItemIdentifiers(NSToolbar toolbar) {
TOOLBAR_OPEN,
TOOLBAR_TRASH,
TOOLBAR_QUEUE,
TOOLBAR_FILTER,
NSToolbarItem.CustomizeToolbarItemIdentifier,
NSToolbarItem.SpaceItemIdentifier,
NSToolbarItem.SeparatorItemIdentifier,
Expand Down
59 changes: 47 additions & 12 deletions source/ch/cyberduck/ui/cocoa/CDTransferTableDataSource.java
Expand Up @@ -18,14 +18,7 @@
* dkocher@cyberduck.ch
*/

import ch.cyberduck.core.AbstractCollectionListener;
import ch.cyberduck.core.DownloadTransfer;
import ch.cyberduck.core.Host;
import ch.cyberduck.core.PathFactory;
import ch.cyberduck.core.SessionFactory;
import ch.cyberduck.core.Transfer;
import ch.cyberduck.core.TransferCollection;
import ch.cyberduck.core.TransferFactory;
import ch.cyberduck.core.*;

import com.apple.cocoa.application.NSDraggingInfo;
import com.apple.cocoa.application.NSPasteboard;
Expand All @@ -38,6 +31,7 @@
import org.apache.log4j.Logger;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
Expand Down Expand Up @@ -72,13 +66,54 @@ public void collectionItemRemoved(Object item) {
TransferCollection.instance().load();
}

/**
*
*/
private TransferFilter filter = new NullTransferFilter();

/**
*
* @param searchString
*/
public void setFilter(final String searchString) {
if(null == searchString || searchString.length() == 0) {
// Revert to the default filter
this.filter = new NullTransferFilter();
}
else {
// Setting up a custom filter
this.filter = new TransferFilter() {
public boolean accept(Transfer transfer) {
// Match for pathnames and hostname
return transfer.getName().indexOf(searchString) != -1
|| transfer.getHost().getHostname().indexOf(searchString) != -1;
}
};
}
}

private Collection filter(Collection c) {
if(null == filter) {
return c;
}
Collection filtered = new Collection(c);
Transfer t = null;
for(Iterator i = filtered.iterator(); i.hasNext();) {
if(!filter.accept(t = (Transfer) i.next())) {
//temporarly remove the t from the collection
i.remove();
}
}
return filtered;
}

/**
*
* @param view
*/
public int numberOfRowsInTableView(NSTableView view) {
synchronized(TransferCollection.instance()) {
return TransferCollection.instance().size();
return this.filter(TransferCollection.instance()).size();
}
}

Expand All @@ -93,13 +128,13 @@ public Object tableViewObjectValueForLocation(NSTableView view, NSTableColumn ta
if (row < numberOfRowsInTableView(view)) {
final String identifier = (String) tableColumn.identifier();
if (identifier.equals(ICON_COLUMN)) {
return (Transfer) TransferCollection.instance().get(row);
return (Transfer) this.filter(TransferCollection.instance()).get(row);
}
if (identifier.equals(PROGRESS_COLUMN)) {
return ((CDProgressController)controllers.get(TransferCollection.instance().get(row))).view();
return ((CDProgressController)controllers.get(this.filter(TransferCollection.instance()).get(row))).view();
}
if (identifier.equals(TYPEAHEAD_COLUMN)) {
return ((Transfer) TransferCollection.instance().get(row)).getName();
return ((Transfer) this.filter(TransferCollection.instance()).get(row)).getName();
}
throw new IllegalArgumentException("Unknown identifier: " + identifier);
}
Expand Down

0 comments on commit 5bf3e19

Please sign in to comment.