Class: Merrol::FileController

Inherits:
Controller show all
Defined in:
lib/merrol/controllers/file_controller.rb

Instance Method Summary collapse

Methods inherited from Controller

#method_missing, #name

Constructor Details

#initialize(commands, views) ⇒ FileController

Returns a new instance of FileController.



3
4
5
6
# File 'lib/merrol/controllers/file_controller.rb', line 3

def initialize commands, views
  super commands, views
  @source_models = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Merrol::Controller

Instance Method Details

#load(path) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/merrol/controllers/file_controller.rb', line 32

def load path
  model = SourceModel.new(path)
  @source_models[path] = model
  model.style_scheme = edit_view.theme
  model.highlight_matching_brackets = edit_view.highlight_brackets
  model.modified = false
  model.place_cursor model.start_iter
  model.signal_connect('modified_changed') do
    if model.modified?
      file_status_view.file = File.app_relative('data/images/modified.svg')
    else
      file_status_view.file = File.app_relative('data/images/saved.svg')
    end
  end
  edit_view.buffer = model
  file_list_view.prepend path
end

#load_all(paths) ⇒ Object



50
51
52
53
54
# File 'lib/merrol/controllers/file_controller.rb', line 50

def load_all paths
  paths.each do |path|
    load path
  end
end

#saveObject



28
29
30
# File 'lib/merrol/controllers/file_controller.rb', line 28

def save
  edit_view.buffer.save
end

#switchObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/merrol/controllers/file_controller.rb', line 8

def switch
  return if file_list_view.empty?
  file_list_view.show if @second_switch
  @second_switch = true
  file_list_view.next
  edit_view.buffer = @source_models[file_list_view.selected]
  edit_view.scroll_to_cursor
  self.handler_id = main_view.signal_connect('key_release_event') do |widget, event|
    if event.keyval == Gdk::Keyval::GDK_Control_L
      @second_switch = false
      file_list_view.hide
      main_view.signal_handler_disconnect(handler_id)
      file_list_view.selected_to_top
      true
    else
      false
    end
  end
end