[Dextrose] [PATCH] sl#3076: Add a submenu in journal-palette, to copy a journal entry to the "Documents" folder.

Ajay Garg ajay at activitycentral.com
Fri Feb 3 13:33:36 EST 2012


Now, the "Copy to" option for a journal- or mounted-drive-entry shows
the option to copy "Documents" folder as well.

Note that, this is in addition to the already-exising "Copy to Documents"
feature via "Drag-and-Drop".


 src/jarabe/journal/journalactivity.py |    5 ++++
 src/jarabe/journal/palettes.py        |   37 +++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/src/jarabe/journal/journalactivity.py b/src/jarabe/journal/journalactivity.py
index bb1c7f6..8cafef0 100644
--- a/src/jarabe/journal/journalactivity.py
+++ b/src/jarabe/journal/journalactivity.py
@@ -184,6 +184,7 @@ class JournalActivity(JournalWindow):
         search_toolbar = self._main_toolbox.search_toolbar
         search_toolbar.connect('query-changed', self._query_changed_cb)
         search_toolbar.set_mount_point('/')
+        self._mount_point = '/'
 
     def _setup_secondary_view(self):
         self._secondary_view = gtk.VBox()
@@ -253,6 +254,7 @@ class JournalActivity(JournalWindow):
     def __volume_changed_cb(self, volume_toolbar, mount_point):
         logging.debug('Selected volume: %r.', mount_point)
         self._main_toolbox.search_toolbar.set_mount_point(mount_point)
+        self._mount_point = mount_point
         self._main_toolbox.set_current_toolbar(0)
 
     def __model_created_cb(self, sender, **kwargs):
@@ -362,6 +364,9 @@ class JournalActivity(JournalWindow):
         self.show_main_view()
         self.search_grab_focus()
 
+    def get_mount_point(self):
+        return self._mount_point
+
 
 def get_journal():
     global _journal
diff --git a/src/jarabe/journal/palettes.py b/src/jarabe/journal/palettes.py
index e1d1e7d..27b0b54 100644
--- a/src/jarabe/journal/palettes.py
+++ b/src/jarabe/journal/palettes.py
@@ -272,6 +272,16 @@ class CopyMenu(gtk.Menu):
         self.append(clipboard_menu)
         clipboard_menu.show()
 
+        from jarabe.journal import journalactivity
+        journal_model = journalactivity.get_journal()
+        if journal_model.get_mount_point() != model.get_documents_path():
+            documents_menu = DocumentsMenu(self._metadata)
+            documents_menu.set_image(Icon(icon_name='user-documents',
+                                          icon_size=gtk.ICON_SIZE_MENU))
+            documents_menu.connect('volume-error', self.__volume_error_cb)
+            self.append(documents_menu)
+            documents_menu.show()
+
         if self._metadata['mountpoint'] != '/':
             client = gconf.client_get_default()
             color = XoColor(client.get_string('/desktop/sugar/user/color'))
@@ -375,6 +385,33 @@ class ClipboardMenu(MenuItem):
         self._temp_file_path = None
 
 
+class DocumentsMenu(MenuItem):
+    __gtype_name__ = 'JournalDocumentsMenu'
+
+    __gsignals__ = {
+        'volume-error': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
+                         ([str, str])),
+    }
+
+    def __init__(self, metadata):
+        MenuItem.__init__(self, _('Documents'))
+
+        self._temp_file_path = None
+        self._metadata = metadata
+        self.connect('activate', self.__copy_to_documents_cb)
+
+    def __copy_to_documents_cb(self, menu_item):
+        file_path = model.get_file(self._metadata['uid'])
+        if not file_path or not os.path.exists(file_path):
+            logging.warn('Entries without a file cannot be copied.')
+            self.emit('volume-error',
+                      _('Entries without a file cannot be copied.'),
+                      _('Warning'))
+            return
+
+        model.copy(self._metadata, model.get_documents_path())
+
+
 class GroupsMenu(gtk.Menu):
     __gtype_name__ = 'GroupsMenu'
 
-- 
1.7.4.4



More information about the Dextrose mailing list