Usability fixes for dnd on the clipboard
This commit is contained in:
parent
5103f1fb27
commit
eba35406c5
@ -130,6 +130,7 @@ class Shell(gobject.GObject):
|
|||||||
self._frame.notify_key_release()
|
self._frame.notify_key_release()
|
||||||
|
|
||||||
def __window_opened_cb(self, screen, window):
|
def __window_opened_cb(self, screen, window):
|
||||||
|
logging.debug('Shell.__window_opened_cb')
|
||||||
if window.get_window_type() == wnck.WINDOW_NORMAL:
|
if window.get_window_type() == wnck.WINDOW_NORMAL:
|
||||||
try:
|
try:
|
||||||
activity_host = ActivityHost(self.get_model(), window)
|
activity_host = ActivityHost(self.get_model(), window)
|
||||||
@ -143,6 +144,7 @@ class Shell(gobject.GObject):
|
|||||||
self.emit('activity-opened', activity_host)
|
self.emit('activity-opened', activity_host)
|
||||||
|
|
||||||
def __active_window_changed_cb(self, screen):
|
def __active_window_changed_cb(self, screen):
|
||||||
|
logging.debug('Shell.__active_window_changed_cb')
|
||||||
window = screen.get_active_window()
|
window = screen.get_active_window()
|
||||||
if not window or window.get_window_type() != wnck.WINDOW_NORMAL:
|
if not window or window.get_window_type() != wnck.WINDOW_NORMAL:
|
||||||
return
|
return
|
||||||
@ -157,6 +159,7 @@ class Shell(gobject.GObject):
|
|||||||
self._set_current_activity(activity_host)
|
self._set_current_activity(activity_host)
|
||||||
|
|
||||||
def __window_closed_cb(self, screen, window):
|
def __window_closed_cb(self, screen, window):
|
||||||
|
logging.debug('Shell.__window_closed_cb')
|
||||||
if window.get_window_type() != wnck.WINDOW_NORMAL:
|
if window.get_window_type() != wnck.WINDOW_NORMAL:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -207,6 +210,7 @@ class Shell(gobject.GObject):
|
|||||||
logging.error('Cannot start activity.')
|
logging.error('Cannot start activity.')
|
||||||
|
|
||||||
def start_activity(self, activity_type):
|
def start_activity(self, activity_type):
|
||||||
|
logging.debug('Shell.start_activity')
|
||||||
activity = ActivityFactory.create(activity_type)
|
activity = ActivityFactory.create(activity_type)
|
||||||
activity.execute('test', [])
|
activity.execute('test', [])
|
||||||
return activity
|
return activity
|
||||||
|
@ -79,6 +79,10 @@ class EventFrame(gobject.GObject):
|
|||||||
invisible.connect('enter-notify-event', self._enter_notify_cb)
|
invisible.connect('enter-notify-event', self._enter_notify_cb)
|
||||||
invisible.connect('leave-notify-event', self._leave_notify_cb)
|
invisible.connect('leave-notify-event', self._leave_notify_cb)
|
||||||
|
|
||||||
|
invisible.drag_dest_set(0, [], 0)
|
||||||
|
invisible.connect('drag_motion', self._drag_motion_cb)
|
||||||
|
invisible.connect('drag_leave', self._drag_leave_cb)
|
||||||
|
|
||||||
invisible.realize()
|
invisible.realize()
|
||||||
invisible.window.set_events(gtk.gdk.POINTER_MOTION_MASK |
|
invisible.window.set_events(gtk.gdk.POINTER_MOTION_MASK |
|
||||||
gtk.gdk.ENTER_NOTIFY_MASK |
|
gtk.gdk.ENTER_NOTIFY_MASK |
|
||||||
@ -89,9 +93,17 @@ class EventFrame(gobject.GObject):
|
|||||||
|
|
||||||
def _enter_notify_cb(self, widget, event):
|
def _enter_notify_cb(self, widget, event):
|
||||||
self._notify_enter(event.x, event.y)
|
self._notify_enter(event.x, event.y)
|
||||||
|
logging.debug('EventFrame._enter_notify_cb ' + str(self._hover))
|
||||||
|
|
||||||
def _motion_notify_cb(self, widget, event):
|
def _motion_notify_cb(self, widget, event):
|
||||||
self._notify_enter(event.x, event.y)
|
self._notify_enter(event.x, event.y)
|
||||||
|
logging.debug('EventFrame._motion_notify_cb ' + str(self._hover))
|
||||||
|
|
||||||
|
def _drag_motion_cb(self, widget, drag_context, x, y, timestamp):
|
||||||
|
drag_context.drag_status(0, timestamp);
|
||||||
|
self._notify_enter(x, y)
|
||||||
|
logging.debug('EventFrame._drag_motion_cb ' + str(self._hover))
|
||||||
|
return True
|
||||||
|
|
||||||
def _notify_enter(self, x, y):
|
def _notify_enter(self, x, y):
|
||||||
screen_w = gtk.gdk.screen_width()
|
screen_w = gtk.gdk.screen_width()
|
||||||
@ -110,6 +122,15 @@ class EventFrame(gobject.GObject):
|
|||||||
self.emit('enter-edge')
|
self.emit('enter-edge')
|
||||||
|
|
||||||
def _leave_notify_cb(self, widget, event):
|
def _leave_notify_cb(self, widget, event):
|
||||||
|
self._notify_leave()
|
||||||
|
logging.debug('EventFrame._leave_notify_cb ' + str(self._hover))
|
||||||
|
|
||||||
|
def _drag_leave_cb(self, widget, drag_context, timestamp):
|
||||||
|
self._notify_leave()
|
||||||
|
logging.debug('EventFrame._drag_leave_cb ' + str(self._hover))
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _notify_leave(self):
|
||||||
self._hover = EventFrame.HOVER_NONE
|
self._hover = EventFrame.HOVER_NONE
|
||||||
if self._active:
|
if self._active:
|
||||||
self.emit('leave')
|
self.emit('leave')
|
||||||
@ -220,8 +241,12 @@ class Frame:
|
|||||||
|
|
||||||
def _create_clipboard_panel(self, grid, x, y, width, height):
|
def _create_clipboard_panel(self, grid, x, y, width, height):
|
||||||
[x, y, width, height] = grid.rectangle(x, y, width, height)
|
[x, y, width, height] = grid.rectangle(x, y, width, height)
|
||||||
panel = ClipboardPanelWindow(x, y, width, height)
|
panel = ClipboardPanelWindow(self, x, y, width, height)
|
||||||
|
|
||||||
self._connect_to_panel(panel)
|
self._connect_to_panel(panel)
|
||||||
|
panel.connect('drag-motion', self._drag_motion_cb)
|
||||||
|
panel.connect('drag-leave', self._drag_leave_cb)
|
||||||
|
|
||||||
self._windows.append(panel)
|
self._windows.append(panel)
|
||||||
|
|
||||||
return panel
|
return panel
|
||||||
@ -253,12 +278,26 @@ class Frame:
|
|||||||
|
|
||||||
def _enter_notify_cb(self, window, event):
|
def _enter_notify_cb(self, window, event):
|
||||||
self._timeline.goto('slide_in', True)
|
self._timeline.goto('slide_in', True)
|
||||||
|
logging.debug('Frame._enter_notify_cb ' + str(self._mode))
|
||||||
|
|
||||||
|
def _drag_motion_cb(self, window, context, x, y, time):
|
||||||
|
self._timeline.goto('slide_in', True)
|
||||||
|
logging.debug('Frame._drag_motion_cb ' + str(self._mode))
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _drag_leave_cb(self, window, drag_context, timestamp):
|
||||||
|
self._leave_notify()
|
||||||
|
logging.debug('Frame._drag_leave_cb ' + str(self._mode))
|
||||||
|
|
||||||
def _leave_notify_cb(self, window, event):
|
def _leave_notify_cb(self, window, event):
|
||||||
# FIXME for some reason every click cause also a leave-notify
|
# FIXME for some reason every click cause also a leave-notify
|
||||||
if event.state == gtk.gdk.BUTTON1_MASK:
|
if event.state == gtk.gdk.BUTTON1_MASK:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self._leave_notify()
|
||||||
|
logging.debug('Frame._leave_notify_cb ' + str(self._mode))
|
||||||
|
|
||||||
|
def _leave_notify(self):
|
||||||
if self._active_menus == 0 and \
|
if self._active_menus == 0 and \
|
||||||
(self._mode == Frame.HIDE_ON_LEAVE or \
|
(self._mode == Frame.HIDE_ON_LEAVE or \
|
||||||
self._mode == Frame.AUTOMATIC):
|
self._mode == Frame.AUTOMATIC):
|
||||||
@ -267,14 +306,17 @@ class Frame:
|
|||||||
def _enter_edge_cb(self, event_frame):
|
def _enter_edge_cb(self, event_frame):
|
||||||
self._mode = Frame.HIDE_ON_LEAVE
|
self._mode = Frame.HIDE_ON_LEAVE
|
||||||
self._timeline.play(None, 'slide_in')
|
self._timeline.play(None, 'slide_in')
|
||||||
|
logging.debug('Frame._enter_edge_cb ' + str(self._mode))
|
||||||
|
|
||||||
def _enter_corner_cb(self, event_frame):
|
def _enter_corner_cb(self, event_frame):
|
||||||
self._mode = Frame.HIDE_ON_LEAVE
|
self._mode = Frame.HIDE_ON_LEAVE
|
||||||
self._timeline.play('slide_in', 'slide_in')
|
self._timeline.play('slide_in', 'slide_in')
|
||||||
|
logging.debug('Frame._enter_corner_cb ' + str(self._mode))
|
||||||
|
|
||||||
def _event_frame_leave_cb(self, event_frame):
|
def _event_frame_leave_cb(self, event_frame):
|
||||||
if self._mode != Frame.STICKY:
|
if self._mode != Frame.STICKY:
|
||||||
self._timeline.goto('slide_out', True)
|
self._timeline.goto('slide_out', True)
|
||||||
|
logging.debug('Frame._event_frame_leave_cb ' + str(self._mode))
|
||||||
|
|
||||||
def show_and_hide(self, seconds):
|
def show_and_hide(self, seconds):
|
||||||
self._mode = Frame.AUTOMATIC
|
self._mode = Frame.AUTOMATIC
|
||||||
|
@ -33,6 +33,9 @@ class _ContextMap:
|
|||||||
|
|
||||||
return object_id
|
return object_id
|
||||||
|
|
||||||
|
def has_context(self, context):
|
||||||
|
return context in self._context_map
|
||||||
|
|
||||||
class ClipboardBox(hippo.CanvasBox):
|
class ClipboardBox(hippo.CanvasBox):
|
||||||
|
|
||||||
def __init__(self, menu_shell):
|
def __init__(self, menu_shell):
|
||||||
@ -91,10 +94,12 @@ class ClipboardBox(hippo.CanvasBox):
|
|||||||
logging.debug('ClipboardBox: ' + object_id + ' state was changed.')
|
logging.debug('ClipboardBox: ' + object_id + ' state was changed.')
|
||||||
|
|
||||||
def drag_motion_cb(self, widget, context, x, y, time):
|
def drag_motion_cb(self, widget, context, x, y, time):
|
||||||
|
logging.debug('ClipboardBox._drag_motion_cb')
|
||||||
context.drag_status(gtk.gdk.ACTION_COPY, time)
|
context.drag_status(gtk.gdk.ACTION_COPY, time)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def drag_drop_cb(self, widget, context, x, y, time):
|
def drag_drop_cb(self, widget, context, x, y, time):
|
||||||
|
logging.debug('ClipboardBox._drag_drop_cb')
|
||||||
object_id = util.unique_id()
|
object_id = util.unique_id()
|
||||||
self._context_map.add_context(context, object_id, len(context.targets))
|
self._context_map.add_context(context, object_id, len(context.targets))
|
||||||
|
|
||||||
@ -117,6 +122,10 @@ class ClipboardBox(hippo.CanvasBox):
|
|||||||
else:
|
else:
|
||||||
logging.warn('ClipboardBox: empty selection for target ' + selection.target)
|
logging.warn('ClipboardBox: empty selection for target ' + selection.target)
|
||||||
|
|
||||||
|
# If it's the last target to be processed, finish the dnd transaction
|
||||||
|
if not self._context_map.has_context(context):
|
||||||
|
context.finish(True, False, time)
|
||||||
|
|
||||||
def drag_data_get_cb(self, widget, context, selection, targetType, eventTime):
|
def drag_data_get_cb(self, widget, context, selection, targetType, eventTime):
|
||||||
logging.debug("drag_data_get_cb: requested target " + selection.target)
|
logging.debug("drag_data_get_cb: requested target " + selection.target)
|
||||||
|
|
||||||
|
@ -8,9 +8,11 @@ from sugar.clipboard import clipboardservice
|
|||||||
from sugar import util
|
from sugar import util
|
||||||
|
|
||||||
class ClipboardPanelWindow(PanelWindow):
|
class ClipboardPanelWindow(PanelWindow):
|
||||||
def __init__(self, x, y, width, height):
|
def __init__(self, frame, x, y, width, height):
|
||||||
PanelWindow.__init__(self, x, y, width, height)
|
PanelWindow.__init__(self, x, y, width, height)
|
||||||
|
|
||||||
|
self._frame = frame
|
||||||
|
|
||||||
# Listening for new clipboard objects
|
# Listening for new clipboard objects
|
||||||
clipboard = gtk.Clipboard()
|
clipboard = gtk.Clipboard()
|
||||||
clipboard.connect("owner-change", self._owner_change_cb)
|
clipboard.connect("owner-change", self._owner_change_cb)
|
||||||
@ -52,6 +54,8 @@ class ClipboardPanelWindow(PanelWindow):
|
|||||||
if selection:
|
if selection:
|
||||||
self._add_selection(key, selection)
|
self._add_selection(key, selection)
|
||||||
|
|
||||||
|
self._frame.show_and_hide(0)
|
||||||
|
|
||||||
def _add_selection(self, key, selection):
|
def _add_selection(self, key, selection):
|
||||||
if selection.data:
|
if selection.data:
|
||||||
logging.debug('adding type ' + selection.type + '.')
|
logging.debug('adding type ' + selection.type + '.')
|
||||||
|
Loading…
Reference in New Issue
Block a user