Ticket #10656: bookmarks_dialog_diff.txt

File bookmarks_dialog_diff.txt, 11.2 KB (added by Stephen L'Allier, 6 years ago)
Line 
1--- bookmarks_dialog.cpp 2015-12-08 12:25:54.592336187 -0500
2+++ bookmarks_dialog_new.cpp 2015-12-08 12:24:50.788353133 -0500
3@@ -47,6 +47,16 @@
4 return ShowModal();
5 }
6
7+int find(wxString a, vector<Category> b){
8+ for(int x = 0; x < b.size(); x++){
9+ if(b[x].name == a){
10+ return x;
11+ }
12+ }
13+ return -1;
14+}
15+
16+
17 void CNewBookmarkDialog::OnOK(wxCommandEvent&)
18 {
19 bool const global = xrc_call(*this, "ID_TYPE_GLOBAL", &wxRadioButton::GetValue);
20@@ -160,6 +170,7 @@
21
22 CXmlFile file(wxGetApp().GetSettingsFile(_T("bookmarks")));
23 auto element = file.Load();
24+
25 if (!element) {
26 wxMessageBoxEx(file.GetError(), _("Error loading xml file"), wxICON_ERROR);
27
28@@ -167,6 +178,7 @@
29 }
30
31 for (auto bookmark = element.child("Bookmark"); bookmark; bookmark = bookmark.next_sibling("Bookmark")) {
32+ wxString Cate;
33 wxString name;
34 wxString local_dir;
35 wxString remote_dir_raw;
36@@ -194,10 +206,30 @@
37 bool const comparison = GetTextElementBool(bookmark, "DirectoryComparison");
38
39 CBookmarkItemData *data = new CBookmarkItemData(local_dir, remote_dir, sync, comparison);
40- m_pTree->AppendItem(m_bookmarks_global, name, 1, 1, data);
41+
42+ //=================================================================================
43+ Cate = GetTextElement(bookmark, "Category");
44+ if (Cate.empty()){
45+ m_pTree->AppendItem(m_bookmarks_global, name, 1, 1, data);
46+ }
47+ else{
48+ if(find(Cate, cate_list) == -1){
49+ Category temp;
50+ temp.name = Cate;
51+ temp.cate = m_pTree->AppendItem(m_bookmarks_global, _(Cate), 0, 0);
52+
53+ cate_list.push_back(temp);
54+ m_pTree->SortChildren(cate_list[cate_list.size()-1].cate);
55+
56+ }
57+ m_pTree->AppendItem(cate_list[find(Cate, cate_list)].cate, name, 1, 1, data);
58+ }
59+ //===================================================================================
60+
61 }
62
63 m_pTree->SortChildren(m_bookmarks_global);
64+ m_pTree->Connect(wxEVT_CONTEXT_MENU, wxCommandEventHandler(CBookmarksDialog::OnMenu), NULL, this);
65 }
66
67 void CBookmarksDialog::LoadSiteSpecificBookmarks()
68@@ -226,6 +258,7 @@
69 m_pTree->SortChildren(m_bookmarks_site);
70 }
71
72+
73 int CBookmarksDialog::Run()
74 {
75 if (!Load(m_parent, _T("ID_BOOKMARKS")))
76@@ -248,6 +281,8 @@
77 m_bookmarks_global = m_pTree->AppendItem(root, _("Global bookmarks"), 0, 0);
78 LoadGlobalBookmarks();
79 m_pTree->Expand(m_bookmarks_global);
80+
81+
82 if (m_server) {
83 m_bookmarks_site = m_pTree->AppendItem(root, _("Site-specific bookmarks"), 0, 0);
84 LoadSiteSpecificBookmarks();
85@@ -295,24 +330,44 @@
86 bookmark = element.child("Bookmark");
87 }
88 }
89-
90+//------------------------------------------------------------------------------------------------------------------------------------------------------------------
91 wxTreeItemIdValue cookie;
92 for (wxTreeItemId child = m_pTree->GetFirstChild(m_bookmarks_global, cookie); child.IsOk(); child = m_pTree->GetNextChild(m_bookmarks_global, cookie)) {
93- CBookmarkItemData *data = (CBookmarkItemData *)m_pTree->GetItemData(child);
94- wxASSERT(data);
95-
96- auto bookmark = element.append_child("Bookmark");
97- AddTextElement(bookmark, "Name", m_pTree->GetItemText(child));
98- if (!data->m_local_dir.empty())
99- AddTextElement(bookmark, "LocalDir", data->m_local_dir);
100- if (!data->m_remote_dir.empty())
101- AddTextElement(bookmark, "RemoteDir", data->m_remote_dir.GetSafePath());
102- if (data->m_sync)
103- AddTextElementRaw(bookmark, "SyncBrowsing", "1");
104- if (data->m_comparison)
105- AddTextElementRaw(bookmark, "DirectoryComparison", "1");
106+ if(m_pTree->ItemHasChildren(child)){
107+ wxTreeItemIdValue cookie2;
108+ for (wxTreeItemId grandchild = m_pTree->GetFirstChild(child, cookie2); grandchild.IsOk(); grandchild = m_pTree->GetNextChild(child, cookie2)){
109+ CBookmarkItemData *data = (CBookmarkItemData *)m_pTree->GetItemData(grandchild);
110+ wxASSERT(data);
111+
112+ auto bookmark = element.append_child("Bookmark");
113+ AddTextElement(bookmark, "Name", m_pTree->GetItemText(grandchild));
114+ if (!data->m_local_dir.empty())
115+ AddTextElement(bookmark, "LocalDir", data->m_local_dir);
116+ if (!data->m_remote_dir.empty())
117+ AddTextElement(bookmark, "RemoteDir", data->m_remote_dir.GetSafePath());
118+ if (data->m_sync)
119+ AddTextElementRaw(bookmark, "SyncBrowsing", "1");
120+ if (data->m_comparison)
121+ AddTextElementRaw(bookmark, "DirectoryComparison", "1");
122+ AddTextElement(bookmark, "Category", m_pTree->GetItemText(child));
123+ }
124+ }else{
125+ CBookmarkItemData *data = (CBookmarkItemData *)m_pTree->GetItemData(child);
126+ wxASSERT(data);
127+
128+ auto bookmark = element.append_child("Bookmark");
129+ AddTextElement(bookmark, "Name", m_pTree->GetItemText(child));
130+ if (!data->m_local_dir.empty())
131+ AddTextElement(bookmark, "LocalDir", data->m_local_dir);
132+ if (!data->m_remote_dir.empty())
133+ AddTextElement(bookmark, "RemoteDir", data->m_remote_dir.GetSafePath());
134+ if (data->m_sync)
135+ AddTextElementRaw(bookmark, "SyncBrowsing", "1");
136+ if (data->m_comparison)
137+ AddTextElementRaw(bookmark, "DirectoryComparison", "1");
138+ }
139 }
140-
141+//-------------------------------------------------------------------------------------------------------------------------------------------------------------
142 if (!file.Save(false)) {
143 wxString msg = wxString::Format(_("Could not write \"%s\", the global bookmarks could no be saved: %s"), file.GetFileName(), file.GetError());
144 wxMessageBoxEx(msg, _("Error writing xml file"), wxICON_ERROR);
145@@ -336,13 +391,144 @@
146 return;
147 }
148 }
149+//==========================================================
150+void CBookmarksDialog::saveCategory(wxCommandEvent&) {
151
152+ UpdateBookmark();
153+ CInterProcessMutex mutex(MUTEX_GLOBALBOOKMARKS);
154+
155+ wxTreeItemId item = m_pTree->GetSelection();
156+ CBookmarkItemData *data = (CBookmarkItemData *)m_pTree->GetItemData(item);
157+ CBookmarkItemData *ldata = new CBookmarkItemData(data->m_local_dir, data->m_remote_dir, data->m_sync,data->m_comparison);
158+ wxString name = m_pTree->GetItemText(item);
159+
160+
161+ wxTextEntryDialog dlg(this,"Enter Category Name");
162+ wxString Cate;
163+ if(dlg.ShowModal() == wxID_OK){
164+
165+ wxTreeItemId parent = m_pTree->GetItemParent(item);
166+
167+ m_is_deleting = true;
168+ m_pTree->Delete(item);
169+ m_pTree->SelectItem(parent);
170+ m_is_deleting = false;
171+ if(!m_pTree->ItemHasChildren(parent) && (item != m_bookmarks_global || item != m_bookmarks_site)){
172+ m_pTree->Delete(parent);
173+ }
174+
175+ Cate = dlg.GetValue();
176+
177+ if(find(Cate, cate_list) == -1){
178+ Category temp;
179+ temp.name = Cate;
180+ temp.cate = m_pTree->AppendItem(m_bookmarks_global, _(Cate), 0, 0);
181+
182+ cate_list.push_back(temp);
183+ m_pTree->SortChildren(cate_list[cate_list.size()-1].cate);
184+
185+ }
186+ m_pTree->AppendItem(cate_list[find(Cate, cate_list)].cate, name, 1, 1, ldata);
187+ }
188+}
189+
190+void CBookmarksDialog::MoveCategory(wxCommandEvent& event) {
191+
192+ UpdateBookmark();
193+ CInterProcessMutex mutex(MUTEX_GLOBALBOOKMARKS);
194+
195+ wxTreeItemId item = m_pTree->GetSelection();
196+ CBookmarkItemData *data = (CBookmarkItemData *)m_pTree->GetItemData(item);
197+ CBookmarkItemData *ldata = new CBookmarkItemData(data->m_local_dir, data->m_remote_dir, data->m_sync,data->m_comparison);
198+ wxString name = m_pTree->GetItemText(item);
199+
200+
201+ wxTreeItemId parent = m_pTree->GetItemParent(item);
202+ wxString pname = m_pTree->GetItemText(parent);
203+
204+ m_is_deleting = true;
205+ m_pTree->Delete(item);
206+ m_pTree->SelectItem(parent);
207+ m_is_deleting = false;
208+ if(!m_pTree->ItemHasChildren(parent) && (item != m_bookmarks_global || item != m_bookmarks_site)){
209+ cate_list.erase(cate_list.begin() + (find(pname, cate_list)));
210+ m_pTree->Delete(parent);
211+ }
212+
213+ m_pTree->AppendItem(cate_list[event.GetId()].cate, name, 1, 1, ldata);
214+}
215+
216+void CBookmarksDialog::Uncategorize(wxCommandEvent&) {
217+
218+ UpdateBookmark();
219+ CInterProcessMutex mutex(MUTEX_GLOBALBOOKMARKS);
220+
221+ wxTreeItemId item = m_pTree->GetSelection();
222+ CBookmarkItemData *data = (CBookmarkItemData *)m_pTree->GetItemData(item);
223+ CBookmarkItemData *ldata = new CBookmarkItemData(data->m_local_dir, data->m_remote_dir, data->m_sync,data->m_comparison);
224+ wxString name = m_pTree->GetItemText(item);
225+
226+
227+ //----------------
228+ wxTreeItemId parent = m_pTree->GetItemParent(item);
229+ wxString pname = m_pTree->GetItemText(parent);
230+ m_is_deleting = true;
231+ m_pTree->Delete(item);
232+ m_pTree->SelectItem(parent);
233+ m_is_deleting = false;
234+ if(!m_pTree->ItemHasChildren(parent) && (item != m_bookmarks_global || item != m_bookmarks_site)){
235+ cate_list.erase(cate_list.begin() + (find(pname, cate_list)));
236+ m_pTree->Delete(parent);
237+ }
238+ //--------------------
239+ m_pTree->AppendItem(m_bookmarks_global, name, 1, 1, ldata);
240+}
241+
242+void CBookmarksDialog::OnMenu(wxCommandEvent&) {
243+
244+ wxTreeItemId item = m_pTree->GetSelection();
245+ wxString name = m_pTree->GetItemText(item);
246+
247+ if(!(find(name, cate_list) != -1 || item == m_bookmarks_global || item == m_bookmarks_site)){
248+
249+ ctmu = new wxMenu;
250+ ctmu->Append(1999, wxT("New Category"));
251+ ctmu->AppendSeparator();
252+ Move = new wxMenu;
253+
254+ for(int x = 0; x < cate_list.size();x++){
255+ Move->Append(x , cate_list[x].name);
256+
257+ Connect(x, wxEVT_COMMAND_MENU_SELECTED,
258+ wxCommandEventHandler(CBookmarksDialog::MoveCategory));
259+ }
260+
261+ ctmu->AppendSubMenu(Move, wxT("Move to ..."));
262+ ctmu->AppendSeparator();
263+ ctmu->Append(2000,wxT("Uncategorize"));
264+
265+ Connect(1999, wxEVT_COMMAND_MENU_SELECTED,
266+ wxCommandEventHandler(CBookmarksDialog::saveCategory));
267+
268+ Connect(2000, wxEVT_COMMAND_MENU_SELECTED,
269+ wxCommandEventHandler(CBookmarksDialog::Uncategorize));
270+
271+ if(m_pTree->GetItemParent(item) == m_bookmarks_global){
272+ ctmu->Enable(2000,false);
273+ }
274+ wxWindow::PopupMenu(ctmu);
275+ }
276+}
277+
278+//==========================================================================
279 void CBookmarksDialog::OnOK(wxCommandEvent&)
280 {
281 if (!Verify())
282 return;
283+
284 UpdateBookmark();
285
286+
287 SaveGlobalBookmarks();
288 SaveSiteSpecificBookmarks();
289
290@@ -577,11 +763,15 @@
291 return;
292
293 wxTreeItemId parent = m_pTree->GetItemParent(item);
294-
295+ wxString pname = m_pTree->GetItemText(parent);
296 m_is_deleting = true;
297 m_pTree->Delete(item);
298 m_pTree->SelectItem(parent);
299 m_is_deleting = false;
300+ if(!m_pTree->ItemHasChildren(parent) && (item != m_bookmarks_global || item != m_bookmarks_site)){
301+ cate_list.erase(cate_list.begin() + (find(pname, cate_list)));
302+ m_pTree->Delete(parent);
303+ }
304 }
305
306 void CBookmarksDialog::OnCopy(wxCommandEvent&)