コード例 #1
0
ファイル: Desktop.cpp プロジェクト: GustavoMOG/ede
bool Desktop::rename_icon(DesktopIcon *di, const char *name) {
	di->copy_label(name);
	di->update_label_font_and_size();
	di->fast_redraw();
	
	/* open file and try to change the name */
	DesktopFile df;
	E_RETURN_VAL_IF_FAIL(df.load(di->get_path()) == true, false);
	
	df.set_name(name);
	return df.save(di->get_path());
}
コード例 #2
0
ファイル: IconDialog.cpp プロジェクト: GustavoMOG/ede
static void ok_cb(Fl_Widget*, void *d) {
	if(is_empty_input(name) || is_empty_input(execute) || !img->image()) {
		/* do nothing */
		win->hide();
		return;
	}
	
	Desktop *self = (Desktop*)d;
	
	DesktopFile df;
	df.create_new(DESK_FILE_TYPE_APPLICATION);
	df.set_name(name->value());

	if(comment->value())
		df.set_comment(comment->value());

	df.set_icon((img_path.length() > 1) ? img_path.c_str() : DEFAULT_ICON);
	df.set_exec(execute->value());
	
	if(!is_empty_input(workdir))
		df.set_path(workdir->value());
	
	df.set_startup_notify(start_notify->value());
	df.set_terminal(run_in_terminal->value());

	/* determine filename and save it */
	String file = name->value();
	const char *fp = file.c_str();

	str_tolower((unsigned char*)fp);
	file += EDE_DESKTOP_DESKTOP_EXT;

	/* go through the file and replace spaces with '_' */
	for(String::size_type i = 0; i < file.length(); i++)
		if(isspace(file[i])) file[i] = '_';

	String path = build_filename(self->desktop_path(), file.c_str());
	
	int  X = 0, Y = 0;
	if(curr_icon) {
		X = curr_icon->x();
		Y = curr_icon->y();
		/* try to remove icon from filesystem only when we can't overwrite old icon path */
		self->remove_icon(curr_icon, old_desktop_path != path);
	}

	if(df.save(path.c_str())) {
		DesktopIcon *ic = self->read_desktop_file(path.c_str(), file.c_str());
		if(ic) {
			if(X > 0 || Y > 0) ic->position(X, Y);
			self->add(ic);
		}

		self->redraw();
		
		/* 
		 * In case when we rename icon, icon position will not be saved (because they are saved by icon basename). So
		 * with different paths we are assured the name was changed and we proceed further.
		 */
		if(old_desktop_path != path) self->save_icons_positions();
	} else {
		alert(_("Unable to create '%s' file. Received error is: %s\n"), path.c_str(), df.strerror());
	}

	win->hide();
}