示例#1
0
 def select_line( self, action ):
    doc = self.window.get_active_document()
    if doc:
       document.select_line(doc)
    return True
示例#2
0
 def on_key_press( self, view, event, data=None ):
    
    # didn't do nuffink guv
    handled = False;
    
    # get a nice unicode character
    char = unichr(Gdk.keyval_to_unicode(event.keyval))
    
    # if we got a null char use None instead
    if char == '\0':
       char = None
    
    # ignore modifiers except ctrl, alt and shift
    state = event.state & Gtk.accelerator_get_default_mod_mask()
    
    # which modifier combo did we have
    is_alt        = state == Gdk.ModifierType.MOD1_MASK
    is_ctrl       = state == Gdk.ModifierType.CONTROL_MASK
    is_ctrl_shift = state == Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.SHIFT_MASK
    
    #print gtk.gdk.keyval_name(event.keyval)
    
    buf = view.get_buffer()
    
    if is_ctrl:
       
       # ctrl + left - move cursor left one word
       if event.keyval == Gdk.KEY_Left:
          document.backward_word(buf, document.WORD_MOVE)
          self.view.scroll_mark_onscreen(buf.get_insert())
          handled = True
       
       # ctrl + right - move cursor right one word
       elif event.keyval == Gdk.KEY_Right:
          document.forward_word(buf, document.WORD_MOVE)
          self.view.scroll_mark_onscreen(buf.get_insert())
          handled = True
       
       # ctrl + backspace - delete to start/end of word
       elif event.keyval == Gdk.KEY_BackSpace:
          document.backward_word(buf, document.WORD_DELETE)
          self.view.scroll_mark_onscreen(buf.get_insert())
          handled = True
       
       # ctrl + delete - delete to start/end of word
       elif event.keyval == Gdk.KEY_Delete:
          document.forward_word(buf, document.WORD_DELETE)
          handled = True
       
    #   # ctrl + c - copy current line to clipboard if no selection
    #   elif event.keyval = Gdk.KEY_c:
    #      if not buf.get_has_selection():
    #         document.copy_line(buf, self.view.get_clipboard(gtk.gdk.SELECTION_CLIPBOARD), key == Gdk.KEY_x)
    #         handled = True
    #   
    #   # ctrl + x - cut current line to clipboard if no selection
    #   elif event.keyval = Gdk.KEY_x:
    #      if not buf.get_has_selection():
    #         document.copy_line(buf, self.view.get_clipboard(gtk.gdk.SELECTION_CLIPBOARD), key == Gdk.KEY_x)
    #         handled = True
    #   
    #   view.cut_clipboard()
    #   view.copy_clipboard() 
       
    elif is_ctrl_shift:
       
       # ctrl + shift + left - move cursor left one word
       if event.keyval == Gdk.KEY_Left:
          document.backward_word(buf, document.WORD_SELECT)
          handled = True
       
       # ctrl + shift + right - move cursor right one word
       elif event.keyval == Gdk.KEY_Right:
          document.forward_word(buf, document.WORD_SELECT)
          handled = True
       
       # ctrl + shift + A - select line
       elif event.keyval == Gdk.KEY_A:
          handled = document.select_line(view.get_buffer())
       
    elif is_alt:
       pass
    
    return handled