diff options
| author | j-p <jp.bruyere@live.be> | 2018-12-11 23:20:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-11 23:20:54 +0100 |
| commit | d7239eebe4b07685aabaf6663bebbc77386286ea (patch) | |
| tree | 836cee695262dc2fc3f1219de385752177893ed2 /CrowIDE/src/ProjectTree/ProjectFile.cs | |
| parent | f1531e562b4ecd9d568a28c2fffe7ffed06c728a (diff) | |
| parent | 7e831f8ebac4affbb01211b1f6ec3887280fea2b (diff) | |
Merge pull request #44 from jpbruyere/xlib
Xlib
Diffstat (limited to 'CrowIDE/src/ProjectTree/ProjectFile.cs')
| -rw-r--r-- | CrowIDE/src/ProjectTree/ProjectFile.cs | 66 |
1 files changed, 50 insertions, 16 deletions
diff --git a/CrowIDE/src/ProjectTree/ProjectFile.cs b/CrowIDE/src/ProjectTree/ProjectFile.cs index 2fac2f91..2c60c32c 100644 --- a/CrowIDE/src/ProjectTree/ProjectFile.cs +++ b/CrowIDE/src/ProjectTree/ProjectFile.cs @@ -34,7 +34,7 @@ using System.Threading; namespace Crow.Coding { public class ProjectFile : ProjectItem { - protected bool isOpened = false; + bool isOpened = false; DateTime accessTime; string source; string origSource; @@ -47,22 +47,28 @@ namespace Crow.Coding List<String> undoStack = new List<string>(); List<String> redoStack = new List<string>(); - public Crow.Command cmdSave, cmdSaveAs, cmdOpen, cmdUndo, cmdRedo; + public Crow.Command cmdSave, cmdSaveAs, cmdOpen, cmdClose, cmdUndo, cmdRedo; void initCommands (){ cmdSave = new Crow.Command (new Action (() => Save ())) - { Caption = "Save", Icon = new SvgPicture ("#Crow.Coding.ui.icons.inbox.svg"), CanExecute = false }; + { Caption = "Save", Icon = new SvgPicture ("#icons.save.svg"), CanExecute = false }; cmdSaveAs = new Crow.Command (new Action (() => SaveAs ())) - { Caption = "Save As ..", Icon = new SvgPicture ("#Crow.Coding.ui.icons.inbox.svg"), CanExecute = false }; + { Caption = "Save As ..", Icon = new SvgPicture ("#icons.save.svg"), CanExecute = false }; cmdOpen = new Crow.Command (new Action (() => Open ())) - { Caption = "Open", Icon = new SvgPicture ("#Crow.Coding.ui.icons.outbox.svg"), CanExecute = false }; + { Caption = "Open", Icon = new SvgPicture ("#icons.open.svg"), CanExecute = true }; + cmdClose = new Crow.Command (new Action (() => OnQueryClose (this,null))) + { Caption = "Close", Icon = new SvgPicture ("#icons.open.svg"), CanExecute = false }; cmdUndo = new Crow.Command (new Action (() => Undo (null))) - { Caption = "Undo", Icon = new SvgPicture ("#Crow.Coding.icons.undo.svg"), CanExecute = false }; + { Caption = "Undo", Icon = new SvgPicture ("#icons.undo.svg"), CanExecute = false }; cmdRedo = new Crow.Command (new Action (() => Redo (null))) - { Caption = "Redo", Icon = new SvgPicture ("#Crow.Coding.icons.redo.svg"), CanExecute = false }; + { Caption = "Redo", Icon = new SvgPicture ("#icons.redo.svg"), CanExecute = false }; Commands.Insert (0, cmdOpen); - Commands.Insert (1, cmdSave); + Commands.Insert (1, cmdSave); + Commands.Insert (2, cmdSaveAs); + Commands.Insert (3, cmdUndo); + Commands.Insert (4, cmdRedo); + Commands.Add (cmdClose); } public ProjectFile () { initCommands(); @@ -85,6 +91,25 @@ namespace Crow.Coding return node.SelectSingleNode ("LogicalName")?.InnerText; } } + public bool IsOpened { + get { return isOpened; } + set { + if (isOpened == value) + return; + isOpened = value; + + cmdOpen.CanExecute = !isOpened; + cmdClose.CanExecute = isOpened; + cmdSave.CanExecute = isOpened && IsDirty; + + if (isOpened) + Project.solution.OpenItem (this); + else + Project.solution.CloseItem (this); + + NotifyValueChanged ("IsOpened", isOpened); + } + } public void UnregisterEditor (object editor){ lock(RegisteredEditors){ @@ -124,9 +149,11 @@ namespace Crow.Coding } public string Source { get { - if (!isOpened) - Open (); - else { + if (!IsOpened) { + using (StreamReader sr = new StreamReader (AbsolutePath)) + source = sr.ReadToEnd (); + + } else { if (DateTime.Compare ( accessTime, System.IO.File.GetLastWriteTime (AbsolutePath)) < 0) @@ -195,13 +222,13 @@ namespace Crow.Coding } } - public void Open () { + public void Open () { accessTime = System.IO.File.GetLastWriteTime (AbsolutePath); using (StreamReader sr = new StreamReader (AbsolutePath)) { source = sr.ReadToEnd (); } - isOpened = true; origSource = source; + IsOpened = true; NotifyValueChanged ("IsDirty", false); } public virtual void Save () { @@ -223,9 +250,8 @@ namespace Crow.Coding NotifyValueChanged ("IsDirty", false); } public void Close () { - origSource = null; - isOpened = false; - Project.solution.CloseItem (this); + origSource = source = null; + IsOpened = false; } public void Undo(object sender){ undo(); @@ -276,7 +302,15 @@ namespace Crow.Coding } + public void onDoubleClick (object sender, MouseButtonEventArgs e){ + if (IsOpened) + return; + Open (); + } + public void onClick (object sender, MouseButtonEventArgs e){ + IsSelected = true; + } public void OnQueryClose (object sender, EventArgs e){ if (IsDirty) { MessageBox mb = MessageBox.ShowModal (CrowIDE.MainIFace, |