Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 13dcb03

Browse files
committed
finish new config window buttons
1 parent e95a8ee commit 13dcb03

File tree

10 files changed

+61
-18
lines changed

10 files changed

+61
-18
lines changed

Resources/Icons/add.png

-5.69 KB
Binary file not shown.

Resources/Icons/duplicate.png

-7.16 KB
Binary file not shown.

Resources/Icons/icon-add.png

862 Bytes
Loading

Resources/Icons/icon-duplicate.png

1.42 KB
Loading

Resources/Icons/icon-trash.png

1.21 KB
Loading

Resources/Icons/trash.png

-9.92 KB
Binary file not shown.

Spcode.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,9 @@
466466
<Content Include="Deploy\nsis-plugins\DotNetChecker.dll" />
467467
<Resource Include="Resources\Icons\icon-error.png" />
468468
<Resource Include="Resources\Icons\icon-warning.png" />
469-
<Resource Include="Resources\Icons\add.png" />
470-
<Resource Include="Resources\Icons\duplicate.png" />
471-
<Resource Include="Resources\Icons\trash.png" />
469+
<Resource Include="Resources\Icons\icon-add.png" />
470+
<Resource Include="Resources\Icons\icon-duplicate.png" />
471+
<Resource Include="Resources\Icons\icon-trash.png" />
472472
<Content Include="Resources\License.txt" />
473473
<Content Include="Resources\Misc\Configurations\sm_1_10_0_6509\include\admin.inc" />
474474
<Content Include="Resources\Misc\Configurations\sm_1_10_0_6509\include\adminmenu.inc" />

UI/Windows/ConfigWindow.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@
6868
<Setter Property="Height" Value="2"/>
6969
</Style>
7070

71-
<Image x:Key="ImgAdd" Source="/SPCode;component/Resources/Icons/add.png" Width="16"/>
72-
<Image x:Key="ImgCopy" Source="/SPCode;component/Resources/Icons/duplicate.png" Width="16"/>
73-
<Image x:Key="ImgDelete" Source="/SPCode;component/Resources/Icons/trash.png" Width="16"/>
71+
<Image x:Key="ImgAdd" Source="/SPCode;component/Resources/Icons/icon-add.png" Width="16"/>
72+
<Image x:Key="ImgCopy" Source="/SPCode;component/Resources/Icons/icon-duplicate.png" Width="16"/>
73+
<Image x:Key="ImgDelete" Source="/SPCode;component/Resources/Icons/icon-trash.png" Width="16"/>
7474

7575
<ResourceDictionary.MergedDictionaries>
7676
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />

UI/Windows/ConfigWindow.xaml.cs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,39 +255,48 @@ private void LoadConfigToUI(int index)
255255

256256
private void NewButton_Click(object sender, RoutedEventArgs e)
257257
{
258-
var c = new Config
258+
var cfg = new Config
259259
{
260-
Name = "New Config",
260+
Name = Translate("NewConfig"),
261261
Standard = false,
262262
OptimizeLevel = 2,
263263
VerboseLevel = 1,
264264
SMDirectories = new List<string>()
265265
};
266-
var configList = new List<Config>(Program.Configs) { c };
267-
Program.Configs = configList;
268-
ConfigListBox.Items.Add(new ListBoxItem { Content = Translate("NewConfig") });
266+
Program.Configs.Add(cfg);
267+
ConfigListBox.Items.Add(new ListBoxItem
268+
{
269+
Content = Translate("NewConfig")
270+
});
269271
}
270272

271273
private void CopyButton_Click(object sender, RoutedEventArgs e)
272274
{
273-
275+
var cfg = Program.Configs[ConfigListBox.SelectedIndex].Clone() as Config;
276+
var newName = $"Copy of {cfg.Name}";
277+
cfg.Name = newName;
278+
cfg.Standard = false;
279+
Program.Configs.Add(cfg);
280+
ConfigListBox.Items.Add(new ListBoxItem
281+
{
282+
Content = newName
283+
});
284+
ConfigListBox.SelectedIndex = ConfigListBox.Items.Count - 1;
274285
}
275286

276287
private void DeleteButton_Click(object sender, RoutedEventArgs e)
277288
{
278289
var index = ConfigListBox.SelectedIndex;
279-
var c = Program.Configs[index];
280-
if (c.Standard)
290+
var cfg = Program.Configs[index];
291+
if (cfg.Standard)
281292
{
282293
this.ShowMessageAsync(Translate("CannotDelConf"),
283294
Translate("YCannotDelConf"), MessageDialogStyle.Affirmative,
284295
Program.MainWindow.MetroDialogOptions);
285296
return;
286297
}
287298

288-
var configList = new List<Config>(Program.Configs);
289-
configList.RemoveAt(index);
290-
Program.Configs = configList;
299+
Program.Configs.Remove(cfg);
291300
ConfigListBox.Items.RemoveAt(index);
292301
if (index == Program.SelectedConfig)
293302
{
@@ -733,6 +742,9 @@ await this.ShowMessageAsync(Translate("ErrorSavingConfigs"),
733742
private void Language_Translate()
734743
{
735744
Title = Translate("Configs");
745+
NewButton.ToolTip = Translate("New");
746+
CopyButton.ToolTip = Translate("Copy");
747+
DeleteButton.ToolTip = Translate("Delete");
736748
AddSMDirButton.Content = Translate("Add");
737749
RemoveSMDirButton.Content = Translate("Remove");
738750
NameBlock.Text = Translate("Name");

Utils/Models/Config.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace SPCode.Utils
77
{
8-
public class Config
8+
public class Config : ICloneable
99
{
1010
public bool AutoCopy;
1111
public bool AutoUpload;
@@ -76,5 +76,36 @@ public void LoadSMDef()
7676
SMDef = new SMDefinition();
7777
}
7878
}
79+
80+
public object Clone()
81+
{
82+
return new Config
83+
{
84+
AutoCopy = AutoCopy,
85+
AutoUpload = AutoUpload,
86+
AutoRCON = AutoRCON,
87+
CopyDirectory = CopyDirectory,
88+
DeleteAfterCopy = DeleteAfterCopy,
89+
FTPDir = FTPDir,
90+
FTPHost = FTPHost,
91+
FTPPassword = FTPPassword,
92+
FTPUser = FTPUser,
93+
Name = Name,
94+
OptimizeLevel = OptimizeLevel,
95+
PostCmd = PostCmd,
96+
PreCmd = PreCmd,
97+
RConCommands = RConCommands,
98+
RConIP = RConIP,
99+
RConPort = RConPort,
100+
RConPassword = RConPassword,
101+
ServerArgs = ServerArgs,
102+
ServerFile = ServerFile,
103+
SMDef = SMDef,
104+
SMDirectories = SMDirectories,
105+
RejectedPaths = RejectedPaths,
106+
Standard = Standard,
107+
VerboseLevel = VerboseLevel
108+
};
109+
}
79110
}
80111
}

0 commit comments

Comments
 (0)