summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/user_preference.rb13
-rw-r--r--app/views/users/_preferences.html.erb1
-rw-r--r--config/locales/en.yml1
-rw-r--r--lib/redmine/wiki_formatting/markdown/helper.rb4
-rw-r--r--lib/redmine/wiki_formatting/textile/helper.rb4
-rw-r--r--public/javascripts/jstoolbar/jstoolbar.js2
-rw-r--r--test/integration/layout_test.rb1
-rw-r--r--test/unit/user_preference_test.rb7
8 files changed, 29 insertions, 4 deletions
diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb
index 597ac9c90..3f0d9743c 100644
--- a/app/models/user_preference.rb
+++ b/app/models/user_preference.rb
@@ -35,9 +35,11 @@ class UserPreference < ActiveRecord::Base
'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
@@ -98,6 +100,15 @@ class UserPreference < ActiveRecord::Base
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
diff --git a/app/views/users/_preferences.html.erb b/app/views/users/_preferences.html.erb
index 6397c3a38..3734c3064 100644
--- a/app/views/users/_preferences.html.erb
+++ b/app/views/users/_preferences.html.erb
@@ -6,4 +6,5 @@
<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 %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 031c7ba87..3df365c09 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -389,6 +389,7 @@ en:
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
diff --git a/lib/redmine/wiki_formatting/markdown/helper.rb b/lib/redmine/wiki_formatting/markdown/helper.rb
index 6b5a1dfc3..aafa90e3c 100644
--- a/lib/redmine/wiki_formatting/markdown/helper.rb
+++ b/lib/redmine/wiki_formatting/markdown/helper.rb
@@ -33,11 +33,13 @@ module Redmine
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
diff --git a/lib/redmine/wiki_formatting/textile/helper.rb b/lib/redmine/wiki_formatting/textile/helper.rb
index e3865fca5..9b45fd388 100644
--- a/lib/redmine/wiki_formatting/textile/helper.rb
+++ b/lib/redmine/wiki_formatting/textile/helper.rb
@@ -34,11 +34,13 @@ module Redmine
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
diff --git a/public/javascripts/jstoolbar/jstoolbar.js b/public/javascripts/jstoolbar/jstoolbar.js
index dccff9952..4f5ab7306 100644
--- a/public/javascripts/jstoolbar/jstoolbar.js
+++ b/public/javascripts/jstoolbar/jstoolbar.js
@@ -453,7 +453,7 @@ jsToolBar.prototype.resizeDragStop = function(event) {
/* 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(){
diff --git a/test/integration/layout_test.rb b/test/integration/layout_test.rb
index 7b5e9325f..f152251d5 100644
--- a/test/integration/layout_test.rb
+++ b/test/integration/layout_test.rb
@@ -66,6 +66,7 @@ class LayoutTest < Redmine::IntegrationTest
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
diff --git a/test/unit/user_preference_test.rb b/test/unit/user_preference_test.rb
index 8eb3490d8..cc6c5d48c 100644
--- a/test/unit/user_preference_test.rb
+++ b/test/unit/user_preference_test.rb
@@ -110,4 +110,11 @@ class UserPreferenceTest < ActiveSupport::TestCase
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