1515// You should have received a copy of the GNU General Public License
1616// along with this program; if not, write to the Free Software
1717// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18-
18+ # include " stdafx.h "
1919#include " NavigateToDlg.h"
2020#include " ../PluginDefinition.h"
2121
2222#include < shlwapi.h>
2323#include < string>
2424#include < algorithm>
2525
26+
2627#ifdef UNICODE
2728 #define generic_itoa _itow
2829 typedef std::string String;
3334
3435extern NppData nppData;
3536
37+ typedef HRESULT (WINAPI *SHAUTOCOMPLETEFN)
38+ (HWND hTarget, DWORD dwFlags);
39+ static HINSTANCE hSHLWAPIDLL = NULL ;
40+
41+ bool SetupForAutoComplete (HWND hTarget, DWORD dwFlags)
42+ {
43+ if (hTarget == NULL )
44+ {
45+ return false ;
46+ }
47+
48+ bool ok = false ;
49+
50+ if (hSHLWAPIDLL == NULL )
51+ {
52+ hSHLWAPIDLL= LoadLibrary (TEXT (" SHLWAPI.DLL" ));
53+ if (hSHLWAPIDLL== NULL )
54+ {
55+ return false ;
56+ }
57+ }
58+
59+ SHAUTOCOMPLETEFN pSHAC =
60+ (SHAUTOCOMPLETEFN)GetProcAddress (hSHLWAPIDLL,
61+ " SHAutoComplete" );
62+
63+ if (pSHAC != NULL )
64+ {
65+ ok = SUCCEEDED (pSHAC (hTarget, dwFlags));
66+ }
67+
68+ return ok;
69+ }
70+
3671INT_PTR CALLBACK NavigateToDlg::run_dlgProc (UINT message, WPARAM wParam, LPARAM lParam)
3772{
3873 if (GetAsyncKeyState (VK_ESCAPE) < 0 ) {
@@ -43,7 +78,7 @@ INT_PTR CALLBACK NavigateToDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
4378 {
4479 ::SetFocus (::GetDlgItem(_hSelf, IDC_RESULTS_LIST));
4580 }
46-
81+
4782 switch (message)
4883 {
4984 case WM_COMMAND :
@@ -63,11 +98,13 @@ INT_PTR CALLBACK NavigateToDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
6398 else
6499 */
65100 openSelectedFile ();
101+ // save history
102+ SendMessage (::GetDlgItem (_hSelf, ID_GOLINE_EDIT),(UINT) CB_ADDSTRING,(WPARAM) 0 ,(LPARAM)NppManager::strToWStr (editValue).c_str ());
66103 return TRUE ;
67104 }
68105 }
69106
70- if ((HIWORD (wParam) == EN_CHANGE ) && (LOWORD (wParam) == ID_GOLINE_EDIT)) // your edit control ID
107+ if ((HIWORD (wParam) == CBN_EDITCHANGE || HIWORD (wParam) == CBN_SELCHANGE ) && (LOWORD (wParam) == ID_GOLINE_EDIT)) // your edit control ID
71108 {
72109 loadFileNamesToList (getFilterEditValue ());
73110 HWND hwndListBox = ::GetDlgItem (_hSelf, IDC_RESULTS_LIST);
@@ -91,6 +128,38 @@ INT_PTR CALLBACK NavigateToDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
91128 }
92129 return FALSE ;
93130 }
131+ case WM_INITDIALOG:
132+ {
133+ memset (&LvCol,0 ,sizeof (LvCol)); // Zero Members
134+ LvCol.mask =LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM; // Type of mask
135+ LvCol.cx =0x28 ; // width between each coloum
136+ LvCol.pszText =TEXT (" Name" ); // First Header Text
137+ LvCol.cx =0x81 ; // width of column
138+ SendMessage (::GetDlgItem (_hSelf, IDC_RESULTS_LIST),LVM_SETEXTENDEDLISTVIEWSTYLE,
139+ 0 ,LVS_EX_FULLROWSELECT); // Set style
140+ SendMessage (::GetDlgItem (_hSelf, IDC_RESULTS_LIST),LVM_INSERTCOLUMN,0 ,(LPARAM)&LvCol); // Insert/Show the coloum
141+ LvCol.pszText =TEXT (" Path" ); // Next coloum
142+ SendMessage (::GetDlgItem (_hSelf, IDC_RESULTS_LIST),LVM_INSERTCOLUMN,1 ,(LPARAM)&LvCol); // ...
143+ LvCol.pszText =TEXT (" Type" ); //
144+ SendMessage (::GetDlgItem (_hSelf, IDC_RESULTS_LIST),LVM_INSERTCOLUMN,2 ,(LPARAM)&LvCol); //
145+
146+ if (cmdComboBoxEdit)
147+ {
148+ // enable auto complete for m_myCombo
149+ SetupForAutoComplete (cmdComboBoxEdit->m_hWnd , SHACF_USETAB);
150+ }
151+ }
152+ case WM_NOTIFY:
153+ {
154+ switch (LOWORD (wParam))
155+ {
156+ case IDC_RESULTS_LIST:
157+ if (((LPNMHDR)lParam)->code == NM_DBLCLK)
158+ {
159+ openSelectedFile ();
160+ }
161+ }
162+ }
94163 default :
95164 return DockingDlgInterface::run_dlgProc (message, wParam, lParam);
96165 }
@@ -102,40 +171,68 @@ void NavigateToDlg::loadFileNamesToList(const std::string &filter)
102171 TCHAR toto[10 ];
103172 // show count
104173 ::SetDlgItemText (_hSelf, ID_UGO_RESULTS_CNT_LABEL, generic_itoa(fileNameList.size(), toto, 10));
174+
105175 // reset list
106176 HWND hwndListBox = ::GetDlgItem (_hSelf, IDC_RESULTS_LIST);
107- SendMessage (hwndListBox, LB_RESETCONTENT, 0 , 0 );
177+ SendMessage (hwndListBox, LVM_DELETEALLITEMS, 0 , 0 );
108178 if (fileNameList.size () == 0 )
109179 {
110180 return ;
111181 }
112- else
182+ // add filenames
183+ for (std::vector<std::string>::iterator it = fileNameList.begin (); it != fileNameList.end (); ++it)
113184 {
114- // add filenames
115- for (std::vector<std::string>::iterator it = fileNameList.begin (); it != fileNameList.end (); ++it)
185+ std::wstring fileName = NppManager::strToWStr (*it);
186+ // add to list
187+ if (!fileName.empty ())
116188 {
117- std::wstring fileName = NppManager::strToWStr (*it);
118- // add to list
119- if (!fileName.empty ())
120- {
121- SendMessage (hwndListBox, LB_ADDSTRING, 0 , (LPARAM)fileName.c_str ());
122- }
189+ memset (&LvItem,0 ,sizeof (LvItem)); // Zero struct's Members
190+
191+ // Setting properties Of members:
192+
193+ LvItem.mask =LVIF_TEXT; // Text Style
194+ LvItem.cchTextMax = 256 ; // Max size of test
195+ LvItem.iItem =0 ; // choose item
196+ LvItem.iSubItem =0 ; // Put in first coluom
197+ LvItem.pszText =(LPWSTR)fileName.c_str (); // Text to display (can be from a char variable) (Items)
198+ SendMessage (hwndListBox,LVM_INSERTITEM,0 ,(LPARAM)&LvItem); // Send info to the Listview
199+ LvItem.iSubItem =1 ;
200+ LvItem.pszText =(LPWSTR)fileName.c_str ();
201+ SendMessage (hwndListBox,LVM_SETITEM,0 ,(LPARAM)&LvItem); // Enter text to SubItems
123202 }
124203 }
125204}
126205
127206int NavigateToDlg::getSelectedFileId ()
128207{
129- HWND hListBox = GetDlgItem (_hSelf, IDC_RESULTS_LIST);
130- return (int )SendMessage (hListBox, LB_GETCURSEL, 0 , 0 );
208+ HWND hListBox = GetDlgItem (_hSelf, IDC_RESULTS_LIST);
209+ int iSelect = SendMessage (hListBox,LVM_GETNEXTITEM,
210+ -1 ,LVNI_FOCUSED); // return item selected
211+
212+ if (iSelect==-1 ) // no items
213+ {
214+ nppManager->showMessageBox (" Sorry... There is no files to open." );
215+ }
216+ return iSelect;
131217}
132218
133219void NavigateToDlg::openSelectedFile ()
134220{
135- TCHAR filePath[MAX_PATH];
221+ char filePath[MAX_PATH]={ 0 } ;
136222 HWND hListBox = GetDlgItem (_hSelf, IDC_RESULTS_LIST);
137223 int pos = getSelectedFileId ();
138- SendMessage (hListBox, LB_GETTEXT, pos, (LPARAM)filePath);
139- nppManager->switchToFile (NppManager::wStrToStr (filePath));
224+ memset (&LvItem,0 ,sizeof (LvItem));
225+ LvItem.mask =LVIF_TEXT;
226+ LvItem.iSubItem =0 ;
227+ LvItem.pszText =(LPWSTR)filePath;
228+ LvItem.cchTextMax =256 ;
229+ LvItem.iItem =pos;
230+
231+ SendMessage (hListBox,LVM_GETITEMTEXT,
232+ pos, (LPARAM)&LvItem);
233+ bool isSwitched = nppManager->switchToFile (NppManager::wStrToStr (LvItem.pszText ));
140234 ::SetFocus (::GetDlgItem(_hSelf, IDC_RESULTS_LIST));
235+
236+ if (isSwitched)
237+ display (false );
141238}
0 commit comments