2 using System.Collections.ObjectModel;
3 using System.ComponentModel;
7 using System.Threading.Tasks;
9 using FooEditEngine.UWP;
10 using Windows.Storage;
14 class MainViewModel : INotifyPropertyChanged
16 ObservableCollection<Document> _list = new ObservableCollection<Document>();
18 public MainViewModel()
22 public ObservableCollection<Document> DocumentList
30 Document _currentDocument;
31 public Document CurrentDocument
35 return this._currentDocument;
39 this._currentDocument = value;
40 this.OnPropertyChanged(this);
41 if(this.CurrentDocumentChanged != null)
42 this.CurrentDocumentChanged(this, null);
46 public event EventHandler CurrentDocumentChanged;
48 public event PropertyChangedEventHandler PropertyChanged;
50 public void Initalize()
52 var complete_collection = new CompleteCollection<ICompleteItem>();
53 CompleteHelper.AddComleteWord(complete_collection, "int");
54 CompleteHelper.AddComleteWord(complete_collection, "float");
55 CompleteHelper.AddComleteWord(complete_collection, "double");
56 CompleteHelper.AddComleteWord(complete_collection, "char");
57 CompleteHelper.AddComleteWord(complete_collection, "byte");
58 CompleteHelper.AddComleteWord(complete_collection, "var");
59 CompleteHelper.AddComleteWord(complete_collection, "short");
61 var doc = new Document() { Title = "test1" };
62 doc.AutoComplete = new AutoCompleteBox(doc);
63 doc.AutoComplete.Items = complete_collection;
64 doc.AutoComplete.Enabled = true;
65 doc.ShowLineBreak = true;
68 doc = new Document() { Title = "test2" };
71 this.CurrentDocument = _list[0];
74 public void AddDocument()
76 var doc = new Document() { Title = "test" + _list.Count };
78 this.CurrentDocument = _list.Last();
81 public async Task AddDocumentFromFile(IStorageFile file)
85 var doc = new Document() { Title = "test" + _list.Count };
86 doc.ShowLineBreak = true;
87 doc.ShowFullSpace = true;
89 using (var ws = await file.OpenAsync(FileAccessMode.Read))
90 using (var fs = new StreamReader(ws.AsStream()))
92 await doc.LoadAsync(fs, null);
96 this.CurrentDocument = _list.Last();
100 private void OnPropertyChanged(object sender, [System.Runtime.CompilerServices.CallerMemberName] string name = "")
102 if(this.PropertyChanged != null)
103 this.PropertyChanged(sender, new PropertyChangedEventArgs(name));