Difference between revisions of "Patch Browser Delete Individual History Items"

From WebOS Internals
Jump to navigation Jump to search
m (Updated with WebOS 1.2 filenames)
m
Line 14: Line 14:
  
  
['''Note for WebOS 1.2:''' The filename has changed.  The following changes should be made to /usr/palm/applications/com.palm.app.browser/app/controllers/history-assistant.js instead of global.js.  The line numbers aren't the same, but the section of code you should look for are.]
+
['''Note for WebOS 1.2:''' The filename has changed.  The following changes should be made to /usr/palm/applications/com.palm.app.browser/app/controllers/'''history-assistant.js''' instead of global.js.  The line numbers aren't the same, but the section of code you should look for are.]
  
 
Then, open global_code.js file for editing.
 
Then, open global_code.js file for editing.
Line 61: Line 61:
 
Ok! The event is all hooked up to the handler, and the list is swipeable. Now we just need to add code to the history-store model to delete the actual item from the database.
 
Ok! The event is all hooked up to the handler, and the list is swipeable. Now we just need to add code to the history-store model to delete the actual item from the database.
  
['''Note for WebOS 1.2:''' The changes below should be made to /usr/palm/applications/com.palm.app.browser/app/models/history-store.js instead of global.js.  The line numbers aren't the same, but the section of code you should look for are.]
+
['''Note for WebOS 1.2:''' The changes below should be made to /usr/palm/applications/com.palm.app.browser/app/'''models/history-store.js''' instead of global.js.  The line numbers aren't the same, but the section of code you should look for are.]
  
 
Look for this function, on about line 7350:
 
Look for this function, on about line 7350:

Revision as of 18:56, 1 October 2009


Introduction

This will enable swipe-deletion of individual history items from the Browser history list.

Note: I haven't created a "patch" yet. Only manual editing instructions on this page currently. Feel free to create a patch if you can -- I'm having trouble doing the usual ssh/sftp, accessing gitorious, etc. from behind this proxy, so I'm doing this all the old-fashioned way.


Editing Instructions

Note: When I first attempted these changes, I edited the code in the files where you'd expect them to be (controllers/history-assistant.js, models/history-store.js), and found that no functionality changed. I grepped around and found that all the code from those two files (and many others is duplicated in controllers/global_code.js, and that only after I changed *that* file did it work. I don't know why, but oh well... So you'll only have to modify one file to get this working.

First, backup the file we're going to edit.

cd /usr/palm/applications/com.palm.app.browser/app/controllers
cp global_code.js global_code.js.bkp


[Note for WebOS 1.2: The filename has changed. The following changes should be made to /usr/palm/applications/com.palm.app.browser/app/controllers/history-assistant.js instead of global.js. The line numbers aren't the same, but the section of code you should look for are.]

Then, open global_code.js file for editing.

First, we add the ability to swipe-delete to the historyList control itself: Find (on line 1101)

		this.controller.setupWidget('historyList', {
			itemTemplate:'history/history-entry',
			listTemplate:'history/history-container',
			itemsCallback:this._itemsCallback.bind(this)

Add a comma to the end of the last parameter line, and then add the swipeToDelete and autoconfirmDelete parameters, so it looks like this:

		this.controller.setupWidget('historyList', {
			itemTemplate:'history/history-entry',
			listTemplate:'history/history-container',
			itemsCallback:this._itemsCallback.bind(this),
			swipeToDelete:true,
			autoconfirmDelete:true
		});

NOTE: if you want history item deletes to have the Delete/Cancel confirmation, change autoconfirmDelete to false. But with autoconfirmDelete:true, you can delete multiple pages quickly.

Next, we want to hook the delete event of the historyList to a handler. A few lines down, right after

this._onListSelectionHandler = this._onListSelection.bindAsEventListener(this);

Add the following line:

this._onListDeleteHandler = this._onListDelete.bindAsEventListener(this);

Then we need to add a listener for that event. About 20 lines down in the HistoryAssistant.prototype.activate function, right after this line:

this._historyListWidget.addEventListener(Mojo.Event.listTap, this._onListSelectionHandler);

add this:

this._historyListWidget.addEventListener(Mojo.Event.listDelete, this._onListDeleteHandler);

Then we need to add the stopListening in the deactivate function (just a few lines down). Right after this line:

Mojo.Event.stopListening(this._historyListWidget, Mojo.Event.listTap, this._onListSelectionHandler);

add this:

Mojo.Event.stopListening(this._historyListWidget, Mojo.Event.listDelete, this._onListDeleteHandler);

Then we add the handler itself. About 80 lines down, right after the HistoryAssistant.prototype._onListSelection function (though it doesn't *really* matter where you put it.. I'm just putting like things together), add this:

HistoryAssistant.prototype._onListDelete = function(event) {
	this.historyStore.deleteHistoryEntry(event.item.url, function() {}, function() {});
};

Ok! The event is all hooked up to the handler, and the list is swipeable. Now we just need to add code to the history-store model to delete the actual item from the database.

[Note for WebOS 1.2: The changes below should be made to /usr/palm/applications/com.palm.app.browser/app/models/history-store.js instead of global.js. The line numbers aren't the same, but the section of code you should look for are.]

Look for this function, on about line 7350:

function HistoryStore(options, onSuccess, onFailure) {
	try {
		this.displayName = options.displayName || this.name;
		this.estimatedSize = options.estimatedSize;
		this.database = options.database;
		this.database.transaction(this._createTable.bind(this, onSuccess, onFailure));
	} catch (e) {
		Mojo.Log.logException(e, 'HistoryStore()');
	}
}

After that, add this:

HistoryStore.prototype._deleteHistoryEntry = function(url, onSuccess, onFailure, transaction) {
	this._executeSql(transaction, onSuccess, onFailure,
		"DELETE FROM 'history' WHERE url = ?", [url] );
};

HistoryStore.prototype.deleteHistoryEntry = function(url, onSuccess, onFailure) {
        this.database.transaction(this._deleteHistoryEntry.bind(this, url, onSuccess, onFailure));
};

Note: because of the simplicity of the SQL statement (basically "delete all history items with this url"), one swipe could delete multiple history items. For example, if you swipe an item with the url http://forums.precentral.net/faq.php, and you have more than one of them in your history, they will all be deleted. This may or may not be what you want.

That's all.. reboot your pre and give it a try!