2
// Copyright (C) 2009 Chris Szikszoy, Robert Dyer
3
// Copyright (C) 2010 Robert Dyer
4
// Copyright (C) 2011 Robert Dyer
6
// This program is free software: you can redistribute it and/or modify
7
// it under the terms of the GNU General Public License as published by
8
// the Free Software Foundation, either version 3 of the License, or
9
// (at your option) any later version.
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21
using System.Collections.Generic;
28
using Docky.Services.Prefs;
30
namespace RecentDocuments
32
public class RecentFilesProvider : AbstractDockItemProvider
34
#region AbstractDockItemProvider implementation
36
public override string Name {
44
int NumRecentDocs { get; set; }
46
bool CanClear { get; set; }
48
AbstractDockItem emptyItem = new EmptyRecentItem ();
50
public RecentFilesProvider (IPreferences prefs)
52
NumRecentDocs = prefs.Get<int> ("NumRecentDocs", 7);
55
Gtk.RecentManager.Default.Changed += delegate { RefreshRecentDocs (); };
58
public void RefreshRecentDocs ()
60
List<AbstractDockItem> items = new List<AbstractDockItem> ();
62
GLib.List recent_items = new GLib.List (Gtk.RecentManager.Default.Items.Handle, typeof(Gtk.RecentInfo), false, false);
63
IEnumerable<Gtk.RecentInfo> infos = recent_items.OfType<Gtk.RecentInfo> ();
64
CanClear = recent_items.Count > 0;
66
items.Add (emptyItem);
67
items.AddRange (infos.Where (it => it.Exists ())
68
.OrderByDescending (f => f.Modified)
70
.Select (f => (AbstractDockItem)FileDockItem.NewFromUri (f.Uri)));
72
foreach (Gtk.RecentInfo ri in infos)
74
recent_items.Dispose ();
79
public override MenuList GetMenuItems (AbstractDockItem item)
81
MenuList list = base.GetMenuItems (item);
83
list[MenuListContainer.ProxiedItems].RemoveAt (0);
84
list[MenuListContainer.Footer].Add (new MenuItem (Catalog.GetString ("_Clear Recent Documents..."), "edit-clear", (o, a) => ClearRecent (), !CanClear));
91
Gtk.MessageDialog md = new Gtk.MessageDialog (null,
93
Gtk.MessageType.Warning,
95
"<b><big>" + Catalog.GetString ("Clear the Recent Documents list?") + "</big></b>");
97
md.Title = Catalog.GetString ("Clear Recent Documents");
98
md.Icon = DockServices.Drawing.LoadIcon ("docky", 22);
99
md.SecondaryText = Catalog.GetString ("If you clear the Recent Documents list, you clear the following:\n" +
100
"\u2022 All items from the Places \u2192 Recent Documents menu item.\n" +
101
"\u2022 All items from the recent documents list in all applications.");
104
md.AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
105
md.AddButton (Gtk.Stock.Clear, Gtk.ResponseType.Ok);
106
md.DefaultResponse = Gtk.ResponseType.Ok;
108
md.Response += (o, args) => {
109
if (args.ResponseId != Gtk.ResponseType.Cancel)
110
Gtk.RecentManager.Default.PurgeItems ();