[ttssh2-commit] [9901] リストビューを実装

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2022年 5月 2日 (月) 23:08:19 JST


Revision: 9901
          https://osdn.net/projects/ttssh2/scm/svn/commits/9901
Author:   zmatsuo
Date:     2022-05-02 23:08:19 +0900 (Mon, 02 May 2022)
Log Message:
-----------
リストビューを実装

- 次のフォルダも表示
  - カレントディレクトリ
  - HomeDir, 個人設定ファイルのあるフォルダ
  - ExeDir, 実行ファイル(ttermpro.exeなど)のあるフォルダ
  - LogDir, Tera Termの動作ログやダンプを置くフォルダ
  - LogDefaultPathW, 端末ログを置くフォルダ
  - Download, ダウンロードフォルダ
  - Susie Plugin Path, Susiプラグイン
  - UI language file, UI langファイル

Modified Paths:
--------------
    branches/setupdir/teraterm/common/tt_res.h
    branches/setupdir/teraterm/common/tttypes.h
    branches/setupdir/teraterm/teraterm/setupdirdlg.cpp
    branches/setupdir/teraterm/teraterm/ttermpro.rc
    branches/setupdir/teraterm/teraterm/vtwin.cpp

-------------- next part --------------
Modified: branches/setupdir/teraterm/common/tt_res.h
===================================================================
--- branches/setupdir/teraterm/common/tt_res.h	2022-05-02 13:56:12 UTC (rev 9900)
+++ branches/setupdir/teraterm/common/tt_res.h	2022-05-02 14:08:19 UTC (rev 9901)
@@ -137,7 +137,6 @@
 #define IDC_TRANS_TRANS                 2506
 #define IDC_AUTOSTART                   2507
 #define IDC_REALTIME_CHECK              2508
-#define IDC_LIST1                       2509
 #define IDC_LIST                        2509
 #define IDC_EDIT                        2510
 #define IDC_SCROLL_LINE                 2510
@@ -261,6 +260,7 @@
 #define IDC_SENDFILE_DELAYTIME_LABEL    2604
 #define IDC_SENDFILE_DELAYTIME_EDIT     2605
 #define IDC_SENDFILE_CHECK_4            2606
+#define IDC_SETUP_DIR_LIST              2607
 #define ID_ACC_SENDBREAK                50001
 #define ID_ACC_COPY                     50002
 #define ID_ACC_NEWCONNECTION            50003
@@ -355,13 +355,13 @@
 #define ID_FILE_TERATERMMENU            52006
 
 // Next default values for new objects
-//
+// 
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NO_MFC                     1
 #define _APS_NEXT_RESOURCE_VALUE        132
 #define _APS_NEXT_COMMAND_VALUE         52031
-#define _APS_NEXT_CONTROL_VALUE         2607
+#define _APS_NEXT_CONTROL_VALUE         2608
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif

Modified: branches/setupdir/teraterm/common/tttypes.h
===================================================================
--- branches/setupdir/teraterm/common/tttypes.h	2022-05-02 13:56:12 UTC (rev 9900)
+++ branches/setupdir/teraterm/common/tttypes.h	2022-05-02 14:08:19 UTC (rev 9901)
@@ -351,7 +351,7 @@
 struct tttset {
 /*------ VTSet --------*/
 	/* Tera Term home directory */
-	char HomeDir[MAXPATHLEN];		// ttermpro.exe \x82̂\xA0\x82\xE9\x83t\x83H\x83\x8B\x83_(\x8Cl\x90ݒ\xE8\x83t\x83@\x83C\x83\x8B\x82̂\xA0\x82\xE9\x83t\x83H\x83\x8B\x83_)
+	char HomeDir[MAXPATHLEN];		// \x8Cl\x90ݒ\xE8\x83t\x83@\x83C\x83\x8B\x82̂\xA0\x82\xE9\x83t\x83H\x83\x8B\x83_
 
 	/* Setup file name */
 	char SetupFName[MAX_PATH];
@@ -635,7 +635,7 @@
 	BYTE UnicodeAmbiguousWidth;
 	BYTE UnicodeEmojiOverride;
 	BYTE UnicodeEmojiWidth;
-	wchar_t *HomeDirW;	// ttermpro.exe \x82̂\xA0\x82\xE9\x83t\x83H\x83\x8B\x83_(\x8Cl\x90ݒ\xE8\x83t\x83@\x83C\x83\x8B\x82̂\xA0\x82\xE9\x83t\x83H\x83\x8B\x83_)
+	wchar_t *HomeDirW;		// \x8Cl\x90ݒ\xE8\x83t\x83@\x83C\x83\x8B\x82̂\xA0\x82\xE9\x83t\x83H\x83\x8B\x83_
 	wchar_t *SetupFNameW;	// "TERATERM.INI" \x82̃t\x83\x8B\x83p\x83X
 	wchar_t *KeyCnfFNW;		// "KEYBOARD.CNF" \x82̃t\x83\x8B\x83p\x83X
 	wchar_t *LogFNW;

Modified: branches/setupdir/teraterm/teraterm/setupdirdlg.cpp
===================================================================
--- branches/setupdir/teraterm/teraterm/setupdirdlg.cpp	2022-05-02 13:56:12 UTC (rev 9900)
+++ branches/setupdir/teraterm/teraterm/setupdirdlg.cpp	2022-05-02 14:08:19 UTC (rev 9901)
@@ -324,6 +324,148 @@
 	return ret;
 }
 
