-
Notifications
You must be signed in to change notification settings - Fork 732
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
files/usr/share/cinnamon/applets/recent@cinnamon.org/applet.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
const DocInfo = imports.misc.docInfo; | ||
const Gtk = imports.gi.Gtk; | ||
const Gio = imports.gi.Gio; | ||
const St = imports.gi.St; | ||
const Main = imports.ui.main; | ||
const PopupMenu = imports.ui.popupMenu; | ||
const Lang = imports.lang; | ||
const Applet = imports.ui.applet; | ||
|
||
function MyPopupMenuItem() | ||
{ | ||
this._init.apply(this, arguments); | ||
} | ||
|
||
MyPopupMenuItem.prototype = | ||
{ | ||
__proto__: PopupMenu.PopupBaseMenuItem.prototype, | ||
_init: function(icon, text, params) | ||
{ | ||
PopupMenu.PopupBaseMenuItem.prototype._init.call(this, params); | ||
this.box = new St.BoxLayout({ style_class: 'popup-combobox-item' }); | ||
this.icon = icon; | ||
this.box.add(this.icon); | ||
this.label = new St.Label({ text: text }); | ||
this.box.add(this.label); | ||
this.addActor(this.box); | ||
} | ||
}; | ||
|
||
function MyMenu(launcher, orientation) { | ||
this._init(launcher, orientation); | ||
} | ||
|
||
MyMenu.prototype = { | ||
__proto__: PopupMenu.PopupMenu.prototype, | ||
|
||
_init: function(launcher, orientation) { | ||
this._launcher = launcher; | ||
|
||
PopupMenu.PopupMenu.prototype._init.call(this, launcher.actor, 0.0, orientation, 0); | ||
Main.uiGroup.add_actor(this.actor); | ||
this.actor.hide(); | ||
} | ||
} | ||
|
||
function MyApplet(orientation) { | ||
this._init(orientation); | ||
} | ||
|
||
MyApplet.prototype = { | ||
__proto__: Applet.IconApplet.prototype, | ||
|
||
_init: function(orientation) { | ||
Applet.IconApplet.prototype._init.call(this, orientation); | ||
|
||
try { | ||
this.set_applet_icon_name("document-open-recent"); | ||
this.set_applet_tooltip(_("Recent documents")); | ||
|
||
this.menuManager = new PopupMenu.PopupMenuManager(this); | ||
this.menu = new MyMenu(this, orientation); | ||
this.menuManager.addMenu(this.menu); | ||
|
||
this.RecentManager = new DocInfo.DocManager(); | ||
this._display(); | ||
this.RecentManager.connect('changed', Lang.bind(this, this._redisplay)); | ||
} | ||
catch (e) { | ||
global.logError(e); | ||
} | ||
}, | ||
|
||
on_applet_clicked: function(event) { | ||
this.menu.toggle(); | ||
}, | ||
|
||
_display: function() { | ||
for (let id = 0; id < 15 && id < this.RecentManager._infosByTimestamp.length; id++) { | ||
let icon = this.RecentManager._infosByTimestamp[id].createIcon(22); | ||
let menuItem = new MyPopupMenuItem(icon, this.RecentManager._infosByTimestamp[id].name, {}); | ||
this.menu.addMenuItem(menuItem); | ||
menuItem.connect('activate', Lang.bind(this, this._launchFile, this.RecentManager._infosByTimestamp[id].uri)); | ||
} | ||
if (this.RecentManager._infosByTimestamp.length > 0) { | ||
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); | ||
let icon = new St.Icon({ icon_name: 'edit-clear', icon_type: St.IconType.SYMBOLIC, icon_size: 22 }); | ||
let menuItem = new MyPopupMenuItem(icon, 'Clear list', {}); | ||
this.menu.addMenuItem(menuItem); | ||
menuItem.connect('activate', Lang.bind(this, this._clearAll)); | ||
} | ||
}, | ||
|
||
_redisplay: function() { | ||
this.menu.removeAll(); | ||
this._display(); | ||
}, | ||
|
||
_launchFile: function(a, b, c) { | ||
Gio.app_info_launch_default_for_uri(c, global.create_app_launch_context()); | ||
}, | ||
|
||
_clearAll: function() { | ||
let GtkRecent = new Gtk.RecentManager(); | ||
GtkRecent.purge_items(); | ||
}, | ||
|
||
destroy: function() { | ||
this.RecentManager.disconnectAll(); | ||
this.actor._delegate = null; | ||
this.menu.destroy(); | ||
this.actor.destroy(); | ||
this.emit('destroy'); | ||
} | ||
}; | ||
|
||
function main(metadata, orientation) { | ||
let myApplet = new MyApplet(orientation); | ||
return myApplet; | ||
} |
6 changes: 6 additions & 0 deletions
6
files/usr/share/cinnamon/applets/recent@cinnamon.org/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"uuid": "recent@cinnamon.org", | ||
"name": "Recent documents", | ||
"description": "Access the documents you recently opened", | ||
"icon": "document-open-recent" | ||
} |