예제 #1
0
void TDirListBox::newDirectory( const char *str )
{
    strcpy( dir, str );
    TDirCollection *dirs = new TDirCollection( 5, 5 );
    dirs->insert( new TDirEntry( drives, drives ) );
    if( strcmp( dir, drives ) == 0 )
        showDrives( dirs );
    else
        showDirs( dirs );
    newList( dirs );
    focusItem( cur );
}
예제 #2
0
void gBrowser::up_dir() {

	/* updir = remove last folder from the path. Start from strlen(-1) to
	 * skip the trailing slash */

	int i = strlen(path_obj->value())-1;

	/* on Windows an updir from the path "X:\" (3 chars long) must redirect
	 * to the list of available devices. */

#if defined(_WIN32)
	if (i <= 3 || !strcmp(path_obj->value(), "All drives")) {
		path_obj->value("All drives");
		showDrives();
		return;
	}
	else {
		while (i >= 0) {
			if (path_obj->value()[i] == '\\')
				break;
			i--;
		}

		/* delete the last part of the string, from i to len-i, ie everything
		 * after the "/" */

		std::string tmp = path_obj->value();
		tmp.erase(i, tmp.size()-i);

		/* if tmp.size == 2 we have something like 'C:'. Add a trailing
		 * slash */

		if (tmp.size() == 2)
			tmp += "\\";

		path_obj->value(tmp.c_str());
		refresh();
	}
#elif defined(__linux__) || defined (__APPLE__)
	while (i >= 0) {
		if (path_obj->value()[i] == '/')
			break;
		i--;
	}

	/* i == 0 means '/', the root dir. It's meaningless to go updir */

	if (i==0)
		path_obj->value("/");
	else {

		/* delete the last part of the string, from i to len-i, ie everything
		 * after the "/" */

		std::string tmp = path_obj->value();
		tmp.erase(i, tmp.size()-i);
		path_obj->value(tmp.c_str());
	}
	refresh();
#endif
}