← Back to team overview

gtg team mailing list archive

[Merge] lp:~joaoricardoascenso/gtg/bug495246 into lp:gtg

 

Joao ascenso has proposed merging lp:~joaoricardoascenso/gtg/bug495246 into lp:gtg.

Requested reviews:
  Gtg developers (gtg)

For more details, see:
https://code.launchpad.net/~joaoricardoascenso/gtg/bug495246/+merge/56881

Fixed bug 495246

Changes the tag menu in the task editor for a check box menu. The bug also asked for ordered itens, but im my tests all itens were already ordered automatically.
-- 
https://code.launchpad.net/~joaoricardoascenso/gtg/bug495246/+merge/56881
Your team Gtg developers is requested to review the proposed merge of lp:~joaoricardoascenso/gtg/bug495246 into lp:gtg.
=== modified file 'AUTHORS'
--- AUTHORS	2011-04-05 19:00:08 +0000
+++ AUTHORS	2011-04-08 06:17:28 +0000
@@ -74,3 +74,4 @@
 * Daniel Neel <dneelyep@xxxxxxxxx>
 * Ivan Evtukhovich <evtuhovich@xxxxxxxxx>
 * Madhumitha Viswanathan <madhuvishy@xxxxxxxxx>
+* Joao Ascenso <joaoricardoascenso@xxxxxxxxx>

=== modified file 'CHANGELOG'
--- CHANGELOG	2011-04-05 19:00:08 +0000
+++ CHANGELOG	2011-04-08 06:17:28 +0000
@@ -1,4 +1,5 @@
 ????-??-?? Getting Things GNOME! ?.?.?
+    * Changed the tag menu list in task editing to be a list of checkboxes
     * Fixed crash traceback when pressing 'delete' key, by Jeff Oliver
     * Added link to web documentation in Help menu, by Ronan Jouchet
     * Fixed bug with data consistency #579189, by Marko Kevac

=== modified file 'GTG/gtk/editor/editor.py'
--- GTG/gtk/editor/editor.py	2010-09-15 05:02:01 +0000
+++ GTG/gtk/editor/editor.py	2011-04-08 06:17:28 +0000
@@ -158,6 +158,9 @@
         self.plugin_api = PluginAPI(self.req, self.vmanager, self)
         self.pengine.register_api(self.plugin_api)
         self.pengine.onTaskLoad(self.plugin_api)
+        
+        #menu itens for the checkboxmenu
+        self.menu = gtk.Menu()
 
         #Putting the refresh callback at the end make the start a lot faster
         self.textview.refresh_callback(self.refresh_editor)
@@ -323,26 +326,41 @@
         if startdate != prevdate or type(startdate) is not type(prevdate):
             zedate = str(startdate).replace("-",date_separator)
             self.startdate_widget.set_text(zedate) 
-        #Refreshing the tag list in the insert tag button
+        self.refresh_menu()
+        if refreshtext:
+            self.textview.modified(refresheditor=False)
+        if to_save:
+            self.light_save()
+    
+    #Refreshing the tag Checkboxlist in the insert tag button
+    def refresh_menu(self):
+        
+        menu = self.menu
+        menu = gtk.Menu()
         taglist = self.req.get_used_tags()
-        menu = gtk.Menu()
+        tasktaglist = self.task.get_tags()
         tag_count = 0
         for tagname in taglist:
             tag_object = self.req.get_tag(tagname)
-            if not tag_object.is_special() and \
-               not self.task.has_tags(tag_list=[tagname]):
+            if not tag_object.is_special():
                 tag_count += 1
-                mi = gtk.MenuItem(label = tagname, use_underline=False)
-                mi.connect("activate", self.inserttag, tagname)
+                #bug#495246 change to a checkbox
+                mi = gtk.CheckMenuItem(tagname)
+                #if its an active tag, check the checkbox
+                if self.task.has_tags(tag_list=[tagname]):
+					mi.set_active(True)
+                mi.connect("activate", self.inserttag, tagname, mi.get_active())
+                #save the label of the button
+                mi.set_data("label", tagname)
                 mi.show()
                 menu.append(mi)
         if tag_count > 0 :
             self.inserttag_button.set_menu(menu)
