/// <summary> /// Determine if the path can be used to create a file or directory. /// </summary> /// /// <remarks> /// Optional to throw an exception message or just return <c>false</c> if invalid. /// Check <c>IoUtility.CheckCreatable()</c> at the first. /// Then return <c>true</c> if the file doesn't exist yet or force to <c>overwrite</c>. /// Otherwise popup a dialog for the user to make the decision. /// </remarks> /// /// <returns><c>true</c> if is creatable; otherwise, <c>false</c>.</returns> /// <param name="path">Path.</param> /// <param name="overwrite">Overwrite.</param> /// <param name="exception">Flag to throw an exception or return <c>false</c>.</param> /// public static bool CheckIoCreatable(string path, bool overwrite = false, bool exception = false) { if (!IoUtility.CheckCreatable(path, exception)) { return(false); } if (overwrite || !File.Exists(path)) { return(true); } var _message = Path.GetFileName(path) + " already exists.\nDo you want to replace it?"; if (EditorUtility.DisplayDialog("Confirm Save As", _message, "Yes", "No")) { return(true); } if (exception) { throw new OperationCanceledException(path + " already exists."); } else { return(false); } }
public bool Save(FileInfo file) { if (file != null) { IoUtility.SaveFile(CurrentFile.FullName, this.Text); //_textEditor.SaveFile(file.FullName); CurrentFile = file; TextChangedStatus = 0; //this.Text = Text; if (this.DockForm.TabText.EndsWith(" *")) { string title = this.DockForm.TabText; string newTitle = title.Substring(0, title.Length - 2); this.DockForm.TabText = newTitle; } return(true); } return(false); }
private void ListOld_DragDrop(object sender, DragEventArgs e) { string filePath = ((Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); try { var txt = IoUtility.GetFileText(filePath); if (string.IsNullOrWhiteSpace(txt)) { MessageBox.Show("该文件没有内容"); return; } } catch (Exception ex) { MessageBox.Show("错误:" + ex.Message); } }