@@ -50,20 +50,21 @@ def on_selection_modified(self, view):
50
50
# Show details in output panel of selected variable in context window
51
51
if view .name () == V .TITLE_WINDOW_CONTEXT :
52
52
V .show_context_output (view )
53
+ elif view .name () == V .TITLE_WINDOW_BREAKPOINT :
54
+ V .toggle_breakpoint (view )
53
55
else :
54
56
pass
55
57
56
58
57
59
class XdebugBreakpointCommand (sublime_plugin .TextCommand ):
58
60
"""
59
61
Add/Remove breakpoint(s) for rows (line numbers) in selection.
60
-
61
- TODO: By argument setting expression for conditional breakpoint
62
62
"""
63
- def run (self , edit , rows = None , expression = None ):
63
+ def run (self , edit , rows = None , condition = None , enabled = None , filename = None ):
64
64
# Get filename in current view and check if is a valid filename
65
- filename = self .view .file_name ()
66
- if not filename :
65
+ if filename is None :
66
+ filename = self .view .file_name ()
67
+ if not filename or not os .path .isfile (filename ):
67
68
return
68
69
69
70
# Add entry for file in breakpoint data
@@ -76,40 +77,76 @@ def run(self, edit, rows=None, expression=None):
76
77
77
78
# Loop through rows
78
79
for row in rows :
79
- # Add breakpoint
80
- if row not in S .BREAKPOINT [filename ]:
81
- S .BREAKPOINT [filename ][row ] = { 'id' : None , 'enabled' : True , 'expression' : expression }
82
- if session .is_connected ():
80
+ expression = None
81
+ if condition is not None and len (condition .strip ()) > 0 :
82
+ expression = condition
83
+ # Check if breakpoint exists
84
+ breakpoint_exists = row in S .BREAKPOINT [filename ]
85
+ # Disable/Remove breakpoint
86
+ if breakpoint_exists :
87
+ if session .is_connected () and S .BREAKPOINT [filename ][row ]['id' ] is not None :
83
88
try :
84
- S .SESSION .send (dbgp .BREAKPOINT_SET , t = 'line' , f = util . get_real_path ( filename , True ), n = row )
89
+ S .SESSION .send (dbgp .BREAKPOINT_REMOVE , d = S . BREAKPOINT [ filename ][ row ][ 'id' ] )
85
90
response = S .SESSION .read ().firstChild
86
- breakpoint_id = response .getAttribute ('id' )
87
- if breakpoint_id :
88
- S .BREAKPOINT [filename ][row ]['id' ] = breakpoint_id
89
91
except (socket .error , session .ProtocolConnectionException ):
90
92
e = sys .exc_info ()[1 ]
91
93
session .connection_error ("%s" % e )
92
- # Remove breakpoint
93
- else :
94
- if session .is_connected () and S .BREAKPOINT [filename ][row ]['id' ] is not None :
94
+ if enabled is False :
95
+ S .BREAKPOINT [filename ][row ]['enabled' ] = False
96
+ elif enabled is None :
97
+ del S .BREAKPOINT [filename ][row ]
98
+ # Add/Enable breakpoint
99
+ if not breakpoint_exists or enabled is True :
100
+ if row not in S .BREAKPOINT [filename ]:
101
+ S .BREAKPOINT [filename ][row ] = { 'id' : None , 'enabled' : True , 'expression' : expression }
102
+ else :
103
+ S .BREAKPOINT [filename ][row ]['enabled' ] = True
104
+ if condition is not None :
105
+ S .BREAKPOINT [filename ][row ]['expression' ] = expression
106
+ else :
107
+ expression = S .BREAKPOINT [filename ][row ]['expression' ]
108
+ if session .is_connected ():
95
109
try :
96
- S .SESSION .send (dbgp .BREAKPOINT_REMOVE , d = S . BREAKPOINT [ filename ][ row ][ 'id' ] )
110
+ S .SESSION .send (dbgp .BREAKPOINT_SET , t = 'line' , f = util . get_real_path ( filename , True ), n = row , expression = expression )
97
111
response = S .SESSION .read ().firstChild
112
+ breakpoint_id = response .getAttribute ('id' )
113
+ if breakpoint_id :
114
+ S .BREAKPOINT [filename ][row ]['id' ] = breakpoint_id
98
115
except (socket .error , session .ProtocolConnectionException ):
99
116
e = sys .exc_info ()[1 ]
100
117
session .connection_error ("%s" % e )
101
- del S .BREAKPOINT [filename ][row ]
102
118
103
119
# Render breakpoint markers
104
120
V .render_regions ()
105
121
106
122
# Update breakpoint list
107
- V .show_content (V .DATA_BREAKPOINT )
123
+ try :
124
+ if sublime .active_window ().get_layout () == S .LAYOUT_DEBUG :
125
+ V .show_content (V .DATA_BREAKPOINT )
126
+ except :
127
+ pass
108
128
109
129
# Save breakpoint data to file
110
130
util .save_breakpoint_data ()
111
131
112
132
133
+ class XdebugConditionalBreakpointCommand (sublime_plugin .TextCommand ):
134
+ """
135
+ Add conditional breakpoint(s) for rows (line numbers) in selection.
136
+ """
137
+ def run (self , edit ):
138
+ self .view .window ().show_input_panel ('Breakpoint condition' , '' , self .on_done , self .on_change , self .on_cancel )
139
+
140
+ def on_done (self , condition ):
141
+ self .view .run_command ('xdebug_breakpoint' , {'condition' : condition , 'enabled' : True })
142
+
143
+ def on_change (self , line ):
144
+ pass
145
+
146
+ def on_cancel (self ):
147
+ pass
148
+
149
+
113
150
class XdebugClearBreakpointsCommand (sublime_plugin .TextCommand ):
114
151
"""
115
152
Clear all breakpoints in selected view.
0 commit comments