+/**
+ *	\x83\x8A\x83X\x83g\x92\xE8\x8B`\x97p\x8D\\x91\xA2\x91\xCC
+ */
+typedef enum {
+	LIST_PARAM_STR = 1,			// \x95\xB6\x8E\x9A\x97\xF1
+	LIST_PARAM_FUNC = 2,		// \x8A֐\x94
+} SetupListParam;
+typedef struct {
+	const char *key;			// \x83e\x83L\x83X\x83g\x82̃L\x81[
+	const wchar_t *def_text;	// \x83f\x83t\x83H\x83\x8B\x83g\x83e\x83L\x83X\x83g
+	SetupListParam param;		// param_ptr \x82̓\xE0\x97e\x82\xF0\x8E\xA6\x82\xB7
+	void *param_ptr;			// param\x82\xAA\x8E\xA6\x82\xB7\x92l
+	void *data_ptr;				// \x8A֐\x94\x96\x88\x82Ɏg\x97p\x82\xB7\x82\xE9\x83f\x81[\x83^
+} SetupList;
+
+/**
+ *	\x83\x81\x83j\x83\x85\x81[\x82\xF0\x8Fo\x82\xB5\x82đI\x91\xF0\x82\xB3\x82ꂽ\x8F\x88\x97\x9D\x82\xF0\x8E\xC0\x8Ds\x82\xB7\x82\xE9
+ */
+static void PopupAndExec(HWND hWnd, const POINT *pointer_pos, const wchar_t *path, const TTTSet *pts)
+{
+	const wchar_t *UILanguageFile = pts->UILanguageFileW;
+	const DWORD file_stat = GetFileAttributesW(path);
+	const BOOL dir = (file_stat & FILE_ATTRIBUTE_DIRECTORY) != 0 ? TRUE : FALSE;
+
+	HMENU hMenu= CreatePopupMenu();
+	AppendMenuW(hMenu, (dir ? MF_DISABLED : MF_ENABLED) | MF_STRING | 0, 1, L"&Open file");
+	AppendMenuW(hMenu, MF_ENABLED | MF_STRING | 0, 2, L"Open folder(with explorer)");
+	AppendMenuW(hMenu, MF_ENABLED | MF_STRING | 0, 3, L"Send path to clipboard");
+	int result = TrackPopupMenu(hMenu, TPM_RETURNCMD, pointer_pos->x, pointer_pos->y, 0 , hWnd, NULL);
+	DestroyMenu(hMenu);
+	switch (result) {
+	case 1: {
+		// \x83A\x83v\x83\x8A\x82ŊJ\x82\xAD
+		const char *editor = pts->ViewlogEditor;
+		openFileWithApplication(path, editor, UILanguageFile);
+		break;
+	}
+	case 2: {
+		// \x83t\x83H\x83\x8B\x83_\x82\xF0\x8AJ\x82\xA2\x82āA\x83t\x83@\x83C\x83\x8B\x82\xF0\x91I\x91\xF0\x82\xB7\x82\xE9
+		openDirectoryWithExplorer(path, UILanguageFile);
+		break;
+	}
+	case 3: {
+		// \x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82֕\xB6\x8E\x9A\x97񑗐M
+		CBSetTextW(hWnd, path, 0);
+		break;
+	}
+	default:
+		break;
+	}
+}
+
+static wchar_t *GetCygtermIni(const SetupList *list, const TTTSet *pts)
+{
+	wchar_t *cygterm_ini;
+	aswprintf(&cygterm_ini, L"%s\\cygterm.cfg", pts->HomeDirW);
+	if (list->data_ptr != 0) {
+		wchar_t *virtual_store_path;
+		BOOL ret = convertVirtualStoreW(cygterm_ini, &virtual_store_path);
+		free(cygterm_ini);
+		if (ret) {
+			return virtual_store_path;
+		} else {
+			return NULL;
+		}
+	}
+	return cygterm_ini;
+}
+
+static wchar_t *GetTTXSSHKwnownHostFile(const SetupList *list, const TTTSet *)
+{
+	HMODULE h = GetModuleHandle("ttxssh.dll");
+	if (h == NULL) {
+		return NULL;
+	}
+
+	size_t (CALLBACK *func)(wchar_t *, size_t) = NULL;
+	void **pfunc = (void **)&func;
+	*pfunc = (void *)GetProcAddress(h, "TTXReadKnownHostsFile");
+	if (func == NULL) {
+		return NULL;
+	}
+
+	size_t size = func(NULL, 0);
+	if (size == 0) {
+		return NULL;
+	}
+
+	wchar_t *temp = (wchar_t *)malloc(sizeof(wchar_t) * size);
+	func(temp, size);
+	assert(!IsRelativePathW(temp));
+
+	if (list->data_ptr != 0) {
+		wchar_t *virtual_store_path;
+		BOOL ret = convertVirtualStoreW(temp, &virtual_store_path);
+		if (ret) {
+			return virtual_store_path;
+		} else {
+			return NULL;
+		}
+	}
+
+	return temp;
+}
+
+/**
+ *	Virtaul Store\x82ւ̃p\x83X\x82\xF0\x95Ԃ\xB7
+ */
+static wchar_t *GetVirtualStorePath(const SetupList *list, const TTTSet *)
+{
+	const wchar_t *path = (wchar_t *)list->data_ptr;
+	wchar_t *virtual_store_path;
+	BOOL ret = convertVirtualStoreW(path, &virtual_store_path);
+	if (ret) {
+		return virtual_store_path;
+	} else {
+		// virtual store\x82͎g\x97p\x82\xB3\x82\xEA\x82Ă\xA2\x82Ȃ\xA2
+		return NULL;
+	}
+}
+
+/**
+ *	Susie plug-in \x83p\x83X
+ */
+static wchar_t *GetSusiePluginPath(const SetupList *, const TTTSet *pts)
+{
+	const char *spi_path = pts->EtermLookfeel.BGSPIPath;
+	wchar_t *path;
+	aswprintf(&path, L"%s\\%hs", pts->ExeDirW, spi_path);
+	return path;
+}
+
+/**
+ *	Susie plug-in \x83p\x83X
+ */
+static wchar_t *GetCurrentPath(const SetupList *, const TTTSet *)
+{
+	wchar_t *path;
+	hGetCurrentDirectoryW(&path);
+	return path;
+}
+
 static INT_PTR CALLBACK OnSetupDirectoryDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
 {
 	static const DlgTextInfo TextInfos[] = {
@@ -449,6 +591,112 @@
 			}
 		}
 
