Skip to content

Commit

Permalink
now showing results and clicking on them opens the file at the locati…
Browse files Browse the repository at this point in the history
…on in macvim
  • Loading branch information
jtaby committed May 28, 2011
1 parent be75915 commit f621717
Show file tree
Hide file tree
Showing 8 changed files with 3,113 additions and 28 deletions.
27 changes: 19 additions & 8 deletions VimAck.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
A9106010137D8624005E57AD /* AppDelegate.rb in Resources */ = {isa = PBXBuildFile; fileRef = A910600F137D8624005E57AD /* AppDelegate.rb */; };
A91C5D20137D896600512CF1 /* AckWindowController.rb in Resources */ = {isa = PBXBuildFile; fileRef = A91C5D1F137D896600512CF1 /* AckWindowController.rb */; };
A91C5D29137D8B8A00512CF1 /* AckWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = A91C5D28137D8B8A00512CF1 /* AckWindow.xib */; };
A9CADADC1391707B00001AC2 /* ack in Resources */ = {isa = PBXBuildFile; fileRef = A9CADADB1391707B00001AC2 /* ack */; };
A9F3BDD2139182A800A4E5C6 /* ack in Resources */ = {isa = PBXBuildFile; fileRef = A9F3BDD1139182A800A4E5C6 /* ack */; };
A9F3BDD413918FAA00A4E5C6 /* MatchedLine.rb in Resources */ = {isa = PBXBuildFile; fileRef = A9F3BDD313918FAA00A4E5C6 /* MatchedLine.rb */; };
A9F3BDD613918FBA00A4E5C6 /* MatchedFile.rb in Resources */ = {isa = PBXBuildFile; fileRef = A9F3BDD513918FBA00A4E5C6 /* MatchedFile.rb */; };
A9F3BDD813918FC700A4E5C6 /* AckTableViewController.rb in Resources */ = {isa = PBXBuildFile; fileRef = A9F3BDD713918FC700A4E5C6 /* AckTableViewController.rb */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -32,7 +35,10 @@
A910600F137D8624005E57AD /* AppDelegate.rb */ = {isa = PBXFileReference; lastKnownFileType = text.script.ruby; path = AppDelegate.rb; sourceTree = "<group>"; };
A91C5D1F137D896600512CF1 /* AckWindowController.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = AckWindowController.rb; sourceTree = "<group>"; };
A91C5D28137D8B8A00512CF1 /* AckWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AckWindow.xib; sourceTree = "<group>"; };
A9CADADB1391707B00001AC2 /* ack */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ack; sourceTree = "<group>"; };
A9F3BDD1139182A800A4E5C6 /* ack */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ack; sourceTree = "<group>"; };
A9F3BDD313918FAA00A4E5C6 /* MatchedLine.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = MatchedLine.rb; sourceTree = "<group>"; };
A9F3BDD513918FBA00A4E5C6 /* MatchedFile.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = MatchedFile.rb; sourceTree = "<group>"; };
A9F3BDD713918FC700A4E5C6 /* AckTableViewController.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = AckTableViewController.rb; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -77,12 +83,15 @@
A9105FFF137D8624005E57AD /* VimAck */ = {
isa = PBXGroup;
children = (
A9CADADA1391707B00001AC2 /* bin */,
A9F3BDD0139182A800A4E5C6 /* bin */,
A910600F137D8624005E57AD /* AppDelegate.rb */,
A91C5D1F137D896600512CF1 /* AckWindowController.rb */,
A9106008137D8624005E57AD /* Resources */,
A910600C137D8624005E57AD /* Other Sources */,
A9106000137D8624005E57AD /* Supporting Files */,
A9F3BDD313918FAA00A4E5C6 /* MatchedLine.rb */,
A9F3BDD513918FBA00A4E5C6 /* MatchedFile.rb */,
A9F3BDD713918FC700A4E5C6 /* AckTableViewController.rb */,
);
path = VimAck;
sourceTree = "<group>";
Expand Down Expand Up @@ -115,13 +124,12 @@
name = "Other Sources";
sourceTree = "<group>";
};
A9CADADA1391707B00001AC2 /* bin */ = {
A9F3BDD0139182A800A4E5C6 /* bin */ = {
isa = PBXGroup;
children = (
A9CADADB1391707B00001AC2 /* ack */,
A9F3BDD1139182A800A4E5C6 /* ack */,
);
name = bin;
path = ../../../../github/VimAck/VimAck/bin;
path = bin;
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down Expand Up @@ -197,7 +205,10 @@
A9106010137D8624005E57AD /* AppDelegate.rb in Resources */,
A91C5D20137D896600512CF1 /* AckWindowController.rb in Resources */,
A91C5D29137D8B8A00512CF1 /* AckWindow.xib in Resources */,
A9CADADC1391707B00001AC2 /* ack in Resources */,
A9F3BDD2139182A800A4E5C6 /* ack in Resources */,
A9F3BDD413918FAA00A4E5C6 /* MatchedLine.rb in Resources */,
A9F3BDD613918FBA00A4E5C6 /* MatchedFile.rb in Resources */,
A9F3BDD813918FC700A4E5C6 /* AckTableViewController.rb in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
99 changes: 99 additions & 0 deletions VimAck/AckTableViewController.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#
# AckTableViewController.rb
# VimAck
#
# Created by Majd Taby on 5/28/11.
# Copyright 2011 University of Michigan - Dearborn. All rights reserved.
#

class AckTableViewController
attr_accessor :table_view, :records, :projectRoot

def initialize
@records = {}
end

## NSTableDataSource methods

def outlineView(outlineView, numberOfChildrenOfItem:item)
return (item == nil) ? @records.length : item.records.length;
end

def outlineView(outlineView, isItemExpandable:item)
return (item.instance_of? MatchedFile) ? true : false;
end

def outlineView(outlineView, child:index, ofItem:item)
if item == nil
@records[index]
else
ret = item.records[index]
ret
end
end

def outlineView(outlineView, objectValueForTableColumn:tableColumn, byItem:item)
if item.instance_of? MatchedFile

path = File.path item.filename
separater = " - "
base = File.basename item.filename

styledString = NSMutableAttributedString.alloc.initWithString "#{base}#{separater}#{path}"

styledString.addAttribute(NSFontAttributeName,
value: NSFont.systemFontOfSize(11),
range: [0,styledString.length])

else
styledString = NSMutableAttributedString.alloc.initWithString item.matched_line


styledString.addAttribute(NSForegroundColorAttributeName,
value: NSColor.grayColor,
range: [0,styledString.length])

item.matched_ranges.each do |range|

styledString.addAttribute(NSFontAttributeName,
value: NSFont.systemFontOfSize(11),
range: [0,styledString.length])

styledString.addAttribute(NSFontAttributeName,
value: NSFont.boldSystemFontOfSize(11),
range:[range,item.query.length])

styledString.addAttribute(NSForegroundColorAttributeName,
value: NSColor.blackColor,
range:[range,item.query.length])
end

end

styledString
end

def outlineView(outlineView, willDisplayCell:cell, forTableColumn:tableColumn, item:item)
cell.setRepresentedObject(item)
end

def tableView(tableView, willDisplayCell:cell, forTableColumn:column, row:row)
cell.setRepresentedObject(@records[row])
end

def outlineViewSelectionDidChange(notification)
rowNumber = notification.object.selectedRow
item = notification.object.itemAtRow(rowNumber)

fullPath = "#{@projectRoot}/#{item.filename}"
lineNumber = item.line_number
columnNumber = item.matched_ranges[0] + 1

urlString = "mvim://open?url=file://#{fullPath}&line=#{lineNumber}&column=#{columnNumber}"
puts urlString
url = NSURL.URLWithString(urlString)

NSWorkspace.sharedWorkspace.openURL(url)
end

end
Loading

0 comments on commit f621717

Please sign in to comment.