Skip to content

Commit

Permalink
Add search UI with menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Palmer committed Jun 13, 2008
1 parent 191bb02 commit 6040395
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 3 deletions.
34 changes: 34 additions & 0 deletions ApplicationController.rb
Expand Up @@ -36,6 +36,7 @@ class ApplicationController < OSX::NSObject
ib_outlet :local_branches_menu
ib_outlet :remote_branches_menu
ib_outlet :tags_menu
ib_outlet :search_field

def applicationDidFinishLaunching(sender)
@window.makeKeyAndOrderFront(self)
Expand All @@ -58,6 +59,7 @@ def awakeFromNib
@branch_field.cell.setBackgroundStyle(NSBackgroundStyleRaised)

setup_refs_view_menu
setup_search_field
end
end

Expand All @@ -81,6 +83,14 @@ def swap_tab(segment)
@tab_panel.selectTabViewItemWithIdentifier(tag)
end

def set_search_category(sender)
menu = @search_field.cell.searchMenuTemplate
menu.itemWithTitle(@current_search_item).setState(NSOffState)
menu.itemWithTitle(sender.title).setState(NSOnState)
@search_field.cell.setSearchMenuTemplate(menu)
@current_search_item = sender.title
end

private
def setup_refs_view_menu
[@local_branches_menu, @remote_branches_menu, @tags_menu].each { |m| m.submenu.setAutoenablesItems(false) }
Expand All @@ -101,5 +111,29 @@ def setup_refs_view_menu
add_menu_item.call(heads, @local_branches_menu)
add_menu_item.call(repo.remotes, @remote_branches_menu)
add_menu_item.call(repo.tags, @tags_menu)
end

def setup_search_field
@search_menu = NSMenu.alloc.initWithTitle("Search Menu")
@search_field.cell.setSearchMenuTemplate(@search_menu)
@search_menu.setAutoenablesItems(false)

add_menu_item = lambda do |title, tooltip, state|
item = NSMenuItem.alloc.initWithTitle_action_keyEquivalent(title, :set_search_category, "")
@search_menu.addItem(item)
item.setToolTip(tooltip)
item.setEnabled(true)
item.setTarget(self)
if state
item.setState(NSOnState)
@current_search_item = title
end
end

add_menu_item.call("Commits", "Search commit messages", true)
add_menu_item.call("SHA1", "Find a commit by its SHA1 hash", false)
add_menu_item.call("Author", "Find all all commits by a particular author", false)
add_menu_item.call("Path", "Find commits based on a path", false)

