~karlo-jez/gtg/gtgonline

« back to all changes in this revision

Viewing changes to dbusserver/GTG/tools/clipboard.py

  • Committer: Karlo Jež
  • Date: 2010-05-25 18:20:23 UTC
  • Revision ID: keks@keks-laptop-20100525182023-4iiio5ji2z9are00
Task treeview enhancements

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# -----------------------------------------------------------------------------
 
3
# Gettings Things Gnome! - a personal organizer for the GNOME desktop
 
4
# Copyright (c) 2008-2009 - Lionel Dricot & Bertrand Rousseau
 
5
#
 
6
# This program is free software: you can redistribute it and/or modify it under
 
7
# the terms of the GNU General Public License as published by the Free Software
 
8
# Foundation, either version 3 of the License, or (at your option) any later
 
9
# version.
 
10
#
 
11
# This program is distributed in the hope that it will be useful, but WITHOUT
 
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
13
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 
14
# details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License along with
 
17
# this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
# -----------------------------------------------------------------------------
 
19
 
 
20
"""
 
21
TaskClipboard allows to cut/copy the content of a TaskView accross multiples
 
22
taskeditors, preserving subtasks
 
23
"""
 
24
class TaskClipboard():
 
25
    def __init__(self,req):
 
26
        self.description = None
 
27
        self.content = []
 
28
        self.req = req
 
29
        
 
30
    """"take two gtk.TextIter as parameter and copy the
 
31
    """
 
32
    def copy(self,start,stop,bullet=None):
 
33
        self.clear()
 
34
        #Now, we take care of the normal, cross application clipboard
 
35
        text = start.get_text(stop)
 
36
        if text and bullet:
 
37
            #we replace the arrow by the original "-"
 
38
            newtext = text.replace(bullet, "-")
 
39
            self.description = newtext
 
40
        elif text:
 
41
            self.description = text
 
42
        
 
43
        end_line = start.copy()
 
44
        #we take line after line in the selection
 
45
        nextline = True
 
46
        while end_line.get_line() <= stop.get_line() and nextline:
 
47
            nextline = end_line.forward_line()
 
48
            end_line.backward_char()
 
49
            #we want to detect subtasks in the selection
 
50
            tags = end_line.get_tags()+end_line.get_toggled_tags(False)
 
51
            is_subtask = False
 
52
            for ta in tags :
 
53
                if (ta.get_data('is_subtask')):
 
54
                    is_subtask = True
 
55
                    tid = ta.get_data('child')
 
56
                    tas = self.req.get_task(tid)
 
57
                    tas.set_to_keep()
 
58
                    tas.sync()
 
59
                    self.content.append(['subtask', tid])
 
60
            if not is_subtask:
 
61
                if end_line.get_line() < stop.get_line():
 
62
                    self.content.append(['text', "%s\n" %start.get_text(end_line)])
 
63
                else:
 
64
                    self.content.append(['text', start.get_text(stop)])
 
65
            end_line.forward_char()
 
66
            start.forward_line()
 
67
 
 
68
    def paste_text(self):
 
69
        return self.description
 
70
        
 
71
    def paste(self):
 
72
        return self.content
 
73
    
 
74
    def clear(self):
 
75
        self.descriptiion = None
 
76
        self.content = []