foiegras r71 - in trunk: . src/foiegras/buffer



Author: denisw
Date: Mon Mar 17 10:22:33 2008
New Revision: 71
URL: http://svn.gnome.org/viewvc/foiegras?rev=71&view=rev

Log:
2008-03-17  Denis Washington  <denisw svn gnome org>

	* src/foiegras/buffer/docbuffer.py:
	Fix deleting the complete title and typing a new one, plus
	minor cleanup.


Modified:
   trunk/ChangeLog
   trunk/src/foiegras/buffer/docbuffer.py

Modified: trunk/src/foiegras/buffer/docbuffer.py
==============================================================================
--- trunk/src/foiegras/buffer/docbuffer.py	(original)
+++ trunk/src/foiegras/buffer/docbuffer.py	Mon Mar 17 10:22:33 2008
@@ -20,7 +20,7 @@
 import gobject
 
 from block_handler import block_handler
-from tags import INLINE_TAGS, BLOCK_TAGS, SIMPLE_BLOCK_TAGS, TAG_TABLE
+from tags import INLINE_TAGS, BLOCK_TAGS, SIMPLE_BLOCK_TAGS, TAG_TABLE, get_text_tag
 from open import open_document
 from save import save_document
 
@@ -39,12 +39,10 @@
         gtk.TextBuffer.__init__(self, TAG_TABLE)
 
         self.__filename = filename
-        self.__block_tag = "p"
         self.__activated_tags = set()
         self.__deactivated_tags = set()
         self.__manual_insert = False
 
-        self.connect("insert-text", self.__insert_text_cb)
         self.connect_after("insert-text", self.__insert_text_after_cb)
      
         if filename:
@@ -82,6 +80,7 @@
 
             self.apply_tag(self.get_tag_table().lookup("_readonly"), newline_iter, end_iter)
 
+
     def get_filename(self):
         """
         Returns the name of the file represented by the buffer.
@@ -207,8 +206,22 @@
                 tags = tags.intersection(applied)
                 it.forward_char()
 
-        if len(tags) == 0:
-            tags.add("p")
+        has_block_tag = False
+
+        for t in tags:
+            if t in BLOCK_TAGS:
+                has_block_tag = True
+
+        if not has_block_tag:
+            newline = start.copy()
+
+            if not newline.ends_line():
+                newline.forward_to_line_end()
+
+            if newline.has_tag(get_text_tag("title")):
+                tags.add("title")
+            else:
+                tags.add("p")
 
         return tags
 
@@ -221,26 +234,6 @@
         self.__manual_insert = False
 
 
-    def __insert_text_cb(self, textbuffer, location, text, length):
-        """
-        "insert-text" signal handler.
-        """
-        if not self.__manual_insert:
-            block_tag = None
-
-            for tag_name in BLOCK_TAGS:
-                tag = self.get_tag_table().lookup(tag_name)
-
-                if location.has_tag(tag):
-                    block_tag = tag_name
-
-            if block_tag:
-                self.__block_tag = block_tag
-            else:
-                self.__block_tag = "p"
-            
-
-
     def __insert_text_after_cb(self, textbuffer, location, text, length):
         """
         "insert-text" signal handler. (Runs after the default hander).
@@ -255,8 +248,6 @@
             for i in range(num_lines_back):
                 location.backward_line()
 
-            #self.apply_block_tag(self.__block_tag, location)
-
             start_iter = location.copy()
             start_iter.backward_chars(length)
 
@@ -289,7 +280,15 @@
         self.__deactivated_tags.clear()
 
         if len(active_tags) == 0:
-            active_tags.add("p")
+            newline = location.copy()
+
+            if not newline.ends_line():
+                newline.forward_to_line_end()
+
+            if newline.has_tag(get_text_tag("title")):
+                active_tags.add("title")
+            else:
+                active_tags.add("p")
 
         return active_tags
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]