Commits

Mathieu Henri committed 69aa068

fixed some contentLength/size/length mismatch, added .go_to_line in cls.ResourceDetailView.instance.createView

  • Participants
  • Parent commits e04b1a2

Comments (0)

Files changed (5)

File src/resource-manager/opensingleresource.js

 window.cls || (window.cls = {});
 
-cls.OpenSingleResource = function(view,manager, url, data)
+cls.OpenSingleResource = function(view, manager, url, data)
 {
-  this._view = view;
-  this._manager = manager;
-  this._url = url;
-  this._data = data;
-  
-  if (!this._tagman)
-  {
-    this._init_prototype();
-  }
-  this._show_resource();
+	this._view = view;
+	this._manager = manager;
+	this._url = url;
+	this._data = data;
+	
+	if (!this._tagman)
+	{
+		this._init_prototype();
+	}
+	this._show_resource();
 };
 
 cls.OpenSingleResource.prototype = new function()
 {
-  const
-  TRANSPORT_STRING = 1,
-  TRANSPORT_DATA_URI = 3,
-  DECODE_TRUE = 1,
-  SIZE_LIMIT = 1e7,
-  TRANSPORT_OFF = 4;
+	const
+	TRANSPORT_STRING = 1,
+	TRANSPORT_DATA_URI = 3,
+	DECODE_TRUE = 1,
+	SIZE_LIMIT = 1e7,
+	TRANSPORT_OFF = 4;
 
-  this._show_resource = function()
-  {
-    if (!this._manager.get_resource_for_url(this._url))
-    //if (!this._view.show_resource_for_url(this._url, this._data))
-    {
-      if (this._service.requestGetResourceID)
-      {
-        var tag = this._tagman.set_callback(this, this._on_resolve_url);
-        this._service.requestGetResourceID(tag, [this._url]);
-      }
-      else
-      {
-        this._fallback();
-      }
-    }
-  };
+	this._show_resource = function()
+	{
+		if (!this._manager.get_resource_for_url(this._url))
+		{
+			if (this._service.requestGetResourceID)
+			{
+				var tag = this._tagman.set_callback(this, this._on_resolve_url);
+				this._service.requestGetResourceID(tag, [this._url]);
+			}
+			else
+			{
+				this._fallback();
+			}
+		}
+	};
 
-  this._on_resolve_url = function(status, message)
-  {
-    if (status)
-    {
-      if (this._service.requestCreateRequest)
-      {
-        var debugContext = window.window_manager_data.get_debug_context();
-        var tag = this._tagman.set_callback(this, this._on_resolve_url_request);
-        this._service.requestCreateRequest(tag, [debugContext, this._url, 'GET']);
-      }
-      else
-      {
-        this._fallback();
-      }
-    }
-    else
-    {
-      const RESOURCE_ID = 0;
-      this._rid = message[RESOURCE_ID];
+	this._requestResource = function(id)
+	{
+			const RESOURCE_ID = 0;
+			this._rid = message[RESOURCE_ID];
 //      if (!this._view.show_resource_for_id(this._rid))
-      {
-        var tag = this._tagman.set_callback(this, this._on_mime_type);
-        this._service.requestGetResource(tag, [this._rid, [TRANSPORT_OFF]]);
-      }
-    }
-  };
+			{
+				var tag = this._tagman.set_callback(this, this._on_mime_type);
+				this._service.requestGetResource(tag, [this._rid, [TRANSPORT_OFF]]);
+			}
+	}
 
-  this._on_resolve_url_request = function(status, message)
-  {
-    if (status)
-    {
-      this._fallback();
-    }
-    else
-    {
-      const RESOURCE_ID = 0;
-      this._rid = message[RESOURCE_ID];
+	this._on_resolve_url = function(status, message)
+	{
+		if (status)
+		{
+			if (this._service.requestCreateRequest)
+			{
+				var debugContext = window.window_manager_data.get_debug_context();
+				var tag = this._tagman.set_callback(this, this._on_resolve_url_request);
+				this._service.requestCreateRequest(tag, [debugContext, this._url, 'GET']);
+			}
+			else
+			{
+				this._fallback();
+			}
+		}
+		else
+		{
+			const RESOURCE_ID = 0;
+			this._rid = message[RESOURCE_ID];
 //      if (!this._view.show_resource_for_id(this._rid))
-      {
-        var tag = this._tagman.set_callback(this, this._on_mime_type);
-        this._service.requestGetResource(tag, [this._rid, [TRANSPORT_OFF]]);
-      }
-    }
-  };
+			{
+				var tag = this._tagman.set_callback(this, this._on_mime_type);
+				this._service.requestGetResource(tag, [this._rid, [TRANSPORT_OFF]]);
+			}
+		}
+	};
 
-  this._on_mime_type = function(status, message)
-  {
-    if (status)
-    {
-      this._fallback();
-    }
-    else
-    {
-      this._res = new cls.Resource(this._rid);
-      this._res.update("urlfinished", new this._ResourceData(message));
-      var resptype = this._utils.mime_to_content_mode(this._res.mime);
-      var tag = this._tagman.set_callback(this, this._on_resource);
-      var msg = 
-      [
-        this._rid, 
-        [
-          resptype == "datauri" ? TRANSPORT_DATA_URI : TRANSPORT_STRING,
-          DECODE_TRUE,
-          SIZE_LIMIT
-        ]
-      ];
-      this._service.requestGetResource(tag, msg);
-    }
-  };
-.001
+	this._on_resolve_url_request = function(status, message)
+	{
+		if (status)
+		{
+			this._fallback();
+		}
+		else
+		{
+			const RESOURCE_ID = 0;
+			this._rid = message[RESOURCE_ID];
+//      if (!this._view.show_resource_for_id(this._rid))
+			{
+				var tag = this._tagman.set_callback(this, this._on_mime_type);
+				this._service.requestGetResource(tag, [this._rid, [TRANSPORT_OFF]]);
+			}
+		}
+	};
 
-  this._on_resource = function(status, message)
-  {
-    if (status)
-    {
-      this._fallback();
-    }
-    else
-    {
-      //this._res.update("urlfinished", new this._ResourceData(message));
-      this._res.update("responsefinished", message );
-      this._view.open_resource_tab(this._res, this._data);
-      window.UI.instance.show_view( this._view.id );
-    }
-  };
+	this._on_mime_type = function(status, message)
+	{
+		if (status)
+		{
+			this._fallback();
+		}
+		else
+		{
+			this._res = new cls.Resource(this._rid);
+			this._res.update("urlfinished", new this._ResourceData(message));
+			var resptype = this._utils.mime_to_content_mode(this._res.mime);
+			var tag = this._tagman.set_callback(this, this._on_resource);
+			var msg = 
+			[
+				this._rid, 
+				[
+					resptype == "datauri" ? TRANSPORT_DATA_URI : TRANSPORT_STRING,
+					DECODE_TRUE,
+					SIZE_LIMIT
+				]
+			];
+			this._service.requestGetResource(tag, msg);
+		}
+	};
 
-  this._fallback = function()
-  {
-    window.open(this._url);
-  };
+	this._on_resource = function(status, message)
+	{
+		if (status)
+		{
+			this._fallback();
+		}
+		else
+		{
+			//this._res.update("urlfinished", new this._ResourceData(message));
+			this._res.update("responsefinished", message );
+			this._view.open_resource_tab(this._res, this._data);
+			window.UI.instance.show_view( this._view.id );
+		}
+	};
 
-  this._init_prototype = function()
-  {
-    this._tagman = window.tagManager;
-    this._service = window.services['resource-manager'];
-    this._ResourceData = cls.ResourceManager["1.0"].ResourceData;
-    this._utils = cls.ResourceUtil;
-  }.bind(this);
+	this._fallback = function()
+	{
+		window.open(this._url);
+	};
+
+	this._init_prototype = function()
+	{
+		this._tagman = window.tagManager;
+		this._service = window.services['resource-manager'];
+		this._ResourceData = cls.ResourceManager["1.0"].ResourceData;
+		this._utils = cls.ResourceUtil;
+	}.bind(this);
 
 }; 

