Bug 777811 - Add getSubject() to AwesomeBarItem. r=mfinkle

This commit is contained in:
Brian Nicholson 2012-07-30 17:00:49 -07:00
Родитель 6a82faa7b4
Коммит 350b982475
1 изменённых файлов: 23 добавлений и 27 удалений

Просмотреть файл

@ -167,6 +167,7 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
private interface AwesomeBarItem {
public void onClick();
public ContextMenuSubject getSubject();
}
private class AwesomeBarCursorItem implements AwesomeBarItem {
@ -176,10 +177,6 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
mCursor = cursor;
}
public Cursor getCursor() {
return mCursor;
}
public void onClick() {
AwesomeBarTabs.OnUrlOpenListener listener = getUrlListener();
if (listener == null)
@ -193,6 +190,22 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
}
listener.onUrlOpen(url);
}
public ContextMenuSubject getSubject() {
// Use the history id in order to allow removing history entries
int id = mCursor.getInt(mCursor.getColumnIndexOrThrow(Combined.HISTORY_ID));
String keyword = null;
int keywordCol = mCursor.getColumnIndex(URLColumns.KEYWORD);
if (keywordCol != -1)
keyword = mCursor.getString(keywordCol);
return new ContextMenuSubject(id,
mCursor.getString(mCursor.getColumnIndexOrThrow(URLColumns.URL)),
mCursor.getBlob(mCursor.getColumnIndexOrThrow(URLColumns.FAVICON)),
mCursor.getString(mCursor.getColumnIndexOrThrow(URLColumns.TITLE)),
keyword);
}
}
private class AwesomeBarSearchEngineItem implements AwesomeBarItem {
@ -207,6 +220,11 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
if (listener != null)
listener.onSearch(mSearchEngine, mSearchTerm);
}
public ContextMenuSubject getSubject() {
// Do not show context menu for search engine items
return null;
}
}
private class AwesomeBarCursorAdapter extends SimpleCursorAdapter {
@ -527,29 +545,7 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
ListView list = (ListView)view;
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
Object selectedItem = list.getItemAtPosition(info.position);
if (!(selectedItem instanceof AwesomeBarCursorItem)) {
Log.e(LOGTAG, "item at " + info.position + " is a search item");
return subject;
}
Cursor cursor = ((AwesomeBarCursorItem) selectedItem).getCursor();
// Don't show the context menu for folders
String keyword = null;
int keywordCol = cursor.getColumnIndex(URLColumns.KEYWORD);
if (keywordCol != -1)
keyword = cursor.getString(keywordCol);
// Use the history id in order to allow removing history entries
int id = cursor.getInt(cursor.getColumnIndexOrThrow(Combined.HISTORY_ID));
subject = new ContextMenuSubject(id,
cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL)),
cursor.getBlob(cursor.getColumnIndexOrThrow(URLColumns.FAVICON)),
cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.TITLE)),
keyword);
subject = ((AwesomeBarItem) list.getItemAtPosition(info.position)).getSubject();
if (subject == null)
return subject;