Implement ActionList::Entry#clear.
[kaya.git] / lib / auto_reload.rb
blob18cd7a96b6338e7104a8cf459f032fb2e2239abb
1 # Copyright (c) 2010 Paolo Capriotti <p.capriotti@gmail.com>
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 require 'toolkit'
10 class AutoReload  
11   def self.start(basedir)
12     if @notifier
13       warn "AutoReload already started"
14     else
15       @notifier = new(File.expand_path(basedir))
16     end
17   end
18   
19   def initialize(basedir)
20     @watch = KDE::DirWatch.new
21     @watch.add_dir(basedir, KDE::DirWatch::WatchSubDirs)
22     @watch.on(:dirty) do |filename|
23       if filename =~ /\.rb$/
24         warn "reloading #{filename}"
25         begin
26           load(filename)
27         rescue Exception => e
28           warn e
29         end
30       end
31     end
32   end
33 end