Files
hrynco-kswitcher/src/files_text_window.h
T
2026-11-25 23:29:30 +02:00

135 lines
4.9 KiB
C++

#pragma once
#include <windows.h>
#include "files_appearance.h"
#include <filesystem>
#include <functional>
#include <optional>
#include <system_error>
#include <cstdint>
#include <string_view>
#include <vector>
#include "files_text_document.h"
namespace ks::lan { struct FilesPeer; }
namespace ks::files
{
inline constexpr int searchOptionsDivider = 104;
inline constexpr int searchButtonsDivider = 105;
inline constexpr int searchHistoryButton = 108;
inline constexpr wchar_t farDropDownProperty[]=L"KSwitcher.Files.ActiveDropDown";
struct TextWindowFont
{
LOGFONTW font;
int tenthsOfPoint;
};
void setFileWindowTaskbar(HWND window,int iconResource,const wchar_t *identity);
struct FarDropDownPalette
{
COLORREF surface, text, selection;
};
enum class FarHistoryKind { search, folder };
struct FarHistoryEntry { std::wstring date,text; };
std::vector<FarHistoryEntry> loadFarHistory(FarHistoryKind kind);
void rememberFarHistory(FarHistoryKind kind,std::wstring_view text);
int chooseFarDropDown(HWND anchor,const std::vector<FarHistoryEntry> &entries,int selected,
FarDropDownPalette palette,int rightInset=0);
void showFarHistory(HWND dialog,int fieldId,const std::vector<FarHistoryEntry> &history,
FarDropDownPalette palette);
void installFarHistoryKey(HWND field,int arrowId);
struct TextDialogs
{
INT_PTR (*confirmSave)(HWND,bool draft);
INT_PTR (*paint)(HWND, UINT, WPARAM, LPARAM, const wchar_t *);
INT_PTR (*paintSearch)(HWND, UINT, WPARAM, LPARAM);
void (*prepare)(HWND);
void (*options)(HWND, AppearanceArea);
void (*message)(HWND, const wchar_t *);
TextWindowFont (*readFont)();
FarDropDownPalette (*dropDownPalette)();
INT_PTR (*run)(HINSTANCE,LPCWSTR,HWND,DLGPROC,LPARAM);
void (*finish)(HWND,INT_PTR);
bool (*dismissOwned)(HWND);
bool (*confirmExisting)(HWND);
bool (*saveOptions)(HWND,std::filesystem::path &,TextSaveFormat &);
bool (*reloadChanged)(HWND){};
unsigned (*readScale)(AppearanceArea){};
};
struct TextOpenOptions
{
TextEncoding encoding=TextEncoding::automatic;
bool draft{};
bool hex{};
uint64_t line{};
};
struct RemoteTextRevision
{
uint64_t size{}, modified{};
bool editable{};
};
struct RemoteAccessDenied : std::system_error
{
explicit RemoteAccessDenied(const char *operation):
std::system_error(ERROR_ACCESS_DENIED,std::system_category(),operation) {}
};
struct RemoteTextSource
{
using Progress=std::function<bool(uint64_t,uint64_t)>;
using Download=std::function<RemoteTextRevision(const std::filesystem::path &,const std::filesystem::path &,
bool,const Progress &,uint64_t)>;
using Upload=std::function<RemoteTextRevision(const std::filesystem::path &,const std::filesystem::path &,
const RemoteTextRevision &)>;
struct Elevation
{
Download download;
std::function<RemoteTextRevision(const std::filesystem::path &,const std::filesystem::path &,
const RemoteTextRevision &,const Progress &)> upload;
std::function<bool(HWND,const std::filesystem::path &,bool)> approve;
};
std::string id;
std::wstring name;
Download download;
Upload upload;
std::optional<Elevation> elevation;
};
RemoteTextSource createLanTextSource(const lan::FilesPeer &peer);
inline constexpr UINT quickViewToggleMessage=WM_APP+31;
HWND createQuickView(HWND owner,TextDialogs dialogs);
void previewQuickViewFile(HWND window,const std::filesystem::path &path);
void previewQuickViewText(HWND window,const std::wstring &title,std::string_view contents,bool diff=false);
HWND createImageQuickView(HWND owner,TextDialogs dialogs);
void previewImageQuickViewFile(HWND window,const std::filesystem::path &path);
struct ImageEditDialogs;
struct ImageWindowSession;
void openImageWindow(HWND owner,std::vector<std::filesystem::path> images,const std::filesystem::path &path,
TextDialogs dialogs,const lan::FilesPeer *peer=nullptr,const RemoteTextSource *source=nullptr,
const ImageEditDialogs *editor=nullptr,const ImageWindowSession *session=nullptr);
void showAllViewerBookmarks(HWND owner,TextDialogs dialogs);
void openTextWindow(HWND owner,const std::filesystem::path &path,bool edit,TextDialogs dialogs,
const lan::FilesPeer *peer=nullptr,std::string_view fragment={},bool newWindow=false,
TextOpenOptions options={});
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 saveLocalDocumentSession(const wchar_t *registryKey,bool enabled);
void restoreLocalDocumentSession(HWND owner,TextDialogs dialogs,const wchar_t *registryKey,const ImageEditDialogs &imageEditor);
void textWindowOwnerClosed();
void standaloneFilesWindowOpened();
void standaloneFilesWindowClosed();
bool cycleTextWindows(HWND current,bool reverse);
std::optional<AppearanceArea> textWindowAppearanceArea(HWND window);
}