Ejemplo n.º 1
0
 public static void Save( string filename, Content content )
 {
     using( StreamWriter stream = File.CreateText( filename ) )
     {
         HtmlExport.Save( stream, content );
     }
 }
Ejemplo n.º 2
0
 public void CreateNewContext()
 {
     Content content = new Content();
     Assert.IsNull( content.Title, "Title should be null" );
     Assert.IsNull( content.Comments, "Comments should be null" );
     Assert.IsNull( content.Text, "Text should be null" );
     Assert.IsNull( content.LastModified, "LastModified should be null" );
 }
Ejemplo n.º 3
0
 public void Setup()
 {
     this.content = new Content();
     this.content.Title = "A title";
     this.content.Comments = "Some comments";
     this.content.Text = "This is a lot of text";
     this.content.SetUnmodified();
 }
Ejemplo n.º 4
0
        public static void Save( TextWriter stream, Content content )
        {
            Stopwatch timer = new Stopwatch();
            timer.Start();

            TextExport.WriteEntry( stream, content );

            timer.Stop();
            Console.WriteLine( "Content saved in {0}", timer.Elapsed );
        }
Ejemplo n.º 5
0
        public void SaveProjectNullLastModified()
        {
            Content content = new Content();
            content.Title = "A title";
            content.Text = "Some text";
            content.Comments = "These are some comments.";
            content.IsIncluded = true;
            content.LastModified = null;

            SaveAndLoadContent( content );
        }
Ejemplo n.º 6
0
        public void SaveProjectNullTitle()
        {
            Content content = new Content();
            content.Title = null;
            content.Text = "Some text";
            content.Comments = "These are some comments.";
            content.IsIncluded = true;
            content.LastModified = new DateTime( 2029, 12, 31 );

            SaveAndLoadContent( content );
        }
Ejemplo n.º 7
0
        public void SaveProjectIncludedFalse()
        {
            Content content = new Content();
            content.Title = "A title";
            content.Text = "Some text";
            content.Comments = "These are some comments.";
            content.IsIncluded = false;
            content.LastModified = new DateTime( 2009, 4, 9 );

            SaveAndLoadContent( content );
        }
Ejemplo n.º 8
0
        public void SaveProjectNullText()
        {
            Content content = new Content();
            content.Title = "A title";
            content.Text = null;
            content.Comments = "These are some comments.";
            content.IsIncluded = true;
            content.LastModified = new DateTime( 2009, 4, 9 );

            SaveAndLoadContent( content );
        }
Ejemplo n.º 9
0
        public static void Save( TextWriter stream, Content content )
        {
            Stopwatch timer = new Stopwatch();
            timer.Start();

            StartHtml( stream, content.Title );

            WriteEntry( stream, content );

            FinishHtml( stream );

            timer.Stop();
            Console.WriteLine( "Content saved in {0}", timer.Elapsed );
        }
Ejemplo n.º 10
0
        public static void SaveToClipboard( Content content )
        {
            string exported = null;
            using( MemoryStream memory = new MemoryStream() )
            {
                using( StreamWriter writer = new StreamWriter( memory, Encoding.Unicode ) )
                {
                    StartHtml( writer, content.Title );
                    WriteEntry( writer, content );
                    FinishHtml( writer );
                    writer.Flush();
                    exported = Encoding.Unicode.GetString( memory.GetBuffer(), 0, (int)memory.Length );
                }

            }
            Clipboard.Clear();
            Clipboard.SetText( exported, TextDataFormat.Html );
            Clipboard.SetText( exported, TextDataFormat.UnicodeText );
        }
Ejemplo n.º 11
0
 private void LoadContent( Content content )
 {
     this.checkIncluded.IsChecked = content.IsIncluded;
     this.textBoxTitle.Text = content.Title;
     this.textBoxComment.Text = content.Comments;
     this.uiSectionNumber.Text = this.GetSectionNumber( content );
     if( content.LastModified.HasValue )
         this.uiLastModified.Text = content.LastModified.Value.ToString( "M/d/yyyy h:mm:ss" );
     else
         this.uiLastModified.Text = "n/a";
     //this.textBoxPlace.Text = content.Place;
     //this.textBoxTime.Text = content.Time;
     this.RichTextBoxText = content.Text;
     this.richTextBox1.IsReadOnly = content.IsLocked;
 }
