Skip to content

Commit

Permalink
Implemented adding folders, saving projects automatically and updated…
Browse files Browse the repository at this point in the history
… various minor aspects.
  • Loading branch information
hach-que committed Aug 11, 2011
1 parent fd7dd8d commit 0f4cf3a
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 107 deletions.
4 changes: 2 additions & 2 deletions ide/src/Designers/Start/Designer.cs
Expand Up @@ -27,8 +27,8 @@ public Designer(MOAI.Manager manager, File file)
this.CanSave = false;
this.File = null;

this.TabText = "Start Page";
this.c_WebBrowser.Url = new System.Uri(Program.Manager.Settings["RootPath"] + "/Start Page/index.htm", System.UriKind.Absolute);
this.TabText = "Cloud Dashboard";
this.c_WebBrowser.Url = new System.Uri("http://dashboard.moaicloud.com/login.php", System.UriKind.Absolute);
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions ide/src/MOAI IDE.csproj
Expand Up @@ -602,6 +602,7 @@
</Compile>
<Compile Include="Management\Associations.cs" />
<Compile Include="Templates\Files\BaseTemplate.cs" />
<Compile Include="Templates\Files\FolderTemplate.cs" />
<Compile Include="Templates\Files\ScriptTemplate.cs" />
<Compile Include="Templates\Files\FileCreationData.cs" />
<Compile Include="Templates\Solutions\BaseTemplate.cs" />
Expand Down
5 changes: 4 additions & 1 deletion ide/src/Management/File.cs
Expand Up @@ -54,7 +54,10 @@ public virtual void Associate(System.Windows.Forms.TreeNode node)
{
// Set properties.
this.Text = this.ToString();
this.ImageKey = Associations.GetImageKey(this.p_FileInfo.Extension.Substring(1));
if (this.p_FileInfo.Extension != "")
this.ImageKey = Associations.GetImageKey(this.p_FileInfo.Extension.Substring(1));
else
this.ImageKey = null;
this.SelectedImageKey = this.ImageKey;

// Add this file to the node.
Expand Down
42 changes: 26 additions & 16 deletions ide/src/Management/Folder.cs
Expand Up @@ -71,27 +71,37 @@ public DirectoryInfo FolderInfo
}

