Browse Source

GUI tweaks.

The check_method_timeout() static function was used for processing
timeouts in milliseconds, hence the name.  We are now reusing it to
check arbitrary numbers, so the name is no longer appropriate.

Instead of having checkboxes to enable or disable file rotation
parameters we enable or disable the editboxes where the values are
entered, based on the state of the rotation checkbox.

Similarly, the editboxes for shutdown method timeouts are enabled and
disabled based on the state of the method checkboxes.

The throttle timeout editbox was poorly aligned.
Iain Patterson 8 years ago
parent
commit
9808f7658c
3 changed files with 56 additions and 41 deletions
  1. 37 20
      gui.cpp
  2. 3 3
      nssm.rc
  3. 16 18
      resource.h

+ 37 - 20
gui.cpp

@@ -68,12 +68,23 @@ static inline void check_stop_method(nssm_service_t *service, unsigned long meth
   service->stop_method &= ~method;
 }
 
-static inline void check_method_timeout(HWND tab, unsigned long control, unsigned long *timeout) {
+static inline void check_number(HWND tab, unsigned long control, unsigned long *timeout) {
   BOOL translated;
   unsigned long configured = GetDlgItemInt(tab, control, &translated, 0);
   if (translated) *timeout = configured;
 }
 
+static inline void set_timeout_enabled(unsigned long control, unsigned long dependent) {
+  unsigned char enabled = 0;
+  if (SendDlgItemMessage(tablist[NSSM_TAB_SHUTDOWN], control, BM_GETCHECK, 0, 0) & BST_CHECKED) enabled = 1;
+  EnableWindow(GetDlgItem(tablist[NSSM_TAB_SHUTDOWN], dependent), enabled);
+}
+
+static inline void set_rotation_enabled(unsigned char enabled) {
+  EnableWindow(GetDlgItem(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_SECONDS), enabled);
+  EnableWindow(GetDlgItem(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_BYTES_LOW), enabled);
+}
+
 static inline void check_io(TCHAR *name, TCHAR *buffer, unsigned long len, unsigned long control) {
   if (! SendMessage(GetDlgItem(tablist[NSSM_TAB_IO], control), WM_GETTEXTLENGTH, 0, 0)) return;
   if (GetDlgItemText(tablist[NSSM_TAB_IO], control, buffer, (int) len)) return;
@@ -140,12 +151,12 @@ int install(HWND window) {
     check_stop_method(service, NSSM_STOP_METHOD_WINDOW, IDC_METHOD_WINDOW);
     check_stop_method(service, NSSM_STOP_METHOD_THREADS, IDC_METHOD_THREADS);
     check_stop_method(service, NSSM_STOP_METHOD_TERMINATE, IDC_METHOD_TERMINATE);
-    check_method_timeout(tablist[NSSM_TAB_SHUTDOWN], IDC_KILL_CONSOLE, &service->kill_console_delay);
-    check_method_timeout(tablist[NSSM_TAB_SHUTDOWN], IDC_KILL_WINDOW, &service->kill_window_delay);
-    check_method_timeout(tablist[NSSM_TAB_SHUTDOWN], IDC_KILL_THREADS, &service->kill_threads_delay);
+    check_number(tablist[NSSM_TAB_SHUTDOWN], IDC_KILL_CONSOLE, &service->kill_console_delay);
+    check_number(tablist[NSSM_TAB_SHUTDOWN], IDC_KILL_WINDOW, &service->kill_window_delay);
+    check_number(tablist[NSSM_TAB_SHUTDOWN], IDC_KILL_THREADS, &service->kill_threads_delay);
 
     /* Get exit action stuff. */
-    check_method_timeout(tablist[NSSM_TAB_EXIT], IDC_THROTTLE, &service->throttle_delay);
+    check_number(tablist[NSSM_TAB_EXIT], IDC_THROTTLE, &service->throttle_delay);
     combo = GetDlgItem(tablist[NSSM_TAB_EXIT], IDC_APPEXIT);
     service->default_exit_action = (unsigned long) SendMessage(combo, CB_GETCURSEL, 0, 0);
     if (service->default_exit_action == CB_ERR) service->default_exit_action = 0;
@@ -164,12 +175,8 @@ int install(HWND window) {
     /* Get rotation stuff. */
     if (SendDlgItemMessage(tablist[NSSM_TAB_ROTATION], IDC_ROTATE, BM_GETCHECK, 0, 0) & BST_CHECKED) {
       service->rotate_files = true;
-    }
-    if (SendDlgItemMessage(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_SECONDS_ENABLED, BM_GETCHECK, 0, 0) & BST_CHECKED) {
-      check_method_timeout(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_SECONDS, &service->rotate_seconds);
-    }
-    if (SendDlgItemMessage(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_BYTES_LOW_ENABLED, BM_GETCHECK, 0, 0) & BST_CHECKED) {
-      check_method_timeout(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_BYTES_LOW, &service->rotate_bytes_low);
+      check_number(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_SECONDS, &service->rotate_seconds);
+      check_number(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_BYTES_LOW, &service->rotate_bytes_low);
     }
 
     /* Get environment. */
@@ -398,7 +405,7 @@ INT_PTR CALLBACK tab_dlg(HWND tab, UINT message, WPARAM w, LPARAM l) {
     case WM_COMMAND:
       HWND dlg;
       TCHAR buffer[MAX_PATH];
-      unsigned long state;
+      unsigned char enabled;
 
       switch (LOWORD(w)) {
         /* Browse for application. */
@@ -415,13 +422,26 @@ INT_PTR CALLBACK tab_dlg(HWND tab, UINT message, WPARAM w, LPARAM l) {
           }
           break;
 
-          /* Browse for startup directory. */
+        /* Browse for startup directory. */
         case IDC_BROWSE_DIR:
           dlg = GetDlgItem(tab, IDC_DIR);
           GetDlgItemText(tab, IDC_DIR, buffer, _countof(buffer));
           browse(dlg, buffer, OFN_NOVALIDATE, NSSM_GUI_BROWSE_FILTER_DIRECTORIES, 0);
           break;
 
+        /* Shutdown methods. */
+        case IDC_METHOD_CONSOLE:
+          set_timeout_enabled(LOWORD(w), IDC_KILL_CONSOLE);
+          break;
+
+        case IDC_METHOD_WINDOW:
+          set_timeout_enabled(LOWORD(w), IDC_KILL_WINDOW);
+          break;
+
+        case IDC_METHOD_THREADS:
+          set_timeout_enabled(LOWORD(w), IDC_KILL_THREADS);
+          break;
+
         /* Browse for stdin. */
         case IDC_BROWSE_STDIN:
           dlg = GetDlgItem(tab, IDC_STDIN);
@@ -451,13 +471,9 @@ INT_PTR CALLBACK tab_dlg(HWND tab, UINT message, WPARAM w, LPARAM l) {
 
         /* Rotation. */
         case IDC_ROTATE:
-        case IDC_ROTATE_SECONDS_ENABLED:
-        case IDC_ROTATE_BYTES_LOW_ENABLED:
-          if (SendDlgItemMessage(tab, LOWORD(w), BM_GETCHECK, 0, 0) & BST_CHECKED) state = BST_CHECKED;
-          else state = BST_UNCHECKED;
-          SendDlgItemMessage(tablist[NSSM_TAB_ROTATION], IDC_ROTATE, BM_SETCHECK, state, 0);
-          SendDlgItemMessage(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_SECONDS_ENABLED, BM_SETCHECK, state, 0);
-          SendDlgItemMessage(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_BYTES_LOW_ENABLED, BM_SETCHECK, state, 0);
+          if (SendDlgItemMessage(tab, LOWORD(w), BM_GETCHECK, 0, 0) & BST_CHECKED) enabled = 1;
+          else enabled = 0;
+          set_rotation_enabled(enabled);
           break;
       }
       return 1;
@@ -554,6 +570,7 @@ INT_PTR CALLBACK install_dlg(HWND window, UINT message, WPARAM w, LPARAM l) {
       /* Set defaults. */
       SetDlgItemInt(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_SECONDS, 0, 0);
       SetDlgItemInt(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_BYTES_LOW, 0, 0);
+      set_rotation_enabled(0);
 
       /* Environment tab. */
       tab.pszText = message_string(NSSM_GUI_TAB_ENVIRONMENT);

+ 3 - 3
nssm.rc

@@ -146,7 +146,7 @@ FONT 8, "MS Sans Serif"
 {
     GROUPBOX        "Throttling", IDC_STATIC, 7, 7, 251, 25
     LTEXT           "Delay restart if application runs for less than", IDC_STATIC, 13, 18, 137, 8, SS_LEFT
-    EDITTEXT        IDC_THROTTLE, 152, 16, 29, 12, ES_AUTOHSCROLL | ES_NUMBER
+    EDITTEXT        IDC_THROTTLE, 155, 16, 29, 12, ES_AUTOHSCROLL | ES_NUMBER
     LTEXT           "ms", IDC_STATIC, 186, 18, 10, 8, SS_LEFT
     GROUPBOX        "Restart", IDC_STATIC, 7, 33, 251, 42
     LTEXT           "Action to take when application exits other\nthan in response to a controlled service\nshutdown:", IDC_STATIC, 14, 42, 134, 24, SS_LEFT
@@ -178,10 +178,10 @@ FONT 8, "MS Sans Serif"
     GROUPBOX        "File rotation", IDC_STATIC, 7, 7, 251, 68
     AUTOCHECKBOX    "Replace existing Output and/or Error files", IDC_TRUNCATE, 13, 18, 145, 8
     AUTOCHECKBOX    "Rotate files", IDC_ROTATE, 13, 32, 51, 8
-    AUTOCHECKBOX    "Restrict rotation to files older than", IDC_ROTATE_SECONDS_ENABLED, 13, 46, 121, 8
+    LTEXT           "Restrict rotation to files older than", IDC_STATIC, 25, 46, 121, 8
     EDITTEXT        IDC_ROTATE_SECONDS, 140, 44, 29, 12, ES_AUTOHSCROLL | ES_NUMBER
     LTEXT           "s", IDC_STATIC, 171, 46, 8, 8, SS_LEFT
-    AUTOCHECKBOX    "Restrict rotation to files bigger than", IDC_ROTATE_BYTES_LOW_ENABLED, 13, 60, 125, 8
+    LTEXT           "Restrict rotation to files bigger than", IDC_STATIC, 25, 60, 125, 8
     EDITTEXT        IDC_ROTATE_BYTES_LOW, 140, 58, 49, 12, ES_AUTOHSCROLL | ES_NUMBER
     LTEXT           "kB", IDC_STATIC, 191, 60, 8, 8, SS_LEFT
 }

+ 16 - 18
resource.h

@@ -3,16 +3,16 @@
 // Used by nssm.rc
 //
 #define IDC_STATIC (-1)
-#define IDI_NSSM                   101
-#define IDD_INSTALL                   102
-#define IDD_REMOVE            103
-#define IDD_APPLICATION            104
-#define IDD_DETAILS            105
-#define IDD_IO            106
-#define IDD_ROTATION        107
-#define IDD_APPEXIT            108
-#define IDD_SHUTDOWN            109
-#define IDD_ENVIRONMENT            110
+#define IDI_NSSM                        101
+#define IDD_INSTALL                     102
+#define IDD_REMOVE                      103
+#define IDD_APPLICATION                 104
+#define IDD_DETAILS                     105
+#define IDD_IO                          106
+#define IDD_ROTATION                    107
+#define IDD_APPEXIT                     108
+#define IDD_SHUTDOWN                    109
+#define IDD_ENVIRONMENT                 110
 #define IDC_PATH                        1000
 #define IDC_TAB1                        1001
 #define IDC_CANCEL                      1002
@@ -41,13 +41,11 @@
 #define IDC_ENVIRONMENT_REPLACE         1026
 #define IDC_TRUNCATE                    1027
 #define IDC_ROTATE                      1028
-#define IDC_ROTATE_SECONDS_ENABLED      1029
-#define IDC_ROTATE_SECONDS              1030
-#define IDC_ROTATE_BYTES_LOW_ENABLED    1031
-#define IDC_ROTATE_BYTES_LOW            1032
-#define IDC_DISPLAYNAME                 1033
-#define IDC_DESCRIPTION                 1034
-#define IDC_STARTUP                     1035
+#define IDC_ROTATE_SECONDS              1029
+#define IDC_ROTATE_BYTES_LOW            1030
+#define IDC_DISPLAYNAME                 1031
+#define IDC_DESCRIPTION                 1032
+#define IDC_STARTUP                     1033
 
 // Next default values for new objects
 // 
@@ -55,7 +53,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        111
 #define _APS_NEXT_COMMAND_VALUE         40001
-#define _APS_NEXT_CONTROL_VALUE         1036
+#define _APS_NEXT_CONTROL_VALUE         1034
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif