Double click on PDF syncs with code

This commit is contained in:
James Allen 2014-04-08 16:49:21 +01:00
parent da0ed94488
commit 374cf99ef2
7 changed files with 74 additions and 1 deletions

View file

@ -35,6 +35,9 @@ module.exports = CompileController =
getFileFromClsi: (req, res, next = (error) ->) -> getFileFromClsi: (req, res, next = (error) ->) ->
CompileController.proxyToClsi("/project/#{req.params.Project_id}/output/#{req.params.file}", req, res, next) CompileController.proxyToClsi("/project/#{req.params.Project_id}/output/#{req.params.file}", req, res, next)
proxySync: (req, res, next = (error) ->) ->
CompileController.proxyToClsi(req.url, req, res, next)
proxyToClsi: (url, req, res, next = (error) ->) -> proxyToClsi: (url, req, res, next = (error) ->) ->
logger.log url: url, "proxying to CLSI" logger.log url: url, "proxying to CLSI"
url = "#{Settings.apis.clsi.url}#{url}" url = "#{Settings.apis.clsi.url}#{url}"

View file

@ -108,6 +108,9 @@ module.exports = class Router
next() next()
), SecurityManager.requestCanAccessProject, CompileController.getFileFromClsi ), SecurityManager.requestCanAccessProject, CompileController.getFileFromClsi
app.del "/project/:Project_id/output", SecurityManager.requestCanAccessProject, CompileController.deleteAuxFiles app.del "/project/:Project_id/output", SecurityManager.requestCanAccessProject, CompileController.deleteAuxFiles
app.get "/project/:Project_id/sync/code", SecurityManager.requestCanAccessProject, CompileController.proxySync
app.get "/project/:Project_id/sync/pdf", SecurityManager.requestCanAccessProject, CompileController.proxySync
app.del '/Project/:Project_id', SecurityManager.requestIsOwner, Project.deleteProject app.del '/Project/:Project_id', SecurityManager.requestIsOwner, Project.deleteProject
app.post '/Project/:Project_id/clone', SecurityManager.requestCanAccessProject, Project.cloneProject app.post '/Project/:Project_id/clone', SecurityManager.requestCanAccessProject, Project.cloneProject

View file

@ -64,6 +64,7 @@ define [
PdfView = PdfjsView PdfView = PdfjsView
@pdfjs = true @pdfjs = true
@pdfView = new PdfView(manager: @) @pdfView = new PdfView(manager: @)
@pdfView.on "dblclick", (e) => @trigger "dblclick", e
render: () -> render: () ->
@setElement(@templates.pdfPanel) @setElement(@templates.pdfPanel)

View file

@ -33,6 +33,8 @@ define [
@pdfListView = new PDFListView @$(".pdfjs-list-view")[0], @pdfListView = new PDFListView @$(".pdfjs-list-view")[0],
textLayerBuilder: TextLayerBuilder textLayerBuilder: TextLayerBuilder
annotationsLayerBuilder: AnnotationsLayerBuilder annotationsLayerBuilder: AnnotationsLayerBuilder
ondblclick: (e) =>
@trigger "dblclick", e
#logLevel: PDFListView.Logger.DEBUG #logLevel: PDFListView.Logger.DEBUG
@pdfListView.listView.pageWidthOffset = 20 @pdfListView.listView.pageWidthOffset = 20
@pdfListView.listView.pageHeightOffset = 20 @pdfListView.listView.pageHeightOffset = 20

View file

@ -24,6 +24,7 @@ define [
createPdfPanel: () -> createPdfPanel: () ->
@view = new CompiledView manager: @, ide: @ide @view = new CompiledView manager: @, ide: @ide
@view.on "dblclick", (e) => @syncToCode(e)
@view.render() @view.render()
if $.localStorage("layout.pdf") == "flat" if $.localStorage("layout.pdf") == "flat"
@switchToFlatView() @switchToFlatView()
@ -210,3 +211,21 @@ define [
}) })
}] }]
syncToCode: (e) ->
$.ajax {
url: "/project/#{@ide.project_id}/sync/pdf"
data:
page: e.page + 1
h: e.x.toFixed(2)
v: e.y.toFixed(2)
type: "GET"
headers:
"X-CSRF-Token": window.csrfToken
success: (response) =>
data = JSON.parse(response)
if data.code and data.code.length > 0
file = data.code[0].file
line = data.code[0].line
@ide.fileTreeManager.openDocByPath(file, line)
}

View file

@ -215,6 +215,16 @@ ListView.prototype = {
// per pageContainer. // per pageContainer.
this.pdfDoc.pages.map(function(page) { this.pdfDoc.pages.map(function(page) {
var pageView = new PageView(page, this); var pageView = new PageView(page, this);
// TODO: Switch over to a proper event handler
var that = this;
var index = that.pageViews.length;
pageView.ondblclick = function(e) {
e.page = index;
if (that.ondblclick) {
that.ondblclick.call(that, e);
}
}
this.pageViews.push(pageView); this.pageViews.push(pageView);
var container = new PageContainerView(this); var container = new PageContainerView(this);
@ -462,6 +472,27 @@ function PageView(page, listView) {
var dom = this.dom = document.createElement('div'); var dom = this.dom = document.createElement('div');
dom.className = "plv-page-view page-view"; dom.className = "plv-page-view page-view";
var that = this;
dom.ondblclick = function(e) {
var layerX = e.layerX;
var layerY = e.layerY;
var element = e.target;
while (element.offsetParent && element.offsetParent !== dom) {
layerX = layerX + element.offsetLeft;
layerY = layerY + element.offsetTop;
element = element.offsetParent;
}
var pdfPoint = that.viewport.convertToPdfPoint(layerX, layerY);
var event = {
x: pdfPoint[0],
y: that.normalHeight - pdfPoint[1]
};
if (that.ondblclick) {
that.ondblclick.call(that.listView, event)
}
}
this.createNewCanvas(); this.createNewCanvas();
} }
@ -560,6 +591,7 @@ PageView.prototype = {
scaled: pixelRatio != 1 scaled: pixelRatio != 1
}; };
}, },
createNewCanvas: function() { createNewCanvas: function() {
if (this.canvas) { if (this.canvas) {
this.dom.removeChild(this.canvas); this.dom.removeChild(this.canvas);
@ -766,13 +798,19 @@ function PDFListView(mainDiv, options) {
} }
logger.logLevel = options.logLevel; logger.logLevel = options.logLevel;
var self = this;
this.listView = new ListView(mainDiv, options); this.listView = new ListView(mainDiv, options);
this.listView.ondblclick = function(e) {
if (options.ondblclick) {
options.ondblclick.call(self, e);
}
}
this.renderController = new RenderController(); this.renderController = new RenderController();
this.renderController.addListView(this.listView); this.renderController.addListView(this.listView);
this.renderController.updateRenderList(); this.renderController.updateRenderList();
var self = this;
mainDiv.addEventListener('scroll', function() { mainDiv.addEventListener('scroll', function() {
// This will update the list AND start rendering if needed. // This will update the list AND start rendering if needed.

View file

@ -84,6 +84,13 @@ TextLayerBuilder.prototype = {
textDiv.style.left = geom.x + 'px'; textDiv.style.left = geom.x + 'px';
textDiv.style.top = (geom.y - fontHeight) + 'px'; textDiv.style.top = (geom.y - fontHeight) + 'px';
textDiv.ondblclick = function(e) {
if (window.getSelection)
window.getSelection().removeAllRanges();
else if (document.selection)
document.selection.empty();
}
// The content of the div is set in the `setTextContent` function. // The content of the div is set in the `setTextContent` function.
this.textDivs.push(textDiv); this.textDivs.push(textDiv);