Class: RuDebug

Inherits:
Object
  • Object
show all
Defined in:
lib/rudebug/main.rb,
lib/rudebug/connect.rb

Defined Under Namespace

Classes: Page

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(glade_file) ⇒ RuDebug

Returns a new instance of RuDebug.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rudebug/main.rb', line 6

def initialize(glade_file)
  load_config()

  @glade_file = glade_file
  @glade = GladeXML.new(glade_file) do |handler|
    method(handler) rescue lambda { |*args| p [handler, *args] }
  end

  @window = @glade["main-window"]
  @notebook = @glade["session-notebook"]
  @notebook.homogeneous = false
  @notebook.remove_page(0)
  @notebook.show_tabs = false
  @pages = {}

  initialize_connect()

  @window.show
end

Instance Attribute Details

#glade_fileObject (readonly)

Returns the value of attribute glade_file.



4
5
6
# File 'lib/rudebug/main.rb', line 4

def glade_file
  @glade_file
end

#notebookObject (readonly)

Returns the value of attribute notebook.



4
5
6
# File 'lib/rudebug/main.rb', line 4

def notebook
  @notebook
end

#pagesObject (readonly)

Returns the value of attribute pages.



4
5
6
# File 'lib/rudebug/connect.rb', line 4

def pages
  @pages
end

#windowObject (readonly)

Returns the value of attribute window.



4
5
6
# File 'lib/rudebug/main.rb', line 4

def window
  @window
end

Instance Method Details

#config_pathObject



26
27
28
29
# File 'lib/rudebug/main.rb', line 26

def config_path()
  base_path = ENV["APPDATA"] || File.expand_path("~")
  File.join(base_path, ".rudebug_conf")
end

#connect_to(server, con_type) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/rudebug/connect.rb', line 109

def connect_to(server, con_type)
  @connection_status.text = @connect_text = "Connecting to %s..." % server

  @connect_thread = Thread.new do
    begin
      @connection = con_type.new
      @connection.on_session = method(:on_session)
      @connection.on_disconnect = method(:on_disconnect)
      @connection.connect(server)
    rescue Exception => error
      on_failure(error)
      sleep 2
      retry
    end
  end

  update_connect_buttons()
end

#current_pageObject



155
156
157
158
159
# File 'lib/rudebug/connect.rb', line 155

def current_page()
  active_page = @notebook.get_nth_page(@notebook.page)
  title = @notebook.get_tab_label_text(active_page)
  @pages[title]
end

#disconnectObject



141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/rudebug/connect.rb', line 141

def disconnect()
  connection = @connection
  on_disconnect()

  Thread.new do
    connection.disconnect unless connection.nil?

    unless @connect_thread.nil?
      @connect_thread.kill
      @connect_thread = nil
    end
  end
end

#initialize_connectObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rudebug/connect.rb', line 6

def initialize_connect()
  @connect_dlg = @glade["connect-dialog"]
  @connectdlg_entry = @glade["connectdlg-server-entry"]
  @connectdlg_type = @glade["connectdlg-type-combobox"]
  @connectdlg_btn = @glade["connectdlg-button"]

  load_connect_servers()

  @connect_btn = @glade["connect-button"]
  @disconnect_btn = @glade["disconnect-button"]
  @continue_btn = @glade["continue-button"]
  @step_into_btn = @glade["step-into-button"]
  @step_over_btn = @glade["step-over-button"]

  @connect_menuitem = @glade["connect-menuitem"]
  @disconnect_menuitem = @glade["disconnect-menuitem"]

  @connection_status = @glade["status-label"]
  @connect_dlg.transient_for = @window

  @connect_page = @notebook.get_nth_page(0)
  @not_connected = @connection_status.text
  @connection = nil
end

#load_configObject



31
32
33
34
35
36
37
# File 'lib/rudebug/main.rb', line 31

def load_config()
  @config = begin
    YAML.load(File.read(config_path)).to_hash
  rescue Exception
    {}
  end
end

#load_connect_serversObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rudebug/connect.rb', line 31

def load_connect_servers()
  default_servers = [
    "localhost:8989",
    "druby://localhost:42531"
  ]

  conf_servers = @config[:servers].to_ary rescue []
  servers = (conf_servers + default_servers).uniq

  servers.each do |server|
    @connectdlg_entry.append_text(server)
  end

  @connectdlg_entry.active = 0
end

#on_connect_button_clickedObject Also known as: on_connect_activate



56
57
58
59
# File 'lib/rudebug/connect.rb', line 56

def on_connect_button_clicked()
  @connect_dlg.show
  @connectdlg_btn.grab_focus
end

#on_connect_dialog_delete_event(dialog, event) ⇒ Object



67
68
69
# File 'lib/rudebug/connect.rb', line 67

