diff --git a/services/web/public/coffee/editor/Editor.coffee b/services/web/public/coffee/editor/Editor.coffee index c74a85522d..f05f7ed222 100644 --- a/services/web/public/coffee/editor/Editor.coffee +++ b/services/web/public/coffee/editor/Editor.coffee @@ -35,6 +35,8 @@ define [ identifier: "editor" element: @editorPanel @initializeEditor() + @bindToFileTreeEvents() + @enable() @loadingIndicator = $(@templates.loadingIndicator) @editorPanel.find("#editor").append(@loadingIndicator) @leftPanel = @editorPanel.find("#leftEditorPanel") @@ -42,6 +44,11 @@ define [ @initSplitView() @switchToFlatView() + bindToFileTreeEvents: () -> + @ide.fileTreeManager.on "open:doc", (doc_id, options = {}) => + if @enabled + @openDoc doc_id, options + initSplitView: () -> splitter = @editorPanel.find("#editorSplitter") options = @@ -351,3 +358,9 @@ define [ getCurrentDocId: () -> @current_doc_id + + enable: () -> + @enabled = true + + disable: () -> + @enabled = false diff --git a/services/web/public/coffee/file-tree/FileTreeManager.coffee b/services/web/public/coffee/file-tree/FileTreeManager.coffee index cdde12d21e..2dad0e329e 100644 --- a/services/web/public/coffee/file-tree/FileTreeManager.coffee +++ b/services/web/public/coffee/file-tree/FileTreeManager.coffee @@ -76,7 +76,7 @@ define [ openDoc: (doc, line) -> doc_id = doc.id or doc - @ide.editor.openDoc(doc_id, line: line) + @trigger "open:doc", doc_id, line: line @selectEntity(doc_id) $.localStorage "doc.open_id.#{@project_id}", doc_id @@ -86,8 +86,7 @@ define [ @openDoc(doc_id, line) openFile: (file) -> - @ide.mainAreaManager.change('file') - @ide.fileViewManager.showFile(file) + @trigger "open:file", file @selectEntity(file.id) openFolder: (folder) -> diff --git a/services/web/public/coffee/file-view/FileViewManager.coffee b/services/web/public/coffee/file-view/FileViewManager.coffee index 35af265735..4f414493b9 100644 --- a/services/web/public/coffee/file-view/FileViewManager.coffee +++ b/services/web/public/coffee/file-view/FileViewManager.coffee @@ -13,5 +13,20 @@ define [ @ide.layoutManager.on "resize", () => @view.onResize() @view.onResize() + @bindToFileTreeEvents() + @enable() + + bindToFileTreeEvents: () -> + @ide.fileTreeManager.on "open:file", (file) => + if @enabled + @showFile(file) + showFile: (file) -> + @ide.mainAreaManager.change('file') @view.setModel(file) + + enable: () -> + @enabled = true + + disable: () -> + @enabled = false diff --git a/services/web/public/coffee/ide.coffee b/services/web/public/coffee/ide.coffee index 5b6eb591a7..2a09dbe4ff 100644 --- a/services/web/public/coffee/ide.coffee +++ b/services/web/public/coffee/ide.coffee @@ -106,12 +106,12 @@ define [ @sideBarView = new SideBarManager(@, $("#sections")) selectElement = @sideBarView.selectElement mainAreaManager = @mainAreaManager = new MainAreaManager(@, $("#content")) + @fileTreeManager = new FileTreeManager(@) @editor = new Editor(@) @pdfManager = new PdfManager(@) if @userSettings.autoComplete @autoCompleteManager = new AutoCompleteManager(@) @spellingManager = new SpellingManager(@) - @fileTreeManager = new FileTreeManager(@) @fileUploadManager = new FileUploadManager(@) @searchManager = new SearchManager(@) @cursorManager = new CursorManager(@) diff --git a/services/web/public/coffee/track-changes/ChangeListView.coffee b/services/web/public/coffee/track-changes/ChangeListView.coffee index bdcc8d2da7..348b5fbe9b 100644 --- a/services/web/public/coffee/track-changes/ChangeListView.coffee +++ b/services/web/public/coffee/track-changes/ChangeListView.coffee @@ -243,20 +243,20 @@ define [ @$(".change-selector-to").prop("checked", checked) setSelected: (first, last) -> - @$el.addClass("selected") + @$el.addClass("selected-change") if first - @$el.addClass("selected-to") + @$el.addClass("selected-change-to") else - @$el.removeClass("selected-to") + @$el.removeClass("selected-change-to") if last - @$el.addClass("selected-from") + @$el.addClass("selected-change-from") else - @$el.removeClass("selected-from") + @$el.removeClass("selected-change-from") setUnselected: () -> - @$el.removeClass("selected-to") - @$el.removeClass("selected-from") - @$el.removeClass("selected") + @$el.removeClass("selected-change-to") + @$el.removeClass("selected-change-from") + @$el.removeClass("selected-change") setHoverSelected: (first, last) -> @$el.addClass("hover-selected") diff --git a/services/web/public/coffee/track-changes/TrackChangesManager.coffee b/services/web/public/coffee/track-changes/TrackChangesManager.coffee index 22f87f6cca..4c12a2b4ec 100644 --- a/services/web/public/coffee/track-changes/TrackChangesManager.coffee +++ b/services/web/public/coffee/track-changes/TrackChangesManager.coffee @@ -24,6 +24,16 @@ define [ e.preventDefault @hide() + @bindToFileTreeEvents() + + @disable() + + bindToFileTreeEvents: () -> + @ide.fileTreeManager.on "open:doc", (doc_id) => + if @enabled + @doc_id = doc_id + @updateDiff() + @ide.fileTreeManager.on "contextmenu:beforeshow", (entity, entries) => if entity instanceof Doc entries.push { @@ -31,12 +41,11 @@ define [ }, { text: "History" onClick: () => - @show(entity.id) + @doc_id = entity.id + @show() } - show: (@doc_id) -> - @ide.fileTreeManager.selectEntity(@doc_id) - + show: () -> @changes = new ChangeList([], project_id: @project_id, ide: @ide) @changeListView = new ChangeListView( @@ -48,7 +57,7 @@ define [ @autoSelectDiff() @changeListView.on "change_diff", (fromIndex, toIndex) => - @showDiff(fromIndex, toIndex) + @selectDocAndUpdateDiff(fromIndex, toIndex) @changeListView.on "restore", (change) => @restore(change) @@ -57,9 +66,16 @@ define [ @diffView.destroy() @ide.mainAreaManager.change "trackChanges" + @ide.editor.disable() + @ide.fileViewManager.disable() + @enable() hide: () -> + @ide.editor.enable() + @ide.fileViewManager.enable() + @disable() @ide.fileTreeManager.openDoc(@doc_id) + @ide.mainAreaManager.change "editor" autoSelectDiff: () -> if @changes.models.length == 0 @@ -78,13 +94,29 @@ define [ toChange = @changes.models[0] fromChange = @changes.models[fromIndex] - @showDiff(fromChange, toChange) @changeListView.setSelectionRange(fromIndex, 0) + @updateDiff() - showDiff: (fromIndex, toIndex) -> - doc_id = @doc_id + selectDocAndUpdateDiff: (fromIndex, toIndex) -> + doc_ids = [] + for change in @changes.models.slice(toIndex, fromIndex + 1) + for doc in change.get("docs") or [] + doc_ids.push doc.id if doc.id not in doc_ids - {from, to} = @_findDocVersionsRangeInSelection(doc_id, fromIndex, toIndex) + if !@doc_id? or @doc_id not in doc_ids + @doc_id = doc_ids[0] + + @updateDiff() + + updateDiff: () -> + fromIndex = @changeListView.selectedFromIndex + toIndex = @changeListView.selectedToIndex + + if !toIndex? or !fromIndex? + console.log "No selection - what should we do!?" + return + + {from, to} = @_findDocVersionsRangeInSelection(@doc_id, fromIndex, toIndex) if !from? or !to? console.log "No diff, should probably just show latest version" @@ -92,7 +124,7 @@ define [ @diff = new Diff({ project_id: @project_id - doc_id: doc_id + doc_id: @doc_id from: from to: to }) @@ -105,6 +137,9 @@ define [ ) @diff.fetch() + @ide.fileTreeManager.selectEntity(@doc_id) + + _findDocVersionsRangeInSelection: (doc_id, fromIndex, toIndex) -> from = null to = null @@ -155,4 +190,10 @@ define [ callback(error) } + enable: () -> + @enabled = true + + disable: () -> + @enabled = false + return TrackChangesManager diff --git a/services/web/public/stylesheets/less/trackchanges.less b/services/web/public/stylesheets/less/trackchanges.less index 13bd4525ee..a7d0455f2c 100644 --- a/services/web/public/stylesheets/less/trackchanges.less +++ b/services/web/public/stylesheets/less/trackchanges.less @@ -160,7 +160,7 @@ li.loading-changes, li.empty-message { padding: 6px; } - li.selected { + li.selected-change { background-color: #eaeaea; .change-selectors { .range { @@ -168,7 +168,7 @@ } } } - li.selected-to { + li.selected-change-to { .change-selectors { .range { top: 10px; @@ -178,7 +178,7 @@ } } } - li.selected-from { + li.selected-change-from { .change-selectors { .range { bottom: 37px; @@ -230,7 +230,7 @@ } } } - li.selected-from.hover-selected-from { + li.selected-change-from.hover-selected-from { .change-selectors { .range { bottom: 37px;