@@ -7,6 +7,7 @@ define(function (require) {
77 LocalizationUtils = brackets . getModule ( "utils/LocalizationUtils" ) ,
88 Strings = brackets . getModule ( "strings" ) ,
99 Metrics = brackets . getModule ( "utils/Metrics" ) ,
10+ NotificationUI = brackets . getModule ( "widgets/NotificationUI" ) ,
1011 Mustache = brackets . getModule ( "thirdparty/mustache/mustache" ) ;
1112
1213 // Local modules
@@ -205,7 +206,18 @@ define(function (require) {
205206 if ( doc ) {
206207 lastDocumentSeen = doc ;
207208 }
208- return doc || lastDocumentSeen ;
209+ // no fallback to lastDocumentSeen here: when no document is open, file
210+ // history must not stick to a file the user has already closed
211+ return doc ;
212+ }
213+
214+ function _showFileHistoryToast ( message ) {
215+ NotificationUI . createToastFromTemplate ( Strings . GIT_SHOW_FILE_HISTORY ,
216+ "<div>" + _ . escape ( message ) + "</div>" , {
217+ toastStyle : NotificationUI . NOTIFICATION_STYLES_CSS_CLASS . INFO ,
218+ autoCloseTimeS : 15 ,
219+ instantOpen : true
220+ } ) ;
209221 }
210222
211223 function handleFileChange ( ) {
@@ -251,10 +263,15 @@ define(function (require) {
251263 }
252264
253265 if ( historyEnabled && newHistoryMode === "FILE" ) {
254- if ( doc ) {
266+ if ( doc && doc . file ) {
255267 file = { } ;
256268 file . absolute = doc . file . fullPath ;
257269 file . relative = FileUtils . getRelativeFilename ( Preferences . get ( "currentGitRoot" ) , file . absolute ) ;
270+ if ( ! file . relative ) {
271+ // the file is not inside the repository, so it has no history
272+ historyEnabled = false ;
273+ file = null ;
274+ }
258275 } else {
259276 // we want a file history but no file was found
260277 historyEnabled = false ;
@@ -315,8 +332,17 @@ define(function (require) {
315332 $historyList = $ ( ) ;
316333 } ) ;
317334 EventEmitter . on ( Events . HISTORY_SHOW_FILE , function ( ) {
318- handleToggleHistory ( "FILE" ) ;
319335 Metrics . countEvent ( Metrics . EVENT_TYPE . GIT , 'panel' , "fileHistory" ) ;
336+ const doc = getCurrentDocument ( ) ;
337+ if ( ! doc || ! doc . file ) {
338+ _showFileHistoryToast ( Strings . GIT_FILE_HISTORY_OPEN_A_FILE ) ;
339+ return ;
340+ }
341+ if ( ! FileUtils . getRelativeFilename ( Preferences . get ( "currentGitRoot" ) , doc . file . fullPath ) ) {
342+ _showFileHistoryToast ( Strings . GIT_FILE_HISTORY_NOT_IN_REPO ) ;
343+ return ;
344+ }
345+ handleToggleHistory ( "FILE" ) ;
320346 } ) ;
321347 EventEmitter . on ( Events . HISTORY_SHOW_GLOBAL , function ( ) {
322348 handleToggleHistory ( "GLOBAL" ) ;
0 commit comments