Permalink
Browse files

Sort FTP profiles in dialog window

Fixes FS#394
  • Loading branch information...
1 parent 8e69455 commit 1a72db12f4c84d50177060516aac9dff728980e2 @tea tea committed Dec 26, 2010
Showing with 28 additions and 13 deletions.
  1. +13 −3 src/RemoteProfileDlg.cpp
  2. +8 −10 src/eSettings.cpp
  3. +7 −0 src/eSettings.h
View
@@ -158,12 +158,22 @@ void RemoteProfileDlg::EnableSettings(bool enable) {
m_openButton->Enable(enable);
}
+struct UncasedLess : public std::binary_function<wxString, wxString, bool> {
+ bool operator()(const wxString& __x, const wxString& __y) const {
+ return __x.CmpNoCase(__y) < 0;
+ }
+};
void RemoteProfileDlg::Init() {
+ typedef std::multimap<const wxString, unsigned int, UncasedLess> profile_list_t;
+ profile_list_t profile_list;
+
const unsigned int profile_count = m_settings.GetRemoteProfileCount();
+ for(unsigned int i = 0; i < profile_count; ++i) {
+ profile_list.insert(profile_list_t::value_type(m_settings.GetRemoteProfileName(i), i));
+ }
- for (unsigned int i = 0; i < profile_count; ++i) {
- const wxString profileName = m_settings.GetRemoteProfileName(i);
- m_profileList->Append(profileName, (void*)i);
+ for(profile_list_t::const_iterator i = profile_list.begin(); i != profile_list.end(); ++i) {
+ m_profileList->Append(i->first, (void*)i->second);
}
// Initially no profile is selected
View
@@ -371,7 +371,7 @@ RemoteProfile* eSettings::DoGetRemoteProfile(size_t profile_id) {
return *p;
// Get the profile
- const wxJSONValue remotes = m_jsonRoot.ItemAt(wxT("remoteProfiles"));
+ const wxJSONValue remotes = GetRemoteProfiles();
wxASSERT((int)profile_id < remotes.Size());
const wxJSONValue profile = remotes.ItemAt(profile_id);
@@ -391,28 +391,26 @@ RemoteProfile* eSettings::DoGetRemoteProfile(size_t profile_id) {
size_t eSettings::GetRemoteProfileCount() const {
if (!m_jsonRoot.HasMember(wxT("remoteProfiles"))) return 0;
-
const wxJSONValue remotes = m_jsonRoot.ItemAt(wxT("remoteProfiles"));
- return remotes.Size();
+ return remotes.IsArray() ? remotes.Size() : 0;
}
wxString eSettings::GetRemoteProfileName(size_t profile_id) const {
- const wxJSONValue remotes = m_jsonRoot.ItemAt(wxT("remoteProfiles"));
+ const wxJSONValue remotes = GetRemoteProfiles();
wxASSERT((int)profile_id < remotes.Size());
const wxJSONValue profile = remotes.ItemAt(profile_id);
return profile.ItemAt(wxT("name")).AsString();
}
size_t eSettings::AddRemoteProfile(const RemoteProfile& profile) {
- wxJSONValue& remotes = m_jsonRoot[wxT("remoteProfiles")];
- const size_t profile_id = remotes.Size();
+ const size_t profile_id = GetRemoteProfileCount();
SetRemoteProfile(profile_id, profile);
AutoSave();
return profile_id;
}
void eSettings::SetRemoteProfile(size_t profile_id, const RemoteProfile& profile) {
- wxJSONValue& remotes = m_jsonRoot[wxT("remoteProfiles")];
+ wxJSONValue& remotes = GetRemoteProfiles();
// Add new profile if needed
wxASSERT((int)profile_id <= remotes.Size());
@@ -475,7 +473,7 @@ const RemoteProfile* eSettings::GetRemoteProfileFromUrl(const wxString& url, boo
}
// See if we can find a matching profile in settings
- const wxJSONValue remotes = m_jsonRoot.ItemAt(wxT("remoteProfiles"));
+ const wxJSONValue remotes = GetRemoteProfiles();
const int profile_count = remotes.Size();
for (int i = 0; i < profile_count; ++i) {
const wxJSONValue profile = remotes.ItemAt(i);
@@ -535,7 +533,7 @@ void eSettings::SetRemoteProfileLogin(const RemoteProfile* profile, const wxStri
}
void eSettings::DeleteRemoteProfile(size_t profile_id) {
- wxJSONValue& remotes = m_jsonRoot[wxT("remoteProfiles")];
+ wxJSONValue& remotes = GetRemoteProfiles();
wxASSERT((int)profile_id < remotes.Size());
// Remove from db
@@ -553,7 +551,7 @@ void eSettings::DeleteRemoteProfile(size_t profile_id) {
}
void eSettings::SaveRemoteProfile(RemoteProfile* rp) {
- wxJSONValue& remotes = m_jsonRoot[wxT("remoteProfiles")];
+ wxJSONValue& remotes = GetRemoteProfiles();
// Add new profile if needed
if (rp->IsTemp()) rp->m_id = remotes.Size();
View
@@ -154,6 +154,13 @@ class eSettings: public ISettings {
static void GetRecents(const wxJSONValue& jarray, wxArrayString& recents);
// Remote profile (support functions)
+ wxJSONValue& GetRemoteProfiles() {
+ wxJSONValue& res = m_jsonRoot[wxT("remoteProfiles")];
+ res.SetType(wxJSONTYPE_ARRAY);
+ return res;
+ }
+ const wxJSONValue GetRemoteProfiles() const {return m_jsonRoot.ItemAt(wxT("remoteProfiles"));}
+
RemoteProfile* DoGetRemoteProfile(size_t profile_id);
void SaveRemoteProfile(RemoteProfile* rp);
static wxString StripSlashes(const wxString& path);

0 comments on commit 1a72db1

Please sign in to comment.