redcar 0.7 → 0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +42 -0
- data/README.md +5 -3
- data/Rakefile +39 -81
- data/bin/redcar +1 -1
- data/lib/redcar.rb +9 -6
- data/lib/redcar/installer.rb +1 -1
- data/lib/redcar/ruby_extensions.rb +19 -0
- data/lib/redcar/runner.rb +1 -1
- data/lib/redcar/usage.rb +3 -0
- data/lib/redcar_quick_start.rb +11 -11
- data/plugins/application/features/step_definitions/tree_steps.rb +22 -5
- data/plugins/application/features/step_definitions/window_steps.rb +9 -1
- data/plugins/application/features/support/env.rb +5 -2
- data/plugins/application/lib/application.rb +51 -46
- data/plugins/application/lib/application/window.rb +60 -30
- data/plugins/application_swt/lib/application_swt.rb +16 -16
- data/plugins/application_swt/lib/application_swt/window.rb +35 -7
- data/plugins/auto_completer/features/support/env.rb +0 -2
- data/plugins/auto_indenter/features/support/env.rb +0 -1
- data/plugins/auto_pairer/features/auto_pairer.feature +50 -45
- data/plugins/auto_pairer/features/support/env.rb +0 -1
- data/plugins/auto_pairer/lib/auto_pairer/document_controller.rb +11 -6
- data/plugins/clipboard-viewer/Screenshot.png +0 -0
- data/plugins/clipboard-viewer/lib/clipboard_viewer.rb +50 -0
- data/plugins/clipboard-viewer/lib/clipboard_viewer/browser_controller.rb +27 -0
- data/plugins/clipboard-viewer/lib/clipboard_viewer/clipboard_bar.rb +67 -0
- data/plugins/clipboard-viewer/plugin.rb +9 -0
- data/plugins/clipboard-viewer/views/clipboard.html.erb +15 -0
- data/plugins/clipboard-viewer/views/default.css +43 -0
- data/plugins/clipboard-viewer/views/redcar_small_icon.png +0 -0
- data/plugins/comment/features/line_comment.feature +137 -0
- data/plugins/comment/features/selection_comment.feature +21 -0
- data/plugins/comment/features/step_definitions/comment_steps.rb +7 -0
- data/plugins/comment/lib/comment.rb +266 -0
- data/plugins/comment/plugin.rb +7 -0
- data/plugins/comment/vendor/comment_lib.json +47 -0
- data/plugins/declarations/lib/declarations.rb +1 -1
- data/plugins/document_search/features/replace.feature +10 -2
- data/plugins/document_search/features/support/env.rb +0 -1
- data/plugins/document_search/lib/document_search.rb +4 -1
- data/plugins/document_search/lib/document_search/replace.rb +11 -3
- data/plugins/document_search/lib/document_search/search_and_replace.rb +5 -2
- data/plugins/edit_view/features/case_change.feature +9 -9
- data/plugins/edit_view/features/cursor_navigation.feature +36 -0
- data/plugins/edit_view/features/step_definitions/editing_steps.rb +63 -8
- data/plugins/edit_view/features/step_definitions/notebook_steps.rb +2 -0
- data/plugins/edit_view/features/step_definitions/tab_steps.rb +8 -5
- data/plugins/edit_view/features/support/env.rb +8 -2
- data/plugins/edit_view/lib/edit_view.rb +16 -1
- data/plugins/edit_view/lib/edit_view/actions/cmd_enter.rb +11 -0
- data/plugins/edit_view/lib/edit_view/document.rb +27 -10
- data/plugins/edit_view/lib/edit_view/edit_tab.rb +17 -4
- data/plugins/edit_view/spec/edit_view/document_spec.rb +3 -0
- data/plugins/edit_view_swt/lib/edit_view_swt.rb +42 -3
- data/plugins/edit_view_swt/lib/edit_view_swt/word_movement.rb +17 -15
- data/plugins/help/lib/help.rb +40 -0
- data/plugins/help/plugin.rb +8 -0
- data/plugins/html_view/features/step_definitions/html_view_steps.rb +6 -4
- data/plugins/line_tools/features/support/env.rb +0 -1
- data/plugins/macros/features/step_definitions/macro_steps.rb +0 -55
- data/plugins/macros/features/support/env.rb +0 -2
- data/plugins/open_default_app/lib/open_default_app.rb +35 -0
- data/plugins/open_default_app/plugin.rb +8 -0
- data/plugins/open_default_app/screenshot.png +0 -0
- data/plugins/plugin_manager_ui/lib/plugin_manager_ui.rb +17 -3
- data/plugins/project/features/find_file.feature +3 -2
- data/plugins/project/features/highlight_focussed_tab.feature +8 -0
- data/plugins/project/features/move_and_rename_files.feature +25 -0
- data/plugins/project/features/open_and_save_files.feature +10 -1
- data/plugins/project/features/open_directory_tree.feature +32 -2
- data/plugins/project/features/step_definitions/directory_steps.rb +17 -0
- data/plugins/project/features/step_definitions/project_tree_steps.rb +3 -0
- data/plugins/project/features/sub_project.feature +14 -0
- data/plugins/project/features/support/env.rb +22 -3
- data/plugins/project/features/watch_for_modified_files.feature +32 -9
- data/plugins/project/lib/project.rb +53 -21
- data/plugins/project/lib/project/adapters/local.rb +21 -16
- data/plugins/project/lib/project/adapters/remote.rb +15 -13
- data/plugins/project/lib/project/commands.rb +37 -16
- data/plugins/project/lib/project/dir_controller.rb +41 -42
- data/plugins/project/lib/project/drb_service.rb +35 -21
- data/plugins/project/lib/project/file_list.rb +7 -1
- data/plugins/project/lib/project/manager.rb +28 -3
- data/plugins/project/lib/project/sub_project.rb +17 -0
- data/plugins/project/lib/project/support/recycle.js +2 -0
- data/plugins/project/lib/project/support/trash.rb +72 -0
- data/plugins/project/spec/fixtures/multi-byte-files/a/341/204/200/341/205/247/341/206/274/341/204/205/341/205/251/foo +1 -0
- data/plugins/project/spec/fixtures/multi-byte-files//341/204/220/341/205/246/341/204/211/341/205/263/341/204/220/341/205/263.py +1 -0
- data/plugins/project/spec/project/file_list_spec.rb +4 -0
- data/plugins/redcar/features/goto_line_command.feature +20 -0
- data/plugins/redcar/redcar.rb +107 -47
- data/plugins/repl/lib/repl.rb +20 -20
- data/plugins/repl/lib/repl/clojure_mirror.rb +50 -58
- data/plugins/repl/lib/repl/groovy_mirror.rb +22 -41
- data/plugins/repl/lib/repl/repl_mirror.rb +85 -14
- data/plugins/repl/lib/repl/ruby_mirror.rb +12 -39
- data/plugins/repl/spec/repl/groovy_mirror_spec.rb +1 -1
- data/plugins/repl/spec/repl/ruby_mirror_spec.rb +12 -12
- data/plugins/ruby/README +6 -0
- data/plugins/ruby/lib/syntax_check/ruby.rb +28 -0
- data/plugins/ruby/plugin.rb +7 -0
- data/plugins/runnables/features/command_tree.feature +9 -0
- data/plugins/runnables/features/file_runner_input.feature +20 -0
- data/plugins/runnables/features/run_alternate_command.feature +14 -0
- data/plugins/runnables/features/support/env.rb +42 -5
- data/plugins/runnables/lib/runnables.rb +67 -21
- data/plugins/runnables/lib/runnables/commands.rb +35 -18
- data/plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb +23 -37
- data/plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_type_group.rb +16 -18
- data/plugins/scm_svn/features/support/env.rb +0 -3
- data/plugins/snippets/features/snippets.feature +17 -2
- data/plugins/snippets/features/support/env.rb +0 -1
- data/plugins/snippets/lib/snippets/tab_handler.rb +51 -18
- data/plugins/swt/lib/swt/cucumber_patches.rb +13 -68
- data/plugins/swt/lib/swt/cucumber_runner.rb +2 -3
- data/plugins/syntax_check/README +6 -0
- data/plugins/syntax_check/lib/syntax_check.rb +16 -0
- data/plugins/syntax_check/lib/syntax_check/checker.rb +47 -0
- data/plugins/syntax_check/lib/syntax_check/error.rb +23 -0
- data/plugins/syntax_check/plugin.rb +7 -0
- data/plugins/tree_view_swt/lib/tree_view_swt.rb +6 -0
- data/plugins/web_bookmarks/Screenshot.png +0 -0
- data/plugins/web_bookmarks/lib/web_bookmarks.rb +42 -0
- data/plugins/web_bookmarks/lib/web_bookmarks/bookmark.rb +43 -0
- data/plugins/web_bookmarks/lib/web_bookmarks/browser_bar.rb +70 -0
- data/plugins/web_bookmarks/lib/web_bookmarks/commands.rb +111 -0
- data/plugins/web_bookmarks/lib/web_bookmarks/tree.rb +67 -0
- data/plugins/web_bookmarks/lib/web_bookmarks/view_controller.rb +22 -0
- data/plugins/web_bookmarks/plugin.rb +11 -0
- data/plugins/web_bookmarks/views/index.html.erb +5 -0
- metadata +60 -10
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
<script type="text/javascript" src="file://<%= Redcar::HtmlView.jquery_path %>"></script>
|
|
3
|
+
<% redcar_css = File.expand_path(File.join(Redcar.root, %w(plugins clipboard-viewer views default.css))) %>
|
|
4
|
+
<link rel="stylesheet" href="file://<%= redcar_css %>" type="text/css" media="screen">
|
|
5
|
+
<h1>Clipboard History</h1>
|
|
6
|
+
<div class="content" id="copies">
|
|
7
|
+
<table>
|
|
8
|
+
<thead><th>Recently Copied Text</th></thead>
|
|
9
|
+
<tbody>
|
|
10
|
+
<% @list.each_with_index do |item, i|%>
|
|
11
|
+
<tr><td class="copied-item" id="item_<%=i%>"><pre><%= item.join("").gsub("<", "<").gsub(">", ">") %></pre></td></td>
|
|
12
|
+
<% end %>
|
|
13
|
+
</tbody>
|
|
14
|
+
</table>
|
|
15
|
+
</div>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
body {
|
|
2
|
+
margin:0;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
h1 {
|
|
6
|
+
background: #5f282d url("redcar_small_icon.png") no-repeat 10px 10px;
|
|
7
|
+
color: #dcb663;
|
|
8
|
+
height: 30px;
|
|
9
|
+
line-height: 30px;
|
|
10
|
+
padding: 10px 10px 10px 52px;
|
|
11
|
+
font-family: Palatino, Times, serif;
|
|
12
|
+
letter-spacing: 3px;
|
|
13
|
+
font-size: 100%;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.content {
|
|
17
|
+
margin: 10px;
|
|
18
|
+
font-size: 1.2em;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
td.copied-item pre {
|
|
22
|
+
font-family: monospace;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.refresh {
|
|
26
|
+
padding: 5px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.even {
|
|
30
|
+
background-color: #ddd;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
table {
|
|
34
|
+
font-size: 80%;
|
|
35
|
+
border-collapse: collapse;
|
|
36
|
+
border: 1px solid #888;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
td,th {
|
|
40
|
+
border-collapse: collapse;
|
|
41
|
+
border: 1px solid #888;
|
|
42
|
+
padding: 8px;
|
|
43
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
Feature: Commenting lines by prefixing a comment string
|
|
2
|
+
|
|
3
|
+
Background:
|
|
4
|
+
When I open a new edit tab
|
|
5
|
+
|
|
6
|
+
Scenario: Commenting a single line
|
|
7
|
+
When I replace the contents with "A piece of code"
|
|
8
|
+
And I switch the language to "C"
|
|
9
|
+
And I move the cursor to 5
|
|
10
|
+
And I toggle comment lines
|
|
11
|
+
Then the contents should be "// A pie<c>ce of code"
|
|
12
|
+
When I toggle comment lines
|
|
13
|
+
Then the contents should be "A pie<c>ce of code"
|
|
14
|
+
|
|
15
|
+
Scenario: Uncommenting a single line
|
|
16
|
+
When I replace the contents with "# A piece of code"
|
|
17
|
+
And I switch the language to "Ruby"
|
|
18
|
+
And I move the cursor to 5
|
|
19
|
+
And I toggle comment lines
|
|
20
|
+
Then the contents should be "A p<c>iece of code"
|
|
21
|
+
|
|
22
|
+
Scenario: Commenting a single line among many
|
|
23
|
+
When I replace the contents with "foo\nbar\nbaz"
|
|
24
|
+
And I switch the language to "Ruby"
|
|
25
|
+
And I move the cursor to 4
|
|
26
|
+
And I toggle comment lines
|
|
27
|
+
Then the contents should be "foo\n<c># bar\nbaz"
|
|
28
|
+
When I toggle comment lines
|
|
29
|
+
Then the contents should be "foo\n<c>bar\nbaz"
|
|
30
|
+
|
|
31
|
+
Scenario: Uncommenting a single line that doesn't have the space
|
|
32
|
+
When I replace the contents with "#A piece of code"
|
|
33
|
+
And I switch the language to "Ruby"
|
|
34
|
+
And I move the cursor to 5
|
|
35
|
+
And I toggle comment lines
|
|
36
|
+
Then the contents should be "A piece of code"
|
|
37
|
+
|
|
38
|
+
Scenario: Commenting several lines
|
|
39
|
+
When I replace the contents with "Two pieces\nof code"
|
|
40
|
+
And I switch the language to "Ruby"
|
|
41
|
+
And I select from 0 to 13
|
|
42
|
+
And I toggle comment lines
|
|
43
|
+
Then the contents should be "<s># Two pieces\n# of<c> code"
|
|
44
|
+
When I toggle comment lines
|
|
45
|
+
Then the contents should be "<s>Two pieces\nof<c> code"
|
|
46
|
+
|
|
47
|
+
Scenario: Uncommenting several lines, not all of them have the space
|
|
48
|
+
When I replace the contents with "# Two pieces\n#of code"
|
|
49
|
+
And I switch the language to "Ruby"
|
|
50
|
+
And I select from 0 to 16
|
|
51
|
+
And I toggle comment lines
|
|
52
|
+
Then the contents should be "<s>Two pieces\nof<c> code"
|
|
53
|
+
|
|
54
|
+
Scenario: Commenting when not all the lines begin with the comment symbol
|
|
55
|
+
When I replace the contents with "# foo\n# bar\nbaz"
|
|
56
|
+
And I switch the language to "Ruby"
|
|
57
|
+
And I select from 0 to 15
|
|
58
|
+
And I toggle comment lines
|
|
59
|
+
Then the contents should be "<s># # foo\n# # bar\n# baz<c>"
|
|
60
|
+
When I toggle comment lines
|
|
61
|
+
Then the contents should be "# foo\n# bar\nbaz"
|
|
62
|
+
|
|
63
|
+
Scenario: Commenting a single line with the cursor on the next line
|
|
64
|
+
When I replace the contents with "Two pieces\nof code"
|
|
65
|
+
And I switch the language to "Ruby"
|
|
66
|
+
And I select from 0 to 11
|
|
67
|
+
And I toggle comment lines
|
|
68
|
+
Then the contents should be "<s># Two pieces\n<c>of code"
|
|
69
|
+
When I toggle comment lines
|
|
70
|
+
Then the contents should be "<s>Two pieces\n<c>of code"
|
|
71
|
+
|
|
72
|
+
Scenario: Commenting a single line with the cursor and selection point on the same line
|
|
73
|
+
When I replace the contents with "Two pieces\nof code"
|
|
74
|
+
And I switch the language to "Ruby"
|
|
75
|
+
And I select from 3 to 0
|
|
76
|
+
And I toggle comment lines
|
|
77
|
+
Then the contents should be "<c># Two<s> pieces\nof code"
|
|
78
|
+
When I toggle comment lines
|
|
79
|
+
Then the contents should be "<c>Two<s> pieces\nof code"
|
|
80
|
+
|
|
81
|
+
Scenario: Inserting a single space after comments when a line has no indentation
|
|
82
|
+
When I replace the contents with "A few\nlines\nof unindented\ncode"
|
|
83
|
+
And I switch the language to "Ruby"
|
|
84
|
+
And I select from 2 to 27
|
|
85
|
+
And I toggle comment lines
|
|
86
|
+
Then the contents should be "A <s># few\n# lines\n# of unindented\n# c<c>ode"
|
|
87
|
+
When I toggle comment lines
|
|
88
|
+
Then the contents should be "A <s>few\nlines\nof unindented\nc<c>ode"
|
|
89
|
+
|
|
90
|
+
Scenario: Commenting an indented single line
|
|
91
|
+
When I replace the contents with " A piece of code"
|
|
92
|
+
And I switch the language to "C"
|
|
93
|
+
And I toggle comment lines
|
|
94
|
+
Then the contents should be " // A piece of code"
|
|
95
|
+
When I toggle comment lines
|
|
96
|
+
Then the contents should be " A piece of code"
|
|
97
|
+
|
|
98
|
+
Scenario: Commenting several lines, not from the start of one of them
|
|
99
|
+
When I replace the contents with "Two pieces\nof code"
|
|
100
|
+
And I switch the language to "Ruby"
|
|
101
|
+
And I select from 2 to 13
|
|
102
|
+
And I toggle comment lines
|
|
103
|
+
Then the contents should be "Tw<s># o pieces\n# of<c> code"
|
|
104
|
+
When I toggle comment lines
|
|
105
|
+
Then the contents should be "Tw<s>o pieces\nof<c> code"
|
|
106
|
+
|
|
107
|
+
Scenario: Commenting several lines, not from the start of one of them
|
|
108
|
+
When I replace the contents with " foo\n bar"
|
|
109
|
+
And I switch the language to "Ruby"
|
|
110
|
+
And I select from 2 to 15
|
|
111
|
+
And I toggle comment lines
|
|
112
|
+
Then the contents should be " <s> # foo\n # bar<c>"
|
|
113
|
+
When I toggle comment lines
|
|
114
|
+
Then the contents should be " <s> foo\n bar<c>"
|
|
115
|
+
|
|
116
|
+
Scenario: Commenting several lines, with mismatched indentation, beginning in the start
|
|
117
|
+
When I replace the contents with " def foo\n dfo\n sdfj\n asdf\nasdf"
|
|
118
|
+
And I switch the language to "Ruby"
|
|
119
|
+
And I select from 0 to 40
|
|
120
|
+
And I toggle comment lines
|
|
121
|
+
Then the contents should be "<s># def foo\n# dfo\n# sdfj\n# asdf\n# as<c>df"
|
|
122
|
+
|
|
123
|
+
Scenario: Commenting several indented lines, beginning before the text starts
|
|
124
|
+
When I replace the contents with " def foo\n dfo"
|
|
125
|
+
And I switch the language to "Ruby"
|
|
126
|
+
And I select from 2 to 25
|
|
127
|
+
And I toggle comment lines
|
|
128
|
+
Then the contents should be " <s> # def foo\n # dfo<c>"
|
|
129
|
+
|
|
130
|
+
# This is pretty damn marginal, and I'm tired...
|
|
131
|
+
#Scenario: Commenting several lines, with mismatched indentation, beginning in the middle
|
|
132
|
+
# When I replace the contents with " def foo\n dfo\n sdfj\n asdf\nasdf"
|
|
133
|
+
# And I switch the language to "Ruby"
|
|
134
|
+
# And I select from 6 to 40
|
|
135
|
+
# And I toggle comment lines
|
|
136
|
+
# Then the contents should be " de<s># f foo\n # dfo\n # sdfj\n # asdf\n # as<c>df"
|
|
137
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Feature: Commenting a selected area of text
|
|
2
|
+
|
|
3
|
+
Background:
|
|
4
|
+
When I open a new edit tab
|
|
5
|
+
|
|
6
|
+
Scenario: Commenting a part of a line
|
|
7
|
+
When I replace the contents with "a piece of code"
|
|
8
|
+
And I switch the language to "Java"
|
|
9
|
+
And I toggle block comment
|
|
10
|
+
Then I should see "/*a piece of code*/" in the edit tab
|
|
11
|
+
When I toggle block comment
|
|
12
|
+
Then I should see "a piece of code" in the edit tab
|
|
13
|
+
|
|
14
|
+
Scenario: Commenting a selection spanning several lines
|
|
15
|
+
When I replace the contents with "a piece\nof code"
|
|
16
|
+
And I switch the language to "C++"
|
|
17
|
+
And I select from 4 to 9
|
|
18
|
+
And I toggle block comment
|
|
19
|
+
Then I should see "a pi/*ece\no*/f code" in the edit tab
|
|
20
|
+
And I toggle block comment
|
|
21
|
+
Then I should see "a piece\nof code" in the edit tab
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
|
|
2
|
+
module Redcar
|
|
3
|
+
class Comment
|
|
4
|
+
def self.menus
|
|
5
|
+
Menu::Builder.build do
|
|
6
|
+
sub_menu "Edit" do
|
|
7
|
+
sub_menu "Formatting" do
|
|
8
|
+
item "Toggle Line Comment" , ToggleLineCommentCommand
|
|
9
|
+
item "Toggle Selection Comment", ToggleSelectionCommentCommand
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.storage
|
|
16
|
+
@storage ||=begin
|
|
17
|
+
storage = Plugin::Storage.new('comment_plugin')
|
|
18
|
+
storage.set_default('default_line_comment' , "#")
|
|
19
|
+
storage.set_default('default_start_block' , "/*")
|
|
20
|
+
storage.set_default('default_end_block' , "*/")
|
|
21
|
+
storage.set_default('warning_for_using_defaults' , true)
|
|
22
|
+
storage
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.comment_map
|
|
27
|
+
@map ||=begin
|
|
28
|
+
c = File.read(Comment.comment_lib_path)
|
|
29
|
+
map = JSON.parse(c)
|
|
30
|
+
Comment.comment_extension_paths.each do |path|
|
|
31
|
+
json = File.read(path)
|
|
32
|
+
JSON.parse(json).each do |item,content|
|
|
33
|
+
map[item] = content
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
map
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.extensions_file;"comment_extensions.json";end
|
|
41
|
+
|
|
42
|
+
def self.comment_lib_path
|
|
43
|
+
File.dirname(__FILE__) + "/../vendor/comment_lib.json"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.comment_extension_paths
|
|
47
|
+
project = Redcar::Project::Manager.focussed_project
|
|
48
|
+
if project
|
|
49
|
+
project.config_files(Comment.extensions_file)
|
|
50
|
+
else
|
|
51
|
+
Dir[File.join(Redcar.user_dir,Comment.extensions_file)]
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.keymaps
|
|
56
|
+
osx = Redcar::Keymap.build("main", :osx) do
|
|
57
|
+
link "Cmd+/", ToggleLineCommentCommand
|
|
58
|
+
link "Cmd+.", ToggleSelectionCommentCommand
|
|
59
|
+
end
|
|
60
|
+
linwin = Redcar::Keymap.build("main", [:linux, :windows]) do
|
|
61
|
+
link "Ctrl+/", ToggleLineCommentCommand
|
|
62
|
+
link "Ctrl+.", ToggleSelectionCommentCommand
|
|
63
|
+
end
|
|
64
|
+
[osx, linwin]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def self.grammar_missing(grammar)
|
|
68
|
+
if Comment.storage['warning_for_using_defaults']
|
|
69
|
+
Application::Dialog.message_box("Comment type not found for #{grammar}. Using defaults instead.") unless @messaged
|
|
70
|
+
@messaged = true
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
class ToggleSelectionCommentCommand < Redcar::EditTabCommand
|
|
75
|
+
def execute
|
|
76
|
+
type = Comment.comment_map["#{tab.edit_view.grammar.gsub("\"","")}"]
|
|
77
|
+
if type
|
|
78
|
+
start = type["start_block"]
|
|
79
|
+
ending = type["end_block" ]
|
|
80
|
+
return unless start and ending
|
|
81
|
+
else
|
|
82
|
+
Comment.grammar_missing(tab.edit_view.grammar)
|
|
83
|
+
start = Comment.storage['default_start_block']
|
|
84
|
+
ending = Comment.storage['default_end_block']
|
|
85
|
+
end
|
|
86
|
+
doc.controllers(Redcar::AutoIndenter::DocumentController).first.disable do
|
|
87
|
+
doc.compound do
|
|
88
|
+
if doc.selection?
|
|
89
|
+
text = doc.selected_text
|
|
90
|
+
if text[0,start.split(//).length] == start and
|
|
91
|
+
text[text.split(//).length-ending.split(//).length,text.split(//).length] == ending
|
|
92
|
+
text = text[start.split(//).length,text.split(//).length]
|
|
93
|
+
text = text[0,text.split(//).length-ending.split(//).length]
|
|
94
|
+
doc.replace_selection(text)
|
|
95
|
+
else
|
|
96
|
+
doc.replace_selection("#{start}#{text}#{ending}")
|
|
97
|
+
end
|
|
98
|
+
else
|
|
99
|
+
line = doc.cursor_line
|
|
100
|
+
text = doc.get_line_without_end_of_line(line)
|
|
101
|
+
start_idx = text.index(start)
|
|
102
|
+
end_idx = text.rindex(ending)
|
|
103
|
+
start_length = start.split(//).length
|
|
104
|
+
ending_start_offset = text.split(//).length-ending.split(//).length
|
|
105
|
+
if text[0,start_length] == start and text[ending_start_offset,text.split(//).length] == ending
|
|
106
|
+
text = text[start.length,text.split(//).length]
|
|
107
|
+
text = text[0,ending_start_offset]
|
|
108
|
+
doc.replace_line(line,text)
|
|
109
|
+
else
|
|
110
|
+
replacement = "#{start}#{text}#{ending}"
|
|
111
|
+
replacement += "\n" if doc.get_line(line) =~ /\n$/
|
|
112
|
+
doc.replace_line(line,replacement)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
class ToggleLineCommentCommand < Redcar::EditTabCommand
|
|
121
|
+
|
|
122
|
+
attr_reader :comment
|
|
123
|
+
|
|
124
|
+
def line_start_regex
|
|
125
|
+
/^(\s*)#{comment}\s?/
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def starts_with_comment?(line)
|
|
129
|
+
line =~ line_start_regex
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def strip_comment(line, offset=nil)
|
|
133
|
+
new_line = line.clone
|
|
134
|
+
if offset and offset != 0 and
|
|
135
|
+
new_line[0..offset] !~ /^\s*$/
|
|
136
|
+
new_line[offset..(offset + comment.length)] = ""
|
|
137
|
+
@point_comment_removed = offset
|
|
138
|
+
new_line
|
|
139
|
+
else
|
|
140
|
+
md = line.match(line_start_regex)
|
|
141
|
+
@point_comment_removed = md[1].length
|
|
142
|
+
md[1] + md.post_match
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def add_comment(line, offset)
|
|
147
|
+
if line.length < offset
|
|
148
|
+
line + " "*(offset - line.length) + comment + " "
|
|
149
|
+
else
|
|
150
|
+
line.clone.insert(offset, comment + " ")
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def comment_insertion_point_for(line)
|
|
155
|
+
md = line.match(/^(\s*)([^\s])/)
|
|
156
|
+
md[1].length
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def execute
|
|
160
|
+
type = Comment.comment_map["#{tab.edit_view.grammar.gsub("\"","")}"]
|
|
161
|
+
if type
|
|
162
|
+
@comment = type["line_comment"]
|
|
163
|
+
return unless comment
|
|
164
|
+
else
|
|
165
|
+
Comment.grammar_missing(tab.edit_view.grammar)
|
|
166
|
+
@comment = Comment.storage['default_line_comment']
|
|
167
|
+
end
|
|
168
|
+
selected = doc.selection?
|
|
169
|
+
cursor_offset = doc.cursor_offset
|
|
170
|
+
selection_offset = doc.selection_offset
|
|
171
|
+
cursor_line = doc.cursor_line
|
|
172
|
+
selection_line = doc.selection_line
|
|
173
|
+
cursor_line_offset = doc.cursor_line_offset
|
|
174
|
+
selection_line_offset = doc.selection_line_offset
|
|
175
|
+
if cursor_offset < selection_offset
|
|
176
|
+
start_point_offset = cursor_offset
|
|
177
|
+
end_point_offset = selection_offset
|
|
178
|
+
start_point_line = cursor_line
|
|
179
|
+
start_point_line_offset = cursor_line_offset
|
|
180
|
+
else
|
|
181
|
+
start_point_offset = selection_offset
|
|
182
|
+
end_point_offset = cursor_offset
|
|
183
|
+
start_point_line = selection_line
|
|
184
|
+
start_point_line_offset = selection_line_offset
|
|
185
|
+
end
|
|
186
|
+
start_line = doc.line_at_offset(start_point_offset)
|
|
187
|
+
end_line = doc.line_at_offset(end_point_offset)
|
|
188
|
+
|
|
189
|
+
if doc.offset_at_line(end_line) == end_point_offset and start_line != end_line
|
|
190
|
+
end_line -= 1
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
doc.controllers(Redcar::AutoIndenter::DocumentController).first.disable do
|
|
194
|
+
doc.compound do
|
|
195
|
+
all_lines_are_already_commented = true
|
|
196
|
+
start_line_comment_offset = nil
|
|
197
|
+
insertion_column = 1000
|
|
198
|
+
|
|
199
|
+
(start_line..end_line).each do |line|
|
|
200
|
+
text = doc.get_line(line)
|
|
201
|
+
if text.length <= insertion_column + 1 and text =~ /^\s*$/
|
|
202
|
+
else
|
|
203
|
+
insertion_column = [insertion_column, comment_insertion_point_for(text)].min
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
if line == start_point_line and selected
|
|
207
|
+
text = text[start_point_line_offset..-1]
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
unless starts_with_comment?(text)
|
|
211
|
+
all_lines_are_already_commented = false
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
if all_lines_are_already_commented
|
|
216
|
+
(start_line..end_line).each do |line|
|
|
217
|
+
doc.replace_line(line) do |text|
|
|
218
|
+
new_text =
|
|
219
|
+
if line == start_point_line and selected
|
|
220
|
+
strip_comment(text, start_point_line_offset)
|
|
221
|
+
else
|
|
222
|
+
strip_comment(text)
|
|
223
|
+
end
|
|
224
|
+
diff = text.length - new_text.length
|
|
225
|
+
if cursor_offset < selection_offset
|
|
226
|
+
selection_offset -= diff
|
|
227
|
+
else
|
|
228
|
+
if cursor_line > line or (cursor_line == line and cursor_line_offset > @point_comment_removed)
|
|
229
|
+
cursor_offset -= diff
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
new_text
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
else
|
|
236
|
+
(start_line..end_line).each do |line|
|
|
237
|
+
doc.replace_line(line) do |text|
|
|
238
|
+
new_text = if line == start_point_line and selected
|
|
239
|
+
add_comment(text, [start_point_line_offset, insertion_column].max)
|
|
240
|
+
else
|
|
241
|
+
add_comment(text, insertion_column)
|
|
242
|
+
end
|
|
243
|
+
diff = new_text.length - text.length
|
|
244
|
+
if cursor_offset < selection_offset
|
|
245
|
+
selection_offset += diff
|
|
246
|
+
else
|
|
247
|
+
if cursor_line > line or (cursor_line == line and cursor_line_offset > insertion_column)
|
|
248
|
+
cursor_offset += diff
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
new_text
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
if selected
|
|
259
|
+
doc.set_selection_range(cursor_offset, selection_offset)
|
|
260
|
+
else
|
|
261
|
+
doc.set_selection_range(cursor_offset, cursor_offset)
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
end
|