~ubuntu-branches/ubuntu/warty/monodevelop/warty

« back to all changes in this revision

Viewing changes to src/Main/Base/Internal/Project/Project/IncludeFilesDialog.cs

  • Committer: Bazaar Package Importer
  • Author(s): Brandon Hale
  • Date: 2004-10-07 11:51:11 UTC
  • Revision ID: james.westby@ubuntu.com-20041007115111-pxcqnwfxyq5mhcx5
Tags: 0.5.1-3
Use dh_netdeps in debian/rules and debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// <file>
 
2
//     <copyright see="prj:///doc/copyright.txt"/>
 
3
//     <license see="prj:///doc/license.txt"/>
 
4
//     <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
 
5
//     <version value="$version"/>
 
6
// </file>
 
7
using System;
 
8
using System.Drawing;
 
9
using System.Collections;
 
10
using System.Collections.Specialized;
 
11
using System.ComponentModel;
 
12
 
 
13
using MonoDevelop.Core.Properties;
 
14
using MonoDevelop.Core.Services;
 
15
using MonoDevelop.Services;
 
16
using MonoDevelop.Gui;
 
17
using MonoDevelop.Internal.Project;
 
18
 
 
19
using Gtk;
 
20
 
 
21
namespace MonoDevelop.Internal.Project
 
