Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CustomApplicationsMenu@LLOBERA] store preferences in applet settings #6200

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/python3

import random
from JsonSettingsWidgets import *
from gi.repository import Gio, Gtk
alexkuz marked this conversation as resolved.
Show resolved Hide resolved


class TextWidget(SettingsWidget):
def __init__(self, info, key, settings):
SettingsWidget.__init__(self)
self.settings = settings

self.set_margin_left(0)
self.set_margin_right(0)
self.set_border_width(0)

css_provider = Gtk.CssProvider()
css_provider.load_from_data(b"""
textview {
font-size: 14px;
font-family: monospace;
}
""")

screen = Gdk.Screen.get_default()
Gtk.StyleContext().add_provider_for_screen(
Gdk.Screen.get_default(),
css_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)

self.textview = Gtk.TextView()
self.textview.set_border_width(10)
self.textbuffer = self.textview.get_buffer()

self.settings.bind(key, self.textbuffer, 'text', Gio.SettingsBindFlags.DEFAULT)

self.pack_start(self.textview, True, True, 0)
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ const Lang = imports.lang;
const Util = imports.misc.util;
const Applet = imports.ui.applet;
const PopupMenu = imports.ui.popupMenu;
const Settings = imports.ui.settings;


const appletUUID = 'CustomApplicationsMenu@LLOBERA';
const AppletDirectory = imports.ui.appletManager.appletMeta[appletUUID].path;

const SettingsFile = AppletDirectory + "/applications.json";
const AppSys = Cinnamon.AppSystem.get_default();

// l10n/translation support
Expand Down Expand Up @@ -102,23 +103,22 @@ function MyApplet(orientation) {
MyApplet.prototype = {
__proto__: Applet.IconApplet.prototype,

_init: function(orientation) {
_init: function(orientation, panelHeight, instanceId) {
Applet.IconApplet.prototype._init.call(this, orientation);

try {
this.set_applet_icon_symbolic_name("help-about-symbolic");
this.set_applet_tooltip(_("Custom Applications Menu"));

// watch settings file for changes
var file = Gio.file_new_for_path(SettingsFile);
this._monitor = file.monitor(Gio.FileMonitorFlags.NONE, null);
this._monitor.connect('changed', Lang.bind(this, this._on_settingsfile_changed));

this.menuManager = new PopupMenu.PopupMenuManager(this);
this.menu = new Applet.AppletPopupMenu(this, orientation);
this.menuManager.addMenu(this.menu);

this.settings = new Settings.AppletSettings(this, appletUUID, instanceId);
this.settings.monitor.connect("changed", Lang.bind(this, this._on_settings_changed));

this._readSettings();

this._createMenuRecursive(this.menu, this.applications);
this._createContextMenu();
}
Expand All @@ -131,8 +131,7 @@ MyApplet.prototype = {
this.menu.toggle();
},

// if applications.json is modified
_on_settingsfile_changed: function() {
_on_settings_changed: function() {
this._readSettings();
this.menu.removeAll();
this._createMenuRecursive(this.menu, this.applications);
Expand Down Expand Up @@ -223,8 +222,12 @@ MyApplet.prototype = {

// parse the applications.json file into the applications variable
_readSettings: function() {
var jsonFileContent = Cinnamon.get_file_contents_utf8_sync(SettingsFile);
this.applications = JSON.parse(jsonFileContent);
try {
this.applications = JSON.parse(this.settings.getValue("applications"));
} catch(e) {
global.logError("Error parsing settings: " + e);
this.applications = [];
}
},

_createMenuItem: function(parentMenuItem, application) {
Expand All @@ -243,11 +246,6 @@ MyApplet.prototype = {
},

_createContextMenu: function() {
this.edit_menu_item = new Applet.MenuItem(_("Edit"), "document-edit-symbolic", function() {
Util.spawnCommandLine("xdg-open " + SettingsFile);
});
this._applet_context_menu.addMenuItem(this.edit_menu_item);

this.help_menu_item = new Applet.MenuItem(_("Help"), "help-faq-symbolic", function() {
Util.spawnCommandLine("xdg-open " + AppletDirectory + "/README.md");
});
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"head_applications": {
"type": "header",
"description": "Applications"
},
"applications": {
"type": "custom",
"file": "TextWidget.py",
"widget": "TextWidget",
"default": "[\n {\n \"desktopFile\": \"cinnamon-settings\"\n },\n {\n \"desktopFile\": \"gnome-system-monitor\"\n },\n {\n \"command\": \"S\"\n },\n {\n \"displayName\": \"Internet\",\n \"iconName\": \"applications-internet\",\n \"menu\": [\n {\n \"desktopFile\": \"firefox\",\n \"command\": \"firefox\"\n },\n {\n \"desktopFile\": \"firefox\",\n \"command\": \"firefox -P Profile2 -no-remote\",\n \"displayName\": \"Firefox Profile2\",\n \"active\": false\n }\n ]\n }\n]"
}
}