public static ManagedFile SaveFileAs(string text) { ManagedFile file = null; var lastPath = StateManager.SystemState.LastFileOpenLocation; if (string.IsNullOrEmpty(lastPath)) { lastPath = CommonFolders.UserProjects; } var dlg = new SaveFileDialog(); dlg.InitialDirectory = lastPath; dlg.DefaultExt = ".cs"; dlg.Filter = "C Sharp (*.cs)|*.cs|Visual Basic (*.vb)|*.vb|All File (*.*)|*.*"; var result = dlg.ShowDialog(); if (result == DialogResult.OK) { file = ManagedFile.Create(dlg.FileName); file.Save(text); StateManager.SystemState.LastFileOpenLocation = file.FilePath; if (file.Extension == ".lyzard") { StateManager.SystemState.RecentProjects.Add(file.FullPath); } else { StateManager.SystemState.RecentFiles.Add(file.FullPath); } } return(file); }
private void CreateLogFile() { if (_logPath != LogFileName()) { _logPath = LogFileName(); _logFile = ManagedFile.Create(_logPath); } }
private Settings LoadSettings() { _file = ManagedFile.Create(_settingsPath); if (_file.Load().Length > 0) { return(_file.Load <Settings>()); } else { var settings = new Settings(); _file.Save <Settings>(Settings); return(settings); } }
private void WriteCache(string path, string text) { if (_cache.ContainsKey(path)) { var file = _cache[path].Item1; _cache[path] = Tuple.Create(file, text); file.Save(text); } else { var file = ManagedFile.Create(path); _cache.Add(path, Tuple.Create(file, text)); file.Save(text); } }
/////////////////////// /// private methods /// /////////////////// private string ReadCache(string path) { if (_cache.ContainsKey(path)) { return(_cache[path].Item2); } else { var file = ManagedFile.Create(path); var contents = file.Load(); file.Changed += File_Changed; _cache[path] = Tuple.Create(file, contents); return(contents); } }
public CodeEditorViewModel(string path) { _file = ManagedFile.Create(path); SystemLog.Instance.LogInfo($"Opening file...{_file.FileName}"); if (_file != null) { Document.Text = _file.Load(); ContentId = $"file://{_file.FullPath}"; SyntaxHighlighting = HighlightingManager.Instance.GetDefinitionByExtension( _file.Extension ); Title = _file.FileName + $" - ({SyntaxHighlighting?.Name})"; initialLoad = true; } }