Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5bf2d7ab45 | ||
|
|
4ab1f3c950 |
No files matched your search
+9
-3
@@ -81,11 +81,17 @@ Warning і початковий фокус на No.
|
||||
Рядки зіставляються за вмістом. Зміни лише у відступах і кінцевих пробілах
|
||||
типово пропускаються. Перемикач **Show whitespace changes** показує їх.
|
||||
Вставлені й видалені порожні рядки враховуються завжди.
|
||||
**Apply to left/right** копіює виділений блок у відповідну сторону.
|
||||
Порівняння перераховується, а змінену сторону позначає зірочка.
|
||||
**Undo** або **Ctrl+Z** повертає останню незаписану дію.
|
||||
**Save left/right** зберігає відповідну сторону, **Ctrl+S** зберігає обидві.
|
||||
Зовнішня зміна цільового файла зупиняє запис і залишає правки для перегляду.
|
||||
Закриття зі змінами пропонує Save, Discard або Cancel.
|
||||
Кнопка розгортання в системному заголовку збільшує вікно порівняння
|
||||
до робочої області екрана. Повторне натискання відновлює попередній розмір.
|
||||
Вікно працює в режимі перегляду. Підтримуються UTF-8 і UTF-16 з BOM,
|
||||
до 2 МіБ і 100 000 рядків на файл. Стилі переносу рядків порівнюються
|
||||
як рівнозначні.
|
||||
Підтримуються UTF-8 і UTF-16 з BOM, до 2 МіБ і 100 000 рядків на файл.
|
||||
Стилі переносу рядків порівнюються як рівнозначні. Під час запису
|
||||
зберігаються кодування, BOM і наявні кінці рядків цільового файла.
|
||||
|
||||
- У меню Files і його списках, що випадають, стрілки вгору й вниз
|
||||
переходять між першим і останнім пунктами циклічно та оминають розділювачі.
|
||||
|
||||
+5
-4
@@ -418,11 +418,12 @@ EXSTYLE WS_EX_APPWINDOW
|
||||
CAPTION "Compare files"
|
||||
FONT 9, "Segoe UI"
|
||||
BEGIN
|
||||
LTEXT "", 400, 4, 30, 247, 13, SS_ENDELLIPSIS | SS_NOPREFIX
|
||||
LTEXT "", 401, 259, 30, 247, 13, SS_ENDELLIPSIS | SS_NOPREFIX
|
||||
CONTROL "", 402, "ListBox", LBS_OWNERDRAWFIXED | LBS_NODATA | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP | WS_BORDER, 0, 45, 510, 207
|
||||
LTEXT "", 400, 4, 50, 247, 13, SS_ENDELLIPSIS | SS_NOPREFIX
|
||||
LTEXT "", 401, 259, 50, 247, 13, SS_ENDELLIPSIS | SS_NOPREFIX
|
||||
CONTROL "", 402, "ListBox", LBS_OWNERDRAWFIXED | LBS_NODATA | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP | WS_BORDER, 0, 65, 510, 187
|
||||
CONTROL "", 407, "ToolbarWindow32", CCS_NORESIZE | CCS_NOPARENTALIGN | TBSTYLE_FLAT | TBSTYLE_LIST | WS_TABSTOP, 10, 8, 200, 19
|
||||
LTEXT "", 403, 216, 12, 98, 14
|
||||
CONTROL "", 408, "ToolbarWindow32", CCS_NORESIZE | CCS_NOPARENTALIGN | TBSTYLE_FLAT | TBSTYLE_LIST | WS_TABSTOP, 10, 28, 490, 19
|
||||
END
|
||||
|
||||
115 DIALOGEX 0, 0, 290, 58
|
||||
@@ -430,7 +431,7 @@ STYLE DS_SETFONT | DS_CENTER | WS_POPUP
|
||||
CAPTION "Compare files"
|
||||
FONT 10, "Consolas"
|
||||
BEGIN
|
||||
LTEXT "Reading and comparing files...", -1, 14, 15, 262, 13
|
||||
LTEXT "Reading and comparing files...", 548, 14, 15, 262, 13
|
||||
CONTROL "&Cancel", IDCANCEL, "Button", BS_OWNERDRAW | WS_TABSTOP, 101, 31, 88, 17
|
||||
END
|
||||
|
||||
|
||||
+390
-70
@@ -67,6 +67,11 @@ struct CompareFile
|
||||
std::wstring label;
|
||||
std::optional<FilesPeer> peer;
|
||||
std::optional<FtpProfile> ftp;
|
||||
std::optional<ks::files::RemoteTextSource> remote;
|
||||
ks::files::RemoteTextRevision revision;
|
||||
std::string originalBytes;
|
||||
std::wstring originalText;
|
||||
bool dirty{};
|
||||
};
|
||||
|
||||
struct CompareRow
|
||||
@@ -81,11 +86,18 @@ struct CompareRow
|
||||
|
||||
struct FileComparison
|
||||
{
|
||||
static constexpr std::array controls{400,401,402,403,407};
|
||||
static constexpr std::array controls{400,401,402,403,407,408};
|
||||
CompareFile files[2];
|
||||
std::vector<std::wstring> lines[2];
|
||||
ks::files::ComparisonText text[2];
|
||||
std::vector<CompareRow> rows;
|
||||
std::vector<int> changes,allChanges;
|
||||
struct Undo
|
||||
{
|
||||
int side{};
|
||||
ks::files::ComparisonReplace edit;
|
||||
};
|
||||
std::vector<Undo> undo;
|
||||
bool working{};
|
||||
bool showWhitespace{};
|
||||
RECT initialClient{};
|
||||
std::array<RECT,controls.size()> initialControls{};
|
||||
@@ -206,63 +218,132 @@ bool handleComparisonMessage(MSG &message)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
std::vector<std::wstring> readComparisonLines(const CompareFile &input,const std::atomic_bool &canceled)
|
||||
struct CompareCache
|
||||
{
|
||||
struct TemporaryDirectory
|
||||
fs::path directory;
|
||||
|
||||
fs::path create()
|
||||
{
|
||||
fs::path path;
|
||||
~TemporaryDirectory()
|
||||
{
|
||||
if(path.empty()) return;
|
||||
std::error_code ignored;
|
||||
fs::remove_all(path,ignored);
|
||||
}
|
||||
} temporary;
|
||||
auto path=input.path;
|
||||
if(input.ftp || input.peer)
|
||||
{
|
||||
const auto directory=fs::temp_directory_path()/(L"ks-files-compare-"+ks::wide(ks::lan::randomHex(16)));
|
||||
requireFileOperation(fs::create_directory(directory),ERROR_ALREADY_EXISTS);
|
||||
temporary.path=directory;
|
||||
path=directory/L"file";
|
||||
CopyHost source(input.peer?&*input.peer:nullptr,input.ftp);
|
||||
const auto info=source.stat(input.path,canceled);
|
||||
requireFileOperation(info.has_value(),ERROR_FILE_NOT_FOUND);
|
||||
requireFileOperation(!(info->attributes&(FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_REPARSE_POINT)),
|
||||
ERROR_NOT_SUPPORTED);
|
||||
requireFileOperation(info->size<=compareFileLimit,ERROR_FILE_TOO_LARGE);
|
||||
FilesConnection local;
|
||||
const auto progress=[&](uint64_t,uint64_t){return !canceled;};
|
||||
if(source.ftp) downloadFtpFile(*source.ftp,local,input.path,path,*info,false,progress);
|
||||
else ks::lan::streamFile(*source.files,local,input.peer->id,input.path,path,info->size,
|
||||
info->modified,false,false,progress);
|
||||
auto path=fs::temp_directory_path()/(L"ks-files-compare-"+ks::wide(ks::lan::randomHex(16)));
|
||||
requireFileOperation(fs::create_directory(path),ERROR_ALREADY_EXISTS);
|
||||
directory=std::move(path);
|
||||
return directory/L"file";
|
||||
}
|
||||
ks::files::TextDocument document(path,false);
|
||||
|
||||
~CompareCache()
|
||||
{
|
||||
if(directory.empty()) return;
|
||||
std::error_code ignored;
|
||||
fs::remove_all(directory,ignored);
|
||||
}
|
||||
};
|
||||
|
||||
ks::files::RemoteTextRevision comparisonLocalRevision(const fs::path &path)
|
||||
{
|
||||
WIN32_FILE_ATTRIBUTE_DATA info{};
|
||||
checkFileOperation(GetFileAttributesExW(path.c_str(),GetFileExInfoStandard,&info)!=FALSE);
|
||||
requireFileOperation(!(info.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY),ERROR_NOT_SUPPORTED);
|
||||
const auto size=(uint64_t(info.nFileSizeHigh)<<32)|info.nFileSizeLow;
|
||||
const auto stamp=(uint64_t(info.ftLastWriteTime.dwHighDateTime)<<32)|info.ftLastWriteTime.dwLowDateTime;
|
||||
return {size,stamp,(info.dwFileAttributes&(FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_REPARSE_POINT))==0};
|
||||
}
|
||||
|
||||
std::string comparisonRawBytes(const ks::files::TextDocument &document,const std::atomic_bool &canceled)
|
||||
{
|
||||
requireFileOperation(document.size()<=compareFileLimit,ERROR_FILE_TOO_LARGE);
|
||||
std::string raw;
|
||||
raw.reserve(static_cast<size_t>(document.size()));
|
||||
while(raw.size()<document.size())
|
||||
{
|
||||
requireFileOperation(!canceled,ERROR_CANCELLED);
|
||||
raw+=document.readBytes(raw.size(),ks::files::hexPageBytes);
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
|
||||
ks::files::ComparisonText readComparisonLines(CompareFile &input,const std::atomic_bool &canceled)
|
||||
{
|
||||
CompareCache temp;
|
||||
auto path=input.path;
|
||||
if(input.ftp) input.remote=ftpTextSource(*input.ftp);
|
||||
else if(input.peer)
|
||||
{
|
||||
FilesConnection source(&*input.peer);
|
||||
const auto info=statFile(source,input.path);
|
||||
requireFileOperation(info.has_value(),ERROR_FILE_NOT_FOUND);
|
||||
requireFileOperation(!(info->attributes&(FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_REPARSE_POINT)),ERROR_NOT_SUPPORTED);
|
||||
input.remote=ks::files::createLanTextSource(*input.peer);
|
||||
}
|
||||
if(input.remote)
|
||||
{
|
||||
path=temp.create();
|
||||
input.revision=input.remote->download(input.path,path,false,[&](uint64_t,uint64_t){return !canceled;},
|
||||
compareFileLimit);
|
||||
}
|
||||
else input.revision=comparisonLocalRevision(path);
|
||||
|
||||
ks::files::TextDocument document(path,false);
|
||||
input.originalBytes=comparisonRawBytes(document,canceled);
|
||||
std::string text;
|
||||
for(uint64_t page=0;page<document.pages() && !canceled;++page) text+=document.readPage(page);
|
||||
requireFileOperation(!canceled,ERROR_CANCELLED);
|
||||
if(std::any_of(text.begin(),text.end(),[](unsigned char ch){
|
||||
return ch<32 && ch!='\t' && ch!='\r' && ch!='\n' && ch!='\f';
|
||||
})) throw std::runtime_error("Select two text files.");
|
||||
if(!input.remote && (comparisonLocalRevision(path).modified!=input.revision.modified ||
|
||||
comparisonRawBytes(document,canceled)!=input.originalBytes))
|
||||
throw std::runtime_error("The file changed while it was read for comparison.");
|
||||
if(text.empty()) return {};
|
||||
const auto bytes=static_cast<int>(text.size());
|
||||
const auto count=MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,text.data(),bytes,nullptr,0);
|
||||
if(!count) throw std::runtime_error("Compare files supports UTF-8 and UTF-16 text.");
|
||||
std::wstring decoded(count,L'\0');
|
||||
checkFileOperation(MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,text.data(),bytes,decoded.data(),count)!=0);
|
||||
std::vector<std::wstring> lines;
|
||||
size_t start=0;
|
||||
while(true)
|
||||
auto result=ks::files::splitComparisonText(decoded);
|
||||
if(result.lines.size()>100'000) throw std::runtime_error("Each file can contain up to 100,000 lines.");
|
||||
input.originalText=std::move(decoded);
|
||||
return result;
|
||||
}
|
||||
|
||||
void saveComparisonFile(CompareFile &file,const ks::files::ComparisonText &text,const std::atomic_bool &canceled)
|
||||
{
|
||||
requireFileOperation(file.revision.editable,ERROR_ACCESS_DENIED);
|
||||
CompareCache temporary;
|
||||
auto target=file.path;
|
||||
if(file.remote)
|
||||
{
|
||||
requireFileOperation(!canceled,ERROR_CANCELLED);
|
||||
if(lines.size()==100'000) throw std::runtime_error("Each file can contain up to 100,000 lines.");
|
||||
const auto end=decoded.find_first_of(L"\r\n",start);
|
||||
lines.push_back(decoded.substr(start,end==decoded.npos?end:end-start));
|
||||
if(end==decoded.npos) break;
|
||||
start=end+((decoded[end]==L'\r' && end+1<decoded.size() && decoded[end+1]==L'\n')?2:1);
|
||||
target=temporary.create();
|
||||
const auto revision=file.remote->download(file.path,target,true,[&](uint64_t,uint64_t){return !canceled;},
|
||||
compareFileLimit);
|
||||
if(revision.modified!=file.revision.modified || revision.size!=file.revision.size)
|
||||
throw std::runtime_error("The file changed since it was compared. Open a new comparison before saving.");
|
||||
}
|
||||
return lines;
|
||||
else
|
||||
{
|
||||
const auto revision=comparisonLocalRevision(target);
|
||||
requireFileOperation(revision.editable,ERROR_ACCESS_DENIED);
|
||||
if(revision.modified!=file.revision.modified || revision.size!=file.revision.size)
|
||||
throw std::runtime_error("The file changed since it was compared. Open a new comparison before saving.");
|
||||
}
|
||||
ks::files::TextDocument document(target,true);
|
||||
if(comparisonRawBytes(document,canceled)!=file.originalBytes)
|
||||
throw std::runtime_error("The file changed since it was compared. Open a new comparison before saving.");
|
||||
auto joined=text.joined();
|
||||
const auto contents=ks::utf8(joined);
|
||||
const auto bytes=document.encoding()==ks::files::TextEncoding::utf8?contents.size():
|
||||
joined.size()*sizeof(wchar_t);
|
||||
requireFileOperation(bytes+document.boundary(0)<=compareFileLimit,ERROR_FILE_TOO_LARGE);
|
||||
for(uint64_t page=1;page<document.pages();++page) document.stage(page,{});
|
||||
document.stage(0,contents);
|
||||
requireFileOperation(!canceled,ERROR_CANCELLED);
|
||||
if(!document.save()) throw std::runtime_error("The file was saved but could not be reopened.");
|
||||
if(file.remote)
|
||||
file.revision=file.remote->upload(file.path,target,file.revision);
|
||||
else file.revision=comparisonLocalRevision(target);
|
||||
const std::atomic_bool committed{};
|
||||
file.originalBytes=comparisonRawBytes(document,committed);
|
||||
file.originalText=std::move(joined);
|
||||
file.dirty=false;
|
||||
}
|
||||
|
||||
std::wstring_view comparisonContent(std::wstring_view line)
|
||||
@@ -274,7 +355,7 @@ std::wstring_view comparisonContent(std::wstring_view line)
|
||||
|
||||
void alignComparison(FileComparison &result,const std::atomic_bool &canceled)
|
||||
{
|
||||
const auto &left=result.lines[0],&right=result.lines[1];
|
||||
const auto &left=result.text[0].lines,&right=result.text[1].lines;
|
||||
std::map<std::wstring_view,unsigned> ids;
|
||||
std::map<unsigned,unsigned> blankIds;
|
||||
unsigned nextId=1;
|
||||
@@ -436,6 +517,174 @@ void alignComparison(FileComparison &result,const std::atomic_bool &canceled)
|
||||
append(static_cast<int>(a.size()-suffix+i),static_cast<int>(b.size()-suffix+i));
|
||||
}
|
||||
|
||||
enum ComparisonCommand { applyLeft=409,applyRight,undoCompare,saveLeft,saveRight,saveComparison };
|
||||
|
||||
struct ComparisonProgress
|
||||
{
|
||||
const wchar_t *status;
|
||||
bool cancelable=true;
|
||||
std::atomic_bool canceled{};
|
||||
};
|
||||
|
||||
INT_PTR CALLBACK comparisonProgressDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp);
|
||||
|
||||
template<class Work>
|
||||
bool runComparisonWork(HWND owner,const wchar_t *status,bool cancelable,const Work &work)
|
||||
{
|
||||
ComparisonProgress state{status,cancelable};
|
||||
FileOperationUi worker;
|
||||
FilesModalDialog progress(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(115),owner,
|
||||
comparisonProgressDialog,reinterpret_cast<LPARAM>(&state),false);
|
||||
if(!progress.window()) throw std::runtime_error("Could not open the comparison progress dialog.");
|
||||
progress.show();
|
||||
try {worker.run(progress.window(),state.canceled,[&]{work(state.canceled);});}
|
||||
catch(const std::system_error &error)
|
||||
{
|
||||
if(error.code().value()==ERROR_CANCELLED) return false;
|
||||
throw;
|
||||
}
|
||||
return !state.canceled;
|
||||
}
|
||||
|
||||
std::optional<ks::files::ComparisonReplace> comparisonBlock(const FileComparison &comparison,int side,LRESULT selected)
|
||||
{
|
||||
if(selected<0 || static_cast<size_t>(selected)>=comparison.rows.size() ||
|
||||
!comparison.rows[selected].hasChange(comparison.showWhitespace)) return {};
|
||||
auto first=static_cast<size_t>(selected),end=first+1;
|
||||
while(first>0 && comparison.rows[first-1].hasChange(comparison.showWhitespace)) --first;
|
||||
while(end<comparison.rows.size() && comparison.rows[end].hasChange(comparison.showWhitespace)) ++end;
|
||||
const auto line=[](const CompareRow &row,int file){return file==0?row.left:row.right;};
|
||||
const auto &target=comparison.text[side];
|
||||
const auto &source=comparison.text[1-side];
|
||||
ks::files::ComparisonReplace edit{target.lines.size()};
|
||||
for(size_t row=first;row<end;++row)
|
||||
{
|
||||
const auto old=line(comparison.rows[row],side);
|
||||
const auto incoming=line(comparison.rows[row],1-side);
|
||||
if(old>=0)
|
||||
{
|
||||
edit.start=std::min(edit.start,static_cast<size_t>(old));
|
||||
++edit.count;
|
||||
}
|
||||
if(incoming>=0)
|
||||
{
|
||||
edit.lines.push_back(source.lines[incoming]);
|
||||
edit.endings.push_back(old>=0?target.endings[old]:target.preferred);
|
||||
}
|
||||
}
|
||||
if(!edit.count)
|
||||
for(size_t row=end;row<comparison.rows.size();++row)
|
||||
if(const auto next=line(comparison.rows[row],side);next>=0)
|
||||
{
|
||||
edit.start=static_cast<size_t>(next);
|
||||
break;
|
||||
}
|
||||
return edit;
|
||||
}
|
||||
|
||||
void updateComparisonSummary(HWND dialog,const FileComparison &comparison);
|
||||
|
||||
void comparisonUpdateRows(HWND dialog,const FileComparison &comparison,LRESULT selected,LRESULT top)
|
||||
{
|
||||
const auto list=GetDlgItem(dialog,402);
|
||||
SendMessageW(list,LB_SETCOUNT,comparison.rows.size(),0);
|
||||
if(!comparison.rows.empty())
|
||||
{
|
||||
const auto last=static_cast<LRESULT>(comparison.rows.size())-1;
|
||||
SendMessageW(list,LB_SETCURSEL,std::clamp<LRESULT>(selected,0,last),0);
|
||||
SendMessageW(list,LB_SETTOPINDEX,std::clamp<LRESULT>(top,0,last),0);
|
||||
}
|
||||
updateComparisonSummary(dialog,comparison);
|
||||
InvalidateRect(list,nullptr,TRUE);
|
||||
}
|
||||
|
||||
bool applyComparisonEdit(HWND dialog,FileComparison &comparison,int side,const ks::files::ComparisonReplace &edit,
|
||||
bool remember)
|
||||
{
|
||||
const auto list=GetDlgItem(dialog,402);
|
||||
const auto selected=SendMessageW(list,LB_GETCURSEL,0,0);
|
||||
const auto top=SendMessageW(list,LB_GETTOPINDEX,0,0);
|
||||
FileComparison candidate;
|
||||
ks::files::ComparisonReplace reverse;
|
||||
comparison.working=true;
|
||||
try
|
||||
{
|
||||
const bool success=runComparisonWork(dialog,L"Updating comparison…",true,[&](const auto &stop) {
|
||||
candidate.text[0]=comparison.text[0];
|
||||
candidate.text[1]=comparison.text[1];
|
||||
reverse=ks::files::replaceComparisonText(candidate.text[side],edit);
|
||||
if(candidate.text[side].lines.size()>100'000)
|
||||
throw std::runtime_error("Each file can contain up to 100,000 lines.");
|
||||
alignComparison(candidate,stop);
|
||||
});
|
||||
comparison.working=false;
|
||||
if(!success) return false;
|
||||
if(remember) comparison.undo.push_back({side,std::move(reverse)});
|
||||
else comparison.undo.pop_back();
|
||||
comparison.text[side]=std::move(candidate.text[side]);
|
||||
comparison.rows=std::move(candidate.rows);
|
||||
comparison.changes=std::move(candidate.changes);
|
||||
comparison.allChanges=std::move(candidate.allChanges);
|
||||
comparison.files[side].dirty=comparison.text[side].joined()!=comparison.files[side].originalText;
|
||||
comparisonUpdateRows(dialog,comparison,selected,top);
|
||||
return true;
|
||||
}
|
||||
catch(const std::exception &error)
|
||||
{
|
||||
comparison.working=false;
|
||||
showFileOperationError(dialog,L"Could not apply the block",ks::wide(error.what()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool commitComparison(HWND dialog,FileComparison &comparison,int requested=-1)
|
||||
{
|
||||
std::array committed{comparison.files[0],comparison.files[1]};
|
||||
comparison.working=true;
|
||||
bool success=true;
|
||||
try
|
||||
{
|
||||
runComparisonWork(dialog,L"Saving comparison changes…",false,[&](const auto &stop) {
|
||||
for(int side=0;side<2;++side)
|
||||
if((requested<0 || requested==side) && comparison.files[side].dirty)
|
||||
saveComparisonFile(committed[side],comparison.text[side],stop);
|
||||
});
|
||||
}
|
||||
catch(const std::system_error &error)
|
||||
{
|
||||
const auto detail=error.code().value()==ERROR_FILE_TOO_LARGE?L"Each text file can be up to 2 MiB.":fileError(error);
|
||||
showFileOperationError(dialog,L"Comparison save failed",detail);
|
||||
success=false;
|
||||
}
|
||||
catch(const std::exception &error)
|
||||
{
|
||||
showFileOperationError(dialog,L"Comparison save failed",ks::wide(error.what()));
|
||||
success=false;
|
||||
}
|
||||
comparison.working=false;
|
||||
for(int side=0;side<2;++side)
|
||||
if(!committed[side].dirty) comparison.files[side]=std::move(committed[side]);
|
||||
std::erase_if(comparison.undo,[&](const auto &previous){return !comparison.files[previous.side].dirty;});
|
||||
updateComparisonSummary(dialog,comparison);
|
||||
return success;
|
||||
}
|
||||
|
||||
void closeComparison(HWND dialog,FileComparison &comparison)
|
||||
{
|
||||
if(comparison.working || FilesModalDialog::dismissOwned(dialog)) return;
|
||||
if(comparison.files[0].dirty || comparison.files[1].dirty)
|
||||
{
|
||||
const auto choice=showFilesNotice(dialog,L"Save changes from the comparison?",L"Compare files",
|
||||
{.saveChanges=true});
|
||||
if(choice==IDYES)
|
||||
{
|
||||
if(!commitComparison(dialog,comparison)) return;
|
||||
}
|
||||
else if(choice!=IDNO) return;
|
||||
}
|
||||
DestroyWindow(dialog);
|
||||
}
|
||||
|
||||
void drawComparisonRow(const FileComparison &comparison,const DRAWITEMSTRUCT &item)
|
||||
{
|
||||
const auto dc=item.hDC;
|
||||
@@ -488,7 +737,7 @@ void drawComparisonRow(const FileComparison &comparison,const DRAWITEMSTRUCT &it
|
||||
numberArea.right=std::min(area.right,area.left+7*cell);
|
||||
DrawTextW(dc,numberText.c_str(),-1,&numberArea,DT_RIGHT|DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX);
|
||||
area.left=std::min(area.right,numberArea.right+cell);
|
||||
const auto &line=comparison.lines[side][number];
|
||||
const auto &line=comparison.text[side].lines[number];
|
||||
const auto paneWidth=area.right-area.left;
|
||||
if(paneWidth<=0) return;
|
||||
const auto limit=static_cast<size_t>(paneWidth/cell+2)*4;
|
||||
@@ -530,6 +779,11 @@ void drawComparisonRow(const FileComparison &comparison,const DRAWITEMSTRUCT &it
|
||||
|
||||
LRESULT CALLBACK comparisonKeys(HWND control,UINT message,WPARAM wp,LPARAM lp,UINT_PTR,DWORD_PTR)
|
||||
{
|
||||
if(message==WM_KEYDOWN && (GetKeyState(VK_CONTROL)&0x8000) && (wp=='Z' || wp=='S'))
|
||||
{
|
||||
SendMessageW(GetParent(control),WM_COMMAND,wp=='Z'?undoCompare:saveComparison,0);
|
||||
return 0;
|
||||
}
|
||||
if(message==WM_KEYDOWN && (wp==VK_F7 || wp==VK_F8))
|
||||
{
|
||||
SendMessageW(GetParent(control),WM_COMMAND,wp==VK_F7?404:405,0);
|
||||
@@ -626,6 +880,7 @@ void layoutComparison(HWND dialog)
|
||||
if(id==400 || id==401) continue;
|
||||
auto bounds=comparison->initialControls[i];
|
||||
if(id==402) bounds={0,bounds.top,client.right,client.bottom};
|
||||
if(id==408) bounds.right=client.right-bounds.left;
|
||||
SetWindowPos(GetDlgItem(dialog,id),nullptr,bounds.left,bounds.top,
|
||||
bounds.right-bounds.left,std::max(0L,bounds.bottom-bounds.top),
|
||||
SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCOPYBITS);
|
||||
@@ -642,6 +897,19 @@ void updateComparisonSummary(HWND dialog,const FileComparison &comparison)
|
||||
SetDlgItemTextW(dialog,403,summary.c_str());
|
||||
const auto toolbar=GetDlgItem(dialog,407);
|
||||
for(const auto id:{404,405}) SendMessageW(toolbar,TB_ENABLEBUTTON,id,MAKELONG(blocks!=0,0));
|
||||
const auto actions=GetDlgItem(dialog,408);
|
||||
const auto row=SendDlgItemMessageW(dialog,402,LB_GETCURSEL,0,0);
|
||||
const bool selected=row>=0 && static_cast<size_t>(row)<comparison.rows.size() &&
|
||||
comparison.rows[row].hasChange(comparison.showWhitespace);
|
||||
for(int side=0;side<2;++side)
|
||||
{
|
||||
const auto &file=comparison.files[side];
|
||||
const auto header=(file.dirty?L"* ":L"")+file.label+(file.revision.editable?L"":L" (read-only)");
|
||||
SetDlgItemTextW(dialog,400+side,header.c_str());
|
||||
SendMessageW(actions,TB_ENABLEBUTTON,applyLeft+side,MAKELONG(selected && file.revision.editable,0));
|
||||
SendMessageW(actions,TB_ENABLEBUTTON,saveLeft+side,MAKELONG(file.dirty,0));
|
||||
}
|
||||
SendMessageW(actions,TB_ENABLEBUTTON,undoCompare,MAKELONG(!comparison.undo.empty(),0));
|
||||
}
|
||||
|
||||
void initializeComparisonToolbar(HWND toolbar)
|
||||
@@ -662,6 +930,24 @@ void initializeComparisonToolbar(HWND toolbar)
|
||||
SendMessageW(toolbar,TB_ADDBUTTONSW,std::size(buttons),reinterpret_cast<LPARAM>(buttons));
|
||||
}
|
||||
|
||||
void initializeComparisonActions(HWND toolbar)
|
||||
{
|
||||
SendMessageW(toolbar,TB_BUTTONSTRUCTSIZE,sizeof(TBBUTTON),0);
|
||||
SendMessageW(toolbar,TB_SETEXTENDEDSTYLE,0,TBSTYLE_EX_MIXEDBUTTONS);
|
||||
SendMessageW(toolbar,TB_SETMAXTEXTROWS,1,0);
|
||||
constexpr BYTE text=BTNS_AUTOSIZE|BTNS_SHOWTEXT;
|
||||
const auto separator=MulDiv(8,GetDpiForWindow(toolbar),96);
|
||||
const TBBUTTON buttons[]{
|
||||
{I_IMAGENONE,applyLeft,TBSTATE_ENABLED,text,{},0,reinterpret_cast<INT_PTR>(L"Apply to left")},
|
||||
{I_IMAGENONE,applyRight,TBSTATE_ENABLED,text,{},0,reinterpret_cast<INT_PTR>(L"Apply to right")},
|
||||
{I_IMAGENONE,undoCompare,TBSTATE_ENABLED,text,{},0,reinterpret_cast<INT_PTR>(L"Undo")},
|
||||
{separator,0,0,BTNS_SEP,{},0,0},
|
||||
{I_IMAGENONE,saveLeft,TBSTATE_ENABLED,text,{},0,reinterpret_cast<INT_PTR>(L"Save left")},
|
||||
{I_IMAGENONE,saveRight,TBSTATE_ENABLED,text,{},0,reinterpret_cast<INT_PTR>(L"Save right")}
|
||||
};
|
||||
SendMessageW(toolbar,TB_ADDBUTTONSW,std::size(buttons),reinterpret_cast<LPARAM>(buttons));
|
||||
}
|
||||
|
||||
INT_PTR CALLBACK comparisonDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
{
|
||||
auto *comparison=reinterpret_cast<FileComparison*>(GetWindowLongPtrW(dialog,DWLP_USER));
|
||||
@@ -685,15 +971,17 @@ INT_PTR CALLBACK comparisonDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
SendMessageW(dialog,WM_SETICON,ICON_SMALL,reinterpret_cast<LPARAM>(small));
|
||||
SendMessageW(dialog,WM_SETICON,ICON_BIG,reinterpret_cast<LPARAM>(large));
|
||||
ks::files::setFileWindowTaskbar(dialog,IDI_FILES_COMPARE,L"HrynCo.KSwitcher.Files.Compare");
|
||||
for(int side=0;side<2;++side) SetDlgItemTextW(dialog,400+side,comparison->files[side].label.c_str());
|
||||
initializeComparisonToolbar(toolbar);
|
||||
updateComparisonSummary(dialog,*comparison);
|
||||
const auto actions=GetDlgItem(dialog,408);
|
||||
initializeComparisonActions(actions);
|
||||
SetWindowSubclass(list,comparisonKeys,1,0);
|
||||
SetWindowSubclass(toolbar,comparisonKeys,1,0);
|
||||
SetWindowSubclass(actions,comparisonKeys,1,0);
|
||||
applyComparisonAppearance(dialog,*comparison);
|
||||
SendMessageW(list,LB_SETCOUNT,comparison->rows.size(),0);
|
||||
layoutComparisonHeaders(dialog,*comparison);
|
||||
if(!comparison->changes.empty()) SendMessageW(list,LB_SETCURSEL,comparison->changes.front(),0);
|
||||
updateComparisonSummary(dialog,*comparison);
|
||||
return TRUE;
|
||||
}
|
||||
if(message==filesPreferencesChanged && comparison)
|
||||
@@ -702,16 +990,16 @@ INT_PTR CALLBACK comparisonDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
layoutComparisonHeaders(dialog,*comparison);
|
||||
return TRUE;
|
||||
}
|
||||
if(message==WM_CLOSE)
|
||||
if(message==WM_CLOSE && comparison)
|
||||
{
|
||||
DestroyWindow(dialog);
|
||||
closeComparison(dialog,*comparison);
|
||||
return TRUE;
|
||||
}
|
||||
if(message==WM_MOUSEWHEEL && comparison && zoomComparison(dialog,*comparison,wp)) return TRUE;
|
||||
if(message==WM_NCDESTROY)
|
||||
{
|
||||
ks::files::setFileWindowTaskbar(dialog,IDI_FILES_COMPARE,nullptr);
|
||||
comparisonWindows.erase(dialog);
|
||||
if(comparisonWindows.erase(dialog)) ks::files::standaloneFilesWindowClosed();
|
||||
return FALSE;
|
||||
}
|
||||
if(message==WM_GETMINMAXINFO && comparison && comparison->minimumWindow.cx)
|
||||
@@ -737,7 +1025,34 @@ INT_PTR CALLBACK comparisonDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
if(message==WM_COMMAND && comparison)
|
||||
{
|
||||
const auto id=LOWORD(wp);
|
||||
if(id==IDCANCEL) {DestroyWindow(dialog);return TRUE;}
|
||||
if(comparison->working) return TRUE;
|
||||
if(id==IDCANCEL) {closeComparison(dialog,*comparison);return TRUE;}
|
||||
if(id==applyLeft || id==applyRight)
|
||||
{
|
||||
const auto side=id-applyLeft;
|
||||
if(comparison->files[side].revision.editable)
|
||||
if(const auto edit=comparisonBlock(*comparison,side,SendMessageW(list,LB_GETCURSEL,0,0)))
|
||||
applyComparisonEdit(dialog,*comparison,side,*edit,true);
|
||||
SetFocus(list);
|
||||
return TRUE;
|
||||
}
|
||||
if(id==undoCompare)
|
||||
{
|
||||
if(!comparison->undo.empty())
|
||||
{
|
||||
const auto &previous=comparison->undo.back();
|
||||
applyComparisonEdit(dialog,*comparison,previous.side,previous.edit,false);
|
||||
}
|
||||
SetFocus(list);
|
||||
return TRUE;
|
||||
}
|
||||
if(id==saveLeft || id==saveRight || id==saveComparison)
|
||||
{
|
||||
if(comparison->files[0].dirty || comparison->files[1].dirty)
|
||||
commitComparison(dialog,*comparison,id==saveComparison?-1:id-saveLeft);
|
||||
SetFocus(list);
|
||||
return TRUE;
|
||||
}
|
||||
if(id==406 && HIWORD(wp)==BN_CLICKED)
|
||||
{
|
||||
comparison->showWhitespace=SendMessageW(toolbar,TB_ISBUTTONCHECKED,id,0)!=0;
|
||||
@@ -759,6 +1074,7 @@ INT_PTR CALLBACK comparisonDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
const auto next=std::upper_bound(changes.begin(),changes.end(),current);
|
||||
if(next!=changes.end()) SendMessageW(list,LB_SETCURSEL,*next,0);
|
||||
}
|
||||
updateComparisonSummary(dialog,*comparison);
|
||||
return TRUE;
|
||||
}
|
||||
if(id==402 && HIWORD(wp)==LBN_DBLCLK)
|
||||
@@ -769,13 +1085,18 @@ INT_PTR CALLBACK comparisonDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
const auto &row=comparison->rows[current];
|
||||
const auto side=[&](int file,int line)
|
||||
{
|
||||
return line<0?std::wstring(L"—"):comparison->lines[file][line];
|
||||
return line<0?std::wstring(L"—"):comparison->text[file].lines[line];
|
||||
};
|
||||
const auto detail=L"Left\n"+side(0,row.left)+L"\n\nRight\n"+side(1,row.right);
|
||||
showFilesNotice(dialog,detail.c_str(),L"Line details");
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
if(id==402 && HIWORD(wp)==LBN_SELCHANGE)
|
||||
{
|
||||
updateComparisonSummary(dialog,*comparison);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
@@ -785,13 +1106,20 @@ INT_PTR CALLBACK comparisonProgressDialog(HWND dialog,UINT message,WPARAM wp,LPA
|
||||
if(message==WM_INITDIALOG)
|
||||
{
|
||||
SetWindowLongPtrW(dialog,DWLP_USER,lp);
|
||||
const auto &state=*reinterpret_cast<ComparisonProgress *>(lp);
|
||||
prepareTextDialog(dialog);
|
||||
SetDlgItemTextW(dialog,548,state.status);
|
||||
EnableWindow(GetDlgItem(dialog,IDCANCEL),state.cancelable);
|
||||
return TRUE;
|
||||
}
|
||||
if(message==WM_COMMAND && LOWORD(wp)==IDCANCEL)
|
||||
if(message==WM_CLOSE || (message==WM_COMMAND && LOWORD(wp)==IDCANCEL))
|
||||
{
|
||||
*reinterpret_cast<std::atomic_bool*>(GetWindowLongPtrW(dialog,DWLP_USER))=true;
|
||||
EnableWindow(GetDlgItem(dialog,IDCANCEL),FALSE);
|
||||
auto &state=*reinterpret_cast<ComparisonProgress *>(GetWindowLongPtrW(dialog,DWLP_USER));
|
||||
if(state.cancelable)
|
||||
{
|
||||
state.canceled=true;
|
||||
EnableWindow(GetDlgItem(dialog,IDCANCEL),FALSE);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return paintTextDialog(dialog,message,wp,lp,L" Compare files ");
|
||||
@@ -828,41 +1156,33 @@ void compareSelectedFiles(HWND owner)
|
||||
L"Compare files");
|
||||
return;
|
||||
}
|
||||
std::atomic_bool canceled{};
|
||||
try
|
||||
{
|
||||
{
|
||||
FileOperationUi worker;
|
||||
FilesModalDialog progress(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(115),owner,
|
||||
comparisonProgressDialog,reinterpret_cast<LPARAM>(&canceled),false);
|
||||
if(!progress.window()) throw std::runtime_error("Could not open the progress dialog.");
|
||||
progress.show();
|
||||
worker.run(progress.window(),canceled,[&]
|
||||
{
|
||||
for(int side=0;side<2;++side)
|
||||
comparison.lines[side]=readComparisonLines(comparison.files[side],canceled);
|
||||
alignComparison(comparison,canceled);
|
||||
});
|
||||
}
|
||||
if(!canceled)
|
||||
const bool read=runComparisonWork(owner,L"Reading and comparing files…",true,[&](const auto &stop) {
|
||||
for(int side=0;side<2;++side)
|
||||
comparison.text[side]=readComparisonLines(comparison.files[side],stop);
|
||||
alignComparison(comparison,stop);
|
||||
});
|
||||
if(read)
|
||||
{
|
||||
const auto window=CreateDialogParamW(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(114),nullptr,
|
||||
comparisonDialog,reinterpret_cast<LPARAM>(&comparison));
|
||||
if(!window) throw std::runtime_error("Could not open the comparison window.");
|
||||
comparisonWindows.emplace(window,std::move(state));
|
||||
ks::files::standaloneFilesWindowOpened();
|
||||
ShowWindow(window,IsZoomed(owner)?SW_MAXIMIZE:SW_SHOW);
|
||||
SetFocus(GetDlgItem(window,402));
|
||||
}
|
||||
}
|
||||
catch(const std::system_error &error)
|
||||
{
|
||||
if(canceled || error.code().value()==ERROR_CANCELLED) return;
|
||||
if(error.code().value()==ERROR_CANCELLED) return;
|
||||
const auto detail=error.code().value()==ERROR_FILE_TOO_LARGE?L"Each text file can be up to 2 MiB.":
|
||||
fileError(error);
|
||||
showFileOperationError(owner,L"Comparison failed",detail);
|
||||
}
|
||||
catch(const std::exception &error)
|
||||
{
|
||||
if(!canceled) showFileOperationError(owner,L"Comparison failed",ks::wide(error.what()));
|
||||
showFileOperationError(owner,L"Comparison failed",ks::wide(error.what()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace ks::files
|
||||
{
|
||||
enum class ComparisonEnding { absent, crlf, lf, cr };
|
||||
|
||||
inline std::wstring_view comparisonEndingText(ComparisonEnding ending)
|
||||
{
|
||||
switch(ending)
|
||||
{
|
||||
case ComparisonEnding::crlf: return L"\r\n";
|
||||
case ComparisonEnding::lf: return L"\n";
|
||||
case ComparisonEnding::cr: return L"\r";
|
||||
default: return {};
|
||||
}
|
||||
}
|
||||
|
||||
struct ComparisonText
|
||||
{
|
||||
std::vector<std::wstring> lines;
|
||||
std::vector<ComparisonEnding> endings;
|
||||
ComparisonEnding preferred=ComparisonEnding::crlf;
|
||||
|
||||
std::wstring joined() const
|
||||
{
|
||||
std::wstring result;
|
||||
for(size_t i=0;i<lines.size();++i)
|
||||
{
|
||||
result+=lines[i];
|
||||
if(i+1<lines.size())
|
||||
result+=comparisonEndingText(endings[i]==ComparisonEnding::absent?preferred:endings[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
inline ComparisonText splitComparisonText(std::wstring_view contents)
|
||||
{
|
||||
ComparisonText result;
|
||||
if(contents.empty()) return result;
|
||||
size_t start=0;
|
||||
while(true)
|
||||
{
|
||||
const auto end=contents.find_first_of(L"\r\n",start);
|
||||
result.lines.emplace_back(contents.substr(start,end==contents.npos?end:end-start));
|
||||
auto ending=ComparisonEnding::absent;
|
||||
if(end!=contents.npos)
|
||||
ending=contents[end]==L'\n'?ComparisonEnding::lf:
|
||||
end+1<contents.size() && contents[end+1]==L'\n'?ComparisonEnding::crlf:ComparisonEnding::cr;
|
||||
result.endings.push_back(ending);
|
||||
if(ending==ComparisonEnding::absent) break;
|
||||
if(result.endings.size()==1) result.preferred=ending;
|
||||
start=end+(ending==ComparisonEnding::crlf?2:1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
struct ComparisonReplace
|
||||
{
|
||||
size_t start{}, count{};
|
||||
std::vector<std::wstring> lines;
|
||||
std::vector<ComparisonEnding> endings;
|
||||
};
|
||||
|
||||
inline ComparisonReplace replaceComparisonText(ComparisonText &document,const ComparisonReplace &change)
|
||||
{
|
||||
const auto first=document.lines.begin()+change.start, last=first+change.count;
|
||||
const auto firstEnding=document.endings.begin()+change.start, lastEnding=firstEnding+change.count;
|
||||
ComparisonReplace reverse{change.start,change.lines.size(),{first,last},{firstEnding,lastEnding}};
|
||||
document.lines.erase(first,last);
|
||||
document.lines.insert(document.lines.begin()+change.start,change.lines.begin(),change.lines.end());
|
||||
document.endings.erase(firstEnding,lastEnding);
|
||||
document.endings.insert(document.endings.begin()+change.start,change.endings.begin(),change.endings.end());
|
||||
return reverse;
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -28,6 +28,7 @@
|
||||
#include <wininet.h>
|
||||
#include "files_terminal.h"
|
||||
#include "files_archive.h"
|
||||
#include "files_compare_text.h"
|
||||
#include "files_image_decode.h"
|
||||
#include "files_win32_directory.h"
|
||||
#include "files_command_completion.h"
|
||||
@@ -5860,7 +5861,7 @@ ks::files::RemoteTextSource ftpTextSource(const FtpProfile &profile)
|
||||
ERROR_NOT_SUPPORTED);
|
||||
const bool editable=!(info->attributes&FILE_ATTRIBUTE_READONLY);
|
||||
if(edit && !editable) throw std::runtime_error("The FTP file is read-only.");
|
||||
if(info->size>limit) throw std::runtime_error("The image is too large to preview.");
|
||||
if(info->size>limit) throw std::system_error(ERROR_FILE_TOO_LARGE,std::system_category());
|
||||
FilesConnection local;
|
||||
downloadFtpFile(ftp,local,path,cache,*info,false,progress);
|
||||
return ks::files::RemoteTextRevision{info->size,info->modified,editable};
|
||||
|
||||
@@ -600,7 +600,7 @@ RemoteTextSource lanTextSource(const lan::FilesPeer &peer)
|
||||
throw std::runtime_error("Update KSwitcher on the remote computer to edit this file.");
|
||||
if(edit && readOnly) throw std::runtime_error("The remote file is read-only.");
|
||||
const RemoteTextRevision revision{info.at("size"),info.at("modified"),canCommit && !readOnly};
|
||||
if(revision.size>sizeLimit) throw std::runtime_error("The image is too large to preview.");
|
||||
if(revision.size>sizeLimit) throw std::system_error(ERROR_FILE_TOO_LARGE,std::system_category());
|
||||
try
|
||||
{
|
||||
lan::streamFile(source,target,peer.id,original,cache,revision.size,revision.modified,false,false,progress);
|
||||
@@ -684,6 +684,12 @@ std::map<HWND,std::shared_ptr<TextWindow>> textWindows;
|
||||
std::vector<HWND> textWindowOrder;
|
||||
HWND filesOwner{};
|
||||
bool textOwnerClosed=false;
|
||||
unsigned standaloneFilesWindows{};
|
||||
void quitWhenFilesWindowsClose()
|
||||
{
|
||||
if(textOwnerClosed && textWindows.empty() && textWindowOrder.empty() && !standaloneFilesWindows)
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
constexpr ULONG_PTR openDocumentQuery=0x4B534644;
|
||||
|
||||
std::wstring documentIdentity(const std::filesystem::path &path,std::string_view peer)
|
||||
@@ -2990,7 +2996,7 @@ LRESULT CALLBACK TextWindow::procedure(HWND window, UINT message, WPARAM wparam,
|
||||
self->window=nullptr;
|
||||
textWindows.erase(window);
|
||||
std::erase(textWindowOrder,window);
|
||||
if(textOwnerClosed && textWindows.empty() && textWindowOrder.empty()) PostQuitMessage(0);
|
||||
quitWhenFilesWindowsClose();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -3108,7 +3114,18 @@ void textWindowOwnerClosed()
|
||||
{
|
||||
filesOwner=nullptr;
|
||||
textOwnerClosed=true;
|
||||
if(textWindows.empty() && textWindowOrder.empty()) PostQuitMessage(0);
|
||||
quitWhenFilesWindowsClose();
|
||||
}
|
||||
|
||||
void standaloneFilesWindowOpened()
|
||||
{
|
||||
++standaloneFilesWindows;
|
||||
}
|
||||
|
||||
void standaloneFilesWindowClosed()
|
||||
{
|
||||
if(standaloneFilesWindows) --standaloneFilesWindows;
|
||||
quitWhenFilesWindowsClose();
|
||||
}
|
||||
|
||||
bool cycleTextWindows(HWND current,bool reverse)
|
||||
@@ -3221,7 +3238,7 @@ void openImageWindow(HWND owner,std::vector<std::filesystem::path> images,const
|
||||
const auto window=createImageView(owner,false,imageViewStyle(dialogs),std::move(images),path,std::move(load),
|
||||
[](HWND closed) {
|
||||
std::erase(textWindowOrder,closed);
|
||||
if(textOwnerClosed && textWindows.empty() && textWindowOrder.empty()) PostQuitMessage(0);
|
||||
quitWhenFilesWindowsClose();
|
||||
});
|
||||
if(!window) throw std::runtime_error("Could not open the image viewer.");
|
||||
textWindowOrder.push_back(window);
|
||||
@@ -3292,6 +3309,11 @@ void openRemoteTextWindow(HWND owner,const std::filesystem::path &path,bool edit
|
||||
openTextWindowImpl(owner,path,edit,dialogs,&source,fragment,newWindow,options);
|
||||
}
|
||||
|
||||
RemoteTextSource createLanTextSource(const lan::FilesPeer &peer)
|
||||
{
|
||||
return lanTextSource(peer);
|
||||
}
|
||||
|
||||
void showAllViewerBookmarks(HWND owner,TextDialogs dialogs)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -81,6 +81,7 @@ struct RemoteTextSource
|
||||
std::function<RemoteTextRevision(const std::filesystem::path &,const std::filesystem::path &,
|
||||
const RemoteTextRevision &)> upload;
|
||||
};
|
||||
RemoteTextSource createLanTextSource(const lan::FilesPeer &peer);
|
||||
|
||||
inline constexpr UINT quickViewToggleMessage=WM_APP+31;
|
||||
HWND createQuickView(HWND owner,TextDialogs dialogs);
|
||||
@@ -97,5 +98,7 @@ void openTextWindow(HWND owner,const std::filesystem::path &path,bool edit,TextD
|
||||
void openRemoteTextWindow(HWND owner,const std::filesystem::path &path,bool edit,TextDialogs dialogs,
|
||||
const RemoteTextSource &source,std::string_view fragment={},bool newWindow=false,TextOpenOptions options={});
|
||||
void textWindowOwnerClosed();
|
||||
void standaloneFilesWindowOpened();
|
||||
void standaloneFilesWindowClosed();
|
||||
bool cycleTextWindows(HWND current,bool reverse);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "files_text_document.h"
|
||||
#include "files_compare_text.h"
|
||||
|
||||
#include <objbase.h>
|
||||
#include <winioctl.h>
|
||||
@@ -189,6 +190,24 @@ void bookmarkedLines(const fs::path &file)
|
||||
check(rejected,"Cancel a bookmark scan");
|
||||
}
|
||||
|
||||
void comparisonEdits()
|
||||
{
|
||||
using namespace ks::files;
|
||||
auto mixed=splitComparisonText(L"alpha\r\nbeta\nlast\r");
|
||||
check(mixed.joined()==L"alpha\r\nbeta\nlast\r","Round-trip mixed line endings");
|
||||
const auto replace=replaceComparisonText(mixed,{1,1,{L"new",L"extra"},{ComparisonEnding::lf,ComparisonEnding::crlf}});
|
||||
check(mixed.joined()==L"alpha\r\nnew\nextra\r\nlast\r","Replace a block and retain the other line endings");
|
||||
replaceComparisonText(mixed,replace);
|
||||
check(mixed.joined()==L"alpha\r\nbeta\nlast\r","Undo a block replacement");
|
||||
const auto shorten=replaceComparisonText(mixed,{3,1,{},{}});
|
||||
check(mixed.joined()==L"alpha\r\nbeta\nlast","Remove the terminating empty line");
|
||||
replaceComparisonText(mixed,shorten);
|
||||
check(mixed.joined()==L"alpha\r\nbeta\nlast\r","Undo preserves the original trailing separator");
|
||||
auto single=splitComparisonText(L"first");
|
||||
replaceComparisonText(single,{1,0,{L"second"},{ComparisonEnding::absent}});
|
||||
check(single.joined()==L"first\r\nsecond","Use the target convention when inserting past EOF");
|
||||
}
|
||||
|
||||
void saveDraft(const fs::path &file)
|
||||
{
|
||||
TextDocument draft({});
|
||||
@@ -238,6 +257,7 @@ int main()
|
||||
saveDraft(fixture.directory / L"created.txt");
|
||||
hexBytes(fixture.directory / L"raw.bin");
|
||||
bookmarkedLines(fixture.directory / L"bookmarks.txt");
|
||||
comparisonEdits();
|
||||
sparseFile(fixture.directory / L"5gib.log");
|
||||
std::cout << "Files text document regressions passed.\n";
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user