From f3403d72a9cc5019af259e265b6d295fe81ad5b4 Mon Sep 17 00:00:00 2001 From: Peter Lind Date: Wed, 13 Aug 2014 18:52:59 +0200 Subject: [PATCH] Improved code for cycling through profiles --- terminatorlib/terminal.py | 42 +++++++++++---------------------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 012c9ebb..6b57fc63 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -198,41 +198,23 @@ class Terminal(gtk.VBox): def switch_to_next_profile(self): profilelist = self.config.list_profiles() + list_length = len(profilelist) - if len(profilelist) > 1: - next = False - first = False - - for profile in profilelist: - if first == False: - first = profile - - if next: - self.force_set_profile(False, profile) - return - - if profile == self.get_profile(): - next = True - - if first: - self.force_set_profile(False, first) + if list_length > 1: + if profilelist.index(self.get_profile()) + 1 == list_length: + self.force_set_profile(False, profilelist[0]) + else: + self.force_set_profile(False, profilelist[profilelist.index(self.get_profile()) + 1]) def switch_to_previous_profile(self): profilelist = self.config.list_profiles() + list_length = len(profilelist) - if len(profilelist) > 1: - last = False - - for profile in profilelist: - if profile == self.get_profile(): - if last: - self.force_set_profile(False, last) - return - - last = profile - - if last: - self.force_set_profile(False, last) + if list_length > 1: + if profilelist.index(self.get_profile()) == 0: + self.force_set_profile(False, profilelist[list_length - 1]) + else: + self.force_set_profile(False, profilelist[profilelist.index(self.get_profile()) - 1]) def get_cwd(self): """Return our cwd"""