[empathy] Ctrl-L (Clear) blanks the current window.



commit 8ae80c01fbdfbfe23f04943b89d3889a995d91a0
Author: Kevin Haller <kevin haller outofbits com>
Date:   Thu Feb 5 06:41:35 2015 +0100

    Ctrl-L (Clear) blanks the current window.
    
    Problems:
    * Bug#709811        https://bugzilla.gnome.org/show_bug.cgi?id=709811
    * Bug#550885        https://bugzilla.gnome.org/show_bug.cgi?id=550885
    
    Will Thompson (last bug report) has proposed to design the clearance of the
    chat window like in a linux terminal. I think, thats a good idea and it
    solves also the upper problem (that some parts of the history are deleted
    and older ones, which were not displayed before the clearance command, show
    up by scrolling up)
    
    I changed empathy_theme_adium_clear() so that the Javascript function
    'clearPage()' is exectued instead of re-loading the template. The
    Javascipt function is implemented in the data/Template html file.

 data/Template.html                   |   55 ++++++++++++++++++++++++++++++++++
 libempathy-gtk/empathy-theme-adium.c |    3 +-
 2 files changed, 57 insertions(+), 1 deletions(-)
---
diff --git a/data/Template.html b/data/Template.html
index 295ba8b..2b1ec21 100644
--- a/data/Template.html
+++ b/data/Template.html
@@ -26,6 +26,7 @@
                        this.isCoalescing = false;
                        this.isConsecutive = undefined;
                        this.shouldScroll = undefined;
+                       this.interdiv = undefined;
                        
                        var appendElement = function (elem) {
                                document.getElementById("Chat").appendChild(elem);
@@ -101,6 +102,22 @@
                                }
                        }
                        
+                       // This method is called, if the size of the chat window
+                       // changes or after new messages have been appended.
+                       // Adjusts the size of the interleaving page (if existing)
+                       this.onchange = function() {
+                               if (self.interdiv !== undefined){
+                                       var old_padding = parseInt(self.interdiv.style.paddingTop, 10);
+                                       var diff = document.height -
+                                                  (self.interdiv.offsetTop + old_padding);
+                                       new_padding = window.innerHeight - diff;
+
+                                       if (new_padding <= 0)
+                                               removePage();
+                                       else
+                                               self.interdiv.style.paddingTop = new_padding + "px";
+                               }
+                       }
                        
                        // coalased analogs to the global functions
                        
@@ -118,6 +135,7 @@
                                node = null;
 
                                setShouldScroll(shouldScroll);
+                               self.onchange();
                                self.coalesce();
                        }
                        
@@ -133,6 +151,7 @@
                                }
                                node = null;
                                setShouldScroll(shouldScroll);
+                               self.onchange();
                                self.coalesce();
                        }
                        
@@ -305,6 +324,7 @@
 
                window.onresize = function windowDidResize(){
                        alignChat(true/*nearBottom()*/); //nearBottom buggy with inactive tabs
+                       window.onresize = coalescedHTML.onchange;
                }
                
                function initStyle() {
@@ -312,6 +332,41 @@
                        if(!coalescedHTML)
                                coalescedHTML = new CoalescedHTML();
                }
+
+               /* Implementation of the CTRL-L command to clear the chat
+                 * window. (Similar to a linux terminal)
+                 */
+               function clearPage(){
+                       removePage();
+                       if (checkForAndRemoveInsertNodes()){
+                               var interdiv = document.createElement('div');
+                               interdiv.id = 'interleaving_page';
+                               interdiv.style.paddingTop = window.innerHeight + 'px';
+                               chat.appendChild(interdiv);
+                               coalescedHTML.interdiv = interdiv;
+                       }
+               }
+
+               function checkForAndRemoveInsertNodes() {
+                       var inserts = chat.querySelectorAll("#insert");
+                       if (inserts.length <= 0){
+                               return false;
+                       }
+                       for (var n = 0; n < inserts.length-1; n++) {
+                               var rm = inserts[n];
+                               rm.parentNode.removeChild(rm);
+                       }
+                       return true;
+               }
+
+               function removePage(){
+                       var interdivs = chat.querySelectorAll("#interleaving_page");
+                       if (interdivs.length > 0){
+                               var rm = interdivs[0];
+                               rm.parentNode.removeChild(rm);
+                       }
+                       coalescedHTML.interdiv = undefined;
+               }
        </script>
 
        <style type="text/css">
diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c
index 79cbabb..5c5b7a7 100644
--- a/libempathy-gtk/empathy-theme-adium.c
+++ b/libempathy-gtk/empathy-theme-adium.c
@@ -1288,7 +1288,8 @@ empathy_theme_adium_get_has_selection (EmpathyThemeAdium *self)
 void
 empathy_theme_adium_clear (EmpathyThemeAdium *self)
 {
-  theme_adium_load_template (self);
+  webkit_web_view_execute_script (WEBKIT_WEB_VIEW (self), "clearPage()");
+  empathy_theme_adium_scroll_down (self);
 
   /* Clear last contact to avoid trying to add a 'joined'
    * message when we don't have an insertion point. */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]