Exemplo n.º 1
0
		public void AddFile(string inDirectory)
		{
			string caption = "Add New File";
			string label = "File Name:";
			string defaultLine = "New File.txt";

			LineEntryDialog dialog = new LineEntryDialog(caption, label, defaultLine);
			if (dialog.ShowDialog() == DialogResult.OK)
			{
				try
				{
					string path = Path.Combine(inDirectory, dialog.Line);

					OnFileCreated(path);
					
					// MIKA: DETECT EOL AND ENCODING
					Encoding encoding = this.fdActions.GetDefaultEncoding();
					string eolMarker = this.fdActions.GetDefaultEOLMarker();
					
					using (FileStream stream = File.Open(path,FileMode.CreateNew))
					{
						StreamWriter writer = new StreamWriter(stream, encoding);
						writer.Write(eolMarker);
						writer.Flush();
					}
					
					DocumentSeekRequest = 0;
					OnOpenFile(path);
				}
				catch (Exception exception)
				{
					ErrorHandler.ShowInfo("Could not add the file: " + exception.Message);
				}
			}
		}
Exemplo n.º 2
0
		public void AddClass(Project project, string inDirectory)
		{
			string caption = "Add New Class";
			string label = "Class Name:";
			string defaultLine = "NewClass";

			LineEntryDialog dialog = new LineEntryDialog(caption, label, defaultLine);
			if (dialog.ShowDialog() == DialogResult.OK)
			{
				try
				{
					string name = Path.GetFileNameWithoutExtension(dialog.Line);
					string path = Path.Combine(inDirectory, name + ".as");
					OnFileCreated(path);

					// figure out the best classpath to build from
					string classpath = project.AbsoluteClasspaths.GetClosestParent(path);

					// no luck?  try the global classpaths!
					if (classpath == null)
					{
						PathCollection globalPaths = new PathCollection();
						foreach (string cp in Settings.GlobalClasspaths.Split(';'))
							globalPaths.Add(cp);
						classpath = globalPaths.GetClosestParent(path);
					}

					// still no luck?  nothing else we can do
					if (classpath == null)
						throw new Exception("An appropriate project classpath could not be located to create the class from.");

					// figure out the full class name cleverly
					string className = PathHelper.GetRelativePath(classpath,path);
					className = className.Replace(".as", "");
					className = className.Replace(Path.DirectorySeparatorChar, '.');
					
					string constructor = className;
					int p = className.LastIndexOf('.');
					if (p >= 0) constructor = className.Substring(p+1);
					
					// MIKA: DETECT EOL AND ENCODING
					Encoding encoding = this.fdActions.GetDefaultEncoding();
					string eolMarker = this.fdActions.GetDefaultEOLMarker();
					
					using (FileStream stream = File.Open(path,FileMode.CreateNew))
					{
						StreamWriter writer = new StreamWriter(stream, encoding);
						string code = eolMarker;
						code += "class " + className + eolMarker;
						code += "{" + eolMarker;
						code += "\tfunction " + constructor + "()" + eolMarker;
						code += "\t{" + eolMarker;
						code += "\t\t";
						DocumentSeekRequest = code.Length;
						code += eolMarker;
						code += "\t}" + eolMarker;
						code += "}" + eolMarker;
						writer.Write(code);
						writer.Flush();
					}
					OpenFile(path);
				}
				catch (Exception exception)
				{
					ErrorHandler.ShowInfo("Could not add the class: " + exception.Message);
				}
			}
		}