Skip to content

Commit

Permalink
Merge pull request rime#985 from fxliang/feats_and_fixes
Browse files Browse the repository at this point in the history
Feats and fixes
  • Loading branch information
determ1ne authored Aug 19, 2023
2 parents f6bac0a + 8dcc49c commit db79168
Show file tree
Hide file tree
Showing 17 changed files with 229 additions and 26 deletions.
76 changes: 71 additions & 5 deletions RimeWithWeasel/RimeWithWeasel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ UINT RimeWithWeaselHandler::AddSession(LPWSTR buffer, EatLine eat)
std::string schema_id = status.schema_id;
m_last_schema_id = schema_id;
_LoadSchemaSpecificSettings(schema_id);
_LoadAppInlinePreeditSet(session_id, true);
_UpdateInlinePreeditStatus(session_id);
_RefreshTrayIcon(session_id, _UpdateUICallback);
RimeFreeStatus(&status);
}
// show session's welcome message :-) if any
if (eat) {
Expand Down Expand Up @@ -441,11 +443,20 @@ void RimeWithWeaselHandler::_LoadSchemaSpecificSettings(const std::string& schem
memset(buffer, '\0', sizeof(buffer));
if (RimeConfigGetString(&config, "style/color_scheme", buffer, BUF_SIZE))
{
RimeConfig weaselconfig;
if (RimeConfigOpen("weasel", &weaselconfig))
std::string color_name(buffer);
RimeConfigIterator preset = {0};
if(RimeConfigBeginMap(&preset, &config, ("preset_color_schemes/" + color_name).c_str()))
{
_UpdateUIStyleColor(&config, m_ui->style(), color_name);
}
else
{
_UpdateUIStyleColor(&weaselconfig, m_ui->style(), std::string(buffer));
RimeConfigClose(&weaselconfig);
RimeConfig weaselconfig;
if (RimeConfigOpen("weasel", &weaselconfig))
{
_UpdateUIStyleColor(&weaselconfig, m_ui->style(), std::string(buffer));
RimeConfigClose(&weaselconfig);
}
}
}
// load schema icon start
Expand All @@ -461,6 +472,55 @@ void RimeWithWeaselHandler::_LoadSchemaSpecificSettings(const std::string& schem
RimeConfigClose(&config);
}

void RimeWithWeaselHandler::_LoadAppInlinePreeditSet(UINT session_id, bool ignore_app_name)
{
static char _app_name[50];
RimeGetProperty(session_id, "client_app", _app_name, sizeof(_app_name) - 1);
std::string app_name(_app_name);
if(!ignore_app_name && m_last_app_name == app_name)
return;
m_last_app_name = app_name;
if (!app_name.empty())
{
if (m_app_options.find(app_name) != m_app_options.end())
{
AppOptions& options(m_app_options[app_name]);
auto pfind = std::make_shared<bool>(false);
std::for_each(options.begin(), options.end(), [session_id, app_name, pfind, this](std::pair<const std::string, bool> &pair)
{
if(pair.first == "inline_preedit")
{
*pfind = true;
RimeSetOption(session_id, pair.first.c_str(), Bool(pair.second));
m_ui->style().inline_preedit = Bool(pair.second);
_UpdateInlinePreeditStatus(session_id);
}
});
if (!(*pfind))
{
goto load_schema_inline;
}
}
else
{
load_schema_inline:
RIME_STRUCT(RimeStatus, status);
if (RimeGetStatus(session_id, &status))
{
std::string schema_id = status.schema_id;
RimeConfig config;
if (!RimeSchemaOpen(schema_id.c_str(), &config)) return;
Bool inline_preedit = m_ui->style().inline_preedit;
if (RimeConfigGetBool(&config, "style/inline_preedit", &inline_preedit))
m_ui->style().inline_preedit = !!inline_preedit;
RimeConfigClose(&config);
RimeFreeStatus(&status);
_UpdateInlinePreeditStatus(session_id);
}
}
}
}

bool RimeWithWeaselHandler::_ShowMessage(Context& ctx, Status& status) {
// show as auxiliary string
std::wstring& tips(ctx.aux.str);
Expand Down Expand Up @@ -517,6 +577,8 @@ bool RimeWithWeaselHandler::_Respond(UINT session_id, EatLine eat)
std::set<std::string> actions;
std::list<std::string> messages;

// load App inline_preedit setting if app_name changed
_LoadAppInlinePreeditSet(session_id);
// extract information

RIME_STRUCT(RimeCommit, commit);
Expand Down Expand Up @@ -557,7 +619,7 @@ bool RimeWithWeaselHandler::_Respond(UINT session_id, EatLine eat)
messages.push_back(std::string("ctx.preedit.cursor=") +
std::to_string(utf8towcslen(first.c_str(), 0)) + ',' +
std::to_string(utf8towcslen(first.c_str(), first.size())) + ',' +
std::to_string(utf8towcslen(first.c_str(), ctx.composition.cursor_pos)) + '\n');
std::to_string(utf8towcslen(first.c_str(), first.size())) + '\n');
break;
}
// no preview, fall back to composition
Expand Down Expand Up @@ -1000,13 +1062,16 @@ void RimeWithWeaselHandler::_GetStatus(Status & stat, UINT session_id, Context&
if(schema_id != ".default") { // don't load for schema select menu
RimeSetOption(session_id, "__synced", false); // Sync new schema options with front end
_LoadSchemaSpecificSettings(schema_id);
_LoadAppInlinePreeditSet(session_id, true);
_UpdateInlinePreeditStatus(session_id); // in case of inline_preedit set in schema
_RefreshTrayIcon(session_id, _UpdateUICallback); // refresh icon after schema changed
ctx.aux.str = stat.schema_name;
m_ui->Update(ctx, stat);
m_ui->ShowWithTimeout(1200);
}
}
else
_LoadAppInlinePreeditSet(session_id);
RimeFreeStatus(&status);
}
}
Expand Down Expand Up @@ -1054,3 +1119,4 @@ void RimeWithWeaselHandler::_UpdateInlinePreeditStatus(UINT session_id)
// show soft cursor on weasel panel but not inline
RimeSetOption(session_id, "soft_cursor", Bool(!inline_preedit));
}

