En cours Modifier 'applet.js' de 'removable-drives@cinnamon.org'

Installation, configuration et utilisation des logiciels que vous souhaitez installer.
Avatar du membre
6ril
Messages : 12
Enregistré le : jeu. 4 janv. 2018 14:54
Localisation : Balaruc les bains France

Re: Modifier 'applet.js' de 'removable-drives@cinnamon.org'

Message par 6ril »

Dernier message de la page précédente :

Salut Harghlub et merci pour contrib. Les crochets dont tu parles sont ceux que j'ai mis moi-même dans mon message en pensant isoler la partie du code dans mon message. Il ne font pas partie du code lui-même!
Voici donc le fichier original et celui que j'ai modifié (sans les crochets):
contenu de l'applet.js original: (à savoir qu'en ouvrant les codes qui suivent dans Xed (ou autres) avec l'incrémentation activée, les lignes concernées sont 57; 58; 59 et 60)

Code : Tout sélectionner

const Lang = imports.lang;
const St = imports.gi.St;
const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;
const Applet = imports.ui.applet;
const Main = imports.ui.main;
const PopupMenu = imports.ui.popupMenu;

const PANEL_EDIT_MODE_KEY = "panel-edit-mode";

class DriveMenuItem extends PopupMenu.PopupBaseMenuItem {
    constructor(place) {
        super();

        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() {
        this.place.remove();
    }

    activate(event) {
        this.place.launch({ timestamp: event.get_time() });
        super.activate(event);
    }
}

class CinnamonRemovableDrivesApplet extends Applet.IconApplet {
    constructor(orientation, panel_height, instance_id) {
        super(orientation, panel_height, instance_id);

        this.set_applet_icon_symbolic_name("drive-harddisk");
        this.set_applet_tooltip(_("Removable drives"));

        global.settings.connect('changed::' + PANEL_EDIT_MODE_KEY, Lang.bind(this, this._onPanelEditModeChanged));

        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 homeFile = Gio.file_new_for_path(GLib.get_home_dir());
            let homeUri = homeFile.get_uri();
            Gio.app_info_launch_default_for_uri(homeUri, null);
        });

        Main.placesManager.connect('mounts-updated', Lang.bind(this, this._update));
        this._onPanelEditModeChanged();
    }

    _onPanelEditModeChanged() {
        if (global.settings.get_boolean(PANEL_EDIT_MODE_KEY)) {
            this.actor.show();
        }
        else {
            this._update();
        }
    }

    on_applet_clicked(event) {
        this.menu.toggle();
    }

    _update() {
        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 = any;
    }
}

function main(metadata, orientation, panel_height, instance_id) {
    return new CinnamonRemovableDrivesApplet(orientation, panel_height, instance_id);
}

contenu de l'applet modifié (mais qui ne plante l'applet, mais ne donne pas de résultat:

const Lang = imports.lang;
const St = imports.gi.St;
const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;
const Applet = imports.ui.applet;
const Main = imports.ui.main;
const PopupMenu = imports.ui.popupMenu;

const PANEL_EDIT_MODE_KEY = "panel-edit-mode";

class DriveMenuItem extends PopupMenu.PopupBaseMenuItem {
    constructor(place) {
        super();

        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() {
        this.place.remove();
    }

    activate(event) {
        this.place.launch({ timestamp: event.get_time() });
        super.activate(event);
    }
}

class CinnamonRemovableDrivesApplet extends Applet.IconApplet {
    constructor(orientation, panel_height, instance_id) {
        super(orientation, panel_height, instance_id);

        this.set_applet_icon_symbolic_name("drive-harddisk");
        this.set_applet_tooltip(_("Removable drives"));

        global.settings.connect('changed::' + PANEL_EDIT_MODE_KEY, Lang.bind(this, this._onPanelEditModeChanged));

        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(_("Poste de travail"), function(event) {
            let computerFile = Gio.file_new_for_path(GLib.get_computer_dir());
            let computerUri = computerFile.get_uri();
            Gio.app_info_launch_default_for_uri(computerUri, null);
        });

        Main.placesManager.connect('mounts-updated', Lang.bind(this, this._update));
        this._onPanelEditModeChanged();
    }

    _onPanelEditModeChanged() {
        if (global.settings.get_boolean(PANEL_EDIT_MODE_KEY)) {
            this.actor.show();
        }
        else {
            this._update();
        }
    }

    on_applet_clicked(event) {
        this.menu.toggle();
    }

    _update() {
        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 = any;
    }
}

function main(metadata, orientation, panel_height, instance_id) {
    return new CinnamonRemovableDrivesApplet(orientation, panel_height, instance_id);
}
Merci encore, 6ril
Modifié en dernier par thyam le dim. 18 avr. 2021 15:44, modifié 1 fois.
Raison : mis en balise code
System: Kernel: 5.4.0-42-generic x86_64 bits: 64 Desktop: Cinnamon 4.4.8 Distro: Linux Mint 19.3 Tricia Machine: Type: Laptop System: Dell product: Latitude E7440 date: 10/09/2018 CPU: Dual Core: Intel Core i7-4600U type: MT MCP speed: 1189 MHz min/max: 800/3300 MHz Graphics: Device-1: Intel Haswell-ULT Integrated Graphics Info: Processes: 250 Uptime: 1h 32m Memory: 7.68 GiB used: 2.48 GiB (32.2%) Shell: bash inxi: 3.0.32

Avatar du membre
alain
Administrateur du site
Messages : 14788
Enregistré le : dim. 11 oct. 2015 23:41
Localisation : Chelles
Contact :

Re: Modifier 'applet.js' de 'removable-drives@cinnamon.org'

Message par alain »

Bonjour.

Sujet archivé (en lecture seule) car 2 mois sans réponse.
Si besoin de rouvrir faire un MP à un membre de l'équipe ;)
PC are like air conditioning, they becomes useless when you open Windows (L.T)
PC1 : CM : ASRock 990FX | CPU: AMD FX 8350-8 cores, 4 GHz | RAM: 16 Go DDR3 1600 MHz | CG: ATI RX 580-8 Go | OS : LM 20.3 Uma Xfce 4.16 | K: 5.4
PC2
:Core2 Quad Q9650 @ 3 GHz | CG: Nvidia GTX 650TI | OS: LM 21.3 Xfce 4.18| K: 6.5
PC3 :Core i7-2600 @ 3,5 GHz | CG: ATI HD 4650 | OS: Emmade5 Xfce 4.18.0 | K: 6.1
PC4 : AMD Ryzen 5 3500X 4GHz | CG: GTX 970 | Ram : 8GB |OS : Debian 10.5 | K: 5.10
In a world without walls and fences, who needs windows and gates?

Répondre