aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAlexander Neumann <alexander.neumann@picos-software.com>2019-04-16 18:22:18 +0200
committerAlexander Neumann <alexander.neumann@picos-software.com>2019-04-23 11:05:00 +0200
commit68c720fefd1ae8c9cd1ea6755453b8281c093dc9 (patch)
treea9d9698bb0d2d4b42fa3c7dea1dff4b422a3a614
parentui: implement log dialog; some refactoring in manage tunnels window to share some bits (diff)
downloadwireguard-windows-68c720fefd1ae8c9cd1ea6755453b8281c093dc9.tar.xz
wireguard-windows-68c720fefd1ae8c9cd1ea6755453b8281c093dc9.zip
ui: move orderedStringSet to util.go
Signed-off-by: Alexander Neumann <alexander.neumann@picos-software.com>
-rw-r--r--ui/tunnelconfigdialog.go80
-rw-r--r--ui/util.go80
2 files changed, 80 insertions, 80 deletions
diff --git a/ui/tunnelconfigdialog.go b/ui/tunnelconfigdialog.go
index 0a7432ac..e937455d 100644
--- a/ui/tunnelconfigdialog.go
+++ b/ui/tunnelconfigdialog.go
@@ -321,83 +321,3 @@ func (dlg *TunnelConfigDialog) onSaveButtonClicked() {
dlg.Accept()
}
-
-type orderedStringSet struct {
- items []string
- item2index map[string]int
-}
-
-func orderedStringSetFromSlice(items []string) *orderedStringSet {
- oss := newOrderedStringSet()
- oss.AddMany(items)
- return oss
-}
-
-func newOrderedStringSet() *orderedStringSet {
- return &orderedStringSet{item2index: make(map[string]int)}
-}
-
-func (oss *orderedStringSet) Add(item string) bool {
- if _, ok := oss.item2index[item]; ok {
- return false
- }
-
- oss.item2index[item] = len(oss.items)
- oss.items = append(oss.items, item)
- return true
-}
-
-func (oss *orderedStringSet) AddMany(items []string) {
- for _, item := range items {
- oss.Add(item)
- }
-}
-
-func (oss *orderedStringSet) UniteWith(other *orderedStringSet) {
- if other == oss {
- return
- }
-
- oss.AddMany(other.items)
-}
-
-func (oss *orderedStringSet) Remove(item string) bool {
- if i, ok := oss.item2index[item]; ok {
- oss.items = append(oss.items[:i], oss.items[i+1:]...)
- delete(oss.item2index, item)
- return true
- }
-
- return false
-}
-
-func (oss *orderedStringSet) Len() int {
- return len(oss.items)
-}
-
-func (oss *orderedStringSet) ToSlice() []string {
- return append(([]string)(nil), oss.items...)
-}
-
-func (oss *orderedStringSet) Contains(item string) bool {
- _, ok := oss.item2index[item]
- return ok
-}
-
-func (oss *orderedStringSet) IsSupersetOf(other *orderedStringSet) bool {
- if oss.Len() < other.Len() {
- return false
- }
-
- for _, item := range other.items {
- if !oss.Contains(item) {
- return false
- }
- }
-
- return true
-}
-
-func (oss *orderedStringSet) String() string {
- return fmt.Sprintf("%v", oss.items)
-}
diff --git a/ui/util.go b/ui/util.go
index b17f106c..0cca0909 100644
--- a/ui/util.go
+++ b/ui/util.go
@@ -12,6 +12,86 @@ import (
"github.com/lxn/walk"
)
+type orderedStringSet struct {
+ items []string
+ item2index map[string]int
+}
+
+func orderedStringSetFromSlice(items []string) *orderedStringSet {
+ oss := newOrderedStringSet()
+ oss.AddMany(items)
+ return oss
+}
+
+func newOrderedStringSet() *orderedStringSet {
+ return &orderedStringSet{item2index: make(map[string]int)}
+}
+
+func (oss *orderedStringSet) Add(item string) bool {
+ if _, ok := oss.item2index[item]; ok {
+ return false
+ }
+
+ oss.item2index[item] = len(oss.items)
+ oss.items = append(oss.items, item)
+ return true
+}
+
+func (oss *orderedStringSet) AddMany(items []string) {
+ for _, item := range items {
+ oss.Add(item)
+ }
+}
+
+func (oss *orderedStringSet) UniteWith(other *orderedStringSet) {
+ if other == oss {
+ return
+ }
+
+ oss.AddMany(other.items)
+}
+
+func (oss *orderedStringSet) Remove(item string) bool {
+ if i, ok := oss.item2index[item]; ok {
+ oss.items = append(oss.items[:i], oss.items[i+1:]...)
+ delete(oss.item2index, item)
+ return true
+ }
+
+ return false
+}
+
+func (oss *orderedStringSet) Len() int {
+ return len(oss.items)
+}
+
+func (oss *orderedStringSet) ToSlice() []string {
+ return append(([]string)(nil), oss.items...)
+}
+
+func (oss *orderedStringSet) Contains(item string) bool {
+ _, ok := oss.item2index[item]
+ return ok
+}
+
+func (oss *orderedStringSet) IsSupersetOf(other *orderedStringSet) bool {
+ if oss.Len() < other.Len() {
+ return false
+ }
+
+ for _, item := range other.items {
+ if !oss.Contains(item) {
+ return false
+ }
+ }
+
+ return true
+}
+
+func (oss *orderedStringSet) String() string {
+ return fmt.Sprintf("%v", oss.items)
+}
+
func writeFileWithOverwriteHandling(owner walk.Form, filePath string, write func(file *os.File) error) bool {
showError := func(err error) bool {
if err == nil {