Skip to content

Commit

Permalink
Bumped version 1.0.0.14.
Browse files Browse the repository at this point in the history
Added auto-change of working folder on drag-n-drop operations.
Added registration of context menu "Use Polang" for .po/.pot/.lang file types.
  • Loading branch information
raspopov committed Nov 19, 2017
1 parent 8b8cc5a commit bd49df9
Show file tree
Hide file tree
Showing 9 changed files with 410 additions and 141 deletions.
7 changes: 6 additions & 1 deletion BrowseCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "stdafx.h"
#include "Polang.h"
#include "BrowseCtrl.h"

#ifdef _DEBUG
Expand Down Expand Up @@ -54,6 +53,12 @@ void CBrowseCtrl::OnDropFiles( HDROP hDropInfo )
if ( DragQueryFile( hDropInfo, 0, szItem, _countof( szItem ) ) && ( GetFileAttributes( szItem ) & FILE_ATTRIBUTE_DIRECTORY ) == 0 )
{
SetWindowText( szItem );

if ( auto pOwner = GetParent() )
{
NMHDR hdr = { GetSafeHwnd(), (UINT_PTR)GetDlgCtrlID(), NM_DRAGDROP };
pOwner->SendMessage( WM_NOTIFY, (WPARAM)hdr.idFrom, (LPARAM)&hdr );
}
}

DragFinish( hDropInfo );
Expand Down
2 changes: 2 additions & 0 deletions BrowseCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ class CBrowseCtrl : public CMFCEditBrowseCtrl

DECLARE_MESSAGE_MAP()
};

#define NM_DRAGDROP (NM_FIRST + 1)
117 changes: 116 additions & 1 deletion Polang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define new DEBUG_NEW
#endif

#define Classes _T("SOFTWARE\\Classes\\")
#define Verb _T("\\Shell")
#define Command _T("\\Command")

// CPolangApp

BEGIN_MESSAGE_MAP(CPolangApp, CWinAppEx)
Expand All @@ -51,13 +55,124 @@ BOOL CPolangApp::InitInstance()
INITCOMMONCONTROLSEX InitCtrls = { sizeof( InitCtrls ), ICC_WIN95_CLASSES };
InitCommonControlsEx( &InitCtrls );

CWinApp::InitInstance();
__super::InitInstance();

// Activate "Windows Native" visual manager for enabling themes in MFC controls
CMFCVisualManager::SetDefaultManager( RUNTIME_CLASS( CMFCVisualManagerWindows ) );

SetRegistryKey( AFX_IDS_COMPANY_NAME );

int nRegister = 0;
int nArgs = 0;
if ( LPWSTR* szArglist = CommandLineToArgvW( GetCommandLineW(), &nArgs ) )
{
for ( int i = 1; i < nArgs; ++i )
{
if ( _tcsicmp( szArglist[ i ] + 1, _T("RegServer") ) == 0 )
{
nRegister = 1;
}
else if ( _tcsicmp( szArglist[ i ] + 1, _T( "UnRegServer" ) ) == 0 )
{
nRegister = -1;
}
}
LocalFree( szArglist );
}

CString sPath;
GetModuleFileName( NULL, sPath.GetBuffer( MAX_PATH ), MAX_PATH );
sPath.ReleaseBuffer();
sPath = CString( _T("\"") ) + sPath + _T("\" \"%1\"");

const CString sApp = AfxGetAppName();
const CString sName = LoadString( IDS_VERB_NAME );
const CString sType = LoadString( IDS_TYPE );

static const LPCTSTR szExts[] = { _T(".po"), _T(".pot"), _T(".lang") };
for ( int i = 0; i < 3; ++i )
{
for ( auto & szExt : szExts )
{
const CString sDefaultProgId = sApp + szExt;

CString sProgId;
DWORD nSize = 64;
DWORD nType = 0;
LSTATUS res = SHGetValue( HKEY_CLASSES_ROOT, szExt, NULL, &nType, sProgId.GetBuffer( nSize + 1 ), &nSize );
sProgId.ReleaseBuffer();
if ( res == ERROR_SUCCESS && nSize && nType == REG_SZ )
{
// OK
}
else
{
// Own extension key
sProgId = sDefaultProgId;

if ( nRegister >= 0 )
{
res = SHRegSetUSValue( CString( Classes ) + szExt, NULL, REG_SZ,
sProgId, sProgId.GetLength() * sizeof( TCHAR ), SHREGSET_HKCU );
res = SHRegSetUSValue( CString( Classes ) + szExt, NULL, REG_SZ,
sProgId, sProgId.GetLength() * sizeof( TCHAR ), SHREGSET_HKLM );

res = SHRegSetUSValue( CString( Classes ) + sProgId, NULL, REG_SZ,
sType, sType.GetLength() * sizeof( TCHAR ), SHREGSET_HKCU );
res = SHRegSetUSValue( CString( Classes ) + sProgId, NULL, REG_SZ,
sType, sType.GetLength() * sizeof( TCHAR ), SHREGSET_HKLM );
}
}

if ( nRegister >= 0 )
{
res = SHRegSetUSValue( CString( Classes ) + sProgId + Verb + _T("\\") + sApp, NULL, REG_SZ,
sName, sName.GetLength() * sizeof( TCHAR ), SHREGSET_HKCU );
res = SHRegSetUSValue( CString( Classes ) + sProgId + Verb + _T( "\\" ) + sApp, NULL, REG_SZ,
sName, sName.GetLength() * sizeof( TCHAR ), SHREGSET_HKLM );

res = SHRegSetUSValue( CString( Classes ) + sProgId + Verb + _T("\\") + sApp + Command, NULL, REG_SZ,
sPath, sPath.GetLength() * sizeof( TCHAR ), SHREGSET_HKCU );
res = SHRegSetUSValue( CString( Classes ) + sProgId + Verb + _T( "\\" ) + sApp + Command, NULL, REG_SZ,
sPath, sPath.GetLength() * sizeof( TCHAR ), SHREGSET_HKLM );
}
else
{
SHDeleteValue( HKEY_CLASSES_ROOT, sProgId + Verb + _T("\\") + sApp + Command, NULL );
SHDeleteEmptyKey( HKEY_CLASSES_ROOT, sProgId + Verb + _T("\\") + sApp + Command );

SHDeleteValue( HKEY_CLASSES_ROOT, sProgId + Verb + _T("\\") + sApp, NULL );
SHDeleteEmptyKey( HKEY_CLASSES_ROOT, sProgId + Verb + _T("\\") + sApp );

SHDeleteValue( HKEY_CLASSES_ROOT, sProgId + Verb, NULL );
SHDeleteEmptyKey( HKEY_CLASSES_ROOT, sProgId + Verb );

// Own extension key?
if ( sProgId == sDefaultProgId )
{
SHDeleteValue( HKEY_CLASSES_ROOT, sProgId, NULL );

SHDeleteEmptyKey( HKEY_CLASSES_ROOT, sProgId );

// Check for ProgID existence
res = SHDeleteEmptyKey( HKEY_CLASSES_ROOT, sProgId );
if ( res == ERROR_FILE_NOT_FOUND )
{
SHDeleteValue( HKEY_CLASSES_ROOT, szExt, NULL );
SHDeleteEmptyKey( HKEY_CLASSES_ROOT, szExt );
}
}
else
{
SHDeleteEmptyKey( HKEY_CLASSES_ROOT, sProgId );
}
}
}
}
if ( nRegister != 0 )
// Registration only
return FALSE;

CPolangDlg dlg;
m_pMainWnd = &dlg;
dlg.DoModal();
Expand Down
6 changes: 5 additions & 1 deletion Polang.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,38 @@ class CPolangApp : public CWinAppEx
CPolangApp();

protected:
virtual BOOL InitInstance();
virtual BOOL InitInstance() override;

DECLARE_MESSAGE_MAP()
};

extern CPolangApp theApp;

// Load string from resources
inline CString LoadString(UINT nId)
{
CString str;
VERIFY( str.LoadString( nId ) );
return str;
}

// Cut off file extension (i.e. extract path + filename only)
inline CString TrimExtension(LPCTSTR szFilename)
{
if ( ! szFilename || ! *szFilename )
return CString();
return CString( szFilename, (int)( PathFindExtension( szFilename ) - szFilename ) );
}

// Cut off file name from path (i.e. extract path only)
inline CString TrimFileName(LPCTSTR szFilename)
{
if ( ! szFilename || ! *szFilename )
return CString();
return CString( szFilename, (int)( PathFindFileName( szFilename ) - szFilename ) );
}

// Check if this is a real file on disk
inline bool IsFileName(LPCTSTR szFilename)
{
if ( ! szFilename || ! *szFilename )
Expand Down
Binary file modified Polang.rc
Binary file not shown.
Loading

0 comments on commit bd49df9

Please sign in to comment.