Пример #1
0
        private void ActionButton_Click(object sender, RoutedEventArgs e)
        {
            e.Handled = true;

            List <CommandInfo> infoList = new List <CommandInfo>();
            var groupItem           = UIHelper.GetParentDependencyObject <GroupItem>((Button)sender);
            var collectionViewGroup = groupItem.Content as CollectionViewGroup;

            if (collectionViewGroup == null)
            {
                return;
            }

            foreach (CommandInfo info in lstAvailableActions.SelectedItems)
            {
                if (collectionViewGroup.Items.Contains(info))
                {
                    infoList.Add(info);
                }
            }

            if (infoList.Count == 0)
            {
                lstAvailableActions.SelectedItems.Clear();
                foreach (CommandInfo item in collectionViewGroup.Items)
                {
                    lstAvailableActions.SelectedItems.Add(item);
                    infoList.Add(item);
                }
            }

            var          sourceAction        = infoList.First().Action;
            var          selectedApplication = (IApplication)lstAvailableApplication.SelectedItem;
            ActionDialog actionDialog        = new ActionDialog(sourceAction, selectedApplication);
            var          result = actionDialog.ShowDialog();

            if (result != null && result.Value)
            {
                var newAction = actionDialog.NewAction;
                selectedApplication.RemoveAction(newAction);
                selectedApplication.AddAction(newAction);

                if (newAction != sourceAction)
                {
                    lstAvailableActions.SelectedItem = null;
                    foreach (CommandInfo info in infoList)
                    {
                        sourceAction.RemoveCommand(info.Command);
                        newAction.AddCommand(info.Command);
                    }
                }

                var emptyActions = selectedApplication.Actions.Where(a => a.Commands == null || a.Commands.Count() == 0).ToList();
                foreach (var action in emptyActions)
                {
                    selectedApplication.RemoveAction(action);
                }
                ApplicationManager.Instance.SaveApplications();
            }
        }
Пример #2
0
        private void btnAddAction_Click(object sender, RoutedEventArgs e)
        {
            var          ai           = lstAvailableActions.SelectedItem as ActionInfo;
            string       gestureName  = ai?.GestureName;
            ActionDialog actionDialog = new ActionDialog(gestureName, lstAvailableApplication.SelectedItem as IApplication);

            actionDialog.Show();
        }
        private void QuickAddUnpressedCustomActionMenuItem_Click(object sender, EventArgs e)
        {
            ActionDialog d = new ActionDialog(_board, "Add Unpressed Action");

            if (d.ShowDialog() == DialogResult.OK)
            {
                _unpressedActions.Add(d.Action);
            }
        }
    //In Other place need to use this Dialog just Call this Method
    public static bool EnsureExecute(string msg)
    {
        ActionDialog dialogAc = new ActionDialog(msg);

        //this line will run through only when dialogAc is closed
        dialogAc.ShowDialog();
        //the magic is the property ClickResult of dialogAc
        //can be accessed even when it's closed
        return(dialogAc.ClickResult);
    }
Пример #5
0
        private void ActionButton_Click(object sender, RoutedEventArgs e)
        {
            e.Handled = true;

            List <CommandInfo> infoList = new List <CommandInfo>();
            var groupItem           = UIHelper.GetParentDependencyObject <GroupItem>((Button)sender);
            var collectionViewGroup = groupItem.Content as CollectionViewGroup;

            if (collectionViewGroup == null)
            {
                return;
            }

            lstAvailableActions.SelectedItems.Clear();
            foreach (CommandInfo item in collectionViewGroup.Items)
            {
                lstAvailableActions.SelectedItems.Add(item);
                infoList.Add(item);
            }

            var sourceAction        = infoList.First().Action;
            var selectedApplication = lstAvailableApplication.SelectedItem as IApplication;

            if (selectedApplication == null)
            {
                selectedApplication = ApplicationManager.Instance.GetAvailableUserApplications().FirstOrDefault(app => app.Actions.Contains(sourceAction));
                if (selectedApplication == null)
                {
                    return;
                }
            }
            ActionDialog actionDialog = new ActionDialog(sourceAction, selectedApplication);
            var          result       = actionDialog.ShowDialog();

            if (result != null && result.Value)
            {
                var newAction = actionDialog.NewAction;
                selectedApplication.RemoveAction(newAction);
                selectedApplication.AddAction(newAction);

                if (newAction != sourceAction)
                {
                    lstAvailableActions.SelectedItem = null;
                    foreach (CommandInfo info in infoList)
                    {
                        sourceAction.RemoveCommand(info.Command);
                        newAction.AddCommand(info.Command);
                    }
                }
                ApplicationManager.Instance.SaveApplications();
            }
        }
Пример #6
0
 private static void DequeueActionDialog()
 {
     if (actionDialogQueue.Count == 0)
     {
         // TODO: Throw error.
     }
     else if (IsAnyUiElementActive())
     {
         // TODO: Throw error.
     }
     else
     {
         activeItem = actionDialogQueue.Dequeue();
         activeItem.OnDialogDismissed += OnActionDialogDismissed;
     }
 }
