Hi,

the following patch does fix #360 and #365 and fixes the regression of being able to store the source in the Journal.

Additions:
_('Instance Source')

_('Activity Bundle Source')

_('View Source')

Those two were present before, so we even could copy the translations we have for them over. I would be willing to help with that.

_('Keep')

_('Source')

I know it is late in the cycle, but I still would like to add this and therefore ask for an exception.

Thanks,
   Simon
diff --git a/extensions/globalkey/viewsource.py b/extensions/globalkey/viewsource.py
index 3afdc29..11b905e 100644
--- a/extensions/globalkey/viewsource.py
+++ b/extensions/globalkey/viewsource.py
@@ -30,9 +30,11 @@ import gconf
 from sugar.graphics import style
 from sugar.graphics.icon import Icon
 from sugar.graphics.xocolor import XoColor
+from sugar.graphics.menuitem import MenuItem
 from sugar.graphics.toolbutton import ToolButton
 from sugar.graphics.radiotoolbutton import RadioToolButton
 from sugar.bundle.activitybundle import ActivityBundle
+from sugar.datastore import datastore
 from sugar import mime
 
 from jarabe.model import shell
@@ -199,7 +201,51 @@ class ViewSource(gtk.Window):
             self._selected_file = file_path
         else:
             self._source_display.file_path = None
+
+class DocumentButton(RadioToolButton):
+    __gtype_name__ = 'SugarDocumentButton'
     
+    def __init__(self, file_name, document_path, title):
+        RadioToolButton.__init__(self)
+
+        self._document_path = document_path
+        self._title = title
+        self.props.tooltip = _('Instance Source')
+
+        client = gconf.client_get_default()
+        self._color = client.get_string('/desktop/sugar/user/color')
+        icon = Icon(file=file_name,
+                    icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR,
+                    xo_color=XoColor(self._color))
+        self.set_icon_widget(icon)
+        icon.show()
+
+        menu_item = MenuItem(_('Keep'))
+        icon = Icon(icon_name='document-save', icon_size=gtk.ICON_SIZE_MENU, 
+                    xo_color=XoColor(self._color))
+        menu_item.set_image(icon)
+
+        menu_item.connect('activate', self.__keep_in_journal_cb)
+        self.props.palette.menu.append(menu_item)
+        menu_item.show()
+
+    def __keep_in_journal_cb(self, menu_item):
+        mime_type = mime.get_from_file_name(self._document_path)
+        if mime_type == 'application/octet-stream':
+            mime_type = mime.get_for_file(self._document_path)
+
+        jobject = datastore.create()
+        title = _('Source') + ': ' + self._title
+        jobject.metadata['title'] = title
+        jobject.metadata['keep'] = '0'
+        jobject.metadata['buddies'] = ''
+        jobject.metadata['preview'] = ''
+        jobject.metadata['icon-color'] = self._color
+        jobject.metadata['mime_type'] = mime_type
+        jobject.metadata['source'] = '1'
+        jobject.file_path = self._document_path
+        datastore.write(jobject)
+
 class Toolbar(gtk.Toolbar):
     __gtype_name__ = 'SugarViewSourceToolbar'
 
@@ -217,19 +263,11 @@ class Toolbar(gtk.Toolbar):
 
         self._add_separator()
 
-        client = gconf.client_get_default()
-        color = XoColor(client.get_string('/desktop/sugar/user/color'))
         activity_bundle = ActivityBundle(bundle_path)
         file_name = activity_bundle.get_icon()
 
         if document_path is not None and os.path.exists(document_path):
-            document_button = RadioToolButton()
-            icon = Icon(file=file_name,
-                        icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR,
-                        xo_color=color)
-            document_button.set_icon_widget(icon)
-            icon.show()
-            document_button.props.tooltip = _('Document')            
+            document_button = DocumentButton(file_name, document_path, title)
             document_button.connect('toggled', self.__button_toggled_cb, 
                                     document_path)
             self.insert(document_button, -1)
@@ -246,7 +284,7 @@ class Toolbar(gtk.Toolbar):
             icon.show()
             if document_path is not None:
                 activity_button.props.group = document_button
-            activity_button.props.tooltip = _('Activity')
+            activity_button.props.tooltip = _('Activity Bundle Source')
             activity_button.connect('toggled', self.__button_toggled_cb, 
                                     bundle_path)
             self.insert(activity_button, -1)
diff --git a/src/jarabe/view/palettes.py b/src/jarabe/view/palettes.py
index 64637a9..66f49e8 100644
--- a/src/jarabe/view/palettes.py
+++ b/src/jarabe/view/palettes.py
@@ -68,6 +68,12 @@ class CurrentActivityPalette(BasePalette):
 
         # TODO: share-with, keep
 
+        accelerator = ' (Alt+Shift+v)'
+        menu_item = MenuItem(_('View Source') + accelerator, 'view-source')
+        menu_item.connect('activate', self.__view_source__cb)
+        self.menu.append(menu_item)
+        menu_item.show()
+
         separator = gtk.SeparatorMenuItem()
         self.menu.append(separator)
         separator.show()
@@ -80,6 +86,10 @@ class CurrentActivityPalette(BasePalette):
     def __resume_activate_cb(self, menu_item):
         self._home_activity.get_window().activate(gtk.get_current_event_time())
 
+    def __view_source__cb(self, menu_item):
+        import globalkey.viewsource
+        globalkey.viewsource.handle_key_press('')
+
     def __stop_activate_cb(self, menu_item):
         self._home_activity.get_window().close(1)
 
_______________________________________________
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel

Reply via email to