Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace various "Visualize with..." menu items with single configurable item #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<key>command</key>
<string>#!/usr/bin/env ruby18
require ENV['TM_BUNDLE_SUPPORT'] + '/environment.rb'
dispatch(:controller =&gt; "misc", :action =&gt; "gitk")
dispatch(:controller =&gt; "misc", :action =&gt; "external")
</string>
<key>input</key>
<string>none</string>
<key>inputFormat</key>
<string>text</string>
<key>name</key>
<string>Visualize Branch History With GitK</string>
<string>Visualize History with External Git App</string>
<key>outputCaret</key>
<string>afterOutput</string>
<key>outputFormat</key>
Expand All @@ -26,7 +26,7 @@ dispatch(:controller =&gt; "misc", :action =&gt; "gitk")
<key>semanticClass</key>
<string>action.scm.other</string>
<key>uuid</key>
<string>20F5C491-F71C-4963-9C61-DF7294976550</string>
<string>547EFC07-D15D-4217-9695-9043232560FF</string>
<key>version</key>
<integer>2</integer>
</dict>
Expand Down
30 changes: 0 additions & 30 deletions Commands/Use Git-Gui.tmCommand

This file was deleted.

33 changes: 0 additions & 33 deletions Commands/Use GitX.tmCommand

This file was deleted.

33 changes: 0 additions & 33 deletions Commands/Use Gitnub.tmCommand

This file was deleted.

95 changes: 68 additions & 27 deletions Support/app/controllers/misc_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,28 @@ def init
puts "<h2>Initializing Git Repository in #{ENV['TM_PROJECT_DIRECTORY']}</h2>"
puts htmlize(git.init(ENV["TM_PROJECT_DIRECTORY"]))
end

def gitk
run_detached("PATH=#{File.dirname(git.git)}:$PATH && gitk --all", "Wish Shell")
end

def gitgui
run_detached("PATH=#{File.dirname(git.git)}:$PATH && git gui", "Git Gui")
end

def gitnub
cmd = first_which(git.config["git-tmbundle.gitnub-path"], "nub", "/Applications/GitNub.app/Contents/MacOS/GitNub")
if cmd
run_detached(cmd + " #{ENV['TM_PROJECT_DIRECTORY']}", "Gitnub")
else
puts "Unable to find Gitnub. Use the config dialog to set the Gitnub path to where you've installed it."
output_show_tool_tip
end
end

def gitx
cmd = first_which(git.config["git-tmbundle.gitx-path"], "gitx", "/Applications/GitX.app/Contents/Resources/gitx")
if cmd
run_detached("cd '#{ENV['TM_DIRECTORY']}';" + cmd, "GitX")

def external
gui_type = git.config["git-tmbundle.ext-app"]
case gui_type
when "gitk"
ext_gitk
when "gitgui"
ext_gitgui
when "gitx"
ext_gitx
when "gitnub"
ext_gitnub
when "stree"
ext_stree
when "custom"
ext_custom
else
puts "Unable to find GitX. Use the config dialog to set the GitX path to where you've installed it."
puts "Select an external GUI tool from the config dialog(Bundles → Git → Config...)."
output_show_tool_tip
end
end

protected
def first_which(*args)
args.map do |arg|
Expand All @@ -42,7 +35,7 @@ def first_which(*args)
end
nil
end

def run_detached(cmd, app_name)
exit if fork # Parent exits, child continues.
Process.setsid # Become session leader.
Expand All @@ -63,5 +56,53 @@ def run_detached(cmd, app_name)
Process.detach(pid)
#inspired by http://andrejserafim.wordpress.com/2007/12/16/multiple-threads-and-processes-in-ruby/
end


def ext_gitk
run_detached("cd '#{git.path()}'; PATH=#{File.dirname(git.git)}:$PATH && gitk --all", "Wish")
end

def ext_gitgui
run_detached("cd '#{git.path()}'; PATH=#{File.dirname(git.git)}:$PATH && git gui", "Git Gui")
end

def ext_gitnub
cmd = first_which(git.config["git-tmbundle.gitnub-path"], "nub", "/Applications/GitNub.app/Contents/MacOS/GitNub")
if cmd
run_detached(cmd + " #{ENV['TM_PROJECT_DIRECTORY']}", "Gitnub")
else
puts "Unable to find Gitnub. Use the config dialog to set the Gitnub path to where you've installed it."
output_show_tool_tip
end
end

def ext_gitx
cmd = first_which(git.config["git-tmbundle.gitx-path"], "gitx", "/Applications/GitX.app/Contents/Resources/gitx")
if cmd
run_detached("cd '#{ENV['TM_DIRECTORY']}';" + cmd, "GitX")
else
puts "Unable to find GitX. Use the config dialog to set the GitX path to where you've installed it."
output_show_tool_tip
end
end

def ext_stree
cmd = first_which(git.config["git-tmbundle.stree-path"], "stree", "/Applications/SourceTree.app/Contents/Resources/stree")
if cmd
run_detached("cd '#{git.path()}';" + cmd, "SourceTree")
else
puts "Unable to find SourceTree. Use the config dialog to set the SourceTree path to where you've installed it."
output_show_tool_tip
end
end

def ext_custom
cmd = git.config["git-tmbundle.ext-custom-cmd"]
if cmd
run_detached("cd '#{git.path()}'; " + cmd, "Custom Git GUI")
else
puts "Set the custom GUI command to use from the config dialog(Bundles → Git → Config...)."
output_show_tool_tip
end

end
end
27 changes: 26 additions & 1 deletion Support/app/helpers/config_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
module ConfigHelper
def config_form_field(type, local_or_global, config_key, options = {})
if type == "select"
config_select_field(local_or_global, config_key, options)
else
config_text_field(local_or_global, config_key, options)
end
end

