3
// Copyright (C) 2008 GNOME Do
5
// This program is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program. If not, see <http://www.gnu.org/licenses/>.
20
using System.Collections.Generic;
30
using Do.Universe.Common;
32
using Do.Interface.Wink;
33
using Do.Interface.CairoUtils;
35
using Docky.Interface.Menus;
36
using Docky.Utilities;
40
namespace Docky.Interface
44
public class ItemDockItem : WnckDockItem, IRightClickable
49
List<Wnck.Window> windows;
51
public event EventHandler RemoveClicked;
53
protected override string Icon {
54
get { return item.Icon; }
59
if (NeedsAttention && AttentionWindows.Any ())
60
return AttentionWindows.First ().Name;
62
if (VisibleWindows.Any () && WindowCount == 1)
63
return VisibleWindows.First ().Name;
69
public override Item Item {
73
public override IEnumerable<Wnck.Window> Windows {
74
get { return windows; }
77
IEnumerable<Wnck.Window> AttentionWindows {
78
get { return VisibleWindows.Where (w => w.NeedsAttention ()); }
81
public IEnumerable<int> Pids {
82
get { return windows.Select (win => win.Pid).ToArray (); }
85
public override int WindowCount {
86
get { return window_count; }
89
public ItemDockItem (Item item) : base ()
93
windows = new List<Wnck.Window> ();
96
NeedsAttention = DetermineUrgencyStatus ();
101
public void UpdateApplication ()
103
UnregisterWindowEvents ();
105
if (item is IApplicationItem) {
106
windows = WindowUtils.WindowListForCmd ((item as IApplicationItem).Exec);
107
window_count = windows.Where (w => !w.IsSkipTasklist).Count ();
110
RegisterWindowEvents ();
112
SetIconRegionFromCache ();
115
void RegisterWindowEvents ()
117
foreach (Wnck.Window w in VisibleWindows) {
118
w.StateChanged += HandleStateChanged;
119
w.NameChanged += HandleNameChanged;
123
void UnregisterWindowEvents ()
125
foreach (Wnck.Window w in Windows) {
127
w.StateChanged -= HandleStateChanged;
128
w.NameChanged -= HandleNameChanged;
133
void HandleStateChanged (object o, StateChangedArgs args)
135
if (handle_timer > 0) return;
136
// we do this delayed so that we dont get a flood of these events. Certain windows behave badly.
137
handle_timer = GLib.Timeout.Add (100, HandleUpdate);
138
window_count = VisibleWindows.Count ();
139
SetIconRegionFromCache ();
142
void HandleNameChanged(object sender, EventArgs e)
149
bool needed_attention = NeedsAttention;
150
NeedsAttention = DetermineUrgencyStatus ();
152
if (NeedsAttention != needed_attention) {
153
UpdateRequestType req;
155
req = UpdateRequestType.NeedsAttentionSet;
157
req = UpdateRequestType.NeedsAttentionUnset;
158
OnUpdateNeeded (new UpdateRequestArgs (this, req));
166
public override void HotSeatRequested ()
168
if (WindowCount == 0) return;
170
List<AbstractDockItem> dockitems = new List<AbstractDockItem> ();
172
foreach (Act act in ActionsForItem (item)) {
173
dockitems.Add (new ActionDockItem (act, item));
176
Docky.Core.DockServices.ItemsService.HotSeatItem (this, dockitems);
177
base.HotSeatRequested ();
180
public override void Clicked (uint button, Gdk.ModifierType state, PointD position)
182
SetIconRegionFromCache ();
183
base.Clicked (button, state, position);
187
protected override void Launch ()
189
if (Item is IFileItem)
190
Services.Core.PerformDefaultAction (Item as Item, new [] { typeof (OpenAction), });
192
Services.Core.PerformDefaultAction (Item as Item, Type.EmptyTypes);
195
public override bool Equals (AbstractDockItem other)
197
if (other == null) return false;
199
ItemDockItem di = other as ItemDockItem;
200
return di != null && di.Item != null && Item != null && di.Item.UniqueId == Item.UniqueId;
203
#region IDisposable implementation
205
public override void Dispose ()
207
UnregisterWindowEvents ();
216
#region IRightClickable implementation
218
public IEnumerable<AbstractMenuArgs> GetMenuItems ()
220
bool hasApps = HasVisibleApps;
222
yield return new SeparatorMenuButtonArgs ();
225
foreach (Act act in ActionsForItem (item))
226
yield return new LaunchMenuButtonArgs (act, item, act.Name, act.Icon).AsDark ();
228
foreach (Act act in ActionsForItem (item))
229
yield return new LaunchMenuButtonArgs (act, item, act.Name, act.Icon);
233
foreach (Wnck.Window window in VisibleWindows) {
234
yield return new SeparatorMenuButtonArgs ();
235
yield return new WindowMenuButtonArgs (window, window.Name, Icon);