Пример #1
0
        private void HoverButton_Click(object sender, RoutedEventArgs e)
        {
            var flyoutMenu1 = new MenuFlyoutItem();

            flyoutMenu1.Text   = "Create Playlist";
            flyoutMenu1.Click += MenuAddPlaylist_Click;
            var seperator   = new MenuFlyoutSeparator();
            var flyoutMenu2 = new MenuFlyoutItem();

            flyoutMenu2.Text = "Add To >";

            var flyout = new MenuFlyout();

            flyout.Items.Add(flyoutMenu1);

            flyout.Items.Add(flyoutMenu2);

            foreach (PlayList playlist in playlists)
            {
                var flyoutmenu = new MenuFlyoutItem();
                flyoutmenu.Text   = playlist.Name;
                flyoutmenu.Click += MenuFlyoutItem_Click;
                flyout.Items.Add(flyoutmenu);
            }
            var button = (Button)sender;

            button.Flyout = flyout;
        }
Пример #2
0
        private void server_RightTapped(object sender, RightTappedRoutedEventArgs e)
        {
            MenuFlyout     myFlyout    = new MenuFlyout();
            MenuFlyoutItem connectItem = new MenuFlyoutItem {
                Text = "连接"
            };
            MenuFlyoutItem deleteItem = new MenuFlyoutItem {
                Text = "删除"
            };
            MenuFlyoutItem detialsItem = new MenuFlyoutItem {
                Text = "详情"
            };
            MenuFlyoutSeparator separator = new MenuFlyoutSeparator();
            MenuFlyoutItem      pinItem   = new MenuFlyoutItem {
                Text = "固定到开始菜单"
            };

            connectItem.Click += connectItem_Click;
            pinItem.Click     += pinItem_Click;
            deleteItem.Click  += deleteItem_Click;
            detialsItem.Click += detialsItem_Click;
            myFlyout.Items.Add(connectItem);
            myFlyout.Items.Add(deleteItem);
            myFlyout.Items.Add(detialsItem);
            myFlyout.Items.Add(separator);
            myFlyout.Items.Add(pinItem);

            //if you only want to show in left or buttom
            //myFlyout.Placement = FlyoutPlacementMode.Left;

            FrameworkElement senderElement = sender as FrameworkElement;

            //the code can show the flyout in your mouse click
            myFlyout.ShowAt(sender as UIElement, e.GetPosition(sender as UIElement));
        }
        /// <summary>
        /// Build navigation popup menu when clicking on Notebook title.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (navigationMenu != null)
            {
                return;
            }

            navigationMenu = new MenuFlyout();
            var navigationNotebooks = NotesDataSource.GetGroups();

            for (int i = 0; i < navigationNotebooks.Count; i++)
            {
                MenuFlyoutItem command = new MenuFlyoutItem();
                command.Text   = navigationNotebooks[i].Title;
                command.Name   = navigationNotebooks[i].UniqueId;
                command.Click += (s, args) => Navigate(command.Name);
                navigationMenu.Items.Add(command);
            }
            MenuFlyoutSeparator separator = new MenuFlyoutSeparator();

            navigationMenu.Items.Add(separator);

            MenuFlyoutItem cmd = new MenuFlyoutItem();

            cmd.Text   = "Home";
            cmd.Click += (s, args) => Navigate(null);
            navigationMenu.Items.Add(cmd);

            navigationMenu.ShowAt((FrameworkElement)pageTitle);
            navigationMenu = null;
        }
        async void GetPairedDevices(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("Getting list of paired devices");
            try
            {
                DeviceInformationCollection DeviceInfoCollection = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));

                var numDevices = DeviceInfoCollection.Count();

                _pairedDevices = new ObservableCollection<PairedDeviceInfo>();
                _pairedDevices.Clear();

                FlyoutBase mn = ConnectButton.Flyout;
                MenuFlyout m = (MenuFlyout)mn;
                m.Items.Clear();

                if (numDevices == 0)
                {
                    System.Diagnostics.Debug.WriteLine("No paired devices found.");
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("{0} paired devices found.", numDevices);

                    foreach (var deviceInfo in DeviceInfoCollection)
                    {
                        _pairedDevices.Add(new PairedDeviceInfo(deviceInfo));

                        ToggleMenuFlyoutItem fi = new ToggleMenuFlyoutItem();
                        fi.Text = deviceInfo.Name;

                        if (NowConnectedDevice != null && NowConnectedDevice.Id == deviceInfo.Id )
                        {
                            fi.IsChecked = true;
                        }
                        else
                        {
                            fi.IsChecked = false;
                        }
                        fi.Click += new RoutedEventHandler((ss, ev) => MenuFlyoutItemDevice_Click(ss, ev, deviceInfo, fi));
                        m.Items.Add(fi);
                    }
                }
                MenuFlyoutSeparator fs = new MenuFlyoutSeparator();
                m.Items.Add(fs);
                MenuFlyoutItem f = new MenuFlyoutItem();
                f.Text = "Refresh";
                f.Click += new RoutedEventHandler(GetPairedDevices);
                m.Items.Add(f);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("GetPairedDevices: " + ex.Message);
            }
        }
Пример #5
0
        public static MenuFlyoutSeparator CreateFlyoutSeparator(this MenuFlyoutSubItem flyout)
        {
            if (flyout.Items.Count > 0 && (flyout.Items[flyout.Items.Count - 1] is MenuFlyoutItem or MenuFlyoutSubItem))
            {
                var separator = new MenuFlyoutSeparator();
                flyout.Items.Add(separator);
                return(separator);
            }

            return(null);
        }