Ejemplo n.º 12
0
        private void buttonInsertSection_Click( object sender, RoutedEventArgs e )
        {
            if( !this.view.HasSelectedContent ) return;

            Content newContent = new Content();
            newContent.Parent = this.view.SelectedEntryParent;
            newContent.Title = null;
            newContent.Text = "Write something here.";

            ExtendedTreeViewItem newItem = this.CreateTreeViewItem( newContent,
                this.view.SelectedItemParent );

            this.view.SelectedEntryParent.Children.Insert( this.view.SelectedEntryIndex, newContent );
            this.view.SelectedItemParent.Insert( this.view.SelectedEntryIndex, newItem );

            this.SetItemSelection( newItem );

            newItem.BringIntoView();
            newItem.IsSelected = true;

            this.RestartProjectWordCounter();
            this.RestartSelectionWordCounter();
        }
Ejemplo n.º 13
0
        private void buttonAddChild_Click( object sender, RoutedEventArgs e )
        {
            Content folderContent = new Content();
            folderContent.Parent = this.view.SelectedEntryParent;
            folderContent.Title = "New Folder";
            folderContent.Text = null;
            folderContent.IsFolder = true;

            ExtendedTreeViewItem newItem = this.CreateTreeViewItem( folderContent,
                this.view.SelectedItemParent );

            this.AddContent( folderContent, newItem );

            //Content newContent = new Content();
            //newContent.Parent = folderContent;
            //newContent.Title = null;
            //newContent.Text = "Write something here.";

            //ExtendedTreeViewItem newItem = this.CreateTreeViewItem( newContent,
            //    folderItem.Items );

            //folderContent.Children.Add( newContent );
            //folderItem.Items.Add( newItem );

            this.SetItemSelection( newItem );

            newItem.BringIntoView();
            newItem.IsSelected = true;

            this.RestartProjectWordCounter();
            this.RestartSelectionWordCounter();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Add a node in one of three places, based on the user's selection:
        /// 1. If a folder is selected, the new node is added as a child
        /// 2. If a section is select, the new node is added after the selection
        /// 3. If nothing is selected, the new node is added at the end
        /// </summary>
        /// <param name="newContent"></param>
        /// <param name="newItem"></param>
        private void AddContent( Content newContent, ExtendedTreeViewItem newItem )
        {
            if( this.view.HasSelectedContent && this.view.SelectedContent.IsFolder )
            {
                // Add a new node under the selected folder
                this.view.SelectedContent.Children.Add( newContent );
                this.view.SelectedItem.Items.Add( newItem );
            }
            else if( this.view.HasSelectedContent && !this.view.SelectedContent.IsFolder )
            {
                // Add a new node after the selected entry
                this.view.SelectedEntryParent.Children.Insert( this.view.SelectedEntryIndex + 1, newContent );
                this.view.SelectedItemParent.Insert( this.view.SelectedEntryIndex + 1, newItem );
            }
            else
            {
                // Add a new node at the end of the collection
                this.view.SelectedEntryParent.Children.Add( newContent );
                this.view.SelectedItemParent.Add( newItem );
            }

            // Update parent folder's modified date, if this is a child section.
            if( newContent.Parent is Content )
            {
                ((Content)newContent.Parent).LastModified = DateTime.Now;
                // Force parent node to redraw word count
                ((Content)newContent.Parent).RefreshWordCount();
            }
        }
Ejemplo n.º 15
0
        public static void LoadEntries( XmlTextReader reader, IEntry parent, IList<IEntry> entries )
        {
            IEntry lastEntry = null;
            string nodeName = reader.Name;

            while( reader.Read() )
            {
            begin:
                if( reader.EOF ) break; // sanity check to prevent endless loops

                if( reader.NodeType == XmlNodeType.EndElement && reader.Name == nodeName )
                    break;

                if( reader.NodeType != XmlNodeType.Element ) continue;

                switch( reader.Name )
                {
                    //case "folder":
                    //    Folder folder = new Folder();
                    //    folder.Title = "Folder";
                    //    XmlStorage.LoadEntries( reader, folder, folder.Children );
                    //    entries.Add( folder );
                    //    lastEntry = folder;
                    //    break;
                    case "folder":
                    case "children":
                        XmlStorage.LoadEntries( reader, lastEntry, lastEntry.Children );
                        break;
                    case "entry":
                        Content content = new Content();
                        content.Parent = parent;

                        string folder = reader.GetAttribute( "folder" );
                        if( folder != null ) content.IsFolder = bool.Parse( folder );

                        string included = reader.GetAttribute( "included" );
                        if( included != null ) content.IsIncluded = bool.Parse( included );

                        DateTime? lastModified;
                        string lastModifiedText = reader.GetAttribute( "modified" );
                        if( lastModifiedText != null )
                            lastModified = DateTime.ParseExact( lastModifiedText, "s", System.Globalization.CultureInfo.InvariantCulture ).ToLocalTime();
                        else
                            lastModified = null;

                        content.Title = reader.GetAttribute( "title" );
                        content.Comments = reader.GetAttribute( "comment" );
                        //content.Place = reader.GetAttribute( "place" );
                        //content.Time = reader.GetAttribute( "time" );

                        bool isEmpty = reader.IsEmptyElement;

                        if( !isEmpty )
                        {
                            content.Text = reader.ReadString();
                            if( content.Text.StartsWith( Environment.NewLine ) )
                                content.Text = content.Text.TrimStart();
                        }

                        // Set the last modified date last, because updating
                        // any of the above properties also refreshes last modified!
                        content.LastModified = lastModified;
                        content.SetUnmodified();

                        entries.Add( content );
                        lastEntry = content;

                        // ReadString() above actually advances to the next element,
                        // so we must skip the Read() at the top of the loop.
                        if( !isEmpty ) goto begin;

                        // But ReadString on empty elements does NOT advance.
                        break;
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Legacy code to read from a plain text file.
        /// </summary>
        /// <param name="filename">Filename to load</param>
        /// <param name="encoding">Character encoding; usually UTF-8 but 1252
        /// also useful.</param>
        /// <returns></returns>
        public static Project LoadFromText( string filename, Encoding encoding )
        {
            Stopwatch timer = new Stopwatch();
            timer.Start();
            Project project = new Project();

            using( FileStream stream = File.Open( filename, FileMode.Open ) )
            {
                using( StreamReader reader = new StreamReader( stream, encoding ) )
                {
                    int index = 1;
                    StringBuilder sb = new StringBuilder();
                    string line = reader.ReadLine();
                    do
                    {
                        if( line.StartsWith( "#" ) )
                        {
                            Content content = new Content();
                            content.Parent = project;
                            content.Title = string.Empty;
                            content.Text = sb.ToString();
                            project.Children.Add( content );
                            index++;
                            sb = new StringBuilder();
                        }
                        else
                        {
                            sb.Append( line );
                            sb.AppendLine();
                        }
                        line = reader.ReadLine();
                    }
                    while( line != null );

                    if( sb.Length > 0 )
                    {
                        Content content = new Content();
                        content.Parent = project;
                        content.Title = string.Empty;
                        content.Text = sb.ToString();
                        project.Children.Add( content );
                        index++;
                    }
                }
            }
            timer.Stop();
            Console.WriteLine( "Text loaded in {0}", timer.Elapsed );
            return project;
        }
Ejemplo n.º 17
0
 private static void CompareContents( Content content, Content testContent )
 {
     Assert.AreEqual( content.LastModified, testContent.LastModified );
     Assert.AreEqual( content.Title, testContent.Title );
     Assert.AreEqual( content.Text, testContent.Text );
     Assert.AreEqual( content.Comments, testContent.Comments );
     Assert.AreEqual( content.IsIncluded, testContent.IsIncluded );
 }
Ejemplo n.º 18
0
        public void NewProject()
        {
            this.Project = new Project();
            this.Project.DailyRecord = this.Project.GetDailyRecord();

            Content folder;

            folder = new Content();
            folder.Parent = this.Project;
            folder.IsFolder = true;
            folder.Title = "Draft";
            folder.Comments = "This folder contains the complete draft content.";
            folder.IsIncluded = true;
            this.Project.Children.Add( folder );

            folder = new Content();
            folder.Parent = this.Project;
            folder.IsFolder = true;
            folder.Title = "Scratchpad";
            folder.Comments = "This folder contains notes and snippets not contained in the draft.";
            folder.IsIncluded = false;
            this.Project.Children.Add( folder );

            this.Window.ResetProject();

            this.InitializeSelectedContent();
        }
Ejemplo n.º 19
0
 private static void SaveAndLoadContent( Content content )
 {
     Project project = new Project();
     project.Children.Add( content );
     Project testProject = SaveAndLoadProject( project );
     Assert.AreEqual( project.Children.Count, testProject.Children.Count );
     Content testContent = (Content)testProject.Children[0];
     CompareContents( content, testContent );
 }