'no_self_notified',
'textarea_font',
'recently_used_projects',
- 'history_default_tab')
+ 'history_default_tab',
+ 'toolbar_language_options')
TEXTAREA_FONT_OPTIONS = ['monospace', 'proportional']
+ DEFAULT_TOOLBAR_LANGUAGE_OPTIONS = %w[c cpp csharp css diff go groovy html java javascript objc perl php python r ruby sass scala shell sql swift xml yaml]
def initialize(attributes=nil, *args)
super
def history_default_tab; self[:history_default_tab]; end
def history_default_tab=(value); self[:history_default_tab]=value; end
+ def toolbar_language_options
+ self[:toolbar_language_options].presence || DEFAULT_TOOLBAR_LANGUAGE_OPTIONS.join(',')
+ end
+
+ def toolbar_language_options=(value)
+ languages = value.to_s.delete(' ').split(',').select{|lang| Redmine::SyntaxHighlighting.language_supported?(lang) }.compact
+ self[:toolbar_language_options] = languages.join(',')
+ end
+
# Returns the names of groups that are displayed on user's page
# Example:
# preferences.my_page_groups
<p><%= pref_fields.select :textarea_font, textarea_font_options %></p>
<p><%= pref_fields.text_field :recently_used_projects, :size => 2 %></p>
<p><%= pref_fields.select :history_default_tab, history_default_tab_options %></p>
+<p><%= pref_fields.text_area :toolbar_language_options, :rows => 4 %></p>
<% end %>
field_recently_used_projects: Number of recently used projects in jump box
field_history_default_tab: Issue's history default tab
field_unique_id: Unique ID
+ field_toolbar_language_options: Code highlighting toolbar languages
setting_app_title: Application title
setting_welcome_text: Welcome text
def heads_for_wiki_formatter
unless @heads_for_wiki_formatter_included
+ toolbar_language_options = User.current && User.current.pref.toolbar_language_options
content_for :header_tags do
javascript_include_tag('jstoolbar/jstoolbar') +
javascript_include_tag('jstoolbar/markdown') +
javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
- javascript_tag("var wikiImageMimeTypes = #{Redmine::MimeType.by_type('image').to_json};") +
+ javascript_tag("var wikiImageMimeTypes = #{Redmine::MimeType.by_type('image').to_json};" +
+ "var userHlLanguages = #{(toolbar_language_options.nil? ? UserPreference::DEFAULT_TOOLBAR_LANGUAGE_OPTIONS : toolbar_language_options.split(',')).to_json};") +
stylesheet_link_tag('jstoolbar')
end
@heads_for_wiki_formatter_included = true
def heads_for_wiki_formatter
unless @heads_for_wiki_formatter_included
+ toolbar_language_options = User.current && User.current.pref.toolbar_language_options
content_for :header_tags do
javascript_include_tag('jstoolbar/jstoolbar') +
javascript_include_tag('jstoolbar/textile') +
javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
- javascript_tag("var wikiImageMimeTypes = #{Redmine::MimeType.by_type('image').to_json};") +
+ javascript_tag("var wikiImageMimeTypes = #{Redmine::MimeType.by_type('image').to_json};" +
+ "var userHlLanguages = #{(toolbar_language_options.nil? ? UserPreference::DEFAULT_TOOLBAR_LANGUAGE_OPTIONS : toolbar_language_options.split(',')).to_json};") +
stylesheet_link_tag('jstoolbar')
end
@heads_for_wiki_formatter_included = true
/* Code highlighting menu */
jsToolBar.prototype.precodeMenu = function(fn){
- var hlLanguages = ["c", "cpp", "csharp", "css", "diff", "go", "groovy", "html", "java", "javascript", "objc", "perl", "php", "python", "r", "ruby", "sass", "scala", "shell", "sql", "swift", "xml", "yaml"];
+ var hlLanguages = window.userHlLanguages;
var menu = $("<ul style='position:absolute;'></ul>");
for (var i = 0; i < hlLanguages.length; i++) {
$("<li></li>").text(hlLanguages[i]).appendTo(menu).mousedown(function(){
get '/projects/ecookbook/issues/new'
assert_select 'head script[src^=?]', '/javascripts/jstoolbar/jstoolbar.js?'
+ assert_include "var userHlLanguages = #{UserPreference::DEFAULT_TOOLBAR_LANGUAGE_OPTIONS.to_json};", response.body
end
def test_calendar_header_tags
up.save!
assert_equal ['documents'], up.my_page_settings.keys
end
+
+ def test_toolbar_language_options_setter_should_remove_except_supported_languages
+ up = User.find(2).pref
+ # bar is not a supported language
+ up.toolbar_language_options = 'ruby,cpp,bar,c'
+ assert_equal 'ruby,cpp,c', up.toolbar_language_options
+ end
end