~cszikszoy/do-plugins/fix-confluence

« back to all changes in this revision

Viewing changes to Confluence/src/ConfluenceConfigWidget.cs

  • Committer: Chris
  • Date: 2009-06-20 02:11:31 UTC
  • Revision ID: chris@szikszoy.com-20090620021131-cahieuyuq6zusq47
fix confluence shit

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
//
16
16
 
17
17
using System;
 
18
using Do.Platform;
18
19
 
19
20
namespace Confluence
20
21
{
21
22
        [System.ComponentModel.Category("Confluence")]
22
23
        [System.ComponentModel.ToolboxItem(true)]
23
24
        public partial class ConfluenceConfigWidget : Gtk.Bin
24
 
        {
25
 
                private ConfluenceSearchAction _confluenceSearch;
26
 
                
27
 
                public ConfluenceConfigWidget(ConfluenceSearchAction confluenceSearch)
28
 
                {
29
 
                        this.Build();
30
 
                        _confluenceSearch = confluenceSearch;
31
 
                        SetFieldsFromConfig( _confluenceSearch.Config );
 
25
        {               
 
26
                private readonly int DefaultMaxResults = 20;
 
27
                static IPreferences Prefs;
 
28
                
 
29
                public ConfluenceConfigWidget ()
 
30
                {
 
31
                        this.Build ();
 
32
                        SetFieldsFromConfig ();
 
33
                        
 
34
                        Console.WriteLine ("Building new config.");
 
35
                }
 
36
                
 
37
                static ConfluenceConfigWidget ()
 
38
                {
 
39
                        Prefs = Services.Preferences.Get<Confluence.ConfluenceConfigWidget> ();
32
40
                }
33
41
                
34
42
                protected virtual void OnSaveButtonReleased (object sender, System.EventArgs e)
35
43
                {
36
 
                        _confluenceSearch.Log( "Re-init Confluence Plugin with new settings..." );
37
 
 
38
 
                        _confluenceSearch.Config = GetConfigFromFields();
 
44
                        GetConfigFromFields ();
39
45
                        
40
46
                        // Write the config back out to the fields to reflect how we saved it
41
 
                        SetFieldsFromConfig( _confluenceSearch.Config );
 
47
                        SetFieldsFromConfig ();
42
48
                }
43
49
 
44
50
                // Bindings...
45
51
                
46
 
                private void SetFieldsFromConfig( IConfluenceConfiguration config )
47
 
                {
48
 
                        _entryBaseUrl.Text = config.BaseUrl;
49
 
                        _entryUsername.Text = config.Username;
50
 
                        _entryPassword.Text = config.Password;
51
 
                        _entryMaxSearchResults.Text = Convert.ToString(config.MaxSearchResults);
52
 
                }
53
 
                
54
 
                private IConfluenceConfiguration GetConfigFromFields()
55
 
                {
56
 
                        ConfluenceConfiguration config = new ConfluenceConfiguration();
57
 
                        config.BaseUrl = _entryBaseUrl.Text;
58
 
                        config.Username = _entryUsername.Text;
59
 
                        config.Password = _entryPassword.Text;
60
 
                        
61
 
                        try 
62
 
                        {
63
 
                                config.MaxSearchResults = Convert.ToInt32(_entryMaxSearchResults.Text);
64
 
                        } 
65
 
                        catch (FormatException) 
66
 
                        {
67
 
                                _confluenceSearch.Log( "Invalid max search results specified.  Setting to default value." );
68
 
                                config.MaxSearchResults = config.DefaultMaxSearchResults;
69
 
                        }
70
 
                        
71
 
                        return config;
72
 
                }
 
52
                private void SetFieldsFromConfig ()
 
53
                {
 
54
                        _entryBaseUrl.Text = BaseURL;
 
55
                        _entryUsername.Text = UserName;
 
56
                        _entryPassword.Text = Password;
 
57
                        _entryMaxSearchResults.Text = MaxResults.ToString ();
 
58
                }
 
59
                
 
60
                private void GetConfigFromFields ()
 
61
                {
 
62
                        BaseURL = _entryBaseUrl.Text;
 
63
                        UserName = _entryUsername.Text;
 
64
                        Password = _entryPassword.Text;
 
65
                        
 
66
                        try {
 
67
                                MaxResults = Convert.ToInt32(_entryMaxSearchResults.Text);
 
68
                        } catch (FormatException) {
 
69
                                Log.Debug ("Invalid max search results specified.  Setting to default value.");
 
70
                                MaxResults = DefaultMaxResults;
 
71
                        }
 
72
                }
 
73
                
 
74
                public static string BaseURL
 
75
                {
 
76
                        get { 
 
77
                                return Prefs.Get<string> ("BaseURL", ""); 
 
78
                        }
 
79
                        set { Prefs.Set<string> ("BaseURL", value); }
 
80
                }
 
81
 
 
82
                public static string UserName
 
83
                {
 
84
                        get { 
 
85
                                return Prefs.Get<string> ("UserName", ""); 
 
86
                        }
 
87
                        set { Prefs.Set<string> ("UserName", value); }
 
88
                }
 
89
 
 
90
                public static string Password
 
91
                {
 
92
                        get { 
 
93
                                return Prefs.GetSecure<string> ("Password", ""); 
 
94
                        }
 
95
                        set { Prefs.SetSecure<string> ("Password", value); }
 
96
                }
 
97
                
 
98
                public static int MaxResults
 
99
                {
 
100
                        get { 
 
101
                                return Prefs.Get<int> ("MaxResults", 20); 
 
102
                        }
 
103
                        set { Prefs.Set<int> ("MaxResults", value); }
 
104
                }       
73
105
        }
74
106
}