示例#1
0
    def OnCopyTabPath(self, evt):
        """Copy the path of the selected tab to the clipboard.
        @param evt: wxMenuEvent

        """
        if evt.GetId() == ed_glob.ID_COPY_PATH:
            path = self.control.GetFileName()
            if path is not None:
                util.SetClipboardText(path)
        else:
            evt.Skip()
示例#2
0
 def OnCopyModulePath(self, editor, evt):
     path = os.path.normcase(editor.GetFileName())
     if path is not None:
         childPath, foo = PyStudioUtils.get_packageroot(path)
         modulepath = PyStudioUtils.get_modulepath(childPath)
         util.SetClipboardText(modulepath)
    def OnMenu(self, evt):
        """Handle menu events"""
        e_id = evt.GetId()
        sel = self._list.GetFirstSelected()
        path = None
        item = None
        if sel > -1 and sel < len(self._files):
            item = self._files[sel]
            path = item['name']

        if e_id == ID_EDIT:
            # Open the selected file in the editor
            if path is not None:
                self.OpenFile(path)

        elif e_id == ID_RENAME:
            # Rename the selected file
            if path is not None:
                name = wx.GetTextFromUser(_("Enter the new name"),
                                          _("Rename File"))
                if len(name):
                    self._select = name
                    self._StartBusy(True)
                    self._client.RenameAsync(path, name)

        elif e_id == ID_DELETE:
            # Remove the selected path
            # TODO: add support for removing directories
            if path is not None:
                result = wx.MessageBox(
                    _("Are you sure you want to delete %s?") % path,
                    _("Delete File?"),
                    style=wx.YES_NO | wx.CENTER | wx.ICON_WARNING)

                if result == wx.YES:
                    self._client.DeleteFileAsync(path)

        elif e_id == ID_REFRESH:
            # Refresh the file list
            self._select = path
            self.RefreshFiles()

        elif e_id in (ID_NEW_FILE, ID_NEW_FOLDER):
            #            if item is not None:
            # TODO: change to create the new file/folder in the subdirectory
            #       when the selected item is a directory.
            #                if item['isdir']:
            #                    pass
            #                else:
            #                    pass

            # Prompt for the new name
            if e_id == ID_NEW_FILE:
                name = wx.GetTextFromUser(_("Enter name for new file."),
                                          _("New File"))

                # Check if the file already exists
                found = self._list.FindItem(-1, name)
                if found == wx.NOT_FOUND and len(name):
                    self._select = name
                    self._client.NewFileAsync(name)
            else:
                name = wx.GetTextFromUser(_("Enter name for new directory."),
                                          _("New Directory"))

                # Check if the file already exists
                found = self._list.FindItem(-1, name)
                if found == wx.NOT_FOUND and len(name):
                    self._select = name
                    self._client.NewDirAsync(name)

            if found != wx.NOT_FOUND and len(name):
                wx.MessageBox(
                    _("%s already exists. Please enter a different name." %
                      name),
                    _("%s already exists" % name),
                    style=wx.OK | wx.CENTER | wx.ICON_WARNING)

        elif e_id == ID_COPY_URL:
            # Copy the url of the selected file to the clipboard
            url = u"/".join([
                u"ftp:/",
                self._client.GetHostname().lstrip(u"/"),
                self._client.GetCurrentDirectory().lstrip(u"/"),
                path.lstrip(u"/")
            ])
            util.SetClipboardText(url)

        # TODO: add general upload and download functionality
        elif e_id == ID_DOWNLOAD:
            pass

        elif e_id == ID_UPLOAD:
            pass

        else:
            evt.Skip()