mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Automatically open previously open doc
This commit is contained in:
parent
35c7f27788
commit
2520651ef2
5 changed files with 46 additions and 12 deletions
|
@ -54,7 +54,14 @@ block content
|
|||
include ./editor/file-tree
|
||||
|
||||
.ui-layout-center
|
||||
#editor(ace-editor, theme="'cobalt'", show-print-margin="false", sharejs-doc="editor.sharejs_doc", last-updated="editor.last_updated")
|
||||
#editor(
|
||||
ace-editor,
|
||||
ng-show="!!editor.sharejs_doc"
|
||||
theme="'cobalt'",
|
||||
show-print-margin="false",
|
||||
sharejs-doc="editor.sharejs_doc",
|
||||
last-updated="editor.last_updated"
|
||||
)
|
||||
|
||||
//- #loadingScreen
|
||||
//- h3 Loading...
|
||||
|
|
|
@ -9,8 +9,34 @@ define [
|
|||
last_updated: null
|
||||
}
|
||||
|
||||
@$scope.$on "entity:selected", (event, entity) =>
|
||||
if (entity.type == "doc")
|
||||
@openDoc(entity)
|
||||
|
||||
initialized = false
|
||||
@$scope.$on "file-tree:initialized", () =>
|
||||
if !initialized
|
||||
initialized = true
|
||||
@autoOpenDoc()
|
||||
|
||||
autoOpenDoc: () ->
|
||||
open_doc_id =
|
||||
$.localStorage("doc.open_id.#{@$scope.project_id}") or
|
||||
@$scope.project.rootDoc_id
|
||||
return if !open_doc_id?
|
||||
doc = @ide.fileTreeManager.findEntityById(open_doc_id)
|
||||
return if !doc?
|
||||
@openDoc(doc)
|
||||
|
||||
openDoc: (doc, options = {}) ->
|
||||
# TODO: Don't open if already open
|
||||
console.log "Trying to open doc", doc.id
|
||||
return if doc.id == @open_doc_id
|
||||
@open_doc_id = doc.id
|
||||
console.log "Actually opening doc", doc.id
|
||||
|
||||
$.localStorage "doc.open_id.#{@$scope.project_id}", doc.id
|
||||
@ide.fileTreeManager.selectEntity(doc)
|
||||
|
||||
@_openNewDocument doc, (error, sharejs_doc) =>
|
||||
if error?
|
||||
@ide.showGenericServerErrorMessage()
|
||||
|
|
|
@ -61,9 +61,7 @@ define [
|
|||
session.setMode(new LatexMode())
|
||||
|
||||
doc = session.getDocument()
|
||||
console.log "Document", doc
|
||||
doc.on "change", () ->
|
||||
console.log "DOC CHANGE"
|
||||
scope.$apply () ->
|
||||
scope.lastUpdated = new Date()
|
||||
|
||||
|
@ -85,8 +83,8 @@ define [
|
|||
sharejs_doc.attachToAce(editor)
|
||||
|
||||
detachFromAce = (sharejs_doc) ->
|
||||
old_sharejs_doc.detachFromAce()
|
||||
old_sharejs_doc.off "remoteop.recordForUndo"
|
||||
sharejs_doc.detachFromAce()
|
||||
sharejs_doc.off "remoteop.recordForUndo"
|
||||
|
||||
template: """
|
||||
<div class="ace-editor-wrapper">
|
||||
|
|
|
@ -10,6 +10,7 @@ define [
|
|||
constructor: (@ide, @$scope) ->
|
||||
@$scope.$on "project:joined", =>
|
||||
@loadRootFolder()
|
||||
@$scope.$emit "file-tree:initialized"
|
||||
|
||||
@_bindToSocketEvents()
|
||||
|
||||
|
@ -60,6 +61,13 @@ define [
|
|||
@$scope.$apply () =>
|
||||
@_moveEntityInScope(entity, folder)
|
||||
|
||||
selectEntity: (entity) ->
|
||||
return if entity.selected # Don't get into a recursive event loop
|
||||
@ide.fileTreeManager.forEachEntity (entity) ->
|
||||
entity.selected = false
|
||||
entity.selected = true
|
||||
@$scope.$emit "entity:selected", entity
|
||||
|
||||
findEntityById: (id) ->
|
||||
@_findEntityByIdInFolder @$scope.rootFolder, id
|
||||
|
||||
|
|
|
@ -3,12 +3,7 @@ define [
|
|||
], (App) ->
|
||||
App.controller "FileTreeEntityController", ["$scope", "ide", "$modal", ($scope, ide, $modal) ->
|
||||
$scope.select = () ->
|
||||
ide.fileTreeManager.forEachEntity (entity) ->
|
||||
entity.selected = false
|
||||
$scope.entity.selected = true
|
||||
|
||||
if ($scope.entity.type == "doc")
|
||||
ide.editorManager.openDoc($scope.entity)
|
||||
ide.fileTreeManager.selectEntity($scope.entity)
|
||||
|
||||
$scope.inputs =
|
||||
name: $scope.entity.name
|
||||
|
|
Loading…
Reference in a new issue