public override void CloseView(bool force) { if (!force && IsDirty) { ResourceService resourceService = (ResourceService)ServiceManager.Services.GetService(typeof(ResourceService)); DialogResult dr = MessageBox.Show(resourceService.GetString("MainWindow.SaveChangesMessage"), resourceService.GetString("MainWindow.SaveChangesMessageHeader") + " ?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (dr) { case DialogResult.Yes: if (ContentName == null) { SaveFileAs(); if (IsDirty) { return; //如果用户在保存新建的文件时选择了取消按钮,则直接返回,并且不关闭当前文档. } } else { FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService)); fileUtilityService.ObservedSave(new FileOperationDelegate(SaveFile), ContentName, FileErrorPolicy.ProvideAlternative); } break; case DialogResult.No: break; case DialogResult.Cancel: return; } } OnCloseEvent(null); }
public override void Run() { IViewContent content = WorkbenchSingleton.Workbench.ActiveViewContent; if (content != null) { if (content.IsViewOnly) { return; } if (content.ContentName == null) { SaveFileAs sfa = new SaveFileAs(); sfa.Run(); } else { FileAttributes attr = FileAttributes.ReadOnly | FileAttributes.Directory | FileAttributes.Offline | FileAttributes.System; if ((File.GetAttributes(content.ContentName) & attr) != 0) { SaveFileAs sfa = new SaveFileAs(); sfa.Run(); } else { FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService)); fileUtilityService.ObservedSave(new FileOperationDelegate(content.SaveFile), content.ContentName); } } } }
public IXmlConvertable GetStoredMemento(IViewContent content) { if (content != null && content.ContentName != null) { PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService)); string directory = propertyService.ConfigDirectory + "temp"; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string fileName = content.ContentName.Substring(3).Replace('/', '.').Replace('\\', '.').Replace(Path.DirectorySeparatorChar, '.'); string fullFileName = directory + Path.DirectorySeparatorChar + fileName; // check the file name length because it could be more than the maximum length of a file name FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService)); if (fileUtilityService.IsValidFileName(fullFileName) && File.Exists(fullFileName)) { IXmlConvertable prototype = ((IMementoCapable)content).CreateMemento(); XmlDocument doc = new XmlDocument(); doc.Load(fullFileName); return((IXmlConvertable)prototype.FromXmlElement((XmlElement)doc.DocumentElement.ChildNodes[0])); } } return(null); }
public FileList() { FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService)); Columns.Add("文件", 100, HorizontalAlignment.Left); Columns.Add("大小", -2, HorizontalAlignment.Right); Columns.Add("最后修改时间", -2, HorizontalAlignment.Left); try { watcher = new FileSystemWatcher(); } catch {} if (watcher != null) { watcher.NotifyFilter = NotifyFilters.FileName; watcher.EnableRaisingEvents = false; watcher.Renamed += new RenamedEventHandler(fileRenamed); watcher.Deleted += new FileSystemEventHandler(fileDeleted); watcher.Created += new FileSystemEventHandler(fileCreated); watcher.Changed += new FileSystemEventHandler(fileChanged); } HideSelection = false; GridLines = true; LabelEdit = true; SmallImageList = IconManager.List; HeaderStyle = ColumnHeaderStyle.Nonclickable; View = View.Details; Alignment = ListViewAlignment.Left; }
public override void Run() { string fileName = Application.StartupPath + Path.DirectorySeparatorChar + System.Configuration.ConfigurationSettings.AppSettings["HelpFileDirectory"].ToString(); FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService)); if (fileUtilityService.TestFileExists(fileName)) { Help.ShowHelp((Form)WorkbenchSingleton.Workbench, fileName); } }
void InitializeView() { ImageList smalllist = new ImageList(); ImageList imglist = new ImageList(); imglist.ImageSize = new Size(32, 32); smalllist.ImageSize = new Size(16, 16); smalllist.Images.Add(ResourceService.GetBitmap("Icons.32x32.EmptyFileIcon")); imglist.Images.Add(ResourceService.GetBitmap("Icons.32x32.EmptyFileIcon")); int i = 0; Hashtable tmp = new Hashtable(icons); FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService)); foreach (DictionaryEntry entry in icons) { Bitmap bitmap = ResourceService.GetBitmap(entry.Key.ToString()); if (bitmap != null) { smalllist.Images.Add(bitmap); imglist.Images.Add(bitmap); tmp[entry.Key] = ++i; } else { Console.WriteLine("can't load bitmap " + entry.Key.ToString() + " using default"); } } icons = tmp; foreach (TemplateItem item in alltemplates) { if (item.Template.Icon == null) { item.ImageIndex = 0; } else { item.ImageIndex = (int)icons[item.Template.Icon]; } } templateview.LargeImageList = imglist; templateview.SmallImageList = smalllist; InsertCategories(null, categories); if (categories.Count > 0) { categorytree.SelectedNode = (TreeNode)categorytree.Nodes[0]; } }
public override void Run() { FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService)); string file = site.StartsWith("home://") ? fileUtilityService.GetDirectoryNameWithSeparator(Application.StartupPath) + site.Substring(7).Replace('/', Path.DirectorySeparatorChar) : site; try { Process.Start(file); } catch (Exception) { MessageBox.Show("Can't execute/view " + file + "\n Please check that the file exists and that you can open this file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static FileTemplate() { FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService)); StringCollection files = fileUtilityService.SearchDirectory(Application.StartupPath + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "resources" + Path.DirectorySeparatorChar + "templates", "*.xft"); foreach (string file in files) { LoadFileTemplate(file); } }
static void WriteToolsToFile(string fileName) { XmlDocument doc = new XmlDocument(); doc.LoadXml("<TOOLS VERSION = \"" + TOOLFILEVERSION + "\" />"); foreach (ExternalTool et in tool) { doc.DocumentElement.AppendChild(et.ToXmlElement(doc)); } FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService)); fileUtilityService.ObservedSave(new NamedFileOperationDelegate(doc.Save), fileName, FileErrorPolicy.ProvideAlternative); }
public override void Run() { IViewContent content = WorkbenchSingleton.Workbench.ActiveViewContent; if (content != null) { if (content.IsViewOnly) { return; } using (SaveFileDialog fdiag = new SaveFileDialog()) { fdiag.OverwritePrompt = true; fdiag.AddExtension = true; string[] fileFilters = (string[])(AddInTreeSingleton.AddInTree.GetTreeNode("/DataStructure/Workbench/FileFilter").BuildChildItems(this)).ToArray(typeof(string)); fdiag.Filter = String.Join("|", fileFilters); for (int i = 0; i < fileFilters.Length; ++i) { if (fileFilters[i].IndexOf(Path.GetExtension(content.ContentName == null ? content.UntitledName : content.ContentName)) >= 0) { fdiag.FilterIndex = i + 1; break; } } if (fdiag.ShowDialog() == DialogResult.OK) { string fileName = fdiag.FileName; IFileService fileService = (IFileService)NetFocus.DataStructure.Services.ServiceManager.Services.GetService(typeof(IFileService)); FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService)); if (!fileUtilityService.IsValidFileName(fileName)) { MessageBox.Show("File name " + fileName + " is invalid"); return; } if (fileUtilityService.ObservedSave(new NamedFileOperationDelegate(content.SaveFile), fileName) == FileOperationResult.OK) { fileService.RecentOpenMemeto.AddLastFile(fileName); //MessageBox.Show(fileName, "文件已保存", MessageBoxButtons.OK); } } } } }
void FillLists() { string uPath = Path.Combine(PropertyService.DataDirectory, "modes"); StringCollection uCol; if (Directory.Exists(uPath)) { uCol = FileUtilityService.SearchDirectory(uPath, "*.xshd", true); } else { Directory.CreateDirectory(uPath); uCol = new StringCollection(); } foreach (string str in uCol) { XmlTextReader reader = new XmlTextReader(str); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "SyntaxDefinition": string name = reader.GetAttribute("name"); if (name != null) { highlightItemNameList.Add(new DictionaryEntry(name, str)); } goto exit; default: MessageBox.Show("不可识别的根节点在高亮度显示策略文件中:" + str, "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); goto exit; } } } exit: reader.Close(); } userList.Items.Clear(); userList.DataSource = highlightItemNameList; userList.DisplayMember = "Key"; userList.ValueMember = "Value"; }
public override bool StorePanelContents() { ArrayList newlist = new ArrayList(); foreach (ExternalTool tool in ((ListBox)ControlDictionary["toolListBox"]).Items) { if (!FileUtilityService.IsValidFileName(tool.Command)) { MessageService.ShowError(String.Format("The command of tool \"{0}\" is invalid.", tool.MenuCommand)); return(false); } newlist.Add(tool); } ToolLoader.Tool = newlist; ToolLoader.SaveTools(); ((DefaultWorkbench)WorkbenchSingleton.Workbench).CreateMenu(null, null); return(true); }
public override void Run() { FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService)); foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection) { if (content.IsViewOnly) { continue; } if (content.ContentName == null) { using (SaveFileDialog fdiag = new SaveFileDialog()) { fdiag.OverwritePrompt = true; fdiag.AddExtension = true; fdiag.Filter = String.Join("|", (string[])(AddInTreeSingleton.AddInTree.GetTreeNode("/DataStructure/Workbench/FileFilter").BuildChildItems(this)).ToArray(typeof(string))); if (fdiag.ShowDialog() == DialogResult.OK) { string fileName = fdiag.FileName; if (Path.GetExtension(fileName).StartsWith("?") || Path.GetExtension(fileName) == "*") { fileName = Path.ChangeExtension(fileName, ""); } if (fileUtilityService.ObservedSave(new NamedFileOperationDelegate(content.SaveFile), fileName) == FileOperationResult.OK) { //MessageBox.Show(fileName, "文件已保存", MessageBoxButtons.OK); } } } } else { fileUtilityService.ObservedSave(new FileOperationDelegate(content.SaveFile), content.ContentName); } } }
public void StoreMemento(IViewContent content) { if (content.ContentName == null) { return; } PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService)); string directory = propertyService.ConfigDirectory + "temp"; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } XmlDocument doc = new XmlDocument(); doc.LoadXml("<?xml version=\"1.0\"?>\n<Mementoable/>"); XmlAttribute fileAttribute = doc.CreateAttribute("file"); fileAttribute.InnerText = content.ContentName; doc.DocumentElement.Attributes.Append(fileAttribute); IXmlConvertable memento = ((IMementoCapable)content).CreateMemento(); doc.DocumentElement.AppendChild(memento.ToXmlElement(doc)); string fileName = content.ContentName.Substring(3).Replace('/', '.').Replace('\\', '.').Replace(Path.DirectorySeparatorChar, '.'); FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService)); // check the file name length because it could be more than the maximum length of a file name string fullFileName = directory + Path.DirectorySeparatorChar + fileName; if (fileUtilityService.IsValidFileName(fullFileName)) { fileUtilityService.ObservedSave(new NamedFileOperationDelegate(doc.Save), fullFileName, FileErrorPolicy.ProvideAlternative); } }
void startEvent(object sender, System.EventArgs e) { resultListView.BeginUpdate(); resultListView.Items.Clear(); switch (locationComboBox.SelectedIndex) { case 0: { // current file IViewContent content = WorkbenchSingleton.Workbench.ActiveViewContent; if (content != null) { if (content.ContentName == null) { MessageBox.Show(ResourceService.GetString("Dialog.WordCountDialog.SaveTheFileWarning"), ResourceService.GetString("Global.WarningText"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService)); if (fileUtilityService.TestFileExists(content.ContentName)) { resultListView.Items.Add(GetReport(content.ContentName).ToListItem()); } } } break; } case 1: { // all open files if (WorkbenchSingleton.Workbench.ViewContentCollection.Count > 0) { string tmp = ""; Report all = new Report(ResourceService.GetString("Dialog.WordCountDialog.TotalText"), 0, 0, 0); foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection) { if (content.ContentName == null) { MessageBox.Show(ResourceService.GetString("Dialog.WordCountDialog.SaveAllFileWarning"), ResourceService.GetString("Global.WarningText"), MessageBoxButtons.OK, MessageBoxIcon.Warning); continue; } else { FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService)); if (fileUtilityService.TestFileExists(content.ContentName)) { Report r = GetReport(content.ContentName); tmp += r.ToString(); all += r; resultListView.Items.Add(r.ToListItem()); } } } resultListView.Items.Add(new ListViewItem("")); resultListView.Items.Add(all.ToListItem()); } break; } } resultListView.EndUpdate(); }
public ShellTree() { Sorted = true; TreeNode rootNode = Nodes.Add("桌面"); rootNode.ImageIndex = 6; rootNode.SelectedImageIndex = 6; rootNode.Tag = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); TreeNode myFilesNode = rootNode.Nodes.Add("我的文档"); myFilesNode.ImageIndex = 7; myFilesNode.SelectedImageIndex = 7; try { myFilesNode.Tag = Environment.GetFolderPath(Environment.SpecialFolder.Personal); } catch (Exception) { myFilesNode.Tag = "C:\\"; } myFilesNode.Nodes.Add(""); TreeNode computerNode = rootNode.Nodes.Add("我的电脑"); computerNode.ImageIndex = 8; computerNode.SelectedImageIndex = 8; try { computerNode.Tag = Environment.GetFolderPath(Environment.SpecialFolder.Personal); } catch (Exception) { computerNode.Tag = "C:\\"; } foreach (string driveName in Environment.GetLogicalDrives()) { DriveObject drive = new DriveObject(driveName); TreeNode node = new TreeNode(drive.ToString()); node.Nodes.Add(new TreeNode("")); node.Tag = driveName.Substring(0, driveName.Length - 1); computerNode.Nodes.Add(node); FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService)); switch (DriveObject.GetDriveType(driveName)) { case DriveType.Removeable: node.ImageIndex = node.SelectedImageIndex = 2; break; case DriveType.Fixed: node.ImageIndex = node.SelectedImageIndex = 3; break; case DriveType.Cdrom: node.ImageIndex = node.SelectedImageIndex = 4; break; case DriveType.Remote: node.ImageIndex = node.SelectedImageIndex = 5; break; default: node.ImageIndex = node.SelectedImageIndex = 3; break; } } foreach (string directory in Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory))) { TreeNode node = rootNode.Nodes.Add(Path.GetFileName(directory)); node.Tag = directory; node.ImageIndex = node.SelectedImageIndex = 0; node.Nodes.Add(new TreeNode("")); } rootNode.Expand(); computerNode.Expand(); InitializeComponent(); }