Changeset 1443
- Timestamp:
- 07/01/08 21:49:54 (5 months ago)
- Location:
- trunk/peppy
- Files:
-
- 3 modified
-
buffers.py (modified) (1 diff)
-
mainmenu.py (modified) (1 diff)
-
plugins/project.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/peppy/buffers.py
r1413 r1443 348 348 self.viewers.append(mode) # keep track of views 349 349 assert self.dprint("views of %s: %s" % (self,self.viewers)) 350 351 def iterViewers(self): 352 """Return an iterator over all the views of this buffer""" 353 for view in self.viewers: 354 yield view 350 355 351 356 def forEachView(self, func_name): -
trunk/peppy/mainmenu.py
r1427 r1443 64 64 tooltip = "New plain text file" 65 65 icon = "icons/page_white_text_new.png" 66 default_menu = ("File/New", - 2)66 default_menu = ("File/New", -99) 67 67 key_bindings = {'win': "C-N", 'mac': "C-N"} 68 68 -
trunk/peppy/plugins/project.py
r1442 r1443 17 17 import peppy.vfs as vfs 18 18 19 from peppy.buffers import * 19 20 from peppy.yapsy.plugins import * 20 21 from peppy.actions import * … … 49 50 wildcards = self.ctags_exclude.split() 50 51 excludes = " ".join(["--exclude=%s" % w for w in wildcards]) 51 args = "-o %s %s %s %s" % (ctags_file, ProjectPlugin.classprefs.ctags_args, self.ctags_extra_args, excludes) 52 53 # Put the output file last in this list because extra spaces at the end 54 # don't get squashed like they do from the shell. Ctags will actually 55 # try to look for a filename called " ", which fails. 56 args = "%s %s %s -o %s" % (ProjectPlugin.classprefs.ctags_args, self.ctags_extra_args, excludes, ctags_file) 52 57 cmd = "%s %s" % (ProjectPlugin.classprefs.ctags_command, args) 53 58 dprint(cmd) … … 86 91 else: 87 92 self.dprint(line) 88 except Exception, e:89 raise90 dprint(self.tags.keys())93 except LookupError, e: 94 dprint("Tag file %s not found" % filename) 95 pass 91 96 92 97 def getTag(self, tag): … … 96 101 class ProjectInfo(CTAGS): 97 102 default_prefs = ( 103 StrParam('project_name', '', 'Project name'), 98 104 DirParam('build_dir', '', 'working directory in which to build', fullwidth=True), 99 105 StrParam('build_command', '', 'shell command to build project, relative to working directory', fullwidth=True), … … 277 283 278 284 279 class ShowProjectSettings(SelectAction): 280 """Edit project settigns""" 285 286 class ProjectActionMixin(object): 287 def getProjectDir(self, cwd): 288 dlg = wx.DirDialog(self.frame, "Choose Top Level Directory", 289 defaultPath = cwd) 290 retval = dlg.ShowModal() 291 if retval == wx.ID_OK: 292 path = dlg.GetPath() 293 dprint(path) 294 info = ProjectPlugin.createProject(path) 295 else: 296 info = None 297 dlg.Destroy() 298 return info 299 300 def showProjectPreferences(self, info): 301 dlg = ProjectSettings(self.frame, info) 302 retval = dlg.ShowModal() 303 if retval == wx.ID_OK: 304 dlg.applyPreferences() 305 info.savePrefs() 306 307 def createProject(self): 308 cwd = self.frame.cwd() 309 info = self.getProjectDir(cwd) 310 if info: 311 self.showProjectPreferences(info) 312 info.regenerateTags() 313 314 315 class CreateProject(ProjectActionMixin, SelectAction): 316 """Create a new project""" 317 name = "Project..." 318 default_menu = ("File/New", 20) 319 320 def action(self, index=-1, multiplier=1): 321 self.createProject() 322 323 324 class CreateProjectFromExisting(ProjectActionMixin, SelectAction): 325 """Create a new project""" 326 name = "Project From Existing Code..." 327 default_menu = ("File/New", 21) 328 329 def action(self, index=-1, multiplier=1): 330 self.createProject() 331 332 class ShowProjectSettings(ProjectActionMixin, SelectAction): 333 """Edit project settings""" 281 334 name = "Project Settings..." 282 335 default_menu = ("Project", -990) … … 285 338 if self.mode.project_info: 286 339 info = self.mode.project_info 287 dlg = ProjectSettings(self.frame, info) 288 retval = dlg.ShowModal() 289 if retval == wx.ID_OK: 290 dlg.applyPreferences() 291 info.savePrefs() 340 self.showProjectPreferences(info) 292 341 293 342 … … 398 447 399 448 @classmethod 400 def registerProject(cls, mode): 401 url = cls.findProjectURL(mode.buffer.url) 449 def registerProject(cls, mode, url=None): 450 if url is None: 451 url = cls.findProjectURL(mode.buffer.url) 402 452 if url: 403 if str(url)not in cls.known_projects:453 if url not in cls.known_projects: 404 454 info = ProjectInfo(url) 405 cls.known_projects[ str(url)] = info455 cls.known_projects[url] = info 406 456 else: 407 info = cls.known_projects[str(url)] 408 mode.project_info = info 457 info = cls.known_projects[url] 458 if mode: 459 mode.project_info = info 409 460 dprint("found project %s" % info) 410 else: 461 return info 462 elif mode: 411 463 mode.project_info = None 412 464 … … 414 466 def getProjectInfo(cls, mode): 415 467 url = cls.findProjectURL(mode.buffer.url) 416 if url and str(url)in cls.known_projects:417 return cls.known_projects[ str(url)]468 if url and url in cls.known_projects: 469 return cls.known_projects[url] 418 470 return None 471 472 @classmethod 473 def createProject(cls, topdir): 474 url = vfs.normalize(topdir) 475 if url in cls.known_projects: 476 raise TypeError("Project already exists.") 477 proj_dir = url.resolve2(cls.classprefs.project_directory) 478 vfs.make_folder(proj_dir) 479 info = cls.registerProject(None, proj_dir) 480 info.savePrefs() 481 dprint(info) 482 buffers = BufferList.getBuffers() 483 for buffer in buffers: 484 if buffer.url.scheme != "file": 485 continue 486 dprint("prefix=%s topdir=%s" % (buffer.url.path.get_prefix(url.path), url.path)) 487 if buffer.url.path.get_prefix(url.path) == url.path: 488 dprint("belongs in project! %s" % buffer.url.path) 489 for mode in buffer.iterViewers(): 490 mode.project_info = info 491 else: 492 dprint("not in project: %s" % buffer.url.path) 493 return info 419 494 420 495 @classmethod … … 438 513 if mode.buffer.url in self.known_project_dirs: 439 514 actions.extend([SaveProjectTemplate, BuildProject, RunProject, RebuildCtags]) 440 actions. append(ShowProjectSettings)515 actions.extend([CreateProject, CreateProjectFromExisting, ShowProjectSettings]) 441 516 return actions 442 517
