public void DeleteSubItem(IUniverseSubItem subItem) { if (subItem is StoryViewModel) { StoryViewModel story = (StoryViewModel)subItem; Stories.Remove(story); if (story.Model.CategoryId != null) { CategoryViewModel cat = Categories.Single(i => i.Model.id == story.Model.CategoryId); cat.Stories.Remove(story); cat.UpdateStorySortIndices(); } UpdateSubItemSortIndices(); } else if (subItem is CategoryViewModel) { CategoryViewModel cat = (CategoryViewModel)subItem; List <StoryViewModel> stories = cat.Stories.ToList(); foreach (var story in stories) { story.Model.CategoryId = null; story.SortIndex = SubItems.Max(i => i.SortIndex) + 1; story.Save(); SubItems.Add(story); } Categories.Remove(cat); SubItems.Remove(cat); UpdateSubItemSortIndices(); } }
public void CreateStory() { Story story = new Story(Model.Connection); story.UniverseId = Model.id; StoryPropertiesDialog dialog = new StoryPropertiesDialog(DialogOwner, story, Categories); bool?result = dialog.ShowDialog(); if (result.HasValue && result.Value) { if (story.CategoryId == null) { if (SubItems.Count > 0) { story.SortIndex = SubItems.Max(i => i.SortIndex) + 1; } else { story.SortIndex = 0; } } else { if (Stories.Count(i => i.Model.CategoryId == story.CategoryId) > 0) { story.SortIndex = Stories.Where(i => i.Model.CategoryId == story.CategoryId).Max(i => i.SortIndex + 1); } else { story.SortIndex = 0; } } story.Create(); StoryViewModel storyVm = new StoryViewModel(story); storyVm.UniverseVm = this; Stories.Add(storyVm); UpdateStoryInTree(storyVm); } }
public void CreateCategory() { NameItemDialog dialog = new NameItemDialog(DialogOwner, "New Category"); bool? result = dialog.ShowDialog(); if (result.HasValue && result.Value) { Category category = new Category(Model.Connection); category.UniverseId = Model.id; category.Name = dialog.UserInput; if (SubItems.Count > 0) { category.SortIndex = SubItems.Max(i => i.SortIndex) + 1; } category.Create(); CategoryViewModel catVm = new CategoryViewModel(category); catVm.UniverseVm = this; Categories.Add(catVm); SubItems.Add(catVm); } }
public override void Draw(IGraphics graphics, AppTime appTime) { // todo: draw individual char, check for & and have a different color for the char thereafter // ex: &File, should emphasize on (F) var ops = this.TextRenderOperations; //ops.Insert(0, new DrawStringOperation(" ", this.ForegroundColor, this.BackgroundColor)); //ops.Add(new DrawStringOperation(" ", this.ForegroundColor, this.BackgroundColor)); var totalWidth = 0; //graphics.DrawLine(Position.X, Position.Y, Position.X + Size.Width - 1, Position.Y, this.BackgroundColor); if (this.IsSelected) { foreach (var op in ops) { graphics.DrawString(op.Text, Position.X + totalWidth, Position.Y, ConsoleColor.White, Application.ThemeColor); totalWidth += op.Text.Length; } var remaining = this.Size.Width - 1 - totalWidth; if (remaining > 0) { graphics.DrawString(new string(' ', remaining), Position.X + totalWidth, Position.Y, ConsoleColor.White, Application.ThemeColor); } } else { foreach (var op in ops) { graphics.DrawString( op.Text, Position.X + totalWidth, Position.Y, this.IsEnabled ? op.ForegroundColor : this.DisabledForegroundColor, this.BackgroundColor); totalWidth += op.Text.Length; } } if (this.IsMenuOpen) { // draw sub items, this is actually the menu, but to draw it we have to determine the amount of rows we want to draw and then // draw borders around them. if (SubItems.Count > 0) { var height = SubItems.Count + 3; // +2 is th border top and border bottom var width = Math.Max(this.MinWidth, SubItems.Max(x => (x.Text?.Length + 2) ?? 0)) + 2; // max width var offsetY = 2; var borderOffsetY = 1; if (BorderThickness.Top == 0) { --height; --offsetY; --borderOffsetY; } graphics.DrawShadowRect(this.Position.X, this.Position.Y + 1, width, height, this.BackgroundColor); graphics.DrawBorder(BorderThickness, this.Position.X, this.Position.Y + borderOffsetY, width - 2, height - offsetY, this.BorderColor, this.BackgroundColor); // draw each item for (var i = 0; i < SubItems.Count; ++i) { using (var gfx = graphics.CreateViewport(this.Position.X + 1, this.Position.Y + i + offsetY)) { SubItems[i].Size = new System.Drawing.Size(width - 2, 1); SubItems[i].Draw(gfx, appTime); } } } } }