~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/MergeDialog.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// MergeDialog.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez Gual <lluis@novell.com>
 
6
// 
 
7
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
 
8
// 
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using Gtk;
 
29
using MonoDevelop.Core;
 
30
using MonoDevelop.Ide;
 
31
 
 
32
namespace MonoDevelop.VersionControl.Git
 
33
{
 
34
        public partial class MergeDialog : Gtk.Dialog
 
35
        {
 
36
                TreeStore store;
 
37
                GitRepository repo;
 
38
                string currentSel;
 
39
                string currentType;
 
40
                bool rebasing;
 
41
                
 
42
                public MergeDialog (GitRepository repo, bool rebasing)
 
43
                {
 
44
                        this.Build ();
 
45
                        
 
46
                        this.repo = repo;
 
47
                        this.rebasing = rebasing;
 
48
                        
 
49
                        store = new TreeStore (typeof(string), typeof(Gdk.Pixbuf), typeof (string), typeof(string));
 
50
                        tree.Model = store;
 
51
                        
 
52
                        CellRendererPixbuf crp = new CellRendererPixbuf ();
 
53
                        TreeViewColumn col = new TreeViewColumn ();
 
54
                        col.PackStart (crp, false);
 
55
                        col.AddAttribute (crp, "pixbuf", 1);
 
56
                        CellRendererText crt = new CellRendererText ();
 
57
                        col.PackStart (crt, true);
 
58
                        col.AddAttribute (crt, "text", 2);
 
59
                        tree.AppendColumn (col);
 
60
                        
 
61
                        tree.Selection.Changed += HandleTreeSelectionChanged;
 
62
                        
 
63
                        if (rebasing) {
 
64
                                labelHeader.Text = GettextCatalog.GetString ("Select the branch to which to rebase:");
 
65
                                checkStage.Label = GettextCatalog.GetString ("Stash/unstash local changes before/after rebasing");
 
66
                        }
 
67
                        
 
68
                        checkStage.Active = true;
 
69
                        
 
70
                        Fill ();
 
71
                }
 
72
                
 
73
                public string SelectedBranch {
 
74
                        get { return currentSel; }
 
75
                }
 
76
                
 
77
                public bool StageChanges {
 
78
                        get { return checkStage.Active; }
 
79
                }
 
80
 
 
81
                void HandleTreeSelectionChanged (object sender, EventArgs e)
 
82
                {
 
83
                        TreeIter it;
 
84
                        if (tree.Selection.GetSelected (out it)) {
 
85
                                currentSel = (string) store.GetValue (it, 0);
 
86
                                currentType = (string) store.GetValue (it, 3);
 
87
                        }
 
88
                        else
 
89
                                currentSel = null;
 
90
                        UpdateStatus ();
 
91
                }
 
92
                
 
93
                void Fill ()
 
94
                {
 
95
                        store.Clear ();
 
96
                        
 
97
                        foreach (Branch b in repo.GetBranches ())
 
98
                                store.AppendValues (b.Name, ImageService.GetPixbuf ("vc-git-branch"), b.Name, "branch");
 
99
                        
 
100
                        foreach (string t in repo.GetTags ())
 
101
                                store.AppendValues (t, ImageService.GetPixbuf ("vc-git-tag"), t, "tag");
 
102
                        
 
103
                        foreach (RemoteSource r in repo.GetRemotes ()) {
 
104
                                TreeIter it = store.AppendValues (null, ImageService.GetPixbuf ("md-web-search-icon"), r.Name, null);
 
105
                                foreach (string b in repo.GetRemoteBranches (r.Name))
 
106
                                        store.AppendValues (it, r.Name + "/" + b, ImageService.GetPixbuf ("vc-git-branch"), b, "remote");
 
107
                        }
 
108
                        UpdateStatus ();
 
109
                }
 
110
                
 
111
                void UpdateStatus ()
 
112
                {
 
113
                        if (currentSel != null) {
 
114
                                string cb = repo.GetCurrentBranch ();
 
115
                                string txt = null;
 
116
                                if (rebasing) {
 
117
                                        switch (currentType) {
 
118
                                        case "branch": txt = GettextCatalog.GetString ("The branch <b>{1}</b> will be rebased to the branch <b>{0}</b>.", currentSel, cb); break;
 
119
                                        case "tag": txt = GettextCatalog.GetString ("The branch <b>{1}</b> witl be rebased to the tag <b>{0}</b>.", currentSel, cb); break;
 
120
                                        case "remote": txt = GettextCatalog.GetString ("The branch <b>{1}</b> will be rebased to the remote branch <b>{0}</b>.", currentSel, cb); break;
 
121
                                        }
 
122
                                }
 
123
                                else {
 
124
                                        switch (currentType) {
 
125
                                        case "branch": txt = GettextCatalog.GetString ("The branch <b>{0}</b> will be merged into the branch <b>{1}</b>.", currentSel, cb); break;
 
126
                                        case "tag": txt = GettextCatalog.GetString ("The tag <b>{0}</b> will be merged into the branch <b>{1}</b>.", currentSel, cb); break;
 
127
                                        case "remote": txt = GettextCatalog.GetString ("The remote branch <b>{0}</b> will be merged into the branch <b>{1}</b>.", currentSel, cb); break;
 
128
                                        }
 
129
                                }
 
130
                                labelOper.Visible = true;
 
131
                                labelOper.Markup = txt;
 
132
                                buttonOk.Sensitive = true;
 
133
                        } else {
 
134
                                labelOper.Visible = false;
 
135
                                buttonOk.Sensitive = false;
 
136
                        }
 
137
                }
 
138
        }
 
139
}
 
140