def config_text_field(local_or_global, config_key, options = {})
content_tag :input, {:type => "text", :value => git.config[local_or_global, config_key], :onchange => "dispatch({controller: 'config', action: 'set', scope: '#{local_or_global}', key: '#{config_key}', value: $F(this)})"}.merge(options)
end
end

def config_select_field(local_or_global, config_key, options = {})
selected_value = git.config[local_or_global, config_key]
if options[:select_options]
select_options = options[:select_options].map do |value, label|
if selected_value.to_s == value.to_s
content_tag(:option, label, :value => value, :selected=>"selected")
else
content_tag(:option, label, :value => value)
end
end
else
select_options = []
end

content_tag(:select, select_options, {:mulitiple => false, :onchange => "dispatch({controller: 'config', action: 'set', scope: '#{local_or_global}', key: '#{config_key}', value: $F(this)})"}.merge(options).reject(:select_options))
end
end
27 changes: 16 additions & 11 deletions Support/app/views/config/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,28 @@
<%
tabindex = 0
[
["Name", "user.name", [:global]],
["Email", "user.email", [:global]],
["text", "Name", "user.name", [:global]],
["text", "Email", "user.email", [:global]],
[],
["Log limit", "git-tmbundle.log.limit", [:global, :local], {:style => "width: 40px"}],
["Log context lines", "git-tmbundle.log.context-lines", [:global, :local], {:style => "width: 40px"}],
["Show diff check (yes or no)", "git-tmbundle.show-diff-check", [:global, :local], {:style => "width: 40px"}],
["text", "Log limit", "git-tmbundle.log.limit", [:global, :local], {:style => "width: 40px"}],
["text", "Log context lines", "git-tmbundle.log.context-lines", [:global, :local], {:style => "width: 40px"}],
["text", "Show diff check (yes or no)", "git-tmbundle.show-diff-check", [:global, :local], {:style => "width: 40px"}],
[],
["Gitnub path", "git-tmbundle.gitnub-path", [:global], {:style => "width: 250px"}],
["GitX path", "git-tmbundle.gitx-path", [:global], {:style => "width: 250px"}],
].each do |label, key, scopes, input_options|
["select", "External Git App", "git-tmbundle.ext-app", [:global], {
:select_options => {:gitgui => "Git Gui", :gitk => "gitk", :gitnub => "Gitnub",
:gitx => "GitX", :stree => "SourceTree", :custom => "custom" }
}],
["text", "Gitnub path", "git-tmbundle.gitnub-path", [:global], {:style => "width: 250px"}],
["text", "GitX path", "git-tmbundle.gitx-path", [:global], {:style => "width: 250px"}],
["text", "Custom Command", "git-tmbundle.ext-custom-cmd", [:global], {:style => "width: 250px"}],
].each do |type, label, key, scopes, input_options|
%>
<tr>
<% [:global, :local].each do |scope| %>
<% if scopes && scopes.include?(scope)
<% if scopes && scopes.include?(scope)
tabindex += 1 %>
<td><%= label %></td>
<td><%= config_text_field scope, key, {:tabindex => tabindex}.merge(input_options || {}) %></td>
<td><%= config_form_field type, scope, key, {:tabindex => tabindex}.merge(input_options || {}) %></td>
<% else %>
<td>&nbsp;</td>
<td>&nbsp;</td>
Expand All @@ -40,6 +45,6 @@
<% end %>
</tbody>
</table>

</form>

9 changes: 2 additions & 7 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@
<string>0DBC221A-B726-4367-A5E1-04AB999F8CC2</string>
<string>7CE2C842-EBC4-443C-8DDB-3B16AC593D9A</string>
<string>------------------------------------</string>
<string>20F5C491-F71C-4963-9C61-DF7294976550</string>
<string>1FF5FF82-13A0-4C83-BAD6-D67AE8180FA9</string>
<string>1C12DE42-78A9-4DCA-BB55-2B8E6328C72D</string>
<string>D0DF4B19-F311-48CC-BF68-F8B33CD051D3</string>
<string>------------------------------------</string>
<string>5A08145A-069F-4196-8F32-07C05EF4DCB6</string>
<string>547EFC07-D15D-4217-9695-9043232560FF</string>
<string>------------------------------------</string>
<string>739BCC37-16DE-40BE-83C1-0AE8FDC45036</string>
<string>794C7EF9-B0A5-4B27-90BD-000837237B85</string>
Expand Down Expand Up @@ -111,9 +108,6 @@
<string>3E646038-6F79-46BE-96A3-9802E7011162</string>
<string>E6D2DCFE-A40D-4BF1-9B43-7E3199CF00B4</string>
<string>7CE2C842-EBC4-443C-8DDB-3B16AC593D9A</string>
<string>20F5C491-F71C-4963-9C61-DF7294976550</string>
<string>D0DF4B19-F311-48CC-BF68-F8B33CD051D3</string>
<string>1FF5FF82-13A0-4C83-BAD6-D67AE8180FA9</string>
<string>246BC5D6-F4DC-458B-8966-C601B65AA1E9</string>
<string>6494E41A-04CE-4D30-BD9A-B50056A7C13F</string>
<string>3F84F9EB-027A-4200-B29B-C99EFA09F453</string>
Expand All @@ -130,6 +124,7 @@
<string>0DBC221A-B726-4367-A5E1-04AB999F8CC2</string>
<string>E0901B2E-8953-4A2F-A872-8DBE1A047370</string>
<string>683BF855-9BC9-47A6-89DD-7C2192E62FD7</string>
<string>547EFC07-D15D-4217-9695-9043232560FF</string>
</array>
<key>require</key>
<array>
Expand Down