12 changes: 11 additions & 1 deletion WeaselSetup/InstallOptionsDlg.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "stdafx.h"
#include "stdafx.h"
#include "InstallOptionsDlg.h"
#include <atlstr.h>

Expand Down Expand Up @@ -32,6 +32,14 @@ LRESULT InstallOptionsDialog::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&) {
remove_.EnableWindow(installed);
dir_.EnableWindow(user_dir.empty() ? FALSE : TRUE);

ok_.Attach(GetDlgItem(IDOK));
if (installed)
ok_.SetWindowTextW(L"修改資料夾");

ime_.Attach(GetDlgItem(IDC_CHECK_INSTIME));
if (installed)
ime_.EnableWindow(FALSE);

CenterWindow();
return 0;
}
Expand Down Expand Up @@ -60,6 +68,8 @@ LRESULT InstallOptionsDialog::OnRemove(WORD, WORD code, HWND, BOOL&) {
const bool non_silent = false;
uninstall(non_silent);
installed = false;
ime_.EnableWindow(!installed);
ok_.SetWindowTextW(L"安裝");
cn_.EnableWindow(!installed);
tw_.EnableWindow(!installed);
remove_.EnableWindow(installed);
Expand Down
2 changes: 2 additions & 0 deletions WeaselSetup/InstallOptionsDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ class InstallOptionsDialog : public CDialogImpl<InstallOptionsDialog>
CButton remove_;
CButton default_dir_;
CButton custom_dir_;
CButton ok_;
CButton ime_;
CEdit dir_;
};
34 changes: 30 additions & 4 deletions WeaselSetup/WeaselSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "stdafx.h"

#include "resource.h"
#include <thread>

#include "InstallOptionsDlg.h"

Expand Down Expand Up @@ -34,6 +35,16 @@ int install(bool hant, bool silent, bool old_ime_support);
int uninstall(bool silent);
bool has_installed();