+		/////////////////////////////////////////////////////////////
+		HWND hWndList = GetDlgItem(hDlgWnd, IDC_SETUP_DIR_LIST);
+		ListView_SetExtendedListViewStyleEx(hWndList, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
+
+		LV_COLUMNA lvcol;
+		lvcol.mask = LVCF_TEXT | LVCF_SUBITEM;
+		lvcol.pszText = (LPSTR)"name";
+		lvcol.iSubItem = 0;
+		//ListView_InsertColumn(hWndList, 0, &lvcol);
+		SendMessage(hWndList, LVM_INSERTCOLUMNA, 0, (LPARAM)&lvcol);
+
+		lvcol.pszText = (LPSTR)"path/file";
+		lvcol.iSubItem = 1;
+		//ListView_InsertColumn(hWndList, 1, &lvcol);
+		SendMessage(hWndList, LVM_INSERTCOLUMNA, 1, (LPARAM)&lvcol);
+
+		// \x90ݒ\xE8\x88ꗗ
+		static const SetupList setup_list[] = {
+			{ "DLG_SETUPDIR_INIFILE", L"Tera Term Configuration File",
+			  LIST_PARAM_STR, pts->SetupFNameW, },
+			{ NULL, L"  Virtual Store",
+			  LIST_PARAM_FUNC, (void *)GetVirtualStorePath, pts->SetupFNameW },
+			{ "DLG_SETUPDIR_KEYBOARDFILE", L"Keyboard Configuration File",
+			  LIST_PARAM_STR, pts->KeyCnfFNW },
+			{ NULL, L"  Virtual Store",
+			  LIST_PARAM_FUNC, (void*)GetVirtualStorePath, pts->KeyCnfFNW },
+			{ "DLG_SETUPDIR_CYGTERMFILE", L"CygTerm Configuration File",
+			  LIST_PARAM_FUNC, (void*)GetCygtermIni, (void *)0 },
+			{ NULL, L"  Virtual Store",
+			  LIST_PARAM_FUNC, (void*)GetCygtermIni, (void *)1 },
+			{ "DLG_SETUPDIR_KNOWNHOSTSFILE", L"SSH known_hosts File",
+			  LIST_PARAM_FUNC, (void*)GetTTXSSHKwnownHostFile, (void *)0 },
+			{ NULL, L"  Virtual Store",
+			  LIST_PARAM_FUNC, (void*)GetTTXSSHKwnownHostFile, (void *)1 },
+			{ NULL, L"CurrentDirectry",
+			  LIST_PARAM_FUNC, (void*)GetCurrentPath },
+			{ NULL, L"HomeDir",
+			  LIST_PARAM_STR, pts->HomeDirW },
+			{ NULL, L"ExeDir",
+			  LIST_PARAM_STR, pts->ExeDirW },
+			{ NULL, L"LogDir",
+			  LIST_PARAM_STR, pts->LogDirW },
+			{ NULL, L"LogDefaultPathW",
+			  LIST_PARAM_STR, pts->LogDefaultPathW },
+			{ NULL, L"Download",
+			  LIST_PARAM_STR, pts->FileDirW },
+			{ NULL, L"Susie Plugin Path",
+			  LIST_PARAM_FUNC, (void*)GetSusiePluginPath },
+			{ NULL, L"UI language file",
+			  LIST_PARAM_STR, pts->UILanguageFileW },
+		};
+
+		int y = 0;
+		for (const SetupList *list = &setup_list[0]; list != &setup_list[_countof(setup_list)]; list++) {
+
+			const SetupListParam param = list->param;
+			wchar_t *s;
+			if (param & LIST_PARAM_STR) {
+				// \x95\xB6\x8E\x9A\x97\xF1\x82ւ̃|\x83C\x83\x93\x83^
+				s = (wchar_t *)list->param_ptr;
+			} else if (param & LIST_PARAM_FUNC) {
+				// \x8A֐\x94\x82\xA9\x82當\x8E\x9A\x97\xF1\x82\xF0\x82\xE0\x82炤
+				typedef wchar_t *(*func_t)(const SetupList *list, TTTSet *pts);
+				func_t func = (func_t)list->param_ptr;
+				s = func(list, pts);
+			} else {
+				assert("bad list?");
+				s = NULL;
+			}
+			if (s == NULL) {
+				// \x95\\x8E\xA6\x95s\x97v
+				continue;
+			}
+
+			const char *key = list->key;
+			const wchar_t *def_text = list->def_text;
+			wchar_t *text;
+			GetI18nStrWW("Tera Term", key, def_text, pts->UILanguageFileW, &text);
+
+			LVITEMW item;
+			item.mask = LVIF_TEXT;
+			item.iItem = y;
+			item.iSubItem = 0;
+			item.pszText = text;
+			SendMessage(hWndList, LVM_INSERTITEMW, 0, (LPARAM)&item);
+			free(text);
+
+			item.mask = LVIF_TEXT;
+			item.iItem = y;
+			item.iSubItem = 1;
+			item.pszText = s;
+			SendMessage(hWndList, LVM_SETITEMW, 0, (LPARAM)&item);
+
+			y++;
+
+			if (param & LIST_PARAM_FUNC) {
+				// \x95\\x8E\xA6\x97p\x82ɂ\xE0\x82\xE7\x82\xC1\x82\xBD\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x8AJ\x95\xFA
+				free(s);
+			}
+		}
+
+		// \x95\x9D\x82𒲐\xAE
+		for (int i = 0; i < 2; i++) {
+			ListView_SetColumnWidth(hWndList, i, LVSCW_AUTOSIZE);
+		}
+
 		CenterWindow(hDlgWnd, GetParent(hDlgWnd));
 
 		return TRUE;
@@ -561,6 +809,39 @@
 		TTEndDialog(hDlgWnd, 0);
 		return TRUE;
 
+	case WM_NOTIFY: {
+		NMHDR *nmhdr = (NMHDR *)lp;
+		if (nmhdr->idFrom == IDC_SETUP_DIR_LIST) {
+			NMLISTVIEW *nmlist = (NMLISTVIEW *)lp;
+			switch (nmlist->hdr.code) {
+//			case NM_CLICK:
+			case NM_RCLICK: {
+				POINT pointer_pos;
+				GetCursorPos(&pointer_pos);
+				LVHITTESTINFO ht = {};
+				ht.pt = pointer_pos;
+				ScreenToClient(nmlist->hdr.hwndFrom, &ht.pt);
+				ListView_HitTest(nmlist->hdr.hwndFrom, &ht);
+				if (ht.flags & LVHT_ONITEM) {
+					int hit_item = ht.iItem;
+
+					wchar_t path[MAX_PATH];
+					LV_ITEMW item;
+					item.mask = TVIF_TEXT;
+					item.iItem = hit_item;
+					item.iSubItem = 1;
+					item.pszText = path;
+					item.cchTextMax = _countof(path);
+					SendMessageW(nmlist->hdr.hwndFrom, LVM_GETITEMW, 0, (LPARAM)&item);
+
+					PopupAndExec(nmlist->hdr.hwndFrom, &pointer_pos, path, pts);
+				}
+				break;
+			}
+			}
+		}
+		break;
+	}
 	default:
 		return FALSE;
 	}

