Bearsampp 2026.9.23
Loading...
Searching...
No Matches
class.action.changeBrowser.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2026 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
18{
20 private $wbWindow;
22 private $wbLabelExp;
30 private $wbBtnBrowse;
34 private $wbBtnSave;
36 private $wbBtnCancel;
37
39 const GAUGE_SAVE = 2;
40
48 public function __construct($args)
49 {
50 global $bearsamppConfig, $bearsamppLang, $bearsamppWinbinder;
51
52 $bearsamppWinbinder->reset();
53 $this->wbWindow = $bearsamppWinbinder->createAppWindow($bearsamppLang->getValue(Lang::CHANGE_BROWSER_TITLE), 490, 350, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP);
54
55 $this->wbLabelExp = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_BROWSER_EXP_LABEL), 15, 15, 470, 50);
56
57 $currentBrowser = $bearsamppConfig->getBrowser();
58 $this->wbRadioButton[] = $bearsamppWinbinder->createRadioButton($this->wbWindow, $currentBrowser, true, 15, 40, 470, 20, true);
59
60 $yPos = 70;
61 $installedBrowsers = Win32Native::getInstalledBrowsers();
62 foreach ($installedBrowsers as $installedBrowser) {
63 if ($installedBrowser != $currentBrowser) {
64 $this->wbRadioButton[] = $bearsamppWinbinder->createRadioButton($this->wbWindow, $installedBrowser, false, 15, $yPos, 470, 20);
65 $yPos += 30;
66 }
67 }
68
69 $this->wbRadioButtonOther = $bearsamppWinbinder->createRadioButton($this->wbWindow, $bearsamppLang->getValue(Lang::CHANGE_BROWSER_OTHER_LABEL), false, 15, $yPos, 470, 15);
70
71 $this->wbInputBrowse = $bearsamppWinbinder->createInputText($this->wbWindow, null, 30, $yPos + 30, 190, null, 20, WBC_READONLY);
72 $this->wbBtnBrowse = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_BROWSE), 225, $yPos + 25, 110);
73 $bearsamppWinbinder->setEnabled($this->wbBtnBrowse[WinBinder::CTRL_OBJ], false);
74
75 $this->wbProgressBar = $bearsamppWinbinder->createProgressBar($this->wbWindow, self::GAUGE_SAVE, 15, 287, 275);
76 $this->wbBtnSave = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_SAVE), 300, 282);
77 $this->wbBtnCancel = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 387, 282);
78 $bearsamppWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], empty($currentBrowser) ? false : true);
79
80 $bearsamppWinbinder->setHandler($this->wbWindow, $this, 'processWindow');
81 $bearsamppWinbinder->mainLoop();
82 $bearsamppWinbinder->reset();
83 }
84
97 public function processWindow($window, $id, $ctrl, $param1, $param2)
98 {
99 global $bearsamppConfig, $bearsamppLang, $bearsamppWinbinder;
100
101 // Get other value
102 $browserPath = $bearsamppWinbinder->getText($this->wbInputBrowse[WinBinder::CTRL_OBJ]);
103
104 // Get value
105 $selected = null;
106 if ($bearsamppWinbinder->getValue($this->wbRadioButtonOther[WinBinder::CTRL_OBJ]) == 1) {
107 $bearsamppWinbinder->setEnabled($this->wbBtnBrowse[WinBinder::CTRL_OBJ], true);
108 $selected = $bearsamppWinbinder->getText($this->wbInputBrowse[WinBinder::CTRL_OBJ]);
109 } else {
110 $bearsamppWinbinder->setEnabled($this->wbBtnBrowse[WinBinder::CTRL_OBJ], false);
111 }
112 foreach ($this->wbRadioButton as $radioButton) {
113 if ($bearsamppWinbinder->getValue($radioButton[WinBinder::CTRL_OBJ]) == 1) {
114 $selected = $bearsamppWinbinder->getText($radioButton[WinBinder::CTRL_OBJ]);
115 break;
116 }
117 }
118
119 // Enable/disable save button
120 $bearsamppWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], empty($selected) ? false : true);
121
122 switch ($id) {
123 case $this->wbBtnBrowse[WinBinder::CTRL_ID]:
124 $browserPath = trim(
125 $bearsamppWinbinder->sysDlgOpen(
126 $window,
128 array(array($bearsamppLang->getValue(Lang::EXECUTABLE), '*.exe')),
129 $browserPath
130 )
131 );
132 if ($browserPath && is_file($browserPath)) {
133 $bearsamppWinbinder->setText($this->wbInputBrowse[WinBinder::CTRL_OBJ], $browserPath);
134 }
135 break;
136 case $this->wbBtnSave[WinBinder::CTRL_ID]:
137 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
138
139 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
140 $bearsamppConfig->replace(Config::CFG_BROWSER, $selected);
141
142 $bearsamppWinbinder->messageBoxInfo(
143 sprintf($bearsamppLang->getValue(Lang::CHANGE_BROWSER_OK), $selected),
145 );
146 $bearsamppWinbinder->destroyWindow($window);
147
148 break;
149 case IDCLOSE:
150 case $this->wbBtnCancel[WinBinder::CTRL_ID]:
151 $bearsamppWinbinder->destroyWindow($window);
152 break;
153 }
154 }
155}
156
global $bearsamppLang
processWindow($window, $id, $ctrl, $param1, $param2)
const CFG_BROWSER
const CHANGE_BROWSER_OTHER_LABEL
const CHANGE_BROWSER_OK
const BUTTON_BROWSE
const BUTTON_CANCEL
const ALIAS_DEST_PATH
const CHANGE_BROWSER_TITLE
const EXECUTABLE
const BUTTON_SAVE
const CHANGE_BROWSER_EXP_LABEL
static getInstalledBrowsers()
global $bearsamppConfig
Definition homepage.php:46