require 'P4'
require ENV['TM_BUNDLE_SUPPORT'] + '/lib/configuration.rb'
require ENV['TM_SUPPORT_PATH'] + '/lib/ui.rb'
class Connect
attr_accessor :config, :new
def initialize
@config = Configuration.new(nil)
conf_file = File.join(ENV['TM_BUNDLE_SUPPORT'], "/lib/p4.conf")
if File.exists?(conf_file)
File.open(conf_file) do |f|
begin
@config = Marshal.load(f)
rescue EOFError
@config.config_hash = nil
end
end
end
@p4 = P4.new
end
def connect
if @config.config_hash
@p4.user = @config.config_hash['p4user']
@p4.client = @config.config_hash['p4client']
if @config.config_hash['p4pass']
@p4.password = @config.config_hash['p4pass']
end
@p4.port = @config.config_hash['p4port']
else
return nil
end
begin
@p4.connect
@p4.run_login
rescue
return nil
end
return @p4
end
def disconnect(p4)
p4.disconnect
end
def get_changelist_choice(prompt, start_items)
if @p4
pending = @p4.run_changes('-c', @p4.client, '-u', @p4.user, '-s', 'pending')
items = start_items
pending.each do |i|
items << i['change']
end
change = []
change_out = TextMate::UI.request_item(:title => "Changelist", :prompt => "#{prompt} which changelist?", :items => items)
if change_out == "default"
change[0] = "default"
elsif change_out == "new"
change[0] = "new"
change[1] = "new"
elsif change_out =~ /^[0-9]+$/
change[0] = "pending"
change[1] = change_out
end
return change
else
return nil
end
end
end
conn = Connect.new
conn.connect