Пример #7
0
        private void cmdEditAction_Click(object sender, RoutedEventArgs e)
        {
            // Make sure at least one item is selected
            if (lstAvailableActions.SelectedItems.Count == 0)
            {
                return;
            }

            // Get first item selected, associated action, and selected application
            ActionInfo   selectedItem        = (ActionInfo)lstAvailableActions.SelectedItem;
            IAction      selectedAction      = null;
            IApplication selectedApplication = null;
            string       selectedGesture     = null;

            selectedApplication = lstAvailableApplication.SelectedItem as IApplication;

            if (selectedApplication == null)
            {
                // Select action from global application list
                selectedAction = ApplicationManager.Instance.GetGlobalApplication().Actions.FirstOrDefault(a => a.Name == selectedItem.ActionName);
            }
            else
            {
                // Select action from selected application list
                selectedAction = selectedApplication.Actions.FirstOrDefault(a => a.Name == selectedItem.ActionName);
            }
            if (selectedAction == null)
            {
                return;
            }
            // Get currently assigned gesture
            selectedGesture = selectedAction.GestureName;

            // Set current application, current action, and current gestures
            ApplicationManager.Instance.CurrentApplication = selectedApplication;
            GestureManager.Instance.GestureName            = selectedGesture;

            ActionDialog actionDialog = new ActionDialog(selectedAction, selectedApplication);

            actionDialog.ShowDialog();
        }
Пример #8
0
        private void btnAddAction_Click(object sender, RoutedEventArgs e)
        {
            if (GestureManager.Instance.Gestures.Length == 0)
            {
                UIHelper.GetParentWindow(this)
                .ShowMessageAsync(LocalizationProvider.Instance.GetTextValue("Action.Messages.NoGestureTitle"),
                                  LocalizationProvider.Instance.GetTextValue("Action.Messages.NoGesture"), MessageDialogStyle.Affirmative,
                                  new MetroDialogSettings()
                {
                    AffirmativeButtonText = LocalizationProvider.Instance.GetTextValue("Common.OK"),
                    ColorScheme           = MetroDialogColorScheme.Accented,
                    AnimateHide           = false,
                    AnimateShow           = false
                });
                return;
            }

            var          ai           = lstAvailableActions.SelectedItem as ActionInfo;
            string       gestureName  = ai?.GestureName;
            ActionDialog actionDialog = new ActionDialog(gestureName, lstAvailableApplication.SelectedItem as IApplication);

            actionDialog.Show();
        }
Пример #9
0
 private static void OnActionDialogDismissed(object sender, EventArgs e)
 {
     hasActiveItem = false;
     activeItem    = null;
 }
Пример #10
0
 public static void EnqueueActionDialog(ActionDialog actionDialog)
 {
     actionDialogQueue.Enqueue(actionDialog);
 }
Пример #11
0
#pragma warning disable 1998 // The async Task keeps the signature identical between platforms.
        static public async Task <PromptResult> PromptAsync(string message, string title)
        {
#if WINDOWS_UWP
            // First we will try the advanced AlertDialog route. However, mixing Xaml and WinJS is not supported.
            // Therefore we must have a fallback using basic MessageDialog for WinJS (below).
            try
            {
                ActionDialog dlg = new ActionDialog()
                {
                    ConfirmText         = ReadResourceString("Confirm"),
                    DeclineText         = ReadResourceString("Decline"),
                    DelayText           = ReadResourceString("Delay"),
                    DontRemindAgainText = ReadResourceString("DontRemindAgain"),
                    PromptText          = ReadResourceString("RateAppPrompt"),
                    Title = title,
                };

                var result = ContentDialogResult.None;

                try
                {
                    result = await dlg.ShowAsync();
                }
                catch (Exception ex)
                {
                    //	this may happen if any other modal window is shown at the moment (ie, Windows query about running application background task)
                    await new MessageDialog($"Show Error: {ex.Message}").ShowAsync();
                }

                // Convert to a PromptResult based on the state of the ActionDialog
                if (result == ContentDialogResult.Primary)
                {
                    return(PromptResult.Confirm);
                }
                else if (dlg.DontRemindAgain)
                {
                    return(PromptResult.Decline);
                }
                else
                {
                    return(PromptResult.Delay);
                }
            }

            // If we are here, ActionDialog is not supported. We must use basic MessageDialog instead.
            catch (Exception) // No specific exception because it's HRESULT of RPC_E_WRONG_THREAD
            {
                // Use plain message dialog as with Win8 but use new string resource names
                var dlg = new MessageDialog(message, title);
                dlg.Commands.Add(new UICommand(ReadResourceString("Confirm"), null, true));
                dlg.Commands.Add(new UICommand(ReadResourceString("Decline"), null, false));

                var result = false;

                try
                {
                    result = (bool)(await dlg.ShowAsync()).Id;
                }
                catch (Exception ex)
                {
                    //	this may happen if any other modal window is shown at the moment (ie, Windows query about running application background task)
                    await new MessageDialog($"Show Error: {ex.Message}").ShowAsync();
                }

                // Convert to PromptResult
                return(result ? PromptResult.Confirm : PromptResult.Decline);
            }
#elif WIN_RT
            // Use plain message dialog
            var dlg = new MessageDialog(message, title);
            dlg.Commands.Add(new UICommand(ReadResourceString("OK"), null, true));
            dlg.Commands.Add(new UICommand(ReadResourceString("Cancel"), null, false));

            var result = false;

            try
            {
                result = (bool)(await dlg.ShowAsync()).Id;
            }
            catch (Exception)
            {
                //	this may happen if any other modal window is shown at the moment (ie, Windows query about running application background task)
            }

            return(result ? PromptResult.Confirm : PromptResult.Decline);
#elif WINDOWS_PHONE
            // Use plain message box
            var result = MessageBox.Show(message, title, MessageBoxButton.OKCancel);
            return(result == MessageBoxResult.OK ? PromptResult.Confirm : PromptResult.Decline);
#endif
        }