@@ -11,11 +11,28 @@ EnableExplicit
1111UsePNGImageDecoder()
1212
1313;------------------------------------------------------------------------------------
14- ;- Variables, Enumerations and Maps
14+ ;- Structures
15+ ;------------------------------------------------------------------------------------
16+ Structure Menu
17+ OpenIn.s
18+ Url.s
19+ Title.s
20+ EndStructure
21+
22+ Structure Configuration
23+ List Menus.Menu()
24+ EndStructure
25+
26+ ;------------------------------------------------------------------------------------
27+ ;- Variables, Enumerations, Lists and Maps
1528;------------------------------------------------------------------------------------
1629Global Event = #Null, Quit = #False
30+ Global Customization.Configuration
31+ #JSON_Parser = 0
32+
33+ ; Files
1734Global IndexFile.s = "file://" + GetCurrentDirectory() + "Web/src/index.html"
18- Global TeamViewerQuickSupport .s = "https://download.teamviewer.com/download/TeamViewerQS_x64.exe "
35+ Global ConfigurationFile .s = GetCurrentDirectory() + "Configuration.json "
1936
2037;------------------------------------------------------------------------------------
2138;- Forms
@@ -31,35 +48,81 @@ Procedure ShowMainWindow()
3148 BindEvent(#PB_Event_SizeWindow, @ResizeGadgetsMainWindow(), MainWindow)
3249EndProcedure
3350
34- Procedure ShowHome()
35- SetGadgetText(WebView_Index, IndexFile)
51+ Procedure LoadConfiguration()
52+ If LoadJSON(#JSON_Parser, ConfigurationFile)
53+ ;Debug "JSON object data from file:"
54+ ;Debug ComposeJSON(#JSON_Parser, #PB_JSON_PrettyPrint)
55+ ExtractJSONStructure(JSONValue(#JSON_Parser), Customization, Configuration)
56+ FreeJSON(#JSON_Parser)
57+ Else
58+ Debug "Can't read the configuration or the file is empty: " + ConfigurationFile
59+ EndIf
3660EndProcedure
3761
38- Procedure WebView_Home(EventType)
39- Debug "Inject JavaScript in WebView..."
40- FreeGadget(WebView_Index)
41- WebView_Index = WebViewGadget(#PB_Any, 0, 0, WindowWidth(MainWindow), WindowHeight(MainWindow)-3, #PB_WebView_Debug)
42- ShowHome()
62+ Procedure WebView_Home()
63+ Debug "WebView: Show Local File: " + IndexFile
64+ If IsGadget(WebView_Index) : SetGadgetText(WebView_Index, IndexFile) : EndIf
4365EndProcedure
4466
45- Procedure StartQuickAssist(EventType)
46- Debug "Starting Microsoft Quick Assist by Protocol..."
47- RunProgram("ms-quick-assist://")
67+ Procedure Menu_Quit()
68+ End
4869EndProcedure
4970
50- Procedure StartTeamViewerQS(EventType)
51- RunProgram(TeamViewerQuickSupport)
71+ Procedure Menu_EventHandler()
72+ Protected Entry = EventGadget(), i = 1
73+ Protected OpenIn.s, Url.s
74+
75+ ForEach Customization\Menus()
76+ If Entry = i
77+ OpenIn = Customization\Menus()\OpenIn
78+ Url = Customization\Menus()\Url
79+ EndIf
80+
81+ ; Counter
82+ i+1
83+ Next
84+
85+ Debug "Open-in ("+OpenIn+") with url: " + Url
86+ Select OpenIn
87+ Case "process":
88+ RunProgram(Url)
89+ Case "browser":
90+ If IsGadget(WebView_Index) : SetGadgetText(WebView_Index, Url) : EndIf
91+ EndSelect
92+
5293EndProcedure
5394
54- Procedure QuitApplication(EventType)
55- End
95+ Procedure BuildMenu()
96+ Protected i = 1
97+
98+ If CreateMenu(0, WindowID(MainWindow))
99+ MenuTitle("File")
100+
101+ ForEach Customization\Menus()
102+ MenuItem(i, Customization\Menus()\Title)
103+ BindMenuEvent(0, i, @Menu_EventHandler())
104+
105+ ; Counter
106+ i+1
107+ Next
108+
109+ MenuBar()
110+ MenuItem(98, "&Quit")
111+ BindMenuEvent(0, 98, @Menu_Quit())
112+
113+ MenuTitle("Browse")
114+ MenuItem(99, "Home")
115+ BindMenuEvent(0, 99, @WebView_Home())
116+ EndIf
56117EndProcedure
57118
58119;------------------------------------------------------------------------------------
59120;- Main Loop
60121;------------------------------------------------------------------------------------
61122ShowMainWindow()
62- ShowHome()
123+ LoadConfiguration()
124+ BuildMenu()
125+ WebView_Home()
63126
64127;------------------------------------------------------------------------------------
65128;- Event Loop
@@ -77,9 +140,10 @@ Repeat
77140 EndSelect
78141
79142Until Quit = #True
143+
80144; IDE Options = PureBasic 6.10 LTS (Windows - x64)
81- ; CursorPosition = 47
82- ; FirstLine = 22
83- ; Folding = - -
145+ ; CursorPosition = 89
146+ ; FirstLine = 44
147+ ; Folding = 1 -
84148; EnableXP
85149; DPIAware
0 commit comments