forked from huggle/huggle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.vb
1841 lines (1513 loc) · 66.6 KB
/
Main.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'This is a source code or part of Huggle project
'Copyright (C) 2012 Huggle team
'This program is free software: you can redistribute it and/or modify
'it under the terms of the GNU General Public License as published by
'the Free Software Foundation, either version 3 of the License, or
'(at your option) any later version.
'This program is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'GNU General Public License for more details.
Imports System.IO
Imports System.Text
Imports System.Threading
Imports System.Web.HttpUtility
Class Main
Public Reverting, DisplayingEdit As Boolean
Private LoggingOut As Boolean
Public Shortcuts As Boolean = False
Public DisableControl As Boolean = True
Public ControlLock As Integer = 5
Public WatchP As Thread
Public HistorySelectionStart As Integer
'Timer is enabled when a key is pressed and prevents both MainForm.Main.KeyDown and
'BrowserTab.Browser.PreviewKeyDown being raised at the same time, which sometimes happens depending on
'what is currently focused in the browser and what was last focused outside it
Private WithEvents KeyDelayTimer As New Windows.Forms.Timer
Public Sub Initialize()
Icon = My.Resources.huggle_icon
TrayIcon.Icon = My.Resources.huggle_icon
KeyDelayTimer.Interval = 100
ScrollTimer.Interval = 1000 \ Config.HistoryScrollSpeed
'Temporary bugfix
If Config.RollbackSummary IsNot Nothing Then _
Config.RollbackSummary = Config.RollbackSummary.Replace("$1", "$3").Replace("$2", "$1").Replace("$3", "$2")
InitialTab.Parent = Tabs.TabPages(0)
CurrentTab = InitialTab
CurrentQueue = Queue.Default
SecondQueue = Queue.SecondDefault
Location = New Point(Math.Max(32, Config.WindowPosition.X), Math.Max(32, Config.WindowPosition.Y))
Size = New Size(Math.Max(Config.WindowSize.Width, MinimumSize.Width), _
Math.Max(Config.WindowSize.Height, MinimumSize.Height))
If Config.WindowMaximize Then WindowState = FormWindowState.Maximized Else WindowState = FormWindowState.Normal
SystemReconnectIRC.Enabled = Config.IrcMode
StartTime = Date.UtcNow
For Each Item As String In LogBuffer
Log(Item)
Next Item
WatchP = New Thread(AddressOf Control)
WatchP.Priority = Threading.ThreadPriority.Highest
DisableControl = False
UserBlockB.Enabled = True
WatchP.Start()
Configure()
End Sub
Sub DrawHistory()
Dim Break As Integer = 0
If CurrentPage Is Nothing Then Exit Sub
History.Page = CurrentPage
HistoryStrip.Refresh()
HistoryScrollRB.Enabled = (History.Offset > 0)
Dim Edit As Edit = CurrentPage.LastEdit
Dim X As Integer = History.Width - 18 + (History.Offset * 17)
Dim EnableScroll As Boolean
While Edit IsNot Nothing AndAlso Edit IsNot NullEdit And Break < Misc.GlExcess
If X < 0 Then
EnableScroll = True
Exit While
End If
X -= 17
Edit = Edit.Prev
Break = Break + 1
End While
If Break >= Misc.GlExcess Then Log("Debug DrawHistory()")
HistoryScrollLB.Enabled = EnableScroll
If CurrentPage.FirstEdit Is Nothing Then HistoryB.Enabled = True
End Sub
Sub WelcomeItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ThisI As ToolStripItem = CType(sender, ToolStripItem)
If Config.WelcomesList.ContainsKey(ThisI.Text) And CurrentUser IsNot Nothing Then
Dim NewRequest As New UserMessageRequest
NewRequest.User = CurrentUser
NewRequest.AutoSign = False
NewRequest.Message = Config.WelcomesList.Item(ThisI.Text)
NewRequest.Summary = Config.WelcomeSummary
NewRequest.Minor = Config.Minor("note")
NewRequest.Watch = Config.Watch("note")
NewRequest.AvoidText = "<!-- Template:Welcome"
NewRequest.Start()
End If
End Sub
Sub DrawContribs()
Dim Break As Integer = 0
If CurrentUser Is Nothing Then Exit Sub
Contribs.User = CurrentUser
ContribsStrip.Refresh()
ContribsScrollRB.Enabled = (Contribs.Offset > 0)
Dim Edit As Edit = CurrentUser.LastEdit
Dim X As Integer = Contribs.Width - 18 + (Contribs.Offset * 17)
Dim EnableScroll As Boolean
While Edit IsNot Nothing AndAlso Edit IsNot NullEdit And Break < Misc.GlExcess
Break = Break + 1
If X < 0 Then
EnableScroll = True
Exit While
End If
X -= 17
Edit = Edit.PrevByUser
End While
If Break >= Misc.GlExcess Then Log("Debug stop Main.DrawContribs()")
ContribsScrollLB.Enabled = EnableScroll
If CurrentEdit.User.FirstEdit Is Nothing Then ContribsB.Enabled = True
End Sub
Sub DrawQueues()
Dim Large As Integer = 0
If CurrentQueue IsNot Nothing AndAlso CurrentQueue.Edits IsNot Nothing AndAlso QueueContainer.Visible Then
Dim QueueHeight As Double = (QueueArea.Height \ 20) - 2
Large = Math.Max(1, Convert.ToInt32(QueueHeight))
If QueueHeight > 0 Then
If CInt(QueueHeight) < CurrentQueue.Edits.Count Then
QueueScroll.Enabled = True
If (CurrentQueue.Edits.Count - 2) >= 1 Then
QueueScroll.Maximum = CurrentQueue.Edits.Count - 2
End If
QueueScroll.Minimum = 0
QueueScroll.SmallChange = 1
If QueueScroll.Value > QueueScroll.Maximum Then
QueueScroll.Value = 1
End If
End If
QueueScroll.LargeChange = Large
Else
QueueScroll.Enabled = False
QueueScroll.Value = 1
End If
QueueArea.Draw(CurrentQueue, QueueScroll.Value)
End If
If SecondQueue IsNot Nothing AndAlso SecondQueue.Edits IsNot Nothing AndAlso QueueContainer.Visible _
AndAlso Config.ShowTwoQueues Then
Dim QueueHeight As Double = (QueueArea2.Height \ 20) - 2
Large = Math.Max(1, Convert.ToInt32(QueueHeight))
If QueueHeight > 0 Then
If CInt(QueueHeight) < SecondQueue.Edits.Count Then
QueueScroll2.Enabled = True
If (SecondQueue.Edits.Count - 2) >= 1 Then
QueueScroll2.Maximum = SecondQueue.Edits.Count - 2
End If
QueueScroll2.Minimum = 0
If QueueScroll2.Value > QueueScroll2.Maximum Then
QueueScroll2.Value = QueueScroll2.Minimum
End If
QueueScroll2.SmallChange = 1
QueueScroll2.LargeChange = Math.Max(1, Convert.ToInt32(QueueHeight))
Else
QueueScroll2.Enabled = False
QueueScroll2.Value = 1
End If
End If
QueueArea2.Draw(SecondQueue, QueueScroll2.Value)
End If
End Sub
Private Sub Main_ResizeShown() Handles Me.Resize, Me.Shown
Status.Columns(1).Width = Width - 30
HistoryStrip.Left = MainStrip.Right
ContribsStrip.Left = MainStrip.Right
HistoryStrip.Width = Width - MainStrip.Right - 3
ContribsStrip.Width = Width - MainStrip.Right - 3
History.Width = Width - MainStrip.Right - 330
Contribs.Width = Width - MainStrip.Right - 330
If Visible Then
DrawHistory()
DrawContribs()
End If
End Sub
Private Sub ShowStartupPage() Handles Me.Shown
If Config.StartupPage IsNot Nothing Then
Dim NewRequest As New BrowserRequest
NewRequest.NoFormatting = True
'
NewRequest.Url = SitePath() & "index.php?title=" & UrlEncode(Config.StartupPage) & "&action=render"
NewRequest.Start()
End If
End Sub
Private Sub Main_FormClosing() Handles Me.FormClosing
TrayIcon.Visible = False
Visible = False
If Not LoggingOut Then ClosingForm.ShowDialog()
End Sub
Private Sub Revert_Click() Handles RevertB.ButtonClick
DoRevert(CurrentEdit)
End Sub
Sub DiffNextB_Click() Handles QueueNext.Click, NextDiffB.Click
ShowNextEdit()
End Sub
Private Sub UserIgnore_Click() Handles UserIgnore.Click, UserIgnoreB.Click
If CurrentUser IsNot Nothing Then
If CurrentUser.Ignored Then UnignoreUser(CurrentUser) Else IgnoreUser(CurrentUser)
End If
End Sub
Public Sub IgnoreUser(ByVal User As User)
If User Is Nothing Then
Exit Sub
End If
'Sets the username to be ignored
User.Ignored = True
If Not WhitelistManualChanges.Contains(User.Name) Then WhitelistManualChanges.Add(User.Name)
'Says that the user will be ignored (in log)
Log("Ignored user '" & User.Name & "'")
'Add undo menu item
For Each Item As Command In Undo
If Item.Type = CommandType.Unignore AndAlso Item.User Is User Then
RemoveFromUndoList(Item)
Exit For
End If
Next Item
Dim NewCommand As New Command
NewCommand.User = User
NewCommand.Description = Msg("main-user-ignore") & " " & User.Name
NewCommand.Type = CommandType.Ignore
AddToUndoList(NewCommand)
If User Is CurrentUser Then
RefreshInterface()
DrawHistory()
End If
End Sub
Public Sub UnignoreUser(ByVal User As User)
If User Is Nothing Then
Exit Sub
End If
User.Ignored = False
If WhitelistManualChanges.Contains(User.Name) Then WhitelistManualChanges.Remove(User.Name)
If WhitelistAutoChanges.Contains(User.Name) Then WhitelistAutoChanges.Remove(User.Name)
Log("Unignored user '" & User.Name & "'")
'Add undo menu item
For Each Item As Command In Undo
If Item.Type = CommandType.Ignore AndAlso Item.User Is User Then
RemoveFromUndoList(Item)
Exit For
End If
Next Item
Dim NewCommand As New Command
NewCommand.User = User
NewCommand.Description = Msg("main-user-unignore") & " " & User.Name
NewCommand.Type = CommandType.Unignore
AddToUndoList(NewCommand)
If User Is User Then
RefreshInterface()
DrawHistory()
End If
End Sub
Private Sub HistoryPrev_Click() Handles HistoryPrevB.Click
If CurrentEdit IsNot Nothing Then
If CurrentEdit.Prev Is Nothing Then
Dim PreviousEdit As New Edit
PreviousEdit.Page = CurrentEdit.Page
PreviousEdit.Oldid = "prev"
PreviousEdit.Id = CurrentEdit.Oldid
PreviousEdit.Next = CurrentEdit
CurrentEdit.Prev = PreviousEdit
End If
DisplayEdit(CurrentEdit.Prev)
End If
End Sub
Private Sub HistoryNext_Click() Handles HistoryNextB.Click
If CurrentEdit IsNot Nothing Then
If CurrentEdit.Multiple Then
DisplayEdit(CurrentEdit.Prev.Next.Next)
Else
If CurrentEdit.Next Is Nothing Then
Dim NextEdit As New Edit
NextEdit.Page = CurrentEdit.Page
NextEdit.Oldid = CurrentEdit.Id
NextEdit.Id = "next"
NextEdit.Prev = CurrentEdit
CurrentEdit.Next = NextEdit
End If
DisplayEdit(CurrentEdit.Next)
End If
End If
End Sub
Private Sub HistoryLast_Click() Handles HistoryLastB.Click
If CurrentPage IsNot Nothing Then
If CurrentPage.LastEdit IsNot Nothing Then
DisplayEdit(CurrentPage.LastEdit)
Else
Dim NewEdit As New Edit
NewEdit.Page = CurrentPage
NewEdit.Id = "cur"
NewEdit.Oldid = "prev"
DisplayEdit(NewEdit)
End If
End If
End Sub
Private Sub ContribsPrev_Click() Handles ContribsPrevB.Click
If CurrentEdit IsNot Nothing AndAlso CurrentEdit.PrevByUser IsNot Nothing _
AndAlso CurrentEdit.PrevByUser IsNot NullEdit Then DisplayEdit(CurrentEdit.PrevByUser)
End Sub
Private Sub ContribsNext_Click() Handles ContribsNextB.Click
If CurrentEdit IsNot Nothing AndAlso CurrentEdit.NextByUser IsNot Nothing _
Then DisplayEdit(CurrentEdit.NextByUser)
End Sub
Private Sub ContribsLast_Click() Handles ContribsLastB.Click
If CurrentUser IsNot Nothing AndAlso CurrentEdit IsNot CurrentUser.LastEdit _
Then DisplayEdit(CurrentUser.LastEdit)
End Sub
Private Sub ContribsFirst()
If CurrentUser IsNot Nothing AndAlso CurrentUser.FirstEdit IsNot Nothing _
Then DisplayEdit(CurrentUser.FirstEdit)
End Sub
Private Sub HistoryFirst()
If CurrentPage IsNot Nothing AndAlso CurrentPage.FirstEdit IsNot Nothing _
Then DisplayEdit(CurrentPage.FirstEdit)
End Sub
Private Sub History_MouseDown(ByVal s As Object, ByVal e As MouseEventArgs) Handles History.MouseDown
If CurrentEdit IsNot Nothing Then
HistorySelectionStart = CInt((History.Width - e.X - 10) / 17) + History.Offset
If e.Button = MouseButtons.Left Then
History.NewerEdit = CurrentEdit
History.OlderEdit = CurrentEdit.Prev
DisplayHistoryItem(HistorySelectionStart)
ElseIf e.Button = MouseButtons.Right Then
History.NewerEdit = CurrentPage.LastEdit
Dim ThisEdit As Edit = CurrentPage.LastEdit
For i As Integer = 0 To HistorySelectionStart - 1
If ThisEdit.Prev Is Nothing OrElse ThisEdit.Prev Is NullEdit Then Exit Sub
ThisEdit = ThisEdit.Prev
Next i
History.OlderEdit = ThisEdit
ShowDiffToCur(ThisEdit)
End If
DrawHistory()
End If
End Sub
Private Sub History_MouseUp(ByVal s As Object, ByVal e As MouseEventArgs) Handles History.MouseUp
If CurrentEdit IsNot Nothing Then
If HistorySelectionStart > 0 AndAlso e.Button = MouseButtons.Left Then
Dim Position As Integer = CInt((History.Width - e.X - 10) / 17) + History.Offset
If Position <> HistorySelectionStart Then
Dim OlderEdit As Edit = CurrentPage.LastEdit
For i As Integer = 0 To Math.Max(Position, HistorySelectionStart) - 1
If OlderEdit.Prev Is Nothing OrElse OlderEdit.Prev Is NullEdit Then Exit Sub
OlderEdit = OlderEdit.Prev
Next i
History.OlderEdit = OlderEdit
Dim NewerEdit As Edit = CurrentPage.LastEdit
For i As Integer = 0 To Math.Min(Position, HistorySelectionStart) - 1
If NewerEdit.Prev Is Nothing OrElse NewerEdit.Prev Is NullEdit Then Exit Sub
NewerEdit = NewerEdit.Prev
Next i
History.NewerEdit = NewerEdit
ShowDiffBetween(OlderEdit, NewerEdit)
End If
HistorySelectionStart = 0
End If
End If
End Sub
Private Sub History_MouseMove(ByVal s As Object, ByVal e As MouseEventArgs) Handles History.MouseMove
If CurrentPage IsNot Nothing AndAlso CurrentPage.LastEdit IsNot Nothing Then
Dim Position As Integer = CInt((History.Width - e.X - 10) / 17) + History.Offset
Dim ThisEdit As Edit = CurrentPage.LastEdit
For i As Integer = 0 To Position - 1
If ThisEdit.Prev Is Nothing OrElse ThisEdit.Prev Is NullEdit Then
EditInfo.Visible = False
Exit Sub
End If
ThisEdit = ThisEdit.Prev
Next i
EditInfo.SetEdit(ThisEdit, EditInfoPanel.DisplayMode.PageName)
EditInfo.Left = Width - EditInfo.Width - 12
EditInfo.Top = 78
EditInfo.Visible = True
End If
End Sub
Private Sub HistoryContribs_MouseLeave() Handles History.MouseLeave, Contribs.MouseLeave
EditInfo.Visible = False
End Sub
Private Sub Contribs_MouseDown(ByVal s As Object, ByVal e As MouseEventArgs) Handles Contribs.MouseDown
If CurrentUser IsNot Nothing AndAlso CurrentUser.LastEdit IsNot Nothing Then
Dim Position As Integer = CInt((Contribs.Width - e.X - 10) / 17) + Contribs.Offset
Dim Edit As Edit = CurrentUser.LastEdit
For i As Integer = 0 To Position - 1
If Edit.PrevByUser Is Nothing OrElse Edit.PrevByUser Is NullEdit Then Exit Sub
Edit = Edit.PrevByUser
Next i
Contribs.SelectedEdit = Edit
DisplayEdit(Edit)
End If
DrawContribs()
End Sub
Private Sub Contribs_MouseMove(ByVal s As Object, ByVal e As MouseEventArgs) Handles Contribs.MouseMove
If CurrentUser IsNot Nothing AndAlso CurrentUser.LastEdit IsNot Nothing Then
Dim Position As Integer = CInt((Contribs.Width - e.X - 10) / 17) + Contribs.Offset
Dim Edit As Edit = CurrentUser.LastEdit
For i As Integer = 0 To Position - 1
If Edit.PrevByUser Is Nothing OrElse Edit.PrevByUser Is NullEdit Then
EditInfo.Visible = False
Exit Sub
End If
Edit = Edit.PrevByUser
Next i
EditInfo.SetEdit(Edit, EditInfoPanel.DisplayMode.UserName)
EditInfo.Left = Width - EditInfo.Width - 12
EditInfo.Top = 78
EditInfo.Visible = True
End If
End Sub
Private Sub ViewHistory_Click() Handles PageHistory.Click, HistoryB.Click
If CurrentPage IsNot Nothing Then
Dim NewHistoryRequest As New HistoryRequest
NewHistoryRequest.Page = CurrentPage
NewHistoryRequest.Start(AddressOf GotHistory)
End If
End Sub
Private Sub GotHistory(ByVal Result As RequestResult)
If Not Result.Error Then DrawHistory()
End Sub
Private Sub UserContribs_Click() Handles UserContribs.Click, ContribsB.Click
If CurrentUser IsNot Nothing Then
Dim NewRequest As New ContribsRequest
NewRequest.User = CurrentUser
NewRequest.Start(AddressOf GotContribs)
End If
End Sub
Private Sub GotContribs(ByVal Result As RequestResult)
If Not Result.Error Then
DrawHistory()
DrawContribs()
End If
End Sub
Private Sub HistoryScrollTimer_Tick() Handles ScrollTimer.Tick
If ScrollTimer.Tag Is HistoryScrollLB Then HistoryLeft()
If ScrollTimer.Tag Is HistoryScrollRB Then HistoryRight()
If ScrollTimer.Tag Is ContribsScrollLB Then ContribsLeft()
If ScrollTimer.Tag Is ContribsScrollRB Then ContribsRight()
End Sub
Private Sub HistoryScroll_MouseDown(ByVal Sender As Object, ByVal e As MouseEventArgs) _
Handles HistoryScrollLB.MouseDown, HistoryScrollRB.MouseDown
ScrollTimer.Tag = Sender
ScrollTimer.Start()
End Sub
Private Sub HistoryScroll_MouseUp(ByVal Sender As Object, ByVal e As MouseEventArgs) _
Handles HistoryScrollLB.MouseUp, HistoryScrollRB.MouseUp
If Sender Is HistoryScrollLB Then HistoryLeft() Else HistoryRight()
ScrollTimer.Stop()
End Sub
Private Sub ContribsScroll_MouseDown(ByVal Sender As Object, ByVal e As MouseEventArgs) _
Handles ContribsScrollLB.MouseDown, ContribsScrollRB.MouseDown
ScrollTimer.Tag = Sender
ScrollTimer.Start()
End Sub
Private Sub ContribsScroll_MouseUp(ByVal Sender As Object, ByVal e As MouseEventArgs) _
Handles ContribsScrollLB.MouseUp, ContribsScrollRB.MouseUp
If Sender Is ContribsScrollLB Then ContribsLeft() Else ContribsRight()
ScrollTimer.Stop()
End Sub
Sub HistoryLeft()
If HistoryScrollLB.Enabled Then
History.Offset += 1
DrawHistory()
If Not HistoryScrollLB.Enabled Then ScrollTimer.Stop()
End If
End Sub
Sub HistoryRight()
If HistoryScrollRB.Enabled Then
If History.Offset > 0 Then
History.Offset -= 1
DrawHistory()
End If
If Not HistoryScrollRB.Enabled Then ScrollTimer.Stop()
End If
End Sub
Sub ContribsLeft()
If ContribsScrollLB.Enabled Then
Contribs.Offset += 1
DrawContribs()
If Not ContribsScrollLB.Enabled Then ScrollTimer.Stop()
End If
End Sub
Sub ContribsRight()
If ContribsScrollRB.Enabled Then
If Contribs.Offset > 0 Then
Contribs.Offset -= 1
DrawContribs()
End If
If Not ContribsScrollRB.Enabled Then ScrollTimer.Stop()
End If
End Sub
Sub PageViewLatest_Click() Handles PageViewLatest.Click
If CurrentPage IsNot Nothing Then DisplayUrl _
(SitePath() & "index.php?title=" & UrlEncode(CurrentPage.Name.Replace(" ", "_")))
End Sub
Sub PageView_Click() Handles PageViewB.Click, RevisionView.Click
If CurrentEdit IsNot Nothing AndAlso CurrentPage IsNot Nothing Then DisplayUrl _
(SitePath() & "index.php?title=" & UrlEncode(CurrentPage.Name) & "&oldid=" & CurrentEdit.Id)
End Sub
Private Sub DiffRevertSummary_Click() Handles RevertAdvanced.Click
If CurrentEdit IsNot Nothing AndAlso CurrentEdit.Prev IsNot Nothing Then
Dim NewRevertForm As New RevertForm
NewRevertForm.Edit = CurrentEdit
If NewRevertForm.ShowDialog = DialogResult.OK Then
RevertB.Enabled = False
RevertWarnB.Enabled = False
Reverting = True
RevertTimer.Interval = 5000
RevertTimer.Start()
End If
End If
End Sub
Private Sub RevertTimer_Tick() Handles RevertTimer.Tick
RevertTimer.Stop()
Reverting = False
If CurrentEdit IsNot Nothing Then
RevertB.Enabled = True
If CurrentEdit.User IsNot Nothing AndAlso Not CurrentEdit.User.Ignored Then RevertWarnB.Enabled = True
End If
End Sub
Private Sub SystemExit_Click() Handles SystemExit.Click
Close()
End Sub
Private Sub UserTalk_Click() Handles UserTalk.Click, UserTalkB.Click
If CurrentEdit IsNot Nothing AndAlso CurrentEdit.User IsNot Nothing Then
Dim NewBrowserRequest As New BrowserRequest
NewBrowserRequest.Tab = CurrentTab
NewBrowserRequest.Url = SitePath() & "index.php?title=" & UrlEncode(CurrentUser.TalkPage.Name)
NewBrowserRequest.Start()
Dim NewWarnLevelRequest As New WarningLogRequest
NewWarnLevelRequest.User = CurrentEdit.User
NewWarnLevelRequest.Start()
End If
End Sub
Private Sub HistoryScrollLast_Click()
If History.Offset > 0 Then
History.Offset = 0
DrawHistory()
End If
End Sub
Private Sub ContribsScrollLast_Click()
If Contribs.Offset > 0 Then
Contribs.Offset = 0
DrawContribs()
End If
End Sub
Private Sub RcReqTimer_Tick() Handles RcReqTimer.Tick
If Not Config.IrcMode Then
RcReqTimer.Stop()
Dim NewRcApiRequest As New RcApiRequest
NewRcApiRequest.Start()
End If
End Sub
Private Sub UserMessage_Click() _
Handles UserMessage.Click, UserMessageB.Click, UserMessageOther.Click
If CurrentUser IsNot Nothing Then
Dim NewMessageForm As New MessageForm
NewMessageForm.User = CurrentUser
NewMessageForm.ShowDialog()
End If
End Sub
Private Sub Warn_Click() Handles WarnAdvanced.Click
If CurrentUser IsNot Nothing Then
Dim NewWarningForm As New WarningForm
NewWarningForm.User = CurrentUser
If NewWarningForm.ShowDialog() = DialogResult.OK Then WarnB.Enabled = False
End If
End Sub
Private Sub RevertWarnB_ButtonClick() Handles RevertWarnB.ButtonClick
RevertAndWarn()
End Sub
Public Sub RevertAndWarn(Optional ByVal WarnType As String = "warning", _
Optional ByVal Level As UserLevel = UserLevel.None, Optional ByVal Summary As String = Nothing, _
Optional ByVal CurrentOnly As Boolean = False)
Try
Dim summ2 As String = "_"
If Summary IsNot Nothing Then
If Config.TemplateSummary.ContainsKey(Summary) Then
summ2 = Config.TemplateSummary(Summary).Replace("$1", CurrentEdit.User.Name)
Else
If Config.WarningTypes.ContainsKey(Summary) Then
summ2 = Config.RevertSummary
Else
summ2 = Summary
End If
End If
If summ2 <> "_" Then Summary = summ2
End If
If CurrentEdit IsNot Nothing AndAlso CurrentEdit.Prev IsNot Nothing Then
'Get confirmation if needed
If Config.ConfirmMultiple AndAlso CurrentEdit.User IsNot Nothing _
AndAlso CurrentEdit.User Is CurrentEdit.Prev.User _
AndAlso MessageBox.Show("This will revert multiple edits by '" & CurrentEdit.User.Name & "'. Continue?", _
"Huggle", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then Exit Sub
If DoRevert(CurrentEdit, Summary, CurrentOnly:=CurrentOnly) Then
'Be sure not to warn twice for the same edit
Dim i As Integer = 0
While i < PendingWarnings.Count - 1
If PendingWarnings(i).Page Is CurrentEdit.Page Then PendingWarnings.RemoveAt(i) Else i += 1
End While
If Level <> UserLevel.None Then CurrentEdit.LevelToWarn = Level
CurrentEdit.TypeToWarn = WarnType
PendingWarnings.Add(CurrentEdit)
'If AutoAdvance is turned on in the config then Show the next edit
If Config.AutoAdvance Then ShowNextEdit()
End If
End If
Catch ex As Exception
End Try
End Sub
Private Sub EditPage_Click() Handles PageEdit.Click, PageEditB.Click
If CurrentPage IsNot Nothing Then
Dim NewEditForm As New EditForm
NewEditForm.Page = CurrentPage
NewEditForm.Show()
End If
End Sub
Private Sub TagPage_Click() Handles PageTagB.Click, PageTag.Click
If CurrentEdit.Page IsNot Nothing Then
Dim NewTagForm As New TagForm
NewTagForm.Page = CurrentEdit.Page
NewTagForm.ToSpeedy.Enabled = PageTagSpeedy.Enabled
NewTagForm.ToProd.Enabled = PageTagProd.Enabled
NewTagForm.ShowDialog()
End If
End Sub
Sub TagSpeedy_Click() Handles PageTagSpeedy.Click
If CurrentPage IsNot Nothing Then
Dim NewSpeedyTagForm As New SpeedyForm
NewSpeedyTagForm.Page = CurrentPage
NewSpeedyTagForm.ShowDialog()
End If
End Sub
Sub PageDelete_Click() Handles PageDelete.Click, PageDeleteB.Click
If CurrentPage IsNot Nothing Then
Dim NewDeleteForm As New DeleteForm
NewDeleteForm.Page = CurrentPage
NewDeleteForm.Show()
End If
End Sub
Sub PageTagProd_Click() Handles PageTagProd.Click
If CurrentEdit IsNot Nothing AndAlso CurrentPage IsNot Nothing Then
Dim NewForm As New ProdForm
NewForm.Page = CurrentPage
NewForm.ShowDialog()
End If
End Sub
Private Sub PageMove_Click() Handles PageMove.Click
If CurrentEdit IsNot Nothing AndAlso CurrentEdit.Page IsNot Nothing Then
Dim NewMovePageForm As New MoveForm
NewMovePageForm.Page = CurrentEdit.Page
If NewMovePageForm.ShowDialog = DialogResult.OK Then
Dim NewMoveRequest As New MoveRequest
NewMoveRequest.Page = CurrentEdit.Page
NewMoveRequest.Target = NewMovePageForm.Target.Text
NewMoveRequest.Summary = NewMovePageForm.Reason.Text
NewMoveRequest.Start()
End If
End If
End Sub
Sub Log(ByVal Message As String, Optional ByVal Tag As Object = Nothing, _
Optional ByVal InProgress As Boolean = False)
Dim NewItem As New ListViewItem
If InProgress Then NewItem.ForeColor = Color.Red
If Tag IsNot Nothing Then NewItem.Tag = Tag
NewItem.SubItems.Add(Date.Now.Year.ToString & "-" & Date.Now.Month.ToString.PadLeft(2, "0"c) _
& "-" & Date.Now.Day.ToString.PadLeft(2, "0"c) & " " & Date.Now.ToLongTimeString _
& UtcOffset() & " -- " & Message)
If InProgress Then
Status.Items.Insert(0, NewItem)
Else
Dim i As Integer = 0
While i < Status.Items.Count
If Status.Items(i).ForeColor <> Color.Red Then
Status.Items.Insert(i, NewItem)
Exit Sub
End If
i += 1
End While
Status.Items.Insert(0, NewItem)
End If
UpdateCancelButton()
End Sub
Sub Delog(ByVal Request As Request)
Dim Break As Integer = 0
Dim i As Integer = 0
Status.BeginUpdate()
While i < Status.Items.Count And Break < Misc.GlExcess
Break = Break + 1
If Status.Items(i).ForeColor = Color.Red AndAlso Status.Items(i).Tag Is Request _
Then Status.Items.RemoveAt(i) Else i += 1
End While
Status.EndUpdate()
UpdateCancelButton()
End Sub
Private Sub UpdateCancelButton()
Dim CancellableRequests As Boolean
For Each Item As ListViewItem In Status.Items
If Item.ForeColor = Color.Red Then
CancellableRequests = True
Exit For
End If
Next Item
CancelB.Enabled = CancellableRequests
End Sub
Function UtcOffset() As String
If TimeZone.CurrentTimeZone.GetUtcOffset(Date.Now).TotalMinutes = 0 Then Return "" _
Else Return " (" & CStr(If(TimeZone.CurrentTimeZone.GetUtcOffset(Date.Now).Minutes < 0, "-", "+")) _
& CStr(TimeZone.CurrentTimeZone.GetUtcOffset(Date.Now).Hours).PadLeft(2, "0"c) & ":" _
& CStr(TimeZone.CurrentTimeZone.GetUtcOffset(Date.Now).Minutes).PadLeft(2, "0"c) & ")"
End Function
Private Sub GoBack_Click() _
Handles BrowserBack.Click, BrowserBackB.ButtonClick
CurrentTab.HistoryBack()
End Sub
Private Sub GoForward_Click() _
Handles BrowserForward.Click, BrowserForwardB.ButtonClick
CurrentTab.HistoryForward()
End Sub
Private Sub SystemShowNewMessages_Click() Handles SystemMessages.Click
DisplayEdit(User.Me.TalkPage.LastEdit)
SystemMessages.Enabled = False
End Sub
Sub BlockUser(ByVal ThisUser As User)
On Error Resume Next
If ThisUser IsNot Nothing And ThisUser.Name IsNot Nothing Then
Dim NewBlockForm As New BlockForm
NewBlockForm.User = ThisUser
NewBlockForm.Show()
Else
Debug.Write("No user")
End If
End Sub
Sub ReportUser(ByVal User As User, Optional ByVal Edit As Edit = Nothing)
Dim NewUserReport As New ReportForm
NewUserReport.User = User
NewUserReport.Edit = Edit
NewUserReport.Show()
End Sub
Private Sub HistoryDiffToCur_Click() Handles HistoryDiffToCurB.Click
If CurrentEdit IsNot Nothing AndAlso CurrentEdit.Prev IsNot Nothing Then ShowDiffToCur(CurrentEdit.Prev)
End Sub
Private Sub WatchPage_Click() Handles PageWatch.Click, PageWatchB.Click
If CurrentEdit IsNot Nothing AndAlso CurrentEdit.Page IsNot Nothing Then
If Watchlist.Contains(CurrentEdit.Page.SubjectPage) Then
Dim NewRequest As New UnwatchRequest
NewRequest.Page = CurrentEdit.Page.SubjectPage
NewRequest.Manual = True
NewRequest.Start()
Else
Dim NewRequest As New WatchRequest
NewRequest.Page = CurrentEdit.Page.SubjectPage
NewRequest.Manual = True
NewRequest.Start()
End If
End If
End Sub
Private Sub LogContextCopy_Click() Handles LogCopy.Click
If Status.SelectedIndices.Count > 0 _
Then Clipboard.SetText(Status.Items(Status.SelectedIndices(0)).SubItems(1).Text)
End Sub
Private Sub TrayRestore_Click() Handles TrayRestore.Click
Visible = Not Visible
If Visible Then TrayRestore.Text = Msg("minimizewindow") Else TrayRestore.Text = Msg("restorewindow")
End Sub
Private Sub TrayExit_Click() Handles TrayExit.Click
Close()
End Sub
Private Sub TrayIcon_DoubleClick() Handles TrayIcon.DoubleClick
TrayRestore_Click()
End Sub
Private Sub TrayIcon_BalloonTipClicked() Handles TrayIcon.BalloonTipClicked
If SystemMessages.Enabled Then SystemShowNewMessages_Click()
If Not Visible Then TrayRestore_Click()
End Sub
Private Sub Tabs_SelectedIndexChanged() Handles Tabs.SelectedIndexChanged
If Tabs.SelectedTab IsNot Nothing Then
CType(Tabs.SelectedTab.Controls(0), BrowserTab).Highlight = False
CurrentTab = CType(Tabs.SelectedTab.Controls(0), BrowserTab)
Tabs.SelectedTab.Font = Me.Font
Tabs.SelectedTab.ForeColor = Color.Black
PageB.Text = CurrentEdit.Page.Name
UserB.Text = CurrentEdit.User.Name
DrawHistory()
DrawContribs()
BrowserBackB.DropDown = CurrentTab.BackMenu
BrowserForwardB.DropDown = CurrentTab.ForwardMenu
RefreshInterface()
End If
End Sub
Private Sub NewTab_Click() _
Handles BrowserNewTab.Click, BrowserNewTabB.Click
If CurrentEdit IsNot Nothing AndAlso CurrentEdit.Page IsNot Nothing Then
Dim NewTabPage As New TabPage
Dim NewBrowserTab As New BrowserTab
NewBrowserTab.Parent = NewTabPage
NewBrowserTab.ShowNewEdits = Config.ShowNewEdits
NewBrowserTab.ShowNewContribs = False
NewBrowserTab.Edit = CurrentEdit
NewTabPage.Controls.Add(NewBrowserTab)
NewTabPage.Controls(0).Dock = DockStyle.Fill
NewTabPage.Text = CurrentEdit.Page.Name
Tabs.ItemSize = New Size(150, 22)
Tabs.TabPages.Add(NewTabPage)
Tabs.SelectedTab = NewTabPage
BrowserCloseTabB.Enabled = True
BrowserCloseOthers.Enabled = True
BrowserCloseTab.Enabled = True
End If
End Sub
Private Sub CloseTab_Click() _
Handles BrowserCloseTab.Click, BrowserCloseTabB.Click
Dim SelectedIndex As Integer = Tabs.SelectedIndex
If SelectedIndex > 0 Then Tabs.SelectedIndex = (SelectedIndex - 1)
Tabs.TabPages.RemoveAt(SelectedIndex)
If Tabs.TabPages.Count = 1 Then
Tabs.ItemSize = New Size(1, 1)
BrowserCloseTabB.Enabled = False
BrowserCloseOthers.Enabled = False
BrowserCloseTab.Enabled = False
End If
End Sub