1+ // Read Stanton SmartImage ShellMain.Dialog.cs
2+ // 2023-01-13 @ 11:28 PM
3+
4+ using System . Data ;
5+ using Kantan . Console ;
6+ using Novus . OS ;
7+ using NStack ;
8+ using SmartImage . App ;
9+ using SmartImage . Lib ;
10+ using SmartImage . Lib . Engines ;
11+ using SmartImage . Shell ;
12+ using Terminal . Gui ;
13+
14+ namespace SmartImage ;
15+
16+ public sealed partial class ShellMain
17+ {
18+ private void AboutDialog ( )
19+ {
20+ var d = new Dialog ( )
21+ {
22+ Text = $ "{ R2 . Name } { Integration . Version } by { R2 . Author } \n " +
23+ $ "Current directory: { Integration . CurrentAppFolder } ",
24+
25+ Title = R2 . Name ,
26+ AutoSize = true ,
27+ Width = UI . Dim_30_Pct ,
28+ Height = UI . Dim_30_Pct ,
29+ } ;
30+
31+ var b1 = UI . CreateLinkButton ( d , "Repo" , R2 . Repo_Url ) ;
32+ var b2 = UI . CreateLinkButton ( d , "Wiki" , R2 . Wiki_Url ) ;
33+ var b3 = UI . CreateLinkButton ( d , "Ok" , null , ( ) => Application . RequestStop ( ) ) ;
34+
35+ d . AddButton ( b1 ) ;
36+ d . AddButton ( b2 ) ;
37+ d . AddButton ( b3 ) ;
38+
39+ Application . Run ( d ) ;
40+ }
41+
42+ /// <summary>
43+ /// <see cref="Btn_Config"/>
44+ /// </summary>
45+ private void ConfigDialog ( )
46+ {
47+ var dlCfg = new Dialog ( "Configuration" )
48+ {
49+ Text = ustring . Empty ,
50+ AutoSize = false ,
51+ Width = UI . Dim_80_Pct ,
52+ Height = UI . Dim_80_Pct ,
53+ } ;
54+
55+ var btnRefresh = new Button ( "Refresh" ) { } ;
56+ var btnSave = new Button ( "Save" ) { } ;
57+ var btnOk = new Button ( "Ok" ) { } ;
58+
59+ const int WIDTH = 15 ;
60+ const int HEIGHT = 17 ;
61+
62+ /*============================================================================*\
63+ Engines
64+ \*============================================================================*/
65+
66+ Label lbSearchEngines = new ( R1 . S_SearchEngines )
67+ {
68+ X = 0 ,
69+ Y = 0 ,
70+ AutoSize = true ,
71+ ColorScheme = UI . Cs_Lbl1
72+ } ;
73+
74+ ListView lvSearchEngines = new ( UI . EngineOptions )
75+ {
76+ AllowsMultipleSelection = true ,
77+ AllowsMarking = true ,
78+ AutoSize = true ,
79+ Width = WIDTH ,
80+ Height = HEIGHT ,
81+
82+ Y = Pos . Bottom ( lbSearchEngines )
83+ } ;
84+
85+ Label lbPriorityEngines = new ( R1 . S_PriorityEngines )
86+ {
87+ X = Pos . Right ( lbSearchEngines ) + 1 ,
88+ Y = 0 ,
89+ AutoSize = true ,
90+ ColorScheme = UI . Cs_Lbl1
91+ } ;
92+
93+ ListView lvPriorityEngines = new ( UI . EngineOptions )
94+ {
95+ AllowsMultipleSelection = true ,
96+ AllowsMarking = true ,
97+ AutoSize = true ,
98+ Width = WIDTH ,
99+ Height = HEIGHT ,
100+
101+ Y = Pos . Bottom ( lbPriorityEngines ) ,
102+ X = Pos . Right ( lvSearchEngines ) + 1
103+ } ;
104+
105+ var cfgInfo = new FileInfo ( SearchConfig . Configuration . FilePath ) ;
106+
107+ Label lbConfig = new ( $ "Config")
108+ {
109+ X = Pos . Right ( lbPriorityEngines ) + 1 ,
110+ Y = 0 ,
111+ AutoSize = true ,
112+ ColorScheme = UI . Cs_Lbl1
113+ // Height = 10,
114+ } ;
115+
116+ lbConfig . Clicked += ( ) =>
117+ {
118+ FileSystem . ExploreFile ( cfgInfo . FullName ) ;
119+ } ;
120+
121+ DataTable dtConfig = Config . ToTable ( ) ;
122+
123+ var tvConfig = new TableView ( dtConfig )
124+ {
125+ AutoSize = true ,
126+ Y = Pos . Bottom ( lbConfig ) ,
127+ X = Pos . Right ( lvPriorityEngines ) + 1 ,
128+ Width = Dim . Fill ( WIDTH ) ,
129+ Height = 9 ,
130+ } ;
131+
132+ void ReloadDialog ( )
133+ {
134+ tvConfig . Table = Config . ToTable ( ) ;
135+ tvConfig . SetNeedsDisplay ( ) ;
136+ dlCfg . SetNeedsDisplay ( ) ;
137+ }
138+
139+ lvSearchEngines . OpenSelectedItem += args1 =>
140+ {
141+ SearchEngineOptions e = Config . SearchEngines ;
142+ UI . OnEngineSelected ( args1 , ref e , lvSearchEngines ) ;
143+ Config . SearchEngines = e ;
144+ ReloadDialog ( ) ;
145+ } ;
146+
147+ lvPriorityEngines . OpenSelectedItem += args1 =>
148+ {
149+ SearchEngineOptions e = Config . PriorityEngines ;
150+ UI . OnEngineSelected ( args1 , ref e , lvPriorityEngines ) ;
151+ Config . PriorityEngines = e ;
152+ ReloadDialog ( ) ;
153+ } ;
154+
155+ lvSearchEngines . FromEnum ( Config . SearchEngines ) ;
156+ lvPriorityEngines . FromEnum ( Config . PriorityEngines ) ;
157+
158+ /*============================================================================*\
159+ Checkboxes
160+ \*============================================================================*/
161+
162+ CheckBox cbContextMenu = new ( R2 . Int_ContextMenu )
163+ {
164+ X = Pos . X ( tvConfig ) ,
165+ Y = Pos . Bottom ( tvConfig ) + 1 ,
166+ Width = WIDTH ,
167+ Height = 1 ,
168+ ColorScheme = UI . Cs_Btn3
169+ } ;
170+
171+ cbContextMenu . Toggled += b =>
172+ {
173+ Integration . HandleContextMenu ( ! b ) ;
174+ } ;
175+
176+ Label lbHelp = new ( $ "{ UI . Line } Arrow keys or mouse :: select option\n " +
177+ $ "{ UI . Line } Space bar or click :: toggle mark option\n " +
178+ $ "{ UI . Line } Enter :: save option")
179+ {
180+ AutoSize = true ,
181+
182+ X = 0 ,
183+ Y = Pos . Bottom ( lvSearchEngines ) + 1
184+ } ;
185+
186+ CheckBox cbOnTop = new ( R1 . S_OnTop )
187+ {
188+ X = Pos . Right ( cbContextMenu ) + 1 ,
189+ Y = Pos . Y ( cbContextMenu ) ,
190+ AutoSize = true ,
191+ ColorScheme = UI . Cs_Btn3 ,
192+ Height = 1 ,
193+ } ;
194+
195+ cbOnTop . Toggled += b =>
196+ {
197+ Integration . KeepOnTop ( ! b ) ;
198+ Config . OnTop = Integration . IsOnTop ;
199+ ReloadDialog ( ) ;
200+ } ;
201+
202+ CheckBox cbAutoSearch = new ( R1 . S_AutoSearch )
203+ {
204+ X = Pos . Right ( cbOnTop ) + 1 ,
205+ Y = Pos . Y ( cbOnTop ) ,
206+ // Width = WIDTH,
207+ Height = 1 ,
208+ AutoSize = true ,
209+ ColorScheme = UI . Cs_Btn3
210+
211+ } ;
212+
213+ cbAutoSearch . Toggled += b =>
214+ {
215+ m_autoSearch = b ;
216+ ReloadDialog ( ) ;
217+ } ;
218+
219+ cbContextMenu . Checked = Integration . IsContextMenuAdded ;
220+ cbOnTop . Checked = Config . OnTop ;
221+
222+ /*============================================================================*\
223+ Eh username/password
224+ \*============================================================================*/
225+
226+ Label lbEhUsername = new ( R1 . S_EhUsername )
227+ {
228+ X = Pos . X ( cbContextMenu ) ,
229+ Y = Pos . Bottom ( cbContextMenu ) + 1 ,
230+ CanFocus = false ,
231+ ColorScheme = UI . Cs_Lbl1
232+ } ;
233+
234+ TextField tfEhUsername = new ( )
235+ {
236+ X = Pos . Right ( lbEhUsername ) + 1 ,
237+ Y = Pos . Y ( lbEhUsername ) ,
238+ Width = WIDTH * 2 ,
239+ Height = 1 ,
240+ } ;
241+
242+ tfEhUsername . TextChanging += args =>
243+ {
244+ Config . EhUsername = args . NewText . ToString ( ) ;
245+ ReloadDialog ( ) ;
246+ } ;
247+
248+ Label lbEhPassword = new ( R1 . S_EhPassword )
249+ {
250+ X = Pos . X ( lbEhUsername ) ,
251+ Y = Pos . Bottom ( lbEhUsername ) ,
252+ CanFocus = false ,
253+ ColorScheme = UI . Cs_Lbl1
254+ } ;
255+
256+ TextField tfEhPassword = new ( )
257+ {
258+ X = Pos . Right ( lbEhPassword ) + 1 ,
259+ Y = Pos . Y ( lbEhPassword ) ,
260+ Width = WIDTH * 2 ,
261+ Height = 1 ,
262+ } ;
263+
264+ tfEhPassword . TextChanging += args =>
265+ {
266+ Config . EhPassword = args . NewText . ToString ( ) ;
267+ ReloadDialog ( ) ;
268+ } ;
269+
270+ /*============================================================================*\
271+ Register
272+ \*============================================================================*/
273+
274+ btnRefresh . Clicked += ReloadDialog ;
275+
276+ btnOk . Clicked += ( ) =>
277+ {
278+ Application . RequestStop ( ) ;
279+ } ;
280+
281+ btnSave . Clicked += ( ) =>
282+ {
283+ Config . Save ( ) ;
284+ ReloadDialog ( ) ;
285+ } ;
286+
287+ dlCfg . Add ( tvConfig , lvSearchEngines , lvPriorityEngines ,
288+ cbContextMenu , cbOnTop , lbConfig , lbSearchEngines , lbPriorityEngines ,
289+ lbHelp , cbAutoSearch , lbEhUsername , tfEhUsername , lbEhPassword , tfEhPassword ) ;
290+
291+ dlCfg . AddButton ( btnRefresh ) ;
292+ dlCfg . AddButton ( btnOk ) ;
293+ dlCfg . AddButton ( btnSave ) ;
294+
295+ Application . Run ( dlCfg ) ;
296+
297+ Tf_Input . SetFocus ( ) ;
298+ Tf_Input . EnsureFocus ( ) ;
299+ }
300+ }
0 commit comments