Пример #6
0
        private void ResetItems()
        {
            if (AssociatedObject == null)
            {
                return;
            }

            var menuFlyout        = AssociatedObject;
            var itemsSrouce       = ItemsSource.Cast <object>().ToList();
            var customObjectToTag = CustomObjectToTag;


            // 前回追加分のメニューアイテムを削除
            foreach (var oldItem in _addedMenuFlyoutItems)
            {
                menuFlyout.Items.Remove(oldItem);
            }

            _addedMenuFlyoutItems.Clear();


            // これから配置するアイテムとの間にセパレータが必要な場合
            if (IsRequireInsertSeparaterBetweenDefaultItems)
            {
                if (itemsSrouce.Count >= 1 && menuFlyout.Items.Count >= 1)
                {
                    var separator = new MenuFlyoutSeparator();
                    menuFlyout.Items.Add(separator);
                    _addedMenuFlyoutItems.Add(separator);
                }
            }

            // ItemTemplateからMenuFlyoutItem系のインスタンスを生成してMenuFlyoutSubItemに追加する
            foreach (var item in itemsSrouce)
            {
                var templatedContent = ItemTemplate.LoadContent();
                if (templatedContent is MenuFlyoutItemBase flyoutItem)
                {
                    flyoutItem.DataContext = item;
                    flyoutItem.Tag         = customObjectToTag ?? flyoutItem.Tag;

                    menuFlyout.Items.Add(flyoutItem);
                    _addedMenuFlyoutItems.Add(flyoutItem);
                }
#if DEBUG
                else
                {
                    throw new Models.Infrastructure.HohoemaExpception($"{nameof(MenuFlyoutItemsSetter)}.{nameof(ItemTemplate)} is must be MenuFlyoutItemBase inherit class.");
                }
#endif
            }
        }
Пример #7
0
        private async void Button_RightTapped(object sender, RoutedEventArgs e)
        {
            PFeedItem           item      = (PFeedItem)((Button)sender).DataContext;
            MenuFlyout          menu      = FlyoutBase.GetAttachedFlyout((Button)sender) as MenuFlyout;
            MenuFlyoutItem      favbutton = menu.Items[4] as MenuFlyoutItem;
            MenuFlyoutSeparator favsep    = menu.Items[3] as MenuFlyoutSeparator;

            StorageFile cache = await ApplicationData.Current.LocalFolder.GetFileAsync("saved_cache");

            string favcache = await FileIO.ReadTextAsync(cache);

            if (favcache.Contains(item.link))
            {
                favbutton.Visibility = Visibility.Collapsed;
                favsep.Visibility    = Visibility.Collapsed;
            }

            FlyoutBase.ShowAttachedFlyout(sender as FrameworkElement);
        }
Пример #8
0
        /// <summary>
        /// Show MenuFlyout for new Notes/Notebook
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void AppBarButtonAddItemsClick(object sender, RoutedEventArgs e)
        {
            MenuFlyout menu = new MenuFlyout();

            MenuFlyoutItem item = new MenuFlyoutItem()
            {
                Text = "Food"
            };

            item.Click += ((s, args) => { CreateNew(new FoodDataItem()); });
            menu.Items.Add(item);

            item = new MenuFlyoutItem()
            {
                Text = "To Do"
            };
            item.Click += ((s, args) => { CreateNew(new ToDoDataItem()); });
            menu.Items.Add(item);

            item = new MenuFlyoutItem()
            {
                Text = "Note"
            };
            item.Click += ((s, args) => { CreateNew(new NoteDataItem()); });
            menu.Items.Add(item);

            MenuFlyoutSeparator separator = new MenuFlyoutSeparator();

            menu.Items.Add(separator);

            item = new MenuFlyoutItem()
            {
                Text = "Notebook"
            };
            item.Click += ((s, args) => { CreateNewNotebook(s); });
            menu.Items.Add(item);

            menu.ShowAt((FrameworkElement)sender);
        }
Пример #9
0
        private void UpdateMenuItems()
        {
            ManageConnection.Items.Clear();
            var newItem = new MenuFlyoutItem();

            newItem.Text   = "New Connection";
            newItem.Click += OnClick_NewConnection;
            ManageConnection.Items.Add(newItem);

            var seperator = new MenuFlyoutSeparator();

            ManageConnection.Items.Add(seperator);

            foreach (var item in recentConnectionStrings)
            {
                newItem = new MenuFlyoutItem
                {
                    Text = item.nickname,
                    Name = item.connectionString
                };
                newItem.Click += OnCLick_RecentConnection;
                ManageConnection.Items.Add(newItem);
            }
        }
