예제 #1
0
    def open_file(self, widget, from_journal=False):
        self.editor.pep8.check_exit()
        self.save_file(None, type="exit")
        if not from_journal:
            file_path, remember = file_choosers.open_file_dialog()
            if file_path != None:
                self.set_title(os.path.split(file_path)[-1])
                mime_type = mime.get_from_file_name(file_path)
                self.metadata["mime_type"] = mime_type

                file = open(file_path, "r")
                self.editor.buffer.set_text(file.read())
                if remember:
                    self.editor.file = file_path
                self.editor._search_and_active_language(mime_type)
                file.close()

        if from_journal:
            file_path = from_journal
            mime_type = mime.get_from_file_name(file_path)
            self.metadata["mime_type"] = mime_type

            file = open(file_path, "r")
            self.editor.buffer.set_text(file.read())
            self.editor.file = file_path
            self.editor._search_and_active_language(mime_type)
            file.close()
예제 #2
0
        def open_file(self, widget, from_journal=False):
                self.pep8.check_exit(self.editor.buffer, self.editor._get_all_text())
                self.save_file(None, type="exit")
                if not from_journal:
                        file_path, remember = file_choosers.open_file_dialog()
                        if file_path != None:
                                self.set_title(os.path.split(file_path)[-1])
                                mime_type = mime.get_from_file_name(file_path)
                                self.metadata["mime_type"] = mime_type

                                file = open(file_path, "r")
                                self.editor.buffer.set_text(file.read())
                                if remember:
                                        self.editor.file = file_path
                                self.editor._search_and_active_language(
                                                                     mime_type)
                                file.close()

                if from_journal:
                        file_path = from_journal
                        mime_type = mime.get_from_file_name(file_path)
                        self.metadata["mime_type"] = mime_type

                        file = open(file_path, "r")
                        self.editor.buffer.set_text(file.read())
                        self.editor.file = file_path
                        self.editor._search_and_active_language(mime_type)
                        file.close()
예제 #3
0
        def save_file_as(self, widget):
                file_path = file_choosers.save_file_dialog()
                if file_path:
                        self.editor.file = file_path
                        file = open(self.editor.file, "w")
                        file.write(self.editor._get_all_text())
                        file.close()

                        self.set_title(os.path.split(file_path)[-1])
                        mime_type = mime.get_from_file_name(file_path)
                        self.metadata["mime_type"] = mime_type
                        self.editor.file = file_path
                        self.editor._search_and_active_language(mime_type)
예제 #4
0
    def save_file_as(self, widget):
        file_path = file_choosers.save_file_dialog()
        if file_path:
            self.editor.file = file_path
            file = open(self.editor.file, "w")
            file.write(self.editor._get_all_text())
            file.close()

            self.set_title(os.path.split(file_path)[-1])
            mime_type = mime.get_from_file_name(file_path)
            self.metadata["mime_type"] = mime_type
            self.editor.file = file_path
            self.editor._search_and_active_language(mime_type)
예제 #5
0
    def __keep_in_journal_cb(self, menu_item):
        mime_type = mime.get_from_file_name(self._document_path)
        if mime_type == 'application/octet-stream':
            mime_type = mime.get_for_file(self._document_path)

        self._jobject = datastore.create()
        title = _('Source') + ': ' + self._title
        self._jobject.metadata['title'] = title
        self._jobject.metadata['keep'] = '0'
        self._jobject.metadata['buddies'] = ''
        self._jobject.metadata['preview'] = ''
        self._jobject.metadata['icon-color'] = self._color
        self._jobject.metadata['mime_type'] = mime_type
        self._jobject.metadata['source'] = '1'
        self._jobject.file_path = self._document_path
        datastore.write(self._jobject, transfer_ownership=True,
                        reply_handler=self.__internal_save_cb,
                        error_handler=self.__internal_save_error_cb)
예제 #6
0
    def get_mime_type(self):
        if not self._formats:
            return ''

        format_ = mime.choose_most_significant(self._formats.keys())
        if format_ == 'text/uri-list':
            data = self._formats['text/uri-list'].get_data()
            uri = urlparse.urlparse(mime.split_uri_list(data)[0], 'file')
            scheme = uri.scheme  # pylint: disable=E1101
            if scheme == 'file':
                path = uri.path  # pylint: disable=E1101
                if os.path.exists(path):
                    format_ = mime.get_for_file(path)
                else:
                    format_ = mime.get_from_file_name(path)
                logging.debug('Chose %r!', format_)

        return format_
예제 #7
0
    def get_mime_type(self):
        if not self._formats:
            return ''

        format_ = mime.choose_most_significant(self._formats.keys())
        if format_ == 'text/uri-list':
            data = self._formats['text/uri-list'].get_data()
            uri = urlparse.urlparse(mime.split_uri_list(data)[0], 'file')
            scheme = uri.scheme  # pylint: disable=E1101
            if scheme == 'file':
                path = uri.path  # pylint: disable=E1101
                if os.path.exists(path):
                    format_ = mime.get_for_file(path)
                else:
                    format_ = mime.get_from_file_name(path)
                logging.debug('Chose %r!', format_)

        return format_
예제 #8
0
    def __keep_in_journal_cb(self, menu_item):
        mime_type = mime.get_from_file_name(self._document_path)
        if mime_type == 'application/octet-stream':
            mime_type = mime.get_for_file(self._document_path)

        self._jobject = datastore.create()
        title = _('Source') + ': ' + self._title
        self._jobject.metadata['title'] = title
        self._jobject.metadata['keep'] = '0'
        self._jobject.metadata['buddies'] = ''
        self._jobject.metadata['preview'] = ''
        self._jobject.metadata['icon-color'] = self._color
        self._jobject.metadata['mime_type'] = mime_type
        self._jobject.metadata['source'] = '1'
        self._jobject.file_path = self._document_path
        datastore.write(self._jobject,
                        transfer_ownership=True,
                        reply_handler=self.__internal_save_cb,
                        error_handler=self.__internal_save_error_cb)
예제 #9
0
 def test_from_file_name(self):
     self.assertEqual(mime.get_from_file_name('test.pdf'),
                      'application/pdf')
예제 #10
0
 def test_from_file_name(self):
     self.assertEqual(mime.get_from_file_name('test.pdf'),
                      'application/pdf')