Skip to content

Commit

Permalink
Added keyboard shortcuts for applying last color
Browse files Browse the repository at this point in the history
and also popping up color menus
  • Loading branch information
aardappel committed Jan 10, 2022
1 parent fcda44b commit de2c804
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 18 deletions.
41 changes: 36 additions & 5 deletions src/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ struct Document {
// Linux??
// They're both keycode 9 in defs.h
// We ignore it here, such that CTRL+I works, but it means only
// SHIFT+CTRL+TAB works on Linux as
// CTRL+SHIFT+TAB works on Linux as
// a way to switch tabs.
// Also, even though we ignore CTRL+TAB, and it is not assigned in the
// menus, it still has the
Expand Down Expand Up @@ -1032,6 +1032,16 @@ struct Document {
Refresh();
return nullptr;

case A_OPENCELLCOLOR:
if (sys->frame->celldd) sys->frame->celldd->ShowPopup();
break;
case A_OPENTEXTCOLOR:
if (sys->frame->textdd) sys->frame->textdd->ShowPopup();
break;
case A_OPENBORDCOLOR:
if (sys->frame->borddd) sys->frame->borddd->ShowPopup();
break;

case A_REPLACEALL: {
if (!sys->searchstring.Len()) return _(L"No search.");
rootgrid->AddUndo(this); // expensive?
Expand Down Expand Up @@ -1387,18 +1397,34 @@ struct Document {
case A_RESETWIDTH:
case A_RESETSTYLE:
case A_RESETCOLOR:
case A_LASTCELLCOLOR:
case A_LASTTEXTCOLOR:
case A_LASTBORDCOLOR:
selected.g->cell->AddUndo(this);
loopallcellssel(c, true) switch (k) {
case A_RESETSIZE: c->text.relsize = 0; break;
case A_RESETSIZE:
c->text.relsize = 0;
break;
case A_RESETWIDTH:
if (c->grid) c->grid->InitColWidths();
break;
case A_RESETSTYLE: c->text.stylebits = 0; break;
case A_RESETSTYLE:
c->text.stylebits = 0;
break;
case A_RESETCOLOR:
c->cellcolor = 0xFFFFFF;
c->textcolor = 0;
if (c->grid) c->grid->bordercolor = 0xA0A0A0;
break;
case A_LASTCELLCOLOR:
c->cellcolor = sys->lastcellcolor;
break;
case A_LASTTEXTCOLOR:
c->textcolor = sys->lasttextcolor;
break;
case A_LASTBORDCOLOR:
if (c->grid) c->grid->bordercolor = sys->lastbordcolor;
break;
}
selected.g->cell->ResetChildren();
Refresh();
Expand Down Expand Up @@ -1850,8 +1876,13 @@ struct Document {

void ColorChange(int which, int idx) {
if (!selected.g) return;
selected.g->ColorChange(
this, which, idx == CUSTOMCOLORIDX ? sys->customcolor : celltextcolors[idx], selected);
auto col = idx == CUSTOMCOLORIDX ? sys->customcolor : celltextcolors[idx];
switch (which) {
case A_CELLCOLOR: sys->lastcellcolor = col; break;
case A_TEXTCOLOR: sys->lasttextcolor = col; break;
case A_BORDCOLOR: sys->lastbordcolor = col; break;
}
selected.g->ColorChange(this, which, col, selected);
}

void SetImageBM(Cell *c, const wxImage &im, double sc) {
Expand Down
6 changes: 6 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ enum {
A_RESETWIDTH,
A_RESETSTYLE,
A_RESETCOLOR,
A_LASTCELLCOLOR,
A_LASTTEXTCOLOR,
A_LASTBORDCOLOR,
A_OPENCELLCOLOR,
A_OPENTEXTCOLOR,
A_OPENBORDCOLOR,
A_DDIMAGE,
A_MINCLOSE,
A_SINGLETRAY,
Expand Down
39 changes: 26 additions & 13 deletions src/myframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ struct MyFrame : wxFrame {
double csf, csf_orig;
std::vector<std::string> scripts_in_menu;
bool zenmode;

ColorDropdown *celldd = nullptr;
ColorDropdown *textdd = nullptr;
ColorDropdown *borddd = nullptr;

wxString GetPath(const wxString &relpath) {
if (!exepath_.Length()) return relpath;
return exepath_ + "/" + relpath;
Expand Down Expand Up @@ -222,16 +225,16 @@ struct MyFrame : wxFrame {
wxMenu *sizemenu = new wxMenu();
MyAppend(sizemenu, A_INCSIZE, _(L"&Increase text size (SHIFT+mousewheel)\tSHIFT+PGUP"));
MyAppend(sizemenu, A_DECSIZE, _(L"&Decrease text size (SHIFT+mousewheel)\tSHIFT+PGDN"));
MyAppend(sizemenu, A_RESETSIZE, _(L"&Reset text sizes\tSHIFT+CTRL+s"));
MyAppend(sizemenu, A_MINISIZE, _(L"&Shrink text of all sub-grids\tSHIFT+CTRL+m"));
MyAppend(sizemenu, A_RESETSIZE, _(L"&Reset text sizes\tCTRL+SHIFT+s"));
MyAppend(sizemenu, A_MINISIZE, _(L"&Shrink text of all sub-grids\tCTRL+SHIFT+m"));
sizemenu->AppendSeparator();
MyAppend(sizemenu, A_INCWIDTH, _(L"Increase column width (ALT+mousewheel)\tALT+PGUP"));
MyAppend(sizemenu, A_DECWIDTH, _(L"Decrease column width (ALT+mousewheel)\tALT+PGDN"));
MyAppend(sizemenu, A_INCWIDTHNH,
_(L"Increase column width (no sub grids)\tCTRL+ALT+PGUP"));
MyAppend(sizemenu, A_DECWIDTHNH,
_(L"Decrease column width (no sub grids)\tCTRL+ALT+PGDN"));
MyAppend(sizemenu, A_RESETWIDTH, _(L"Reset column widths\tSHIFT+CTRL+w"));
MyAppend(sizemenu, A_RESETWIDTH, _(L"Reset column widths\tCTRL+SHIFT+w"));

wxMenu *bordmenu = new wxMenu();
MyAppend(bordmenu, A_BORD0, L"Border &0\tCTRL+SHIFT+9");
Expand Down Expand Up @@ -278,8 +281,8 @@ struct MyFrame : wxFrame {
temenu->AppendSeparator();
MyAppend(temenu, A_SLEFT, _(L"Extend Selection Left\tSHIFT+LEFT"));
MyAppend(temenu, A_SRIGHT, _(L"Extend Selection Right\tSHIFT+RIGHT"));
MyAppend(temenu, A_SCLEFT, _(L"Extend Selection Word Left\tSHIFT+CTRL+LEFT"));
MyAppend(temenu, A_SCRIGHT, _(L"Extend Selection Word Right\tSHIFT+CTRL+RIGHT"));
MyAppend(temenu, A_SCLEFT, _(L"Extend Selection Word Left\tCTRL+SHIFT+LEFT"));
MyAppend(temenu, A_SCRIGHT, _(L"Extend Selection Word Right\tCTRL+SHIFT+RIGHT"));
MyAppend(temenu, A_SHOME, _(L"Extend Selection to Start\tSHIFT+HOME"));
MyAppend(temenu, A_SEND, _(L"Extend Selection to End\tSHIFT+END"));
temenu->AppendSeparator();
Expand All @@ -300,8 +303,15 @@ struct MyFrame : wxFrame {
MyAppend(stmenu, A_UNDERL, _(L"Toggle cell &underlined\tCTRL+u"));
MyAppend(stmenu, A_STRIKET, _(L"Toggle cell &strikethrough\tCTRL+t"));
stmenu->AppendSeparator();
MyAppend(stmenu, A_RESETSTYLE, _(L"&Reset text styles\tSHIFT+CTRL+r"));
MyAppend(stmenu, A_RESETCOLOR, _(L"Reset &colors\tSHIFT+CTRL+c"));
MyAppend(stmenu, A_RESETSTYLE, _(L"&Reset text styles\tCTRL+SHIFT+r"));
MyAppend(stmenu, A_RESETCOLOR, _(L"Reset &colors\tCTRL+SHIFT+c"));
stmenu->AppendSeparator();
MyAppend(stmenu, A_LASTCELLCOLOR, _(L"Apply last cell color\tSHIFT+ALT+c"));
MyAppend(stmenu, A_LASTTEXTCOLOR, _(L"Apply last text color\tSHIFT+ALT+t"));
MyAppend(stmenu, A_LASTBORDCOLOR, _(L"Apply last border color\tSHIFT+ALT+b"));
MyAppend(stmenu, A_OPENCELLCOLOR, _(L"Open cell colors\tSHIFT+ALT+F9"));
MyAppend(stmenu, A_OPENTEXTCOLOR, _(L"Open text colors\tSHIFT+ALT+F10"));
MyAppend(stmenu, A_OPENBORDCOLOR, _(L"Open border colors\tSHIFT+ALT+F11"));

wxMenu *tagmenu = new wxMenu();
MyAppend(tagmenu, A_TAGADD, _(L"&Add Cell Text as Tag"));
Expand All @@ -312,7 +322,7 @@ struct MyFrame : wxFrame {
L"using a popup menu"));

wxMenu *orgmenu = new wxMenu();
MyAppend(orgmenu, A_TRANSPOSE, _(L"&Transpose\tSHIFT+CTRL+t"),
MyAppend(orgmenu, A_TRANSPOSE, _(L"&Transpose\tCTRL+SHIFT+t"),
_(L"changes the orientation of a grid"));
MyAppend(orgmenu, A_SORT, _(L"Sort &Ascending"),
_(L"Make a 1xN selection to indicate which column to sort on, and which rows to "
Expand Down Expand Up @@ -465,7 +475,7 @@ struct MyFrame : wxFrame {
// CTRL+SHIFT+TAB below still works, so that will have to be used to switch tabs.
_(L"Switch to &next file/tab"));
#endif
MyAppend(viewmenu, A_PREVFILE, _(L"Switch to &previous file/tab\tSHIFT+CTRL+TAB"));
MyAppend(viewmenu, A_PREVFILE, _(L"Switch to &previous file/tab\tCTRL+SHIFT+TAB"));
MyAppend(viewmenu, A_FULLSCREEN,
#ifdef __WXMAC__
_(L"Toggle &Fullscreen View\tCTRL+F11"));
Expand Down Expand Up @@ -662,13 +672,16 @@ struct MyFrame : wxFrame {
new wxTextCtrl(tb, A_REPLACE, "", wxDefaultPosition, wxSize(60, 22) * csf));
tb->AddSeparator();
tb->AddControl(new wxStaticText(tb, wxID_ANY, _(L"Cell ")));
tb->AddControl(new ColorDropdown(tb, A_CELLCOLOR, csf, 1));
celldd = new ColorDropdown(tb, A_CELLCOLOR, csf, 1);
tb->AddControl(celldd);
SEPARATOR;
tb->AddControl(new wxStaticText(tb, wxID_ANY, _(L"Text ")));
tb->AddControl(new ColorDropdown(tb, A_TEXTCOLOR, csf, 2));
textdd = new ColorDropdown(tb, A_TEXTCOLOR, csf, 2);
tb->AddControl(textdd);
SEPARATOR;
tb->AddControl(new wxStaticText(tb, wxID_ANY, _(L"Border ")));
tb->AddControl(new ColorDropdown(tb, A_BORDCOLOR, csf, 7));
borddd = new ColorDropdown(tb, A_BORDCOLOR, csf, 7);
tb->AddControl(borddd);
tb->AddSeparator();
tb->AddControl(new wxStaticText(tb, wxID_ANY, _(L"Image ")));
wxString imagepath = GetPath("images/nuvola/dropdown/");
Expand Down
4 changes: 4 additions & 0 deletions src/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ struct System {
}
} savechecker;

uint lastcellcolor = 0xFFFFFF;
uint lasttextcolor = 0;
uint lastbordcolor = 0xA0A0A0;

System(bool portable)
: cfg(portable ? (wxConfigBase *)new wxFileConfig(
L"", wxT(""), wxGetCwd() + wxT("/TreeSheets.ini"), wxT(""), 0)
Expand Down

0 comments on commit de2c804

Please sign in to comment.