Do

Merge lp:~cszikszoy/do/do-fix-copy into lp:do

Proposed by Chris S.
Status: Merged
Merged at revision: not available
Proposed branch: lp:~cszikszoy/do/do-fix-copy
Merge into: lp:do
Diff against target: None lines
To merge this branch: bzr merge lp:~cszikszoy/do/do-fix-copy
Reviewer Review Type Date Requested Status
Jason Smith (community) Approve
Review via email: mp+7476@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Chris S. (cszikszoy) wrote :

This branch fixes copying to the clipboard in a couple of ways:

* Remove GTK / GDK specific code from core (Do.Core.Controller.cs)
* Add CopyToClipboard as a method of Services.Environment
* Put linux specific (GTK / GDK) clipboard related code inside of Do.Platform.Linux.EnvironmentService.cs
* Adds item checking to copy action

lp:~cszikszoy/do/do-fix-copy updated
1220. By Chris S.

exception handling & logging

Revision history for this message
Jason Smith (jassmith) wrote :

Looks beautiful

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/EnvironmentService.cs'
2--- Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/EnvironmentService.cs 2009-01-21 01:40:49 +0000
3+++ Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/EnvironmentService.cs 2009-06-16 00:30:44 +0000
4@@ -26,7 +26,7 @@
5 using Mono.Unix;
6
7 using Do.Platform;
8-
9+using Do.Universe;
10
11 namespace Do.Platform.Linux
12 {
13@@ -86,6 +86,31 @@
14 Process.Start (line);
15 }
16 }
17+
18+ public void CopyToClipboard (Item item)
19+ {
20+ string text = "";
21+
22+ if (item is ITextItem)
23+ text = (item as ITextItem).Text;
24+ else if (item is IFileItem)
25+ text = (item as IFileItem).Path;
26+ else if (item is IUriItem)
27+ text = (item as IUriItem).Uri;
28+ else if (item is IUrlItem)
29+ text = (item as IUrlItem).Url;
30+ else if (item is IContactDetailItem)
31+ text = (item as IContactDetailItem).Value;
32+ else if (item is ContactItem)
33+ text = (item as ContactItem).Name;
34+ else
35+ text = string.Format ("{0} - {1}", item.Name, item.Description);
36+
37+ Gtk.Clipboard.Get (Gdk.Selection.Clipboard).Text =
38+ Gtk.Clipboard.Get (Gdk.Selection.Primary).Text = text;
39+
40+ Log.Debug ("Copied to clipboard, \"{0}\"", text);
41+ }
42
43 #endregion
44
45@@ -138,6 +163,5 @@
46 }
47 return false;
48 }
49-
50 }
51 }
52
53=== modified file 'Do.Platform.Linux/src/Do.Universe/CopyToClipboardAction.cs'
54--- Do.Platform.Linux/src/Do.Universe/CopyToClipboardAction.cs 2008-12-20 00:31:54 +0000
55+++ Do.Platform.Linux/src/Do.Universe/CopyToClipboardAction.cs 2009-06-16 00:30:44 +0000
56@@ -23,12 +23,10 @@
57 using System.Linq;
58 using System.Collections.Generic;
59
60-using Gtk;
61-using Gdk;
62-
63 using Mono.Unix;
64
65 using Do.Universe;
66+using Do.Platform;
67
68 namespace Do.Universe.Linux
69 {
70@@ -52,20 +50,18 @@
71 get { yield return typeof (Item); }
72 }
73
74+ public override bool SupportsItem (Item item)
75+ {
76+ return !(item is IApplicationItem);
77+ }
78+
79 public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems)
80 {
81- string text = "";
82 Item item = items.First ();
83-
84- if (item is ITextItem)
85- text = (item as ITextItem).Text;
86- else
87- text = string.Format ("{0} - {1}", item.Name, item.Description);
88
89- Clipboard.Get (Gdk.Selection.Clipboard).Text =
90- Clipboard.Get (Gdk.Selection.Primary).Text = text;
91+ Services.Environment.CopyToClipboard (item);
92
93- return null;
94+ yield break;
95 }
96 }
97 }
98
99=== modified file 'Do.Platform/src/Do.Platform/Do.Platform.Default/EnvironmentService.cs'
100--- Do.Platform/src/Do.Platform/Do.Platform.Default/EnvironmentService.cs 2008-12-04 18:49:59 +0000
101+++ Do.Platform/src/Do.Platform/Do.Platform.Default/EnvironmentService.cs 2009-06-16 00:30:44 +0000
102@@ -20,6 +20,8 @@
103 using System;
104 using System.Collections.Generic;
105
106+using Do.Universe;
107+
108 namespace Do.Platform.Default
109 {
110
111@@ -53,6 +55,11 @@
112 {
113 Log.Debug ("Default IEnvironmentService cannot execute \"{0}\".", line);
114 }
115+
116+ public void CopyToClipboard (Item item)
117+ {
118+ Log.Debug ("Default IEnvironmentService cannot copy \"{0}\".", item.Name);
119+ }
120
121 #endregion
122 }
123
124=== modified file 'Do.Platform/src/Do.Platform/IEnvironmentService.cs'
125--- Do.Platform/src/Do.Platform/IEnvironmentService.cs 2008-12-03 19:18:36 +0000
126+++ Do.Platform/src/Do.Platform/IEnvironmentService.cs 2009-06-16 00:30:44 +0000
127@@ -22,6 +22,8 @@
128 using System.Linq;
129 using System.Collections.Generic;
130
131+using Do.Universe;
132+
133 using Do.Platform.ServiceStack;
134
135 namespace Do.Platform
136@@ -37,6 +39,8 @@
137
138 bool IsExecutable (string line);
139 void Execute (string line);
140+
141+ void CopyToClipboard (Item item);
142 }
143
144 public static class IEnvironmentServiceExtensions
145
146=== modified file 'Do/src/Do.Core/Controller.cs'
147--- Do/src/Do.Core/Controller.cs 2009-05-16 06:15:14 +0000
148+++ Do/src/Do.Core/Controller.cs 2009-06-16 00:31:32 +0000
149@@ -477,9 +477,8 @@
150
151 void OnCopyEvent (EventKey evnt)
152 {
153- Gtk.Clipboard clip = Gtk.Clipboard.Get (Selection.Clipboard);
154- if (SearchController.Selection != null)
155- clip.Text = SearchController.Selection.Name;
156+ if (SearchController.Selection is Item)
157+ Services.Environment.CopyToClipboard (SearchController.Selection as Item);
158 }
159
160 void OnActivateKeyPressEvent (EventKey evnt)