~ubuntu-branches/ubuntu/feisty/monodevelop/feisty

« back to all changes in this revision

Viewing changes to Unused/TextEditor/Search/DocumentIterator/DirectoryDocumentIterator.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-08-18 00:51:23 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060818005123-5iit07y0j7wjg55f
Tags: 0.11+svn20060818-0ubuntu1
* New SVN snapshot
  + Works with Gtk# 2.9.0
* debian/control:
  + Updated Build-Depends
* debian/patches/use_nunit2.2.dpatch,
  debian/patches/use_real_libs.dpatch:
  + Updated
* debian/patches/versioncontrol_buildfix.dpatch:
  + Fix build failure in the version control addin

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
 
 
8
using System;
 
9
using System.Collections;
 
10
using System.Collections.Specialized;
 
11
using System.IO;
 
12
 
 
13
using MonoDevelop.Core.Gui;
 
14
using MonoDevelop.Projects;
 
15
using MonoDevelop.DefaultEditor.Gui.Editor;
 
16
using MonoDevelop.Core;
 
17
using MonoDevelop.Core;
 
18
using MonoDevelop.TextEditor;
 
19
 
 
20
namespace MonoDevelop.TextEditor.Document
 
21
{
 
22
        public class DirectoryDocumentIterator : IDocumentIterator
 
23
        {
 
24
                string searchDirectory;
 
25
                string fileMask;
 
26
                bool   searchSubdirectories;
 
27
                
 
28
                StringCollection files    = null;
 
29
                int              curIndex = -1;
 
30
                
 
31
                public DirectoryDocumentIterator(string searchDirectory, string fileMask, bool searchSubdirectories)
 
32
                {
 
33
                        this.searchDirectory      = searchDirectory;
 
34
                        this.fileMask             = fileMask;
 
35
                        this.searchSubdirectories = searchSubdirectories;
 
36
                        
 
37
                        Reset();
 
38
                }
 
39
                
 
40
                public string CurrentFileName {
 
41
                        get {
 
42
                                if (curIndex < 0 || curIndex >= files.Count) {
 
43
                                        return null;
 
44
                                }
 
45
                                
 
46
                                return files[curIndex].ToString();;
 
47
                        }
 
48
                }
 
49
                                
 
50
                public ProvidedDocumentInformation Current {
 
51
                        get {
 
52
                                if (curIndex < 0 || curIndex >= files.Count) {
 
53
                                        return null;
 
54
                                }
 
55
                                if (!File.Exists(files[curIndex].ToString())) {
 
56
                                        ++curIndex;
 
57
                                        return Current;
 
58
                                }
 
59
                                IDocument document;
 
60
                                string fileName = files[curIndex].ToString();
 
61
                                foreach (Document doc in IdeApp.Workbench.Documents) {
 
62
                                        // WINDOWS DEPENDENCY : ToUpper
 
63
                                        if (doc.FileName != null &&
 
64
                                                doc.FileName.ContentName.ToUpper() == fileName.ToUpper()) {
 
65
                                                document = ((ITextEditorControlProvider)content).TextEditorControl.Document;
 
66
                                                return new ProvidedDocumentInformation(document,
 
67
                                                                                       fileName);
 
68
                                        }
 
69
                                }
 
70
                                ITextBufferStrategy strategy = null;
 
71
                                try {
 
72
                                        strategy = StringTextBufferStrategy.CreateTextBufferFromFile(fileName);
 
73
                                } catch (Exception) {
 
74
                                        TaskService taskService = (TaskService)MonoDevelop.Core.ServiceManager.Services.GetService(typeof(TaskService));
 
75
                                        taskService.Tasks.Add(new Task(String.Empty, "can't access " + fileName, -1, -1));
 
76
                                        return null;
 
77
                                }
 
78
                                return new ProvidedDocumentInformation(strategy, 
 
79
                                                                       fileName, 
 
80
                                                                       0);
 
81
                        }
 
82
                }
 
83
                
 
84
                public bool MoveForward() 
 
85
                {
 
86
                        if (curIndex == -1) {
 
87
                                FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService));
 
88
                                files = fileUtilityService.SearchDirectory(this.searchDirectory, this.fileMask, this.searchSubdirectories);
 
89
                        }
 
90
                        return ++curIndex < files.Count;
 
91
                }
 
92
                
 
93
                public bool MoveBackward()
 
94
                {
 
95
                        if (curIndex == -1) {
 
96
                                curIndex = files.Count - 1;
 
97
                                return true;
 
98
                        }
 
99
                        return --curIndex >= -1;
 
100
                }
 
101
                
 
102
                
 
103
                public void Reset() 
 
104
                {
 
105
                        curIndex = -1;
 
106
                }
 
107
        }
 
108
}