Skip to content
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
25 changes: 25 additions & 0 deletions Support/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,31 @@ def update_pbfind(search)
IO.popen('pbcopy -pboard find', 'w') {|pbcopy| pbcopy.write @pbfind}
end

# read file type filter
def search_filetype_filter

unless @search_filetype_filter
filetype_filter_command = "defaults read com.macromates.textmate fileTypeString 2>/dev/null"
@search_filetype_filter = OSX::PropertyList::load(Base64.decode64(%x{#{filetype_filter_command}}))
end

@search_filetype_filter

rescue
@search_filetype_filter = [] # oh the humanity!
end

# update file type filter
def update_search_filetype_filter(filetype_filter)
search_filetype_filter = filetype_filter

filter_history = Base64.encode64(search_filetype_filter.to_plist)

history_command = %Q|defaults write com.macromates.textmate fileTypeString -string #{e_sh filter_history} 2>/dev/null|
%x{#{history_command}}
rescue
end

end
end

Expand Down
27 changes: 26 additions & 1 deletion Support/lib/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class AckInProject::Search
include AckInProject::Environment
AckInProject::Environment.ghetto_include %w(escape), binding

attr_accessor :plist, :current_file, :lines_matched, :files_matched
attr_accessor :plist, :current_file, :lines_matched, :files_matched, :filter

def initialize(plist)
self.plist = plist;
Expand Down Expand Up @@ -79,6 +79,7 @@ def scrub(content)
def prepare_search
# TODO: bail if the search term is empty
result = plist['result']
fileTypes = result['fileTypeString'].split(',') if result['fileTypeString']

options = %w(--group --color --flush)
options << '-w' if result['matchWholeWords'] == 1
Expand All @@ -87,13 +88,37 @@ def prepare_search
options << '-C' if result['showContext'] == 1
options << "--#{result['followSymLinks'] == 1 ? '' : 'no'}follow"
options << "--#{result['loadAckRC'] == 1 ? '' : 'no'}env"

# add file type filters
self.filter = ""
if result['fileTypeString']
fileTypes.each do |f|
f = f.gsub(/\s+/, "")
f = parse_filters(f)
# options << "#{f}" if f != self.filter
end
end

options << "-G '#{self.filter[0..self.filter.length-2]}'" if self.filter != ""

AckInProject.update_search_history result['returnArgument']
AckInProject.update_pbfind result['returnArgument']
AckInProject.update_search_filetype_filter result['fileTypeString'] || ''

%{cd #{e_sh search_directory}; #{e_sh ack} #{options.join(' ')} -- #{e_sh result['returnArgument']}}
end

# check to see it's a big filter or small filter
# update: only support small filter
# TODO: add more types support
def parse_filters(filter)
# if ['ruby', 'shell', 'rake', 'php', 'html', 'xml', 'yaml'].include?(filter)
# " --#{filter} "
# else
self.filter << "\\.#{filter}$|"
# end
end

def search
# tell ack about potential .ackrc files in the project directory
ENV['ACKRC'] = File.join(project_directory, '.ackrc')
Expand Down
5 changes: 4 additions & 1 deletion Support/lib/search_dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def show(&block)

command = %Q{#{TM_DIALOG} -cm -p #{e_sh params.to_plist} -d #{e_sh defaults.to_plist} #{e_sh nib_file('AckInProjectSearch.nib')}}
plist = OSX::PropertyList::load(%x{#{command}})

if plist['result']
block.call(plist)
end
Expand All @@ -26,8 +27,10 @@ def defaults

def params
history = AckInProject.search_history
filetype_filter = AckInProject.search_filetype_filter
{
#'contentHeight' => 168,
#'contentHeight' => 150,
'fileTypeString' => filetype_filter,
'ackExpression' => AckInProject.pbfind,
'ackHistory' => history
}
Expand Down
7 changes: 0 additions & 7 deletions Support/nibs/AckInProjectSearch.nib/classes.nib

This file was deleted.

Loading