コード例 #1
0
        /// <summary>
        /// Adds user page into top navigation menu.
        /// </summary>
        /// <param name="page">Page which should be added to top navigation menu.</param>
        /// <param name="vm">ViewModel for page.</param>
        /// <param name="navMenuLabelKey">Localization key for label in navigation menu.</param>
        /// <param name="navMenuIconKey">Localization key for icon in navigation menu.</param>
        private void AddUserPage(UserControl page, BaseClosableVM vm, string navMenuLabelKey = "", string navMenuIconKey = "")
        {
            page.DataContext = vm;

            ContentPageData pageData = new ContentPageData(new NavMenuItemData()
            {
                IsDropdownItem = false, IsSelected = false
            },
                                                           navMenuLabelKey,
                                                           navMenuIconKey,
                                                           PageKind.UserPages,
                                                           page,
                                                           ChangePage);

            //vm.Closed += (object sender, EventArgs e) => { DelPageFromMenu(pageData); };
            vm.Closed += delPageEventHandler;

            PagesData.Add(pageData);
            TopItemSource.Add(pageData.NavData);

            ResetSelectedItems();
            MainContent = page;
            pageData.NavData.IsSelected = true;
            TitleKey = pageData.LocalizedKey;
        }
コード例 #2
0
        public MainWindowVM()
        {
            ContentPageData buf = new ContentPageData(new NavMenuItemData()
            {
                IsDropdownItem = false, IsSelected = false
            },
                                                      "#appSettingsMenu",
                                                      "AppSettingsPageIcon",
                                                      PageKind.Settings,
                                                      new AppSettingsPage(),
                                                      ChangePage);

            PagesData.Add(buf);
            BottomItemSource.Add(buf.NavData);
            ChangePage(buf);

            buf = new ContentPageData(new NavMenuItemData()
            {
                IsDropdownItem = false, IsSelected = false
            },
                                      "#addBomberPageMenu",
                                      "AddBomberPageIcon",
                                      PageKind.Settings,
                                      (data) => { AddUserPage(new BomberPage(), new BomberPageVM(), "#NavMenuBomberPage", "BomberPageIcon"); });
            PagesData.Add(buf);
            BottomItemSource.Insert(0, buf.NavData);

            buf = new ContentPageData(new NavMenuItemData()
            {
                IsDropdownItem = false, IsSelected = false
            },
                                      "#addTransmitFilePageMenu",
                                      "AddTransmitFilePageIcon",
                                      PageKind.Settings,
                                      (data) => { AddUserPage(new TransmitFilePage(), new TransmitFilePageVM(), "#NavMenuTransmitFilePage", "TransmitFilePageIcon"); });
            PagesData.Add(buf);
            BottomItemSource.Insert(0, buf.NavData);

            buf = new ContentPageData(new NavMenuItemData()
            {
                IsDropdownItem = false, IsSelected = false
            },
                                      "#addTransmitPageMenu",
                                      "AddTransmitPageIcon",
                                      PageKind.Settings,
                                      (data) => { AddUserPage(new TransmitPage(), new TransmitPageVM(), "#NavMenuTransmitPage", "TransmitPageIcon"); });
            PagesData.Add(buf);
            BottomItemSource.Insert(0, buf.NavData);


            Settings.Instance.Proxies.CollectionChanged += OnProxiesCollectionChanged;
            Settings.Instance.PropertyChanged           += OnDevicePropertyChanged;
            PropertyChanged += TitleKey_PropertyChanged;

            Manager <LanguageCultureInfo> .StaticInstance.CultureChanged += Language_CultureChanged;
            Manager <ThemeCultureInfo> .StaticInstance.CultureChanged    += Theme_CultureChanged;

            TitleKey_PropertyChanged(this, new PropertyChangedEventArgs("TitleKey"));
        }
コード例 #3
0
 /// <summary>
 /// Метода, который нужен для удаления прокси из меню
 /// </summary>
 /// <param name="data">ContentPageData который мы проверим на то отвечает ли он за прокси и содержится ли прокси в листе</param>
 /// <param name="proxies">Лист по которому мы будет смотреть содержаться ли прокси</param>
 /// <returns></returns>
 private bool IsContentPageDataContainsProxies(ContentPageData data, IList proxies)
 {
     if (data is ContentPageDataForProxy proxyData)
     {
         return(proxies.Contains(proxyData.Proxy));
     }
     return(false);
 }
コード例 #4
0
        /// <summary>
        /// Delete page from navigation menu.
        /// </summary>
        /// <param name="page">Page which should be deleted</param>
        private void DelPageFromMenu(ContentPageData page)
        {
            MainContent = null;
            ResetSelectedItems();

            PagesData.Remove(page);
            TopItemSource.Remove(page.NavData);
            BottomItemSource.Remove(page.NavData);
            GC.Collect();
            TitleKey = "";
        }
コード例 #5
0
        /// <summary>
        /// Changing active page.
        /// </summary>
        /// <param name="data">Page which should be active.</param>
        private void ChangePage(ContentPageData data)
        {
            if (data.Page == null || data.NavData == null)
            {
                return;
            }

            MainContent = data.Page;
            ResetSelectedItems();
            data.NavData.IsSelected = true;
            TitleKey = data.LocalizedKey;
        }
コード例 #6
0
        private void NavMenuClicked_Execute(NavMenuItemData arg)
        {
            ContentPageData pageData = PagesData.FirstOrDefault(x => x.NavData == arg);

            if ((pageData == null))
            {
                return;
            }

            _context.Post((s) =>
            {
                pageData?.ClickAction?.Invoke(pageData);
            }, null);
        }
コード例 #7
0
 public ContentPageBusiness(String connString)
 {
     this.contentPageData = new ContentPageData(connString);
 }//Fin del constructor.
