@@ -42,7 +42,8 @@ namespace MonoDevelop.VersionControl.Views
4242 [ ToolboxItem ( true ) ]
4343 class ComparisonWidget : EditorCompareWidgetBase
4444 {
45- internal DropDownBox originalComboBox , diffComboBox ;
45+ internal ComboBox originalComboBox , diffComboBox ;
46+ ListStore revisionStore ;
4647
4748 public MonoTextEditor OriginalEditor {
4849 get {
@@ -56,13 +57,13 @@ public MonoTextEditor DiffEditor {
5657 }
5758 }
5859
59- public DropDownBox OriginalCombo {
60+ public ComboBox OriginalCombo {
6061 get {
6162 return originalComboBox ;
6263 }
6364 }
6465
65- public DropDownBox DiffCombo {
66+ public ComboBox DiffCombo {
6667 get {
6768 return diffComboBox ;
6869 }
@@ -88,38 +89,122 @@ protected override void CreateComponents ()
8889 } ;
8990
9091 if ( ! viewOnly ) {
91- originalComboBox = new DropDownBox ( ) ;
92- originalComboBox . WindowRequestFunc = CreateComboBoxSelector ;
93- originalComboBox . Text = GettextCatalog . GetString ( "Loading…" ) ;
92+ revisionStore = new ListStore ( typeof ( Revision ) , typeof ( string ) , typeof ( string ) , typeof ( string ) ) ;
93+ revisionStore . AppendValues ( GettextCatalog . GetString ( "Loading…" ) , "" , "" ) ;
94+
95+ originalComboBox = new ComboBox ( revisionStore ) ;
96+ originalComboBox . Changed += OriginalComboBox_Changed ;
97+ var revRenderer = new CellRendererText ( ) ;
98+ revRenderer . WidthChars = 62 ;
99+ originalComboBox . PackStart ( revRenderer , false ) ;
100+ originalComboBox . AddAttribute ( revRenderer , "text" , 1 ) ;
101+
102+ var timeRenderer = new CellRendererText ( ) ;
103+ timeRenderer . WidthChars = 21 ;
104+
105+ originalComboBox . PackStart ( timeRenderer , false ) ;
106+ originalComboBox . AddAttribute ( timeRenderer , "text" , 2 ) ;
107+
108+ var authorRenderer = new CellRendererText ( ) ;
109+ originalComboBox . PackStart ( authorRenderer , true ) ;
110+ originalComboBox . AddAttribute ( authorRenderer , "text" , 3 ) ;
111+
112+ // originalComboBox.AccessibilityTextFormat = GettextCatalog.GetString ("Select original revision, current: {0}");
113+ originalComboBox . Active = 0 ;
94114 originalComboBox . Sensitive = false ;
95- originalComboBox . Tag = editors [ 1 ] ;
96115
97- diffComboBox = new DropDownBox ( ) ;
98- diffComboBox . WindowRequestFunc = CreateComboBoxSelector ;
99- diffComboBox . Text = GettextCatalog . GetString ( "Loading…" ) ;
116+ diffComboBox = new ComboBox ( revisionStore ) ;
117+ diffComboBox . Changed += DiffComboBox_Changed ;
118+ diffComboBox . PackStart ( revRenderer , false ) ;
119+ diffComboBox . AddAttribute ( revRenderer , "text" , 1 ) ;
120+ diffComboBox . PackStart ( timeRenderer , false ) ;
121+ diffComboBox . AddAttribute ( timeRenderer , "text" , 2 ) ;
122+ diffComboBox . PackStart ( authorRenderer , true ) ;
123+ diffComboBox . AddAttribute ( authorRenderer , "text" , 3 ) ;
124+
125+ // diffComboBox.AccessibilityTextFormat = GettextCatalog.GetString ("Select diff revision, current: {0}");
126+ diffComboBox . Active = 0 ;
100127 diffComboBox . Sensitive = false ;
101- diffComboBox . Tag = editors [ 0 ] ;
102-
103128 this . headerWidgets = new [ ] { diffComboBox , originalComboBox } ;
104129 }
105130 }
106131
132+ void DiffComboBox_Changed ( object sender , EventArgs e )
133+ {
134+ Change ( DiffEditor , diffComboBox . Active ) ;
135+ }
136+
137+ void OriginalComboBox_Changed ( object sender , EventArgs e )
138+ {
139+ Change ( MainEditor , originalComboBox . Active ) ;
140+ }
141+
142+ void Change ( MonoTextEditor textEditor , int n )
143+ {
144+ if ( n == 0 ) {
145+ SetLocal ( textEditor . GetTextEditorData ( ) ) ;
146+ return ;
147+ }
148+
149+ RemoveLocal ( textEditor . GetTextEditorData ( ) ) ;
150+ textEditor . Document . IsReadOnly = true ;
151+
152+ if ( n == 1 ) {
153+ if ( textEditor == editors [ 0 ] ) {
154+ diffRevision = null ;
155+ } else {
156+ originalRevision = null ;
157+ }
158+ Task . Run ( async ( ) => {
159+ try {
160+ return await info . Item . Repository . GetBaseTextAsync ( info . Item . Path ) ;
161+ } catch ( Exception ex ) {
162+ var text = string . Format ( GettextCatalog . GetString ( "Error while getting the base text of {0}:\n {1}" ) , info . Item . Path , ex . ToString ( ) ) ;
163+ await Runtime . RunInMainThread ( ( ) => MessageService . ShowError ( text ) ) ;
164+ return text ;
165+ }
166+ } ) . ContinueWith ( t => {
167+ var editor = textEditor ;
168+ if ( editor . IsDisposed )
169+ return ;
170+ editor . Document . Text = t . Result ;
171+ CreateDiff ( ) ;
172+ } , Runtime . MainTaskScheduler ) ;
173+ return ;
174+ }
175+
176+ var rev = info . History [ n - 2 ] ;
177+ SetRevision ( textEditor , rev ) ;
178+ }
179+
107180 protected override void OnSetVersionControlInfo ( VersionControlDocumentInfo info )
108181 {
109182 info . Updated += OnInfoUpdated ;
110183 MainEditor . Document . IsReadOnly = false ;
111184 base . OnSetVersionControlInfo ( info ) ;
112185 }
113186
187+ const int LocalIndex = 0 ;
188+
189+ const int BaseIndex = 1 ;
190+
114191 void OnInfoUpdated ( object sender , EventArgs args )
115192 {
116- originalComboBox . Text = GettextCatalog . GetString ( "Local" ) ;
117- diffComboBox . Text = GettextCatalog . GetString ( "Base" ) ;
193+ revisionStore . Clear ( ) ;
194+ revisionStore . AppendValues ( null , GettextCatalog . GetString ( "Local" ) , "" , "" ) ;
195+ revisionStore . AppendValues ( null , GettextCatalog . GetString ( "Base" ) , "" , "" ) ;
196+ foreach ( var revision in info . History ) {
197+ revisionStore . AppendValues ( revision , revision . ToString ( ) , revision . Time . ToString ( ) , revision . Author ) ;
198+ }
199+ originalComboBox . Active = LocalIndex ;
200+ diffComboBox . Active = BaseIndex ;
118201 originalComboBox . Sensitive = diffComboBox . Sensitive = true ;
119202 }
120203
121204 protected override void OnDestroyed ( )
122205 {
206+ originalComboBox . Changed -= OriginalComboBox_Changed ;
207+ diffComboBox . Changed -= DiffComboBox_Changed ;
123208 info . Updated -= OnInfoUpdated ;
124209 base . OnDestroyed ( ) ;
125210 }
@@ -211,7 +296,12 @@ public void SetRevision (MonoTextEditor toEditor, Revision rev)
211296 Runtime . RunInMainThread ( ( ) => {
212297 var box = toEditor == editors [ 0 ] ? diffComboBox : originalComboBox ;
213298 RemoveLocal ( toEditor . GetTextEditorData ( ) ) ;
214- box . SetItem ( string . Format ( GettextCatalog . GetString ( "Revision {0}\t {1}\t {2}" ) , rev , rev . Time , rev . Author ) , null , rev ) ;
299+ for ( int i = 0 ; i < info . History . Length ; i ++ ) {
300+ if ( info . History [ i ] . Time == rev . Time ) {
301+ box . Active = 2 + i ;
302+ break ;
303+ }
304+ }
215305 toEditor . Text = text ;
216306 IdeApp . Workbench . StatusBar . AutoPulse = false ;
217307 IdeApp . Workbench . StatusBar . EndProgress ( ) ;
@@ -223,98 +313,5 @@ public void SetRevision (MonoTextEditor toEditor, Revision rev)
223313 }
224314
225315 internal Revision originalRevision , diffRevision ;
226-
227- class ComboBoxSelector : DropDownBoxListWindow . IListDataProvider
228- {
229- ComparisonWidget widget ;
230- DropDownBox box ;
231-
232- public ComboBoxSelector ( ComparisonWidget widget , DropDownBox box )
233- {
234- this . widget = widget ;
235- this . box = box ;
236-
237- }
238-
239- #region IListDataProvider implementation
240- public void Reset ( )
241- {
242- }
243-
244- public string GetMarkup ( int n )
245- {
246- if ( n == 0 )
247- return GettextCatalog . GetString ( "Local" ) ;
248- if ( n == 1 )
249- return GettextCatalog . GetString ( "Base" ) ;
250- Revision rev = widget . info . History [ n - 2 ] ;
251- return GLib . Markup . EscapeText ( string . Format ( "{0}\t {1}\t {2}" , rev , rev . Time , rev . Author ) ) ;
252- }
253-
254- public Xwt . Drawing . Image GetIcon ( int n )
255- {
256- return null ;
257- }
258-
259- public object GetTag ( int n )
260- {
261- if ( n < 2 )
262- return null ;
263- return widget . info . History [ n - 2 ] ;
264- }
265-
266- public void ActivateItem ( int n )
267- {
268- var textEditor = ( MonoTextEditor ) box . Tag ;
269- if ( n == 0 ) {
270- box . SetItem ( GettextCatalog . GetString ( "Local" ) , null , new object ( ) ) ;
271- widget . SetLocal ( textEditor . GetTextEditorData ( ) ) ;
272- return ;
273- }
274- widget . RemoveLocal ( textEditor . GetTextEditorData ( ) ) ;
275- textEditor . Document . IsReadOnly = true ;
276-
277- if ( n == 1 ) {
278- box . SetItem ( GettextCatalog . GetString ( "Base" ) , null , new object ( ) ) ;
279- if ( textEditor == widget . editors [ 0 ] ) {
280- widget . diffRevision = null ;
281- } else {
282- widget . originalRevision = null ;
283- }
284- Task . Run ( async ( ) => {
285- try {
286- return await widget . info . Item . Repository . GetBaseTextAsync ( widget . info . Item . Path ) ;
287- } catch ( Exception ex ) {
288- var text = string . Format ( GettextCatalog . GetString ( "Error while getting the base text of {0}:\n {1}" ) , widget . info . Item . Path , ex . ToString ( ) ) ;
289- await Runtime . RunInMainThread ( ( ) => MessageService . ShowError ( text ) ) ;
290- return text ;
291- }
292- } ) . ContinueWith ( t => {
293- var editor = ( MonoTextEditor ) box . Tag ;
294- if ( editor . IsDisposed )
295- return ;
296- editor . Document . Text = t . Result ;
297- widget . CreateDiff ( ) ;
298- } , Runtime . MainTaskScheduler ) ;
299- return ;
300- }
301-
302- Revision rev = widget . info . History [ n - 2 ] ;
303- widget . SetRevision ( textEditor , rev ) ;
304- }
305-
306- public int IconCount {
307- get {
308- return widget . info . History == null ? 2 : widget . info . History . Length + 2 ;
309- }
310- }
311- #endregion
312- }
313-
314- Gtk . Window CreateComboBoxSelector ( DropDownBox box )
315- {
316- DropDownBoxListWindow window = new DropDownBoxListWindow ( new ComboBoxSelector ( this , box ) ) ;
317- return window ;
318- }
319316 }
320317}
0 commit comments