- Timestamp:
- 09/13/13 13:49:03 (11 years ago)
- Location:
- stable
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 9714,9833,9841,9850,9949
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Data.Views/3.3
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/trunk/sources/HeuristicLab.Data.Views/3.3 merged eligible /branches/Algorithms.GradientDescent/HeuristicLab.Data.Views/3.3 5516-5520 /branches/Benchmarking/sources/HeuristicLab.Data.Views/3.3 6917-7005 /branches/CloningRefactoring/HeuristicLab.Data.Views/3.3 4656-4721 /branches/DataAnalysis Refactoring/HeuristicLab.Data.Views/3.3 5471-5808 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Data.Views/3.3 5815-6180 /branches/DataAnalysis/HeuristicLab.Data.Views/3.3 4458-4459,4462,4464 /branches/GP.Grammar.Editor/HeuristicLab.Data.Views/3.3 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Data.Views/3.3 5060 /branches/HeuristicLab.Data Path DataTypes/HeuristicLab.Data.Views/3.3 9669-9706 /branches/NET40/sources/HeuristicLab.Data.Views/3.3 5138-5162 /branches/ParallelEngine/HeuristicLab.Data.Views/3.3 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Data.Views/3.3 7568-7810 /branches/QAPAlgorithms/HeuristicLab.Data.Views/3.3 6350-6627 /branches/Restructure trunk solution/HeuristicLab.Data.Views/3.3 6828 /branches/RuntimeOptimizer/HeuristicLab.Data.Views/3.3 8943-9078 /branches/ScatterSearch (trunk integration)/HeuristicLab.Data.Views/3.3 7787-8333 /branches/SlaveShutdown/HeuristicLab.Data.Views/3.3 8944-8956 /branches/SuccessProgressAnalysis/HeuristicLab.Data.Views/3.3 5370-5682 /branches/Trunk/HeuristicLab.Data.Views/3.3 6829-6865 /branches/UnloadJobs/HeuristicLab.Data.Views/3.3 9168-9215 /branches/VNS/HeuristicLab.Data.Views/3.3 5594-5752 /branches/histogram/HeuristicLab.Data.Views/3.3 5959-6341
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
stable/HeuristicLab.Data.Views/3.3/Path Views/TextFileView.cs
r9714 r9961 24 24 using System.IO; 25 25 using System.Windows.Forms; 26 using HeuristicLab.Core.Views;27 26 using HeuristicLab.MainForm; 27 using HeuristicLab.PluginInfrastructure; 28 28 29 29 namespace HeuristicLab.Data.Views { 30 30 [View("TextFileView")] 31 31 [Content(typeof(TextFileValue), true)] 32 public sealed partial class TextFileView : ItemView {33 private bool changedFileContent;34 private bool ChangedFileContent{35 get { return changedFileContent; }32 public sealed partial class TextFileView : FileValueView { 33 private bool fileContentChanged; 34 private bool FileContentChanged { 35 get { return fileContentChanged; } 36 36 set { 37 if ( changedFileContent!= value) {38 changedFileContent= value;39 On ChangedFileContent();37 if (fileContentChanged != value) { 38 fileContentChanged = value; 39 OnFileContentChanged(); 40 40 } 41 41 } … … 49 49 public TextFileView() { 50 50 InitializeComponent(); 51 changedFileContent= false;51 fileContentChanged = false; 52 52 } 53 53 54 54 protected override void RegisterContentEvents() { 55 55 base.RegisterContentEvents(); 56 Content.ValueChanged += Content_FilePathChanged; 57 Content.FileOpenDialogFilterChanged += Content_FileDialogFilterChanged; 56 Content.StringValue.ValueChanged += Content_FilePathChanged; 58 57 } 59 58 protected override void DeregisterContentEvents() { 60 Content.ValueChanged -= Content_FilePathChanged; 61 Content.FileOpenDialogFilterChanged -= Content_FileDialogFilterChanged; 59 Content.StringValue.ValueChanged -= Content_FilePathChanged; 62 60 fileSystemWatcher.EnableRaisingEvents = false; 63 61 base.DeregisterContentEvents(); … … 66 64 base.SetEnabledStateOfControls(); 67 65 textBox.ReadOnly = Locked || ReadOnly || Content == null; 68 saveButton.Enabled = !Locked && !ReadOnly && Content != null && ChangedFileContent;66 saveButton.Enabled = !Locked && !ReadOnly && Content != null && FileContentChanged; 69 67 70 68 if (Content != null && Content.Exists()) { … … 83 81 protected override void OnContentChanged() { 84 82 base.OnContentChanged(); 85 ChangedFileContent= false;83 FileContentChanged = false; 86 84 if (Content == null) { 87 fileValueView.Content = null;88 85 textBox.Text = string.Empty; 89 86 //mkommend: other properties of the file system watcher cannot be cleared (e.g., path) as this leads to an ArgumentException … … 91 88 return; 92 89 } 93 94 fileValueView.Content = Content;95 90 saveFileDialog.Filter = Content.FileDialogFilter; 96 91 UpdateTextBox(); … … 101 96 SetEnabledStateOfControls(); 102 97 } 103 private void Content_FileDialogFilterChanged(object sender, EventArgs e) {104 saveFileDialog.Filter = Content.FileDialogFilter;105 }106 98 107 99 private void textBox_TextChanged(object sender, EventArgs e) { 108 ChangedFileContent= fileText != textBox.Text;109 } 110 111 private void On ChangedFileContent() {100 FileContentChanged = fileText != textBox.Text; 101 } 102 103 private void OnFileContentChanged() { 112 104 SetEnabledStateOfControls(); 113 if (ChangedFileContent) { 114 textBox.ForeColor = Color.Red; 115 } else { 116 textBox.ForeColor = Color.Black; 117 } 105 textBox.ForeColor = FileContentChanged ? Color.Red : Color.Black; 118 106 } 119 107 … … 146 134 } else { 147 135 fileText = newContent; 148 ChangedFileContent= true;136 FileContentChanged = true; 149 137 } 150 138 } … … 185 173 WriteFile(path, textBox.Text); 186 174 Content.Value = path; 187 ChangedFileContent= false;175 FileContentChanged = false; 188 176 fileSystemWatcher.EnableRaisingEvents = true; 189 177 } … … 212 200 } 213 201 private void textBox_Validated(object sender, EventArgs e) { 214 if (! ChangedFileContent) return;202 if (!FileContentChanged) return; 215 203 string msg = string.Format("You have not saved the changes in the file \"{0}\" yet. Do you want to save the changes?", Content.Value); 216 204 var result = MessageBox.Show(this, msg, "Save changes?", MessageBoxButtons.YesNo, MessageBoxIcon.Information); … … 229 217 if (!File.Exists(path)) return null; 230 218 string fileContent = string.Empty; 231 using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { 232 using (StreamReader streamReader = new StreamReader(fileStream)) { 233 fileContent = streamReader.ReadToEnd(); 234 } 219 try { 220 using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { 221 using (StreamReader streamReader = new StreamReader(fileStream)) { 222 fileContent = streamReader.ReadToEnd(); 223 } 224 } 225 } 226 catch (Exception e) { 227 ErrorHandling.ShowErrorDialog(e); 235 228 } 236 229 return fileContent; … … 238 231 239 232 private static void WriteFile(string path, string fileContent) { 240 using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Write)) { 241 using (StreamWriter streamWriter = new StreamWriter(fileStream)) { 242 streamWriter.Write(fileContent); 243 } 233 try { 234 using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None)) { 235 using (StreamWriter streamWriter = new StreamWriter(fileStream)) { 236 streamWriter.Write(fileContent); 237 } 238 } 239 } 240 catch (Exception e) { 241 ErrorHandling.ShowErrorDialog(e); 244 242 } 245 243 }
Note: See TracChangeset
for help on using the changeset viewer.