File src/resource-manager/resource_base.js

   this._span.textContent = ' ';
   this._line_count = 0;
   this._line_found = false;
-  this._line = 0;
+  this._target_line = 0;
   this._root_ele = null;
   this._tops = [];
 
           if ((c == CR ) || (c == LF))
           {
             this._line_count++;
-            if (this._line_count == this._line)
+            if (this._line_count == this._target_line)
             {
               var target_pos = child.splitText(pos);
               child.parentNode.insertBefore(this._span, target_pos);
               this._tops.push(this._span.getBoundingClientRect().top);
               child.parentNode.removeChild(this._span);
+              child.parentNode.normalize();
               if (this._tops.length < 2)
               {
-                this._line+=2;
+                this._target_line+=1;
               }
               else
               {
                   scroll_position-=64;
                 }
                 this._root_ele.scrollTop = scroll_position;
-
-                child.parentNode.normalize();
                 this._line_found = true;
                 return;
               }
     // reset all properties
     this._line_count = 0;
     this._line_found = false;
-    this._line = 0;
+    this._target_line = 0;
     this._tops = [];
     var _ele = container.querySelectorAll('.'+HIGHLIGHTED_LINE_CLASSNAME)[0];
     if (_ele)
     if (this._root_ele)
     {
       this.clear_line_numbers(this._root_ele)
-      this._line = parseInt(data.lines[0]);
+      this._target_line = parseInt(data.lines[0]);
       this._traverse_ele(this._root_ele);
     }
 

File src/resource-manager/resource_detail_view.js

 				var toto=Date.now();
 				container.clearAndRender( templates.resource_detail.update(this.resource, this.resource.data) );
 				container.title = (Date.now()-toto)+'ms';
+				this.go_to_line(container,this.data);
 			}
 			else
 			{
 		{
 			container.innerHTML = 'No resource selected'+Date.now();
 		}
+		this.data = null;
 	}
 
 	this.on_resource_data_bound = function(type, data)
 		}
 		this.update();
 	}.bind(this);
-
+/*
 	this.__open_resource = function(resource)
 	{
 		var id = resource.id;
 			this.update();
 		}
 	}
+	*/
+
+
+  const HIGHLIGHTED_LINE_CLASSNAME = 'highlighted-line';
+  const RESOURCE_DETAIL_CONTAINER_CLASSNAME = 'resource-detail-container';
+  const TEXT = document.TEXT_NODE;
+  const ELE  = document.ELEMENT_NODE;
+  this._span = document.createElement('span');
+  this._span.textContent = ' ';
+  this._line_count = 0;
+  this._line_found = false;
+  this._target_line = 0;
+  this._root_ele = null;
+  this._tops = [];
+
+  this._highlight_line = function(ele)
+  {
+    const CR = "\r";
+    const LF = "\n";
+    var child = ele.firstChild;
+    while (child && !this._line_found)
+    {
+      if (child.nodeType == ELE)
+      {
+        this._highlight_line(child);
+      }
+      else if (child.nodeType == TEXT)
+      {
+        var value = child.nodeValue;
+        for (var pos = 0, len = value.length; pos < len; pos++)
+        {
+          var c = value.charAt(pos);
+          // Linefeed recognition will not support Acorn BBC spooled text output 
+          if ((c == CR ) || (c == LF))
+          {
+            this._line_count++;
+            if (this._line_count == this._target_line)
+            {
+              var target_pos = child.splitText(pos);
+              child.parentNode.insertBefore(this._span, target_pos);
+              this._tops.push(this._span.getBoundingClientRect().top);
+              child.parentNode.removeChild(this._span);
+              child.parentNode.normalize();
+              if (this._tops.length < 2)
+              {
+                this._target_line+=1;
+              }
+              else
+              {
+                var scroll_container = ele;
+                var container_top = scroll_container.getBoundingClientRect().top;
+                var delta = this._tops[1] - this._tops[0];
+                var scroll_top = scroll_container.scrollTop;
+                ele.addClass(HIGHLIGHTED_LINE_CLASSNAME);
+                ele.style.cssText = 
+                  "background-size: 100% " + delta + "px;" +
+                  "background-position: 0 " + 
+                    (this._tops[0] - container_top + scroll_top) + "px;";
+                
+                var scroll_position = scroll_top + this._tops[0] - container_top;
+                if (scroll_position <= this._root_ele.parentNode.clientHeight)
+                {
+                  scroll_position-=64;
+                }
+                this._root_ele.scrollTop = scroll_position;
+                this._line_found = true;
+                return;
+              }
+            }
+            if ((c == CR) && (value.charAt(pos+1) == LF))
+            {
+              pos++;
+            }
+          }
+        }
+      }
+      child = child && child.nextSibling;
+    }
+  }
+
+  this.clear_line_highlight = function(container)
+  {
+    // reset all properties
+    this._line_count = 0;
+    this._line_found = false;
+    this._target_line = 0;
+    this._tops = [];
+    var _ele = container.querySelectorAll('.'+HIGHLIGHTED_LINE_CLASSNAME)[0];
+    if (_ele)
+    {
+      _ele.removeClass(HIGHLIGHTED_LINE_CLASSNAME)
+    }
+  }
+
+  this.go_to_line = function(container, data)
+  {
+		if (!data || !(data.lines && data.lines.length)) return;
+    this._root_ele = container.getElementsByClassName(RESOURCE_DETAIL_CONTAINER_CLASSNAME)[0];
+    if (this._root_ele)
+    {
+      this._target_line = parseInt(data.lines[0]);
+      this.clear_line_highlight(this._root_ele)
+      this._highlight_line(this._root_ele);
+    }
+
+  }
 
 	this.open_resource_tab = function(resource, data)
 	{
 		this.resource = resource;
+		this.data = data;
 		this.update();
 	}
 
