From: <sv...@ww...> - 2008-01-31 07:44:25
|
Author: nsmoooose Date: 2008-01-30 23:44:18 -0800 (Wed, 30 Jan 2008) New Revision: 2212 Added: branches/layout_tool_improvements/csp/tools/layout2/scripts/ui/commands/FileCommandRegistry.py Modified: branches/layout_tool_improvements/csp/tools/layout2/scripts/ui/commands/OpenSelectedFileCommand.py Log: Added very basic file identification when you click on a file in the project tree. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=2212 Added: branches/layout_tool_improvements/csp/tools/layout2/scripts/ui/commands/FileCommandRegistry.py =================================================================== --- branches/layout_tool_improvements/csp/tools/layout2/scripts/ui/commands/FileCommandRegistry.py (rev 0) +++ branches/layout_tool_improvements/csp/tools/layout2/scripts/ui/commands/FileCommandRegistry.py 2008-01-31 07:44:18 UTC (rev 2212) @@ -0,0 +1,30 @@ +#!/usr/bin/env python +import os + +from OpenCustomLayoutModelFileCommand import OpenCustomLayoutModelFileCommand + +class FileCommandRegistry: + """This is responsible for knowing what Command to execute + on different files. It is also responsible for identification + of files in order to choose the correct Command.""" + + def GetCommandForFile(self, fileName): + """Returns a Command to use for the file. If no command + can be found for that file type we return None.""" + if os.path.isfile(fileName) == False: + return None + + # Get the file name extension in lowercase. + command = None + extension = os.path.splitext(fileName)[1].lower() + if extension == '.xml': + command = OpenCustomLayoutModelFileCommand() + + # If we have found a command we set the fileName on it + # and returns it. + if command is not None: + command.SetFileName(fileName) + return command + + return None + Modified: branches/layout_tool_improvements/csp/tools/layout2/scripts/ui/commands/OpenSelectedFileCommand.py =================================================================== --- branches/layout_tool_improvements/csp/tools/layout2/scripts/ui/commands/OpenSelectedFileCommand.py 2008-01-23 15:39:46 UTC (rev 2211) +++ branches/layout_tool_improvements/csp/tools/layout2/scripts/ui/commands/OpenSelectedFileCommand.py 2008-01-31 07:44:18 UTC (rev 2212) @@ -3,7 +3,7 @@ import wx from csp.tools.layout2.scripts.data import DataTree from csp.tools.layout2.scripts.ui.controls.ProjectTree import ProjectTree -from OpenCustomLayoutModelFileCommand import OpenCustomLayoutModelFileCommand +from FileCommandRegistry import FileCommandRegistry class OpenSelectedFileCommand: """Opens the selected file in the project tree of this @@ -21,10 +21,7 @@ return "document-open.png" def Execute(self): - """Load a feature group or feature model from the specified file. The existing - graph, if any, will be discarded. If file represents a feature model, a - default feature group is created at the root of the new graph. - """ + """Loads a document from the project tree.""" # Get the application object. This object is used to retreive the # configuration object and the top window for this application. @@ -44,8 +41,16 @@ if fileName is None: return - # Now it is time to identify the filetype of the selected file. - command = OpenCustomLayoutModelFileCommand() - command.SetFileName(fileName) - command.Execute() + # Now we have a file name and all apropriate data to identify + # the file selected. This is the responsibility of the + # FileCommandRegistry. Get a command and execute it. + fileRegistry = FileCommandRegistry() + command = fileRegistry.GetCommandForFile(fileName) + if command is not None: + command.Execute() + else: + messageDialog = wx.MessageDialog(topWindow, + 'Cannot find a FileCommand to execute on that file type.', + 'Error loading file', style = wx.OK|wx.ICON_ERROR) + messageDialog.ShowModal() |