Пример #10
0
        public static MenuFlyout MakeGuildMenu(LocalModels.Guild guild)
        {
            MenuFlyout menu = new MenuFlyout();

            menu.MenuFlyoutPresenterStyle = (Style)App.Current.Resources["MenuFlyoutPresenterStyle1"];

            // Add "Edit Server" button
            MenuFlyoutItem editServer = new MenuFlyoutItem()
            {
                Text = App.GetString("/Flyouts/EditServer"),
                Tag  = guild.Raw.Id,
                Icon = new SymbolIcon(Symbol.Edit),
            };

            editServer.Click += FlyoutManager.EditServer;
            menu.Items.Add(editServer);


            // Add Seperator
            MenuFlyoutSeparator sep1 = new MenuFlyoutSeparator();

            menu.Items.Add(sep1);

            // Create "Mute/Unmute" button
            MenuFlyoutItem mute = new MenuFlyoutItem()
            {
                Icon = new SymbolIcon(Symbol.Mute),
                Tag  = guild.Raw.Id,
            };

            mute.Click += FlyoutManager.MuteServer;

            // If muted, unmute
            if (LocalState.GuildSettings.ContainsKey(guild.Raw.Id) && LocalState.GuildSettings[guild.Raw.Id].raw.Muted)
            {
                mute.Text = App.GetString("/Flyouts/UnmuteServer");
            }

            // If not muted, mute
            else
            {
                mute.Text = App.GetString("/Flyouts/MuteServer");
            }

            // Add "Mute/Unmute" button
            menu.Items.Add(mute);

            // Add "Mark as Read" button
            MenuFlyoutItem markasread = new MenuFlyoutItem()
            {
                Text = App.GetString("/Flyouts/MarkAsRead"),
                Tag  = guild.Raw.Id,
                Icon = new SymbolIcon(Symbol.View),
                //IsEnabled = (ServerList.Items.FirstOrDefault(x => (x as SimpleGuild).Id == guild.RawGuild.Id) as SimpleGuild).IsUnread //TODO: Disable Make as read if not unread
            };

            markasread.Click += FlyoutManager.MarkGuildasRead;
            menu.Items.Add(markasread);

            // If current user is owner
            if (guild.Raw.OwnerId == LocalState.CurrentUser.Id)
            {
                // Add "Delete Server" button
                MenuFlyoutItem deleteServer = new MenuFlyoutItem()
                {
                    Text       = App.GetString("/Flyouts/DeleteServer"),
                    Tag        = guild.Raw.Id,
                    Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)),
                    Icon       = new SymbolIcon(Symbol.Delete),
                };
                deleteServer.Click += FlyoutManager.DeleteServer;
                menu.Items.Add(deleteServer);
            }
            else
            {
                // Add "Leave Server" button
                MenuFlyoutItem leaveServer = new MenuFlyoutItem()
                {
                    Text       = App.GetString("/Flyouts/LeaveServer"),
                    Tag        = guild.Raw.Id,
                    Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)),
                    Icon       = new SymbolIcon(Symbol.Remove),
                };
                leaveServer.Click += FlyoutManager.LeaveServer;
                menu.Items.Add(leaveServer);
            }

            return(menu);
        }