/// <summary>
/// Returns the context menu for this file.
/// Returns the context menu for this folder.
/// </summary>
public override ContextMenu ContextMenu
public override ContextMenuStrip ContextMenuStrip
{
get
{
return new ContextMenu(new MenuItem[] {
new MenuItem("Add"),
new MenuItem("-"),
new MenuItem("Exclude From Project"),
new MenuItem("-"),
new MenuItem("Cut"),
new MenuItem("Copy"),
new MenuItem("Paste"),
new MenuItem("Delete"),
new MenuItem("Rename"),
new MenuItem("-"),
new MenuItem("Open Folder in Windows Explorer"),
new MenuItem("-"),
new MenuItem("Properties")
// Set the context menu for the node.
ContextMenuStrip ret = new ContextMenuStrip();
ret.Items.AddRange(new ToolStripItem[] {
new ToolStripMenuItem("Add", null, new ToolStripItem[] {
Menus.Manager.WrapAction(new Menus.Definitions.Project.AddNewItem(this)),
Menus.Manager.WrapAction(new Menus.Definitions.Project.AddExistingItem(this)),
Menus.Manager.WrapAction(new Menus.Definitions.Project.AddFolder(this)),
new ToolStripSeparator(),
Menus.Manager.WrapAction(new Menus.Definitions.Project.AddScript(this)),
Menus.Manager.WrapAction(new Menus.Definitions.Project.AddClass(this))
}),
new ToolStripSeparator(),
Menus.Manager.WrapAction(new Menus.Definitions.Actions.Exclude(this)),
new ToolStripSeparator(),
Menus.Manager.WrapAction(new Menus.Definitions.Actions.Cut(this)),
Menus.Manager.WrapAction(new Menus.Definitions.Actions.Copy(this)),
Menus.Manager.WrapAction(new Menus.Definitions.Actions.Paste(this)),
Menus.Manager.WrapAction(new Menus.Definitions.Actions.Remove(this)),
Menus.Manager.WrapAction(new Menus.Definitions.Actions.Rename(this)),
new ToolStripSeparator(),
Menus.Manager.WrapAction(new Menus.Definitions.Actions.OpenInWindowsExplorer(this)),
new ToolStripSeparator(),
Menus.Manager.WrapAction(new Menus.Definitions.Actions.Properties(this))
});
return ret;
}
}

Expand Down
113 changes: 67 additions & 46 deletions ide/src/Management/Project.cs
Expand Up @@ -25,20 +25,52 @@ public class Project
public Project()
{
this.p_ProjectInfo = null;

// Add our own events for handling when files are added
// or removed.
this.FileAdded += new EventHandler((sender, e) =>
{
this.Save();
});
this.FileRemoved += new EventHandler((sender, e) =>
{
this.Save();
});
}

/// <summary>
/// Loads a new instance of the Project class from a file on disk.
/// </summary>
/// <param name="file">The solution file to be loaded.</param>
public Project(FileInfo file)
: this()
{
this.p_ProjectInfo = file;

// Read the project data from the file.
this.LoadFromXml(this.p_ProjectInfo);
}

/// <summary>
/// Creates a new Project object that represents a MOAI project. The
/// constructor attempts to load the from disk using the specified path.
/// </summary>
/// <param name="path">The path to the project file.</param>
public Project(string path)
: this()
{
this.p_ProjectInfo = new FileInfo(path);
this.p_Files = new List<File>();

if (this.p_ProjectInfo.Exists)
{
this.LoadFromXml(this.p_ProjectInfo);
this.p_Initalized = true;
}
else
this.p_Initalized = false;
}

/// <summary>
/// Gets the File object based on the relative path provided. The specified path must
/// be a file that is included in the project.
Expand Down Expand Up @@ -127,61 +159,17 @@ private void WriteFiles(XmlWriter writer, System.Collections.ObjectModel.ReadOnl
foreach (File f in files)
{
if (f is Folder)
this.WriteFiles(writer, (f as Folder).Files, (f as Folder).FolderInfo.Name);
this.WriteFiles(writer, (f as Folder).Files, (path + "/" + (f as Folder).FolderInfo.Name).TrimStart(new char[] { '/' }));
else
{
writer.WriteStartElement("File");
writer.WriteAttributeString("Include", path + f.FileInfo.Name);
writer.WriteAttributeString("Include", (path + "/" + f.FileInfo.Name).TrimStart(new char[] { '/' }));
writer.WriteString("");
writer.WriteEndElement();
}
}
}

#endregion

/// <summary>
/// Creates a new Project object that represents a Roket3D project. The
/// constructor attempts to load the from disk using the specified path.
/// </summary>
/// <param name="path">The path to the project file.</param>
public Project(string path)
{
this.p_ProjectInfo = new FileInfo(path);
this.p_Files = new List<File>();

if (this.p_ProjectInfo.Exists)
{
this.LoadFromXml(this.p_ProjectInfo);
this.p_Initalized = true;
}
else
this.p_Initalized = false;
}

/// <summary>
/// Whether the project has been initialized.
/// </summary>
public bool Initalized
{
get
{
return this.p_Initalized;
}
}

/// <summary>
/// The FileInfo object that represents the on-disk project file for
/// this project.
/// </summary>
public FileInfo ProjectInfo
{
get
{
return this.p_ProjectInfo;
}
}

/// <summary>
/// Loads the project data from the specified XML document.
/// </summary>
Expand Down Expand Up @@ -229,6 +217,8 @@ private void LoadFromXml(FileInfo file)
if (!handled)
{
Folder newf = new Folder(this, file.Directory.FullName, path.Substring(0, path.Length - 1));
newf.FileAdded += new EventHandler(ff_FileAdded);
newf.FileRemoved += new EventHandler(ff_FileRemoved);
this.p_Files.Add(newf);
ff = newf;
}
Expand All @@ -246,6 +236,8 @@ private void LoadFromXml(FileInfo file)
if (!handled)
{
Folder newf = new Folder(this, file.Directory.FullName, path.Substring(0, path.Length - 1));
newf.FileAdded += new EventHandler(ff_FileAdded);
newf.FileRemoved += new EventHandler(ff_FileRemoved);
ff.Add(newf);
ff = newf;
}
Expand All @@ -262,6 +254,31 @@ private void LoadFromXml(FileInfo file)
}
}

#endregion

/// <summary>
/// Whether the project has been initialized.
/// </summary>
public bool Initalized
{
get
{
return this.p_Initalized;
}
}

/// <summary>
/// The FileInfo object that represents the on-disk project file for
/// this project.
/// </summary>
public FileInfo ProjectInfo
{
get
{
return this.p_ProjectInfo;
}
}

