diff options
Diffstat (limited to 'src/frontEnd/ProjectExplorer.py')
-rw-r--r-- | src/frontEnd/ProjectExplorer.py | 143 |
1 files changed, 98 insertions, 45 deletions
diff --git a/src/frontEnd/ProjectExplorer.py b/src/frontEnd/ProjectExplorer.py index 638b3147..dfe68e58 100644 --- a/src/frontEnd/ProjectExplorer.py +++ b/src/frontEnd/ProjectExplorer.py @@ -2,6 +2,8 @@ from PyQt4 import QtGui, QtCore import os import json from configuration.Appconfig import Appconfig +from projManagement.newProject import NewProjectInfo +from projManagement.Validation import Validation # This is main class for Project Explorer Area. @@ -25,6 +27,7 @@ class ProjectExplorer(QtGui.QWidget): """ QtGui.QWidget.__init__(self) self.obj_appconfig = Appconfig() + self.obj_validation = Validation() self.treewidget = QtGui.QTreeWidget() self.window = QtGui.QVBoxLayout() header = QtGui.QTreeWidgetItem(["Projects", "path"]) @@ -226,51 +229,101 @@ class ProjectExplorer(QtGui.QWidget): json.dump(self.obj_appconfig.project_explorer, open(self.obj_appconfig.dictPath, 'w')) - '''def renameProject(self): - indexItem = self.treewidget.currentIndex() - baseFileName = str(indexItem.data()) - newBaseFileName, ok = QtGui.QInputDialog.getText( - self, 'Rename Project', 'Project Name:', - QtGui.QLineEdit.Normal, baseFileName - ) - if ok and newBaseFileName: - newBaseFileName = str(newBaseFileName) - projectPath, projectFiles = list( - self.obj_appconfig.project_explorer.items())[indexItem.row()] - updatedProjectFiles = [] + #""" + def renameProject(self): + """ + This function renames the project present in project explorer area + it validates first: - # rename files matching project name - for projectFile in projectFiles: - if baseFileName in projectFile: - oldFilePath = os.path.join(projectPath, projectFile) - projectFile = projectFile.replace( - baseFileName, newBaseFileName, 1) - newFilePath = os.path.join(projectPath, projectFile) - print ("Renaming " + oldFilePath + " to " + newFilePath) - os.rename(oldFilePath, newFilePath) - - updatedProjectFiles.append(projectFile) - - # rename project folder - updatedProjectPath = newBaseFileName.join( - projectPath.rsplit(baseFileName, 1)) - print ("Renaming " + projectPath + " to " + updatedProjectPath) - os.rename(projectPath, updatedProjectPath) - - # update project_explorer dictionary - del self.obj_appconfig.project_explorer[projectPath] - self.obj_appconfig.project_explorer[updatedProjectPath] = ( - updatedProjectFiles - ) + - If project names is not empty. + - Project name does not contain spaces between them. + - Project name is different between what it was earlier. + - Project name should not exist. + + And after project name is changed it recreates the project explorer tree. + """ + self.indexItem = self.treewidget.currentIndex() + self.baseFileName = str(self.indexItem.data()) + self.newBaseFileName, ok = QtGui.QInputDialog.getText(self, 'Rename Project', 'Project Name:', + QtGui.QLineEdit.Normal, self.baseFileName) + if ok and self.newBaseFileName: + print("=================") + print(self.newBaseFileName) + print("=================") + self.newBaseFileName = str(self.newBaseFileName) + projectPath, projectFiles = list(self.obj_appconfig.project_explorer.items())[self.indexItem.row()] + updatedProjectFiles = [] - # save project_explorer dictionary on disk - json.dump(self.obj_appconfig.project_explorer, - open(self.obj_appconfig.dictPath, 'w')) + self.workspace = self.obj_appconfig.default_workspace['workspace'] + self.newBaseFileName = str(self.newBaseFileName).rstrip().lstrip() + self.projDir = os.path.join(self.workspace, str(self.newBaseFileName)) + + if self.newBaseFileName == "": + print("Project name can not be empty") + print("==================") + msg = QtGui.QErrorMessage(self) + msg.showMessage('The project name cannot be empty') + msg.setWindowTitle("Error Message") + + elif self.baseFileName == self.newBaseFileName: + print("Project name has to be different") + print("==================") + msg = QtGui.QErrorMessage(self) + msg.showMessage('The project name has to be different') + msg.setWindowTitle("Error Message") + + else: + self.reply = self.obj_validation.validateNewproj(str(self.projDir)) + print(self.reply) + print("==================") - # recreate project explorer tree - self.treewidget.clear() - for parent, children in ( - self.obj_appconfig.project_explorer.items() - ): - self.addTreeNode(parent, children) - ''' + # rename files matching project name + if self.reply == "VALID": + for projectFile in projectFiles: + if self.baseFileName in projectFile: + oldFilePath = os.path.join(projectPath, projectFile) + projectFile = projectFile.replace(self.baseFileName, self.newBaseFileName, 1) + newFilePath = os.path.join(projectPath, projectFile) + print(oldFilePath) + print("==================") + print(newFilePath) + print("==================") + print ("Renaming " + oldFilePath + " to " + newFilePath) + #os.rename(oldFilePath, newFilePath) + updatedProjectFiles.append(projectFile) + + # rename project folder + updatedProjectPath = self.newBaseFileName.join(projectPath.rsplit(self.baseFileName, 1)) + print ("Renaming " + projectPath + " to " + updatedProjectPath) + os.rename(projectPath, updatedProjectPath) + + # update project_explorer dictionary + del self.obj_appconfig.project_explorer[projectPath] + self.obj_appconfig.project_explorer[updatedProjectPath] = updatedProjectFiles + + # save project_explorer dictionary on disk + json.dump(self.obj_appconfig.project_explorer, open(self.obj_appconfig.dictPath,'w')) + + # recreate project explorer tree + self.treewidget.clear() + for parent, children in self.obj_appconfig.project_explorer.items(): + self.addTreeNode(parent, children) + + elif self.reply == "CHECKEXIST": + print("Project name already exists.") + print("==========================") + msg = QtGui.QErrorMessage(self) + msg.showMessage( + 'The project "' + + self.newBaseFileName + + '" already exist.Please select the different name or' + + ' delete existing project') + msg.setWindowTitle("Error Message") + + elif self.reply == "CHECKNAME": + print("Name can not contain space between them") + print("===========================") + msg = QtGui.QErrorMessage(self) + msg.showMessage( + 'The project name should not contain space between them') + msg.setWindowTitle("Error Message") |