Pārlūkot izejas kodu

Windows: Show context info in dialog

bel2125 8 gadi atpakaļ
vecāks
revīzija
87787ceff0
2 mainītis faili ar 66 papildinājumiem un 3 dzēšanām
  1. 65 2
      src/main.c
  2. 1 1
      src/mod_lua.inl

+ 65 - 2
src/main.c

@@ -1280,6 +1280,8 @@ struct dlg_proc_param {
 	const char *name;
 	char *buffer;
 	unsigned buflen;
+	int idRetry;
+	BOOL (*fRetry)(struct dlg_proc_param *data);
 };
 
 
@@ -1476,6 +1478,22 @@ InputDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
 				/* There is no input line in this dialog. */
 				EndDialog(hDlg, IDOK);
 			}
+
+		} else if (ctrlId == IDRETRY) {
+
+			/* Get handle of input line */
+			hIn = GetDlgItem(hDlg, inBuf->idRetry);
+
+			if (hIn) {
+				/* Load current string */
+				GetWindowText(hIn, inBuf->buffer, (int)inBuf->buflen);
+				if (inBuf->fRetry) {
+					if (inBuf->fRetry(inBuf)) {
+						SetWindowText(hIn, inBuf->buffer);
+					}
+				}
+			}
+
 		} else if (ctrlId == IDCANCEL) {
 			EndDialog(hDlg, IDCANCEL);
 		}
@@ -1713,6 +1731,7 @@ get_password(const char *user,
 	dia->cy = y + (WORD)(HEIGHT * 1.5);
 
 	s_dlg_proc_param.name = "Modify password";
+	s_dlg_proc_param.fRetry = NULL;
 
 	ok =
 	    (IDOK == DialogBoxIndirectParam(
@@ -2022,6 +2041,8 @@ show_settings_dialog()
 
 	dia->cy = ((nelems + 1) / 2 + 1) * HEIGHT + 30;
 
+	s_dlg_proc_param.fRetry = NULL;
+
 	DialogBoxIndirectParam(
 	    NULL, dia, NULL, SettingsDlgProc, (LPARAM)&s_dlg_proc_param);
 
@@ -2234,6 +2255,7 @@ change_password_file()
 		dia->cy = y + 20;
 
 		s_dlg_proc_param.name = path;
+		s_dlg_proc_param.fRetry = NULL;
 
 	} while ((IDOK == DialogBoxIndirectParam(NULL,
 	                                         dia,
@@ -2251,6 +2273,33 @@ change_password_file()
 }
 
 
+static BOOL
+sysinfo_reload(struct dlg_proc_param *prm)
+{
+	static char *buf = 0;
+	int cl, rl;
+
+	cl = mg_get_context_info(g_ctx, NULL, 0);
+	free(buf);
+	cl += 510;
+	buf = (char *)malloc(cl + 1);
+	rl = mg_get_context_info(g_ctx, buf, cl);
+	if ((rl > cl) || (rl <= 0)) {
+		if (g_ctx == NULL) {
+			prm->buffer = "Server not running";
+		} else if (rl <= 0) {
+			prm->buffer = "No server statistics available";
+		} else {
+			prm->buffer = "Please retry";
+		}
+	} else {
+		prm->buffer = buf;
+	}
+
+	return TRUE;
+}
+
+
 int
 show_system_info()
 {
@@ -2322,22 +2371,36 @@ show_system_info()
 	            g_system_info);
 
 	y += (WORD)(HEIGHT * 8);
+
+	add_control(&p,
+	            dia,
+	            0x80,
+	            IDRETRY,
+	            WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
+	            WIDTH - 10 - 55 - 10 - 55,
+	            y,
+	            55,
+	            12,
+	            "Reload");
+
 	add_control(&p,
 	            dia,
 	            0x80,
 	            IDOK,
 	            WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
-	            (WIDTH - 55) / 2,
+	            WIDTH - 10 - 55,
 	            y,
 	            55,
 	            12,
-	            "Ok");
+	            "Close");
 
 	assert((intptr_t)p - (intptr_t)mem < (intptr_t)sizeof(mem));
 
 	dia->cy = y + (WORD)(HEIGHT * 1.5);
 
 	s_dlg_proc_param.name = "System information";
+	s_dlg_proc_param.fRetry = sysinfo_reload;
+	s_dlg_proc_param.idRetry = ID_CONTROLS + 1; /* Reload field with this ID */
 
 	ok =
 	    (IDOK == DialogBoxIndirectParam(

+ 1 - 1
src/mod_lua.inl

@@ -540,7 +540,7 @@ lsp_include(lua_State *L)
 		int depth;
 		lua_pushlightuserdata(L, (void *)&lua_regkey_lsp_include_depth);
 		lua_gettable(L, LUA_REGISTRYINDEX);
-		depth = lua_tointeger(L, -1);
+		depth = (int)(lua_tointeger(L, -1) + 0.5);
 
 		lua_pushlightuserdata(L, (void *)&lua_regkey_lsp_include_depth);
 		lua_pushinteger(L, depth + 1);