diff --git a/makepot b/makepot index 70caf26..d80b2a3 100755 --- a/makepot +++ b/makepot @@ -1,4 +1,4 @@ #!/bin/bash -xgettext --language=Python --keyword=_ --output=mintmenu.pot usr/lib/linuxmint/mintMenu/mintMenu.py usr/lib/linuxmint/mintMenu/mintMenuConfig.py usr/lib/linuxmint/mintMenu/keybinding.py usr/lib/linuxmint/mintMenu/plugins/recent.py usr/lib/linuxmint/mintMenu/plugins/applications.py usr/lib/linuxmint/mintMenu/plugins/system_management.py usr/lib/linuxmint/mintMenu/plugins/places.py +xgettext --language=Python --keyword=_ --output=mintmenu.pot usr/lib/linuxmint/mintMenu/mintMenu.py usr/lib/linuxmint/mintMenu/mintMenuConfig.py usr/lib/linuxmint/mintMenu/keybinding.py usr/lib/linuxmint/mintMenu/plugins/recent.py usr/lib/linuxmint/mintMenu/plugins/applications.py usr/lib/linuxmint/mintMenu/plugins/system_management.py usr/lib/linuxmint/mintMenu/plugins/places.py usr/lib/linuxmint/mintMenu/plugins/recentHelper.py diff --git a/mintmenu.pot b/mintmenu.pot index 20c985e..9e1a5b4 100644 --- a/mintmenu.pot +++ b/mintmenu.pot @@ -126,9 +126,9 @@ msgstr "" msgid "Theme" msgstr "" -#: usr/lib/linuxmint/mintMenu/mintMenuConfig.py:66 -#: usr/lib/linuxmint/mintMenu/plugins/applications.py:189 -#: usr/lib/linuxmint/mintMenu/plugins/applications.py:190 +#: usr/lib/linuxmint/mintMenu/mintMenuConfig.py:69 +#: usr/lib/linuxmint/mintMenu/plugins/applications.py:202 +#: usr/lib/linuxmint/mintMenu/plugins/applications.py:203 msgid "Favorites" msgstr "" @@ -333,8 +333,8 @@ msgstr "" msgid "" msgstr "" -#: usr/lib/linuxmint/mintMenu/plugins/recent.py:31 -msgid "Recent documents" +#: usr/lib/linuxmint/mintMenu/plugins/recent.py:32 +msgid "Recently used" msgstr "" #: usr/lib/linuxmint/mintMenu/plugins/applications.py:187 @@ -532,3 +532,9 @@ msgstr "" #: usr/lib/linuxmint/mintMenu/plugins/places.py:260 msgid "Empty trash" msgstr "" + +#: usr/lib/linuxmint/mintMenu/plugins/recentHelper.py:44 +msgid "" +"Couldn't save recent apps. Check if you have write access to ~/.linuxmint/" +"mintMenu" +msgstr "" diff --git a/usr/lib/linuxmint/mintMenu/plugins/applications.py b/usr/lib/linuxmint/mintMenu/plugins/applications.py index f4d7485..b355387 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/applications.py +++ b/usr/lib/linuxmint/mintMenu/plugins/applications.py @@ -17,6 +17,7 @@ from easybuttons import * from execute import Execute from easygsettings import EasyGSettings from easyfiles import * +import recentHelper as RecentHelper import matemenu @@ -157,6 +158,7 @@ class pluginclass( object ): @print_timing def __init__( self, mintMenuWin, toggleButton, de ): self.mintMenuWin = mintMenuWin + RecentHelper.mintMenuWin = mintMenuWin self.mainMenus = [ ] @@ -247,7 +249,7 @@ class pluginclass( object ): print detail self.currentFavCol = 0 self.favorites = [] - + self.content_holder.set_size_request( self.width, self.height ) self.categoriesBox.set_size_request( self.width / 3, -1 ) self.applicationsBox.set_size_request( self.width / 2, -1 ) @@ -280,8 +282,7 @@ class pluginclass( object ): self.icon_theme = Gtk.IconTheme.get_default(); self.icon_theme.connect("changed", self.on_icon_theme_changed) - - + def refresh_apt_cache(self): if self.useAPT: os.system("mkdir -p %s/.linuxmint/mintMenu/" % home) @@ -433,6 +434,7 @@ class pluginclass( object ): self.Todos() self.buildFavorites() + RecentHelper.buildRecentApps() self.RebuildPlugin() def GetGSettingsEntries( self ): @@ -1288,6 +1290,7 @@ class pluginclass( object ): def do_plugin( self ): self.Todos() self.buildFavorites() + RecentHelper.buildRecentApps() # Scroll button into view def scrollItemIntoView( self, widget, event = None ): @@ -1361,7 +1364,7 @@ class pluginclass( object ): favButton.connect( "popup-menu", self.favPopup ) favButton.connect( "button-press-event", self.favPopup ) favButton.connect( "focus-in-event", self.scrollItemIntoView ) - favButton.connect( "clicked", lambda w: self.mintMenuWin.hide() ) + favButton.connect( "clicked", RecentHelper.applicationButtonClicked ) self.mintMenuWin.setTooltip( favButton, favButton.getTooltip() ) favButton.type = "location" @@ -1478,7 +1481,7 @@ class pluginclass( object ): self.favoritesReorder( favButton.position, position ) self.favoritesSave() - + def favoritesRemove( self, position ): tmp = self.favorites[ position ] self.favorites.remove( self.favorites[ position ] ) @@ -1683,7 +1686,7 @@ class pluginclass( object ): self.mintMenuWin.setTooltip( item["button"], item["button"].getTooltip() ) item["button"].connect( "button-press-event", self.menuPopup ) item["button"].connect( "focus-in-event", self.scrollItemIntoView ) - item["button"].connect( "clicked", lambda w: self.mintMenuWin.hide() ) + item["button"].connect( "clicked", RecentHelper.applicationButtonClicked ) if self.activeFilter[0] == 0: item["button"].filterText( self.activeFilter[1] ) else: diff --git a/usr/lib/linuxmint/mintMenu/plugins/recent.glade b/usr/lib/linuxmint/mintMenu/plugins/recent.glade index d02b357..363539d 100644 --- a/usr/lib/linuxmint/mintMenu/plugins/recent.glade +++ b/usr/lib/linuxmint/mintMenu/plugins/recent.glade @@ -23,7 +23,6 @@ True False - False True diff --git a/usr/lib/linuxmint/mintMenu/plugins/recent.py b/usr/lib/linuxmint/mintMenu/plugins/recent.py index 7dce3eb..38c1130 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/recent.py +++ b/usr/lib/linuxmint/mintMenu/plugins/recent.py @@ -9,6 +9,7 @@ from easygsettings import EasyGSettings from execute import Execute from easyfiles import * from easybuttons import * +import recentHelper as RecentHelper class pluginclass: """This is the main class for the plugin""" @@ -28,12 +29,17 @@ class pluginclass: self.window = self.builder.get_object( "window1" ) #Set 'heading' property for plugin - self.heading = _("Recent documents") + self.heading = _("Recently used") #This should be the first item added to the window in glade self.content_holder = self.builder.get_object( "eventbox1" ) self.recentBox = self.builder.get_object("RecentBox") + self.recentAppBox = self.builder.get_object("RecentApps") + RecentHelper.recentAppBox = self.recentAppBox + + #self.recentApps = [] + self.recentVBox = self.builder.get_object( "vbox1" ) #Specify plugin width @@ -49,12 +55,15 @@ class pluginclass: self.settings.notifyAdd( 'num-recent-docs', self.RegenPlugin ) self.settings.notifyAdd( 'recent-font-size', self.RegenPlugin ) + self.appSettings = EasyGSettings( "com.linuxmint.mintmenu.plugins.applications" ) + self.appSettings.notifyAdd( "icon-size", self.RegenPlugin ) + self.FileList=[] self.RecManagerInstance = Gtk.RecentManager.get_default() self.recentManagerId = self.RecManagerInstance.connect("changed", self.DoRecent) self.RegenPlugin() - self.builder.get_object( "RecentTabs" ).set_current_page(1) + self.builder.get_object( "RecentTabs" ).set_current_page(0) #Connect event handlers self.builder.get_object("ClrBtn").connect("clicked", self.clrmenu) @@ -79,6 +88,8 @@ class pluginclass: self.recenth = self.settings.get( 'int', 'height' ) self.recentw = self.settings.get( 'int', 'width' ) self.numentries = self.settings.get( 'int', 'num-recent-docs' ) + RecentHelper.numentries = self.numentries + self.recentfontsize = self.settings.get( 'int', 'recent-font-size' ) # Hide vertical dotted separator @@ -88,6 +99,7 @@ class pluginclass: # Allow plugin to be minimized to the left plugin pane self.sticky = self.settings.get( "bool", "sticky" ) self.minimized = self.settings.get( "bool", "minimized" ) + RecentHelper.iconSize = self.appSettings.get( "int", "icon-size") self.RebuildPlugin() def SetHidden( self, state ): @@ -105,7 +117,7 @@ class pluginclass: def DoRecent( self, *args, **kargs ): for i in self.recentBox.get_children(): i.destroy() - + self.recentVBox.set_size_request( self.recentw, self.recenth ) if len( self.recentBox.get_children() ) < self.numentries: n=len( self.recentBox.get_children() )-1 @@ -121,6 +133,9 @@ class pluginclass: if Name != None: self.AddRecentBtn( Name, self.IconList[loc] ) loc = loc + 1 + + RecentHelper.doRecentApps() + return True def clrmenu(self, *args, **kargs): @@ -210,3 +225,4 @@ class pluginclass: def do_plugin(self): self.DoRecent() + \ No newline at end of file diff --git a/usr/lib/linuxmint/mintMenu/plugins/recentHelper.py b/usr/lib/linuxmint/mintMenu/plugins/recentHelper.py new file mode 100644 index 0000000..2ebf467 --- /dev/null +++ b/usr/lib/linuxmint/mintMenu/plugins/recentHelper.py @@ -0,0 +1,130 @@ +#!/usr/bin/python2 + +import gi +gi.require_version("Gtk", "3.0") + +import os +import string +from user import home +from easyfiles import * +from easybuttons import * + +recentApps = [] +mintMenuWin = None +recentAppBox = None +numentries = 10 +iconSize = 16 + +def recentAppsAdd( recentAppsButton ): + if recentAppsButton: + + recentApps.insert(0, recentAppsButton ) + + counter = 0 + for recentApp in recentApps: + if counter != 0 and ( recentApp.desktopFile == recentAppsButton.desktopFile or counter >= numentries ): + del recentApps[counter] + counter = counter + 1 + +def recentAppsSave(): + try: + if (not os.path.exists(home + "/.linuxmint/mintMenu/recentApplications.list")): + os.system("touch " + home + "/.linuxmint/mintMenu/recentApplications.list") + recentAppListFile = open( os.path.join( os.path.expanduser( "~"), ".linuxmint", "mintMenu", "recentApplications.list" ) , "w" ) + + for recentApp in recentApps: + if not hasattr(recentApp, "type") or recentApp.type == "location": + recentAppListFile.write( "location:" + recentApp.desktopFile + "\n" ) + else: + recentAppListFile.write( recentApp.type + "\n" ) + + recentAppListFile.close( ) + except Exception, e: + print e + msgDlg = Gtk.MessageDialog( None, gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _("Couldn't save recent apps. Check if you have write access to ~/.linuxmint/mintMenu")+"\n(" + e.__str__() + ")" ) + msgDlg.run(); + msgDlg.destroy(); + +def recentAppBuildLauncher( location ): + try: + ButtonIcon = None + # For Folders and Network Shares + location = string.join( location.split( "%20" ) ) + + if location.startswith( "file" ): + ButtonIcon = "mate-fs-directory" + + if location.startswith( "smb" ) or location.startswith( "ssh" ) or location.startswith( "network" ): + ButtonIcon = "mate-fs-network" + + #For Special locations + if location == "x-nautilus-desktop:///computer": + location = "/usr/share/applications/nautilus-computer.desktop" + elif location == "x-nautilus-desktop:///home": + location = "/usr/share/applications/nautilus-home.desktop" + elif location == "x-nautilus-desktop:///network": + location = "/usr/share/applications/network-scheme.desktop" + elif location.startswith( "x-nautilus-desktop:///" ): + location = "/usr/share/applications/nautilus-computer.desktop" + + if location.startswith( "file://" ): + location = location[7:] + appButton = ApplicationLauncher( location, iconSize) + + if appButton.appExec: + appButton.show() + appButton.connect( "clicked", applicationButtonClicked ) + appButton.type = "location" + return appButton + except Exception, e: + print u"File in recentapp not found: '" + location + "'", e + + return None + + +def buildRecentApps(): + del recentApps[:] + try: + if (not os.path.exists(home + "/.linuxmint/mintMenu/recentApplications.list")): + os.system("touch " + home + "/.linuxmint/mintMenu/recentApplications.list") + recentAppListFile = open( os.path.join( os.path.expanduser( "~"), ".linuxmint", "mintMenu", "recentApplications.list" ) , "r" ) + + recentApplicationsList = recentAppListFile.readlines() + + for app in recentApplicationsList : + app = app.strip() + + if app[0:9] == "location:": + appButton = recentAppBuildLauncher( app[9:] ) + else: + if ( app.endswith( ".desktop" ) ): + appButton = recentAppBuildLauncher( app ) + else: + appButton = None + + if appButton: + recentApps.append( appButton ) + except Exception, e: + print e + return recentApps + +def doRecentApps(): + for i in recentAppBox.get_children(): + i.destroy() + + # recent apps + buildRecentApps() + for AButton in recentApps: + + AButton.set_size_request( 200, -1 ) + AButton.set_relief( Gtk.ReliefStyle.NONE ) + + recentAppBox.pack_start( AButton, False, True, 0 ) + + return True + +def applicationButtonClicked( widget ): + mintMenuWin.hide() + recentAppsAdd(widget) + recentAppsSave() + doRecentApps() diff --git a/usr/share/glib-2.0/schemas/com.linuxmint.mintmenu.gschema.xml b/usr/share/glib-2.0/schemas/com.linuxmint.mintmenu.gschema.xml index 2620b92..8bd4c32 100644 --- a/usr/share/glib-2.0/schemas/com.linuxmint.mintmenu.gschema.xml +++ b/usr/share/glib-2.0/schemas/com.linuxmint.mintmenu.gschema.xml @@ -417,7 +417,7 @@ - 10 + 20