File: LocationManager.cs

package info (click to toggle)
keepass2-plugin-keepassrpc 2.0.2%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,304 kB
  • sloc: cs: 29,001; makefile: 14
file content (92 lines) | stat: -rw-r--r-- 3,035 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Windows.Forms;
using KeePassRPC.Properties;

namespace KeePassRPC.Forms
{
    public partial class LocationManager : Form
    {
        private KeePassRPCExt _plugin;

        public LocationManager(KeePassRPCExt plugin)
        {
            _plugin= plugin;
            InitializeComponent();
            button1.Enabled = false;
            button2.Enabled = false;
            Icon = Resources.KPRPCico;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            // save changes
            string locationsConfig = "";

            foreach (string location in listBox1.Items)
            {
                locationsConfig += location + ",";
            }
            locationsConfig = locationsConfig.Length > 0 ? locationsConfig.Substring(0, locationsConfig.Length - 1) : locationsConfig;
            _plugin._host.CustomConfig.SetString("KeePassRPC.knownLocations", locationsConfig);
            _plugin._host.MainWindow.Invoke((MethodInvoker)delegate { _plugin._host.MainWindow.SaveConfig(); });

            //string rootGroupsConfig = host.CustomConfig
            //        .GetString("KeePassRPC.knownLocations." + location + ".RootGroups", "");

            //TODO2: remove RootGroups that no longer have an associated location... how? can't interate through config entries!
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // add location to list box
            listBox1.Items.Add(textBox1.Text);
            textBox1.Clear();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // remove location from list box
            if (listBox1.SelectedIndex >= 0)
                listBox1.Items.RemoveAt(listBox1.SelectedIndex);
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex >= 0)
                button1.Enabled = true;
            else
                button1.Enabled = false;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (textBox1.Text.Length > 0)
                button2.Enabled = true;
            else
                button2.Enabled = false;
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                listBox1.Items.Add(textBox1.Text);
                textBox1.Clear();
            }
        }

        private void LocationManager_Load(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            string klconf = _plugin._host.CustomConfig.GetString("KeePassRPC.knownLocations");
            if (!string.IsNullOrEmpty(klconf))
            {
                string[] knownLocations = klconf.Split(',');
                foreach (string location in knownLocations)
                {
                    listBox1.Items.Add(location);
                }
            }
        }
    }
}