예제 #1
0
    def load_note(self, note_name, title=None, going_back=False):
        settings = self.settings
        if not title:
            title = note_name if note_name else 'untitled'

        if self.altered:
            response = self.dialog(
                'Save changes to old note? (Y or N, ^C to cancel)', yesno=True)
            if response is None: return
            self.altered = False
            if response:
                self.save_note(self.current_note)
        try:
            if not note_name:
                self.buffer = []
            else:
                note_path = settings.find_note(note_name)
                if os.path.isdir(note_path):
                    title = '<%s>' % title
                    self.buffer = [
                        '[[%s:%s]]' % (note_name, file_name)
                        for file_name in sorted(os.listdir(note_path))
                    ]
                else:
                    with open(note_path) as note_file:
                        self.buffer = [
                            r.rstrip('\n') for r in note_file.readlines()
                        ]
            if not going_back and not (self.history_position == len(
                    self.history) - 1 and self.history[-1] == note_name):
                if note_name in self.history:
                    self.history.remove(note_name)
                    self.history_position -= 1
                self.history = self.history[:self.history_position +
                                            1] + [note_name]
                self.history_position = len(self.history) - 1
        except:
            self.buffer = []
            self.status = "new note: %s" % note_name
            return self.load_note(None, title=title, going_back=going_back)

        self.current_note = title
        self.cursor = (0, 0)
        self.pad_position = (0, 0)
        self.altered = False
예제 #2
0
 def save_note(self, note_name):
     settings = self.settings
     
     if note_name == 'untitled': note_name = ''
     
     note_name = self.dialog('Enter the name of the note to save (^C to cancel):', note_name)
     if not note_name: return
     
     note_path = settings.find_note(note_name)
     if not note_path: note_path = settings.default_note_path(note_name)
     directory = '/'.join(note_path.split('/')[:-1])
     settings.make_dir_if_not_exists(directory)
     with open(note_path, 'w') as note_file:
         note_file.write('\n'.join(self.buffer))
     self.status = 'Saved note "%s" to %s' % (note_name, note_path)
     self.altered = False
     self.current_note = note_name
     self.history[self.history_position] = note_name
     
     if note_name == '**settings**':
         self.settings = reload(settings)
예제 #3
0
    def save_note(self, note_name):
        settings = self.settings

        if note_name == 'untitled': note_name = ''

        note_name = self.dialog(
            'Enter the name of the note to save (^C to cancel):', note_name)
        if not note_name: return

        note_path = settings.find_note(note_name)
        if not note_path: note_path = settings.default_note_path(note_name)
        directory = '/'.join(note_path.split('/')[:-1])
        settings.make_dir_if_not_exists(directory)
        with open(note_path, 'w') as note_file:
            note_file.write('\n'.join(self.buffer))
        self.status = 'Saved note "%s" to %s' % (note_name, note_path)
        self.altered = False
        self.current_note = note_name
        self.history[self.history_position] = note_name

        if note_name == '**settings**':
            self.settings = reload(settings)
예제 #4
0
 def load_note(self, note_name, title=None, going_back = False):
     settings = self.settings
     if not title: 
         title = note_name if note_name else 'untitled'
     
     if self.altered:
         response = self.dialog('Save changes to old note? (Y or N, ^C to cancel)', yesno=True)
         if response is None: return
         self.altered = False
         if response:
             self.save_note(self.current_note)
     try:
         if not note_name:
             self.buffer = []
         else:
             note_path = settings.find_note(note_name)
             if os.path.isdir(note_path):
                 title = '<%s>' % title
                 self.buffer = ['[[%s:%s]]' % (note_name, file_name) for file_name in sorted(os.listdir(note_path))]
             else:
                 with open(note_path) as note_file:
                     self.buffer = [r.rstrip('\n') for r in note_file.readlines()]    
         if not going_back and not (self.history_position == len(self.history)-1 and self.history[-1] == note_name):
             if note_name in self.history: 
                 self.history.remove(note_name)
                 self.history_position -= 1
             self.history = self.history[:self.history_position+1] + [note_name]
             self.history_position = len(self.history) - 1
     except: 
         self.buffer = []
         self.status = "new note: %s" % note_name
         return self.load_note(None, title=title, going_back=going_back)
         
     self.current_note = title
     self.cursor = (0,0)
     self.pad_position = (0,0)
     self.altered = False