Fixed issue #2507: Support keyboard shortcuts in yes/no prompts
[TortoiseGit.git] / src / TortoiseUDiff / TortoiseUDiff.cpp
blobec817531f5a37afdde6fb083c0cfb90e22298bf1
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008, 2010-2012, 2014-2015 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "TortoiseUDiff.h"
21 #include "MainWindow.h"
22 #include "CmdLineParser.h"
23 #include "TaskbarUUID.h"
24 #include "registry.h"
25 #include "LangDll.h"
26 #include "../version.h"
27 #include "../Utils/CrashReport.h"
29 #include <commctrl.h>
30 #pragma comment(lib, "comctl32.lib")
32 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
34 HINSTANCE hResource; // the resource dll
36 int APIENTRY _tWinMain(HINSTANCE hInstance,
37 HINSTANCE /*hPrevInstance*/,
38 LPTSTR lpCmdLine,
39 int /*nCmdShow*/)
41 SetDllDirectory(L"");
42 SetTaskIDPerUUID();
43 CRegStdDWORD loc = CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
44 long langId = loc;
45 MSG msg;
46 HACCEL hAccelTable;
48 #if ENABLE_CRASHHANLDER
49 CCrashReportTGit crasher(_T("TortoiseGitUDiff ") _T(APP_X64_STRING), TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD, TGIT_VERDATE);
50 CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
51 #endif
53 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
55 CLangDll langDLL;
56 hResource = langDLL.Init(_T("TortoiseGitUDiff"), langId);
57 if (hResource == NULL)
58 hResource = hInstance;
60 CCmdLineParser parser(lpCmdLine);
62 if (parser.HasKey(_T("?")) || parser.HasKey(_T("help")))
64 ResString rHelp(hResource, IDS_COMMANDLINEHELP);
65 MessageBox(nullptr, rHelp, L"TortoiseGitUDiff", MB_ICONINFORMATION);
66 return 0;
69 INITCOMMONCONTROLSEX used = {
70 sizeof(INITCOMMONCONTROLSEX),
71 ICC_STANDARD_CLASSES | ICC_BAR_CLASSES
73 InitCommonControlsEx(&used);
76 HMODULE hSciLexerDll = ::LoadLibrary(_T("SciLexer_tgit.dll"));
77 if (hSciLexerDll == NULL)
78 return FALSE;
80 CMainWindow mainWindow(hResource);
81 mainWindow.SetRegistryPath(_T("Software\\TortoiseGit\\UDiffViewerWindowPos"));
82 if (parser.HasVal(_T("title")))
83 mainWindow.SetTitle(parser.GetVal(_T("title")));
84 else if (parser.HasVal(_T("patchfile")))
85 mainWindow.SetTitle(parser.GetVal(_T("patchfile")));
86 else
88 ResString rPipeTitle(hResource, IDS_PIPETITLE);
89 mainWindow.SetTitle(rPipeTitle);
92 if (!mainWindow.RegisterAndCreateWindow())
94 FreeLibrary(hSciLexerDll);
95 return 0;
98 bool bLoadedSuccessfully = false;
99 if ( (lpCmdLine[0] == 0) ||
100 (parser.HasKey(_T("p"))) )
102 // input from console pipe
103 // set console to raw mode
104 DWORD oldMode;
105 GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &oldMode);
106 SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), oldMode & ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT));
108 bLoadedSuccessfully = mainWindow.LoadFile(GetStdHandle(STD_INPUT_HANDLE));
110 else if (parser.HasVal(_T("patchfile")))
111 bLoadedSuccessfully = mainWindow.LoadFile(parser.GetVal(_T("patchfile")));
112 else if (lpCmdLine[0] != 0)
113 bLoadedSuccessfully = mainWindow.LoadFile(lpCmdLine);
116 if (!bLoadedSuccessfully)
118 FreeLibrary(hSciLexerDll);
119 return 0;
122 ::ShowWindow(mainWindow.GetHWNDEdit(), SW_SHOW);
123 ::SetFocus(mainWindow.GetHWNDEdit());
125 hAccelTable = LoadAccelerators(hResource, MAKEINTRESOURCE(IDC_TORTOISEUDIFF));
127 // Main message loop:
128 while (GetMessage(&msg, NULL, 0, 0))
130 if (!TranslateAccelerator(mainWindow, hAccelTable, &msg))
132 TranslateMessage(&msg);
133 DispatchMessage(&msg);
137 FreeLibrary(hSciLexerDll);
138 return (int) msg.wParam;