aboutsummaryrefslogtreecommitdiffstatsci
path: root/CrowIDE/src/ProjectTree
diff options
context:
space:
mode:
Diffstat (limited to 'CrowIDE/src/ProjectTree')
-rw-r--r--CrowIDE/src/ProjectTree/ProjectFile.cs66
-rw-r--r--CrowIDE/src/ProjectTree/ProjectItem.cs45
-rw-r--r--CrowIDE/src/ProjectTree/ProjectNodes.cs25
3 files changed, 119 insertions, 17 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,
diff --git a/CrowIDE/src/ProjectTree/ProjectItem.cs b/CrowIDE/src/ProjectTree/ProjectItem.cs
index 7a30a8e1..89889ca3 100644
--- a/CrowIDE/src/ProjectTree/ProjectItem.cs
+++ b/CrowIDE/src/ProjectTree/ProjectItem.cs
@@ -43,7 +43,26 @@ namespace Crow.Coding
public XmlNode node;
- public string Extension {
+ public override Picture Icon {
+ get {
+ Console.WriteLine("extension="+Extension);
+
+ switch (Extension)
+ {
+ case ".cs":
+ return new SvgPicture("#icons.cs-file.svg");
+ case ".crow":
+ Console.WriteLine("loading icons.xml-file");
+ return new SvgPicture("#icons.xml-file.svg");
+ case ".xml":
+ return new SvgPicture("#icons.xml-file.svg");
+ default:
+ return base.Icon;
+ }
+ }
+ }
+
+ public string Extension {
get { return System.IO.Path.GetExtension (Path); }
}
public string Path {
@@ -71,6 +90,30 @@ namespace Crow.Coding
public string HintPath {
get { return node.SelectSingleNode ("HintPath")?.InnerText; }
}
+
+ public override bool IsSelected {
+ get {
+ return isSelected;
+ }
+ set {
+ if (value == isSelected)
+ return;
+
+ isSelected = value;
+
+ NotifyValueChanged ("IsSelected", isSelected);
+
+ if (isSelected) {
+ Project.solution.SelectedItem = this;
+ Project.IsExpanded = true;
+ ProjectNode pn = Parent;
+ while (pn != null) {
+ pn.IsExpanded = true;
+ pn = pn.Parent;
+ }
+ }
+ }
+ }
}
}
diff --git a/CrowIDE/src/ProjectTree/ProjectNodes.cs b/CrowIDE/src/ProjectTree/ProjectNodes.cs
index b9c855f1..5f518ff7 100644
--- a/CrowIDE/src/ProjectTree/ProjectNodes.cs
+++ b/CrowIDE/src/ProjectTree/ProjectNodes.cs
@@ -79,6 +79,7 @@ namespace Crow.Coding
ProjectNode parent;
bool isExpanded;
+ protected bool isSelected;
ItemType type;
string name;
List<ProjectNode> childNodes = new List<ProjectNode>();
@@ -86,6 +87,18 @@ namespace Crow.Coding
public Project Project;
public List<Crow.Command> Commands;//list of command available for that node
+ public virtual Crow.Picture Icon {
+ get {
+ switch (Type) {
+ case ItemType.Reference:
+ return new SvgPicture ("#Crow.Icons.assembly.svg");
+ case ItemType.ProjectReference:
+ return new SvgPicture("#Crow.Icons.projectRef.svg");
+ default:
+ return new SvgPicture("#icons.blank-file.svg");
+ }
+ }
+ }
public ProjectNode Parent {
get { return parent; }
set { parent = value; }
@@ -124,7 +137,19 @@ namespace Crow.Coding
NotifyValueChanged ("IsExpanded", isExpanded);
}
}
+ public virtual bool IsSelected
+ {
+ get { return isSelected; }
+ set
+ {
+ if (value == isSelected)
+ return;
+
+ isSelected = value;
+ NotifyValueChanged ("IsSelected", isSelected);
+ }
+ }
public override string ToString ()
{
return DisplayName;