Created
March 29, 2012 16:04
-
-
Save jnbek/2238997 to your computer and use it in GitHub Desktop.
my removable drives applet
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
const Lang = imports.lang; | |
const St = imports.gi.St; | |
const Cinnamon = imports.gi.Cinnamon; | |
const Applet = imports.ui.applet; | |
const Main = imports.ui.main; | |
const PopupMenu = imports.ui.popupMenu; | |
function DriveMenuItem(place) { | |
this._init(place); | |
} | |
DriveMenuItem.prototype = { | |
__proto__: PopupMenu.PopupBaseMenuItem.prototype, | |
_init: function(place) { | |
PopupMenu.PopupBaseMenuItem.prototype._init.call(this); | |
this.place = place; | |
this.label = new St.Label({ text: place.name }); | |
this.addActor(this.label); | |
let ejectIcon = new St.Icon({ icon_name: 'media-eject', | |
icon_type: St.IconType.SYMBOLIC, | |
style_class: 'popup-menu-icon ' }); | |
let ejectButton = new St.Button({ child: ejectIcon }); | |
ejectButton.connect('clicked', Lang.bind(this, this._eject)); | |
this.addActor(ejectButton); | |
}, | |
_eject: function() { | |
this.place.remove(); | |
}, | |
activate: function(event) { | |
this.place.launch({ timestamp: event.get_time() }); | |
PopupMenu.PopupBaseMenuItem.prototype.activate.call(this, event); | |
} | |
}; | |
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_symbolic_name("computer"); | |
this.set_applet_tooltip(_("Removable drives")); | |
this.menuManager = new PopupMenu.PopupMenuManager(this); | |
this.menu = new Applet.AppletPopupMenu(this, orientation); | |
this.menuManager.addMenu(this.menu); | |
this._contentSection = new PopupMenu.PopupMenuSection(); | |
this.menu.addMenuItem(this._contentSection); | |
this._update(); | |
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); | |
this.menu.addAction(_("Open file manager"), function(event) { | |
let appSystem = Cinnamon.AppSystem.get_default(); | |
let app = appSystem.lookup_app('nautilus.desktop'); | |
app.activate_full(-1, event.get_time()); | |
}); | |
Main.placesManager.connect('mounts-updated', Lang.bind(this, this._update)); | |
} | |
catch (e) { | |
global.logError(e); | |
} | |
}, | |
on_applet_clicked: function(event) { | |
this.menu.toggle(); | |
}, | |
_update: function() { | |
this._contentSection.removeAll(); | |
let mounts = Main.placesManager.getMounts(); | |
let any = false; | |
for (let i = 0; i < mounts.length; i++) { | |
if (mounts[i].isRemovable()) { | |
this._contentSection.addMenuItem(new DriveMenuItem(mounts[i])); | |
any = true; | |
} | |
} | |
this.actor.visible = true; | |
} | |
}; | |
function main(metadata, orientation) { | |
let myApplet = new MyApplet(orientation); | |
return myApplet; | |
} |
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
{ | |
"uuid": "my-removable-drives@zoelife4u.org", | |
"name": "My Removable drives", | |
"description": "Access removable drives", | |
"icon": "media-eject" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment