[Sugar-devel] Exception for 'View Source' strings in the sugar component

2009-02-19 Thread Simon Schampijer

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', 

Re: [Sugar-devel] Exception for 'View Source' strings in the sugar component

2009-02-19 Thread Tomeu Vizoso
Yup, would be nice to get those in if translators agree.

Regards,

Tomeu

2009/2/19 Simon Schampijer si...@schampijer.de:
 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

 ___
 Sugar-devel mailing list
 Sugar-devel@lists.sugarlabs.org
 http://lists.sugarlabs.org/listinfo/sugar-devel


___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


Re: [Sugar-devel] Exception for 'View Source' strings in the sugar component

2009-02-19 Thread Sayamindu Dasgupta
Given the feature is a long promised one ;-), and given that at least
some of the strings should appear elsewhere, and given that there is
around 10 more days to go for the final release, I think this can go
in.

+1

-sdg-


On Thu, Feb 19, 2009 at 2:01 PM, Simon Schampijer si...@schampijer.de wrote:
 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

 ___
 Sugar-devel mailing list
 Sugar-devel@lists.sugarlabs.org
 http://lists.sugarlabs.org/listinfo/sugar-devel





-- 
Sayamindu Dasgupta
[http://sayamindu.randomink.org/ramblings]
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel