Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Combine jdiel's "language switching" pull request with tvoliter's templatization of index.html using mustache #1358

Merged
merged 20 commits into from
Aug 14, 2012
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "src/thirdparty/smart-auto-complete"]
path = src/thirdparty/smart-auto-complete
url = https://github.com/laktek/jQuery-Smart-Auto-Complete.git
[submodule "src/thirdparty/mustache"]
path = src/thirdparty/mustache
url = https://github.com/janl/mustache.js.git
13 changes: 11 additions & 2 deletions src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@

require.config({
paths: {
"text" : "thirdparty/text"
}
"text" : "thirdparty/text",
"i18n" : "thirdparty/i18n"
},
// store the locale in localStorage until CEF sets the correct navigator.language
locale: window.localStorage.getItem("locale")
});

/**
Expand All @@ -50,6 +53,12 @@ define(function (require, exports, module) {
require("thirdparty/path-utils/path-utils.min");
require("thirdparty/smart-auto-complete/jquery.smart_autocomplete");

// Note: the htmlContentLoad module renders all of html in Bracktes
// If a module depends on the DOM being fulling formed before it is loaded
// then the module must require htmlContentLoad so that it is loaded after
// htmlContentLoad
require("htmlContent/htmlContentLoad");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have seen this sooner, but do we need a completely separate module anymore? htmlContentLoad.js won't be reused anywhere else. It seems like we could inline the Mustache.render() call inside _onReady() in brackets.js.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can make this change, then $(brackets).trigger("htmlContentLoadComplete"); would immediately follow Mustache.render(). I think that would be a cleaner approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I removed that module and moved the functionality to brackets.js

Now SidebarView.js and ProjectManager.js listen for the htmlContentLoadComplete event since they both init jquery vars on load.

From: Jason San Jose [mailto:notifications@github.com]
Sent: Tuesday, August 14, 2012 10:33 AM
To: adobe/brackets
Cc: Ty Voliter
Subject: Re: [brackets] Combine jdiel's "language switching" pull request with tvoliter's templatization of index.html using mustache (#1358)

In src/brackets.js:

@@ -50,6 +57,12 @@ define(function (require, exports, module) {

 require("thirdparty/path-utils/path-utils.min");

 require("thirdparty/smart-auto-complete/jquery.smart_autocomplete");
  • // Load HTML Content
  • // The htmlContentLoad module renders all of html in Bracktes.
  • // If a module depends on the DOM being fulling formed before it is loaded
  • // then the module should listen for the event "htmlContentLoadComplete"
  • require("htmlContent/htmlContentLoad");

Should have seen this sooner, but do we need a completely separate module anymore? htmlContentLoad.js won't be reused anywhere else. It seems like we could inline the Mustache.render() call inside _onReady() in brackets.js.


Reply to this email directly or view it on GitHubhttps://github.com//pull/1358/files#r1374771.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

From: Jason San Jose [mailto:notifications@github.com]
Sent: Tuesday, August 14, 2012 10:34 AM
To: adobe/brackets
Cc: Ty Voliter
Subject: Re: [brackets] Combine jdiel's "language switching" pull request with tvoliter's templatization of index.html using mustache (#1358)

In src/brackets.js:

@@ -50,6 +57,12 @@ define(function (require, exports, module) {

 require("thirdparty/path-utils/path-utils.min");

 require("thirdparty/smart-auto-complete/jquery.smart_autocomplete");
  • // Load HTML Content
  • // The htmlContentLoad module renders all of html in Bracktes.
  • // If a module depends on the DOM being fulling formed before it is loaded
  • // then the module should listen for the event "htmlContentLoadComplete"
  • require("htmlContent/htmlContentLoad");

If we can make this change, then $(brackets).trigger("htmlContentLoadComplete"); would immediately follow Mustache.render(). I think that would be a cleaner approach.


Reply to this email directly or view it on GitHubhttps://github.com//pull/1358/files#r1374784.


// Load LiveDeveopment
require("LiveDevelopment/main");

Expand Down
1 change: 1 addition & 0 deletions src/command/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ define(function (require, exports, module) {
exports.DEBUG_RUN_UNIT_TESTS = "debug.runUnitTests";
exports.DEBUG_SHOW_PERF_DATA = "debug.showPerfData";
exports.DEBUG_NEW_BRACKETS_WINDOW = "debug.newBracketsWindow";
exports.DEBUG_SWITCH_LANGUAGE = "debug.switchLanguage";

// Command that does nothing. Can be used for place holder menuItems

Expand Down
2 changes: 2 additions & 0 deletions src/command/Menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,8 @@ define(function (require, exports, module) {
{key: "Cmd-R", platform: "mac"}]);
menu.addMenuItem(Commands.DEBUG_NEW_BRACKETS_WINDOW);
menu.addMenuDivider();
menu.addMenuItem(Commands.DEBUG_SWITCH_LANGUAGE);
menu.addMenuDivider();
menu.addMenuItem(Commands.DEBUG_RUN_UNIT_TESTS);
menu.addMenuItem(Commands.DEBUG_SHOW_PERF_DATA);

Expand Down
92 changes: 91 additions & 1 deletion src/debug/DebugCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ define(function (require, exports, module) {
Editor = require("editor/Editor").Editor,
Strings = require("strings"),
PerfUtils = require("utils/PerfUtils"),
NativeApp = require("utils/NativeApp");
NativeApp = require("utils/NativeApp"),
NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem,
FileUtils = require("file/FileUtils");

function handleShowDeveloperTools(commandData) {
brackets.app.showDeveloperTools();
Expand Down Expand Up @@ -130,6 +132,93 @@ define(function (require, exports, module) {
function _handleNewBracketsWindow() {
window.open(window.location.href);
}

function _handleSwitchLanguage() {
var stringsPath = FileUtils.getNativeBracketsDirectoryPath() + "/nls";
NativeFileSystem.requestNativeFileSystem(stringsPath, function (dirEntry) {
dirEntry.createReader().readEntries(function (entries) {

var $activeLanguage;
var $submit;
function setLanguage(event) {
if ($activeLanguage) {
$activeLanguage.css("font-weight", "normal");
}
$activeLanguage = $(event.currentTarget);
$activeLanguage.css("font-weight", "bold");
$submit.attr("disabled", false);
}

var $modal = $("<div class='modal hide' />");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll file a general issue to move blocks such as this one into a template.


var $header = $("<div class='modal-header' />")
.append("<a href='#' class='close'>&times;</a>")
.append("<h1 class='dialog-title'>" + Strings.LANGUAGE_TITLE + "</h1>")
.appendTo($modal);

var $body = $("<div class='modal-body' style='max-height: 500px; overflow: auto;' />")
.appendTo($modal);

var $p = $("<p class='dialog-message'>")
.text(Strings.LANGUAGE_MESSAGE)
.appendTo($body);

var $ul = $("<ul>")
.on("click", "li", setLanguage)
.appendTo($p);

// add english
var $li = $("<li>")
.text("en-EN")
.data("locale", "en-EN")
.appendTo($ul);

// inspect all children of dirEntry
entries.forEach(function (entry) {
if (entry.isDirectory && entry.name.match(/^[a-z]{2}-[A-Z]{2}$/)) {
var language = entry.name;
var $li = $("<li>")
.text(entry.name)
.data("locale", language)
.appendTo($ul);
}
});

var $footer = $("<div class='modal-footer' />")
.appendTo($modal);

var $cancel = $("<button class='dialog-button btn left'>")
.on("click", function () {
$modal.modal('hide');
})
.text(Strings.LANGUAGE_CANCEL)
.appendTo($footer);

$submit = $("<button class='dialog-button btn primary'>")
.text(Strings.LANGUAGE_SUBMIT)
.on("click", function () {
if (!$activeLanguage) {
return;
}
var locale = $activeLanguage.data("locale");
window.localStorage.setItem("locale", locale);
CommandManager.execute(Commands.DEBUG_REFRESH_WINDOW);
})
.attr("disabled", "disabled")
.appendTo($footer);

$modal
.appendTo(window.document.body)
.modal({
backdrop: "static",
show: true
})
.on("hidden", function () {
$(this).remove();
});
});
});
}

/* Register all the command handlers */

