aboutsummaryrefslogtreecommitdiffstatsci
path: root/CrowIDE/src/SourceEditor
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2018-02-27 18:18:42 +0100
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2018-02-27 18:18:42 +0100
commit508b53d725958e6a8c8be51db04033aeff1df0da (patch)
tree8495cf890a9cee3466aa8eaceb073f391fb5d628 /CrowIDE/src/SourceEditor
parentf4c05f6b4ddd426a87492b51aca5147d5def2bc5 (diff)
crowide wip, DesignIDS
Diffstat (limited to 'CrowIDE/src/SourceEditor')
-rw-r--r--CrowIDE/src/SourceEditor/SourceEditor.cs77
1 files changed, 52 insertions, 25 deletions
diff --git a/CrowIDE/src/SourceEditor/SourceEditor.cs b/CrowIDE/src/SourceEditor/SourceEditor.cs
index db83b2ba..d594776e 100644
--- a/CrowIDE/src/SourceEditor/SourceEditor.cs
+++ b/CrowIDE/src/SourceEditor/SourceEditor.cs
@@ -86,10 +86,25 @@ namespace Crow.Coding
string oldSource = "";
void updateSourceThreadFunc (){
while (true) {
- if (projNode != null && buffer != null) {
- string newSrc = buffer.FullText;
- if (projNode.Source != newSrc)
- projNode.Source = newSrc;
+ if (projFile != null && buffer != null) {
+ if (!projFile.RegisteredEditors [this]) {
+ loadSource ();
+ isDirty = false;
+ oldSource = projFile.Source;
+ projFile.RegisteredEditors [this] = true;
+ }
+ if (Monitor.TryEnter (buffer.EditMutex)) {
+ string newsrc = "";
+ bool wasDirty = false;
+ if (isDirty) {
+ isDirty = false;
+ wasDirty = true;
+ newsrc = buffer.FullText;
+ }
+ Monitor.Exit (buffer.EditMutex);
+ if (wasDirty)
+ projFile.UpdateSource (this, newsrc);
+ }
}
Thread.Sleep (100);
}
@@ -99,7 +114,7 @@ namespace Crow.Coding
#region private and protected fields
bool foldingEnabled = true;
- ProjectFile projNode = null;
+ ProjectFile projFile = null;
int leftMargin = 0; //margin used to display line numbers, folding errors,etc...
int visibleLines = 1;
int visibleColumns = 1;
@@ -203,6 +218,8 @@ namespace Crow.Coding
buffer.ToogleFolding (line);
}
+ volatile bool isDirty = false;
+
#region Buffer events handlers
void Buffer_BufferCleared (object sender, EventArgs e)
{
@@ -213,6 +230,7 @@ namespace Crow.Coding
PrintedLines = null;
RegisterForGraphicUpdate ();
notifyPositionChanged ();
+ isDirty = true;
}
void Buffer_LineAdditionEvent (object sender, CodeBufferEventArgs e)
{
@@ -237,6 +255,7 @@ namespace Crow.Coding
updateMaxScrollY ();
RegisterForGraphicUpdate ();
notifyPositionChanged ();
+ isDirty = true;
}
void Buffer_LineRemoveEvent (object sender, CodeBufferEventArgs e)
{
@@ -254,6 +273,7 @@ namespace Crow.Coding
updateMaxScrollY ();
RegisterForGraphicUpdate ();
notifyPositionChanged ();
+ isDirty = true;
}
void Buffer_LineUpadateEvent (object sender, CodeBufferEventArgs e)
{
@@ -273,6 +293,7 @@ namespace Crow.Coding
RegisterForGraphicUpdate ();
notifyPositionChanged ();
+ isDirty = true;
}
void Buffer_PositionChanged (object sender, EventArgs e)
{
@@ -356,39 +377,45 @@ namespace Crow.Coding
public ProjectFile ProjectNode
{
get {
- return projNode;
+ return projFile;
}
set
{
- if (projNode == value)
+ if (projFile == value)
return;
- projNode = value;
+ if (projFile != null)
+ projFile.UnregisterEditor (this);
- NotifyValueChanged ("ProjectNode", projNode);
+ projFile = value;
+ NotifyValueChanged ("ProjectNode", projFile);
- if (projNode == null)
- return;
-
- if (!File.Exists (projNode.AbsolutePath))
+ if (projFile == null)
return;
- parser = getParserFromExt (System.IO.Path.GetExtension (projNode.Extension));
+ parser = getParserFromExt (System.IO.Path.GetExtension (projFile.Extension));
- try {
- buffer.Load (projNode.Source);
- oldSource = projNode.Source;
- } catch (Exception ex) {
- Debug.WriteLine (ex.ToString ());
- }
-
- updateMaxScrollY ();
- MaxScrollX = Math.Max (0, buffer.longestLineCharCount - visibleColumns);
- updatePrintedLines ();
+ projFile.RegisterEditor (this);
- RegisterForGraphicUpdate ();
}
}
+ void loadSource () {
+
+ try {
+ buffer.Load (projFile.Source);
+ } catch (Exception ex) {
+ Debug.WriteLine (ex.ToString ());
+ }
+
+ projFile.RegisteredEditors [this] = true;
+
+ updateMaxScrollY ();
+ MaxScrollX = Math.Max (0, buffer.longestLineCharCount - visibleColumns);
+ updatePrintedLines ();
+
+ RegisterForGraphicUpdate ();
+ }
+
[XmlAttributeAttribute][DefaultValue("BlueGray")]
public virtual Color SelectionBackground {
get { return selBackground; }