def _rename_file(self): item = self.currentItem() if item.parent() is None: pathForFile = item.path else: pathForFile = os.path.join(item.path, item.text(0)) result = QInputDialog.getText(self, self.tr("Rename File"), self.tr("Enter New File Name:"), text=item.text(0)) fileName = result[0] if result[1] and fileName.strip() != '': fileName = os.path.join( file_manager.get_folder(pathForFile), fileName) if pathForFile == fileName: return try: fileName = file_manager.rename_file(pathForFile, fileName) name = file_manager.get_basename(fileName) mainContainer = main_container.MainContainer() if mainContainer.is_open(pathForFile): mainContainer.change_open_tab_name(pathForFile, fileName) subitem = ProjectItem(item.parent(), name, file_manager.get_folder(fileName)) subitem.setToolTip(0, name) subitem.setIcon(0, self._get_file_icon(name)) index = item.parent().indexOfChild(item) subitem.parent().takeChild(index) except file_manager.NinjaFileExistsException as ex: QMessageBox.information(self, self.tr("File Already Exists"), self.tr("Invalid Path: the file '%s' already exists." % ex.filename))
def _rename_file(self): item = self.currentItem() if item.parent() is None: pathForFile = item.path else: pathForFile = os.path.join(item.path, item.text(0)) result = QInputDialog.getText(self, self.tr("Rename File"), self.tr("Enter New File Name:"), text=item.text(0)) fileName = result[0] if result[1] and fileName.strip() != '': fileName = os.path.join(file_manager.get_folder(pathForFile), fileName) if pathForFile == fileName: return try: fileName = file_manager.rename_file(pathForFile, fileName) name = file_manager.get_basename(fileName) mainContainer = main_container.MainContainer() if mainContainer.is_open(pathForFile): mainContainer.change_open_tab_name(pathForFile, fileName) subitem = ProjectItem(item.parent(), name, file_manager.get_folder(fileName)) subitem.setToolTip(0, name) subitem.setIcon(0, self._get_file_icon(name)) index = item.parent().indexOfChild(item) subitem.parent().takeChild(index) except file_manager.NinjaFileExistsException as ex: QMessageBox.information( self, self.tr("File Already Exists"), self.tr("Invalid Path: the file '%s' already exists." % ex.filename))