about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/core/actions.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index d73270d5..ed3f7598 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -1066,6 +1066,48 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
             if not i in self.tabs:
                 return self.tab_open(i, path)
 
+    def tab_switch(self, path, create_directory=True):
+        """Switches to tab of given path, opening a new tab as necessary.
+
+        If path does not exist, it is treated as a directory.
+        """
+        if not os.path.exists(path):
+            file_selection = None
+            if create_directory:
+                try:
+                    os.makedirs(path, exist_ok=True)
+                except OSError as err:
+                    self.fm.notify(err, bad=True)
+                    return
+                target_directory = path
+            else:
+                # Give benefit of the doubt.
+                potential_parent = os.path.dirname(path)
+                if os.path.exists(potential_parent) and os.path.isdir(potential_parent):
+                    target_directory = potential_parent
+                else:
+                    self.fm.notify("Unable to resolve given path.", bad=True)
+                    return
+        elif os.path.isdir(path):
+            file_selection = None
+            target_directory = path
+        else:
+            file_selection = path
+            target_directory = os.path.dirname(path)
+
+        for name in self.fm.tabs:
+            tab = self.fm.tabs[name]
+            # Is a tab already open?
+            if tab.path == target_directory:
+                self.fm.tab_open(name=name)
+                if file_selection:
+                    self.fm.select_file(file_selection)
+                return
+
+        self.fm.tab_new(path=target_directory)
+        if file_selection:
+            self.fm.select_file(file_selection)
+
     def _get_tab_list(self):
         assert len(self.tabs) > 0, "There must be >=1 tabs at all times"
         return sorted(self.tabs)
00 committer Kartik K. Agaram <vc@akkartik.com> 2016-12-12 10:07:59 -0800 3707' href='/akkartik/mu/commit/vimrc.vim?h=main&id=49620728e805a3bbc3477c14b8b6ef7e2b5d3ead'>49620728 ^
b96af395 ^

94fa5c95 ^
9a81d746 ^
3e1349d2 ^




01ce563d ^

3e1349d2 ^
1ae4e0d9 ^
3e1349d2 ^




b3cdcdd4 ^
a9817844 ^



b96af395 ^






bc394aaf ^












1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66