+
+
 	this.open_resource = function(id)
 	{
 		this.resourceId = id;

File src/resource-manager/resource_display_broker.js

   cls.ResourceDisplayBroker.instance = this;
 
 
-  this._view = null;
-  this._check = function()
+  this._check = function(line)
   {
-    this._view = window.views.resource_detail_view;
+    var data = {};
+    var manager = window.services["resource-manager"];
+    var view = window.views.resource_detail_view;
+    if (line){ data.lines=[line]; }
+    if (manager && view){ return {view:view,data:data}; }
+    return null;
   }
 
   this.show_resource_for_id = function(id, line)
   {
-    var data = {};
+    var foo = this._check(line);
+    if (foo){ foo.view.show_resource_for_id(id, foo.data); }
+/*
+    var data = this._get_data(line);
     var view = window.views.resource_detail_view; //resource_all;
     if (window.services["resource-manager"] && view)
     {
-      if (line)
-      {
-        var data = {"lines":[line]};
-      }
       view.show_resource_for_id(id, data);
     }
+*/
   }
 
   this.show_resource_for_url = function(url, line)
   {
-    var data = {};
+    var foo = this._check(line);
+    if (foo)
+    {
+      new cls.OpenSingleResource(foo.view, cls.ResourceManagerService.instance, url, foo.data);
+    }
+    else
+    {
+      window.open(url);
+    }
+/*
+    var data = this._get_data(line);
     var view = window.views.resource_detail_view; //resource_all;
     if (window.services["resource-manager"] && view)
     {
-      if (line)
-      {
-        var data = {"lines":[line]};
-      }
       new cls.OpenSingleResource(view, cls.ResourceManagerService.instance, url, data);
     }
     else
     {
       window.open(url);
     }
+*/
   }
 
   /**

File src/resource-manager/resource_templates.js

 			'human_url':resource.human_url,
 			'type':resource.type,
 			'mimeType':resource.data.mimeType,
-			'size':resource.size||resource.data.contentLength||resource.data.length,
+			'size':resource.size||resource.data.contentLength||resource.data.content.length,
 			'characterEncoding':resource.encoding||resource.data.characterEncoding
 		};