mirror of
				https://github.com/chibicitiberiu/rainmeter-studio.git
				synced 2024-02-24 04:33:31 +00:00 
			
		
		
		
	Fixed text editor not working.
This commit is contained in:
		@@ -16,9 +16,9 @@ namespace RainmeterStudio.TextEditorPlugin
 | 
				
			|||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Gets or sets the text associated with this document
 | 
					        /// Gets or sets the text associated with this document
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        public List<string> Lines
 | 
					        public string Text
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            get; private set;
 | 
					            get; set;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
@@ -67,7 +67,7 @@ namespace RainmeterStudio.TextEditorPlugin
 | 
				
			|||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        public TextDocument()
 | 
					        public TextDocument()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            Lines = new List<string>();
 | 
					            Text = String.Empty;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,6 @@
 | 
				
			|||||||
             mc:Ignorable="d" 
 | 
					             mc:Ignorable="d" 
 | 
				
			||||||
             d:DesignHeight="300" d:DesignWidth="300">
 | 
					             d:DesignHeight="300" d:DesignWidth="300">
 | 
				
			||||||
    <Grid>
 | 
					    <Grid>
 | 
				
			||||||
        <TextBox Name="text" AcceptsReturn="True"
 | 
					        <TextBox Name="textBox" AcceptsReturn="True" />
 | 
				
			||||||
                 TextChanged="text_TextChanged"/>
 | 
					 | 
				
			||||||
    </Grid>
 | 
					    </Grid>
 | 
				
			||||||
</UserControl>
 | 
					</UserControl>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,18 +24,17 @@ namespace RainmeterStudio.TextEditorPlugin
 | 
				
			|||||||
        public TextEditorControl(TextDocument document)
 | 
					        public TextEditorControl(TextDocument document)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            InitializeComponent();
 | 
					            InitializeComponent();
 | 
				
			||||||
 | 
					            DataContext = this;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            _document = document;
 | 
					            _document = document;
 | 
				
			||||||
 | 
					            textBox.Text = _document.Text;
 | 
				
			||||||
            StringBuilder txt = new StringBuilder();
 | 
					            textBox.TextChanged += text_TextChanged;
 | 
				
			||||||
            document.Lines.ForEach((line) => txt.AppendLine(line));
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            text.Text = txt.ToString();
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void text_TextChanged(object sender, TextChangedEventArgs e)
 | 
					        private void text_TextChanged(object sender, TextChangedEventArgs e)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            _document.IsDirty = true;
 | 
					            _document.IsDirty = true;
 | 
				
			||||||
 | 
					            _document.Text = textBox.Text;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,7 @@ namespace RainmeterStudio.TextEditorPlugin
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            TextDocument document = new TextDocument();
 | 
					            TextDocument document = new TextDocument();
 | 
				
			||||||
            document.Reference = new Reference(Path.GetFileName(path), path);
 | 
					            document.Reference = new Reference(Path.GetFileName(path), path);
 | 
				
			||||||
            document.Lines.AddRange(File.ReadAllLines(path));
 | 
					            document.Text = File.ReadAllText(path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return document;
 | 
					            return document;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -30,7 +30,7 @@ namespace RainmeterStudio.TextEditorPlugin
 | 
				
			|||||||
            if (textDocument == null)
 | 
					            if (textDocument == null)
 | 
				
			||||||
                throw new ArgumentException("Provided document is not supported by this storage.");
 | 
					                throw new ArgumentException("Provided document is not supported by this storage.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            File.WriteAllLines(path, textDocument.Lines);
 | 
					            File.WriteAllText(path, textDocument.Text);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <inheritdoc />
 | 
					        /// <inheritdoc />
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -66,6 +66,7 @@ namespace RainmeterStudio.UI
 | 
				
			|||||||
            document.Content = e.Editor.EditorUI;
 | 
					            document.Content = e.Editor.EditorUI;
 | 
				
			||||||
            document.Closing += document_Closing;
 | 
					            document.Closing += document_Closing;
 | 
				
			||||||
            document.Closed += document_Closed;
 | 
					            document.Closed += document_Closed;
 | 
				
			||||||
 | 
					            document.Title = GetDocumentTitle(e.Document);
 | 
				
			||||||
            document.IsActiveChanged += new EventHandler((sender2, e2) =>
 | 
					            document.IsActiveChanged += new EventHandler((sender2, e2) =>
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if (document.IsActive)
 | 
					                if (document.IsActive)
 | 
				
			||||||
@@ -77,29 +78,34 @@ namespace RainmeterStudio.UI
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            e.Document.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler((obj, args) =>
 | 
					            e.Document.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler((obj, args) =>
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                string documentName;
 | 
					                // Update document title
 | 
				
			||||||
                
 | 
					                document.Title = GetDocumentTitle(e.Document);
 | 
				
			||||||
                // Get title
 | 
					 | 
				
			||||||
                if (ProjectController.ActiveProject == null || !ProjectController.ActiveProject.Contains(e.Document.Reference))
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    documentName = e.Document.Reference.StoragePath ?? "New document";
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                else
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    documentName = e.Document.Reference.Name;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                // Is document dirty? Append star
 | 
					 | 
				
			||||||
                if (e.Document.IsDirty)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    documentName += "*";
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                // Set document title
 | 
					 | 
				
			||||||
                document.Title = documentName;
 | 
					 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private string GetDocumentTitle(IDocument document)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            string documentName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Get title
 | 
				
			||||||
 | 
					            if (ProjectController.ActiveProject == null || !ProjectController.ActiveProject.Contains(document.Reference))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                documentName = document.Reference.StoragePath ?? "New document";
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                documentName = document.Reference.Name;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Is document dirty? Append star
 | 
				
			||||||
 | 
					            if (document.IsDirty)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                documentName += "*";
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return documentName;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        void document_Closed(object sender, EventArgs e)
 | 
					        void document_Closed(object sender, EventArgs e)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var layoutDocument = (LayoutDocument)sender;
 | 
					            var layoutDocument = (LayoutDocument)sender;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user