Example #1
0
def create_editor(filename, action_group):
    view = CulebraView(action_group)
    # XXX: there's no way to select an encoding
    buff = CulebraBuffer(filename)
    buff.load_from_file()
    view.set_buffer(buff)

    return view
Example #2
0
def create_editor(filename, action_group):
    view = CulebraView(action_group)
    # XXX: there's no way to select an encoding
    buff = CulebraBuffer(filename)
    buff.load_from_file()
    view.set_buffer(buff)
    
    return view
Example #3
0
    def file_new(self, mi=None):
        buff = CulebraBuffer ()
        buff.set_text("")
        buff.set_modified(False)

        manager = buff.languages_manager
        language = manager.get_language_from_mime_type("text/x-python")
        buff.set_highlight(True)
        buff.set_language(language)

        self.entries.append (buff)

        self.plugin.do_edit('changebuffer', len(self.entries) - 1)
Example #4
0
def load_buffer(filename, buff=None):
    """
    Creates a CulebraBuffer from a filename
    """
    new_entry = True
    if buff is None:
        buff = CulebraBuffer(filename=filename)
    # We only update the contents of a new buffer
    fd = open(filename)
    try:
        buff.begin_not_undoable_action()
        buff.set_text("")
        data = fd.read()
        enc_data = None
        for enc in(sys.getdefaultencoding(), "utf-8", "iso8859", "ascii"):
            try:
                enc_data = unicode(data, enc)
                buff.encoding = enc
                break
            except UnicodeDecodeError:
                pass
        assert enc_data is not None, "There was a problem detecting the encoding"
            
        
        buff.set_text(enc_data)
        buff.set_modified(False)
        buff.place_cursor(buff.get_start_iter())
        buff.end_not_undoable_action()

    finally:
        fd.close()

    return buff
Example #5
0
def load_buffer(filename, buff=None):
    """
    Creates a CulebraBuffer from a filename
    """
    new_entry = True
    if buff is None:
        buff = CulebraBuffer(filename=filename)
    # We only update the contents of a new buffer
    fd = open(filename)
    try:
        buff.begin_not_undoable_action()
        buff.set_text("")
        data = fd.read()
        enc_data = None
        for enc in (sys.getdefaultencoding(), "utf-8", "iso8859", "ascii"):
            try:
                enc_data = unicode(data, enc)
                buff.encoding = enc
                break
            except UnicodeDecodeError:
                pass
        assert enc_data is not None, "There was a problem detecting the encoding"

        buff.set_text(enc_data)
        buff.set_modified(False)
        buff.place_cursor(buff.get_start_iter())
        buff.end_not_undoable_action()

    finally:
        fd.close()

    return buff
Example #6
0
    def load_file(self, fname):
        buff = None
        
        for ent in self.entries:
            if ent.filename == fname:
               buff = ent
               break
        
        if buff is None:
            new_entry = True
            buff = CulebraBuffer()
            buff.filename = fname
            # We only update the contents of a new buffer
            try:
                fd = open(fname)
                buff.begin_not_undoable_action()
                buff.set_text('')
                data = fd.read ()
                enc_data = None
                for enc in (sys.getdefaultencoding(), "utf-8", "iso8859", "ascii"):
                    try:
                        enc_data = unicode (data, enc)
                        buff.encoding = enc
                        break
                    except UnicodeDecodeError:
                        pass
                assert enc_data is not None, "There was a problem detecting the encoding"
                    
                
                buff.set_text(enc_data)
                buff.set_modified(False)
                buff.place_cursor(buff.get_start_iter())
                buff.end_not_undoable_action()
                fd.close()

                self.check_mime(buff)

                self.set_title(os.path.basename(fname))
                self.dirname = os.path.dirname(fname)
                
            except:
                dlg = gtk.MessageDialog(self.get_parent_window(),
                        gtk.DIALOG_DESTROY_WITH_PARENT,
                        gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
                        "Can't open " + fname)
                import traceback
                traceback.print_exc ()
                
                print sys.exc_info()[1]
                resp = dlg.run()
                dlg.hide()
                return
            self.entries.append (buff)

        else:
            new_entry = False
            
            
        # Replace a not modified new buffer when we open
        if new_entry and self.entries.count_new() == 1 and len(self.entries) == 2:
            if self.entries[0].is_new:
                new_entry = self.entries[0]
            else:
                new_entry = self.entries[1]
            
            if not new_entry.get_modified():
                # Remove the new entry
                self.entries.remove(new_entry)
                    
        self.editor.grab_focus()