-
-        if refreshtext:
-            self.textview.modified(refresheditor=False)
-        if to_save:
-            self.light_save()
+        else:
+            menu=gtk.Menu()
+            #avoids a bug with the last tag allways showing, but shows an empty menu
+            #need the oposite of self.inserttag_button.set_menu(menu)
+            self.inserttag_button.set_menu(menu)
 
     def date_changed(self,widget,data):
         text = widget.get_text()
@@ -459,9 +477,23 @@
         else :
             self.textview.insert_text(" @",itera)
         self.textview.grab_focus()
+        
 
-    def inserttag(self,widget,tag) : #pylint: disable-msg=W0613
-        self.textview.insert_tags([tag])
+    #tag - name of the tag clicked @example
+    #state - boolean that represents the state of the checkbox
+    #missing automatic detecting of a previous same name tag after removing
+    #unless a tag is manualy changed, in that case it detects and adds
+    def inserttag(self,widget,tag,state) : #pylint: disable-msg=W0613
+        
+        #note that the boolean is inversed
+        #if its a tag that's not active, insert it
+        if not state:
+            self.textview.insert_tags([tag])
+        #if its active remove it
+        else:
+            self.textview.remove_tagbyname(tag)
+        
+        self.textview.refresh_callback(self.refresh_editor)
         self.textview.grab_focus()
 
     def save(self) :

=== modified file 'GTG/gtk/editor/taskview.py'
--- GTG/gtk/editor/taskview.py	2010-06-02 18:12:23 +0000
+++ GTG/gtk/editor/taskview.py	2011-04-08 06:17:28 +0000
@@ -608,6 +608,7 @@
                 for ta in tags :
                     #removing deleted tags
                     if ta.get_data('is_tag') :
+                        
                         tagname = ta.get_data('tagname')
                         old_tags.append(tagname)
                         buff.remove_tag(ta,start,end)
@@ -680,7 +681,12 @@
         # we remove tags that are not in the description anymore
         for t in old_tags :
             if not t in new_tags :
+				#update window to update cheklist of tags
                 self.remove_tag_callback(t)
+        #refresh the window to update the taglistcheckbox
+        self.refresh(self.get_title())
+		    
+        
                 
     def is_at_title(self,buff,itera) :
         to_return = False
@@ -694,6 +700,54 @@
             to_return = True
         return to_return
         
+    #remove a all ocurrences of the tag in the text
+    #used to remove the tags when you click the checkbox
+    def remove_tagbyname(self, tag):
+        
+        buff = self.get_buffer()
+        it = self._apply_title(buff,True)
+        start = it.copy()
+        end = self._apply_title(buff,True)
+        end.forward_lines(self.get_buffer().get_line_count())
+        end2 = end.copy()
+        
+        table = buff.get_tag_table()
+        
+        #We must be strictly < than the end_offset. If not, we might
+        #find the beginning of a tag on the nextline
+        while (it.get_offset() < end.get_offset()) and (it.get_char() != '\0'):
+            if it.begins_tag() :
+                tags = it.get_toggled_tags(True)
+                for ta in tags :
+                    #removing deleted tags
+                    if ta.get_data('is_tag') :
+                        tagname = ta.get_data('tagname')
+                        #if the tag is the one we want to delete
+                        if tag == tagname:	
+                            self.remove_tag_callback(tagname)
+                            buff.remove_tag(ta,start,end)
+                            table.remove(ta)
+                            #Removing the marks if they exist
+                            mark1 = buff.get_mark(tagname)
+                            temp_it = it.copy();
+                            temp_it2 = it.copy();
+                            it.forward_cursor_positions(len(tagname))
+                            if mark1 :
+                                offset1 = buff.get_iter_at_mark(mark1).get_offset()
+                                if start.get_offset() <= offset1 <= end.get_offset() :    
+                                    buff.delete(temp_it,buff.get_iter_at_mark(mark1))
+                                    buff.delete_mark_by_name(tagname)
+                            mark2 = buff.get_mark("/%s"%tagname)
+                            if mark2 :
+                                offset2 = buff.get_iter_at_mark(mark2).get_offset()
+                                if start.get_offset() <= offset2 <= end.get_offset():
+                                    buff.delete(temp_it2,buff.get_iter_at_mark(mark2))
+                                    buff.delete_mark_by_name("/%s"%tagname)
+                            #ends the removal
+                            return                         
+            
+            it.forward_char()
+        
     #When the user removes a selection, we remove subtasks and @tags
     #from this selection
     def _delete_range(self,buff,start,end) :