示例#1
0
文件: file.c 项目: 8l/aoeui
Boolean_t text_rename(struct text *text, const char *path0)
{
	char *path = fix_path(path0);
	struct text *b;
	struct view *view;
	fd_t fd;

	if (!path)
		return FALSE;
	for (b = text; b; b = b->next)
		if (b->path && !strcmp(b->path, path))
			return FALSE;

	errno = 0;
	if ((fd = open(path, O_CREAT|O_RDWR,
			S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) {
		message("%s: can't create", path_format(path));
		RELEASE(path);
		return FALSE;
	}

	if (text->flags & TEXT_CREATED) {
		unlink(text->path);
		text->flags &= ~(TEXT_CREATED | TEXT_SCRATCH);
	}

	/* Do not truncate or overwrite yet. */
	text->flags |= TEXT_SAVED_ORIGINAL;
	text->flags &= ~TEXT_RDONLY;
	text_dirty(text);
	close(text->fd);
	if (text->clean) {
		munmap(text->clean, text->clean_bytes);
		text->clean = NULL;
	}
	text->fd = fd;
	grab_mtime(text);
	RELEASE(text->path);
	text->path = path;
	keyword_init(text);
	for (view = text->views; view; view = view->next)
		view_name(view);
	return TRUE;
}
示例#2
0
void GsTL_project::add_view( const std::string& view_type ) {
  // go to manager of project-views and get a new view

  // get project name
  SmartPtr<Named_interface> dir_ni =
      Root::instance()->interface( projects_manager );
  Manager* dir = dynamic_cast<Manager*>( dir_ni.raw_ptr() );
  appli_assert( dir );
  std::string proj_name = dir->name( (Named_interface*) this );

  // name of the new view: proj_view_2 where "proj" is the name of the project,
  // and suffix 2 is deduced from the number of views currently registered
  std::string view_name( projectViews_manager + "/" + proj_name + "_view_" );
  view_name += String_Op::to_string( views_list_.size() );

  SmartPtr<Named_interface> ni = 
      Root::instance()->new_interface( view_type, view_name );

  Project_view* view = dynamic_cast<Project_view*>( ni.raw_ptr() ); 
  appli_assert( view );
  view->init( this );

  views_list_.push_back( view );
}