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); } } }
public void AddStashTab(StashBookmark stashBookmark) { var vm = new StashBookmarkViewModel(stashBookmark); var index = FindTabIndex(vm); Bookmarks.Insert(index, vm); _persistentData.StashBookmarks.Insert(index, stashBookmark); }
public StashBookmarkViewModel(StashBookmark bookmark) { Bookmark = bookmark; }
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); } } }