Expand All @@ -139,6 +228,7 @@ define(function (require, exports, module) {
CommandManager.register(Strings.CMD_NEW_BRACKETS_WINDOW, Commands.DEBUG_NEW_BRACKETS_WINDOW, _handleNewBracketsWindow);
CommandManager.register(Strings.CMD_RUN_UNIT_TESTS, Commands.DEBUG_RUN_UNIT_TESTS, _handleRunUnitTests);
CommandManager.register(Strings.CMD_SHOW_PERF_DATA, Commands.DEBUG_SHOW_PERF_DATA, _handleShowPerfData);
CommandManager.register(Strings.CMD_SWITCH_LANGUAGE, Commands.DEBUG_SWITCH_LANGUAGE, _handleSwitchLanguage);

CommandManager.register(Strings.CMD_USE_TAB_CHARS, Commands.TOGGLE_USE_TAB_CHARS, _handleUseTabChars)
.setChecked(Editor.getUseTabChar());
Expand Down
37 changes: 37 additions & 0 deletions src/htmlContent/htmlContentLoad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global require, define, brackets: true, $, Mustache */

define(function (require, exports, module) {
"use strict";

// Load dependent non-module scripts
var Strings = require("strings"),
rootView = require("text!htmlContent/main-view.html");

$('body').html(Mustache.render(rootView, Strings));

});
Loading