void XFE_ABDirListView::propertyCB(DIR_Server *dir) { int which = XP_ListGetNumFromObject(m_directories, dir); #if defined(DEBUG_tao) printf("\nXFE_ABDirListView::propertyCB=%d\n", which); #endif if (!which) { /* new */ const int *selected; int count; m_outliner->getSelection(&selected, &count); int pos = 0; if (m_nDirs > 0 && count && selected) { // Insert dir at position pos = selected[0]; DIR_Server *prev_dir; prev_dir = (DIR_Server*)XP_ListGetObjectNum(m_directories, pos+1); XP_ListInsertObjectAfter(m_directories, prev_dir, dir); pos = pos+1; } else { XP_ListAddObjectToEnd(m_directories, dir); pos = m_nDirs+1; } // Repaint m_nDirs = XP_ListCount(m_directories); m_outliner->change(0, m_nDirs, m_nDirs); // Set selection m_outliner->selectItemExclusive(pos); notifyInterested(XFE_ABDirListView::dirSelect, (void *) dir); }/* if */ else m_outliner->invalidateLine(which); DIR_SaveServerPreferences(m_directories); if (m_deleted_directories) { DIR_CleanUpServerPreferences(m_deleted_directories); m_deleted_directories = NULL; }/* if */ getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating); }
/* Function for setting the position of a server. Can be used to append, * delete, or move a server in a server list. * * The third parameter specifies the new position the server is to occupy. * The resulting position may differ depending on the lock state of the * given server and other servers in the list. The following special values * are supported: * DIR_POS_APPEND - Appends the server to the end of the list. If the server * is already in the list, does nothing. * DIR_POS_DELETE - Deletes the given server from the list. Note that this * does not cause the server structure to be freed. * * Returns PR_TRUE if the server list was re-sorted. */ static PRBool DIR_SetServerPosition(nsVoidArray *wholeList, DIR_Server *server, PRInt32 position) { NS_ENSURE_ARG_POINTER(wholeList); PRInt32 i, count, num; PRBool resort = PR_FALSE; DIR_Server *s=nsnull; switch (position) { case DIR_POS_APPEND: /* Do nothing if the request is to append a server that is already * in the list. */ count = wholeList->Count(); for (i= 0; i < count; i++) { if ((s = (DIR_Server *)wholeList->ElementAt(i)) != nsnull) if (s == server) return PR_FALSE; } /* In general, if there are any servers already in the list, set the * position to the position of the last server plus one. If there * are none, set it to position 1. */ if (count > 0) { s = (DIR_Server *)wholeList->ElementAt(count - 1); server->position = s->position + 1; } else server->position = 1; wholeList->AppendElement(server); break; case DIR_POS_DELETE: /* Remove the prefs corresponding to the given server. If the prefName * value is nsnull, the server has never been saved and there are no * prefs to remove. */ if (server->prefName) { nsresult rv; nsCOMPtr<nsIPrefBranch> pPref(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return PR_FALSE; pPref->DeleteBranch(server->prefName); // mark the server as deleted by setting its position to 0 DIR_SetIntPref(server->prefName, "position", 0, -1); } /* If the server is in the server list, remove it. */ num = wholeList->IndexOf(server); if (num >= 0) { /* The list does not need to be re-sorted if the server is the * last one in the list. */ count = wholeList->Count(); if (num == count - 1) { wholeList->RemoveElementAt(num); } else { resort = PR_TRUE; wholeList->RemoveElement(server); } } break; default: /* See if the server is already in the list. */ count = wholeList->Count(); for (i= 0; i < count; i++) { if ((s = (DIR_Server *)wholeList->ElementAt(i)) != nsnull) if (s == server) break; } /* If the server is not in the list, add it to the beginning and re-sort. */ if (s == nsnull) { server->position = position; wholeList->AppendElement(server); resort = PR_TRUE; } /* Don't re-sort if the server is already in the requested position. */ else if (server->position != position) { server->position = position; wholeList->RemoveElement(server); wholeList->AppendElement(server); resort = PR_TRUE; } break; } /* Make sure our position changes get saved back to prefs */ DIR_SaveServerPreferences(wholeList); return resort; }