Main Page   File List   Globals  

changeconfigurationdialog.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2002 Ingo Richter and others.
00003  * All rights reserved.   This program and the accompanying materials
00004  * are made available under the terms of the Common Public License v1.0
00005  * which accompanies this distribution, and is available at
00006  * http://www.eclipse.org/legal/cpl-v10.html
00007  * 
00008  * Contributors:
00009  *    Ingo Richter - Initial implementation.
00010  */
00011 #define strict
00012 
00013 #include <windows.h>
00014 #include <windowsx.h>
00015 #include "changeConfigurationDialog.h"
00016 
00017 #include <assert.h>
00018 
00019 #include "persistent.h"
00020 #include "eclipselauncherres.h"
00021 #include "utils.h"
00022 #include "resource.h"
00023 
00024 #define HANDLE_SETECLIPSEJAVAVM(hwndDlg, newConfiguration, message, controlId) \
00025                 case (message): \
00026                 {   setPath(hwndDlg, (BOOL) newConfiguration, controlId); } break;
00027 
00028 #define HANDLE_SETECLIPSEEXECUTABLE(hwndDlg, newConfiguration, message, controlId) \
00029                 case (message): \
00030                 {   setPath(hwndDlg, (BOOL) newConfiguration, controlId); } break;
00031 
00032 #define HANDLE_SETECLIPSEWORKSPACEPATH(hwndDlg, message) \
00033                 case (message): \
00034                 {   setEclipseWorkspacePath(hwndDlg); } break;
00035 
00036 #define HANDLE_CANCEL_BUTTON(hwndDlg) \
00037                 case IDCANCEL: \
00038                 {   EndDialog(hwndDlg,0); return 1; }
00039 
00040 #define HANDLE_ID_CONFIGNAME(hwndDlg, wParam) \
00041                 case ID_CONFIGNAME: \
00042                 { \
00043                     switch(HIWORD(wParam)) \
00044                     { \
00045                         case EN_CHANGE: \
00046                         { \
00047                             EnableWindow(GetDlgItem(hwndDlg, IDOK), Edit_LineLength(GetDlgItem(hwndDlg, ID_CONFIGNAME) ,0)); \
00048                         } \
00049                         break; \
00050                     } \
00051                 } \
00052 
00053 void addNewConfigurationToListbox(HWND hDialog, HWND hListBox, LPLAUNCHERCONFIG launcherConfig, int currentPosition)
00054 {
00055     LPLAUNCHERCONFIG tempConfig = launcherConfig;
00056     BOOL newConfig = (tempConfig == NULL);
00057 
00058     if(newConfig)
00059     {
00060         tempConfig = createLauncherConfig();
00061     }
00062 
00063     GetDlgItemText(hDialog, ID_CONFIGNAME, getName(tempConfig), MAX_STRING_LENGTH);
00064     GetDlgItemText(hDialog, ID_PATHTOECLIPSE, getExecutablePath(tempConfig), MAX_STRING_LENGTH);
00065     GetDlgItemText(hDialog, ID_OPTIONALPARAMS, getOptionalParameter(tempConfig), MAX_STRING_LENGTH);
00066     GetDlgItemText(hDialog, ID_WORKSPACEPATH, getWorkspacePath(tempConfig), MAX_STRING_LENGTH);
00067     GetDlgItemText(hDialog, ID_VMPARAMETER, getVMParameter(tempConfig), MAX_STRING_LENGTH);
00068     GetDlgItemText(hDialog, ID_ECLIPSEJAVAVM, getJavaVM(tempConfig), MAX_STRING_LENGTH);
00069 
00070     if(newConfig)
00071     {
00072         addLauchnerConfigToList(hListBox, tempConfig, NEW_POSITION);
00073     }
00074     else
00075     {
00076         updateLauchnerConfig(hListBox, tempConfig, currentPosition);
00077     }
00078 }
00079 
00080 
00081 void setEclipseWorkspacePath(HWND hDialog)
00082 {
00083     TCHAR* path = (TCHAR*)malloc(MAX_PATH);
00084     ZeroMemory(path, MAX_PATH);
00085     GetFolderName(path);
00086 
00087     SetDlgItemText(hDialog, ID_WORKSPACEPATH, path);
00088 
00089     free(path);
00090 }
00091 
00092 void setPath(HWND hDialog, BOOL newConfiguration, int controlId)
00093 {
00094     HWND hListBox;
00095 
00096     TCHAR* path = (TCHAR*)malloc(MAX_PATH);
00097     ZeroMemory(path, MAX_PATH);
00098     GetOpenFilename("*.exe", "", path);
00099 
00100     hListBox = (HWND)HIWORD(GetWindowLong(hDialog, GWL_USERDATA));
00101 
00102     SetDlgItemText(hDialog, controlId, path);
00103 
00104     if(newConfiguration)
00105     {
00106         addNewConfigurationToListbox(hDialog, hListBox, createLauncherConfig(), (-1)); //append to List
00107     }
00108 
00109     free(path);
00110 }
00111 
00112 
00117 void setMaxTextLengthOfAllEditFields(HWND hDialog)
00118 {
00119     Edit_LimitText(GetDlgItem(hDialog, ID_CONFIGNAME), MAX_STRING_LENGTH);
00120     Edit_LimitText(GetDlgItem(hDialog, ID_PATHTOECLIPSE), MAX_STRING_LENGTH);
00121     Edit_LimitText(GetDlgItem(hDialog, ID_OPTIONALPARAMS), MAX_STRING_LENGTH);
00122     Edit_LimitText(GetDlgItem(hDialog, ID_WORKSPACEPATH), MAX_STRING_LENGTH);
00123     Edit_LimitText(GetDlgItem(hDialog, ID_VMPARAMETER), MAX_STRING_LENGTH);
00124     Edit_LimitText(GetDlgItem(hDialog, ID_ECLIPSEJAVAVM), MAX_STRING_LENGTH);
00125 }
00126 
00127 LRESULT HandleAddConfigurationDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
00128 {
00129     switch (msg)
00130     {
00131         case WM_INITDIALOG:
00132         {
00133             SetWindowLong(hwndDlg, GWL_USERDATA, lParam); // store Handle of Listbox
00134             EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
00135 
00136             setMaxTextLengthOfAllEditFields(hwndDlg);
00137         }
00138         return 1;
00139 
00140         case WM_COMMAND:
00141         {
00142             switch (LOWORD(wParam))
00143             {
00144                 case IDOK:
00145                 {
00146                     HWND hListBox = (HWND)HIWORD(GetWindowLong(hwndDlg, GWL_USERDATA));
00147 
00148                     addNewConfigurationToListbox(hwndDlg, hListBox, NULL, (-1)); // append to List
00149                     saveConfiguration(hListBox);
00150 
00151                     EndDialog(hwndDlg,1);
00152                     return 1;
00153                 }
00154 
00155                 HANDLE_CANCEL_BUTTON(hwndDlg);
00156                 HANDLE_SETECLIPSEWORKSPACEPATH(hwndDlg, ID_SETWORKSPACEPATH);
00157                 HANDLE_SETECLIPSEEXECUTABLE(hwndDlg, TRUE, ID_SELECTEXECUTABLE, ID_PATHTOECLIPSE);
00158                 HANDLE_SETECLIPSEJAVAVM(hwndDlg, TRUE, ID_SETECLIPSEJAVAVM, ID_ECLIPSEJAVAVM);
00159                 HANDLE_ID_CONFIGNAME(hwndDlg, wParam);
00160             }
00161             break;
00162         }
00163 
00164         FORWARD_WM_CLOSE(hwndDlg, EndDialog);
00165     }
00166 
00167     return FALSE;
00168 }
00169 
00170 
00171 LRESULT HandleEditConfigurationDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
00172 {
00173     switch (msg)
00174     {
00175         case WM_INITDIALOG:
00176         {
00177             DWORD dialog;
00178             HWND hListBox;
00179             int currentSelection;
00180             LPLAUNCHERCONFIG data;
00181             TCHAR* buffer = (TCHAR*)malloc(128);
00182 
00183             SetWindowText(hwndDlg, LocString(IDS_EDIT_NEW_CONFIGURATION, buffer));
00184             SetWindowLong(hwndDlg, GWL_USERDATA, lParam); // store Handle of Listbox
00185             hListBox = (HWND)HIWORD(lParam);
00186             dialog = (DWORD)LOWORD(lParam);
00187 
00188             currentSelection = getCurrentSelection(hListBox);
00189             data = getLauncherConfig(hListBox, currentSelection);
00190 
00191             SetDlgItemText(hwndDlg, ID_CONFIGNAME, getName(data));
00192             SetDlgItemText(hwndDlg, ID_PATHTOECLIPSE, getExecutablePath(data));
00193             SetDlgItemText(hwndDlg, ID_OPTIONALPARAMS, getOptionalParameter(data));
00194             SetDlgItemText(hwndDlg, ID_WORKSPACEPATH, getWorkspacePath(data));
00195             SetDlgItemText(hwndDlg, ID_VMPARAMETER, getVMParameter(data));
00196             SetDlgItemText(hwndDlg, ID_ECLIPSEJAVAVM, getJavaVM(data));
00197 
00198             setMaxTextLengthOfAllEditFields(hwndDlg);
00199 
00200             free(buffer);
00201         }
00202         return 1;
00203 
00204         case WM_COMMAND:
00205         {
00206             switch (LOWORD(wParam))
00207             {
00208                 case IDOK:
00209                 {
00210                     HWND hListBox = (HWND)HIWORD(GetWindowLong(hwndDlg, GWL_USERDATA));
00211 
00212                     UINT currentSelection = getCurrentSelection(hListBox);
00213                     LPLAUNCHERCONFIG data = getLauncherConfig(hListBox, currentSelection);
00214                     addNewConfigurationToListbox(hwndDlg, hListBox, data, currentSelection);
00215 
00216                     saveConfiguration(hListBox);
00217 
00218                     EndDialog(hwndDlg,1);
00219                     return 1;
00220                 }
00221 
00222                 HANDLE_CANCEL_BUTTON(hwndDlg);
00223                 HANDLE_SETECLIPSEWORKSPACEPATH(hwndDlg, ID_SETWORKSPACEPATH);
00224                 HANDLE_SETECLIPSEEXECUTABLE(hwndDlg, FALSE, ID_SELECTEXECUTABLE, ID_PATHTOECLIPSE);
00225                 HANDLE_SETECLIPSEJAVAVM(hwndDlg, FALSE, ID_SETECLIPSEJAVAVM, ID_ECLIPSEJAVAVM);
00226                 HANDLE_ID_CONFIGNAME(hwndDlg, wParam);
00227             }
00228             break;
00229         }
00230 
00231         FORWARD_WM_CLOSE(hwndDlg, EndDialog);
00232     }
00233 
00234     return FALSE;
00235 }
00236 
00241 void disposeAllConfigurations(HWND hListBox)
00242 {
00243     int configurations = getConfigurationCount(hListBox);
00244 
00245     if(configurations > 0)
00246     {
00247         int i;
00248 
00249         for(i = 0; i < configurations; i++)
00250         {
00251             LPLAUNCHERCONFIG launcherconfig = getLauncherConfig(hListBox, i);
00252 
00253             releaseLauncherConfig(launcherconfig);
00254         }
00255     }
00256 }

Generated on Sun Apr 6 13:49:02 2003 for EclipseLauncher by doxygen1.2.17