diff --git a/uppsrc/RichEdit/Editor.cpp b/uppsrc/RichEdit/Editor.cpp index 8244427fb..e859b83a3 100644 --- a/uppsrc/RichEdit/Editor.cpp +++ b/uppsrc/RichEdit/Editor.cpp @@ -278,6 +278,7 @@ void RichEdit::SetupUnits() { WithUnitLayout d; CtrlLayoutOKCancel(d, t_("Units")); + d.accels <<= THISBACK(StyleKeys); for(int i = 1; i <= 10; i++) d.zoom.Add(10 * i, Format(t_("%d%% of width"), 10 * i)); CtrlRetriever r; @@ -452,7 +453,7 @@ void RichEdit::SpellCheck() void RichEdit::SerializeSettings(Stream& s) { - int version = 2; + int version = 3; s / version; s % unit; s % showcodes; @@ -467,6 +468,11 @@ void RichEdit::SerializeSettings(Stream& s) s % findreplace.ignorecase; RefreshBar(); imagefs.Serialize(s); + if(version >= 3) + for(int i = 0; i < 20; i++) { + StyleKey& k = stylekey[i]; + s % k.styleid % k.stylename % k.face % k.height % k.ink % k.paper; + } } void RichEdit::Reset() diff --git a/uppsrc/RichEdit/Kbd.cpp b/uppsrc/RichEdit/Kbd.cpp index 6fed2865a..e6fa59c28 100644 --- a/uppsrc/RichEdit/Kbd.cpp +++ b/uppsrc/RichEdit/Kbd.cpp @@ -135,6 +135,14 @@ bool RichEdit::Key(dword key, int count) break; } default: + if(key >= K_ALT_0 && key <= K_ALT_9) { + ApplyStyleKey(key - K_ALT_0); + return true; + } + if(key >= (K_SHIFT|K_ALT_0) && key <= (K_SHIFT|K_ALT_9)) { + ApplyStyleKey(key - K_SHIFT|K_ALT_0 + 10); + return true; + } if(key == K_SHIFT_SPACE) key = ' '; if(key == 9 || key >= 32 && key < 65536) { diff --git a/uppsrc/RichEdit/RichEdit.h b/uppsrc/RichEdit/RichEdit.h index 25a2b7481..4a1ac5f0a 100644 --- a/uppsrc/RichEdit/RichEdit.h +++ b/uppsrc/RichEdit/RichEdit.h @@ -332,6 +332,17 @@ private: Array redo; FileSel imagefs; + + struct StyleKey { + Uuid styleid; + String stylename; + String face; + int height; + Color ink; + Color paper; + }; + + StyleKey stylekey[20]; Rect GetTextRect() const; Size GetZoomedPage() const; @@ -491,10 +502,15 @@ private: void RefreshDropCaret(); void InsertImage(); + + void StyleKeys(); + void ApplyStyleKey(int i); static bool SpellWord(const wchar *wrd, int len, int lang); static void SpellerAdd(const WString& w, int lang); + friend class StyleKeysDlg; + protected: enum { TIMEID_ENDSIZETRACKING = Ctrl::TIMEID_COUNT, @@ -611,6 +627,7 @@ public: void TableTools(Bar& bar); void InsertImageTool(Bar& bar); + void StyleKeysTool(Bar& bar); void DefaultBar(Bar& bar, bool extended = true); diff --git a/uppsrc/RichEdit/RichEdit.lay b/uppsrc/RichEdit/RichEdit.lay index 08f42e2df..2324166aa 100644 --- a/uppsrc/RichEdit/RichEdit.lay +++ b/uppsrc/RichEdit/RichEdit.lay @@ -47,15 +47,16 @@ LAYOUT(ParaLayout, 488, 352) UNTYPED(n[7], LeftPosZ(408, 54).TopPosZ(320, 19)) END_LAYOUT -LAYOUT(UnitLayout, 244, 144) +LAYOUT(UnitLayout, 244, 140) ITEM(LabelBox, dv___0, SetLabel(t_("Units")).LeftPosZ(8, 228).TopPosZ(4, 40)) ITEM(Switch, unit, SetLabel(t_("dot\npoint\ninch\nmm\ncm")).LeftPosZ(16, 216).TopPosZ(20, 16)) - ITEM(Label, dv___2, SetLabel(t_("Reveal codes")).LeftPosZ(12, 76).TopPosZ(55, 13)) + ITEM(Label, dv___2, SetLabel(t_("Reveal codes")).LeftPosZ(8, 76).TopPosZ(52, 20)) ITEM(ColorPusher, showcodes, LeftPosZ(92, 144).TopPosZ(52, 19)) - ITEM(Label, dv___4, SetLabel(t_("Zoom")).LeftPosZ(12, 76).TopPosZ(80, 19)) + ITEM(Label, dv___4, SetLabel(t_("Zoom")).LeftPosZ(8, 76).TopPosZ(80, 19)) ITEM(DropList, zoom, LeftPosZ(92, 144).TopPosZ(80, 19)) - ITEM(Button, ok, SetLabel(t_("OK")).LeftPosZ(104, 64).TopPosZ(112, 24)) - ITEM(Button, cancel, SetLabel(t_("Cancel")).LeftPosZ(172, 64).TopPosZ(112, 24)) + ITEM(Button, accels, SetLabel(t_("Style keys")).LeftPosZ(8, 76).TopPosZ(108, 24)) + ITEM(Button, ok, SetLabel(t_("OK")).LeftPosZ(104, 64).TopPosZ(108, 24)) + ITEM(Button, cancel, SetLabel(t_("Cancel")).LeftPosZ(172, 64).TopPosZ(108, 24)) END_LAYOUT LAYOUT(SetStyleLayout, 216, 280) @@ -201,3 +202,9 @@ LAYOUT(CellPropertiesLayout, 300, 260) ITEM(Button, cancel, SetLabel(t_("Cancel")).LeftPosZ(232, 64).TopPosZ(232, 24)) END_LAYOUT +LAYOUT(StyleKeysLayout, 736, 556) + ITEM(ArrayCtrl, list, LeftPosZ(8, 720).TopPosZ(8, 508)) + ITEM(Button, ok, SetLabel(t_("OK")).LeftPosZ(596, 64).TopPosZ(524, 24)) + ITEM(Button, cancel, SetLabel(t_("Cancel")).LeftPosZ(664, 64).TopPosZ(524, 24)) +END_LAYOUT + diff --git a/uppsrc/RichEdit/RichEdit.upp b/uppsrc/RichEdit/RichEdit.upp index 80efb340f..a833671fa 100644 --- a/uppsrc/RichEdit/RichEdit.upp +++ b/uppsrc/RichEdit/RichEdit.upp @@ -21,6 +21,7 @@ file Find.cpp optimize_speed, Tool.cpp, Clip.cpp, + StyleKeys.cpp, RichEdit.t charset "UTF-8", RichEdit.icpp, RichEdit.lay, diff --git a/uppsrc/RichEdit/StyleKeys.cpp b/uppsrc/RichEdit/StyleKeys.cpp new file mode 100644 index 000000000..58b8d964c --- /dev/null +++ b/uppsrc/RichEdit/StyleKeys.cpp @@ -0,0 +1,135 @@ +#include "RichEdit.h" + +NAMESPACE_UPP + +class StyleKeysDlg : public WithStyleKeysLayout { + typedef StyleKeysDlg CLASSNAME; + + Array style; + Array face; + Array height; + Array ink; + Array paper; + +public: + void Init(const RichEdit& edit, RichEdit::StyleKey *key); + void Retrieve(RichEdit::StyleKey *k); + + StyleKeysDlg(); +}; + +StyleKeysDlg::StyleKeysDlg() +{ + CtrlLayoutOKCancel(*this, "Styling keys"); + + list.AddColumn("Key"); + list.AddColumn("Paragraph style"); + list.AddColumn("Font"); + list.AddColumn("Height"); + list.AddColumn("Ink"); + list.AddColumn("Paper"); + list.SetLineCy(EditField::GetStdHeight() + 4); + list.NoHorzGrid().EvenRowColor().NoCursor(); + list.ColumnWidths("117 160 160 75 90 90"); +} + +void StyleKeysDlg::Init(const RichEdit& edit, RichEdit::StyleKey *key) +{ + const RichText& text = edit.text; + for(int i = 0; i < 20; i++) { + RichEdit::StyleKey& k = key[i]; + list.Add((i >= 10 ? "Shift+Alt+" : "Alt+") + AsString(i % 10)); + + DropList& st = style.At(i); + st.Add(Null); + const RichStyles& ts = text.GetStyles(); + for(int j = 0; j < ts.GetCount(); j++) { + st.Add(ts.GetKey(j), ts[j].name); + } + if(st.FindKey(k.styleid) < 0) + st.Add(k.styleid, k.stylename); + st <<= k.styleid; + list.SetCtrl(i, 1, st, false); + + DropList& fc = face.At(i); + fc.Add(Null); + for(int j = 0; j < edit.face.GetCount(); j++) + fc.Add(Font::GetFaceName(edit.face.GetKey(j))); + if(fc.Find(k.face) < 0) + fc.Add(k.face); + fc <<= k.face; + list.SetCtrl(i, 2, fc, false); + + DropList& hg = height.At(i); + hg.Add(Null); + for(int j = 0; j < edit.height.GetCount(); j++) + hg.Add(edit.height.Get(j)); + if(hg.Find(k.face) < 0) + hg.Add(k.face); + list.SetCtrl(i, 3, hg, false); + + ColorPusher& n = ink.At(i); + n.NullText(""); + n <<= k.ink; + list.SetCtrl(i, 4, n, false); + + ColorPusher& p = paper.At(i); + p.NullText(""); + p <<= k.paper; + list.SetCtrl(i, 5, p, false); + } +} + +void StyleKeysDlg::Retrieve(RichEdit::StyleKey *key) +{ + for(int i = 0; i < 20; i++) { + RichEdit::StyleKey& k = key[i]; + k.styleid = ~style[i]; + k.stylename = style[i].GetValue(); + k.face = ~face[i]; + k.height = ~height[i]; + k.ink = ~ink[i]; + k.paper = ~paper[i]; + } +} + +void RichEdit::StyleKeys() +{ + StyleKeysDlg dlg; + dlg.Init(*this, stylekey); + if(dlg.Run() == IDOK) + dlg.Retrieve(stylekey); +} + +void RichEdit::ApplyStyleKey(int i) +{ + const StyleKey& k = stylekey[i]; + if(!IsNull(k.styleid)) { + int q = style.FindKey(k.styleid); + if(q >= 0) { + style.SetIndex(q); + Style(); + } + } + if(!IsNull(k.face)) { + int q = face.FindValue(k.face); + if(q >= 0) { + face.SetIndex(q); + SetFace(); + } + } + if(!IsNull(k.height)) { + height <<= k.height; + SetHeight(); + } + if(!IsNull(k.ink)) { + ink <<= k.ink; + SetInk(); + } + if(!IsNull(k.paper)) { + paper <<= k.paper; + SetPaper(); + } +} + +END_UPP_NAMESPACE diff --git a/uppsrc/RichEdit/Tool.cpp b/uppsrc/RichEdit/Tool.cpp index 6270c95e1..eb1fad6fc 100644 --- a/uppsrc/RichEdit/Tool.cpp +++ b/uppsrc/RichEdit/Tool.cpp @@ -413,7 +413,12 @@ void RichEdit::TableTools(Bar& bar) void RichEdit::InsertImageTool(Bar& bar) { - bar.Add("Insert image from file..", THISBACK(InsertImage)); + bar.Add(t_("Insert image from file.."), THISBACK(InsertImage)); +} + +void RichEdit::StyleKeysTool(Bar& bar) +{ + bar.Add(t_("Style keys.."), THISBACK(StyleKeys)); } void RichEdit::DefaultBar(Bar& bar, bool extended) diff --git a/uppsrc/RichEdit/init b/uppsrc/RichEdit/init index f80c2375b..4b6f49a5a 100644 --- a/uppsrc/RichEdit/init +++ b/uppsrc/RichEdit/init @@ -1,7 +1,7 @@ #ifndef _RichEdit_icpp_init_stub #define _RichEdit_icpp_init_stub #include "CtrlLib/init" -#define BLITZ_INDEX__ F507760F71D06E16B7AC2B30FB35B4251 +#define BLITZ_INDEX__ F0AD88DAE5AC04DD9AE26D94EEE4D96E1 #include "RichEdit.icpp" #undef BLITZ_INDEX__ #endif diff --git a/uppsrc/ide/Browser/Accels.cpp b/uppsrc/ide/Browser/Accels.cpp deleted file mode 100644 index b7a394862..000000000 --- a/uppsrc/ide/Browser/Accels.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "Browser.h" - -class AccelDlg : public WithAccelLayout { - typedef AccelDlg CLASSNAME; - - Array style; - Array font; - Array height; - Array ink; - Array paper; - -public: - const RichStyles *textstyles; - - AccelDlg(); -}; - -AccelDlg::AccelDlg() -{ - CtrlLayoutOKCancel(*this, "Styling keys"); - - list.AddColumn("Key"); - list.AddColumn("Paragraph style"); - list.AddColumn("Font"); - list.AddColumn("Height"); - list.AddColumn("Ink"); - list.AddColumn("Paper"); - list.SetLineCy(EditField::GetStdHeight() + 2); - list.NoGrid().EvenRowColor(); - - for(int i = 0; i < 20; i++) { - list.Add((i >= 10 ? "Shift+Alt+" : "Alt+") + AsString(i % 10)); - DropList& st = style.At(i); - st.Add(Null, "-"); - for(int j = 0; j < textstyles->GetCount(); j++) - st.Add(textstyles->GetKey(j), (*textstyles)[j].name); - list.SetCtrl(i, 1, st); - list.SetCtrl(i, 2, font.At(i).Add(Null)); - list.SetCtrl(i, 3, height.At(i).Add(Null)); - list.SetCtrl(i, 4, ink.At(i).NullText("")); - list.SetCtrl(i, 5, paper.At(i).NullText("")); - } -} - -void TopicEditor::Accels() -{ - AccelDlg dlg; - dlg.textstyles = &editor.Get().GetStyles(); - dlg.Run(); -} diff --git a/uppsrc/ide/Browser/Browser.h b/uppsrc/ide/Browser/Browser.h index 64b959dcc..88a3750fa 100644 --- a/uppsrc/ide/Browser/Browser.h +++ b/uppsrc/ide/Browser/Browser.h @@ -352,8 +352,6 @@ protected: void InsertItem(); void FindBrokenRef(); - - void Accels(); public: Callback1 WhenTemplatesMenu; diff --git a/uppsrc/ide/Browser/Browser.upp b/uppsrc/ide/Browser/Browser.upp index 751b338ec..1df5ee4eb 100644 --- a/uppsrc/ide/Browser/Browser.upp +++ b/uppsrc/ide/Browser/Browser.upp @@ -23,7 +23,6 @@ file Topic.cpp, Template.cpp, Link.cpp, - Accels.cpp, TopicWin.cpp, IdeTopic.cpp, TopicI.icpp, diff --git a/uppsrc/ide/Browser/Topic.lay b/uppsrc/ide/Browser/Topic.lay index e61ec970d..7a86d37f0 100644 --- a/uppsrc/ide/Browser/Topic.lay +++ b/uppsrc/ide/Browser/Topic.lay @@ -62,10 +62,3 @@ LAYOUT(SaveTemplateLayout, 248, 96) ITEM(Button, ok, SetLabel(t_("OK")).LeftPosZ(108, 64).TopPosZ(60, 24)) ITEM(Button, cancel, SetLabel(t_("Cancel")).LeftPosZ(176, 64).TopPosZ(60, 24)) END_LAYOUT - -LAYOUT(AccelLayout, 736, 556) - ITEM(ArrayCtrl, list, LeftPosZ(8, 720).TopPosZ(8, 508)) - ITEM(Button, ok, SetLabel(t_("OK")).LeftPosZ(596, 64).TopPosZ(524, 24)) - ITEM(Button, cancel, SetLabel(t_("Cancel")).LeftPosZ(664, 64).TopPosZ(524, 24)) -END_LAYOUT - diff --git a/uppsrc/ide/Browser/TopicWin.cpp b/uppsrc/ide/Browser/TopicWin.cpp index 2561cb833..18c1259ad 100644 --- a/uppsrc/ide/Browser/TopicWin.cpp +++ b/uppsrc/ide/Browser/TopicWin.cpp @@ -142,7 +142,7 @@ void TopicEditor::TopicMenu(Bar& bar) "Save as template..", THISBACK(SaveAsTemplate)); bar.Add(topic.IsCursor(), "Apply template stylesheet..", THISBACK(ApplyStylesheet)); bar.Add("Apply template stylesheet to group..", THISBACK(ApplyStylesheetGroup)); - bar.Add("Styling keys..", THISBACK(Accels)); + editor.StyleKeysTool(bar); } void TopicEditor::FileBar(Bar& bar) diff --git a/uppsrc/ide/Browser/init b/uppsrc/ide/Browser/init index a02d508f9..b7e9dab19 100644 --- a/uppsrc/ide/Browser/init +++ b/uppsrc/ide/Browser/init @@ -4,7 +4,7 @@ #include "ide\Common/init" #include "PdfDraw/init" #include "RichEdit/init" -#define BLITZ_INDEX__ FA8D2E284DF16D32149ED216D1C096475 +#define BLITZ_INDEX__ FBC518112DEEE5BCB5A93FFF277DB6572 #include "TopicI.icpp" #undef BLITZ_INDEX__ #endif diff --git a/uppsrc/ide/version.h b/uppsrc/ide/version.h index f910ca0f9..67425ca07 100644 --- a/uppsrc/ide/version.h +++ b/uppsrc/ide/version.h @@ -1 +1 @@ -#define IDE_VERSION "808.r135" +#define IDE_VERSION "809.r140"