Skip to content

Commit

Permalink
Middle click will now paste the selected text (code only).
Browse files Browse the repository at this point in the history
Fixes issue #25
  • Loading branch information
noamraph committed Mar 3, 2013
1 parent 4c28940 commit a3a4127
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
12 changes: 11 additions & 1 deletion dreampielib/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ def create_sourcebufferview(self, page_num=None):
sv = gtksourceview2.View(sb)
sv.show()
sv.connect('focus-in-event', self.on_sourceview_focus_in)
sv.connect('button-press-event', self.on_sourceview_button_press_event)
_charwidth, charheight = self.get_char_width_height()
self.configure_sourceview(sv)

Expand Down Expand Up @@ -433,6 +434,12 @@ def on_sourceview_focus_in(self, _widget, _event):
self.textbuffer.get_iter_at_mark(
self.textbuffer.get_insert()))

def on_sourceview_button_press_event(self, _widget, event):
if event.button == 2 and self.textbuffer.get_has_selection():
commands = self.selection.get_commands_only()
self.sourcebuffer.insert_interactive_at_cursor(commands, True)
return True

def write(self, data, *tag_names):
self.textbuffer.insert_with_tags_by_name(
self.textbuffer.get_end_iter(), data, *tag_names)
Expand Down Expand Up @@ -1405,7 +1412,10 @@ def on_textview_button_press_event(self, _widget, event):
self.show_popup_menu(event)
return True

if event.type == gdk._2BUTTON_PRESS:
elif event.button == 2:
return self.on_sourceview_button_press_event(_widget, event)

elif event.type == gdk._2BUTTON_PRESS:
return self.on_double_click(event)

def show_popup_menu(self, event):
Expand Down
18 changes: 11 additions & 7 deletions dreampielib/gui/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,7 @@ def copy(self):
else:
beep()

def copy_commands_only(self):
if self.sourcebuffer.get_has_selection():
self.sourcebuffer.copy_clipboard(self.clipboard)
return
if not self.textbuffer.get_has_selection():
beep()
return
def get_commands_only(self):
# We need to copy the text which has the COMMAND tag, doesn't have
# the PROMPT tag, and is selected.
tb = self.textbuffer
Expand All @@ -109,6 +103,16 @@ def copy_commands_only(self):
r.append(get_text(tb, it, it2))
it = it2
r = ''.join(r)
return r

def copy_commands_only(self):
if self.sourcebuffer.get_has_selection():
self.sourcebuffer.copy_clipboard(self.clipboard)
return
if not self.textbuffer.get_has_selection():
beep()
return
r = self.get_commands_only()
if not r:
beep()
else:
Expand Down

0 comments on commit a3a4127

Please sign in to comment.