Пример #11
0
        public static MenuFlyout MakeVoiceMemberMenu(GuildMember member)
        {
            MenuFlyout menu = new MenuFlyout();

            menu.MenuFlyoutPresenterStyle = (Style)App.Current.Resources["MenuFlyoutPresenterStyle1"];

            // Add "Profile" button
            MenuFlyoutItem profile = new MenuFlyoutItem()
            {
                Text = App.GetString("/Flyouts/Profile"),
                Tag  = member.User,
                Icon = new SymbolIcon(Symbol.ContactInfo)
            };

            profile.Click += FlyoutManager.OpenProfile;
            menu.Items.Add(profile);

            // If member is not current user
            if (member.User.Id != LocalState.CurrentUser.Id)
            {
                // Add "Message" button
                MenuFlyoutItem message = new MenuFlyoutItem()
                {
                    Text = App.GetString("/Flyouts/Message"),
                    Tag  = member.User.Id,
                    Icon = new SymbolIcon(Symbol.Message)
                };
                message.Click += FlyoutManager.MessageUser;
                menu.Items.Add(message);
            }


            // Add Separator
            MenuFlyoutSeparator sep1 = new MenuFlyoutSeparator();

            menu.Items.Add(sep1);


            // If not current user
            if (member.User.Id != LocalState.CurrentUser.Id)
            {
                // Create "Invite to Server" sub item
                MenuFlyoutSubItem InviteToServer = new MenuFlyoutSubItem()
                {
                    Text = App.GetString("/Flyouts/InviteToServer")
                           //Tag = member.Raw.User.Id,
                           //Icon = new SymbolIcon(Symbol.)
                };

                // Check all Guilds
                foreach (KeyValuePair <string, LocalModels.Guild> guild in LocalState.Guilds)
                {
                    // If can Create Instant Invite
                    if (guild.Value.permissions.Administrator || guild.Value.permissions.CreateInstantInvite)
                    {
                        // Add Guild to list
                        MenuFlyoutItem item = new MenuFlyoutItem()
                        {
                            Text = guild.Value.Raw.Name, Tag = new Tuple <string, string>(guild.Value.channels.FirstOrDefault().Value.raw.Id, member.User.Id)
                        };
                        item.Click += FlyoutManager.InviteToServer;
                        InviteToServer.Items.Add(item);
                    }
                }

                // Add "Invite to Server" to menu
                menu.Items.Add(InviteToServer);
            }

            // Create "Add Friend" button
            MenuFlyoutItem addFriend = new MenuFlyoutItem()
            {
                Text = App.GetString("/Flyouts/AddFriend"),
                Tag  = member.User.Id,
                Icon = new SymbolIcon(Symbol.AddFriend)
            };

            addFriend.Click += FlyoutManager.AddFriend;

            // Create "Remove Friend" button
            MenuFlyoutItem removeFriend = new MenuFlyoutItem()
            {
                Text       = App.GetString("/Flyouts/RemoveFriend"),
                Tag        = member.User.Id,
                Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)),
                Icon       = new SymbolIcon(Symbol.ContactPresence)
            };

            removeFriend.Click += FlyoutManager.RemoveFriend;

            // Create "Block" button
            MenuFlyoutItem block = new MenuFlyoutItem()
            {
                Text       = App.GetString("/Flyouts/Block"),
                Tag        = member.User.Id,
                Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)),
                Icon       = new SymbolIcon(Symbol.BlockContact)
            };

            block.Click += FlyoutManager.BlockUser;

            // Create "Unblock" button
            MenuFlyoutItem unBlock = new MenuFlyoutItem()
            {
                Text = App.GetString("/Flyouts/Unblock"),
                Tag  = member.User.Id,
                Icon = new SymbolIcon(Symbol.ContactPresence)
            };

            unBlock.Click += FlyoutManager.RemoveFriend;

            // Create "Accept Friend Request" button
            MenuFlyoutItem acceptFriendRequest = new MenuFlyoutItem()
            {
                Text = App.GetString("/Flyouts/AcceptFriendRequest"),
                Tag  = member.User.Id,
                Icon = new SymbolIcon(Symbol.AddFriend)
            };

            acceptFriendRequest.Click += FlyoutManager.AddFriend;

            // Choose which buttons to show
            if (LocalState.Friends.ContainsKey(member.User.Id))
            {
                switch (LocalState.Friends[member.User.Id].Type)
                {
                // No relation
                case 0:
                    // Add "Add Friend" and "Block" buttons
                    menu.Items.Add(addFriend);
                    menu.Items.Add(block);
                    break;

                // Friend
                case 1:
                    // Add "Remove Friend" and "Block" buttons
                    menu.Items.Add(removeFriend);
                    menu.Items.Add(block);
                    break;

                // Blocked
                case 2:
                    // Add "Block" button
                    menu.Items.Add(unBlock);
                    break;

                // Incoming Friend Request
                case 3:
                    // Add "Accept Friend Request" button
                    menu.Items.Add(acceptFriendRequest);
                    menu.Items.Add(block);
                    break;

                // Outgoing Friend Request
                case 4:
                    // Add "Block" button
                    menu.Items.Add(block);
                    break;
                }
            }
            // Member is current user
            else if (member.User.Id == LocalState.CurrentUser.Id)
            {
                // No buttons for current user
            }
            else
            {
                // Default to no relation
                menu.Items.Add(addFriend);
                menu.Items.Add(block);
            }


            // If member is not current user
            if (member.User.Id != LocalState.CurrentUser.Id)
            {
                MenuFlyoutSeparator sep2 = new MenuFlyoutSeparator();
                menu.Items.Add(sep2);
            }

            // If can change user's nickname
            if (Permissions.CanChangeNickname(member.User.Id, App.CurrentGuildId))
            {
                // Add "Change Nickname" button
                MenuFlyoutItem changeNickname = new MenuFlyoutItem()
                {
                    Text = App.GetString("/Flyouts/ChangeNickname"),
                    Tag  = member.User.Id,
                    Icon = new SymbolIcon(Symbol.Rename)
                };
                changeNickname.Click += FlyoutManager.ChangeNickname;
                menu.Items.Add(changeNickname);
            }

            // If Current User has manage roles permission
            if (LocalState.Guilds[App.CurrentGuildId].permissions.Administrator || LocalState.Guilds[App.CurrentGuildId].permissions.ManageRoles)
            {
                // Create "Roles" subitem
                MenuFlyoutSubItem roles = new MenuFlyoutSubItem()
                {
                    Text = App.GetString("/Flyouts/Roles")
                           //Tag = member.Raw.User.Id,
                           //Icon = new SymbolIcon(Symbol.)
                };

                // Add Server's roles to Role SubItem
                foreach (DiscordAPI.SharedModels.Role role in LocalState.Guilds[App.CurrentGuildId].roles.Values.OrderByDescending(x => x.Position))
                {
                    ToggleMenuFlyoutItem roleItem = new ToggleMenuFlyoutItem()
                    {
                        Text       = role.Name,
                        Tag        = new Tuple <string, string>(role.Id, member.User.Id),
                        Foreground = Common.IntToColor(role.Color),
                        IsChecked  = member.Roles != null && member.Roles.Contains(role.Id),
                        //Style = (Style)App.Current.Resources["ToggleOnlyCheckbox"],
                        IsEnabled = LocalState.Guilds[App.CurrentGuildId].members[LocalState.CurrentUser.Id].Roles.FirstOrDefault() != null && role.Position < LocalState.Guilds[App.CurrentGuildId].roles[LocalState.Guilds[App.CurrentGuildId].members[LocalState.CurrentUser.Id].Roles.FirstOrDefault()].Position || LocalState.Guilds[App.CurrentGuildId].Raw.OwnerId == LocalState.CurrentUser.Id  //TODO: Double check role system
                    };
                    roleItem.Click += FlyoutManager.AddRole;
                    if (role.Name != "@everyone")
                    {
                        roles.Items.Add(roleItem);
                    }
                }

                // Add Roles subitem to menu
                menu.Items.Add(roles);
            }

            // If Current User has kick members permission
            if ((LocalState.Guilds[App.CurrentGuildId].permissions.Administrator || LocalState.Guilds[App.CurrentGuildId].permissions.KickMembers) && LocalState.Guilds[App.CurrentGuildId].GetHighestRole(member.Roles).Position < LocalState.Guilds[App.CurrentGuildId].GetHighestRole(LocalState.Guilds[App.CurrentGuildId].members[LocalState.CurrentUser.Id].Roles).Position || LocalState.Guilds[App.CurrentGuildId].Raw.OwnerId == LocalState.CurrentUser.Id && member.User.Id != LocalState.CurrentUser.Id)
            {
                // Add "Kick Member" button
                MenuFlyoutItem kickMember = new MenuFlyoutItem()
                {
                    Text       = App.GetString("/Flyouts/KickMember"),
                    Tag        = member.User.Id,
                    Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)),
                    Icon       = new SymbolIcon(Symbol.BlockContact)
                };
                kickMember.Click += FlyoutManager.KickMember;
                menu.Items.Add(kickMember);
            }
            // If Member is current user and current user is not owner
            else if (member.User.Id == LocalState.CurrentUser.Id && LocalState.Guilds[App.CurrentGuildId].Raw.OwnerId != LocalState.CurrentUser.Id)
            {
                // Add "Leave Server" button
                MenuFlyoutItem leaveServer = new MenuFlyoutItem()
                {
                    Text       = App.GetString("/Flyouts/LeaveServer"),
                    Tag        = member.User.Id,
                    Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)),
                    Icon       = new SymbolIcon(Symbol.Remove)
                };
                leaveServer.Click += FlyoutManager.LeaveServer;
                menu.Items.Add(leaveServer);
            }

            // If User has ban members permission
            if (((LocalState.Guilds[App.CurrentGuildId].permissions.Administrator || LocalState.Guilds[App.CurrentGuildId].permissions.BanMembers) && LocalState.Guilds[App.CurrentGuildId].GetHighestRole(member.Roles).Position < LocalState.Guilds[App.CurrentGuildId].GetHighestRole(LocalState.Guilds[App.CurrentGuildId].members[LocalState.CurrentUser.Id].Roles).Position) || LocalState.Guilds[App.CurrentGuildId].Raw.OwnerId == LocalState.CurrentUser.Id && member.User.Id != LocalState.CurrentUser.Id)
            {
                // Add "Ban Member" button
                MenuFlyoutItem banMember = new MenuFlyoutItem()
                {
                    Text       = App.GetString("/Flyouts/BanMember"),
                    Tag        = member.User.Id,
                    Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)),
                    Icon       = new SymbolIcon(Symbol.BlockContact)
                };
                banMember.Click += FlyoutManager.BanMember;
                menu.Items.Add(banMember);
            }

            // If member is a bot
            if (member.User.Bot)
            {
                // Add Separator
                menu.Items.Add(new MenuFlyoutSeparator());

                // Add extra bot specific stuff
                foreach (var feature in BotExtrasManager.GetBotFeatures(member.User.Id))
                {
                    MenuFlyoutItem link = new MenuFlyoutItem()
                    {
                        Text = feature.Name,
                        Tag  = feature.Url,
                        Icon = new FontIcon()
                        {
                            Glyph = feature.Icon
                        }
                    };
                    link.Click += FlyoutManager.OpenURL;
                    menu.Items.Add(link);
                }
            }

            return(menu);
        }
