Skip to content

Commit c8c25d8

Browse files
version 0.0.1
0 parents  commit c8c25d8

15 files changed

+212
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Davide Giacometti
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Redmine Shortcuts
2+
Simple Redmine plugin that provides keyboard shortcuts.
3+
4+
On issues index
5+
* **N** new issue
6+
7+
On issue show
8+
* **C** copy
9+
* **D** delete
10+
* **E** edit
11+
* **L** log time
12+
* **Q** quote
13+
* **U** unwatch
14+
* **W** watch
15+
16+
On editor
17+
* **CTRL + B** strong
18+
* **CTRL + I** italic
19+
* **CTRL + S** deleted
20+
* **CTRL + U** underline (textile only)
21+
22+
## Supported versions
23+
The plugin has been developed and tested on Redmine 3.4.x but should also works on previous versions.
24+
Any feedback will be appreciated.
25+
26+
## Installation
27+
Just download the latest release of this plugin and extract in #{RAILS_ROOT}/plugins, no migrations or gem installation required. Restart Redmine.
28+
29+
## License
30+
Released under the MIT License.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<% if Setting.plugin_redmine_shortcuts['enable_issue_shortcuts'] == '1' %>
2+
<%= javascript_include_tag 'view_issues_index_bottom', :plugin => 'redmine_shortcuts' %>
3+
<% end %>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<% if Setting.plugin_redmine_shortcuts['enable_issue_shortcuts'] == '1' %>
2+
<%= javascript_include_tag 'view_issues_show_details_bottom', :plugin => 'redmine_shortcuts' %>
3+
<% end %>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<% if Setting.plugin_redmine_shortcuts['enable_editor_shortcuts'] == '1' %>
2+
<% if Setting['text_formatting'] == 'textile' %>
3+
<%= javascript_include_tag 'view_layouts_base_body_bottom_textile', :plugin => 'redmine_shortcuts' %>
4+
<% elsif Setting['text_formatting'] == 'markdown' %>
5+
<%= javascript_include_tag 'view_layouts_base_body_bottom_markdown', :plugin => 'redmine_shortcuts' %>
6+
<% end %>
7+
<% end %>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<table>
2+
<tbody>
3+
<tr>
4+
<th>Enable issue shortcuts</th>
5+
<td>
6+
<%= check_box_tag("settings[enable_issue_shortcuts]", "1", @settings['enable_issue_shortcuts'].to_s == "1" ) %>
7+
</td>
8+
</tr>
9+
<tr>
10+
<th>Enable editor shortcuts</th>
11+
<td>
12+
<%= check_box_tag("settings[enable_editor_shortcuts]", "1", @settings['enable_editor_shortcuts'].to_s == "1" ) %>
13+
</td>
14+
</tr>
15+
</tbody>
16+
</table>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
$(document).keydown(function(e) {
2+
if(!$(':focus').is('input') && !$(':focus').is('select') && !$(':focus').is('textarea')) {
3+
// N
4+
if(e.keyCode == 78) {
5+
$(location).attr('href', $('.icon-add').attr('href'));
6+
e.preventDefault();
7+
} // if
8+
} // if
9+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
$(document).keydown(function(e) {
2+
if(!$(':focus').is('input') && !$(':focus').is('select') && !$(':focus').is('textarea')) {
3+
// C
4+
if(e.keyCode == 67) {
5+
$(location).attr('href', $('.icon-copy').attr('href'));
6+
e.preventDefault();
7+
// D
8+
} else if(e.keyCode == 68) {
9+
$('.icon-del').first().trigger('click');
10+
e.preventDefault();
11+
// E
12+
} else if(e.keyCode == 69) {
13+
$('.icon-edit').first().trigger('click');
14+
e.preventDefault();
15+
// L
16+
} else if(e.keyCode == 76) {
17+
$(location).attr('href', $('.icon-time-add').attr('href'));
18+
e.preventDefault();
19+
// W
20+
} else if(e.keyCode == 87) {
21+
$('.icon-fav-off').first().trigger('click');
22+
e.preventDefault();
23+
// U
24+
} else if(e.keyCode == 85) {
25+
$('.icon-fav').first().trigger('click');
26+
e.preventDefault();
27+
// Q
28+
} else if(e.keyCode == 81) {
29+
$('.icon-comment').first().trigger('click');
30+
e.preventDefault();
31+
} // if-else
32+
} // if
33+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function styleSelectedText(textarea, string) {
2+
$start = textarea.prop('selectionStart');
3+
$end = textarea.prop('selectionEnd');
4+
$content = textarea.val();
5+
$content = $content.slice(0, $start) + string + $content.slice($start, $end) + string + $content.slice($end, $content.length);
6+
textarea.val($content);
7+
textarea.focus();
8+
} // styleSelectedText
9+
10+
$(document).keydown(function(e) {
11+
if($(document.activeElement).hasClass('wiki-edit')) {
12+
// CTRL + B
13+
if(e.ctrlKey && e.keyCode == 66) {
14+
styleSelectedText($(document.activeElement), '**')
15+
e.preventDefault();
16+
// CTRL + S
17+
} else if(e.ctrlKey && e.keyCode == 83) {
18+
styleSelectedText($(document.activeElement), '~~')
19+
e.preventDefault();
20+
// CTRL + I
21+
} else if(e.ctrlKey && e.keyCode == 73) {
22+
styleSelectedText($(document.activeElement), '*')
23+
e.preventDefault();
24+
} // if
25+
} // if
26+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function styleSelectedText(textarea, string) {
2+
$start = textarea.prop('selectionStart');
3+
$end = textarea.prop('selectionEnd');
4+
$content = textarea.val();
5+
$content = $content.slice(0, $start) + string + $content.slice($start, $end) + string + $content.slice($end, $content.length);
6+
textarea.val($content);
7+
textarea.focus();
8+
} // styleSelectedText
9+
10+
$(document).keydown(function(e) {
11+
if($(document.activeElement).hasClass('wiki-edit')) {
12+
// CTRL + B
13+
if(e.ctrlKey && e.keyCode == 66) {
14+
styleSelectedText($(document.activeElement), '*')
15+
e.preventDefault();
16+
// CTRL + S
17+
} else if(e.ctrlKey && e.keyCode == 83) {
18+
styleSelectedText($(document.activeElement), '-')
19+
e.preventDefault();
20+
// CTRL + U
21+
} else if(e.ctrlKey && e.keyCode == 85) {
22+
styleSelectedText($(document.activeElement), '+')
23+
e.preventDefault();
24+
// CTRL + I
25+
} else if(e.ctrlKey && e.keyCode == 73) {
26+
styleSelectedText($(document.activeElement), '_')
27+
e.preventDefault();
28+
} // if
29+
} // if
30+
});

config/locales/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# English strings go here for Rails i18n
2+
en:
3+
# my_label: "My label"

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Plugin's routes
2+
# See: http://guides.rubyonrails.org/routing.html

init.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'redmine_shortcuts/hooks/hooks'
2+
3+
Redmine::Plugin.register :redmine_shortcuts do
4+
name 'Redmine Shortcuts'
5+
author 'Davide Giacometti'
6+
description 'Provides useful keyboard shortcuts'
7+
version '0.0.1'
8+
url 'https://github.com/davidegiacometti/redmine_shortcuts'
9+
author_url 'https://github.com/davidegiacometti'
10+
11+
settings :partial => 'settings/redmine_shortcuts', :default => {'enable_issue_shortcuts' => '1', 'enable_editor_shortcuts' => '1'}
12+
end

lib/redmine_shortcuts/hooks/hooks.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module RedmineShortcuts
2+
class Hooks < Redmine::Hook::ViewListener
3+
def view_layouts_base_body_bottom(context = {})
4+
context[:controller].send(:render_to_string, { partial: 'hooks/view_layouts_base_body_bottom', locals: context })
5+
end
6+
7+
def view_issues_show_details_bottom(context = {})
8+
context[:controller].send(:render_to_string, { partial: 'hooks/view_issues_show_details_bottom', locals: context })
9+
end
10+
11+
def view_issues_index_bottom(context = {})
12+
context[:controller].send(:render_to_string, { partial: 'hooks/view_issues_index_bottom', locals: context })
13+
end
14+
end
15+
end

test/test_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Load the Redmine helper
2+
require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper')

0 commit comments

Comments
 (0)