示例#1
0
        private async Task LoadTabContents()
        {
            var tabContents = Clipboard.GetText();

            try
            {
                var json      = JObject.Parse(tabContents);
                var isQuadTab = json.Value <bool>("quadLayout");
                var items     = new List <Item>();
                foreach (JObject jItem in json["items"])
                {
                    if (isQuadTab)
                    {
                        // icons of quad tabs are downsized and their url doesn't allow inferring the normal-sized url
                        jItem.Remove("icon");
                    }
                    items.Add(new Item(_persistenData, jItem));
                }

                var yStart = _stash.LastOccupiedRow + 3;

                var selectedBookmark = TabsView.CurrentItem as StashBookmark;
                var sb = selectedBookmark != null
                    ? new StashBookmark(selectedBookmark.Name, yStart, selectedBookmark.Color)
                    : new StashBookmark("imported", yStart);

                _stash.BeginUpdate();
                _stash.AddStashTab(sb);

                var yOffsetInImported = items.Min(i => i.Y);
                var yMax = items.Max(i => i.Y + i.Height);
                foreach (var item in items)
                {
                    item.Y += yStart - yOffsetInImported;
                    if (item.X + item.Width > StashViewModel.Columns)
                    {
                        // Mostly for quad stash tabs:
                        // - add items on the right side below those on the left side
                        // - items crossing both sides have to be moved to one side, which might lead to stacked items
                        // Also makes sure items are not added outside the stash when importing other special tabs.
                        item.X  = Math.Max(0, Math.Min(item.X - StashViewModel.Columns, StashViewModel.Columns - 1));
                        item.Y += yMax;
                    }
                    _stash.AddItem(item, true);
                }

                await _dialogCoordinator.ShowInfoAsync(this, L10n.Message("New tab added"),
                                                       string.Format(L10n.Message("New tab with {0} items was added to stash."), items.Count));
            }
            catch (Exception e)
            {
                await _dialogCoordinator.ShowErrorAsync(this,
                                                        L10n.Message("An error occurred while attempting to load stash data."), e.Message);
            }
            finally
            {
                _stash.EndUpdate();
            }
        }
示例#2
0
        private async Task LoadTabContents()
        {
            var tabContents = Clipboard.GetText();

            try
            {
                var json  = JObject.Parse(tabContents);
                var items = json["items"].Select(i => new Item(_persistenData, (JObject)i)).ToArray();

                var yStart = _stash.LastOccupiedRow + 3;

                var selectedBookmark = TabsView.CurrentItem as StashBookmark;
                var sb = selectedBookmark != null
                    ? new StashBookmark(selectedBookmark.Name, yStart, selectedBookmark.Color)
                    : new StashBookmark("imported", yStart);

                _stash.BeginUpdate();
                _stash.AddStashTab(sb);

                var yOffsetInImported = items.Min(i => i.Y);
                var yEnd = yStart;
                foreach (var item in items)
                {
                    item.Y += yStart - yOffsetInImported;
                    yEnd    = Math.Max(yEnd, item.Y + item.Height);
                    if (item.X + item.Width > StashViewModel.Columns)
                    {
                        await _dialogCoordinator.ShowWarningAsync(this, "Skipping item because it is too wide.");

                        continue;
                    }
                    _stash.AddItem(item, true);
                }

                await _dialogCoordinator.ShowInfoAsync(this, L10n.Message("New tab added"),
                                                       string.Format(L10n.Message("New tab with {0} items was added to stash."), items.Length));
            }
            catch (Exception e)
            {
                await _dialogCoordinator.ShowErrorAsync(this,
                                                        L10n.Message("An error occurred while attempting to load stash data."), e.Message);
            }
            finally
            {
                _stash.EndUpdate();
            }
        }