⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 templatefile.cs

📁 代码模版 codtemplate
💻 CS
字号:
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.Windows.Forms;

namespace CodeTemplate
{
	/// <summary>
	/// Summary description for TemplateFile.
	/// </summary>
	internal class TemplateFile
	{
        public TemplateFile(String filePath)
		{
			try
			{
				m_filePath = filePath;

				FileInfo fi = new FileInfo(m_filePath);
				if(!fi.Exists)
				{
					CreateTemplateFromSampleFile();
					m_filePath = Configuration.TemplateFilePath;
				}

				m_fileList = new ArrayList();
				m_templateMenuIDs = new Hashtable();
				m_ok = false;
			}
			catch(Exception)
			{
			}
		}

		static public void CreateTemplateFromSampleFile()
		{
			DirectoryInfo di = new DirectoryInfo(Configuration.RoamingDataDirectory);
			if(!di.Exists)
				di.Create();
				
			foreach(Configuration.SampleFileInfo sample in Configuration.SampleFiles)
			{
				// If the sample template file doesn't exist in the user's roaming directory, 
				// create a copy from the sample directory
				FileInfo fi = new FileInfo(sample.RoamingFile);
				if(!fi.Exists)
				{
					fi = new FileInfo(sample.SampleFile);
					fi.CopyTo(sample.RoamingFile);
				}
			}
		}

		public Boolean IsALoadedTemplateFile(String filePath)
		{
			foreach(FileChangeInfo info in m_fileList)
			{
				if(String.Compare(info.FilePath, filePath, true) == 0)
					return true;
			}

			return false;
		}

        public String BaseFilePath
        {
            get { return ((FileChangeInfo)m_fileList[0]).FilePath; }
		}

		public Boolean Changed
		{
			get 
			{ 
				// Assume change if no files have been parsed
				if(m_fileList.Count == 0) 
					return true;

				// Let's see if any of the loaded files has changed
				foreach(FileChangeInfo info in m_fileList)
				{
					if(info.Changed)
						return true;
				}
				
				return false;
			}
		}

		public Boolean IsOK
		{
			get { return m_ok; }
		}

		public void CacheMenuID(String menuID, TemplateMenuItem menuItem)
		{
			if(menuID == null)
				return;

			String id = menuID.ToUpper();
			if(m_templateMenuIDs.ContainsKey(id))
			{
				MessageBox.Show("Duplicate menu ID: " + id);
				return;
			}

			m_templateMenuIDs.Add(id, menuItem);
		}

		public TemplateMenuItem GetTemplateByID(String menuID)
		{
			return (TemplateMenuItem) m_templateMenuIDs[menuID.ToUpper()];
		}

		public void AddFileChangeInfo(String filePath)
		{
			FileChangeInfo info = new FileChangeInfo(filePath);
			info.Refresh();

			m_fileList.Add(info);
		}

		public void ReadFile(TemplatePopupMenu menu)
		{
			m_ok = false;

			menu.Clear();
			m_templateMenuIDs.Clear();
           
			try
			{
				TemplateFileParser parser = new TemplateFileParser(m_filePath);
				parser.Parse(this, menu);

				if(!menu.IsBalanced)
					throw new Exception("Mismatched submenu definitions");

				m_ok = true;
			}
			catch(FileNotFoundException ex)
			{
				throw new Exception("Cannot find include file " + ex.FileName, ex);
			}
			finally
			{
				menu.PopAll();
				menu.AddSeparator();
				menu.Add("Open <" + Path.GetFileName(this.BaseFilePath) + ">", null, OpenTemplateFileMenuID);
				menu.Add("Rebind Keyboard\t" + Configuration.KeyBindingKeys, null, RebindKeyboardMenuID);
				menu.Add("Help", null, OpenHelpMenuID);
				menu.Add("About Code<Template>.NET", null, AboutMenuID);
			}
		}
        
		public static Int32 OpenTemplateFileMenuID 
		{
			get { return -1; }
		}

		public static Int32 RebindKeyboardMenuID
		{
			get { return -2; } 
		}

		public static Int32 OpenHelpMenuID
		{
			get { return -3; }
		}

		public static Int32 AboutMenuID
		{
			get { return -4; }
		}

		#region Data members

		private String m_filePath;
		private ArrayList m_fileList;
		private Hashtable m_templateMenuIDs;
		private Boolean m_ok;

		#endregion
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -