Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

first commit

  • Loading branch information...
commit d7510b93b511181e7b44707c6a5ecdc0cf4a85bd 1 parent ada157f
@jablkopp authored
View
7 README.md
@@ -1,4 +1,9 @@
## INSTALLATION
cd ~/.redcar/plugins
- git clone git://github.com/jablkopp/go-to-github.git
+ git clone git://github.com/jablkopp/find-in-project.git
+
+## USAGE
+
+ Ctrl + Shift + F (Linux)
+ Cmd + Shift + F (OSX)
View
107 lib/find_in_project.rb
@@ -0,0 +1,107 @@
+require 'erb'
+require "cgi"
+
+module Redcar
+ class FindInProject
+
+ def self.keymaps
+ osx = Keymap.build("main", :osx) do
+ link "Cmd+Shift+F", FindInProject::OpenCommand
+ end
+
+ linwin = Keymap.build("main", [:linux, :windows]) do
+ link "Ctrl+Shift+F", FindInProject::OpenCommand
+ end
+
+ [linwin, osx]
+ end
+
+ def self.menus
+ Menu::Builder.build do
+ sub_menu "Plugins" do
+ sub_menu "Find in project" do
+ item "find!", FindInProject::OpenCommand
+ item "Edit plugin", FindInProject::EditFindInProject
+ end
+ end
+ end
+ end
+
+ class OpenCommand < Redcar::Command
+
+ def execute
+ controller = Controller.new
+ tab = win.new_tab(HtmlTab)
+ tab.html_view.controller = controller
+ tab.focus
+ end
+
+
+ class Controller
+
+ def title
+ "Find in project"
+ end
+
+ def index
+ @plugin_path = File.join(File.dirname(__FILE__), "..")
+ @files ||= ".gitignore tags"
+ @dirs ||= ".git .svn *.log"
+ @includes ||= "*.*"
+ rhtml = ERB.new(File.read(File.join(File.dirname(__FILE__), "..", "views", "index.html.erb")))
+ rhtml.result(binding)
+ end
+
+ def find(query, files, dirs, includes)
+ @query = query
+ @files = files
+ @dirs = dirs
+ @includes = includes
+
+ options = "-r -n -H -E --binary-files='without-match' "
+
+ files.split(' ').each do |file|
+ options << "--exclude=\"#{file}\" "
+ end
+
+ dirs.split(' ').each do |dir|
+ options << "--exclude-dir=\"#{dir}\" "
+ end
+
+ includes.split(' ').each do |inc|
+ options << "--include=\"#{inc}\" "
+ end
+
+ path = Project::Manager.focussed_project.path
+ @output = `cd #{path}; grep "#{query}" #{options} .`
+ @outputs = @output.split("\n")
+ 1
+ end
+
+ def open_file(file, line)
+ tab = Redcar.app.focussed_window.new_tab(Redcar::EditTab)
+ mirror = Project::FileMirror.new(File.join(Project::Manager.focussed_project.path, file))
+ tab.edit_view.document.mirror = mirror
+ tab.edit_view.reset_undo
+ tab.edit_view.document.scroll_to_line(line.to_i-2)
+ tab.focus
+ 1
+ end
+
+ end
+
+ end
+
+ class EditFindInProject < Redcar::Command
+ def execute
+ Project::Manager.open_project_for_path(File.join(Redcar.user_dir, "plugins", "find-in-project"))
+ tab = Redcar.app.focussed_window.new_tab(Redcar::EditTab)
+ mirror = Project::FileMirror.new(File.join(Redcar.user_dir, "plugins", "find-in-project", "lib", "find_in_project.rb"))
+ tab.edit_view.document.mirror = mirror
+ tab.edit_view.reset_undo
+ tab.focus
+ end
+ end
+
+ end
+end
View
64 lib/go_to_github.rb
@@ -1,64 +0,0 @@
-module Redcar
-
- class GoToGithub
-
- def self.keymaps
- osx = Keymap.build("main", :osx) do
- link "Cmd+Shift+G", GoToGithub::ShowLineInGithub
- end
-
- linwin = Keymap.build("main", [:linux, :windows]) do
- link "Ctrl+Shift+G", GoToGithub::ShowLineInGithub
- end
-
- [linwin, osx]
- end
-
- def self.menus
- Menu::Builder.build do
- sub_menu "Plugins" do
- sub_menu "Go to GitHub" do
- item "Show current line in Github!", ShowLineInGithub
- item "Edit plugin", EditGoToGithub
- end
- end
- end
- end
-
-
- class ShowLineInGithub < Redcar::Command
- def execute
- document = win.focussed_notebook.focussed_tab.document
- current_line = document.cursor_line+1
- path = Project::Manager.focussed_project.path
- file = document.path[path.size,document.path.size]
-
- begin
- branch = `cd #{path} && git branch --no-color 2> /dev/null`.match(/\*\ (.*)\n/)[1]
- remote = `cd #{path} && git remote`.gsub("\n", "")
- project_name = `cd #{path} && git config --get remote.#{remote}.url`.match(/github.com[:|\/](.*)\.git\n/)[1]
-
- raise unless branch && remote && project_name
-
- url = "https://github.com/" << project_name << "/blob/" << branch << file << "#L" << current_line.to_s
- Thread.new do
- system("firefox -new-window " << url)
- end
- rescue
- Application::Dialog.message_box("This project is not gitub repository")
- end
- end
- end
-
- class EditGoToGithub < Redcar::Command
- def execute
- Project::Manager.open_project_for_path(File.join(Redcar.user_dir, "plugins", "go-to-github"))
- tab = Redcar.app.focussed_window.new_tab(Redcar::EditTab)
- mirror = Project::FileMirror.new(File.join(Redcar.user_dir, "plugins", "go-to-github", "lib", "go_to_github.rb"))
- tab.edit_view.document.mirror = mirror
- tab.edit_view.reset_undo
- tab.focus
- end
- end
- end
-end
View
14 plugin.rb
@@ -1,8 +1,12 @@
Plugin.define do
- name "go-to-github"
- version "0.1b"
- file "lib", "go_to_github"
- object "Redcar::GoToGithub"
- dependencies "redcar", ">0"
+ name "find-in-project"
+ version "0.1.0"
+
+
+ object "Redcar::FindInProject"
+ file "lib", "find_in_project"
+
+ dependencies "core", ">0",
+ "HTML View", ">=0.3.2"
end
View
46 stylesheets/style.css
@@ -0,0 +1,46 @@
+
+
+
+#output {
+ border: 1px solid #555;
+ margin-top: 20px;
+
+}
+#output table {
+ width: 100%;
+ border-collapse: collapse;
+ background-color: #FFF;
+ font-size: 12px;
+}
+#output table tr:hover {
+ background-color: #f1f1f1;
+}
+
+#output table th {
+ border: 1px solid #eaeaea;
+ padding: 5px;
+ background-color: #f1f1f1;
+}
+
+#output table td {
+ border: 1px solid #eaeaea;
+ padding: 2px;
+}
+
+#output table td.lines {
+ text-align: right;
+ width: 0%;
+ font-weight: bold;
+}
+
+#output table td.content {
+ width: 100%;
+}
+
+#output table td.location {
+ white-space: nowrap;
+}
+
+#output table td b {
+ color: red;
+}
View
70 views/index.html.erb
@@ -0,0 +1,70 @@
+<% jquery_path = File.expand_path(File.join(Redcar.root, %w(plugins html_view assets jquery-1.4.min.js))) %>
+<script type="text/javascript" src="file://<%= jquery_path %>"></script>
+
+<% css_path = @plugin_path + "/stylesheets/style.css" %>
+<link rel="stylesheet" href="file://<%= css_path %>" type="text/css" media="screen">
+<h3>Find in project</h3>
+<form id="form">
+<label for="dirs">Exclude dirs:</label>
+<input id="dirs" type="text" value="<%= @dirs %>"/>
+<br />
+<label for="files">Exclude files:</label>
+<input id="files" type="text" value="<%= @files %>"/>
+<br />
+<label for="includes">Include files:</label>
+<input id="includes" type="text" value="<%= @includes %>"/>
+<br />
+<label for="query">Find:</label>
+<input id="query" type="text" value="<%= @query %>"/>
+<input id="search" type="submit" value="Find in project"/>
+</form>
+<div id="output">
+<table>
+<% @outputs ||= []%>
+<% @outputs.each do |line| %>
+ <% out = line.split(':', 3) %>
+ <tr>
+ <td class="location">
+ <a href="<%= out[0] %>" line="<%= out[1] %>"><%= out[0] %></a>
+ </td>
+ <td class="lines">
+ <%= out[1] %>
+ </td>
+ <td class="content">
+ <%= CGI.escapeHTML(out[2] || "").gsub("#{@query}", "<b>#{@query}</b>") %>
+ </td>
+ </tr>
+<% end %>
+</table>
+</div>
+
+<script language="javascript">
+
+ $('#form').submit(function() {
+ var query = $("#query").val();
+ var search = $("#search");
+ var files = $("#files").val();
+ var dirs = $("#dirs").val();
+ var includes = $("#includes").val();
+ search.attr('disabled', 'disabled');
+ search.val("wait...");
+ try {
+ Controller.find(query, files, dirs, includes);
+ } catch(e) {
+ alert(e.message);
+ }
+ window.location = "controller/index";
+ return false;
+ });
+
+ $("a").click(function(e) {
+ e.preventDefault();
+ try {
+ Controller.openFile($(this).attr('href'), $(this).attr('line'));
+ } catch(e) {
+ alert(e.message);
+ }
+ });
+
+
+</script>

0 comments on commit d7510b9

Please sign in to comment.
Something went wrong with that request. Please try again.