[smuxi: 13/111] Frontend-GNOME-IRC: add context menus to treeview node too
- From: Mirco M. M. Bauer <mmmbauer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [smuxi: 13/111] Frontend-GNOME-IRC: add context menus to treeview node too
- Date: Sun, 16 Feb 2014 13:15:21 +0000 (UTC)
commit 43d61f10049f1b0a511f42d1f445cd19ff4b9bcb
Author: Andrés G. Aragoneses <knocte gmail com>
Date: Thu Dec 19 00:41:21 2013 +0100
Frontend-GNOME-IRC: add context menus to treeview node too
The context menus for IrcPersonChatView were only added for when the
user right clicks on the chat area, but not when the user right-clicks
on the treeview child element. Now they are added to both, and with no
code duplication.
src/Frontend-GNOME-IRC/Frontend-GNOME-IRC.csproj | 3 +-
src/Frontend-GNOME-IRC/IrcPersonChatView.cs | 34 ++++++++++++++++++----
src/Frontend-GNOME-IRC/Makefile.am | 1 +
src/Frontend-GNOME/Views/Chats/ChatView.cs | 24 ++++++++++-----
4 files changed, 47 insertions(+), 15 deletions(-)
---
diff --git a/src/Frontend-GNOME-IRC/Frontend-GNOME-IRC.csproj
b/src/Frontend-GNOME-IRC/Frontend-GNOME-IRC.csproj
index 62c0bea..b29400a 100644
--- a/src/Frontend-GNOME-IRC/Frontend-GNOME-IRC.csproj
+++ b/src/Frontend-GNOME-IRC/Frontend-GNOME-IRC.csproj
@@ -91,6 +91,7 @@
<Private>False</Private>
<Package>glib-sharp-2.0</Package>
</Reference>
+ <Reference Include="System" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
-</Project>
\ No newline at end of file
+</Project>
diff --git a/src/Frontend-GNOME-IRC/IrcPersonChatView.cs b/src/Frontend-GNOME-IRC/IrcPersonChatView.cs
index 286bbc4..7a0b477 100644
--- a/src/Frontend-GNOME-IRC/IrcPersonChatView.cs
+++ b/src/Frontend-GNOME-IRC/IrcPersonChatView.cs
@@ -2,6 +2,7 @@
* Smuxi - Smart MUltipleXed Irc
*
* Copyright (c) 2008, 2010-2011 Mirco Bauer <meebey meebey net>
+ * Copyright (c) 2013 Andrés G. Aragoneses <knocte gmail com>
*
* Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
*
@@ -21,8 +22,8 @@
*/
using System;
+using System.Collections.Generic;
using System.Threading;
-using System.Globalization;
using Smuxi.Engine;
using Smuxi.Common;
@@ -50,6 +51,21 @@ namespace Smuxi.Frontend.Gnome
IrcProtocolManager = (IrcProtocolManager) ProtocolManager;
}
+ protected override void OnTabMenuShown(object sender, EventArgs e)
+ {
+ base.OnTabMenuShown(sender, e);
+
+ var stack = new Stack<Gtk.MenuItem>();
+ foreach (var menu_item in CreateContextMenuItems()) {
+ stack.Push(menu_item);
+ }
+ TabMenu.Prepend(new Gtk.SeparatorMenuItem());
+ while (stack.Count != 0) {
+ TabMenu.Prepend(stack.Pop());
+ }
+ TabMenu.ShowAll();
+ }
+
void OnOutputMessageTextViewPopulatePopup(object o, Gtk.PopulatePopupArgs args)
{
if (OutputMessageTextView.IsAtUrlTag) {
@@ -59,26 +75,32 @@ namespace Smuxi.Frontend.Gnome
Gtk.Menu popup = args.Menu;
popup.Append(new Gtk.SeparatorMenuItem());
+ foreach (var menu_item in CreateContextMenuItems()) {
+ popup.Append(menu_item);
+ }
+ popup.ShowAll();
+ }
+
+ IEnumerable<Gtk.MenuItem> CreateContextMenuItems()
+ {
Gtk.ImageMenuItem whois_item = new Gtk.ImageMenuItem(_("Whois"));
whois_item.Activated += OnMenuWhoisItemActivated;
- popup.Append(whois_item);
+ yield return whois_item;
Gtk.ImageMenuItem ctcp_item = new Gtk.ImageMenuItem(_("CTCP"));
Gtk.Menu ctcp_menu_item = new CtcpMenu(IrcProtocolManager,
Frontend.MainWindow.ChatViewManager,
PersonModel);
ctcp_item.Submenu = ctcp_menu_item;
- popup.Append(ctcp_item);
+ yield return ctcp_item;
Gtk.ImageMenuItem invite_to_item = new Gtk.ImageMenuItem(_("Invite to"));
Gtk.Menu invite_to_menu_item = new InviteToMenu(IrcProtocolManager,
Frontend.MainWindow.ChatViewManager,
PersonModel);
invite_to_item.Submenu = invite_to_menu_item;
- popup.Append(invite_to_item);
-
- popup.ShowAll();
+ yield return invite_to_item;
}
void OnMenuWhoisItemActivated(object sender, EventArgs e)
diff --git a/src/Frontend-GNOME-IRC/Makefile.am b/src/Frontend-GNOME-IRC/Makefile.am
index 1cdbe15..eaca695 100644
--- a/src/Frontend-GNOME-IRC/Makefile.am
+++ b/src/Frontend-GNOME-IRC/Makefile.am
@@ -99,6 +99,7 @@ RESOURCES =
EXTRAS =
REFERENCES = \
+ System \
Mono.Posix \
$(GTK_SHARP_20_LIBS)
diff --git a/src/Frontend-GNOME/Views/Chats/ChatView.cs b/src/Frontend-GNOME/Views/Chats/ChatView.cs
index 06619b8..7c82217 100644
--- a/src/Frontend-GNOME/Views/Chats/ChatView.cs
+++ b/src/Frontend-GNOME/Views/Chats/ChatView.cs
@@ -60,7 +60,6 @@ namespace Smuxi.Frontend.Gnome
bool UseLowBandwidthMode { get; set; }
public Gtk.Image TabImage { get; protected set; }
bool IsAutoScrolling { get; set; }
- Gtk.ImageMenuItem CloseItem { get; set; }
public event EventHandler<EventArgs> StatusChanged;
@@ -318,11 +317,7 @@ namespace Smuxi.Frontend.Gnome
// popup menu
_TabMenu = new Gtk.Menu();
-
- CloseItem = new Gtk.ImageMenuItem(Gtk.Stock.Close, null);
- CloseItem.Activated += new EventHandler(OnTabMenuCloseActivated);
- _TabMenu.Append(CloseItem);
- _TabMenu.ShowAll();
+ _TabMenu.Shown += OnTabMenuShown;
//FocusChild = _OutputTextView;
//CanFocus = false;
@@ -382,7 +377,7 @@ namespace Smuxi.Frontend.Gnome
// HACK: this shouldn't be needed but GTK# keeps GC handles
// these callbacks for some reason and thus leaks :(
_OutputMessageTextView.Dispose();
- CloseItem.Activated -= OnTabMenuCloseActivated;
+ _TabMenu.Shown -= OnTabMenuShown;
_OutputScrolledWindow.Vadjustment.ValueChanged -= OnVadjustmentValueChanged;
}
}
@@ -663,7 +658,20 @@ namespace Smuxi.Frontend.Gnome
Frontend.ShowException(ex);
}
}
-
+
+ protected virtual void OnTabMenuShown(object sender, EventArgs e)
+ {
+ Trace.Call(sender, e);
+
+ foreach (var child in _TabMenu.Children) {
+ _TabMenu.Remove(child);
+ }
+ var closeItem = new Gtk.ImageMenuItem(Gtk.Stock.Close, null);
+ closeItem.Activated += OnTabMenuCloseActivated;
+ _TabMenu.Append(closeItem);
+ _TabMenu.ShowAll();
+ }
+
protected virtual void OnTabMenuCloseActivated(object sender, EventArgs e)
{
Trace.Call(sender, e);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]