Permalink
Browse files

Hide/unhide users via right click

  • Loading branch information...
1 parent d1ca318 commit 1894bd51a1e8156ce1ec994ba4f621b401928488 @lprichar lprichar committed Oct 13, 2012
@@ -1,14 +1,42 @@
-using System;
-using System.Windows.Forms;
-using SirenOfShame.Lib.Helpers;
-
-namespace SirenOfShame.Lib
-{
- public class UserControlBase : UserControl
- {
- protected void Invoke(Action a)
- {
- ControlHelpers.Invoke(this, a);
- }
- }
-}
+using System;
+using System.Windows.Forms;
+using SirenOfShame.Lib.Helpers;
+
+namespace SirenOfShame.Lib
+{
+ public class UserControlBase : UserControl
+ {
+ protected void Invoke(Action a)
+ {
+ ControlHelpers.Invoke(this, a);
+ }
+
+ public void AddMouseUpToAllControls(MouseEventHandler onMouseUp)
+ {
+ AddMouseUpToControlAndAllChildren(this, onMouseUp);
+ }
+
+ public void AddMouseEnterToAllControls(EventHandler onMouseEnter)
+ {
+ AddMouseEnterToControlAndAllChildren(this, onMouseEnter);
+ }
+
+ private static void AddMouseUpToControlAndAllChildren(Control control, MouseEventHandler onMouseUp)
+ {
+ control.MouseUp += onMouseUp;
+ foreach (Control c in control.Controls)
+ {
+ AddMouseUpToControlAndAllChildren(c, onMouseUp);
+ }
+ }
+
+ private static void AddMouseEnterToControlAndAllChildren(Control control, EventHandler onMouseEnter)
+ {
+ control.MouseEnter += onMouseEnter;
+ foreach (Control c in control.Controls)
+ {
+ AddMouseEnterToControlAndAllChildren(c, onMouseEnter);
+ }
+ }
+ }
+}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -60,15 +60,41 @@ public void Initialize(SirenOfShameSettings settings, ImageList avatarImageList)
Cursor = Cursors.Hand,
Visible = !person.Hidden
};
- userPanel.MouseEnter += UserPanelMouseEnter;
- userPanel.Click += UserPanelClick;
+
+ userPanel.AddMouseUpToAllControls(UserPanelMouseUp);
+ userPanel.AddMouseEnterToAllControls(UserPanelMouseEnter);
+
_usersPanel.Controls.Add(userPanel);
}
}
- void UserPanelClick(object sender, EventArgs e)
+ private string _selectedRawName;
+
+ private void UserPanelMouseUp(object sender, MouseEventArgs e)
+ {
+ UserPanel userPanel = TraverseParentsUntilUserPanel((Control) sender);
+ if (userPanel == null) return;
+
+ if (e.Button == MouseButtons.Right)
+ {
+ _selectedRawName = userPanel.RawName;
+ _userMenu.Show((Control)sender, e.Location);
+ var person = Settings.FindPersonByRawName(_selectedRawName);
+ _hiddenButton.Checked = person.Hidden;
+ }
+
+ if (e.Button == MouseButtons.Left)
+ {
+ InvokeOnUserSelected(userPanel.RawName);
+ }
+ }
+
+ private UserPanel TraverseParentsUntilUserPanel(Control sender)
{
- InvokeOnUserSelected(((UserPanel)sender).RawName);
+ var userPanel = sender as UserPanel;
+ if (userPanel != null) return userPanel;
+ if (sender.Parent == null) return null;
+ return TraverseParentsUntilUserPanel(sender.Parent);
}
void UserPanelMouseEnter(object sender, EventArgs e)
@@ -106,15 +132,31 @@ public void RefreshDisplayNames(UserDisplayNameChangedArgs args)
userPanel.DisplayName = args.NewDisplayName;
}
- public void ShowAllUsers(bool showAllUser)
+ private bool _showAllUsers = false;
+
+ public void SetShowAllUsers(bool showAllUsers)
+ {
+ _showAllUsers = showAllUsers;
+ RefreshUserPanelVisibility();
+ }
+
+ private void RefreshUserPanelVisibility()
{
foreach (var userPanel in GetUserPanels())
{
var rawName = userPanel.RawName;
var person = Settings.FindPersonByRawName(rawName);
- userPanel.Visible = showAllUser || !person.Hidden;
+ userPanel.Visible = _showAllUsers || !person.Hidden;
}
}
+
+ private void HiddenButtonClick(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(_selectedRawName)) return;
+ var selectedPerson = Settings.FindPersonByRawName(_selectedRawName);
+ selectedPerson.Hidden = !selectedPerson.Hidden;
+ RefreshUserPanelVisibility();
+ }
}
public delegate void UserSelected(object sender, UserSelectedArgs args);
Oops, something went wrong.

0 comments on commit 1894bd5

Please sign in to comment.