Skip to content

Commit

Permalink
get rid of autoloading, require explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
niklas committed Dec 14, 2010
1 parent 8bbaa1d commit 3946279
Show file tree
Hide file tree
Showing 14 changed files with 622 additions and 116 deletions.
47 changes: 1 addition & 46 deletions bin/vimmate
Expand Up @@ -44,55 +44,10 @@ starting = lambda do
require File.expand_path( File.join( File.dirname(__FILE__), '..', 'config', 'environment' ) )
Thread.abort_on_exception = true

class VimMateApp < ActiveWindow::Application
def initialize(opts={})
@excludes = opts.delete(:excludes)
super
end
def file_tree
files.file_tree
end
def files
controller[:file_filter]
end
def vim
controller[:vim].vim
end
def add_path(path)
file_tree.initial_adding do
file_tree.add_path(path)
end
end

def post_setup
super

@excludes.each do |rule|
file_tree.exclude! rule
end unless @excludes.blank?

# If there are no files given, open an empty window
# If files are specified on the command line, use them
ARGV.each do |file|
path = File.expand_path(file)
add_path(path)
#window.vim.open(path, :tab)
end
end

def run
GLib::Timeout.add(23) do
vim.start
false
end
super
end
end

icon_path = File.join( File.dirname(__FILE__), '..', 'images', 'vimmate48.png' )
Gtk::Window.set_default_icon(icon_path)

app = VimMateApp.new(:title => 'VimMate', :main_window => 'VimMate', :excludes => excludes)
app = VimMate::App.new(:title => 'VimMate', :main_window => 'VimMate', :excludes => excludes)
app.start


Expand Down
30 changes: 17 additions & 13 deletions config/environment.rb
@@ -1,25 +1,29 @@
require 'rubygems'
require 'active_support'


APP_ROOT = File.expand_path( File.join( File.dirname(__FILE__), '..' ) )
PROGRAM_NAME = 'vim_mate'

#ActiveSupport::Dependencies::logger = Logger.new( File.expand_path('log/dependencies.log') )
#ActiveSupport::Dependencies::log_activity = true
ActiveSupport::Dependencies::load_paths << File.join(APP_ROOT, "lib")
ActiveSupport::Dependencies::load_paths << File.join(APP_ROOT, "controllers")
ActiveSupport::Dependencies::load_paths << File.join(APP_ROOT, "lib/vim_mate")
require 'gtk2'
require 'i18n' # activesupport needs this
require 'active_support'
require 'active_support/core_ext/object'
require 'yaml'# for DotFile

$:.unshift APP_ROOT

VimMate::Requirer.require_exit('gtk2')
VimMate::Requirer.require_exit('libglade2')
require 'lib/active_window'
require 'lib/listed_file'
require 'lib/listed_directory'
require 'lib/file_tree_store.rb'
require 'lib/filtered_file_tree_store.rb'
require 'lib/vim'
require 'lib/vim_mate'


#require 'vimmatelib/file_tree_view'
require_dependency 'gtk_thread_helper'
require_dependency 'plugins'
require 'gtk_thread_helper'

require_dependency 'active_window'
require 'active_window'

%w(
file_created file_modified file_deleted file_opened
Expand All @@ -31,5 +35,5 @@
end

Dir[File.join(APP_ROOT, 'controllers', '*_controller.rb' )].each do |controller_path|
require_dependency File.basename(controller_path)
require controller_path
end
3 changes: 1 addition & 2 deletions controllers/file_filter_controller.rb
Expand Up @@ -71,8 +71,7 @@ def expand_first_row
file_tree_view.expand_row(Gtk::TreePath.new("0"), false)
end

def button_pressed(given)
event = given[:event]
def button_pressed(given, event)
if event.kind_of? Gdk::EventButton and event.button == 3
path = file_tree_view.get_path_at_pos(event.x, event.y)
file_tree_view.selection.select_path(path[0]) if path
Expand Down
3 changes: 1 addition & 2 deletions controllers/vim_mate_controller.rb
Expand Up @@ -28,8 +28,7 @@ def post_setup
#end
end

def pressed_key(given)
return unless event = given[:event]
def pressed_key(given, event)
if event.state & Gdk::Window::ModifierType::CONTROL_MASK != 0
if event.state & Gdk::Window::ModifierType::SHIFT_MASK != 0
case event.keyval
Expand Down
20 changes: 14 additions & 6 deletions lib/active_window.rb
@@ -1,8 +1,16 @@
module ActiveWindow

end
require_dependency 'active_window/signal'
require_dependency 'active_window/active_tree_store/columns'
require_dependency 'active_window/active_tree_store/index'
require_dependency 'active_window/active_tree_store/extentions'
require_dependency 'active_window/filtered_active_tree_store'

$:.unshift File.dirname(__FILE__)

require 'active_window/signal'
require 'active_window/listed_item'
require 'active_window/controller'
require 'active_window/dot_file'
require 'active_window/active_column'
require 'active_window/active_tree_store/index'
require 'active_window/active_tree_store/columns'
require 'active_window/active_tree_store/extentions' # must be _extensions
require 'active_window/active_tree_store'
require 'active_window/filtered_active_tree_store'
require 'active_window/application'
66 changes: 26 additions & 40 deletions lib/active_window/application.rb
Expand Up @@ -2,19 +2,29 @@ class ActiveWindow::Application
include ActiveSupport::Callbacks
define_callbacks :after_initialize

attr_accessor :controller, :database, :glade, :window
attr_accessor :controller, :database, :window
attr_reader :builder

def self.widget(*widgets)
widgets.each do |widget|
name = widget.to_s.camelize
define_method widget do
builder[name]
end
end
end

def widget(name)
glade[name]
builder[name]
end

def initialize(options = {})
@glade = GladeXML.new(find_glade, nil, options[:title] || 'application' )
@builder = Gtk::Builder.new
@builder.add_from_file(find_view)
@window = widget(options[:main_window] || 'main_window')
@window.signal_connect("destroy") { Gtk.main_quit }
@dot_file_prefs = DotFile.read
@dot_file_prefs = ActiveWindow::DotFile.read
@database = options[:database]
define_widget_readers
run_callbacks :after_initialize
end

Expand Down Expand Up @@ -49,18 +59,11 @@ def setup
name = klass.to_s.sub('Controller','').underscore.to_sym # eg MyFirstController -> :my_first
controller[name] = ctrl
end

glade.signal_autoconnect_full do |source, target, signal, handler, data|
# for example:
# source : instance of Gtk::ImageMenuItem
# target : nil
# signal : activate, clicked, pressed, etc.
# handler : window.close, which would call WindowController.close()
# data : nil
#puts [source, target, signal, handler, data].inspect
source.signal_connect(signal) { |widget,event| self.dispatch(handler, :source => source, :target => target, :signal => signal, :handler => handler, :data => data, :widget => widget, :event => event) }
#source.signal_connect(signal) { self.(handler, data) }

builder.connect_signals do |handler_name|
dispatch(handler_name)
end

post_setup
end

Expand All @@ -71,10 +74,10 @@ def post_setup
end
end

## gets a handler like "config.reset_settings"
## returns the method (reset_settings) of the controller (ConfigController) to use as a callback
##
## dispatch a signal to the correct controller
##
def dispatch(handler, event)
def dispatch(handler)
controller_name,action = handler.to_s.split('.')
unless controller_name and action
return(error "cannot parse handler '%s'" % handler)
Expand All @@ -92,12 +95,6 @@ def dispatch(handler, event)
end

method = ctrl.method(action)
#puts "calling %s.%s" % [controller_name.camelize, action]
if method.arity == 0
method.call
else
method.call(event)
end
end


Expand All @@ -111,27 +108,16 @@ def error(msg)
puts msg
end

def find_glade
Dir.glob("#{views_directory}/*.glade") do |f|
# TODO find the *.ui file according to app name or whatever
def find_view
Dir.glob("#{views_directory}/*.ui") do |f|
return f
end
raise "could not find a .glade file in #{views_directory}"
raise "could not find a .ui file in #{views_directory}"
end

def views_directory
File.join(APP_ROOT, 'views')
end

def define_widget_readers
glade.widget_names.each do |widget|
meth = widget.underscore
instance_eval <<-EOEVAL
@#{meth} = glade['#{widget}']
def #{meth}
@#{meth}
end
EOEVAL
end
end

end
3 changes: 1 addition & 2 deletions lib/active_window/controller.rb
@@ -1,5 +1,4 @@
# require 'libglade2'
# require 'gtk2'
require 'singleton'

class ActiveWindow::Controller
include Singleton
Expand Down
9 changes: 9 additions & 0 deletions lib/vim.rb
@@ -0,0 +1,9 @@
module Vim
end

require 'vim/buffers.rb'
require 'vim/netbeans.rb'
require 'vim/integration.rb'



12 changes: 12 additions & 0 deletions lib/vim_mate.rb
@@ -0,0 +1,12 @@
module VimMate
end

$:.unshift File.dirname(__FILE__)

require 'vim_mate/requirer'
require 'vim_mate/nice_singleton'
require 'vim_mate/vim_widget'
require 'vim_mate/config'
require 'vim_mate/icons'
require 'vim_mate/plugins'
require 'vim_mate/app'
56 changes: 56 additions & 0 deletions lib/vim_mate/app.rb
@@ -0,0 +1,56 @@
module VimMate
class App < ActiveWindow::Application
def initialize(opts={})
@excludes = opts.delete(:excludes)
super
end
def file_tree
files.file_tree
end
def files
controller[:file_filter]
end
def vim
controller[:vim].vim
end

widget :file_tree_view
widget :tree_scroller
widget :main_pane
widget :general_config
widget :files_filter_button
widget :files_pane
widget :file_popup
widget :files_filter_term

def add_path(path)
file_tree.initial_adding do
file_tree.add_path(path)
end
end

def post_setup
super

@excludes.each do |rule|
file_tree.exclude! rule
end unless @excludes.blank?

# If there are no files given, open an empty window
# If files are specified on the command line, use them
ARGV.each do |file|
path = File.expand_path(file)
add_path(path)
#window.vim.open(path, :tab)
end
end

def run
GLib::Timeout.add(23) do
vim.start
false
end
super
end
end
end
4 changes: 2 additions & 2 deletions lib/vim_mate/plugins.rb
@@ -1,6 +1,6 @@
plugin_dir = File.expand_path File.dirname(__FILE__) + '/plugins'

Dir["#{plugin_dir}/*/init.rb"].each do |plugin_init|
ActiveSupport::Dependencies::load_paths << File.dirname(plugin_init)
require_dependency plugin_init
$: << File.dirname(plugin_init)
require plugin_init
end
4 changes: 2 additions & 2 deletions lib/vim_mate/plugins/inotify/init.rb
@@ -1,4 +1,4 @@
require_dependency 'lib/INotify'
require_dependency 'lib/directory'
require 'lib/INotify'
require 'lib/directory'
ListedDirectory.class_eval { include VimMate::Plugin::INotifyDirectory }

4 changes: 3 additions & 1 deletion lib/vim_mate/vim_widget.rb
Expand Up @@ -97,13 +97,15 @@ def jump_to_line(line)

# Start Vim's window. This must be called after the window which
# will contain Vim is visible.
# FIXME disabled netbeans, crashes to often
def start
return if @vim_started
return unless @gtk_socket
@vim_started = true
listen
fork do
exec %Q[#{Executable} --servername #{@vim_server_name} --socketid #{@gtk_socket.id} -nb:localhost:#{port}:#{Password} -S #{extras_source_path}]
#exec %Q[#{Executable} --servername #{@vim_server_name} --socketid #{@gtk_socket.id} -nb:localhost:#{port}:#{Password} -S #{extras_source_path}]
exec %Q[#{Executable} --servername #{@vim_server_name} --socketid #{@gtk_socket.id} -S #{extras_source_path}]
end
self
end
Expand Down

0 comments on commit 3946279

Please sign in to comment.