コード例 #1
0
ファイル: State.cs プロジェクト: pragmatrix/Dominator
 static DominationState QueryItemState(IDominatorItem item)
 {
     try
     {
         var state = item.GetState();
         return new DominationState(state);
     }
     catch (Exception e)
     {
         return new DominationState(e);
     }
 }
コード例 #2
0
ファイル: UI.cs プロジェクト: pragmatrix/Dominator
		public static UIElement ForItem(IDominatorItem item, IUIRegistrationContext context)
		{
			var panel = new StackPanel
			{
				Margin = new Thickness(0, 0, 0, DefaultMargin * 2)
			};
			var description = CreateDescription(item.Description, forGroup: false);
			panel.Children.Add(description);

			var switchPanel = new DockPanel
			{
				Margin = new Thickness(0, DefaultMargin, 0, 0)
			};

			var sw = createSwitch();
			sw.VerticalAlignment = VerticalAlignment.Top;
			
			switchPanel.Children.Add(sw);
			// we don't want to use actual Label controls, because they parse '_' underscores as
			// Alt Key shortcuts.
			var errorLabel = CreateTextBlock("");
			errorLabel.VerticalAlignment = VerticalAlignment.Center;
			errorLabel.Foreground = RedBrush;
			errorLabel.Margin = new Thickness(DefaultMargin*2, 0, DefaultMargin, 0);

			var messageLabel = CreateTextBlock("");
			messageLabel.VerticalAlignment = VerticalAlignment.Center;
			messageLabel.Margin = new Thickness(DefaultMargin * 2, 0, DefaultMargin, 0);

			switchPanel.Children.Add(errorLabel);
			switchPanel.Children.Add(messageLabel);

			// argh, that **** calls us back when we change the state manually.
			var section = new Soft.Section();

			sw.Checked += (sender, args) =>
			{
				if (!section.IsLocked)
					context.requestAction(item, DominationAction.Dominate);
			};

			sw.Unchecked += (sender, args) =>
			{
				if (!section.IsLocked)
					context.requestAction(item, DominationAction.MakeSubmissive);
			};

			context.registerFeedback(item,
				state =>
				{
					bool error = state.Error_ != null;
					if (error)
					{
						errorLabel.Text = state.Error_.Message;
					}
					else
					{
						Debug.Assert(state.State_ != null);
						switch (state.State_.Value.Kind)
						{
						case DominatorStateKind.Dominated:
							using (section.Lock())
								sw.IsChecked = true;
							break;
						case DominatorStateKind.Submissive:
							using (section.Lock())
								sw.IsChecked = false;
							sw.UncheckedContent = L_YES;
							sw.UncheckedBackground = UncheckedBackgroundRed;
						break;
						case DominatorStateKind.Indetermined:
							using (section.Lock())
								sw.IsChecked = false;
							sw.UncheckedContent = L_N_A;
							sw.UncheckedBackground = UncheckedBackgroundOrange;
						break;
						}

						messageLabel.Text = state.State_.Value.Message;
					}

					errorLabel.Visibility = error ? Visibility.Visible : Visibility.Collapsed;
					messageLabel.Visibility = error ? Visibility.Collapsed : Visibility.Visible;
				});

			panel.Children.Add(switchPanel);
			return panel;
		}
コード例 #3
0
ファイル: UIController.cs プロジェクト: pragmatrix/Dominator
 void scheduleDominationAndFeedback(IDominatorItem dominator, DominationAction action)
 {
     schedule(() =>
     {
         try
         {
             dominator.SetState(action);
             var state = dominator.QueryState();
             scheduleToUI(() => feedBackState(dominator, state));
         }
         catch (Exception e)
         {
             var state = new DominationState(e);
             scheduleToUI(() => feedBackState(dominator, state));
         }
     });
 }
コード例 #4
0
ファイル: UIController.cs プロジェクト: pragmatrix/Dominator
 void feedBackState(IDominatorItem dominator, DominationState state)
 {
     requireOnUIThread();
     _feedback[dominator](state);
 }
コード例 #5
0
ファイル: UIController.cs プロジェクト: pragmatrix/Dominator
 public void requestAction(IDominatorItem dominator, DominationAction action)
 {
     requireOnUIThread();
     scheduleDominationAndFeedback(dominator, action);
 }
コード例 #6
0
ファイル: UIController.cs プロジェクト: pragmatrix/Dominator
 public void registerFeedback(IDominatorItem dominator, Action<DominationState> feedbackFunction)
 {
     requireOnUIThread();
     _feedback[dominator] = feedbackFunction;
 }
コード例 #7
0
ファイル: UIController.cs プロジェクト: pragmatrix/Dominator
 void scheduleFeedbackFor(IDominatorItem dominator)
 {
     schedule(() =>
     {
         var state = dominator.QueryState();
         scheduleToUI(() => feedBackState(dominator, state));
     });
 }