public void AddItems(IEnumerable <Item> items, string tabname = null) { int y = LastOccupiedLine + 2; if (tabname != null) { StashBookmark sb = new StashBookmark(tabname, y); AddBookmark(sb); } int x = 0; int maxh = 0; var y2 = y; var y3 = y; foreach (var item in items) { if (x + item.Width > 12) //next line { x = 0; y += maxh; maxh = 0; } item.X = x; x += item.Width; if (maxh < item.Height) { maxh = item.Height; } item.Y = y; Items.Add(item); if (y3 < item.Y + item.Height) { y3 = item.Y + item.Height; } } AddHighlightRange(new IntRange() { From = y2, Range = y3 - y2 }); ResizeScrollbarThumb(); }
private void R_MouseDown(object sender, MouseButtonEventArgs e) { Rectangle r = sender as Rectangle; StashBookmark sb = r.Tag as StashBookmark; _dnd_startDrag = Mouse.GetPosition(gcontent); _dnd_overlay = new Rectangle() { Fill = r.Fill, Height = r.Height, Margin = r.Margin, Opacity = 0.3, }; gcontent.Children.Add(_dnd_overlay); Grid.SetZIndex(_dnd_overlay, 52635); DragDrop.DoDragDrop(this, sender, DragDropEffects.Move); gcontent.Children.Remove(_dnd_overlay); _dnd_overlay = null; }
private void DeleteBookmarkAndItems(StashBookmark bm) { var from = bm.Position; var to = Bookmarks.Where(b => b.Position > from) .Select(b => b.Position) .DefaultIfEmpty(LastLine) .Min(); var diff = to - from; foreach (var item in Items.ToList()) { if (item.Y >= from && item.Y < to) { Items.Remove(item); } else if (item.Y >= to) { item.Y -= diff; Items.Remove(item); Items.Add(item); } } Bookmarks.Remove(bm); _usedBMarks.Values.ForEach(gcontent.Children.Remove); _usedBMarks.Clear(); foreach (var bookmark in Bookmarks.ToList()) { if (bookmark.Position >= to) { bookmark.Position -= diff; Bookmarks.Remove(bookmark); AddBookmark(bookmark); } } ResizeScrollbarThumb(); }
public void AddBookmark(StashBookmark stashBookmark) { Bookmarks.Insert(FindBPos(stashBookmark.Position, 0, Bookmarks.Count), stashBookmark); }
private void btnPopupLoadFile_Click(object sender, RoutedEventArgs e) { var fileDialog = new OpenFileDialog { Multiselect = false }; var ftoload = fileDialog.ShowDialog(this); if (ftoload.Value) { try { var tabs = JObject.Parse(File.ReadAllText(fileDialog.FileName))["tabs"] as JArray; List<StashBookmark> tabb = new List<StashBookmark>(); foreach (JObject tab in tabs) { string name = tab["n"].Value<string>(); int index = tab["i"].Value<int>(); var c = tab["colour"].Value<JObject>(); var color = Color.FromArgb(0xFF, c["r"].Value<byte>(), c["g"].Value<byte>(), c["b"].Value<byte>()); StashBookmark sb = new StashBookmark(name, index, color); tabb.Add(sb); } Tabs = tabb; cbTabs.SelectedIndex = 0; } catch (Exception ex) { Popup.Error(L10n.Message("An error occurred while attempting to load stash data."), ex.Message); } } }
private void btnPopupLoadTabFile_Click(object sender, RoutedEventArgs e) { var fileDialog = new OpenFileDialog { Multiselect = false }; var ftoload = fileDialog.ShowDialog(this); if (ftoload.Value) { var cont = File.ReadAllText(fileDialog.FileName); var mw = this.Owner as MainWindow; if (mw == null) return; var stash = mw.Stash; IntRange highlightrange = null; try { var data = File.ReadAllText(fileDialog.FileName); var json = JObject.Parse(data); var items = (json["items"] as JArray).Select(i => new Item((JObject)i)).ToArray(); //get free line var y = stash.LastOccupiedLine + 3; var fittingitems = items.Where(i => i.X >= 0 && i.X + i.Width <= 12).ToList(); StashBookmark sb = new StashBookmark("imported", y); if (cbTabs.SelectedItem != null) { var sstab = cbTabs.SelectedItem as StashBookmark; sb = new StashBookmark(sstab.Name, y, sstab.Color); } stash.BeginUpdate(); stash.AddBookmark(sb); var my = fittingitems.Min(i => i.Y); var y2 = y; var unfittingitems = items.Where(i => i.X < 0 || i.X + i.Width > 12); foreach (var item in items) { item.Y += y - my; stash.Items.Add(item); if (y2 < item.Y + item.Height) y2 = item.Y + item.Height; } int x = 0; int maxh = 0; var y3 = y2; foreach (var item in unfittingitems) { if (x + item.Width > 12) //next line { x = 0; y2 += maxh; maxh = 0; } item.X = x; x += item.Width; if (maxh < item.Height) maxh = item.Height; item.Y = y2; stash.Items.Add(item); if (y3 < item.Y + item.Height) y3 = item.Y + item.Height; } Popup.Info(string.Format(L10n.Message("New tab with {0} items was added to stash"),items.Length)); highlightrange = new IntRange() { From = y, Range = y3 - y }; } catch (Exception ex) { Popup.Error(L10n.Message("An error occurred while attempting to load stash data."), ex.Message); } finally { stash.EndUpdate(); } if (highlightrange != null) stash.AddHighlightRange(highlightrange); } }
private void gcontent_Drop(object sender, DragEventArgs e) { if (e.Source == null || (e.Source as FrameworkElement).FindAnchestor <Stash>() != this) { e.Effects = DragDropEffects.None; e.Handled = true; return; } if ((e.AllowedEffects & DragDropEffects.Move) != 0) { bool line = false; if (e.Data.GetDataPresent(typeof(Rectangle))) { line = true; if (!((e.Data.GetData(typeof(Rectangle)) as Rectangle).Tag is StashBookmark)) { e.Effects = DragDropEffects.None; return; } } else if (!e.Data.GetDataPresent(typeof(ItemVisualizer)) || _dnd_overlay.Fill != Brushes.DarkGreen) { e.Effects = DragDropEffects.None; return; } e.Handled = true; e.Effects = DragDropEffects.Move; var newpos = e.GetPosition(gcontent); var dx = newpos.X - _dnd_startDrag.X; var dy = newpos.Y - _dnd_startDrag.Y; var newx = _dnd_original_Margin.Left + dx; var newy = _dnd_original_Margin.Top + dy; var x = (int)Math.Round((newx / GridSize)); var y = (int)Math.Round((newy / GridSize)); y += (int)PageTop; if (line) { y = (int)Math.Round(newpos.Y / GridSize + PageTop); Rectangle r = e.Data.GetData(typeof(Rectangle)) as Rectangle; StashBookmark sb = r.Tag as StashBookmark; sb.Position = y; Bookmarks.Remove(sb); AddBookmark(sb); RedrawItems(); } else { var itm = _dnd_item; _dnd_item = null; itm.X = x; itm.Y = y; Items.Remove(itm); Items.Add(itm); } ResizeScrollbarThumb(); } }