~cszikszoy/do-plugins/pastebin

« back to all changes in this revision

Viewing changes to Pastebin/src/PastebinAction.cs

  • Committer: djsiegel at gmail
  • Date: 2007-11-07 19:51:21 UTC
  • Revision ID: djsiegel@gmail.com-20071107195121-v1niznt43hkai3o1
Added some template files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//  PastebinAction.cs
2
 
//
3
 
//  GNOME Do is the legal property of its developers, whose names are too numerous
4
 
//  to list here.  Please refer to the COPYRIGHT file distributed with this
5
 
//  source distribution.
6
 
//
7
 
//  This program is free software: you can redistribute it and/or modify
8
 
//  it under the terms of the GNU General Public License as published by
9
 
//  the Free Software Foundation, either version 3 of the License, or
10
 
//  (at your option) any later version.
11
 
//
12
 
//  This program is distributed in the hope that it will be useful,
13
 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
//  GNU General Public License for more details.
16
 
//
17
 
//  You should have received a copy of the GNU General Public License
18
 
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 
 
20
 
using System;
21
 
using System.Collections.Generic;
22
 
using System.IO;
23
 
using System.Net;
24
 
using System.Text;
25
 
using System.Text.RegularExpressions;
26
 
 
27
 
using Do.Addins;
28
 
using Do.Universe;
29
 
 
30
 
using Mono.Unix;
31
 
 
32
 
namespace Do.Plugins.Pastebin
33
 
{
34
 
        public class PastebinAction : AbstractAction
35
 
        {
36
 
                public override string Name
37
 
                {
38
 
                        get { return Catalog.GetString ("Send to Pastebin"); }
39
 
                }
40
 
                
41
 
                public override string Description
42
 
                {
43
 
                        get { return Catalog.GetString ("Sends the text to Pastebin."); }
44
 
                }
45
 
                
46
 
                public override string Icon
47
 
                {
48
 
                        get { return "gtk-paste"; }
49
 
                }
50
 
                
51
 
                public override Type[] SupportedItemTypes
52
 
                {
53
 
                        get 
54
 
                        {
55
 
                                return new Type[] {
56
 
                                        typeof (ITextItem)
57
 
                                };
58
 
                        }
59
 
                }
60
 
                        
61
 
                public override bool ModifierItemsOptional
62
 
                {
63
 
                        get { return true; }
64
 
                }
65
 
                
66
 
                public override Type[] SupportedModifierItemTypes
67
 
                {
68
 
                        get 
69
 
                        {
70
 
                                return new Type[] {
71
 
                                        typeof (ITextSyntaxItem)
72
 
                                };
73
 
                        }
74
 
                }
75
 
                        
76
 
                public override IItem[] DynamicModifierItemsForItem (IItem item)
77
 
                {
78
 
                        try
79
 
                        {
80
 
                                Paste2 pastebinProvider = new Paste2 ();
81
 
                                List<IItem> items = new List<IItem> ();
82
 
 
83
 
                                foreach(IItem languageItem in pastebinProvider.SupportedLanguages)
84
 
                                        items.Add (languageItem);
85
 
                                                                                
86
 
                                return items.ToArray ();
87
 
                        }
88
 
                        catch
89
 
                        {
90
 
                                return null;
91
 
                        }
92
 
                }
93
 
                                
94
 
                public override IItem[] Perform (IItem[] items, IItem[] modifierItems)
95
 
                {               
96
 
                        string text = string.Empty;
97
 
                                        
98
 
                        foreach (IItem item in items)
99
 
                        {
100
 
                                        
101
 
                                text += (item as ITextItem).Text;
102
 
                        }
103
 
                        
104
 
                        Paste2 pastebinProvider = null;
105
 
                                        
106
 
                        if (modifierItems.Length > 0)
107
 
                        {
108
 
                                pastebinProvider = new Paste2 (text, (modifierItems[0] as ITextSyntaxItem).Syntax);
109
 
                        }
110
 
                        else
111
 
                        {
112
 
                                pastebinProvider = new Paste2 (text);           
113
 
                        }
114
 
                                        
115
 
                        string url = Pastebin.PostUsing (pastebinProvider);     
116
 
                                        
117
 
                        return new IItem[] { new TextItem (url) };
118
 
                }
119
 
                
120
 
        }
121
 
}
122
 
 
123