static std::wstring install_dir()
{
WCHAR exe_path[MAX_PATH] = { 0 };
GetModuleFileNameW(GetModuleHandle(NULL), exe_path, _countof(exe_path));
std::wstring dir(exe_path);
size_t pos = dir.find_last_of(L"\\");
dir.resize(pos);
return dir;
}

static int CustomInstall(bool installing)
{
bool hant = false;
Expand Down Expand Up @@ -65,11 +76,11 @@ static int CustomInstall(bool installing)
}
RegCloseKey(hKey);
}

bool _has_installed = has_installed();
if (!silent)
{
InstallOptionsDialog dlg;
dlg.installed = has_installed();
dlg.installed = _has_installed;
dlg.hant = hant;
dlg.user_dir = user_dir;
if (IDOK != dlg.DoModal()) {
Expand All @@ -80,10 +91,12 @@ static int CustomInstall(bool installing)
hant = dlg.hant;
user_dir = dlg.user_dir;
old_ime_support = dlg.old_ime_support;
_has_installed = dlg.installed;
}
}
if (0 != install(hant, silent, old_ime_support))
return 1;
if(!_has_installed)
if (0 != install(hant, silent, old_ime_support))
return 1;

ret = RegCreateKeyEx(HKEY_CURRENT_USER, KEY,
0, NULL, 0, KEY_ALL_ACCESS, 0, &hKey, NULL);
Expand All @@ -109,6 +122,19 @@ static int CustomInstall(bool installing)
MessageBox(NULL, L"無法寫入 Hant", L"安裝失敗", MB_ICONERROR | MB_OK);
return 1;
}
if (_has_installed)
{
std::wstring dir(install_dir());
std::thread th([dir]() {
ShellExecuteW(NULL, NULL, (dir + L"\\WeaselServer.exe").c_str(), L"/q", NULL, SW_SHOWNORMAL);
Sleep(500);
ShellExecuteW(NULL, NULL, (dir + L"\\WeaselServer.exe").c_str(), L"", NULL, SW_SHOWNORMAL);
Sleep(500);
ShellExecuteW(NULL, NULL, (dir + L"\\WeaselDeployer.exe").c_str(), L"/deploy", NULL, SW_SHOWNORMAL);
});
th.detach();
MessageBox(NULL, L"修改用戶資料夾位置成功:)", L"修改成功", MB_ICONINFORMATION | MB_OK);
}

return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions WeaselSetup/WeaselSetup.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>WeaselSetup</ProjectName>
</PropertyGroup>
<Import Project="..\weasel.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
Expand Down Expand Up @@ -50,7 +51,6 @@
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)output\</OutDir>
</PropertyGroup>
<Import Project="..\weasel.props" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
Expand All @@ -72,7 +72,7 @@
</Link>
<ResourceCompile>
<Culture>0x7804</Culture>
<AdditionalIncludeDirectories>$(SolutionDir)\include\wtl;$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(IntDir);$(SolutionDir)\include\wtl</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Midl>
Expand Down Expand Up @@ -115,7 +115,7 @@
</Link>
<ResourceCompile>
<Culture>0x7804</Culture>
<AdditionalIncludeDirectories>$(SolutionDir)\include\wtl10;$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(IntDir);$(SolutionDir)\include\wtl</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Midl>
Expand Down
5 changes: 4 additions & 1 deletion WeaselTSF/Composition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ STDAPI CStartCompositionEditSession::DoEditSession(TfEditCookie ec)

/* set selection */
TF_SELECTION tfSelection;
pRangeComposition->Collapse(ec, TF_ANCHOR_END);
if(_inlinePreeditEnabled)
pRangeComposition->Collapse(ec, TF_ANCHOR_END);
else
pRangeComposition->Collapse(ec, TF_ANCHOR_START);
tfSelection.range = pRangeComposition;
tfSelection.style.ase = TF_AE_NONE;
tfSelection.style.fInterimChar = FALSE;
Expand Down
39 changes: 38 additions & 1 deletion WeaselTSF/LanguageBar.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "stdafx.h"
#include <resource.h>
#include <thread>
#include <shellapi.h>
#include "WeaselTSF.h"
#include "LanguageBar.h"
#include "CandidateList.h"
Expand Down Expand Up @@ -277,10 +279,45 @@ void CLangBarItemButton::SetLangbarStatus(DWORD dwStatus, BOOL fSet)
return;
}

