NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
renamesymbolsdialog.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
20#include "../globals.hpp"
21#include "../compositions/grouppanel.hpp"
22#include "../../kernel/core/ui/language.hpp"
23#include "../../kernel/core/utils/stringtools.hpp"
24
25extern Language _guilang;
26
27// Constructor
28RenameSymbolsDialog::RenameSymbolsDialog(wxWindow* parent, const std::vector<wxString>& vChangeLog, wxWindowID id, const wxString& title, const wxString& defaultval) : wxDialog(parent, id, title, wxDefaultPosition, wxDefaultSize, wxCAPTION | wxRESIZE_BORDER | wxSTAY_ON_TOP)
29{
30 m_replaceInComments = nullptr;
31 m_replaceInWholeFile = nullptr;
32 m_replaceBeforeCursor = nullptr;
33 m_replaceAfterCursor = nullptr;
34 m_replaceName = nullptr;
35
36 // Create the vertical sizer for this dialog
37 wxBoxSizer* vSizer = new wxBoxSizer(wxVERTICAL);
38 this->SetSizer(vSizer);
39
40 // Create a GroupPanel and add it to the
41 // vertical sizer of the current dialog
42 GroupPanel* panel = new GroupPanel(this, wxID_ANY, wxDefaultPosition, wxSize(350*g_pixelScale, -1));
43 vSizer->Add(panel, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
44
45 // Create the text input control
46 m_replaceName = panel->CreateTextInput(panel, panel->getVerticalSizer(), _guilang.get("GUI_DLG_RENAMESYMBOLS_QUESTION"), defaultval);
47
48 panel->AddSpacer();
49
50 // Create the checkbox group
51 wxStaticBoxSizer* group = panel->createGroup(_guilang.get("GUI_DLG_RENAMESYMBOLS_SETTINGS"));
52
53 m_replaceInComments = panel->CreateCheckBox(group->GetStaticBox(), group, _guilang.get("GUI_DLG_RENAMESYMBOLS_REPLACECOMMENTS"));
54 m_replaceInComments->SetValue(false);
55
56 m_replaceInWholeFile = panel->CreateCheckBox(group->GetStaticBox(), group, _guilang.get("GUI_DLG_RENAMESYMBOLS_REPLACEWHOLEFILE"));
57 m_replaceInWholeFile->SetValue(false);
58
59 m_replaceBeforeCursor = panel->CreateCheckBox(group->GetStaticBox(), group, _guilang.get("GUI_DLG_RENAMESYMBOLS_REPLACEBEFOREPOS"));
60 m_replaceBeforeCursor->SetValue(true);
61
62 m_replaceAfterCursor = panel->CreateCheckBox(group->GetStaticBox(), group, _guilang.get("GUI_DLG_RENAMESYMBOLS_REPLACEAFTERPOS"));
63 m_replaceAfterCursor->SetValue(true);
64
65 // Greate the changes log group
66 group = panel->createGroup(_guilang.get("GUI_DLG_RENAMESYMBOLS_CHANGELOG"));
67
68 // Create the changes log list view and
69 // create the necessary columns
70 wxListView* listview = panel->CreateListView(group->GetStaticBox(), group, wxLC_REPORT | wxLC_VRULES);
71 listview->AppendColumn("ID");
72 listview->AppendColumn(_guilang.get("GUI_DLG_RENAMESYMBOLS_CHANGELOG_OLDNAME"));
73 listview->AppendColumn(_guilang.get("GUI_DLG_RENAMESYMBOLS_CHANGELOG_NEWNAME"));
74
75 // Fill the changes log with the supplied
76 // changes log from the editor
77 fillChangesLog(listview, vChangeLog);
78
79 // Create a standard button sizer
80 vSizer->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
81
82 GetSizer()->SetSizeHints(this);
83
84 this->Centre();
85
86 // Focus the text input control and select
87 // its contents to allow overtyping
88 m_replaceName->SetFocus();
89 m_replaceName->SelectAll();
90}
91
92// This private member function fills the changes log
93// in the current dialog with the passed changes log
94// information supplied by the editor
95void RenameSymbolsDialog::fillChangesLog(wxListView* listView, const std::vector<wxString>& vChangeLog)
96{
97 wxString sCurrentItem;
98
99 // Gp through the supplied changes log and decode it
100 for (int i = vChangeLog.size()-1; i >= 0 ; i--)
101 {
102 sCurrentItem = vChangeLog[i];
103
104 listView->InsertItem((vChangeLog.size()-1) - i, toString(i+1));
105 listView->SetItem((vChangeLog.size()-1) - i, 1, sCurrentItem.substr(0, sCurrentItem.find('\t')));
106 listView->SetItem((vChangeLog.size()-1) - i, 2, sCurrentItem.substr(sCurrentItem.find('\t')+1));
107 }
108
109 // Create an empty changes log, if necessary and
110 // resize the columns
111 if (!vChangeLog.size())
112 {
113 listView->InsertItem(0, "---");
114 listView->SetItem(0, 1, "---");
115 listView->SetItem(0, 2, "---");
116 listView->SetItemTextColour(0, wxColour(128, 128, 128));
117 listView->SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER);
118 listView->SetColumnWidth(1, wxLIST_AUTOSIZE_USEHEADER);
119 listView->SetColumnWidth(2, wxLIST_AUTOSIZE_USEHEADER);
120
121 }
122 else
123 {
124 listView->SetColumnWidth(0, wxLIST_AUTOSIZE);
125 listView->SetColumnWidth(1, wxLIST_AUTOSIZE);
126 listView->SetColumnWidth(2, wxLIST_AUTOSIZE);
127 }
128}
129
double g_pixelScale
This class simplifies the creation of simple windows and creates a common layout among all windows.
Definition: grouppanel.hpp:188
wxListView * CreateListView(wxWindow *parent, wxSizer *sizer, int nStyle=wxLC_REPORT, wxSize size=wxDefaultSize, int id=wxID_ANY)
This member function creates the layout for a listview control.
Definition: grouppanel.cpp:376
void AddSpacer(int nSize=10, wxSizer *sizer=nullptr)
Add extra space between the last added (main) element and the next element to be added.
Definition: grouppanel.cpp:120
wxCheckBox * CreateCheckBox(wxWindow *parent, wxSizer *sizer, const wxString &description, int id=wxID_ANY, int alignment=wxALIGN_CENTER_VERTICAL)
This member function creates the layout for a usual checkbox.
Definition: grouppanel.cpp:316
wxStaticBoxSizer * createGroup(const wxString &sGroupName, int orient=wxVERTICAL, wxWindow *parent=nullptr, wxSizer *sizer=nullptr, int expand=0)
Member function to create a group (a static box with a label) in the panel.
Definition: grouppanel.cpp:161
wxBoxSizer * getVerticalSizer()
Return the pointer to the vertical sizer.
Definition: grouppanel.cpp:78
TextField * CreateTextInput(wxWindow *parent, wxSizer *sizer, const wxString &description, const wxString &sDefault=wxEmptyString, int nStyle=0, int id=wxID_ANY, const wxSize &size=wxSize(310,-1), int alignment=wxALIGN_CENTER_VERTICAL)
This member function creates the layout for a text input.
Definition: grouppanel.cpp:285
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
wxCheckBox * m_replaceInWholeFile
void fillChangesLog(wxListView *listView, const std::vector< wxString > &vChangeLog)
wxCheckBox * m_replaceBeforeCursor
RenameSymbolsDialog(wxWindow *parent, const std::vector< wxString > &vChangeLog, wxWindowID id=wxID_ANY, const wxString &title=wxEmptyString, const wxString &defaultval=wxEmptyString)
wxCheckBox * m_replaceAfterCursor
wxCheckBox * m_replaceInComments
Language _guilang
std::string toString(int)
Converts an integer to a string without the Settings bloat.