Пример #12
0
        public static MenuFlyout MakeGroupChannelMenu(DirectMessageChannel dm)
        {
            MenuFlyout menu = new MenuFlyout();

            menu.MenuFlyoutPresenterStyle = (Style)App.Current.Resources["MenuFlyoutPresenterStyle1"];

            // Add users
            int x = 0;

            foreach (User user in LocalState.DMs[dm.Id].Users)
            {
                // Create SubItem for user
                MenuFlyoutSubItem item = new MenuFlyoutSubItem()
                {
                    Text = user.Username
                };

                // Add "Profile" button to subitem
                MenuFlyoutItem profile = new MenuFlyoutItem()
                {
                    Text = App.GetString("/Flyouts/Profile"),
                    Icon = new SymbolIcon(Symbol.ContactInfo),
                    Tag  = user
                };
                profile.Click += FlyoutManager.OpenProfile;
                item.Items.Add(profile);


                // Add Seperator
                MenuFlyoutSeparator sep1 = new MenuFlyoutSeparator();
                item.Items.Add(sep1);

                // If current user owns the dm
                if (dm.OwnerId == LocalState.CurrentUser.Id)
                {
                    // Add "Remove from DM" button
                    MenuFlyoutItem removeFromDm = new MenuFlyoutItem()
                    {
                        Text       = App.GetString("/Flyouts/RemoveFromGroup"),
                        Icon       = new SymbolIcon(Symbol.LeaveChat),
                        Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)),
                        Tag        = new Tuple <string, string>(dm.Id, user.Id)
                    };
                    removeFromDm.Click += FlyoutManager.RemoveGroupUser;
                    item.Items.Add(removeFromDm);

                    // Add Seperator
                    MenuFlyoutSeparator sep2 = new MenuFlyoutSeparator();
                    item.Items.Add(sep2);
                }

                // Create "Add Friend" button
                MenuFlyoutItem addFriend = new MenuFlyoutItem()
                {
                    Text = App.GetString("/Flyouts/AddFriend"),
                    Icon = new SymbolIcon(Symbol.AddFriend),
                    Tag  = dm.Users.ToList()[x].Id
                };
                addFriend.Click += FlyoutManager.AddFriend;

                // Create "Accept Friend Request" button
                MenuFlyoutItem acceptFriendRequest = new MenuFlyoutItem()
                {
                    Text = App.GetString("/Flyouts/AcceptFriendRequest"),
                    Icon = new SymbolIcon(Symbol.AddFriend),
                    Tag  = dm.Users.ToList()[x].Id
                };
                acceptFriendRequest.Click += FlyoutManager.AddFriend;

                // Create "Remove Friend" button
                MenuFlyoutItem removeFriend = new MenuFlyoutItem()
                {
                    Text       = App.GetString("/Flyouts/RemoveFriend"),
                    Icon       = new SymbolIcon(Symbol.ContactPresence),
                    Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)),
                    Tag        = dm.Users.ToList()[x].Id
                };
                removeFriend.Click += FlyoutManager.RemoveFriend;

                // Create "Block" button
                MenuFlyoutItem block = new MenuFlyoutItem()
                {
                    Text       = App.GetString("/Flyouts/Block"),
                    Icon       = new SymbolIcon(Symbol.BlockContact),
                    Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)),
                    Tag        = dm.Users.ToList()[x].Id
                };
                block.Click += FlyoutManager.BlockUser;

                // Create "Unblock" button
                MenuFlyoutItem unBlock = new MenuFlyoutItem()
                {
                    Text = App.GetString("/Flyouts/Unblock"),
                    Icon = new SymbolIcon(Symbol.ContactPresence),
                    Tag  = dm.Users.ToList()[x].Id
                };
                unBlock.Click += FlyoutManager.RemoveFriend;

                // Choose buttons to add
                if (LocalState.Friends.ContainsKey(dm.Users.FirstOrDefault().Id))
                {
                    switch (LocalState.Friends[dm.Users.FirstOrDefault().Id].Type)
                    {
                    // No relation
                    case 0:
                        // Add "Add Friend" and "Block" buttons
                        item.Items.Add(addFriend);
                        item.Items.Add(block);
                        break;

                    // Friends
                    case 1:
                        // Add "Remove Friend" and "Block" buttons
                        item.Items.Add(removeFriend);
                        item.Items.Add(block);
                        break;

                    // Blocked
                    case 2:
                        // Add "Unblock" button
                        item.Items.Add(unBlock);
                        break;

                    // Incoming Friend Request
                    case 3:
                        // Add "Accept Friend Request" and "Block" buttons
                        item.Items.Add(acceptFriendRequest);
                        item.Items.Add(block);
                        break;

                    // Outgoing Friend Request
                    case 4:
                        // Add "Block" button
                        menu.Items.Add(block);
                        break;
                    }
                }
                else
                {
                    // Default to no relation
                    item.Items.Add(addFriend);
                    item.Items.Add(block);
                }

                // Add subitems
                menu.Items.Add(item);
                x++;
            }


            // Add seperator
            MenuFlyoutSeparator sep3 = new MenuFlyoutSeparator();

            menu.Items.Add(sep3);

            // Add "Leave DM" button
            MenuFlyoutItem leaveDm = new MenuFlyoutItem()
            {
                Text       = App.GetString("/Flyouts/LeaveGroup"),
                Icon       = new SymbolIcon(Symbol.LeaveChat),
                Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)),
                Tag        = new Tuple <string, string>(dm.Id, LocalState.CurrentUser.Id)
            };

            if (dm.OwnerId == LocalState.CurrentUser.Id)
            {
                leaveDm.Click += FlyoutManager.RemoveGroupUser;
            }
            else
            {
                leaveDm.Click += FlyoutManager.LeaveUnownedChannel;
            }
            menu.Items.Add(leaveDm);

            return(menu);
        }
