예제 #1
0
        private void NoteManager_NoteAdded(object sender, NoteAddedEventArgs e)
        {
            notesListBox.Invoke((MethodInvoker)(() => {
                if (noteManager.currentFolder == e.Note.folderName)
                {
                    notesListBox.Items.Add(e.Note);
                }
            }));

            e.Note.ContentChanged     += Note_ContentChanged;
            e.Note.TitleChanged       += Note_TitleChanged;
            e.Note.VisibleChanged     += Note_VisibleChanged;
            e.Note.PositionChanged    += Note_PositionChanged;
            e.Note.PerformNewNote     += Note_PerformNewNote;
            e.Note.PerformMoveToTrash += Note_PerformMoveToTrash;
            e.Note.PerformSync        += Note_PerformSync;
            e.Note.ShowNotesList      += Note_ShowNotesList;
            e.Note.ColorChanged       += Note_ColorChanged;
            e.Note.FolderChanged      += Note_FolderChanged;

            if (e.Note.visible && e.Note.folderName != noteManager.trashFolderId)
            {
                e.Note.Show();
            }
        }
예제 #2
0
        public void NewNote(string uniqueId, string colorStr = "yellow")
        {
            Note note = new Note(uniqueId, colorStr, DateTime.Now);

            notes.Add(note);
            note.Show();

            NoteAddedEventArgs args = new NoteAddedEventArgs()
            {
                Note = note
            };

            OnNoteAdded(args);

            SaveNoteToDisk(note);
        }
예제 #3
0
        public void UpdateNote(NoteData data)
        {
            bool noteExists = false;

            for (int i = 0; i < notes.Count; i++)
            {
                if (notes[i].uniqueId == data.i)
                {
                    notes[i].SetTitle(data.l);
                    notes[i].SetColor(data.c);
                    notes[i].SetContent(data.t);
                    notes[i].ChangeFolder(data.f);

                    DateTime dt = DateTime.FromBinary(long.Parse(data.s));
                    notes[i].SetSyncDate(dt);

                    SaveNoteToDisk(notes[i]);

                    noteExists = true;
                }
            }

            if (!noteExists)
            {
                string notePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Tinote", "notes", data.i);

                if (!File.Exists(notePath))
                {
                    Note note = new Note(data.i, data.c, DateTime.FromBinary(long.Parse(data.d)));
                    note.SetContent(data.t);
                    note.SetTitle(data.l);

                    notes.Add(note);

                    NoteAddedEventArgs args = new NoteAddedEventArgs()
                    {
                        Note = note
                    };
                    OnNoteAdded(args);

                    SaveNoteToDisk(note);
                }
            }
        }
예제 #4
0
        public void LoadNotesFromDisk()
        {
            try
            {
                string        appDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Tinote", "notes");
                DirectoryInfo di            = new DirectoryInfo(appDataFolder);

                if (!di.Exists)
                {
                    di.Create();
                }

                string[] filePaths = Directory.GetFiles(appDataFolder);

                notes = new List <Note>();

                for (int i = 0; i < filePaths.Length; i++)
                {
                    string[] lines = File.ReadAllLines(filePaths[i]);
                    Note     note  = JsonConvert.DeserializeObject <Note>(lines[0]);

                    if (!note.deleted)
                    {
                        notes.Add(note);

                        NoteAddedEventArgs args = new NoteAddedEventArgs()
                        {
                            Note = note
                        };
                        OnNoteAdded(args);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
예제 #5
0
 protected virtual void OnNoteAdded(NoteAddedEventArgs e)
 {
     NoteAdded?.Invoke(this, e);
 }