Repository: spyder-ide/spyder

Issue:
Add "Copy absolute/relative path" actions to the editor
When you do right click on a tab in the editor, you get the following menu

![Selección_039](https://user-images.githubusercontent.com/365293/69462451-01aa5280-0d47-11ea-9216-1136fa47e6fc.png)

What I'd like to see on it are the same options present in Files called "Copy Absolute/Relative Path"

![Selección_038](https://user-images.githubusercontent.com/365293/69471462-2f09f700-0d6d-11ea-9c0d-d57f93384a0a.png)

As you can see in the editor menu, there's already an option called "Copy path to clipboard". That's the same as "Copy Absolute Path", so @juanis2112, you just need to rename it and remove the icon associated with it. And below it please add "Copy Relatve Path".


Discussion:
Also, please add the same keyboard shortcuts present in Files to those actions in the editor.

Resolving patch:
diff --git a/spyder/plugins/editor/widgets/editorstack/editorstack.py b/spyder/plugins/editor/widgets/editorstack/editorstack.py
--- a/spyder/plugins/editor/widgets/editorstack/editorstack.py
+++ b/spyder/plugins/editor/widgets/editorstack/editorstack.py
@@ -48,6 +48,7 @@
 from spyder.py3compat import to_text_string
 from spyder.utils import encoding, sourcecode, syntaxhighlighters
 from spyder.utils.icon_manager import ima
+from spyder.utils.misc import getcwd_or_home
 from spyder.utils.palette import QStylePalette
 from spyder.utils.qthelpers import (add_actions, create_action,
                                     create_toolbutton, MENU_SEPARATOR,
@@ -204,12 +205,18 @@ def __init__(self, parent, actions, use_switcher=True):
 
         self.data = []
 
-        copy_to_cb_action = create_action(
+        copy_absolute_path_action = create_action(
             self,
-            _("Copy path to clipboard"),
+            _("Copy absolute path"),
+            icon=ima.icon('editcopy'),
+            triggered=lambda: self.copy_absolute_path()
+        )
+        copy_relative_path_action = create_action(
+            self,
+            _("Copy relative path"),
             icon=ima.icon('editcopy'),
             triggered=lambda:
-                QApplication.clipboard().setText(self.get_current_filename())
+            self.copy_relative_path()
         )
         close_right = create_action(self, _("Close all to the right"),
                                     triggered=self.close_all_right)
@@ -233,7 +240,9 @@ def __init__(self, parent, actions, use_switcher=True):
         self.menu_actions = actions + [external_fileexp_action,
                                        None, switcher_action,
                                        symbolfinder_action,
-                                       copy_to_cb_action, None, close_right,
+                                       copy_absolute_path_action,
+                                       copy_relative_path_action, None,
+                                       close_right,
                                        close_all_but_this, sort_tabs]
         self.outlineexplorer = None
         self.is_closable = False
@@ -343,6 +352,36 @@ def show_in_external_file_explorer(self, fnames=None):
                 QMessageBox.information(self, msg_title, msg,
                                         QMessageBox.Ok)
 
+    def copy_absolute_path(self):
+        """Copy current filename absolute path to the clipboard."""
+        QApplication.clipboard().setText(self.get_current_filename())
+
+    def copy_relative_path(self):
+        """Copy current filename relative path to the clipboard."""
+        file_drive = osp.splitdrive(self.get_current_filename())[0]
+        if (
+            os.name == 'nt'
+            and osp.splitdrive(getcwd_or_home())[0] != file_drive
+        ):
+            QMessageBox.warning(
+               self,
+               _("No available relative path"),
+               _("It is not possible to copy a relative path "
+                 "for this file because it is placed in a "
+                 "different drive than your current working "
+                 "directory. Please copy its absolute path.")
+            )
+        else:
+            base_path = getcwd_or_home()
+            if self.get_current_project_path():
+                base_path = self.get_current_project_path()
+
+            rel_path = osp.relpath(
+                self.get_current_filename(), base_path
+            ).replace(os.sep, "/")
+
+            QApplication.clipboard().setText(rel_path)
+
     def create_shortcuts(self):
         """Create local shortcuts"""
         # --- Configurable shortcuts
@@ -1295,6 +1334,12 @@ def get_current_language(self):
         if self.data:
             return self.data[self.get_stack_index()].editor.language
 
+    def get_current_project_path(self):
+        if self.data:
+            finfo = self.get_current_finfo()
+            if finfo:
+                return finfo.editor.current_project_path
+
     def get_filenames(self):
         """
         Return a list with the names of all the files currently opened in


Test patch: