forked from gdevic/GitForce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormMain.cs
More file actions
836 lines (724 loc) · 32.3 KB
/
Copy pathFormMain.cs
File metadata and controls
836 lines (724 loc) · 32.3 KB
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
using System;
using System.Diagnostics;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using GitForce.Main.Left.Panels;
using GitForce.Main.Right.Panels;
namespace GitForce
{
public partial class FormMain : Form
{
#region Initialization
// This simply registers repo's status refresh function at the head of the refresh chain
private static readonly ClassStatus Status = new ClassStatus();
// Left panels
private static readonly PanelView PanelView = new PanelView();
// Right panels
private static readonly PanelRepos PanelRepos = new PanelRepos();
private static readonly PanelCommits PanelCommits = new PanelCommits();
private static readonly PanelRevlist PanelRevlist = new PanelRevlist();
private static readonly PanelBranches PanelBranches = new PanelBranches();
private static readonly Dictionary<string, UserControl> PanelsR = new Dictionary<string, UserControl> {
{ "Repos", PanelRepos },
{ "Commits", PanelCommits },
{ "Revisions", PanelRevlist },
{ "Branches", PanelBranches },
};
private static readonly Dictionary<string, string> PanelsRShortcuts = new Dictionary<string, string> {
{ "Repos", "F10" },
{ "Commits", "F6" },
{ "Revisions", "F7" },
{ "Branches", "F8"},
};
/// <summary>
/// Flags to use when calling SelectiveRefresh function
/// </summary>
[Flags]
public enum SelectveRefreshFlags
{
View = 1,
Repos = 2,
Commits = 4,
Revisions = 8,
Branches = 16,
All = 31
}
// Path to the default custom tools file
private static readonly string DefaultCustomToolsFile = Path.Combine(App.AppHome, "CustomTools.xml");
/// <summary>
/// This is the main entry point to the application main form. Doing all the initialization here.
/// </summary>
public FormMain()
{
InitializeComponent();
ClassWinGeometry.Restore(this);
// WAR: On Linux, remove status bar resizing grip (since it does not work under X)
if (ClassUtils.IsMono())
statusStrip.SizingGrip = false;
// Initialize panels
// Left panel:
splitContainer2.Panel1.Controls.Add(PanelView);
PanelView.Dock = DockStyle.Fill;
// Right set of panels:
foreach (var panel in PanelsR)
{
var tabPage = new TabPage(panel.Key) { Name = panel.Key, ToolTipText = panel.Key + " (" + PanelsRShortcuts[panel.Key] + ")" };
panel.Value.Dock = DockStyle.Fill;
tabPage.Controls.Add(panel.Value);
rightTabControl.TabPages.Add(tabPage);
}
// Show or hide command line
menuViewCommandLine.Checked = cmdBox.Visible = Properties.Settings.Default.ShowCommandLine;
// Enable SSH only if the PuTTY support class has been instantiated
if (App.Putty != null)
{
btSsh.Enabled = true;
menuMainManageKeys.Enabled = true;
}
// We prevent Log window form closing by getting a FormClosing event within which we set "e.Cancel" to True
App.Log.FormClosing += LogWindowToolStripMenuItemClick;
menuViewLogWindow.Checked = Properties.Settings.Default.ShowLogWindow;
// Add all callback handlers
App.Refresh += FormMainRefresh; // Refresh, when any component wants to update the global state
App.PrintStatusMessage += PrintStatus; // Print a line of status message
App.StatusBusy += SetBusy; // Busy flag set or reset
// Register toolbar file buttons with the View panel
PanelView.RegisterToolstripFileButtons(new Dictionary
<PanelView.FileOps, ToolStripButton>
{
{ PanelView.FileOps.Add, btAdd },
{ PanelView.FileOps.Update, btUpdate },
{ PanelView.FileOps.UpdateAll, btUpdateAll },
{ PanelView.FileOps.Revert, btRevert },
{ PanelView.FileOps.Delete, btDelete },
{ PanelView.FileOps.DeleteFs, btDeleteFs },
{ PanelView.FileOps.Edit, btEdit }
});
PrintStatus("GitForce version " + ClassVersion.GetVersion());
// Load default set of repositories
ClassWorkspace.Load(null);
// Load custom tools
App.CustomTools = ClassCustomTools.Load(DefaultCustomToolsFile);
// If there is no current repo, switch the right panel view to Repos
// Otherwise, restore the last view panel
ChangeRightPanel(App.Repos.Current == null ?
"Repos" :
Properties.Settings.Default.viewRightPanel);
// Initiate the first global refresh
App.DoRefresh();
}
/// <summary>
/// Form is closing
/// </summary>
private void FormMainFormClosing(object sender, FormClosingEventArgs e)
{
// Remove the print status handler
App.PrintStatusMessage -= PrintStatus;
// Store geometry of _this_ window
ClassWinGeometry.Save(this);
// Save custom tools to their default location
App.CustomTools.Save(DefaultCustomToolsFile);
// Close the log windown manually in order to save its geometry
App.Log.FormClosing -= LogWindowToolStripMenuItemClick;
App.Log.Close();
// Save windows geometry database
ClassWinGeometry.SaveGeometryDatabase();
// Save current workspace
ClassWorkspace.Save(null);
// Remove all outstanding temp files
ClassGlobals.RemoveTempFiles();
}
/// <summary>
/// Exit command - route to form closing handler
/// </summary>
private void MenuExit(object sender, EventArgs e)
{
Close();
}
#endregion
/// <summary>
/// Main File menu drop down
/// </summary>
private void MenuMainFileDropDownOpening(object sender, EventArgs e)
{
menuMainFile.DropDownItems.Clear();
menuMainFile.DropDownItems.AddRange(PanelView.GetContextMenu(menuMainFile.DropDown));
// Add the workspace menu items
ToolStripMenuItem mWkClear = new ToolStripMenuItem("Clear Workspace", null, WorkspaceClearMenuItem);
ToolStripMenuItem mWkLoad = new ToolStripMenuItem("Load Workspace...", null, WorkspaceLoadMenuItem);
ToolStripMenuItem mWkSave = new ToolStripMenuItem("Save Workspace As...", null, WorkspaceSaveMenuItem);
ToolStripMenuItem mWkLru = new ToolStripMenuItem("Recent Workspaces", null, WorkspaceLoadLruMenuItem);
ToolStripMenuItem mExit = new ToolStripMenuItem("Exit", null, MenuExit, Keys.Alt | Keys.F4);
// Fill in the last recently used workspace list of items
List<string> lru = ClassWorkspace.GetLRU();
foreach (var file in lru)
mWkLru.DropDownItems.Add(new ToolStripMenuItem(file, null, WorkspaceLoadLruMenuItem) { Tag = file });
mWkLru.Enabled = lru.Count > 0;
mWkSave.Enabled = App.Repos.Current != null;
menuMainFile.DropDownItems.AddRange(new ToolStripItem[] {
new ToolStripSeparator(),
mWkClear, mWkLoad, mWkSave, mWkLru,
new ToolStripSeparator(),
mExit });
}
/// <summary>
/// Clear current workspace
/// </summary>
private void WorkspaceClearMenuItem(object sender, EventArgs e)
{
// Save existing workspace before zapping it
if(MessageBox.Show("Current workspace will be cleared from all git repositories. Continue?",
"Clear Workspace", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)==DialogResult.Yes)
{
if (ClassWorkspace.Save(null))
ClassWorkspace.Clear();
}
}
/// <summary>
/// Select and load a specific workspace
/// </summary>
private void WorkspaceLoadMenuItem(object sender, EventArgs e)
{
if (loadWk.ShowDialog() == DialogResult.OK)
{
// Save existing workspace before trying to load a new one
if (ClassWorkspace.Save(null))
if (ClassWorkspace.Load(loadWk.FileName))
App.DoRefresh();
}
}
/// <summary>
/// Load a workspace selected by the last recently used menu
/// </summary>
private void WorkspaceLoadLruMenuItem(object sender, EventArgs e)
{
string name = (sender as ToolStripMenuItem).Tag as string;
// Save existing workspace before trying to load a new one
if (ClassWorkspace.Save(null))
if (ClassWorkspace.Load(name))
App.DoRefresh();
}
/// <summary>
/// Save current workspace
/// </summary>
private void WorkspaceSaveMenuItem(object sender, EventArgs e)
{
if(saveWk.ShowDialog()==DialogResult.OK)
ClassWorkspace.Save(saveWk.FileName);
}
/// <summary>
/// Menu "View" has been opened. Set the bullet next to the current view mode.
/// </summary>
private void MenuMainViewDropDownOpened(object sender, EventArgs e)
{
int mode = Properties.Settings.Default.viewMode;
// Set the correct bullet
List<ToolStripMenuItem> viewMenus = new List<ToolStripMenuItem> {
menuView0, menuView1, menuView2, menuView3, menuView4 };
foreach (var m in viewMenus)
m.Checked = false;
viewMenus[mode].Checked = true;
}
/// <summary>
/// Set the view mode by sending a menu item whose Tag contains the mode number.
/// This function is called from a menu handlers that select view mode.
/// </summary>
private void ViewSetByMenuItem(object sender, EventArgs e)
{
PanelView.ViewSetByMenuItem(sender, e);
}
/// <summary>
/// Switch the view mode to Local File View and Local Pending Changelists.
/// Needed to be reset that way after creating a new repo.
/// </summary>
public void ResetViews()
{
PanelView.SetView(3);
ChangeRightPanel("Commits");
}
/// <summary>
/// This function is called when user changes a right panel
/// </summary>
private void ChangeRightPanel(string panelName)
{
rightTabControl.SelectTab(panelName);
Properties.Settings.Default.viewRightPanel = panelName;
}
private void RightPanelSelectionClick(object sender, EventArgs e)
{
ChangeRightPanel(((ToolStripItem)sender).Tag.ToString());
}
/// <summary>
/// Print into the status pane (and the aux log window).
/// It is ok to send null or empty string.
/// Strings that contain Newline will be broken into separate lines.
/// This function is thread-safe.
/// </summary>
private void PrintStatus(string message)
{
if(string.IsNullOrEmpty(message))
return;
if (listStatus.InvokeRequired)
listStatus.BeginInvoke((MethodInvoker)(() => PrintStatus(message)));
else
{
// Add each line of the message individually
foreach (string line in message.Split(new[] { Environment.NewLine }, StringSplitOptions.None))
{
// Prepend the current time, if that option is requested, in either 12 or 24-hr format
string stamp = Properties.Settings.Default.logTime
? DateTime.Now.ToString(Properties.Settings.Default.logTime24
? "HH:mm:ss"
: "hh:mm:ss") + " "
: "";
listStatus.Items.Add(stamp + line);
}
listStatus.TopIndex = listStatus.Items.Count - 1;
App.PrintLogMessage(message);
}
}
/// <summary>
/// Set the info message into the main form status line (located at the bottom)
/// </summary>
public void SetStatusText(string infoMessage)
{
statusInfoLabel.Text = infoMessage;
}
/// <summary>
/// Set the window title
/// </summary>
public void SetTitle(string title)
{
// Set the title and wait one time slice for it to be painted
Text = title;
Application.DoEvents();
}
/// <summary>
/// Set or clear the busy flag (small "stop" icon on the toolbar)
/// Use timer to turn the GUI elements off to avoid rapid on/off cycles
/// caused by a number of successive toggles. Store the true state of busy-ness
/// in the timerTick.Tag, so when the tick triggers, it will know what was the
/// true busy state.
/// </summary>
private void SetBusy(bool isBusy)
{
// If the signal is to clear the busy flag, arm the timer to do it few ms later
if( isBusy==false)
{
timerBusy.Interval = 300;
timerBusy.Enabled = true;
}
else
{
Cursor = Cursors.WaitCursor;
btCancelOperation.Enabled = true;
Application.DoEvents(); // Give app the chance to redraw the icon
}
timerBusy.Tag = isBusy;
}
/// <summary>
/// Busy signal timer tick handler
/// </summary>
private void TimerBusyTick(object sender, EventArgs e)
{
if((bool)timerBusy.Tag==false)
{
Cursor = Cursors.Default;
btCancelOperation.Enabled = false;
timerBusy.Enabled = false;
Application.DoEvents(); // Give app the chance to redraw the icon
}
}
/// <summary>
/// Refresh main form items, part of the global refresh chain
/// </summary>
private void FormMainRefresh()
{
// Change the window title and display the default remote name
StringBuilder title = new StringBuilder("GitForce ");
// Enable new version button if there is a new version available
btNewVersion.Visible = App.Version.NewVersionAvailable;
menuMainStash.Enabled = menuMainUnstash.Enabled = false;
// Do specific enables based on the availability of the current repo
if (App.Repos.Current != null)
{
menuMainStash.Enabled = menuMainUnstash.Enabled = true;
title.Append("- " + App.Repos.Current.Branches.Current);
if (App.Repos.Current.Remotes.Current != "")
title.Append(" : " + App.Repos.Current.Remotes.Current);
}
Text = title.ToString();
// Build the menu with the list of remote repos
menuMainPushToRemote.Enabled = menuMainPullFromRemote.Enabled = menuMainFetchFromRemote.Enabled =
menuMainEditRemoteRepo.Enabled = menuMainSwitchRemoteRepo.Enabled = false;
btPull.Enabled = btPush.Enabled = false;
menuMainSwitchRemoteRepo.DropDownItems.Clear();
if (App.Repos.Current != null && App.Repos.Current.Remotes.Current != "")
{
List<string> remotes = App.Repos.Current.Remotes.GetListNames();
foreach (string s in remotes)
{
// Create a new menu items for each remote repository
ToolStripMenuItem m = new ToolStripMenuItem(s, null, RemoteChanged) {Checked = false};
menuMainSwitchRemoteRepo.DropDownItems.Add(m);
// For the current repository, add a checkmark and enable corresponding
// menus for push and pull both in the menu and tool box buttons
if (App.Repos.Current.Remotes.Current == s)
{
m.Checked = true;
if (!string.IsNullOrEmpty(App.Repos.Current.Remotes.Get(s).UrlPush))
menuMainPushToRemote.Enabled = btPush.Enabled = true;
if (!string.IsNullOrEmpty(App.Repos.Current.Remotes.Get(s).UrlFetch))
menuMainPullFromRemote.Enabled = menuMainFetchFromRemote.Enabled = btPull.Enabled = true;
}
}
menuMainSwitchRemoteRepo.Enabled = true;
}
if (App.Repos.Current != null)
menuMainEditRemoteRepo.Enabled = true;
}
/// <summary>
/// Selectively refreshes only specified panels
/// </summary>
public void SelectiveRefresh(SelectveRefreshFlags flags)
{
// Always refresh the class status first
ClassStatus.Refresh();
if ((flags & SelectveRefreshFlags.View) == SelectveRefreshFlags.View)
PanelView.ViewRefresh();
if ((flags & SelectveRefreshFlags.Repos) == SelectveRefreshFlags.Repos)
PanelRepos.ReposRefresh();
if ((flags & SelectveRefreshFlags.Commits) == SelectveRefreshFlags.Commits)
PanelCommits.CommitsRefresh();
if ((flags & SelectveRefreshFlags.Revisions) == SelectveRefreshFlags.Revisions)
PanelRevlist.RevlistRefresh();
if ((flags & SelectveRefreshFlags.Branches) == SelectveRefreshFlags.Branches)
PanelBranches.BranchesRefresh();
}
/// <summary>
/// Switch the remote repo. The new repo name is given as sender name.
/// </summary>
private void RemoteChanged(object sender, EventArgs e)
{
PrintStatus("Changed remote repository to " + sender);
App.Repos.Current.Remotes.Current = sender.ToString();
FormMainRefresh();
}
/// <summary>
/// Settings menu selected
/// </summary>
private void MenuOptions(object sender, EventArgs e)
{
FormSettings frmOptions = new FormSettings();
frmOptions.ShowDialog();
}
/// <summary>
/// Refresh Active Pane (do a global refresh for now)
/// </summary>
private void MenuRefreshAll(object sender, EventArgs e)
{
App.DoRefresh();
}
/// <summary>
/// Edit the list of remote repositories
/// </summary>
private void MenuEditRemoteRepos(object sender, EventArgs e)
{
FormRemoteEdit remoteEdit = new FormRemoteEdit(App.Repos.Current);
if (remoteEdit.ShowDialog() == DialogResult.OK)
App.DoRefresh();
}
/// <summary>
/// Fetch from a remote repository
/// </summary>
private void MenuRepoFetch(object sender, EventArgs e)
{
string args = App.Repos.Current.Remotes.Current + " " + App.Repos.Current.Branches.Current;
PrintStatus("Fetch from a remote repo: " + args);
App.Repos.Current.RunCmd("fetch " + args);
}
/// <summary>
/// Pull from a remote repository
/// </summary>
private void MenuRepoPull(object sender, EventArgs e)
{
string args = App.Repos.Current.Remotes.Current + " " + App.Repos.Current.Branches.Current;
PrintStatus("Pull from a remote repo: " + args);
App.Repos.Current.RunCmd("pull " + args);
}
/// <summary>
/// Push to remote repository.
/// Use either the standard form (example: "origin master"), or the user override
/// </summary>
private void MenuRepoPush(object sender, EventArgs e)
{
string args = App.Repos.Current.Remotes.GetPushCmd("");
if (String.IsNullOrEmpty(args))
args = App.Repos.Current.Remotes.Current + " " + App.Repos.Current.Branches.Current;
PrintStatus("Push to a remote repo: " + args);
App.Repos.Current.RunCmd("push " + args);
}
/// <summary>
/// Toggle the execute window between Show and Hide states. This form should not
/// be closed as it accumulates all log messages even when hidden.
/// </summary>
private void LogWindowToolStripMenuItemClick(object sender, EventArgs e)
{
bool @checked = menuViewLogWindow.Checked;
Properties.Settings.Default.ShowLogWindow = menuViewLogWindow.Checked = !@checked;
App.Log.ShowWindow(!@checked);
// We prevent Execute form closing by servicing a FormExecute.FormClosing event with this event,
// so disable closure by setting Cancel to true only if the caller used that type of arguments
if (e is FormClosingEventArgs)
(e as FormClosingEventArgs).Cancel = true;
}
/// <summary>
/// Toggle the Command Line edit box between Show and Hide states.
/// </summary>
private void MenuViewCommandLineClick(object sender, EventArgs e)
{
bool @checked = menuViewCommandLine.Checked;
Properties.Settings.Default.ShowCommandLine = menuViewCommandLine.Checked = !@checked;
cmdBox.Visible = !@checked;
// This is purely cosmetic: pushes the list pane text up to cleanly reveal the tail
listStatus.TopIndex = listStatus.Items.Count - 1;
}
/// <summary>
/// Create Repository menu drop down
/// </summary>
private void MenuMainRepositoryDropDownOpening(object sender, EventArgs e)
{
menuMainRepository.DropDownItems.Clear();
menuMainRepository.DropDownItems.AddRange(PanelRepos.GetContextMenu(menuMainRepository.DropDown));
ToolStripMenuItem mRepos = new ToolStripMenuItem("View Repos", null, RightPanelSelectionClick, Keys.F10) {Tag = "Repos"};
menuMainRepository.DropDownItems.AddRange(new ToolStripItem[] { mRepos });
}
/// <summary>
/// Create Branches menu drop down
/// </summary>
private void MenuMainBranchDropDownOpening(object sender, EventArgs e)
{
menuMainBranch.DropDownItems.Clear();
menuMainBranch.DropDownItems.AddRange(PanelBranches.GetContextMenu(menuMainBranch.DropDown));
ToolStripMenuItem mRefresh = new ToolStripMenuItem("View Branches", null, RightPanelSelectionClick, Keys.F8) {Tag = "Branches"};
menuMainBranch.DropDownItems.AddRange(new ToolStripItem[] { new ToolStripSeparator(), mRefresh });
}
/// <summary>
/// Changelist menu drop down
/// </summary>
private void MenuMainChangelistDropDownOpening(object sender, EventArgs e)
{
// Add the menu items from the commit pane followed menu items from the revisions pane
menuMainChangelist.DropDownItems.Clear();
menuMainChangelist.DropDownItems.AddRange(PanelCommits.GetContextMenu(menuMainChangelist.DropDown, null));
// Add the revision list menu only if the revlist right pane is active
if (Properties.Settings.Default.viewRightPanel == "Revisions")
menuMainChangelist.DropDownItems.AddRange(PanelRevlist.GetContextMenu(menuMainChangelist.DropDown));
ToolStripMenuItem mPending = new ToolStripMenuItem("View Pending Changelists", null, RightPanelSelectionClick, Keys.F6) {Tag = "Commits"};
ToolStripMenuItem mSubmitted = new ToolStripMenuItem("View Submitted Changelists", null, RightPanelSelectionClick, Keys.F7) {Tag = "Revisions"};
menuMainChangelist.DropDownItems.AddRange(new ToolStripItem[] { new ToolStripSeparator(), mPending, mSubmitted });
}
/// <summary>
/// Select all files on the left pane
/// </summary>
private void MenuMainSelectAllClick(object sender, EventArgs e)
{
PanelView.SelectAll();
}
#region Status menu handlers
/// <summary>
/// Right-click on the status menu selected Copy command
/// </summary>
private void MenuStatusCopyClick(object sender, EventArgs e)
{
StringBuilder buffer = new StringBuilder();
foreach (int i in listStatus.SelectedIndices)
buffer.Append(listStatus.Items[i]).Append(Environment.NewLine);
if (buffer.Length > 0)
Clipboard.SetText(buffer.ToString());
}
/// <summary>
/// Right-click on the status menu selected Select-All command
/// </summary>
private void MenuStatusSelectAllClick(object sender, EventArgs e)
{
for (int i = 0; i < listStatus.Items.Count; i++)
listStatus.SetSelected(i, true);
}
/// <summary>
/// Right-click on the status menu selected Clear command
/// </summary>
private void MenuSelectClearClick(object sender, EventArgs e)
{
listStatus.Items.Clear();
}
#endregion
/// <summary>
/// Manage SSH Keys
/// </summary>
private void MenuMainManageKeysClick(object sender, EventArgs e)
{
FormSSH formSsh = new FormSSH();
formSsh.ShowDialog();
}
/// <summary>
/// User clicked on a Website menu item, open the website
/// </summary>
private void WebsiteClick(object sender, EventArgs e)
{
Process.Start((sender as ToolStripMenuItem).Tag.ToString());
}
/// <summary>
/// Stops any currently executing git command thread
/// </summary>
private void BtCancelOperationClick(object sender, EventArgs e)
{
// TODO: Does this control get the thread to run on when a command is executing?
// ClassExecute.KillJob();
}
/// <summary>
/// Show the standard About box
/// </summary>
private void AboutToolStripMenuItemClick(object sender, EventArgs e)
{
FormAbout about = new FormAbout();
about.ShowDialog();
}
/// <summary>
/// User clicked on the Stash menu item
/// </summary>
private void MenuMainStashClick(object sender, EventArgs e)
{
FormStash formStash = new FormStash();
if (formStash.ShowDialog() == DialogResult.OK)
App.DoRefresh();
}
/// <summary>
/// User clicked on the Unstash menu item
/// </summary>
private void MenuMainUnstashClick(object sender, EventArgs e)
{
FormUnstash formUnstash = new FormUnstash();
if (formUnstash.ShowDialog() == DialogResult.OK)
App.DoRefresh();
}
#region Custom Tools menu handlers
/// <summary>
/// Custom Tools menu drop down, build the menu
/// </summary>
private void MenuMainToolsDropDownOpening(object sender, EventArgs e)
{
// Add menu items that are always there, following by tools items
menuMainTools.DropDownItems.Clear();
menuMainTools.DropDownItems.AddRange(new ToolStripItem[] {
new ToolStripMenuItem("Customize", null, CustomizeToolMenuItemClick),
new ToolStripMenuItem("Import", null, ImportToolMenuItemClick),
new ToolStripMenuItem("Export", null, ExportToolMenuItemClick) });
// Add all custom tools to the tools menu
if(App.CustomTools.Tools.Count>0)
{
menuMainTools.DropDownItems.Add(new ToolStripSeparator());
foreach (var tool in App.CustomTools.Tools)
menuMainTools.DropDownItems.Add(new ToolStripMenuItem(tool.Name, null, CustomToolClicked) {Tag = tool});
}
}
/// <summary>
/// User clicked on the Tools' Customize menu item
/// </summary>
private void CustomizeToolMenuItemClick(object sender, EventArgs e)
{
FormCustomizeTools formCustomizeTools = new FormCustomizeTools(App.CustomTools);
if (formCustomizeTools.ShowDialog() == DialogResult.OK)
App.CustomTools = formCustomizeTools.CustomTools.Copy();
}
/// <summary>
/// Import a set of custom tools from a file
/// </summary>
private void ImportToolMenuItemClick(object sender, EventArgs e)
{
if(openTools.ShowDialog()==DialogResult.OK)
{
ClassCustomTools newTools = ClassCustomTools.Load(openTools.FileName);
if (newTools != null)
{
App.CustomTools = newTools;
App.PrintStatusMessage("Loaded custom tools from " + openTools.FileName);
}
}
}
/// <summary>
/// Export current set of custom tools to a file
/// </summary>
private void ExportToolMenuItemClick(object sender, EventArgs e)
{
if (saveTools.ShowDialog() == DialogResult.OK)
{
if (App.CustomTools.Save(saveTools.FileName))
App.PrintStatusMessage("Saved custom tools to " + saveTools.FileName);
}
}
/// <summary>
/// A specific custom tool is clicked (selected).
/// Tag contains the tool class.
/// </summary>
private void CustomToolClicked(object sender, EventArgs e)
{
// Call the panel view's custom tool handling function
PanelView.CustomToolClicked(sender, e);
}
#endregion
/// <summary>
/// Getting started help menu
/// </summary>
private void GettingStartedToolStripMenuClick(object sender, EventArgs e)
{
ClassHelp.Handler("Getting Started");
}
/// <summary>
/// User clicked on a 'new version available' button
/// </summary>
private void NewVersionButtonClick(object sender, EventArgs e)
{
ClassHelp.Handler("Download");
}
/// <summary>
/// Callback on the command line text ready.
/// We execute a custom (immediate) command which can be either a direct git
/// command or a shell (command prompt?) command.
/// Several commands may be separated by "&&" token. This accomodates Gerrit
/// code review process and its shortcuts that can be easily pasted.
/// </summary>
private void CmdBoxTextReady(object sender, string cmd)
{
foreach (string command in cmd.Split(new[] {" && "}, StringSplitOptions.RemoveEmptyEntries))
{
// Print out the command itself
App.PrintStatusMessage(command);
// If the command text started with a command 'git', remove it
string[] tokens = command.Split(' ');
string args = String.Join(" ", tokens, 1, tokens.Count() - 1);
// We are guaranteed to have at least one token (by the TextBoxEx control)
string run;
if (tokens[0].ToLower() == "git")
{
// Command is a git command: execute it
run = ClassGit.Run(args).ToString();
}
else
{
// Command is an arbitrary (command line type) command
// Use the command shell to execute it
run = ClassUtils.ExecuteShellCommand(tokens[0], args);
}
App.PrintStatusMessage(run);
}
}
}
}