Commits

Ali Gholami Rudi  committed 9541600

Showing modified editor status

  • Participants
  • Parent commits eb97bda

Comments (0)

Files changed (6)

File docs/stories.txt

   * Edit menu: cut, paste, undo, redo, revert
 
 
+* Asking whether to save buffer when exiting @ 4h
+
+
 * Showing modified file status @ 8h
 
 

File rope/core.py

         self.active_file_path = StringVar('')
         self.active_editor = None
 
+    def _editor_was_modified(self, editor):
+        new_title = editor.get_file().get_name()
+        if editor.get_editor().is_modified():
+            new_title = '*' + new_title
+        self.buttons[editor]['text'] = new_title
+
     def activate_editor(self, editor):
         if self.active_editor:
             self.active_editor.get_editor().getWidget().forget()
         title.pack(fill=BOTH, side=LEFT)
         self.activate_editor(editor)
         self.core._set_key_binding(editor.get_editor().getWidget())
+        editor.add_modification_observer(self._editor_was_modified)
         return editor
 
     def switch_active_editor(self):
         fileMenu.add_separator()
         fileMenu.add_command(label='Exit',
                              command=self.exit, underline=1)
+        
+        editMenu = Menu(self.menubar, tearoff=0)
+        self.menubar.add_cascade(label='Edit', menu=editMenu, underline=3)
+
+        codeMenu = Menu(self.menubar, tearoff=0)
+        self.menubar.add_cascade(label='Code', menu=editMenu, underline=1)
+
+        helpMenu = Menu(self.menubar, tearoff=0)
+        self.menubar.add_cascade(label='Help', menu=helpMenu, underline=3)
 
     def _set_key_binding(self, widget):
         widget.bind('<Control-x><Control-n>', self._create_new_file_dialog)

File rope/editor.py

         self._bind_keys()
         self._initialize_highlighting()
         self.status_bar_manager = None
+        self.modification_observers = []
 
     def _initialize_highlighting(self):
         def colorize(event=None):
                 if self.text.compare(range_[1], '>', end):
                     end = range_[1]
             self._highlight_range(start, end)
-        def modified(event):
-            if not self.modified_flag:
-                print 'start modified', event
-                self.modified_flag = True
-                colorize()
-                self.text.edit_modified(False)
-                self.modified_flag = False
-                print 'end modified', event
         self.modified_flag = False
         self.text.bind('<Any-KeyRelease>', colorize, '+')
-        #        self.text.bind('<<Modified>>', modified)
+        self.text.bind('<<Modified>>', self._editor_modified)
         self.text.edit_modified(False)
+    
+    def _editor_modified(self, event):
+        if self.modified_flag:
+            self.modified_flag = False
+        else:
+            self.modified_flag = True
+        for observer in self.modification_observers:
+            observer()
+
+    def add_modification_observer(self, observer):
+        self.modification_observers.append(observer)
 
     def _highlight_range(self, startIndex, endIndex):
         for style in self.highlighting.get_styles().keys():
             first_non_space += 1
         self.text.mark_set(INSERT, '%d.%d' % (lineno, first_non_space))
         self.text.see(INSERT)
+    
+    def is_modified(self):
+        return self.modified_flag
 
     def correct_line_indentation(self):
         lineno = self.get_current_line_number()

File rope/fileeditor.py

             editing_tools = rope.editingtools.NormalEditingTools()
         self.editor = editor_factory.create(editing_tools)
         self.editor.set_text(self.file.read())
+        self.modification_observers = []
+        self.editor.add_modification_observer(self._editor_was_modified)
+    
+    def _editor_was_modified(self):
+        for observer in self.modification_observers:
+            observer(self)
+    
+    def add_modification_observer(self, observer):
+        self.modification_observers.append(observer)
 
     def save(self):
         self.file.write(self.editor.get_text())

File rope/statusbar.py

 class StatusBarException(rope.exceptions.RopeUIException):
     pass
 
+
 class StatusText(object):
     def __init__(self, status_bar_manager, kind, label):
         self.manager = status_bar_manager

File ropetest/fileeditortest.py

 import unittest
+import Tkinter
 
 from rope.editor import *
 from rope.fileeditor import *
         self.fileName = self.projectMaker.get_sample_file_name()
         self.project = Project(self.projectMaker.get_root())
         self.editor = FileEditor(self.project, self.project.get_resource(self.fileName),
-                                 MockEditorFactory())
+                                 GraphicalEditorFactory(Tkinter.Frame()))
     
     def tearDown(self):
         self.projectMaker.remove_all()