コード例 #8
0
        private void OnProxiesCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            {
                foreach (var el in e.NewItems)
                {
                    if (el is IChannelProxy proxy)
                    {
                        //recievePage
                        RecieveChannelPage recievePage = null;
                        _context.Send((s) =>
                        {
                            recievePage             = new RecieveChannelPage();
                            recievePage.DataContext = new RecieveChannelPageVM(proxy);
                        }, null);

                        ContentPageData recievePageData = new ContentPageData(new NavMenuItemData()
                        {
                            IsDropdownItem = false, IsSelected = false
                        },
                                                                              "#NavMenuRecieveProxyPage",
                                                                              "RecievedProxyPageIcon",
                                                                              PageKind.Proxy,
                                                                              recievePage,
                                                                              ChangePage);
                        PagesData.Add(recievePageData);


                        //monitorPage
                        MonitorChannelPage monitorPage = null;
                        _context.Send((s) =>
                        {
                            monitorPage             = new MonitorChannelPage();
                            monitorPage.DataContext = new MonitorChannelPageVM(proxy);
                        }, null);

                        ContentPageData monitorPageData = new ContentPageData(new NavMenuItemData()
                        {
                            IsDropdownItem = false, IsSelected = false
                        },
                                                                              "#NavMenuMonitorProxyPage",
                                                                              "MonitorProxyPageIcon",
                                                                              PageKind.Proxy,
                                                                              monitorPage,
                                                                              ChangePage);
                        PagesData.Add(monitorPageData);


                        ContentPageDataForProxy channelViewData = new ContentPageDataForProxy(new NavMenuItemData()
                        {
                            IsDropdownItem = true, IsSelected = false
                        },
                                                                                              "NavMenuProxyIcon",
                                                                                              proxy,
                                                                                              PageKind.Proxy);
                        channelViewData.NavData.AddDropdownItem(recievePageData.NavData);
                        channelViewData.NavData.AddDropdownItem(monitorPageData.NavData);

                        PagesData.Add(channelViewData);

                        _context.Post((s) =>
                        {
                            int insertIndex = PagesData.Where(x => x.Kind == PageKind.Channel || x.Kind == PageKind.Proxy).Max(x => TopItemSource.IndexOf(x.NavData));
                            if (insertIndex < 0)
                            {
                                insertIndex = 0;
                            }
                            else
                            {
                                insertIndex++;
                            }

                            TopItemSource.Insert(insertIndex, channelViewData.NavData);
                        }, null);
                    }
                }
            }


            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset)
            {
                ClearProxies();
            }


            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
            {
                var objectsToRemove = PagesData.Where(x => IsContentPageDataContainsProxies(x, e.OldItems)).Select(x => x.NavData);

                _context.Send((s) =>
                {
                    TopItemSource.RemoveAll(x => objectsToRemove.Contains(x));
                }, null);

                if (e.OldItems != null)
                {
                    foreach (var el in e.OldItems)
                    {
                        if (el is IChannelProxy proxy)
                        {
                            proxy.Dispose();
                        }
                    }
                }
            }
        }
コード例 #9
0
        private void OnDevicePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e != null && e.PropertyName != "Device")
            {
                return;
            }


            ClearChannels();


            if (Settings.Instance.Device == null)
            {
                return;
            }


            Settings.Instance.Device.IsConnectedChanged += (object s, EventArgs args) =>
            {
                if (s == Settings.Instance.Device)
                {
                    if (Settings.Instance.Device.IsConnected)
                    {
                        OnDevicePropertyChanged(null, null);
                    }
                    else
                    {
                        ClearChannels();
                    }
                }
            };

            if (!Settings.Instance.Device.IsConnected)
            {
                return;
            }


            //create views
            foreach (var el in Settings.Instance.Device.Channels.Reverse())
            {
                //recievePage
                var recievePage = new RecieveChannelPage();
                recievePage.DataContext = new RecieveChannelPageVM(el);

                ContentPageData recievePageData = new ContentPageData(new NavMenuItemData()
                {
                    IsDropdownItem = false, IsSelected = false
                },
                                                                      "#NavMenuRecieveChannelPage",
                                                                      "RecievedChannelPageIcon",
                                                                      PageKind.Channel,
                                                                      recievePage,
                                                                      ChangePage);
                PagesData.Add(recievePageData);


                //monitorPage
                var monitorPage = new MonitorChannelPage();
                monitorPage.DataContext = new MonitorChannelPageVM(el);

                ContentPageData monitorPageData = new ContentPageData(new NavMenuItemData()
                {
                    IsDropdownItem = false, IsSelected = false
                },
                                                                      "#NavMenuMonitorChannelPage",
                                                                      "MonitorChannelPageIcon",
                                                                      PageKind.Channel,
                                                                      monitorPage,
                                                                      ChangePage);
                PagesData.Add(monitorPageData);


                ContentPageData channelViewData = new ContentPageData(new NavMenuItemData()
                {
                    IsDropdownItem = true, IsSelected = false
                },
                                                                      "#" + el.ToString() + "NavMenu",
                                                                      el.ToString() + "Icon",
                                                                      PageKind.Channel);
                channelViewData.NavData.AddDropdownItem(recievePageData.NavData);
                channelViewData.NavData.AddDropdownItem(monitorPageData.NavData);

                PagesData.Add(channelViewData);

                _context.Post((s) =>
                {
                    int insertIndex = PagesData.Where(x => x.Kind == PageKind.Channel).Max(x => TopItemSource.IndexOf(x.NavData));
                    if (insertIndex < 0)
                    {
                        insertIndex = 0;
                    }
                    TopItemSource.Insert(insertIndex, channelViewData.NavData);
                }, null);
            }
        }