Пример #13
0
        public static MenuFlyout MakeTextChnMenu(LocalModels.GuildChannel chn)
        {
            MenuFlyout menu = new MenuFlyout();

            menu.MenuFlyoutPresenterStyle = (Style)App.Current.Resources["MenuFlyoutPresenterStyle1"];

            // Add "Edit Channel" button
            MenuFlyoutItem editchannel = new MenuFlyoutItem()
            {
                Text   = App.GetString("/Flyouts/EditChannel"),
                Tag    = chn.raw.Id,
                Icon   = new SymbolIcon(Symbol.Edit),
                Margin = new Thickness(-26, 0, 0, 0)
            };

            editchannel.Click += FlyoutManager.EditChannel;
            menu.Items.Add(editchannel);


            // Add Separator
            MenuFlyoutSeparator sep1 = new MenuFlyoutSeparator();

            menu.Items.Add(sep1);


            // Create "Mute/Unmute" button
            ToggleMenuFlyoutItem mute = new ToggleMenuFlyoutItem()
            {
                Icon   = new SymbolIcon(Symbol.Mute),
                Tag    = chn.raw.Id,
                Margin = new Thickness(-26, 0, 0, 0)
            };

            mute.Click += FlyoutManager.MuteChannel;
            //mute.IsChecked = LocalState.GuildSettings.Contains(chn.Raw.Id);

            // If muted, unmute
            if (LocalState.GuildSettings.ContainsKey(App.CurrentGuildId) && LocalState.GuildSettings[App.CurrentGuildId].channelOverrides.ContainsKey(chn.raw.Id) && LocalState.GuildSettings[App.CurrentGuildId].channelOverrides[chn.raw.Id].Muted)
            {
                mute.Text = App.GetString("/Flyouts/UnmuteChannel");
            }

            // If not muted, mute
            else
            {
                mute.Text = App.GetString("/Flyouts/MuteChannel");
            }

            // Add "Mute/Unmute" button
            menu.Items.Add(mute);

            // Add "Mark as Read" button
            MenuFlyoutItem markasread = new MenuFlyoutItem()
            {
                Text   = App.GetString("/Flyouts/MarkAsRead"),
                Tag    = chn.raw.Id,
                Icon   = new SymbolIcon(Symbol.View),
                Margin = new Thickness(-26, 0, 0, 0),
                //IsEnabled = false
                //IsEnabled = (TextChannels.Items.FirstOrDefault(x => (x as SimpleChannel).Id == chn.Raw.Id) as SimpleChannel).IsUnread
            };

            markasread.Click += FlyoutManager.MarkChannelasRead;
            menu.Items.Add(markasread);


            // Add Separator
            MenuFlyoutSeparator sep2 = new MenuFlyoutSeparator();

            menu.Items.Add(sep2);


            // Create "Delete Channel" button
            MenuFlyoutItem deleteChannel = new MenuFlyoutItem()
            {
                Text       = App.GetString("/Flyouts/DeleteChannel"),
                Tag        = chn.raw.Id,
                Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)),
                Icon       = new SymbolIcon(Symbol.Delete),
                Margin     = new Thickness(-26, 0, 0, 0),
            };

            deleteChannel.Click += FlyoutManager.DeleteChannel;

            // If permissions to delete channel
            if (chn.permissions.ManageChannels || chn.permissions.Administrator || LocalState.Guilds[chn.raw.GuildId].Raw.OwnerId == LocalState.CurrentUser.Id)
            {
                // Add "Delete Channel" button
                menu.Items.Add(deleteChannel);
            }


            return(menu);
        }
