Skip to content

Commit b8d280f

Browse files
committed
Add command line option to desktop editor...
... --show-categories so that categories are shown when opened from the menu editor and not from the app menu.
1 parent eebb995 commit b8d280f

2 files changed

Lines changed: 42 additions & 21 deletions

File tree

files/usr/share/cinnamon/cinnamon-desktop-editor/cinnamon-desktop-editor.py

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,23 @@ def save(self):
323323
class LauncherEditor(ItemEditor):
324324
ui_file = '/usr/share/cinnamon/cinnamon-desktop-editor/launcher-editor.ui'
325325

326+
def __init__(self, item_path=None, callback=None, destdir=None, icon_size=24, show_categories=False):
327+
self.show_categories = show_categories
328+
super(LauncherEditor, self).__init__(item_path, callback, destdir, icon_size)
329+
326330
def build_ui(self):
327331
self.builder.get_object('exec-browse').connect('clicked', self.pick_exec)
328332
self.builder.get_object('name-entry').connect('changed', self.resync_validity)
329333
self.builder.get_object('exec-entry').connect('changed', self.resync_validity)
330334

331-
self.category_widgets = {} # Map ID -> CheckButton
332-
self._setup_categories_list()
333-
self.fdo_categories = []
335+
if self.show_categories:
336+
self.category_widgets = {} # Map ID -> CheckButton
337+
self._setup_categories_list()
338+
self.fdo_categories = []
339+
else:
340+
cat_section = self.builder.get_object('category-section')
341+
cat_section.set_visible(False)
342+
cat_section.set_no_show_all(True)
334343

335344
def resync_validity(self, *args):
336345
name_text = self.builder.get_object('name-entry').get_text().strip()
@@ -371,22 +380,31 @@ def load(self):
371380
self.set_check('nodisplay-check', "NoDisplay")
372381
self.set_icon("Icon")
373382

374-
# Preselect existing categories
375-
try:
376-
flowbox = self.builder.get_object('category-flowbox')
377-
self.fdo_categories = self.keyfile.get_string_list(DESKTOP_GROUP, "Categories")
378-
cinnamon_categories = self._fdo_to_cinnamon(self.fdo_categories)
379-
for cat_id in cinnamon_categories:
380-
if cat_id in self.category_widgets:
381-
self.category_widgets[cat_id].set_active(True)
382-
except GLib.GError:
383-
pass
383+
if self.show_categories:
384+
# Preselect existing categories
385+
try:
386+
flowbox = self.builder.get_object('category-flowbox')
387+
self.fdo_categories = self.keyfile.get_string_list(DESKTOP_GROUP, "Categories")
388+
cinnamon_categories = self._fdo_to_cinnamon(self.fdo_categories)
389+
for cat_id in cinnamon_categories:
390+
if cat_id in self.category_widgets:
391+
self.category_widgets[cat_id].set_active(True)
392+
except GLib.GError:
393+
pass
394+
else:
395+
try:
396+
self.old_categories = self.keyfile.get_locale_string(DESKTOP_GROUP, "Categories", None)
397+
except GLib.GError:
398+
self.old_categories = ""
384399

385400
def get_keyfile_edits(self):
386-
self.fdo_categories = self._cinnamon_to_fdo(self.fdo_categories)
387-
categories_val = ";".join(self.fdo_categories)
388-
if categories_val:
389-
categories_val += ";"
401+
if self.show_categories:
402+
self.fdo_categories = self._cinnamon_to_fdo(self.fdo_categories)
403+
categories_val = ";".join(self.fdo_categories)
404+
if categories_val:
405+
categories_val += ";"
406+
else:
407+
categories_val = self.old_categories
390408

391409
return dict(Name=self.builder.get_object('name-entry').get_text(),
392410
Exec=self.builder.get_object('exec-entry').get_text(),
@@ -548,7 +566,7 @@ def check_custom_path(self):
548566
else:
549567
# If directory appears to be from a user installed app (e.g. wine) rather
550568
# than a user created custom launcher, we show a warning that 'restore' is not available.
551-
if not file_name.startswith(("custom-", "alacarte-")):
569+
if not file_name.startswith("alacarte-"):
552570
self.builder.get_object('restore-info-bar').show()
553571

554572
class CinnamonLauncherEditor(ItemEditor):
@@ -639,6 +657,7 @@ def __init__(self):
639657
parser.add_option("-f", "--file", dest="desktop_file", help="Name of desktop file (i.e. gnome-terminal.desktop)", metavar="DESKTOP_NAME")
640658
parser.add_option("-m", "--mode", dest="mode", default=None, help="Mode to run in: launcher, directory, panel-launcher or nemo-launcher")
641659
parser.add_option("-i", "--icon-size", dest="icon_size", type=int, default=24, help="Size to set the icon picker for (panel-launcher only)")
660+
parser.add_option("--show-categories", action="store_true", dest="show_categories", default=False, help="Show the category selection section (launcher mode only)")
642661
(options, args) = parser.parse_args()
643662

644663
if not options.mode:
@@ -659,6 +678,7 @@ def __init__(self):
659678
self.orig_file = options.original_desktop_file
660679
self.desktop_file = options.desktop_file
661680
self.dest_dir = options.destination_directory
681+
self.show_categories = options.show_categories
662682

663683
if options.mode == "cinnamon-launcher":
664684
self.json_path = args[0]
@@ -671,7 +691,7 @@ def __init__(self):
671691
editor = DirectoryEditor(self.orig_file, self.directory_cb)
672692
editor.dialog.show_all()
673693
elif self.mode == "launcher":
674-
editor = LauncherEditor(self.orig_file, self.launcher_cb)
694+
editor = LauncherEditor(self.orig_file, self.launcher_cb, show_categories=self.show_categories)
675695
editor.dialog.show_all()
676696
elif self.mode == "cinnamon-launcher":
677697
editor = CinnamonLauncherEditor(self.orig_file, self.panel_launcher_cb, icon_size=self.icon_size)

files/usr/share/cinnamon/cinnamon-menu-editor/cme/MainWindow.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def on_new_menu_button_clicked(self, button):
252252

253253
def on_new_launcher_button_clicked(self, button):
254254
file_path = Path(util.getUserItemDir()) / util.getUniqueFileId('alacarte', '.desktop')
255-
process = subprocess.Popen(['cinnamon-desktop-editor', '-mlauncher', '-o' + str(file_path)], env=os.environ)
255+
process = subprocess.Popen(['cinnamon-desktop-editor', '-mlauncher', '-o' + str(file_path), "--show-categories"], env=os.environ)
256256
GLib.child_watch_add(GLib.PRIORITY_DEFAULT, process.pid, self._on_launcher_editor_exited)
257257

258258
def _on_edit_delete_restore_activate(self, menu):
@@ -344,7 +344,8 @@ def _on_edit_properties_activate(self, menu):
344344
file_type = 'launcher' if isinstance(item, CMenu.TreeEntry) else 'directory'
345345
file_path = item.get_desktop_file_path()
346346

347-
process = subprocess.Popen(['cinnamon-desktop-editor', '-m' + file_type, '-o' + file_path], env=os.environ)
347+
print()
348+
process = subprocess.Popen(['cinnamon-desktop-editor', '-m' + file_type, '-o' + file_path, "--show-categories"], env=os.environ)
348349
GLib.child_watch_add(GLib.PRIORITY_DEFAULT, process.pid, self._on_launcher_editor_exited)
349350

350351
def on_menu_tree_cursor_changed(self, treeview):

0 commit comments

Comments
 (0)