def on_connect_dialog_delete_event(dialog, event)
  dialog.hide_on_delete
end

#on_connectdlg_button_clickedObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/rudebug/connect.rb', line 88

def on_connectdlg_button_clicked()
  text = @connectdlg_entry.active_text
  @connect_dlg.hide

  type_text = @connectdlg_type.active_text

  con_type = case type_text
    when "ruby-breakpoint" then Connection::Breakpoint
    when "ruby-debug" then Connection::RubyDebug
  end

  unless text[/:\d/]
    text += ":%d" % case type_text
      when "ruby-breakpoint" then "wtf".to_i(36) # >:)
      when "ruby-debug" then 8989
    end
  end

  connect_to(text, con_type)
end

#on_connectdlg_server_entry_changedObject



71
72
73
74
75
# File 'lib/rudebug/connect.rb', line 71

def on_connectdlg_server_entry_changed()
  text = @connectdlg_entry.active_text
  @connectdlg_type.active = text[/druby/i] ? 0 : 1
  @connectdlg_btn.sensitive = text.size > 0
end

#on_connectdlg_server_entry_key_press_event(server_entry, event) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/rudebug/connect.rb', line 77

def on_connectdlg_server_entry_key_press_event(server_entry, event)
  case event.keyval
    when Gdk::Keyval::GDK_Return then
      on_connectdlg_button_clicked()
    else
      return false
  end

  return true
end

#on_continue_button_clicked(btn) ⇒ Object



192
193
194
# File 'lib/rudebug/connect.rb', line 192

def on_continue_button_clicked(btn)
  btn.sensitive = false if current_page().continue().nil?
end

#on_disconnectObject



168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/rudebug/connect.rb', line 168

def on_disconnect()
  @connection = nil
  update_connect_buttons()
  update_session_buttons()

  @notebook.show_tabs = false
  # Remove pages (session and connection)
  # TODO: Only remove connection
  @notebook.remove_page(0) until @notebook.n_pages == 0

  @connection_status.text = @not_connected
  @notebook.append_page(@connect_page)
end

#on_disconnect_button_clickedObject Also known as: on_disconnect_activate



62
63
64
# File 'lib/rudebug/connect.rb', line 62

def on_disconnect_button_clicked()
  disconnect()
end

#on_failure(error) ⇒ Object



182
183
184
185
186
187
188
189
190
# File 'lib/rudebug/connect.rb', line 182

def on_failure(error)
  puts error, error.backtrace

  @connection_status.text = [
    @connect_text,
    "Failed: %s" % error,
    "Will reconnect..."
  ].join("\n\n")
end

#on_main_window_destroyObject Also known as: on_quit_activate



49
50
51
52
# File 'lib/rudebug/main.rb', line 49

def on_main_window_destroy()
  save_config()
  Gtk.main_quit()
end

#on_session(session) ⇒ Object



161
162
163
164
165
166
# File 'lib/rudebug/connect.rb', line 161

def on_session(session)
  @notebook.remove_page(0) # Remove connect page
  @notebook.show_tabs = true
  @pages[session.title] = Page.new(self, session)
  update_session_buttons()
end

#on_step_into_button_clicked(btn) ⇒ Object



196
197
198
# File 'lib/rudebug/connect.rb', line 196

def on_step_into_button_clicked(btn)
  btn.sensitive = false if current_page().step_into().nil?
end

#on_step_over_button_clicked(btn) ⇒ Object



200
201
202
# File 'lib/rudebug/connect.rb', line 200

def on_step_over_button_clicked(btn)
  btn.sensitive = false if current_page().step_over().nil?
end

#save_configObject



39
40
41
42
43
44
45
46
47
# File 'lib/rudebug/main.rb', line 39

def save_config()
  save_connect_servers()

  File.open(config_path, "w") do |file|
    file.puts(@config.to_yaml)
  end
rescue Exception
  # Ignored
end

#save_connect_serversObject



47
48
49
50
51
52
53
54
# File 'lib/rudebug/connect.rb', line 47

def save_connect_servers()
  servers = []
  @connectdlg_entry.model.each do |model, path, iter|
    servers << iter[0]
  end

  @config[:servers] = servers
end

#update_connect_buttonsObject



128
129
130
131
# File 'lib/rudebug/connect.rb', line 128

def update_connect_buttons()
  @connect_btn.sensitive = @connect_menuitem.sensitive = !@connection
  @disconnect_btn.sensitive = @disconnect_menuitem.sensitive = @connection
end

#update_session_buttonsObject



133
134
135
136
137
138
139
# File 'lib/rudebug/connect.rb', line 133

def update_session_buttons()
  has_page = current_page()
  @continue_btn.sensitive = has_page

  stepping = @connection.stepping_support?() if @connection
  @step_into_btn.sensitive = @step_over_btn.sensitive = stepping && has_page
end