@@ -261,7 +261,7 @@ define(function (require, exports, module) {
261261 var file = FileSystem . getFileForPath ( fullPath ) ;
262262 file . exists ( function ( fileError , fileExists ) {
263263 if ( fileExists ) {
264- EditorManager . showCustomViewer ( viewProvider , fullPath ) ;
264+ EditorManager . _showCustomViewer ( viewProvider , fullPath ) ;
265265 result . resolve ( ) ;
266266 } else {
267267 fileError = fileError || FileSystemError . NOT_FOUND ;
@@ -750,31 +750,39 @@ define(function (require, exports, module) {
750750 return ;
751751 }
752752
753+ doc . isSaving = true ; // mark that we're saving the document
754+
753755 // First, write document's current text to new file
754756 newFile = FileSystem . getFileForPath ( path ) ;
755757
756758 // Save as warns you when you're about to overwrite a file, so we
757759 // explictly allow "blind" writes to the filesystem in this case,
758760 // ignoring warnings about the contents being modified outside of
759761 // the editor.
760- FileUtils . writeText ( newFile , doc . getText ( ) , true ) . done ( function ( ) {
761- // If there were unsaved changes before Save As, they don't stay with the old
762- // file anymore - so must revert the old doc to match disk content.
763- // Only do this if the doc was dirty: doRevert on a file that is not dirty and
764- // not in the working set has the side effect of adding it to the working set.
765- if ( doc . isDirty && ! ( doc . isUntitled ( ) ) ) {
766- // if the file is dirty it must be in the working set
767- // doRevert is side effect free in this case
768- doRevert ( doc ) . always ( openNewFile ) ;
769- } else {
770- openNewFile ( ) ;
771- }
772- } ) . fail ( function ( error ) {
773- _showSaveFileError ( error , path )
774- . done ( function ( ) {
775- result . reject ( error ) ;
776- } ) ;
777- } ) ;
762+ FileUtils . writeText ( newFile , doc . getText ( ) , true )
763+ . done ( function ( ) {
764+ // If there were unsaved changes before Save As, they don't stay with the old
765+ // file anymore - so must revert the old doc to match disk content.
766+ // Only do this if the doc was dirty: doRevert on a file that is not dirty and
767+ // not in the working set has the side effect of adding it to the working set.
768+ if ( doc . isDirty && ! ( doc . isUntitled ( ) ) ) {
769+ // if the file is dirty it must be in the working set
770+ // doRevert is side effect free in this case
771+ doRevert ( doc ) . always ( openNewFile ) ;
772+ } else {
773+ openNewFile ( ) ;
774+ }
775+ } )
776+ . fail ( function ( error ) {
777+ _showSaveFileError ( error , path )
778+ . done ( function ( ) {
779+ result . reject ( error ) ;
780+ } ) ;
781+ } )
782+ . always ( function ( ) {
783+ // mark that we're done saving the document
784+ doc . isSaving = false ;
785+ } ) ;
778786 }
779787
780788 if ( doc ) {
@@ -823,7 +831,7 @@ define(function (require, exports, module) {
823831 doc = ( commandData && commandData . doc ) || activeDoc ,
824832 settings ;
825833
826- if ( doc ) {
834+ if ( doc && ! doc . isSaving ) {
827835 if ( doc . isUntitled ( ) ) {
828836 if ( doc === activeDoc ) {
829837 settings = {
@@ -983,7 +991,7 @@ define(function (require, exports, module) {
983991 result . resolve ( ) ;
984992 } ) ;
985993 } else {
986- EditorManager . closeCustomViewer ( ) ;
994+ EditorManager . _closeCustomViewer ( ) ;
987995 result . resolve ( ) ;
988996 }
989997 }
@@ -1194,15 +1202,15 @@ define(function (require, exports, module) {
11941202 return _closeList ( DocumentManager . getWorkingSet ( ) ,
11951203 ( commandData && commandData . promptOnly ) , true ) . done ( function ( ) {
11961204 if ( ! DocumentManager . getCurrentDocument ( ) ) {
1197- EditorManager . closeCustomViewer ( ) ;
1205+ EditorManager . _closeCustomViewer ( ) ;
11981206 }
11991207 } ) ;
12001208 }
12011209
12021210 function handleFileCloseList ( commandData ) {
12031211 return _closeList ( commandData . fileList , false , false ) . done ( function ( ) {
12041212 if ( ! DocumentManager . getCurrentDocument ( ) ) {
1205- EditorManager . closeCustomViewer ( ) ;
1213+ EditorManager . _closeCustomViewer ( ) ;
12061214 }
12071215 } ) ;
12081216 }
@@ -1466,6 +1474,12 @@ define(function (require, exports, module) {
14661474 Menus . removeMenu ( key ) ;
14671475 } ) ;
14681476
1477+ // If there's a fragment in both URLs, setting location.href won't actually reload
1478+ var fragment = href . indexOf ( "#" ) ;
1479+ if ( fragment !== - 1 ) {
1480+ href = href . substr ( 0 , fragment ) ;
1481+ }
1482+
14691483 window . location . href = href ;
14701484 } ) ;
14711485 } ) . fail ( function ( ) {
@@ -1560,9 +1574,6 @@ define(function (require, exports, module) {
15601574 // Register global commands
15611575 CommandManager . register ( Strings . CMD_FILE_OPEN , Commands . FILE_OPEN , handleFileOpen ) ;
15621576 CommandManager . register ( Strings . CMD_ADD_TO_WORKING_SET , Commands . FILE_ADD_TO_WORKING_SET , handleFileAddToWorkingSet ) ;
1563- // TODO: (issue #274) For now, hook up File > New to the "new in project" handler. Eventually
1564- // File > New should open a new blank tab, and handleFileNewInProject should
1565- // be called from a "+" button in the project
15661577 CommandManager . register ( Strings . CMD_FILE_NEW_UNTITLED , Commands . FILE_NEW_UNTITLED , handleFileNew ) ;
15671578 CommandManager . register ( Strings . CMD_FILE_NEW , Commands . FILE_NEW , handleFileNewInProject ) ;
15681579 CommandManager . register ( Strings . CMD_FILE_NEW_FOLDER , Commands . FILE_NEW_FOLDER , handleNewFolderInProject ) ;
0 commit comments