1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Drawing ; // for notifyicon
3
4
using System . Linq ;
4
5
using System . Text ;
5
6
using System . Threading . Tasks ;
@@ -20,6 +21,9 @@ namespace UnityLauncherPro
20
21
/// </summary>
21
22
public partial class MainWindow : Window
22
23
{
24
+
25
+ private System . Windows . Forms . NotifyIcon notifyIcon ;
26
+
23
27
public MainWindow ( )
24
28
{
25
29
InitializeComponent ( ) ;
@@ -29,10 +33,39 @@ public MainWindow()
29
33
void Start ( )
30
34
{
31
35
// test data
32
- dataGrid . Items . Add ( new TestData { Project = "asdf" , Version = "5000" , Path = "A:/" , Modified = DateTime . Now , Arguments = "" , GITBranch = "-" } ) ;
33
- dataGrid . Items . Add ( new TestData { Project = "asdf asd" , Version = "2" , Path = "C:/" , Modified = DateTime . Now , Arguments = "" , GITBranch = "-" } ) ;
34
- dataGrid . Items . Add ( new TestData { Project = "kuykkyu" , Version = "23.23.23" , Path = "8,1" , Modified = DateTime . Now , Arguments = "" , GITBranch = "-" } ) ;
35
- dataGrid . Items . Add ( new TestData { Project = "RT435y" , Version = "3333" , Path = "X:/" , Modified = DateTime . Now , Arguments = "" , GITBranch = "-" } ) ;
36
+ dataGrid . Items . Add ( new Project { Title = "asdf" , Version = "5000" , Path = "A:/" , Modified = DateTime . Now , Arguments = "" , GITBranch = "-" } ) ;
37
+ dataGrid . Items . Add ( new Project { Title = "asdf asd" , Version = "2" , Path = "C:/" , Modified = DateTime . Now , Arguments = "" , GITBranch = "-" } ) ;
38
+ dataGrid . Items . Add ( new Project { Title = "kuykkyu" , Version = "23.23.23" , Path = "8,1" , Modified = DateTime . Now , Arguments = "" , GITBranch = "-" } ) ;
39
+ dataGrid . Items . Add ( new Project { Title = "RT435y" , Version = "3333" , Path = "X:/" , Modified = DateTime . Now , Arguments = "" , GITBranch = "-" } ) ;
40
+
41
+ // build notifyicon
42
+ notifyIcon = new System . Windows . Forms . NotifyIcon ( ) ;
43
+ notifyIcon . Icon = new Icon ( System . Windows . Application . GetResourceStream ( new Uri ( "pack://application:,,,/Images/icon.ico" ) ) . Stream ) ;
44
+ notifyIcon . MouseClick += new System . Windows . Forms . MouseEventHandler ( NotifyIcon_MouseClick ) ;
45
+ }
46
+
47
+ void NotifyIcon_MouseClick ( object sender , System . Windows . Forms . MouseEventArgs e )
48
+ {
49
+ this . Show ( ) ;
50
+ this . WindowState = WindowState . Normal ;
51
+ notifyIcon . Visible = false ;
52
+ }
53
+
54
+ private void Window_StateChanged ( object sender , EventArgs e )
55
+ {
56
+ if ( this . WindowState == WindowState . Minimized )
57
+ {
58
+ this . ShowInTaskbar = false ;
59
+ notifyIcon . BalloonTipTitle = "Minimize Sucessful" ;
60
+ notifyIcon . BalloonTipText = "Minimized the app " ;
61
+ notifyIcon . ShowBalloonTip ( 400 ) ;
62
+ notifyIcon . Visible = true ;
63
+ }
64
+ else if ( this . WindowState == WindowState . Normal )
65
+ {
66
+ notifyIcon . Visible = false ;
67
+ this . ShowInTaskbar = true ;
68
+ }
36
69
}
37
70
38
71
@@ -65,7 +98,7 @@ private void BtnAddProjectFolder_Click(object sender, RoutedEventArgs e)
65
98
// https://stackoverflow.com/a/50261723/5452781
66
99
// Create a "Save As" dialog for selecting a directory (HACK)
67
100
var dialog = new Microsoft . Win32 . SaveFileDialog ( ) ;
68
- dialog . InitialDirectory = "c:" ; //textbox.Text; // Use current value for initial dir
101
+ dialog . InitialDirectory = "c:" ; // Use current value for initial dir
69
102
dialog . Title = "Select a Directory" ; // instead of default "Save As"
70
103
dialog . Filter = "Project Folder|*.Folder" ; // Prevents displaying files
71
104
dialog . FileName = "Project" ; // Filename will then be "select.this.directory"
@@ -81,7 +114,6 @@ private void BtnAddProjectFolder_Click(object sender, RoutedEventArgs e)
81
114
System . IO . Directory . CreateDirectory ( path ) ;
82
115
}
83
116
// Our final value is in path
84
- //textbox.Text = path;
85
117
Console . WriteLine ( path ) ;
86
118
}
87
119
}
@@ -90,18 +122,13 @@ private void BtnClose_Click(object sender, RoutedEventArgs e)
90
122
{
91
123
this . Close ( ) ;
92
124
}
93
- }
94
125
95
- public struct TestData
96
- {
97
- public string Project { set ; get ; }
98
- public string Version { set ; get ; }
99
- public string Path { set ; get ; }
100
- public DateTime Modified { set ; get ; }
101
- public string Arguments { set ; get ; }
102
- public string GITBranch { set ; get ; }
126
+ private void BtnMinimize_Click ( object sender , RoutedEventArgs e )
127
+ {
128
+ // remove focus from minimize button
129
+ dataGrid . Focus ( ) ;
130
+ notifyIcon . Visible = true ;
131
+ this . Hide ( ) ;
132
+ }
103
133
}
104
-
105
-
106
-
107
134
}
0 commit comments