/// <summary>
/// Returns a TreeNode for TreeView that represents this project.
/// </summary>
Expand All @@ -287,6 +304,10 @@ public System.Windows.Forms.TreeNode ToTreeNode()
Menus.Manager.WrapAction(new Menus.Definitions.Project.ProjBuildOrder(this)),
new ToolStripSeparator(),
new ToolStripMenuItem("Add", null, new ToolStripItem[] {
Menus.Manager.WrapAction(new Menus.Definitions.Project.AddNewItem(this)),
Menus.Manager.WrapAction(new Menus.Definitions.Project.AddExistingItem(this)),
Menus.Manager.WrapAction(new Menus.Definitions.Project.AddFolder(this)),
new ToolStripSeparator(),
Menus.Manager.WrapAction(new Menus.Definitions.Project.AddScript(this)),
Menus.Manager.WrapAction(new Menus.Definitions.Project.AddClass(this))
}),
Expand Down
53 changes: 51 additions & 2 deletions ide/src/Menus/Definitions/Project.cs
Expand Up @@ -51,7 +51,7 @@ class AddNewItem : Action
public override void OnInitialize()
{
this.ItemIcon = Properties.Resources.file_add;
this.Text = "Add New Item";
this.Text = "Add New Item...";
this.Enabled = true;

// Listen for events.
Expand Down Expand Up @@ -291,7 +291,56 @@ public override void OnInitialize()
{
this.Implemented = false;
this.ItemIcon = null;
this.Text = "Add Existing Item";
this.Text = "Add Existing Item...";
this.Enabled = false;
}
}

class AddFolder : Action
{
public AddFolder() : base() { }
public AddFolder(object context) : base(context) { }

/// <summary>
/// This event is raied when the menu item is to be initalized.
/// </summary>
public override void OnInitialize()
{
this.ItemIcon = Properties.Resources.folder;
this.Text = "Add Folder...";
this.Enabled = true;

// Listen for events.
Program.Manager.SolutionLoaded += new EventHandler(Manager_OnSolutionLoaded);
Program.Manager.SolutionUnloaded += new EventHandler(Manager_OnSolutionUnloaded);
}

/// <summary>
/// This event is raised when the menu item is clicked or otherwise activated.
/// </summary>
public override void OnActivate()
{
if (this.Context is Management.Project)
(this.Context as Management.Project).AddFileInteractive("FolderTemplate");
else if (this.Context is Management.Folder)
(this.Context as Management.Folder).Project.AddFileInteractive("FolderTemplate", this.Context as Management.Folder);
else
Program.Manager.ActiveProject.AddFileInteractive("FolderTemplate");
}

/// <summary>
/// This event is raised when a solution is loaded (opened).
/// </summary>
private void Manager_OnSolutionLoaded(object sender, EventArgs e)
{
this.Enabled = true;
}

/// <summary>
/// This event is raised when a solution is unloaded (closed).
/// </summary>
private void Manager_OnSolutionUnloaded(object sender, EventArgs e)
{
this.Enabled = false;
}
}
Expand Down
63 changes: 63 additions & 0 deletions ide/src/Templates/Files/FolderTemplate.cs
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using MOAI.Management;
using System.IO;

namespace MOAI.Templates.Files
{
public class FolderTemplate : BaseTemplate
{
public override string TemplateName
{
get { return "Empty Folder"; }
}

public override string TemplateDescription
{
get { return "an empty folder for storing files"; }
}

public override string TemplateExtension
{
get { return ""; }
}

public override Bitmap TemplateIcon
{
get { return null; }
}

/// <summary>
/// Creates a new empty folder in the specified project, in the specified folder.
/// </summary>
/// <param name="data">The solution creation data, usually derived from the user's input in a NewSolutionForm.</param>
/// <returns>A new solution that can be loaded.</returns>
public override MOAI.Management.File Create(string name, Project project, Folder folder)
{
MOAI.Management.Folder ff = null;

// Determine where to place the folder.
if (folder == null)
{
// Place the folder in the root of the project
ff = new MOAI.Management.Folder(project, project.ProjectInfo.DirectoryName, name);
project.AddFile(ff);
}
else
{
// Place the folder in the specified folder
ff = new MOAI.Management.Folder(project, project.ProjectInfo.DirectoryName, Path.Combine(folder.FolderInfo.Name, name));
folder.Add(ff);
}

// Create the new folder on disk.
if (!Directory.Exists(ff.FolderInfo.FullName))
Directory.CreateDirectory(ff.FolderInfo.FullName);

return ff;
}
}
}

0 comments on commit 0f4cf3a

Please sign in to comment.