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

From WebOS Internals
Jump to navigation Jump to search
m (added section headers)
(Added link to 1.2.1 .patch file, added line number and more comments for 1.2/1.2.1)
 
(3 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
This will enable swipe-deletion of individual history items from the Browser history list.
 
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.
+
A .patch file for webOS 1.2.1 is [http://forums.precentral.net/attachments/webos-patches/35363d1256225771-help-anyone-able-install-swipe-history-patch-browser-swipe-history-1.2.1.patch.zip here]
  
  
==Editing Instructions==
+
==Manual 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.
 
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.
  
Open
+
First, backup the file we're going to edit.
<pre><nowiki>/usr/palm/applications/com.palm.app.browser/app/controllers/global_code.js</nowiki></pre>
+
<pre><nowiki>cd /usr/palm/applications/com.palm.app.browser/app/controllers
 +
cp global_code.js global_code.js.bkp</nowiki></pre>
 +
 
 +
 
 +
['''Note for WebOS 1.2/1.2.1:''' 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:
 
First, we add the ability to swipe-delete to the historyList control itself:
Find (on line 1101)
+
Find ('''1.1: global_code.js''', line 1101   '''1.2.1: history-assistant.js''', line 34)
 
<pre><nowiki> this.controller.setupWidget('historyList', {
 
<pre><nowiki> this.controller.setupWidget('historyList', {
 
itemTemplate:'history/history-entry',
 
itemTemplate:'history/history-entry',
Line 37: Line 43:
 
<pre><nowiki>this._onListDeleteHandler = this._onListDelete.bindAsEventListener(this);</nowiki></pre>
 
<pre><nowiki>this._onListDeleteHandler = this._onListDelete.bindAsEventListener(this);</nowiki></pre>
  
Then we need to add a listener for that event. About 20 lines down in the HistoryAssistant.prototype.activate function, right after this line:
+
Then we need to add a listener for that event. About 20 lines down in the HistoryAssistant.prototype.activate function ('''1.2.1:''' line 65), right after this line:
 
<pre><nowiki>this._historyListWidget.addEventListener(Mojo.Event.listTap, this._onListSelectionHandler);</nowiki></pre>
 
<pre><nowiki>this._historyListWidget.addEventListener(Mojo.Event.listTap, this._onListSelectionHandler);</nowiki></pre>
 
add this:
 
add this:
Line 43: Line 49:
  
 
Then we need to add the stopListening in the deactivate function (just a few lines down).
 
Then we need to add the stopListening in the deactivate function (just a few lines down).
Right after this line:
+
Right after this line ('''1.2.1:''' line 74):
 
<pre><nowiki>Mojo.Event.stopListening(this._historyListWidget, Mojo.Event.listTap, this._onListSelectionHandler);</nowiki></pre>
 
<pre><nowiki>Mojo.Event.stopListening(this._historyListWidget, Mojo.Event.listTap, this._onListSelectionHandler);</nowiki></pre>
 
add this:
 
add this:
 
<pre><nowiki>Mojo.Event.stopListening(this._historyListWidget, Mojo.Event.listDelete, this._onListDeleteHandler);</nowiki></pre>
 
<pre><nowiki>Mojo.Event.stopListening(this._historyListWidget, Mojo.Event.listDelete, this._onListDeleteHandler);</nowiki></pre>
  
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:
+
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 ('''1.2.1:''' line 153):
 
<pre><nowiki>HistoryAssistant.prototype._onListDelete = function(event) {
 
<pre><nowiki>HistoryAssistant.prototype._onListDelete = function(event) {
 
this.historyStore.deleteHistoryEntry(event.item.url, function() {}, function() {});
 
this.historyStore.deleteHistoryEntry(event.item.url, function() {}, function() {});
Line 55: 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.
  
Look for this function, on about line 7350:
+
['''Note for WebOS 1.2/1.2.1:''' 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: ('''1.1: global_code.js''', line 7350   '''1.2.1: history-store.js''', line 17
 
<pre><nowiki>function HistoryStore(options, onSuccess, onFailure) {
 
<pre><nowiki>function HistoryStore(options, onSuccess, onFailure) {
 
try {
 
try {

Latest revision as of 20:10, 22 October 2009


Introduction

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

A .patch file for webOS 1.2.1 is here


Manual 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/1.2.1: 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 (1.1: global_code.js, line 1101 1.2.1: history-assistant.js, line 34)

		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 (1.2.1: line 65), 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 (1.2.1: line 74):

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 (1.2.1: line 153):

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/1.2.1: 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: (1.1: global_code.js, line 7350 1.2.1: history-store.js, line 17

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!