Modified: branches/setupdir/teraterm/teraterm/ttermpro.rc
===================================================================
--- branches/setupdir/teraterm/teraterm/ttermpro.rc	2022-05-02 13:56:12 UTC (rev 9900)
+++ branches/setupdir/teraterm/teraterm/ttermpro.rc	2022-05-02 14:08:19 UTC (rev 9901)
@@ -313,7 +313,7 @@
     EDITTEXT        IDC_EDIT,5,5,150,112,ES_MULTILINE | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL | WS_HSCROLL
 END
 
-IDD_SETUP_DIR_DIALOG DIALOGEX 0, 0, 371, 224
+IDD_SETUP_DIR_DIALOG DIALOGEX 0, 0, 371, 306
 STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Setup directory"
 FONT 8, "Tahoma", 0, 0, 0x0
@@ -342,8 +342,9 @@
     PUSHBUTTON      "Open File",IDC_SSH_SETUPDIR_BUTTON_FILE,312,161,38,14
     LTEXT           "Virtual Store",IDC_SSH_SETUPDIR_STATIC_VSTORE,15,181,45,8
     EDITTEXT        IDC_SSH_SETUPDIR_EDIT_VSTORE,68,179,251,14,ES_AUTOHSCROLL | ES_READONLY
-    PUSHBUTTON      "Help",IDHELP,313,203,50,14
-    DEFPUSHBUTTON   "OK",IDOK,256,203,50,14
+    CONTROL         "",IDC_SETUP_DIR_LIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,7,201,356,78
+    DEFPUSHBUTTON   "OK",IDOK,256,285,50,14
+    PUSHBUTTON      "Help",IDHELP,313,285,50,14
 END
 
 IDD_SENDFILEDLG DIALOGEX 0, 0, 271, 188
@@ -463,7 +464,7 @@
         LEFTMARGIN, 7
         RIGHTMARGIN, 363
         TOPMARGIN, 7
-        BOTTOMMARGIN, 217
+        BOTTOMMARGIN, 299
     END
 
     IDD_SENDFILEDLG, DIALOG

Modified: branches/setupdir/teraterm/teraterm/vtwin.cpp
===================================================================
--- branches/setupdir/teraterm/teraterm/vtwin.cpp	2022-05-02 13:56:12 UTC (rev 9900)
+++ branches/setupdir/teraterm/teraterm/vtwin.cpp	2022-05-02 14:08:19 UTC (rev 9901)
@@ -4717,6 +4717,8 @@
 //
 void CVTWindow::OnOpenSetupDirectory()
 {
+	SetDialogFont(ts.DialogFontName, ts.DialogFontPoint, ts.DialogFontCharSet,
+				  ts.UILanguageFile, "Tera Term", "DLG_TAHOMA_FONT");
 	SetupDirectoryDialog(m_hInst, HVTWin, &ts);
 }
 


ttssh2-commit メーリングリストの案内
Back to archive index