Add history entry into context menu for docs

This commit is contained in:
James Allen 2014-03-13 14:32:30 +00:00
parent 81fcafb476
commit df706da7e0
3 changed files with 37 additions and 10 deletions

View file

@ -100,6 +100,8 @@ define [
showContextMenu: (position) ->
entries = @getContextMenuEntries()
@manager.trigger "contextmenu:beforeshow", @model, entries
@contextMenu = new ContextMenu(position, entries)
@contextMenu.on "destroy", () =>
delete @contextMenu

View file

@ -23,11 +23,14 @@ define [
@insertNameTag()
return @
destroy: () ->
@$editor?.remove()
createAceEditor: () ->
@$el.empty()
$editor = $("<div/>")
@$el.append($editor)
@aceEditor = Ace.edit($editor[0])
@$editor = $("<div/>")
@$el.append(@$editor)
@aceEditor = Ace.edit(@$editor[0])
@aceEditor.setTheme("ace/theme/#{window.userSettings.theme}")
@aceEditor.setReadOnly true
@aceEditor.setShowPrintMargin(false)

View file

@ -4,26 +4,38 @@ define [
"track-changes/ChangeListView"
"track-changes/DiffView"
"utils/Modal"
"models/Doc"
"moment"
], (ChangeList, Diff, ChangeListView, DiffView, Modal, moment) ->
], (ChangeList, Diff, ChangeListView, DiffView, Modal, Doc, moment) ->
class TrackChangesManager
template: $("#trackChangesPanelTemplate").html()
constructor: (@ide) ->
@project_id = window.userSettings.project_id
@$el = $(@template)
$("#editorWrapper").append(@$el)
@hide()
@hideEl()
@ide.editor.on "change:doc", () =>
@hide()
@hideEl()
@$el.find(".track-changes-close").on "click", (e) =>
e.preventDefault
@hide()
show: () ->
@project_id = window.userSettings.project_id
@doc_id = @ide.editor.current_doc_id
@ide.fileTreeManager.on "contextmenu:beforeshow", (entity, entries) =>
if entity instanceof Doc
entries.push {
divider: true
}, {
text: "History"
onClick: () =>
@show(entity.id)
}
show: (@doc_id) ->
@ide.fileTreeManager.selectEntity(@doc_id)
@changes = new ChangeList([], doc_id: @doc_id, project_id: @project_id)
@changeListView = new ChangeListView(
@ -40,8 +52,15 @@ define [
@changeListView.on "restore", (change) =>
@restore(change)
if @diffView?
@diffView.destroy()
@showEl()
hide: () ->
@hideEl()
@ide.fileTreeManager.openDoc(@doc_id)
autoSelectDiff: () ->
if @changes.models.length == 0
return
@ -69,6 +88,9 @@ define [
from: fromModel.get("fromVersion")
to: toModel.get("toVersion")
})
if @diffView?
@diffView.destroy()
@diffView = new DiffView(
model: @diff
el: @$el.find(".track-changes-diff")
@ -79,7 +101,7 @@ define [
@ide.editor.hide()
@$el.show()
hide: () ->
hideEl: () ->
@ide.editor.show()
@$el.hide()