2929#include " Code/QRDUtils.h"
3030#include " ui_EnvironmentEditor.h"
3131
32+ static QString GetTypeString (const EnvironmentModification &env)
33+ {
34+ QString ret;
35+
36+ if (env.mod == EnvMod::Append)
37+ ret = QString (" Append, %1" ).arg (ToQStr (env.sep ));
38+ else if (env.mod == EnvMod::Prepend)
39+ ret = QString (" Prepend, %1" ).arg (ToQStr (env.sep ));
40+ else
41+ ret = " Set" ;
42+
43+ return ret;
44+ }
45+
3246Q_DECLARE_METATYPE (EnvironmentModification);
3347
3448EnvironmentEditor::EnvironmentEditor (QWidget *parent)
@@ -115,34 +129,34 @@ void EnvironmentEditor::on_variables_currentItemChanged(QTreeWidgetItem *current
115129
116130 EnvironmentModification mod = sel[0 ]->data (0 , Qt::UserRole).value <EnvironmentModification>();
117131
118- if (!mod.variable . isEmpty ())
132+ if (!mod.value . empty ())
119133 {
120- ui->name ->setText (mod.variable );
121- ui->value ->setText (mod.value );
122- ui->separator ->setCurrentIndex ((int )mod.separator );
134+ ui->name ->setText (ToQStr ( mod.name ) );
135+ ui->value ->setText (ToQStr ( mod.value ) );
136+ ui->separator ->setCurrentIndex ((int )mod.sep );
123137
124- if (mod.type == EnvMod::Set)
138+ if (mod.mod == EnvMod::Set)
125139 ui->setValue ->setChecked (true );
126- else if (mod.type == EnvMod::Append)
140+ else if (mod.mod == EnvMod::Append)
127141 ui->appendValue ->setChecked (true );
128- else if (mod.type == EnvMod::Prepend)
142+ else if (mod.mod == EnvMod::Prepend)
129143 ui->prependValue ->setChecked (true );
130144 }
131145}
132146
133147void EnvironmentEditor::on_addUpdate_clicked ()
134148{
135149 EnvironmentModification mod;
136- mod.variable = ui->name ->text ();
137- mod.value = ui->value ->text ();
138- mod.separator = (EnvSep)ui->separator ->currentIndex ();
150+ mod.name = ui->name ->text (). toUtf8 (). data ();
151+ mod.value = ui->value ->text (). toUtf8 (). data () ;
152+ mod.sep = (EnvSep)ui->separator ->currentIndex ();
139153
140154 if (ui->appendValue ->isChecked ())
141- mod.type = EnvMod::Append;
155+ mod.mod = EnvMod::Append;
142156 else if (ui->prependValue ->isChecked ())
143- mod.type = EnvMod::Prepend;
157+ mod.mod = EnvMod::Prepend;
144158 else
145- mod.type = EnvMod::Set;
159+ mod.mod = EnvMod::Set;
146160
147161 addModification (mod, false );
148162
@@ -174,7 +188,7 @@ int EnvironmentEditor::existingIndex()
174188
175189void EnvironmentEditor::addModification (EnvironmentModification mod, bool silent)
176190{
177- if (mod.variable . trimmed () == " " )
191+ if (mod.name . empty () )
178192 {
179193 if (!silent)
180194 RDDialog::critical (this , tr (" Invalid variable" ),
@@ -189,15 +203,15 @@ void EnvironmentEditor::addModification(EnvironmentModification mod, bool silent
189203
190204 if (idx < 0 )
191205 {
192- node = makeTreeNode ({mod.variable , mod. GetTypeString (), mod.value });
206+ node = makeTreeNode ({ToQStr ( mod.name ), GetTypeString (mod ), ToQStr ( mod.value ) });
193207 ui->variables ->addTopLevelItem (node);
194208 }
195209 else
196210 {
197211 node = ui->variables ->topLevelItem (idx);
198- node->setText (0 , mod.variable );
199- node->setText (1 , mod. GetTypeString ());
200- node->setText (2 , mod.value );
212+ node->setText (0 , ToQStr ( mod.name ) );
213+ node->setText (1 , GetTypeString (mod ));
214+ node->setText (2 , ToQStr ( mod.value ) );
201215 }
202216
203217 node->setData (0 , Qt::UserRole, QVariant::fromValue (mod));
@@ -225,7 +239,7 @@ QList<EnvironmentModification> EnvironmentEditor::modifications()
225239 EnvironmentModification mod =
226240 ui->variables ->topLevelItem (i)->data (0 , Qt::UserRole).value <EnvironmentModification>();
227241
228- if (!mod.variable . isEmpty ())
242+ if (!mod.name . empty ())
229243 ret.push_back (mod);
230244 }
231245
0 commit comments