mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Reloading when there are modified buffers pops up a dialog.
This commit is contained in:
@@ -85,7 +85,19 @@
|
||||
|
||||
- (bool)keyEventOfType:(cef_handler_keyevent_type_t)type code:(int)code modifiers:(int)modifiers isSystemKey:(bool)isSystemKey isAfterJavaScript:(bool)isAfterJavaScript {
|
||||
if (isAfterJavaScript && type == KEYEVENT_RAWKEYDOWN && modifiers == KEY_META && code == 'R') {
|
||||
_clientHandler->GetBrowser()->ReloadIgnoreCache();
|
||||
|
||||
CefRefPtr<CefV8Context> context = _clientHandler->GetBrowser()->GetMainFrame()->GetV8Context();
|
||||
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||
|
||||
context->Enter();
|
||||
CefRefPtr<CefV8Value> retval;
|
||||
CefRefPtr<CefV8Exception> exception;
|
||||
CefV8ValueList arguments;
|
||||
global->GetValue("reload")->ExecuteFunction(global, arguments, retval, exception, true);
|
||||
if (exception) _clientHandler->GetBrowser()->ReloadIgnoreCache();
|
||||
context->Exit();
|
||||
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,20 @@ describe "Window", ->
|
||||
$(window).trigger 'close'
|
||||
expect(window.close).toHaveBeenCalled()
|
||||
|
||||
describe ".reload()", ->
|
||||
it "returns false when no buffers are modified", ->
|
||||
spyOn($native, "reload")
|
||||
window.reload()
|
||||
expect($native.reload).toHaveBeenCalled()
|
||||
|
||||
it "shows alert when a modifed buffer exists", ->
|
||||
rootView.activeEditor().insertText("hi")
|
||||
spyOn($native, "alert")
|
||||
spyOn($native, "reload")
|
||||
window.reload()
|
||||
expect($native.reload).not.toHaveBeenCalled()
|
||||
expect($native.alert).toHaveBeenCalled()
|
||||
|
||||
describe "requireStylesheet(path)", ->
|
||||
it "synchronously loads the stylesheet at the given path and installs a style tag for it in the head", ->
|
||||
$('head style[path*="atom.css"]').remove()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# This a weirdo file. We don't create a Window class, we just add stuff to
|
||||
# the DOM window.
|
||||
|
||||
Native = require 'native'
|
||||
fs = require 'fs'
|
||||
_ = require 'underscore'
|
||||
$ = require 'jquery'
|
||||
@@ -60,6 +61,20 @@ windowAdditions =
|
||||
return if $("head style[path='#{fullPath}']").length
|
||||
$('head').append "<style path='#{fullPath}'>#{content}</style>"
|
||||
|
||||
reload: ->
|
||||
console.log rootView.modifiedBuffers()
|
||||
if rootView.modifiedBuffers().length > 0
|
||||
message = "There are unsaved buffers, reload anyway?"
|
||||
detailedMessage = "You will lose all unsaved changes if you reload"
|
||||
buttons = [
|
||||
["Reload", -> Native.reload()]
|
||||
["Cancel", ->]
|
||||
]
|
||||
|
||||
Native.alert(message, detailedMessage, buttons)
|
||||
else
|
||||
Native.reload()
|
||||
|
||||
showConsole: ->
|
||||
$native.showDevTools()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user