Arrange icons if file with icon position wasn't found

This commit is contained in:
Sanel Zukan 2009-10-07 14:38:48 +00:00
parent 235cd14b02
commit e6104ff470
2 changed files with 28 additions and 1 deletions

View File

@ -344,7 +344,7 @@ void Desktop::load_icons(const char* path) {
edelib::Resource conf, *conf_ptr = NULL; edelib::Resource conf, *conf_ptr = NULL;
if(!conf.load(ICONS_CONFIG_NAME)) if(!conf.load(ICONS_CONFIG_NAME))
E_WARNING(E_STRLOC ": Can't load icons positions from %s, randomizing them...\n", ICONS_CONFIG_NAME); E_WARNING(E_STRLOC ": Can't load icons positions; arranging them somehow...\n");
else else
conf_ptr = &conf; conf_ptr = &conf;
@ -359,6 +359,10 @@ void Desktop::load_icons(const char* path) {
StringListIter it, it_end; StringListIter it, it_end;
for(it = lst.begin(), it_end = lst.end(); it != it_end; ++it) for(it = lst.begin(), it_end = lst.end(); it != it_end; ++it)
add_icon_by_path((*it).c_str(), conf_ptr); add_icon_by_path((*it).c_str(), conf_ptr);
/* if stored locations wasn't found */
if(!conf_ptr)
auto_arrange();
} }
void Desktop::save_icons_positions(void) { void Desktop::save_icons_positions(void) {
@ -536,6 +540,27 @@ bool Desktop::remove_icon_by_path(const char* path) {
return true; return true;
} }
void Desktop::auto_arrange(void) {
DesktopIcon* ic;
DesktopIconListIter it, it_end;
int X = (gisett->label_maxwidth / 5) + 10;
int Y = 10;
int H = h();
for(it = icons.begin(), it_end = icons.end(); it != it_end; ++it) {
ic = (*it);
ic->position(X, Y);
Y += ic->h() + (ic->h() / 2);
if(Y + (ic->h() / 2) > H) {
Y = 10;
X += gisett->label_maxwidth + (ic->w() / 2);
}
}
}
void Desktop::update_trash_icons(void) { void Desktop::update_trash_icons(void) {
bool is_empty = edelib::dir_empty(trash_path.c_str()); bool is_empty = edelib::dir_empty(trash_path.c_str());
DesktopIconListIter it = icons.begin(), it_end = icons.end(); DesktopIconListIter it = icons.begin(), it_end = icons.end();

View File

@ -125,6 +125,8 @@ private:
DesktopIcon* find_icon_by_path(const char* path, DesktopIconListIter* pos); DesktopIcon* find_icon_by_path(const char* path, DesktopIconListIter* pos);
bool remove_icon_by_path(const char* path); bool remove_icon_by_path(const char* path);
void auto_arrange(void);
void update_trash_icons(void); void update_trash_icons(void);
void unfocus_all(void); void unfocus_all(void);