BOOL is_wow64()
{
DWORD errorCode;
if (GetSystemWow64DirectoryW(NULL, 0) == 0)
if ((errorCode = GetLastError()) == ERROR_CALL_NOT_IMPLEMENTED)
return FALSE;
else
ExitProcess((UINT)errorCode);
else
return TRUE;
}

void WeaselTSF::_HandleLangBarMenuSelect(UINT wID)
{
m_client.TrayCommand(wID);
if(wID != ID_WEASELTRAY_RERUN_SERVICE)
m_client.TrayCommand(wID);
else
{
std::wstring WEASEL_REG_NAME_;
if(is_wow64())
WEASEL_REG_NAME_ = L"Software\\WOW6432Node\\Rime\\Weasel";
else
WEASEL_REG_NAME_ = L"Software\\Rime\\Weasel";

TCHAR szValue[MAX_PATH];
DWORD dwBufLen = MAX_PATH;

LONG lRes = RegGetValue(HKEY_LOCAL_MACHINE, WEASEL_REG_NAME_.c_str(), L"WeaselRoot", RRF_RT_REG_SZ, NULL, szValue, &dwBufLen);
if(lRes == ERROR_SUCCESS)
{
std::wstring dir(szValue);
std::thread th([dir]() {
ShellExecuteW(NULL, L"open", (dir + L"\\stop_service.bat").c_str(), NULL, dir.c_str(), SW_HIDE);
Sleep(100);
ShellExecuteW(NULL, L"open", (dir + L"\\start_service.bat").c_str(), NULL, dir.c_str(), SW_HIDE);
});
th.detach();
}
}
}

HWND WeaselTSF::_GetFocusedContextWindow()
Expand Down
Binary file modified WeaselTSF/WeaselTSF.rc
Binary file not shown.
8 changes: 6 additions & 2 deletions WeaselUI/HorizontalLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ void HorizontalLayout::DoLayout(CDCHandle dc, PDWR pDWR )
int w = offsetX + real_margin_x;

/* calc mark_text sizes */
if (!_style.mark_text.empty() && (_style.hilited_mark_color & 0xff000000))
if ((_style.hilited_mark_color & 0xff000000))
{
CSize sg;
GetTextSizeDW(_style.mark_text, _style.mark_text.length(), pDWR->pTextFormat, pDWR, &sg);
if(_style.mark_text.empty())
GetTextSizeDW(L"|", 1, pDWR->pTextFormat, pDWR, &sg);
else
GetTextSizeDW(_style.mark_text, _style.mark_text.length(), pDWR->pTextFormat, pDWR, &sg);

MARK_WIDTH = sg.cx;
MARK_HEIGHT = sg.cy;
MARK_GAP = MARK_WIDTH + 4;
Expand Down
2 changes: 1 addition & 1 deletion WeaselUI/StandardLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,5 +394,5 @@ bool StandardLayout::ShouldDisplayStatusIcon() const
// rule 2. show status icon when switching mode
// rule 3. always show status icon with tips
// rule 4. rule 3 excluding tips FullScreenLayout with strings
return (_status.ascii_mode || !_status.composing || !_context.aux.empty()) && !((_style.layout_type == UIStyle::LAYOUT_HORIZONTAL_FULLSCREEN || _style.layout_type == UIStyle::LAYOUT_VERTICAL_FULLSCREEN) && !_context.aux.empty());
return ((_status.ascii_mode && !_style.inline_preedit)|| !_status.composing || !_context.aux.empty()) && !((_style.layout_type == UIStyle::LAYOUT_HORIZONTAL_FULLSCREEN || _style.layout_type == UIStyle::LAYOUT_VERTICAL_FULLSCREEN) && !_context.aux.empty());
}
Loading

0 comments on commit db79168

Please sign in to comment.