@@ -323,14 +323,23 @@ def save(self):
323323class 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
554572class 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 )
0 commit comments