NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
revisiondialog.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2019 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#include "revisiondialog.hpp"
20#include "../../kernel/core/ui/language.hpp"
21#include "../NumeReWindow.h"
22
23BEGIN_EVENT_TABLE(RevisionDialog, wxDialog)
24 EVT_TREE_ITEM_RIGHT_CLICK(-1, RevisionDialog::OnRightClick)
25 EVT_TREE_ITEM_ACTIVATED(-1, RevisionDialog::OnItemActivated)
28
29extern Language _guilang;
30
31
40RevisionDialog::RevisionDialog(wxWindow* parent, FileRevisions* rev, const wxString& fileNameAndPath)
41 : wxDialog(parent, wxID_ANY, _guilang.get("GUI_DLG_REVISIONDIALOG_TITLE"), wxDefaultPosition, wxSize(750, 500), wxRESIZE_BORDER | wxCAPTION | wxCLOSE_BOX), revisions(rev)
42{
43 mainWindow = static_cast<NumeReWindow*>(parent);
44 currentFileName = fileNameAndPath.substr(fileNameAndPath.find_last_of("/\\")+1);
45 currentFilePath = fileNameAndPath.substr(0, fileNameAndPath.find_last_of("/\\")+1);
46
47 wxBoxSizer* vsizer = new wxBoxSizer(wxVERTICAL);
48 revisionList = new wxcode::wxTreeListCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_TWIST_BUTTONS | wxTR_FULL_ROW_HIGHLIGHT | wxTR_EXTENDED | wxTR_MULTIPLE);
49 revisionList->AddColumn(_guilang.get("GUI_DLG_REVISIONDIALOG_REV"), 150);
50 revisionList->AddColumn(_guilang.get("GUI_DLG_REVISIONDIALOG_DATE"), 150);
51 revisionList->AddColumn(_guilang.get("GUI_DLG_REVISIONDIALOG_COMMENT"), 450);
52 revisionList->AddRoot(currentFileName);
53
54 populateRevisionList();
55
56 vsizer->Add(revisionList, 1, wxEXPAND | wxALL, 5);
57 vsizer->Add(CreateButtonSizer(wxOK), 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
58
59 SetSizer(vsizer);
60}
61
62
73{
74 wxArrayString revList = revisions->getRevisionList();
75 wxString currentRev = revisions->getCurrentRevision();
76 wxTreeItemId currentItem;
77
78 // Handle each revision independently
79 for (size_t i = 0; i < revList.size(); i++)
80 {
81 // Is it a tag?
82 if (revList[i].substr(0, 3) == "tag")
83 {
84 // A tag is appended to the previous revision
85 wxTreeItemId currentTagItem = revisionList->AppendItem(currentItem, revList[i].substr(0, revList[i].find('\t')));
86 revisionList->SetItemText(currentTagItem, 1, revList[i].substr(revList[i].find('\t')+1, revList[i].find('\t', revList[i].find('\t')+1) - revList[i].find('\t')-1));
87 revisionList->SetItemText(currentTagItem, 2, revList[i].substr(revList[i].rfind('\t')+1));
88 revisionList->SetItemFont(currentTagItem, revisionList->GetFont().MakeItalic());
89 revisionList->SetItemTextColour(currentTagItem, wxColour(0, 0, 192));
90 }
91 else
92 {
93 // Create a new revision in the tree
94 currentItem = revisionList->AppendItem(revisionList->GetRootItem(), revList[i].substr(0, revList[i].find('\t')));
95 revisionList->SetItemText(currentItem, 1, revList[i].substr(revList[i].find('\t')+1, revList[i].find('\t', revList[i].find('\t')+1) - revList[i].find('\t')-1));
96 revisionList->SetItemText(currentItem, 2, revList[i].substr(revList[i].rfind('\t')+1));
97
98 if (revisionList->GetItemText(currentItem, 2).substr(0, 5) == "MOVE:")
99 revisionList->SetItemTextColour(currentItem, wxColour(128, 0, 0));
100
101 if (revisionList->GetItemText(currentItem, 2).substr(0, 7) == "RENAME:")
102 revisionList->SetItemTextColour(currentItem, wxColour(0, 128, 0));
103
104 if (revisionList->GetItemText(currentItem, 2).substr(0, 8) == "RESTORE:")
105 revisionList->SetItemTextColour(currentItem, wxColour(0, 128, 128));
106
107 // Do not display the "DIFF" comment identifier
108 if (revisionList->GetItemText(currentItem, 2).substr(0, 4) == "DIFF")
109 revisionList->SetItemText(currentItem, 2, "");
110
111 if (revisionList->GetItemText(currentItem, 0) == currentRev)
112 revisionList->SetItemBold(currentItem, true);
113 }
114 }
115
116 revisionList->ExpandAll(revisionList->GetRootItem());
117}
118
119
130void RevisionDialog::showRevision(const wxString& revString)
131{
132 wxString revision = revisions->getRevision(revString);
133 mainWindow->ShowRevision(revString + "-" + currentFileName, revision);
134}
135
136
147void RevisionDialog::compareRevisions(const wxString& rev1, const wxString& rev2)
148{
149 mainWindow->ShowRevision(rev1 + "-" + rev2 + "-" + currentFileName + ".diff", revisions->compareRevisions(rev1, rev2));
150}
151
152
160void RevisionDialog::OnRightClick(wxTreeEvent& event)
161{
162 clickedItem = event.GetItem();
163
164 // do nothing, if the parent node is not the
165 // table root node
166 if (event.GetItem() == revisionList->GetRootItem())
167 return;
168
169 // Create the menu
170 wxMenu popUpmenu;
171
172 // Append commons
173 popUpmenu.Append(ID_REVISIONDIALOG_SHOW, _guilang.get("GUI_DLG_REVISIONDIALOG_SHOW"));
174 popUpmenu.AppendSeparator();
175 wxArrayTreeItemIds selection;
176
177 if (revisionList->GetSelections(selection) >= 2)
178 {
179 popUpmenu.Append(ID_REVISIONDIALOG_COMPARE, _guilang.get("GUI_DLG_REVISIONDIALOG_COMPARE", revisionList->GetItemText(selection[0]).ToStdString(), revisionList->GetItemText(selection[1]).ToStdString()));
180 popUpmenu.AppendSeparator();
181 }
182
183 popUpmenu.Append(ID_REVISIONDIALOG_TAG, _guilang.get("GUI_DLG_REVISIONDIALOG_TAG"));
184 popUpmenu.Append(ID_REVISIONDIALOG_RESTORE, _guilang.get("GUI_DLG_REVISIONDIALOG_RESTORE"));
185 popUpmenu.Append(ID_REVISIONDIALOG_REFRESH, _guilang.get("GUI_DLG_REVISIONDIALOG_REFRESH"));
186
187 // Display the menu
188 PopupMenu(&popUpmenu, event.GetPoint());
189
190}
191
192
200void RevisionDialog::OnItemActivated(wxTreeEvent& event)
201{
202 wxString revID = revisionList->GetItemText(event.GetItem());
203 showRevision(revID);
204}
205
206
214void RevisionDialog::OnMenuEvent(wxCommandEvent& event)
215{
216 wxString revID;
217
218 // Ensure that the tree item id is valid and that
219 // the user did not click on the root item
220 if (clickedItem.IsOk() && clickedItem != revisionList->GetRootItem())
221 revID = revisionList->GetItemText(clickedItem);
222 else if (event.GetId() != ID_REVISIONDIALOG_REFRESH)
223 return;
224
225 switch (event.GetId())
226 {
228 // Show the right-clicked revision
229 showRevision(revID);
230 break;
232 {
233 wxArrayTreeItemIds selectedIds;
234
235 if (revisionList->GetSelections(selectedIds) >= 2)
236 compareRevisions(revisionList->GetItemText(selectedIds[0]), revisionList->GetItemText(selectedIds[1]));
237
238 break;
239 }
241 {
242 // Tag the right-clicked revision. Display
243 // a text entry dialog to ask for the
244 // comment
245 wxTextEntryDialog textdialog(this, _guilang.get("GUI_DLG_REVISIONDIALOG_PROVIDETAGCOMMENT"), _guilang.get("GUI_DLG_REVISIONDIALOG_PROVIDETAGCOMMENT_TITLE"), wxEmptyString, wxCENTER | wxOK | wxCANCEL);
246 int ret = textdialog.ShowModal();
247
248 if (ret == wxID_OK)
249 {
250 revisions->tagRevision(revID, textdialog.GetValue());
251 revisionList->DeleteChildren(revisionList->GetRootItem());
253 }
254
255 break;
256 }
258 {
259 // Restore the right-clicked revision. Display
260 // a message box to confirm the overwrite
261 int ret = wxMessageBox(_guilang.get("GUI_DLG_REVISIONDIALOG_CONFIRM_RESTORE", revID.ToStdString()), _guilang.get("GUI_DLG_REVISIONDIALOG_CONFIRM_RESTORE_HEAD"), wxOK | wxCANCEL | wxCENTER | wxICON_QUESTION, this);
262
263 if (ret == wxOK)
264 {
267
268 // Refresh the contents of the revision list
269 revisionList->DeleteChildren(revisionList->GetRootItem());
271 }
272
273 break;
274 }
276 {
277 // Refresh the contents of the revision list
278 revisionList->DeleteChildren(revisionList->GetRootItem());
280
281 break;
282 }
283 }
284}
285
#define wxCLOSE_BOX
wxString getRevision(size_t nRevision)
Returns the contents of the selected revision.
void restoreRevision(size_t nRevision, const wxString &targetFile)
This method will restore the contents of the selected revision.
wxArrayString getRevisionList()
This method returns a log-like list of revisions.
size_t tagRevision(size_t nRevision, const wxString &tagComment)
Allows the user to tag a selected revision with the passed comment.
wxString compareRevisions(const wxString &rev1, const wxString &rev2)
This member function compares two revisions with each other and returns the differnces as unified dif...
wxString getCurrentRevision()
This method returns the revision identifier of the current revision.
This class handles the internal language system and returns the language strings of the selected lang...
Definition: language.hpp:38
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
Definition: language.cpp:292
This class is the actual NumeRe main frame. The application's logic is implemented here.
Definition: NumeReWindow.h:177
void ShowRevision(const wxString &revisionName, const wxString &revisionContent)
This member function creates a new editor page and copies the passed revision contents to this page.
void reloadFileIfOpen(const wxString &fname, bool force=false)
Reloads a file if it is open in any editor.
This class represents the dialog listing the file revisions of the current selected file.
void compareRevisions(const wxString &rev1, const wxString &rev2)
This method compares two defined revisions and opens them as a diff file in the editor.
void OnMenuEvent(wxCommandEvent &event)
This method handles the menu events emitted from the context menu.
void OnRightClick(wxTreeEvent &event)
This method displays the context menu containing the actions.
FileRevisions * revisions
wxTreeItemId clickedItem
void OnItemActivated(wxTreeEvent &event)
This method displays the double-clicked revision.
wxString currentFileName
wxcode::wxTreeListCtrl * revisionList
void populateRevisionList()
This method pupulates the tree list ctrl.
wxString currentFilePath
void showRevision(const wxString &revString)
This method displays the selected revision in the editor.
NumeReWindow * mainWindow
@ ID_REVISIONDIALOG_SHOW
@ ID_REVISIONDIALOG_RESTORE
@ ID_REVISIONDIALOG_COMPARE
@ ID_REVISIONDIALOG_TAG
@ ID_REVISIONDIALOG_REFRESH
static Matrix selection(const MatFuncData &funcData, const MatFuncErrorInfo &errorInfo)
Extracts a selection from a matrix iterating through two matrices simultaneously.
Definition: matfuncs.hpp:3151
std::string get(const std::string &sUrl, const std::string &sUserName, const std::string &sPassWord)
Get the contents of a URL.
Definition: http.cpp:251
Language _guilang
END_EVENT_TABLE()