Пример #14
0
        /// <summary>
        /// Make Flyout for DMChannel
        /// </summary>
        /// <param name="dm">DM Channel</param>
        /// <returns>A MenuFlyout for the DM</returns>
        public static MenuFlyout MakeDMChannelMenu(DirectMessageChannel dm)
        {
            MenuFlyout menu = new MenuFlyout();

            menu.MenuFlyoutPresenterStyle = (Style)App.Current.Resources["MenuFlyoutPresenterStyle1"];

            // Add "Profile" button
            MenuFlyoutItem profile = new MenuFlyoutItem()
            {
                Text = App.GetString("/Flyouts/Profile"),
                Icon = new SymbolIcon(Symbol.ContactInfo),
                Tag  = dm.Users.FirstOrDefault()
            };

            profile.Click += FlyoutManager.OpenProfile;
            menu.Items.Add(profile);


            // Add seperator
            MenuFlyoutSeparator sep1 = new MenuFlyoutSeparator();

            menu.Items.Add(sep1);


            // Create "Remove Friend" button
            MenuFlyoutItem removeFriend = new MenuFlyoutItem()
            {
                Text       = App.GetString("/Flyouts/RemoveFriend"),
                Icon       = new SymbolIcon(Symbol.ContactPresence),
                Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)),
                Tag        = dm.Users.FirstOrDefault().Id
            };

            removeFriend.Click += FlyoutManager.RemoveFriend;

            // Create "Add Friend" button
            MenuFlyoutItem addFriend = new MenuFlyoutItem()
            {
                Text = App.GetString("/Flyouts/AddFriend"),
                Icon = new SymbolIcon(Symbol.AddFriend),
                Tag  = dm.Users.FirstOrDefault().Id
            };

            addFriend.Click += FlyoutManager.AddFriend;

            // Create "Accept Friend Request" button
            MenuFlyoutItem acceptFriendRequest = new MenuFlyoutItem()
            {
                Text = App.GetString("/Flyouts/AcceptFriendRequest"),
                Icon = new SymbolIcon(Symbol.AddFriend),
                Tag  = dm.Users.FirstOrDefault().Id
            };

            acceptFriendRequest.Click += FlyoutManager.AddFriend;

            // Create "Block" button
            MenuFlyoutItem block = new MenuFlyoutItem()
            {
                Text       = App.GetString("/Flyouts/Block"),
                Icon       = new SymbolIcon(Symbol.BlockContact),
                Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)),
                Tag        = dm.Users.FirstOrDefault().Id
            };

            block.Click += FlyoutManager.BlockUser;

            // Create "Unblock" button
            MenuFlyoutItem unBlock = new MenuFlyoutItem()
            {
                Text = App.GetString("/Flyouts/Unblock"),
                Tag  = dm.Users.FirstOrDefault().Id,
                Icon = new SymbolIcon(Symbol.ContactPresence)
            };

            unBlock.Click += FlyoutManager.RemoveFriend;

            // Choose buttons to add
            if (LocalState.Friends.ContainsKey(dm.Users.FirstOrDefault().Id))
            {
                switch (LocalState.Friends[dm.Users.FirstOrDefault().Id].Type)
                {
                // No relation
                case 0:
                    // Add "Add Friend" and "Block" buttons
                    menu.Items.Add(addFriend);
                    menu.Items.Add(block);
                    break;

                // Friend
                case 1:
                    // Add "Remove Friend" and "Block" buttons
                    menu.Items.Add(removeFriend);
                    menu.Items.Add(block);
                    break;

                // Blocked
                case 2:
                    // Add "Unblock" button
                    menu.Items.Add(unBlock);
                    break;

                // Incoming Friend Request
                case 3:
                    // Add "Accept Friend Request" and "Block" buttons
                    menu.Items.Add(acceptFriendRequest);
                    menu.Items.Add(block);
                    break;

                // Outgoing Friend Request
                case 4:
                    // Add "Block" button
                    menu.Items.Add(block);
                    break;
                }
            }
            else
            {
                // Default to no relation
                menu.Items.Add(addFriend);
                menu.Items.Add(block);
            }


            // Add Seperator
            MenuFlyoutSeparator sep2 = new MenuFlyoutSeparator();

            menu.Items.Add(sep2);

            // Add "Close DM" button
            MenuFlyoutItem CloseDM = new MenuFlyoutItem()
            {
                Text       = App.GetString("/Flyouts/CloseDM"),
                Icon       = new SymbolIcon(Symbol.LeaveChat),
                Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)),
                Tag        = dm.Id,
            };

            CloseDM.Click += FlyoutManager.DeleteChannel;
            menu.Items.Add(CloseDM);

            return(menu);
        }
Пример #15
0
        public static MenuFlyout MakeMessageMenu(Message message)
        {
            MenuFlyout menu = new MenuFlyout();

            menu.MenuFlyoutPresenterStyle = (Style)App.Current.Resources["MenuFlyoutPresenterStyle1"];

            // Create "Reply" button
            MenuFlyoutItem reply = new MenuFlyoutItem()
            {
                Text = App.GetString("/Controls/ReplyItem"),
                Tag  = message,
                Icon = new SymbolIcon(Symbol.MailReply)
            };
            //reply.Click += FlyoutManager.;

            // Create "Pin" button
            MenuFlyoutItem pin = new MenuFlyoutItem()
            {
                Text = message.Pinned ? App.GetString("/Controls/Unpin") : App.GetString("/Controls/Pin"),
                Tag  = message.Id,
                Icon = new SymbolIcon(Symbol.Pin)
            };
            //pin.Click += FlyoutManager.;

            // Create "Add Reaction" button
            MenuFlyoutItem addReaction = new MenuFlyoutItem()
            {
                Text = App.GetString("/Controls/AddReacItem"),
                Tag  = message.Id,
                Icon = new SymbolIcon(Symbol.Emoji)
            };
            //addReaction.Click += FlyoutManager.;

            // Create "Edit" button
            MenuFlyoutItem edit = new MenuFlyoutItem()
            {
                Text = App.GetString("/Controls/EditItem"),
                Tag  = message,
                Icon = new SymbolIcon(Symbol.Edit)
            };
            //edit.Click += FlyoutManager.;

            // Create "Delete" button
            MenuFlyoutItem delete = new MenuFlyoutItem()
            {
                Text       = App.GetString("/Controls/DeleteItem"),
                Tag        = message.User.Id,
                Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)),
                Icon       = new SymbolIcon(Symbol.Delete)
            };

            //delete.Click += FlyoutManager.;

            // If current user
            if (LocalState.CurrentUser.Id == message.User.Id)
            {
                // Add "Edit" button
                menu.Items.Add(edit);
            }

            // Null check Guild (for DMs)
            if (App.CurrentGuildId != null)
            {
                // If permissions to delete message
                if (LocalState.Guilds[App.CurrentGuildId].channels[message.ChannelId].permissions.ManageMessages || LocalState.Guilds[App.CurrentGuildId].channels[message.ChannelId].permissions.Administrator || message?.User.Id == LocalState.CurrentUser.Id || LocalState.Guilds[App.CurrentGuildId].Raw.OwnerId == LocalState.CurrentUser.Id)
                {
                    // Add "Delete" button
                    menu.Items.Add(delete);
                }
            }

            // If dev mode
            if (Storage.Settings.DevMode)
            {
                // Add Separator
                MenuFlyoutSeparator sep1 = new MenuFlyoutSeparator();
                menu.Items.Add(sep1);

                // Add "CopyId" button
                MenuFlyoutItem copyId = new MenuFlyoutItem()
                {
                    Text = App.GetString("/Controls/CopyIdItem"),
                    Tag  = message.User.Id,
                    //Foreground = new SolidColorBrush(Color.FromArgb(255, 240, 71, 71)),
                    Icon = new SymbolIcon(Symbol.Copy)
                };
                //copyId.Click += FlyoutManager.;
            }


            return(menu);
        }
