public ProjectItemViewModel GetSelectedBlueprint() { ProjectItemViewModel selected = SelectedItem; if (selected == null) { return(null); } if (selected.Type == ProjectItemType.Root) { return(null); } if (selected.Type != ProjectItemType.Blueprints) { selected = GetParentBlueprint(selected); } if (selected == null) { return(null); } else { return(selected); } }
public string ImportReferences(string code) { List <string> imports = new List <string>(); List <string> lines = new List <string>(System.Text.RegularExpressions.Regex.Split(code, Environment.NewLine)); foreach (string line in lines) { System.Text.RegularExpressions.Regex import = new System.Text.RegularExpressions.Regex(@"^#import\s[a-zA-Z0-9\-_()\[\]+~`'.!@#$%^&]+$"); if (import.IsMatch(line)) { string name = line.Replace("#import ", String.Empty); if (!imports.Contains(name)) { imports.Add(name); } } } foreach (string import in imports) { ProjectItemViewModel reference = GetReferences().FirstOrDefault(i => i.Name == import); if (reference != null) { string content = File.Read(reference.Path); code = code.Replace("#import " + import, String.Empty); code += Environment.NewLine + Environment.NewLine + content; } } return(code); }
public void PerformSearch() { if (_MatchingItemEnumerator == null || !_MatchingItemEnumerator.MoveNext()) { VerifyMatchingItemEnumerator(); } if (_MatchingItemEnumerator == null) { return; } var item = _MatchingItemEnumerator.Current; if (item == null) { return; } if (item.Parent != null) { ProjectItemViewModel parent = (ProjectItemViewModel)item.Parent; parent.IsExpanded = true; } // TODO switch search to filter (hide unmatched items), probably handled by the UI instead item.IsSelected = true; }
public void VerifyFiles() { if (!IsVerifying) { BeginVerify(); foreach (PageViewModel page in _Editor.Items) { if (!page.IgnoreUpdates) { ProjectItemViewModel item = _Project.GetItemByPath(page.Filename); if (File.LastWriteTime(page.Filename) > page.LastSaved) { string message = String.Format("{0} has been modified outside SE Workbench. Do you want to reload it?", page.ProjectItem.Name); MessageBoxResult result = Services.MessageBox.ShowQuestion(message); if (result == MessageBoxResult.Yes) { page.UpdateContent(); } else { page.IgnoreUpdates = true; } } } } EndVerify(); } VerifyPaths(); }
private string BuildScript(string path) { string result = String.Empty; ProjectItemViewModel item = Project.GetItemByPath(path); if (item != null) { string code = File.Read(item.Path); List <string> scripts = Project.GetAssociatedScripts(path); if (scripts.Count < 1) { result += code; } else { result += String.Format("{0}{1}{1}", code, Environment.NewLine); foreach (string script in scripts) { result += String.Format("{0}{1}{1}", script, Environment.NewLine); } } result = Project.ImportReferences(result); } return(result); }
public void PerformAddBlueprints() { ProjectItemViewModel rootitem = _RootItem; if (rootitem == null) { return; } string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string blueprints = Path.Combine(appdata, "SpaceEngineers", "Blueprints"); // TODO implement my own open file dialog to avoid API Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog() { DefaultExt = ".sbc", Filter = "Blueprints File (.sbc)|*.sbc", Multiselect = false, InitialDirectory = blueprints, }; Nullable <bool> result = dialog.ShowDialog(); if (result != null && result.Value == true) { string fullpath = dialog.FileName; string name; Interop.Grid grid; Interop.Blueprint.Import(fullpath, out name, out grid); if (grid != null) { string safename = CreateSafeName(name); string savepath = Path.Combine(Path.GetDirectoryName(rootitem.Path), safename); try { Directory.CreateDirectory(savepath); ProjectItem item = new ProjectItem() { Name = name, Path = savepath, Blueprint = fullpath, Type = ProjectItemType.Blueprints, Project = this, }; rootitem.AddChild(item, grid); rootitem.IsExpanded = true; } catch (Exception ex) { MessageBox.ShowError("Unable to create add blueprint", ex); return; } SaveProject(); } } }
public void PerformDelete() { ProjectItemViewModel selected = SelectedItem; if (selected == null) { return; } if (selected.Type == ProjectItemType.Reference) { PerformRemoveReference(); return; } if (selected.Type != ProjectItemType.Blueprints && selected.Type != ProjectItemType.Folder && selected.Type != ProjectItemType.File) { return; } string message = String.Format("'{0}' will be deleted permanantly?", selected.Name); var result = MessageBox.ShowQuestion(message); if (result == System.Windows.MessageBoxResult.Yes) { bool success = false; try { switch (selected.Type) { case ProjectItemType.Blueprints: case ProjectItemType.Folder: Directory.Delete(selected.Path, true); break; case ProjectItemType.File: File.Delete(selected.Path); break; } success = true; } catch (Exception ex) { MessageBox.ShowError("Unable to delete the selected item", ex); } finally { if (success) { selected.Remove(); SaveProject(); RaiseFileDeleted(selected); } } } }
public PageViewModel(BaseViewModel parent, string name, string path) : base(parent) { ProjectItemViewModel vm = new ProjectItemViewModel(new Models.ProjectItem()) { Name = name, Path = path }; Initialize(parent, vm, Models.PageType.Output); }
public void RaiseFileCreated(ProjectItemViewModel item) { if (item.Type == ProjectItemType.File) { if (FileCreated != null) { FileCreated(this, new FileEventArgs(item.Path)); } } }
public void RaiseReferenceAdded(ProjectItemViewModel item) { if (item.Type == ProjectItemType.Reference) { if (ReferenceAdded != null) { ReferenceAdded(this, new FileEventArgs(item.Path)); } } }
public void PerformAddFile() { ProjectItemViewModel selected = SelectedItem; if (selected == null) { return; } if (selected.Type != ProjectItemType.Blueprints && selected.Type != ProjectItemType.Collection && selected.Type != ProjectItemType.Folder) { selected = GetParentFolder(selected); } if (selected == null || selected.Type == ProjectItemType.Root) { return; } Views.NewItemDialog view = new Views.NewItemDialog(); Nullable <bool> result = view.ShowDialog(); if (result != null && result.Value == true) { string fullpath = Path.Combine(selected.Path, String.Format("{0}.csx", view.ItemName)); try { string starter = Services.NewFile.Contents; File.Write(fullpath, starter); ProjectItemViewModel newfile = null; string name = Path.GetFileNameWithoutExtension(fullpath); ProjectItem item = new ProjectItem() { Name = name, Path = fullpath, Type = ProjectItemType.File, Project = this }; newfile = selected.AddChild(item); selected.IsExpanded = true; if (newfile != null) { RaiseFileCreated(newfile); } } catch (Exception ex) { MessageBox.ShowError("Unable to create new file", ex); return; } SaveProject(); } }
private bool ReferencesExists(ProjectItemViewModel root) { foreach (ProjectItemViewModel child in root.Children) { if (child.Type == ProjectItemType.References) { return(true); } } return(false); }
private void Project_SelectionChanged(object sender, EventArgs e) { ProjectItemViewModel item = Project.GetSelectedBlueprint(); if (item != null) { Blueprint.SetBlueprint(item.Grid); } else { Blueprint.SetBlueprint(null); } }
public void PerformAddFolder() { ProjectItemViewModel selected = SelectedItem; if (selected == null) { return; } if (selected.Type != ProjectItemType.Root && selected.Type != ProjectItemType.Blueprints && selected.Type != ProjectItemType.Collection && selected.Type != ProjectItemType.Folder) { selected = GetParentFolder(selected); } if (selected == null) { return; } Views.NewItemDialog view = new Views.NewItemDialog(); Nullable <bool> result = view.ShowDialog(); if (result != null && result.Value == true) { string name = view.ItemName; string fullpath = Path.Combine(selected.Path, name); if (selected.Type == ProjectItemType.Root) { fullpath = Path.Combine(Path.GetDirectoryName(selected.Path), name); } try { Directory.CreateDirectory(fullpath); ProjectItem item = new ProjectItem() { Name = name, Path = fullpath, Type = ProjectItemType.Folder, Project = this, }; selected.AddChild(item); selected.IsExpanded = true; } catch (Exception ex) { MessageBox.ShowError("Unable to create new directory", ex); return; } SaveProject(); } }
public ProjectItemViewModel(ProjectItem item, ProjectItemViewModel parent) : base(parent) { _Model = item; _Children = new Services.ObservableSortedList <ProjectItemViewModel>( (from child in _Model.Children select new ProjectItemViewModel(child, this)).ToList <ProjectItemViewModel>(), new Comparers.ProjectItemComparer() ); _Grid = new Services.ObservableSortedList <GridItemViewModel>( new GridItemViewModel[] { }, new Comparers.GridItemComparer() ); }
public ProjectItemViewModel GetSelectedFile() { ProjectItemViewModel selected = SelectedItem; if (selected == null) { return(null); } if (selected.Type == ProjectItemType.File) { return(selected); } return(null); }
public ProjectItemViewModel AddChild(ProjectItem item, Interop.Grid grid) { ProjectItemViewModel vm = new ProjectItemViewModel(item, this); if (grid != null) { vm.Grid.Add(CreateGridViewModel(grid)); } _Children.Add(vm); Model.Children.Add(item); return(vm); }
public void RaiseFileDeleted(ProjectItemViewModel item) { if (item.Type == ProjectItemType.File) { if (FileDeleted != null) { FileDeleted(this, new FileEventArgs(item.Path)); } } foreach (ProjectItemViewModel child in item.Children) { RaiseFileDeleted(child); } }
public ProjectItemViewModel(ProjectItem item, ProjectItemViewModel parent) : base(parent) { _Model = item; _Children = new Services.ObservableSortedList<ProjectItemViewModel>( (from child in _Model.Children select new ProjectItemViewModel(child, this)).ToList<ProjectItemViewModel>(), new Comparers.ProjectItemComparer() ); _Grid = new Services.ObservableSortedList<GridItemViewModel>( new GridItemViewModel[] { }, new Comparers.GridItemComparer() ); }
public void SetRootItem(ProjectItem root) { if (root == null) { _RootItem = null; _First.Clear(); return; } SetProject(root, this); _RootItem = new ProjectItemViewModel(root); _First.Clear(); _First.Add(_RootItem); }
public ProjectItemViewModel GetItemByPath(ProjectItemViewModel item, string path) { if (item.Path == path) { return(item); } foreach (ProjectItemViewModel child in item.Children) { ProjectItemViewModel result = GetItemByPath(child, path); if (result != null) { return(result); } } return(null); }
private void Initialize(BaseViewModel parent, ProjectItemViewModel item, Models.PageType type) { _ProjectItem = item; _Model = new Models.Page(); Header = item.Name; Identifier = Guid.NewGuid(); Type = type; item.PropertyChanged += ProjectItem_PropertyChanged; BuildEditor(); _CloseFileCommand = new Commands.DelegateCommand(PerformCloseFile); _SelectPageCommand = new Commands.DelegateCommand(PerformSelectPage); }
private ProjectItemViewModel GetParentFolder(ProjectItemViewModel child) { if (child == null || child.Parent == null) { return(null); } ProjectItemViewModel parent = (ProjectItemViewModel)child.Parent; if (parent.Type == ProjectItemType.Root || parent.Type == ProjectItemType.Collection || parent.Type == ProjectItemType.Blueprints || parent.Type == ProjectItemType.Folder) { return(parent); } else { return(GetParentFolder(parent)); } }
public void RaiseSelectionChanged() { RaisePropertyChanged("SelectedItemType"); ProjectItemViewModel selected = SelectedItem; if (selected == null) { selected = _RootItem; } if (selected.Type != ProjectItemType.Blueprints && selected.Type != ProjectItemType.Folder) { selected = GetParentFolder(selected); } SelectionChanged(this, EventArgs.Empty); }
public List <string> GetAssociatedScripts(string path) { List <string> scripts = new List <string>(); ProjectItemViewModel item = GetItemByPath(path); if (item != null) { ProjectItemViewModel collection = GetParentCollection(item); if (collection != null) { List <string> add = new List <string>(); scripts.AddRange(CollectScripts(path, collection, add)); } } return(scripts); }
private IEnumerable <ProjectItemViewModel> FindMatches(string text, ProjectItemViewModel item) { if (item == null) { yield return(null); } if (item.NameContainsText(text)) { yield return(item); } foreach (ProjectItemViewModel child in item.Children) { foreach (ProjectItemViewModel match in FindMatches(text, child)) { yield return(match); } } }
public ProjectItemViewModel GetParentBlueprint(ProjectItemViewModel item) { if (item == null || item.Type == ProjectItemType.Root) { return(null); } if (item.Type == ProjectItemType.Blueprints) { return(item); } if (item.Parent == null) { return(null); } else { ProjectItemViewModel parent = (ProjectItemViewModel)item.Parent; return(GetParentBlueprint(parent)); } }
private List <string> CollectScripts(string path, ProjectItemViewModel item, List <string> scripts) { if (item == null) { return(scripts); } if (item.Type == ProjectItemType.File && item.Path != path) { string code = File.Read(item.Path); scripts.Add(code); } foreach (ProjectItemViewModel child in item.Children) { List <string> empty = new List <string>(); scripts.AddRange(CollectScripts(path, child, empty)); } return(scripts); }
private ProjectItemViewModel GetParentCollection(ProjectItemViewModel item) { if (item == null || item.Type == ProjectItemType.Root) { return(null); } if (item.Type == ProjectItemType.Collection) { return(item); } if (item.Parent == null) { return(null); } else { ProjectItemViewModel parent = (ProjectItemViewModel)item.Parent; return(GetParentCollection(parent)); } }
private IEnumerable <ProjectItemViewModel> FindSelected(ProjectItemViewModel item) { if (item == null) { yield return(null); } if (item.IsSelected) { yield return(item); } foreach (ProjectItemViewModel child in item.Children) { foreach (ProjectItemViewModel match in FindSelected(child)) { // TODO fix collection modified exception yield return(match); } } }
public void PerformOpenItem(ProjectItemViewModel item) { if (item != null) { if (!File.Exists(item.Path)) { return; } foreach (PageViewModel page in Editor.Items) { if (page.Filename == item.Path) { page.IsActive = true; return; } } PageViewModel newpage = new PageViewModel(this, item); Editor.Items.Add(newpage); } }
public ProjectItemViewModel AddChild(ProjectItem item, Interop.Grid grid) { ProjectItemViewModel vm = new ProjectItemViewModel(item, this); if (grid != null) { vm.Grid.Add(CreateGridViewModel(grid)); } _Children.Add(vm); Model.Children.Add(item); return vm; }
public ProjectItemViewModel GetItemByPath(ProjectItemViewModel item, string path) { if (item.Path == path) { return item; } foreach (ProjectItemViewModel child in item.Children) { ProjectItemViewModel result = GetItemByPath(child, path); if (result != null) { return result; } } return null; }
private void RemoveChild(ProjectItemViewModel child) { Model.Children.Remove(child.Model); _Children.Remove(child); }
private ProjectItemViewModel GetParentCollection(ProjectItemViewModel item) { if (item == null || item.Type == ProjectItemType.Root) { return null; } if (item.Type == ProjectItemType.Collection) { return item; } if (item.Parent == null) { return null; } else { ProjectItemViewModel parent = (ProjectItemViewModel)item.Parent; return GetParentCollection(parent); } }
public PageViewModel(BaseViewModel parent, ProjectItemViewModel item) : base(parent) { Initialize(parent, item, Models.PageType.Page); }
public ProjectItemViewModel GetParentBlueprint(ProjectItemViewModel item) { if (item == null || item.Type == ProjectItemType.Root) { return null; } if (item.Type == ProjectItemType.Blueprints) { return item; } if (item.Parent == null) { return null; } else { ProjectItemViewModel parent = (ProjectItemViewModel)item.Parent; return GetParentBlueprint(parent); } }
private List<BackupItem> GetBackups(ProjectItemViewModel item) { BackupManager manager = new BackupManager(this.Model.Path); List<BackupItem> result = new List<BackupItem>(); if (item.Type == ProjectItemType.File) { BackupItem backup = manager.GetBackup(item.Path); if (backup != null) { result.Add(backup); } } foreach(ProjectItemViewModel child in item.Children) { result.AddRange(GetBackups(child)); } return result; }
private IEnumerable<ProjectItemViewModel> FindSelected(ProjectItemViewModel item) { if (item == null) { yield return null; } if (item.IsSelected) { yield return item; } foreach (ProjectItemViewModel child in item.Children) { foreach (ProjectItemViewModel match in FindSelected(child)) { // TODO fix collection modified exception yield return match; } } }
private bool ReferencesExists(ProjectItemViewModel root) { foreach(ProjectItemViewModel child in root.Children) { if (child.Type == ProjectItemType.References) { return true; } } return false; }
private IEnumerable<ProjectItemViewModel> FindMatches(string text, ProjectItemViewModel item) { if (item == null) { yield return null; } if (item.NameContainsText(text)) { yield return item; } foreach (ProjectItemViewModel child in item.Children) { foreach (ProjectItemViewModel match in FindMatches(text, child)) { yield return match; } } }
private ProjectItemViewModel GetParentFolder(ProjectItemViewModel child) { if (child == null || child.Parent == null) { return null; } ProjectItemViewModel parent = (ProjectItemViewModel)child.Parent; if (parent.Type == ProjectItemType.Root || parent.Type == ProjectItemType.Collection || parent.Type == ProjectItemType.Blueprints || parent.Type == ProjectItemType.Folder) { return parent; } else { return GetParentFolder(parent); } }
private List<string> CollectScripts(string path, ProjectItemViewModel item, List<string> scripts) { if (item == null) { return scripts; } if (item.Type == ProjectItemType.File && item.Path != path) { string code = File.Read(item.Path); scripts.Add(code); } foreach (ProjectItemViewModel child in item.Children) { List<string> empty = new List<string>(); scripts.AddRange(CollectScripts(path, child, empty)); } return scripts; }
private void LoadBlueprints(ProjectItemViewModel item, bool failed) { if (item.Type == ProjectItemType.Blueprints) { string name; Interop.Grid grid; Interop.Blueprint.Import(item.Blueprint, out name, out grid); if (grid == null) { failed = true; } else { item.SetGrid(grid); } } foreach (ProjectItemViewModel child in item.Children) { LoadBlueprints(child, failed); } }