22
{
 
23
        public class IncludeFilesDialog
 
24
        {
 
25
                // gtk widgets
 
26
                [Glade.Widget] Button okbutton;
 
27
                [Glade.Widget] Button cancelbutton;
 
28
                [Glade.Widget] Button selectAllButton;
 
29
                [Glade.Widget] Button deselectAllButton;
 
30
                [Glade.Widget] RadioButton newFilesOnlyRadioButton;
 
31
                [Glade.Widget] RadioButton allFilesRadioButton;
 
32
                [Glade.Widget] Label newFilesInProjectLabel;
 
33
                [Glade.Widget] Label viewLabel;
 
34
                [Glade.Widget] TreeView IncludeFileListView;
 
35
                [Glade.Widget] Dialog IncludeFilesDialogWidget;
 
36
                public ListStore store;
 
37
                
 
38
                // regular members
 
39
                StringCollection newFiles;
 
40
                IProject         project;
 
41
                FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.GetService(typeof(FileUtilityService));
 
42
                
 
43
                public IncludeFilesDialog(IProject project, StringCollection newFiles)
 
44
                {
 
45
                        Console.WriteLine ("*** Include files dialog ***");
 
46
                        // we must do it from *here* otherwise, we get this assembly, not the caller
 
47
                        Glade.XML glade = new Glade.XML (null, "Base.glade", "IncludeFilesDialogWidget", null);
 
48
                        glade.Autoconnect (this);
 
49
                        
 
50
                        // set up dialog title
 
51
                        this.IncludeFilesDialogWidget.Title = String.Format (GettextCatalog.GetString ("Found new files in {0}"), project.Name);
 
52
                        
 
53
                        newFilesOnlyRadioButton.Active = true;
 
54
                        this.newFiles = newFiles;
 
55
                        this.project  = project;
 
56
                        
 
57
                        this.InitialiseIncludeFileList();
 
58
                        
 
59
                        // wire in event handlers
 
60
                        okbutton.Clicked += new EventHandler(AcceptEvent);
 
61
                        cancelbutton.Clicked += new EventHandler(CancelEvent);
 
62
                        selectAllButton.Clicked += new EventHandler(SelectAll);
 
63
                        deselectAllButton.Clicked += new EventHandler(DeselectAll);
 
64
 
 
65
                        // FIXME: I'm pretty sure that these radio buttons 
 
66
                        // don't actually work in SD 0.98 either, so disabling them
 
67
                        newFilesOnlyRadioButton.Sensitive = false;
 
68
                        allFilesRadioButton.Sensitive = false;
 
69
                }
 
70
                
 
71
                #region includeFileListView methods and events 
 
72
                
 
73
                // initialises and populates the include file list tree view
 
74
                private void InitialiseIncludeFileList()
 
75
                {
 
76
                        // set up the list store and treeview
 
77
                        store = new ListStore (typeof(bool), typeof(string));
 
78
                        IncludeFileListView.Selection.Mode = SelectionMode.None;
 
79
                        IncludeFileListView.Model = store;
 
80
                        CellRendererToggle rendererToggle = new CellRendererToggle ();
 
81
                        rendererToggle.Activatable = true;
 
82
                        rendererToggle.Toggled += new ToggledHandler (ItemToggled);
 
83
                        IncludeFileListView.AppendColumn ("Choosen", rendererToggle, "active", 0);
 
84
                        IncludeFileListView.AppendColumn ("Name", new CellRendererText (), "text", 1);
 
85
                        TreeIter iter = new TreeIter ();
 
86
                        
 
87
                        // add the found files to the check list box                                            
 
88
                        foreach (string file in newFiles) {
 
89
                                string name = fileUtilityService.AbsoluteToRelativePath(project.BaseDirectory, file);
 
90
                                iter = store.AppendValues (false, name);
 
91
                        }
 
92
                }
 
93
                
 
94
                private void ItemToggled (object o, ToggledArgs args)
 
95
                {
 
96
                        const int column = 0;
 
97
                        Gtk.TreeIter iter;
 
98
                        
 
99
                        if (store.GetIterFromString(out iter, args.Path)) {
 
100
                                bool val = (bool) store.GetValue(iter, column);
 
101
                                store.SetValue(iter, column, !val);
 
102
                        }
 
103
                }
 
104
                
 
105
                #endregion
 
106
                
 
107
                void AcceptEvent(object sender, EventArgs e)
 
108
                {
 
109
                        TreeIter first; 
 
110
                        store.GetIterFirst(out first);
 
111
                        TreeIter current = first;
 
112
                        for (int i = 0; i < store.IterNChildren() ; ++i) {
 
113
                                // get column raw values
 
114
                                bool isSelected = (bool) store.GetValue(current, 0);
 
115
                                string fileName = (string) store.GetValue(current, 1);
 
116
                        
 
117
                                // process raw values into actual project details
 
118
                                string file = fileUtilityService.RelativeToAbsolutePath(project.BaseDirectory,fileName);
 
119
                                ProjectFile finfo = new ProjectFile(file);
 
120
                                if (isSelected) {
 
121
                                        finfo.BuildAction = project.IsCompileable(file) ? BuildAction.Compile : BuildAction.Nothing;
 
122
                                } else {
 
123
                                        finfo.BuildAction = BuildAction.Exclude;
 
124
                                }
 
125
                                project.ProjectFiles.Add(finfo);
 
126
                                
 
127
                                store.IterNext(ref current);
 
128
                        }
 
129
                        
 
130
                        IncludeFilesDialogWidget.Destroy();
 
131
                }
 
132
                
 
133
                void CancelEvent(object sender, EventArgs e)
 
134
                {
 
135
                        IncludeFilesDialogWidget.Destroy();
 
136
                }
 
137
                
 
138
                void SelectAll(object sender, EventArgs e)
 
139
                {
 
140
                        SetAllCheckedValues(true);
 
141
                }
 
142
                
 
143
                void DeselectAll(object sender, EventArgs e)
 
144
                {
 
145
                        SetAllCheckedValues(false);
 
146
                }
 
147
                
 
148
                private void SetAllCheckedValues(bool value)
 
149
                {
 
150
                        TreeIter first; 
 
151
                        store.GetIterFirst(out first);
 
152
                        TreeIter current = first;
 
153
                        for (int i = 0; i < store.IterNChildren() ; ++i) {
 
154
                                store.SetValue(current, 0, value);
 
155
                                
 
156
                                store.IterNext(ref current);
 
157
                        }
 
158
                }
 
159
                
 
160
                public void ShowDialog()
 
161
                {
 
162
                        this.IncludeFilesDialogWidget.Run();
 
163
                }
 
164
 
 
165
        }
 
166
}
 
167