Пример #16
0
            public RichEditBoxContextFlyout()
            {
                ResourceLoader loader = ResourceLoader.GetForCurrentView();

                Opened += RichEditBoxContextFlyout_Opened;
                Closed += RichEditBoxContextFlyout_Closed;

                CutButton = new MenuFlyoutItem()
                {
                    Text = loader.GetString("CutButton/Text")
                };
                CutButton.Click += CutButton_Click;
                Items.Add(CutButton);

                CopyButton = new MenuFlyoutItem()
                {
                    Text = loader.GetString("CopyButton/Text")
                };
                CopyButton.Click += CopyButton_Click;
                Items.Add(CopyButton);

                PasteButton = new MenuFlyoutItem()
                {
                    Text = loader.GetString("PasteButton/Text")
                };
                PasteButton.Click += PasteButton_Click;
                Items.Add(PasteButton);

                CutCopyPasteSeparator = new MenuFlyoutSeparator();
                Items.Add(CutCopyPasteSeparator);

                SelectAllButton = new MenuFlyoutItem()
                {
                    Text = loader.GetString("SelectAllButton/Text")
                };
                SelectAllButton.Click += SelectAllButton_Click;
                Items.Add(SelectAllButton);

                HighlightSeparator = new MenuFlyoutSeparator();
                Items.Add(HighlightSeparator);

                HighlightButton = new MenuFlyoutItem()
                {
                    Text = loader.GetString("HighlightButton/Text")
                };
                HighlightButton.Click += HighlightButton_Click;
                Items.Add(HighlightButton);

                RemoveHighlightButton = new MenuFlyoutItem()
                {
                    Text = loader.GetString("RemoveHighlightButton/Text")
                };
                RemoveHighlightButton.Click += RemoveHighlightButton_Click;
                Items.Add(RemoveHighlightButton);

                CaseSeparator = new MenuFlyoutSeparator();
                Items.Add(CaseSeparator);

                UppercaseButton = new MenuFlyoutItem()
                {
                    Text = loader.GetString("UppercaseButton/Text")
                };
                UppercaseButton.Click += UppercaseButton_Click;
                Items.Add(UppercaseButton);

                LowercaseButton = new MenuFlyoutItem()
                {
                    Text = loader.GetString("LowercaseButton/Text")
                };
                LowercaseButton.Click += LowercaseButton_Click;
                Items.Add(LowercaseButton);

                SearchSeparator = new MenuFlyoutSeparator();
                Items.Add(SearchSeparator);

                SearchButton = new MenuFlyoutItem()
                {
                    Text = "[search]"
                };
                SearchButton.Click += SearchButton_Click;
                Items.Add(SearchButton);

                if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 4))
                {
                    CutButton.Icon = new FontIcon {
                        Glyph = "\uE8C6"
                    };
                    CopyButton.Icon = new FontIcon {
                        Glyph = "\uE8C8"
                    };
                    PasteButton.Icon = new FontIcon {
                        Glyph = "\uE77F"
                    };
                }

                if (ApiInformation.IsTypePresent("Windows.UI.Xaml.Input.KeyboardAccelerator"))
                {
                    KeyboardAccelerator CtrlX = new KeyboardAccelerator();
                    CtrlX.Key           = VirtualKey.X;
                    CtrlX.Modifiers     = VirtualKeyModifiers.Control;
                    CtrlX.IsEnabled     = false;
                    CutButton.AccessKey = "X";
                    CutButton.KeyboardAccelerators.Add(CtrlX);

                    KeyboardAccelerator CtrlC = new KeyboardAccelerator();
                    CtrlC.Key            = VirtualKey.C;
                    CtrlC.Modifiers      = VirtualKeyModifiers.Control;
                    CtrlC.IsEnabled      = false;
                    CopyButton.AccessKey = "C";
                    CopyButton.KeyboardAccelerators.Add(CtrlC);

                    KeyboardAccelerator CtrlV = new KeyboardAccelerator();
                    CtrlV.Key             = VirtualKey.V;
                    CtrlV.Modifiers       = VirtualKeyModifiers.Control;
                    CtrlV.IsEnabled       = false;
                    PasteButton.AccessKey = "V";
                    PasteButton.KeyboardAccelerators.Add(CtrlV);

                    KeyboardAccelerator CtrlA = new KeyboardAccelerator();
                    CtrlA.Key                 = VirtualKey.A;
                    CtrlA.Modifiers           = VirtualKeyModifiers.Control;
                    CtrlA.IsEnabled           = false;
                    SelectAllButton.AccessKey = "A";
                    SelectAllButton.KeyboardAccelerators.Add(CtrlA);
                }
            }