/** * Destroy the Editor instance for a given mock Document. * @param {!Document} doc */ function destroyMockEditor(doc) { EditorManager._destroyEditorIfUnneeded(doc); // Clear editor holder so EditorManager doesn't try to resize destroyed object EditorManager.setEditorHolder(null); $("#mock-editor-holder").remove(); }
function _onReady() { // Add the platform (mac or win) to the body tag so we can have platform-specific CSS rules $("body").addClass("platform-" + brackets.platform); EditorManager.setEditorHolder($("#editor-holder")); // Let the user know Brackets doesn't run in a web browser yet if (brackets.inBrowser) { Dialogs.showModalDialog( Dialogs.DIALOG_ID_ERROR, Strings.ERROR_BRACKETS_IN_BROWSER_TITLE, Strings.ERROR_BRACKETS_IN_BROWSER ); } _initDragAndDropListeners(); _initCommandHandlers(); KeyBindingManager.init(); Menus.init(); // key bindings should be initialized first _initWindowListeners(); // Read "build number" SHAs off disk at the time the matching Brackets JS code is being loaded, instead // of later, when they may have been updated to a different version BuildInfoUtils.init(); // Use quiet scrollbars if we aren't on Lion. If we're on Lion, only // use native scroll bars when the mouse is not plugged in or when // using the "Always" scroll bar setting. var osxMatch = /Mac OS X 10\D([\d+])\D/.exec(navigator.userAgent); if (osxMatch && osxMatch[1] && Number(osxMatch[1]) >= 7) { // test a scrolling div for scrollbars var $testDiv = $("<div style='position:fixed;left:-50px;width:50px;height:50px;overflow:auto;'><div style='width:100px;height:100px;'/></div>").appendTo(window.document.body); if ($testDiv.outerWidth() === $testDiv.get(0).clientWidth) { $(".sidebar").removeClass("quiet-scrollbars"); } $testDiv.remove(); } PerfUtils.addMeasurement("Application Startup"); // finish UI initialization before loading extensions var initialProjectPath = ProjectManager.getInitialProjectPath(); ProjectManager.openProject(initialProjectPath).done(function () { _initTest(); // WARNING: AppInit.appReady won't fire if ANY extension fails to // load or throws an error during init. To fix this, we need to // make a change to _initExtensions (filed as issue 1029) _initExtensions().always(AppInit._dispatchReady(AppInit.APP_READY)); }); // Check for updates if (!params.get("skipUpdateCheck")) { UpdateNotification.checkForUpdate(); } }
/** * Returns an Editor tied to the given Document, but suitable for use in isolation * (without being placed inside the surrounding Brackets UI). * @return {!Editor} */ function createMockEditorForDocument(doc, visibleRange) { // Initialize EditorManager/PanelManager and position the editor-holder offscreen // (".content" may not exist, but that's ok for headless tests where editor height doesn't matter) var $editorHolder = createMockElement().attr("id", "mock-editor-holder"); PanelManager._setMockDOM($(".content"), $editorHolder); EditorManager.setEditorHolder($editorHolder); // create Editor instance var editor = new Editor(doc, true, $editorHolder.get(0), visibleRange); EditorManager._notifyActiveEditorChanged(editor); return editor; }
/** * Returns a Document and Editor suitable for use with an Editor in * isolation: i.e., a Document that will never be set as the * currentDocument or added to the working set. * @return {!{doc:{Document}, editor:{Editor}}} */ function createMockEditor(initialContent, languageId, visibleRange) { // Initialize EditorManager and position the editor-holder offscreen var $editorHolder = createMockElement().attr("id", "mock-editor-holder"); EditorManager.setEditorHolder($editorHolder); // create dummy Document for the Editor var doc = createMockDocument(initialContent, languageId); // create Editor instance var editor = new Editor(doc, true, $editorHolder.get(0), visibleRange); EditorManager._notifyActiveEditorChanged(editor); return { doc: doc, editor: editor }; }
/** * Returns a Document and Editor suitable for use with an Editor in * isolation: i.e., a Document that will never be set as the * currentDocument or added to the working set. * @return {!{doc:{Document}, editor:{Editor}}} */ function createMockEditor(initialContent, languageId, visibleRange) { // Initialize EditorManager var $editorHolder = $("<div id='mock-editor-holder'/>"); EditorManager.setEditorHolder($editorHolder); EditorManager._init(); $("body").append($editorHolder); // create dummy Document for the Editor var doc = createMockDocument(initialContent, languageId); // create Editor instance var editor = new Editor(doc, true, $editorHolder.get(0), visibleRange); return { doc: doc, editor: editor }; }
/** * Returns a Document and Editor suitable for use with an Editor in * isolation: i.e., a Document that will never be set as the * currentDocument or added to the working set. * @return {!{doc:{Document}, editor:{Editor}}} */ function createMockEditor(initialContent, languageId, visibleRange) { // Initialize EditorManager and position the editor-holder offscreen var $editorHolder = $("<div id='mock-editor-holder'/>") .css({ position: "absolute", left: "-10000px", top: "-10000px" }); EditorManager.setEditorHolder($editorHolder); $("body").append($editorHolder); // create dummy Document for the Editor var doc = createMockDocument(initialContent, languageId); // create Editor instance var editor = new Editor(doc, true, $editorHolder.get(0), visibleRange); EditorManager._notifyActiveEditorChanged(editor); return { doc: doc, editor: editor }; }
function _onReady() { PerfUtils.addMeasurement("window.document Ready"); EditorManager.setEditorHolder($("#editor-holder")); // Let the user know Brackets doesn't run in a web browser yet if (brackets.inBrowser) { Dialogs.showModalDialog( Dialogs.DIALOG_ID_ERROR, Strings.ERROR_IN_BROWSER_TITLE, Strings.ERROR_IN_BROWSER ); } // Use quiet scrollbars if we aren't on Lion. If we're on Lion, only // use native scroll bars when the mouse is not plugged in or when // using the "Always" scroll bar setting. var osxMatch = /Mac OS X 10\D([\d+])\D/.exec(navigator.userAgent); if (osxMatch && osxMatch[1] && Number(osxMatch[1]) >= 7) { // test a scrolling div for scrollbars var $testDiv = $("<div style='position:fixed;left:-50px;width:50px;height:50px;overflow:auto;'><div style='width:100px;height:100px;'/></div>").appendTo(window.document.body); if ($testDiv.outerWidth() === $testDiv.get(0).clientWidth) { $(".sidebar").removeClass("quiet-scrollbars"); } $testDiv.remove(); } // Load all extensions. This promise will complete even if one or more // extensions fail to load. var extensionLoaderPromise = ExtensionLoader.init(params.get("extensions")); // Load the initial project after extensions have loaded extensionLoaderPromise.always(function () { // Finish UI initialization var initialProjectPath = ProjectManager.getInitialProjectPath(); ProjectManager.openProject(initialProjectPath).always(function () { _initTest(); // If this is the first launch, and we have an index.html file in the project folder (which should be // the samples folder on first launch), open it automatically. (We explicitly check for the // samples folder in case this is the first time we're launching Brackets after upgrading from // an old version that might not have set the "afterFirstLaunch" pref.) var prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID), deferred = new $.Deferred(); if (!params.get("skipSampleProjectLoad") && !prefs.getValue("afterFirstLaunch")) { prefs.setValue("afterFirstLaunch", "true"); if (ProjectManager.isWelcomeProjectPath(initialProjectPath)) { var dirEntry = new NativeFileSystem.DirectoryEntry(initialProjectPath); dirEntry.getFile("index.html", {}, function (fileEntry) { var promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, { fullPath: fileEntry.fullPath }); promise.pipe(deferred.resolve, deferred.reject); }, deferred.reject); } else { deferred.resolve(); } } else { deferred.resolve(); } deferred.always(function () { // Signal that Brackets is loaded AppInit._dispatchReady(AppInit.APP_READY); PerfUtils.addMeasurement("Application Startup"); }); // See if any startup files were passed to the application if (brackets.app.getPendingFilesToOpen) { brackets.app.getPendingFilesToOpen(function (err, files) { files.forEach(function (filename) { CommandManager.execute(Commands.FILE_OPEN, { fullPath: filename }); }); }); } }); }); // Check for updates if (!params.get("skipUpdateCheck") && !brackets.inBrowser) { // check once a day, plus 2 minutes, // as the check will skip if the last check was not -24h ago window.setInterval(UpdateNotification.checkForUpdate, 86520000); UpdateNotification.checkForUpdate(); } }
function _onReady() { // Add the platform (mac or win) to the body tag so we can have platform-specific CSS rules $("body").addClass("platform-" + brackets.platform); EditorManager.setEditorHolder($("#editor-holder")); // Let the user know Brackets doesn't run in a web browser yet if (brackets.inBrowser) { Dialogs.showModalDialog( Dialogs.DIALOG_ID_ERROR, Strings.ERROR_IN_BROWSER_TITLE, Strings.ERROR_IN_BROWSER ); } _initDragAndDropListeners(); _initCommandHandlers(); KeyBindingManager.init(); Menus.init(); // key bindings should be initialized first _initWindowListeners(); // Use quiet scrollbars if we aren't on Lion. If we're on Lion, only // use native scroll bars when the mouse is not plugged in or when // using the "Always" scroll bar setting. var osxMatch = /Mac OS X 10\D([\d+])\D/.exec(navigator.userAgent); if (osxMatch && osxMatch[1] && Number(osxMatch[1]) >= 7) { // test a scrolling div for scrollbars var $testDiv = $("<div style='position:fixed;left:-50px;width:50px;height:50px;overflow:auto;'><div style='width:100px;height:100px;'/></div>").appendTo(window.document.body); if ($testDiv.outerWidth() === $testDiv.get(0).clientWidth) { $(".sidebar").removeClass("quiet-scrollbars"); } $testDiv.remove(); } PerfUtils.addMeasurement("Application Startup"); // finish UI initialization before loading extensions var initialProjectPath = ProjectManager.getInitialProjectPath(); ProjectManager.openProject(initialProjectPath).always(function () { _initTest(); // WARNING: AppInit.appReady won't fire if ANY extension fails to // load or throws an error during init. To fix this, we need to // make a change to _initExtensions (filed as issue 1029) _initExtensions().always(AppInit._dispatchReady(AppInit.APP_READY)); // If this is the first launch, and we have an index.html file in the project folder (which should be // the samples folder on first launch), open it automatically. (We explicitly check for the // samples folder in case this is the first time we're launching Brackets after upgrading from // an old version that might not have set the "afterFirstLaunch" pref.) var prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID); if (!params.get("skipSampleProjectLoad") && !prefs.getValue("afterFirstLaunch")) { prefs.setValue("afterFirstLaunch", "true"); if (ProjectManager.isWelcomeProjectPath(initialProjectPath)) { var dirEntry = new NativeFileSystem.DirectoryEntry(initialProjectPath); dirEntry.getFile("index.html", {}, function (fileEntry) { CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, { fullPath: fileEntry.fullPath }); }); } } }); // Check for updates if (!params.get("skipUpdateCheck")) { UpdateNotification.checkForUpdate(); } }
$(window.document).ready(function () { function initListeners() { // Prevent unhandled drag and drop of files into the browser from replacing // the entire Brackets app. This doesn't prevent children from choosing to // handle drops. $(window.document.body) .on("dragover", function (event) { if (event.originalEvent.dataTransfer.files) { event.stopPropagation(); event.preventDefault(); event.originalEvent.dataTransfer.dropEffect = "none"; } }) .on("drop", function (event) { if (event.originalEvent.dataTransfer.files) { event.stopPropagation(); event.preventDefault(); } }); } function initProject() { ProjectManager.loadProject(); // Open project button $("#btn-open-project").click(function () { CommandManager.execute(Commands.FILE_OPEN_FOLDER); }); } function initCommandHandlers() { // Most command handlers are automatically registered when their module is loaded (see "modules // that self-register" above for some). A few commands need an extra kick here though: DocumentCommandHandlers.init($("#main-toolbar")); CommandManager.register(Commands.HELP_ABOUT, function () { Dialogs.showModalDialog(Dialogs.DIALOG_ID_ABOUT); }); } function initKeyBindings() { // Register keymaps and install the keyboard handler // TODO: (issue #268) show keyboard equivalents in the menus var _globalKeymap = KeyMap.create({ "bindings": [ // FILE {"Ctrl-N": Commands.FILE_NEW}, {"Ctrl-O": Commands.FILE_OPEN}, {"Ctrl-S": Commands.FILE_SAVE}, {"Ctrl-W": Commands.FILE_CLOSE}, {"Ctrl-Alt-P": Commands.FILE_LIVE_FILE_PREVIEW}, {"Ctrl-Q": Commands.FILE_QUIT}, // EDIT // disabled until the menu items are connected to the commands. Keyboard shortcuts work via CodeMirror //{"Ctrl-Z": Commands.EDIT_UNDO}, //{"Ctrl-Y": Commands.EDIT_REDO}, //{"Ctrl-X": Commands.EDIT_CUT}, //{"Ctrl-C": Commands.EDIT_COPY}, //{"Ctrl-V": Commands.EDIT_PASTE}, {"Ctrl-A": Commands.EDIT_SELECT_ALL}, {"Ctrl-F": Commands.EDIT_FIND}, {"Ctrl-Shift-F": Commands.EDIT_FIND_IN_FILES}, {"Ctrl-G": Commands.EDIT_FIND_NEXT, "platform": "mac"}, {"F3": Commands.EDIT_FIND_NEXT, "platform": "win"}, {"Ctrl-Shift-G": Commands.EDIT_FIND_PREVIOUS, "platform": "mac"}, {"Shift-F3": Commands.EDIT_FIND_PREVIOUS, "platform": "win"}, {"Ctrl-Alt-F": Commands.EDIT_REPLACE, "platform": "mac"}, {"Ctrl-H": Commands.EDIT_REPLACE, "platform": "win"}, {"Ctrl-/": Commands.EDIT_LINE_COMMENT}, // VIEW {"Ctrl-Shift-H": Commands.VIEW_HIDE_SIDEBAR}, // Navigate {"Ctrl-Shift-O": Commands.NAVIGATE_QUICK_OPEN}, {"Ctrl-T": Commands.NAVIGATE_GOTO_DEFINITION}, {"Ctrl-L": Commands.NAVIGATE_GOTO_LINE, "platform": "mac"}, {"Ctrl-G": Commands.NAVIGATE_GOTO_LINE, "platform": "win"}, {"Ctrl-E": Commands.SHOW_INLINE_EDITOR}, {"Alt-Up": Commands.QUICK_EDIT_PREV_MATCH}, {"Alt-Down": Commands.QUICK_EDIT_NEXT_MATCH}, // DEBUG {"F5": Commands.DEBUG_REFRESH_WINDOW, "platform": "win"}, {"Ctrl-R": Commands.DEBUG_REFRESH_WINDOW, "platform": "mac"} ], "platform": brackets.platform }); KeyBindingManager.installKeymap(_globalKeymap); window.document.body.addEventListener( "keydown", function (event) { if (KeyBindingManager.handleKey(KeyMap.translateKeyboardEvent(event))) { event.stopPropagation(); } }, true ); } function initWindowListeners() { // TODO: (issue 269) to support IE, need to listen to document instead (and even then it may not work when focus is in an input field?) $(window).focus(function () { FileSyncManager.syncOpenDocuments(); FileIndexManager.markDirty(); }); $(window).contextmenu(function (e) { e.preventDefault(); }); } function initSidebarListeners() { var $sidebar = $(".sidebar"); var sidebarWidth = $sidebar.width(); var isSidebarHidden = false; var sidebarSnappedClosed = false; var startingSidebarPosition = sidebarWidth; $("#sidebar-resizer").css("left", sidebarWidth - 1); $("#sidebar-resizer").on("mousedown.sidebar", function (e) { // check to see if we're currently in hidden mode if (ProjectManager.getSidebarState() === ProjectManager.SIDEBAR_CLOSED) { // when we click, start modifying the sidebar size and then // modify the variables to set the sidebar state correctly. CommandManager.execute(Commands.VIEW_HIDE_SIDEBAR, 1); // this makes sure we don't snap back when we drag from a hidden position sidebarSnappedClosed = true; // this keeps the triangle from jumping around $(".triangleVisible").css("display", "none"); } $(".main-view").on("mousemove.sidebar", function (e) { // if we've gone below 10 pixels on a mouse move, and the // sidebar has not been snapped close, hide the sidebar // automatically an unbind the mouse event. if (e.clientX < 10 && !sidebarSnappedClosed) { CommandManager.execute(Commands.VIEW_HIDE_SIDEBAR, startingSidebarPosition); $("#sidebar-resizer").css("left", 0); $(".main-view").off("mousemove.sidebar"); } else { // if we've moving past 10 pixels, make the triangle visible again // and register that the sidebar is no longer snapped closed. if (e.clientX > 10) { sidebarSnappedClosed = false; $(".triangleVisible").css("display", "block"); } $("#sidebar-resizer").css("left", e.clientX); $sidebar.css("width", e.clientX); // trigger the scroll events to resize shadows and the selectionTriangle $("#project-files-container").trigger("scroll"); $("#open-files-container").trigger("scroll"); // the .sidebarSelection needs to be explicitly set $(".sidebarSelection").width(e.clientX); } EditorManager.resizeEditor(); e.preventDefault(); }); e.preventDefault(); }); $("#sidebar-resizer").on("mouseup.sidebar", function (e) { $(".main-view").off("mousemove.sidebar"); startingSidebarPosition = $sidebar.width(); console.log(startingSidebarPosition); }); } // Add the platform (mac or win) to the body tag so we can have platform-specific CSS rules $("body").addClass("platform-" + brackets.platform); EditorManager.setEditorHolder($('#editorHolder')); // Let the user know Brackets doesn't run in a web browser yet if (brackets.inBrowser) { Dialogs.showModalDialog( Dialogs.DIALOG_ID_ERROR, Strings.ERROR_BRACKETS_IN_BROWSER_TITLE, Strings.ERROR_BRACKETS_IN_BROWSER ); } initListeners(); initProject(); initCommandHandlers(); initKeyBindings(); Menus.init(); // key bindings should be initialized first initWindowListeners(); initSidebarListeners(); // Load extensions // FUTURE (JRB): As we get more fine-grained performance measurement, move this out of core application startup // Loading extensions requires creating new require.js contexts, which requires access to the global 'require' object // that always gets hidden by the 'require' in the AMD wrapper. We store this in the brackets object here so that // the ExtensionLoader doesn't have to have access to the global object. brackets.libRequire = global.require; // Also store our current require.js context (the one that loads brackets core modules) so that extensions can use it // Note: we change the name to "getModule" because this won't do exactly the same thing as 'require' in AMD-wrapped // modules. The extension will only be able to load modules that have already been loaded once. brackets.getModule = require; ExtensionLoader.loadAllExtensionsInNativeDirectory( FileUtils.getNativeBracketsDirectoryPath() + "/extensions/default", "extensions/default" ); ExtensionLoader.loadAllExtensionsInNativeDirectory( FileUtils.getNativeBracketsDirectoryPath() + "/extensions/user", "extensions/user" ); // Use quiet scrollbars if we aren't on Lion. If we're on Lion, only // use native scroll bars when the mouse is not plugged in or when // using the "Always" scroll bar setting. var osxMatch = /Mac OS X 10\D([\d+])\D/.exec(navigator.userAgent); if (osxMatch && osxMatch[1] && Number(osxMatch[1]) >= 7) { // test a scrolling div for scrollbars var $testDiv = $("<div style='position:fixed;left:-50px;width:50px;height:50px;overflow:auto;'><div style='width:100px;height:100px;'/></div>").appendTo(window.document.body); if ($testDiv.outerWidth() === $testDiv.get(0).clientWidth) { $(".sidebar").removeClass("quiet-scrollbars"); } $testDiv.remove(); } PerfUtils.addMeasurement("Application Startup"); });
/** * Setup Brackets */ function _onReady() { PerfUtils.addMeasurement("window.document Ready"); EditorManager.setEditorHolder($("#editor-holder")); // Let the user know Brackets doesn't run in a web browser yet if (brackets.inBrowser) { Dialogs.showModalDialog( DefaultDialogs.DIALOG_ID_ERROR, Strings.ERROR_IN_BROWSER_TITLE, Strings.ERROR_IN_BROWSER ); } // Use quiet scrollbars if we aren't on Lion. If we're on Lion, only // use native scroll bars when the mouse is not plugged in or when // using the "Always" scroll bar setting. var osxMatch = /Mac OS X 10\D([\d+])\D/.exec(navigator.userAgent); if (osxMatch && osxMatch[1] && Number(osxMatch[1]) >= 7) { // test a scrolling div for scrollbars var $testDiv = $("<div style='position:fixed;left:-50px;width:50px;height:50px;overflow:auto;'><div style='width:100px;height:100px;'/></div>").appendTo(window.document.body); if ($testDiv.outerWidth() === $testDiv.get(0).clientWidth) { $(".sidebar").removeClass("quiet-scrollbars"); } $testDiv.remove(); } // Load default languages and preferences Async.waitForAll([LanguageManager.ready, PreferencesManager.ready]).always(function () { // Load all extensions. This promise will complete even if one or more // extensions fail to load. var extensionPathOverride = params.get("extensions"); // used by unit tests var extensionLoaderPromise = ExtensionLoader.init(extensionPathOverride ? extensionPathOverride.split(",") : null); // Load the initial project after extensions have loaded extensionLoaderPromise.always(function () { // Finish UI initialization ViewCommandHandlers.restoreFontSize(); var initialProjectPath = ProjectManager.getInitialProjectPath(); ProjectManager.openProject(initialProjectPath).always(function () { _initTest(); // If this is the first launch, and we have an index.html file in the project folder (which should be // the samples folder on first launch), open it automatically. (We explicitly check for the // samples folder in case this is the first time we're launching Brackets after upgrading from // an old version that might not have set the "afterFirstLaunch" pref.) var deferred = new $.Deferred(); if (!params.get("skipSampleProjectLoad") && !PreferencesManager.getViewState("afterFirstLaunch")) { PreferencesManager.setViewState("afterFirstLaunch", "true"); if (ProjectManager.isWelcomeProjectPath(initialProjectPath)) { FileSystem.resolve(initialProjectPath + "index.html", function (err, file) { if (!err) { var promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, { fullPath: file.fullPath }); promise.then(deferred.resolve, deferred.reject); } else { deferred.reject(); } }); } else { deferred.resolve(); } } else { deferred.resolve(); } deferred.always(function () { // Signal that Brackets is loaded AppInit._dispatchReady(AppInit.APP_READY); PerfUtils.addMeasurement("Application Startup"); if (PreferencesManager._isUserScopeCorrupt()) { Dialogs.showModalDialog( DefaultDialogs.DIALOG_ID_ERROR, Strings.ERROR_PREFS_CORRUPT_TITLE, Strings.ERROR_PREFS_CORRUPT ) .done(function () { CommandManager.execute(Commands.FILE_OPEN_PREFERENCES); }); } }); // See if any startup files were passed to the application if (brackets.app.getPendingFilesToOpen) { brackets.app.getPendingFilesToOpen(function (err, files) { DragAndDrop.openDroppedFiles(files); }); } }); }); }); // Check for updates if (!params.get("skipUpdateCheck") && !brackets.inBrowser) { AppInit.appReady(function () { // launches periodic checks for updates cca every 24 hours UpdateNotification.launchAutomaticUpdate(); }); } }
$(window.document).ready(function () { function initListeners() { // Prevent unhandled drag and drop of files into the browser from replacing // the entire Brackets app. This doesn't prevent children from choosing to // handle drops. $(window.document.body) .on("dragover", function (event) { if (event.originalEvent.dataTransfer.files) { event.stopPropagation(); event.preventDefault(); event.originalEvent.dataTransfer.dropEffect = "none"; } }) .on("drop", function (event) { if (event.originalEvent.dataTransfer.files) { event.stopPropagation(); event.preventDefault(); } }); } function initCommandHandlers() { // Most command handlers are automatically registered when their module is loaded (see "modules // that self-register" above for some). A few commands need an extra kick here though: DocumentCommandHandlers.init($("#main-toolbar")); // About dialog CommandManager.register(Commands.HELP_ABOUT, function () { // If we've successfully determined a "build number" via .git metadata, add it to dialog var bracketsSHA = BuildInfoUtils.getBracketsSHA(), bracketsAppSHA = BuildInfoUtils.getBracketsAppSHA(), versionLabel = ""; if (bracketsSHA) { versionLabel += " (" + bracketsSHA.substr(0, 7) + ")"; } if (bracketsAppSHA) { versionLabel += " (shell " + bracketsAppSHA.substr(0, 7) + ")"; } $("#about-build-number").text(versionLabel); Dialogs.showModalDialog(Dialogs.DIALOG_ID_ABOUT); }); } function initKeyBindings() { // Register keymaps and install the keyboard handler // TODO: (issue #268) show keyboard equivalents in the menus var _globalKeymap = KeyMap.create({ "bindings": [ // FILE {"Ctrl-N": Commands.FILE_NEW}, {"Ctrl-O": Commands.FILE_OPEN}, {"Ctrl-S": Commands.FILE_SAVE}, {"Ctrl-W": Commands.FILE_CLOSE}, {"Ctrl-Alt-P": Commands.FILE_LIVE_FILE_PREVIEW}, {"Ctrl-Q": Commands.FILE_QUIT}, // EDIT // disabled until the menu items are connected to the commands. Keyboard shortcuts work via CodeMirror //{"Ctrl-Z": Commands.EDIT_UNDO}, //{"Ctrl-Y": Commands.EDIT_REDO}, //{"Ctrl-X": Commands.EDIT_CUT}, //{"Ctrl-C": Commands.EDIT_COPY}, //{"Ctrl-V": Commands.EDIT_PASTE}, {"Ctrl-A": Commands.EDIT_SELECT_ALL}, {"Ctrl-F": Commands.EDIT_FIND}, {"Ctrl-Shift-F": Commands.EDIT_FIND_IN_FILES}, {"Ctrl-G": Commands.EDIT_FIND_NEXT, "platform": "mac"}, {"F3": Commands.EDIT_FIND_NEXT, "platform": "win"}, {"Ctrl-Shift-G": Commands.EDIT_FIND_PREVIOUS, "platform": "mac"}, {"Shift-F3": Commands.EDIT_FIND_PREVIOUS, "platform": "win"}, {"Ctrl-Alt-F": Commands.EDIT_REPLACE, "platform": "mac"}, {"Ctrl-H": Commands.EDIT_REPLACE, "platform": "win"}, {"Ctrl-D": Commands.EDIT_DUPLICATE}, {"Ctrl-/": Commands.EDIT_LINE_COMMENT}, // VIEW {"Ctrl-Shift-H": Commands.VIEW_HIDE_SIDEBAR}, // Navigate {"Ctrl-Shift-O": Commands.NAVIGATE_QUICK_OPEN}, {"Ctrl-T": Commands.NAVIGATE_GOTO_DEFINITION}, {"Ctrl-L": Commands.NAVIGATE_GOTO_LINE, "platform": "mac"}, {"Ctrl-G": Commands.NAVIGATE_GOTO_LINE, "platform": "win"}, {"Ctrl-E": Commands.SHOW_INLINE_EDITOR}, {"Alt-Up": Commands.QUICK_EDIT_PREV_MATCH}, {"Alt-Down": Commands.QUICK_EDIT_NEXT_MATCH}, // DEBUG {"F5": Commands.DEBUG_REFRESH_WINDOW, "platform": "win"}, {"Ctrl-R": Commands.DEBUG_REFRESH_WINDOW, "platform": "mac"} ], "platform": brackets.platform }); KeyBindingManager.installKeymap(_globalKeymap); window.document.body.addEventListener( "keydown", function (event) { if (KeyBindingManager.handleKey(KeyMap.translateKeyboardEvent(event))) { event.stopPropagation(); } }, true ); } function initWindowListeners() { // TODO: (issue 269) to support IE, need to listen to document instead (and even then it may not work when focus is in an input field?) $(window).focus(function () { FileSyncManager.syncOpenDocuments(); FileIndexManager.markDirty(); }); $(window).contextmenu(function (e) { e.preventDefault(); }); } // Add the platform (mac or win) to the body tag so we can have platform-specific CSS rules $("body").addClass("platform-" + brackets.platform); EditorManager.setEditorHolder($('#editor-holder')); // Let the user know Brackets doesn't run in a web browser yet if (brackets.inBrowser) { Dialogs.showModalDialog( Dialogs.DIALOG_ID_ERROR, Strings.ERROR_BRACKETS_IN_BROWSER_TITLE, Strings.ERROR_BRACKETS_IN_BROWSER ); } initListeners(); initCommandHandlers(); initKeyBindings(); Menus.init(); // key bindings should be initialized first initWindowListeners(); // Read "build number" SHAs off disk at the time the matching Brackets JS code is being loaded, instead // of later, when they may have been updated to a different version BuildInfoUtils.init(); // Load extensions // FUTURE (JRB): As we get more fine-grained performance measurement, move this out of core application startup // Loading extensions requires creating new require.js contexts, which requires access to the global 'require' object // that always gets hidden by the 'require' in the AMD wrapper. We store this in the brackets object here so that // the ExtensionLoader doesn't have to have access to the global object. brackets.libRequire = global.require; // Also store our current require.js context (the one that loads brackets core modules) so that extensions can use it // Note: we change the name to "getModule" because this won't do exactly the same thing as 'require' in AMD-wrapped // modules. The extension will only be able to load modules that have already been loaded once. brackets.getModule = require; ExtensionLoader.loadAllExtensionsInNativeDirectory( FileUtils.getNativeBracketsDirectoryPath() + "/extensions/default", "extensions/default" ); ExtensionLoader.loadAllExtensionsInNativeDirectory( FileUtils.getNativeBracketsDirectoryPath() + "/extensions/user", "extensions/user" ); // Use quiet scrollbars if we aren't on Lion. If we're on Lion, only // use native scroll bars when the mouse is not plugged in or when // using the "Always" scroll bar setting. var osxMatch = /Mac OS X 10\D([\d+])\D/.exec(navigator.userAgent); if (osxMatch && osxMatch[1] && Number(osxMatch[1]) >= 7) { // test a scrolling div for scrollbars var $testDiv = $("<div style='position:fixed;left:-50px;width:50px;height:50px;overflow:auto;'><div style='width:100px;height:100px;'/></div>").appendTo(window.document.body); if ($testDiv.outerWidth() === $testDiv.get(0).clientWidth) { $(".sidebar").removeClass("quiet-scrollbars"); } $testDiv.remove(); } PerfUtils.addMeasurement("Application Startup"); ProjectManager.loadProject(); });
function _onReady() { // Add the platform (mac or win) to the body tag so we can have platform-specific CSS rules $("body").addClass("platform-" + brackets.platform); EditorManager.setEditorHolder($("#editor-holder")); // Let the user know Brackets doesn't run in a web browser yet if (brackets.inBrowser) { Dialogs.showModalDialog( Dialogs.DIALOG_ID_ERROR, Strings.ERROR_IN_BROWSER_TITLE, Strings.ERROR_IN_BROWSER ); } _initDragAndDropListeners(); _initCommandHandlers(); KeyBindingManager.init(); Menus.init(); // key bindings should be initialized first _initWindowListeners(); // Use quiet scrollbars if we aren't on Lion. If we're on Lion, only // use native scroll bars when the mouse is not plugged in or when // using the "Always" scroll bar setting. var osxMatch = /Mac OS X 10\D([\d+])\D/.exec(navigator.userAgent); if (osxMatch && osxMatch[1] && Number(osxMatch[1]) >= 7) { // test a scrolling div for scrollbars var $testDiv = $("<div style='position:fixed;left:-50px;width:50px;height:50px;overflow:auto;'><div style='width:100px;height:100px;'/></div>").appendTo(window.document.body); if ($testDiv.outerWidth() === $testDiv.get(0).clientWidth) { $(".sidebar").removeClass("quiet-scrollbars"); } $testDiv.remove(); } // Initialize LiveDevelopment LiveDevelopmentMain.init(); PerfUtils.addMeasurement("Application Startup"); // finish UI initialization before loading extensions var initialProjectPath = ProjectManager.getInitialProjectPath(); ProjectManager.openProject(initialProjectPath).always(function () { _initTest(); // Create a new DirectoryEntry and call getDirectory() on the user extension // directory. If the directory doesn't exist, it will be created. // Note that this is an async call and there are no success or failure functions passed // in. If the directory *doesn't* exist, it will be created. Extension loading may happen // before the directory is finished being created, but that is okay, since the extension // loading will work correctly without this directory. // If the directory *does* exist, nothing else needs to be done. It will be scanned normally // during extension loading. var extensionPath = ExtensionLoader.getUserExtensionPath(); new NativeFileSystem.DirectoryEntry().getDirectory(extensionPath, {create: true}); // Create the extensions/disabled directory, too. var disabledExtensionPath = extensionPath.replace(/\/user$/, "/disabled"); new NativeFileSystem.DirectoryEntry().getDirectory(disabledExtensionPath, {create: true}); // Load all extensions, and when done fire APP_READY (even if some extensions failed // to load or initialize) _initExtensions().always(function () { AppInit._dispatchReady(AppInit.APP_READY); }); // If this is the first launch, and we have an index.html file in the project folder (which should be // the samples folder on first launch), open it automatically. (We explicitly check for the // samples folder in case this is the first time we're launching Brackets after upgrading from // an old version that might not have set the "afterFirstLaunch" pref.) var prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID); if (!params.get("skipSampleProjectLoad") && !prefs.getValue("afterFirstLaunch")) { prefs.setValue("afterFirstLaunch", "true"); if (ProjectManager.isWelcomeProjectPath(initialProjectPath)) { var dirEntry = new NativeFileSystem.DirectoryEntry(initialProjectPath); dirEntry.getFile("index.html", {}, function (fileEntry) { CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, { fullPath: fileEntry.fullPath }); }); } } }); // Check for updates if (!params.get("skipUpdateCheck") && !brackets.inBrowser) { UpdateNotification.checkForUpdate(); } }