end
end
104 changes: 101 additions & 3 deletions English.lproj/MainMenu.xib
Expand Up @@ -519,6 +519,75 @@
<int key="NSSegmentStyle">2</int>
</object>
</object>
<object class="NSSearchField" id="444059892">
<reference key="NSNextResponder" ref="831824449"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{292, 11}, {154, 22}}</string>
<reference key="NSSuperview" ref="831824449"/>
<bool key="NSEnabled">YES</bool>
<object class="NSSearchFieldCell" key="NSCell" id="534219204">
<int key="NSCellFlags">343014976</int>
<int key="NSCellFlags2">268436480</int>
<string key="NSContents"/>
<reference key="NSSupport" ref="98627494"/>
<reference key="NSControlView" ref="444059892"/>
<bool key="NSDrawsBackground">YES</bool>
<int key="NSTextBezelStyle">1</int>
<object class="NSColor" key="NSBackgroundColor">
<int key="NSColorSpace">6</int>
<string key="NSCatalogName">System</string>
<string key="NSColorName">textBackgroundColor</string>
<object class="NSColor" key="NSColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
</object>
</object>
<reference key="NSTextColor" ref="394328784"/>
<object class="NSButtonCell" key="NSSearchButtonCell">
<int key="NSCellFlags">130560</int>
<int key="NSCellFlags2">0</int>
<string key="NSContents">search</string>
<string key="NSAction">_searchFieldSearch:</string>
<reference key="NSTarget" ref="534219204"/>
<reference key="NSControlView" ref="444059892"/>
<int key="NSButtonFlags">138690815</int>
<int key="NSButtonFlags2">0</int>
<string key="NSKeyEquivalent"/>
<int key="NSPeriodicDelay">400</int>
<int key="NSPeriodicInterval">75</int>
</object>
<object class="NSButtonCell" key="NSCancelButtonCell">
<int key="NSCellFlags">130560</int>
<int key="NSCellFlags2">0</int>
<string key="NSContents">clear</string>
<object class="NSMutableArray" key="NSAccessibilityOverriddenAttributes">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMutableDictionary">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMutableArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>AXDescription</string>
<string>NSAccessibilityEncodedAttributesValueType</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>cancel</string>
<reference ref="9"/>
</object>
</object>
</object>
<string key="NSAction">_searchFieldCancel:</string>
<reference key="NSTarget" ref="534219204"/>
<reference key="NSControlView" ref="444059892"/>
<int key="NSButtonFlags">138690815</int>
<int key="NSButtonFlags2">0</int>
<string key="NSKeyEquivalent"/>
<int key="NSPeriodicDelay">400</int>
<int key="NSPeriodicInterval">75</int>
</object>
<int key="NSMaximumRecents">255</int>
</object>
</object>
</object>
<string key="NSFrameSize">{990, 682}</string>
<reference key="NSSuperview"/>
Expand Down Expand Up @@ -1459,6 +1528,14 @@
</object>
<int key="connectionID">529</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">search_field</string>
<reference key="source" ref="620275248"/>
<reference key="destination" ref="444059892"/>
</object>
<int key="connectionID">555</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
Expand Down Expand Up @@ -1504,6 +1581,7 @@
<reference ref="869639466"/>
<reference ref="1049027428"/>
<reference ref="637722390"/>
<reference ref="444059892"/>
</object>
<reference key="parent" ref="469667931"/>
</object>
Expand Down Expand Up @@ -2131,6 +2209,20 @@
<reference key="parent" ref="269908025"/>
<string key="objectName">NetorkController</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">553</int>
<reference key="object" ref="444059892"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="534219204"/>
</object>
<reference key="parent" ref="831824449"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">554</int>
<reference key="object" ref="534219204"/>
<reference key="parent" ref="444059892"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
Expand Down Expand Up @@ -2265,6 +2357,8 @@
<string>520.IBPluginDependency</string>
<string>525.IBPluginDependency</string>
<string>526.IBPluginDependency</string>
<string>553.IBPluginDependency</string>
<string>554.IBPluginDependency</string>
<string>56.IBPluginDependency</string>
<string>56.ImportedFromIB2</string>
<string>57.IBEditorWindowLastContentRect</string>
Expand Down Expand Up @@ -2303,9 +2397,9 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{44, 112}, {990, 682}}</string>
<string>{{52, 157}, {990, 682}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{44, 112}, {990, 682}}</string>
<string>{{52, 157}, {990, 682}}</string>
<reference ref="9"/>
<reference ref="9"/>
<string>{{146, 174}, {990, 682}}</string>
Expand Down Expand Up @@ -2439,6 +2533,8 @@
<string>com.apple.WebKitIBPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{488, 641}, {218, 193}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
Expand Down Expand Up @@ -2468,7 +2564,7 @@
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">552</int>
<int key="maxID">555</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand Down Expand Up @@ -2501,6 +2597,7 @@
<string>main_canvas</string>
<string>main_view</string>
<string>remote_branches_menu</string>
<string>search_field</string>
<string>tab_panel</string>
<string>tags_menu</string>
<string>window</string>
Expand All @@ -2518,6 +2615,7 @@
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
Expand Down

0 comments on commit 6040395

Please sign in to comment.