From cfecef441e69ab048082bf31183154ef4d3e4f8d Mon Sep 17 00:00:00 2001 From: dolik Date: Wed, 8 Sep 2010 15:45:36 +0000 Subject: [PATCH] theide: QTF designer edits selection git-svn-id: svn://ultimatepp.org/upp/trunk@2672 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/ide/Qtf.cpp | 230 ++++++++++++++++++++++-------------------- uppsrc/ide/Setup.cpp | 1 + uppsrc/ide/ide.h | 1 + uppsrc/ide/ide.lay | 17 ++-- uppsrc/ide/idewin.cpp | 5 +- 5 files changed, 136 insertions(+), 118 deletions(-) diff --git a/uppsrc/ide/Qtf.cpp b/uppsrc/ide/Qtf.cpp index 784180310..02b25dfa5 100644 --- a/uppsrc/ide/Qtf.cpp +++ b/uppsrc/ide/Qtf.cpp @@ -1,109 +1,121 @@ -#include "ide.h" - -INITBLOCK { - RegisterGlobalConfig("QTF-designer"); - RegisterGlobalConfig("QTF-designer-editor"); -} - -class QtfDlg : public WithQtfLayout { - typedef QtfDlg CLASSNAME; - - void Text(); - void Clear(); - void Copy(); - void Editor(); - -public: - void Serialize(Stream& s); - - QtfDlg(); -}; - -void QtfDlg::Text() -{ - qtf <<= ~text; -} - -void QtfDlg::Clear() -{ - text.Clear(); - Text(); -} - -void QtfDlg::Copy() -{ - WriteClipboardText(~text); - Break(); -} - -struct QtfDlgEditor : TopWindow { - RichEditWithToolBar editor; - - void Serialize(Stream& s); - - QtfDlgEditor(); -}; - -void QtfDlgEditor::Serialize(Stream& s) -{ - SerializePlacement(s); -} - -QtfDlgEditor::QtfDlgEditor() -{ - Add(editor.SizePos()); - Rect r = GetWorkArea(); - SetRect(0, 0, r.GetWidth() - 100, r.GetHeight() - 100); -} - -void QtfDlg::Editor() -{ - QtfDlgEditor dlg; - LoadFromGlobal(dlg, "QTF-designer-editor"); - dlg.editor.SetQTF((String)~text); - dlg.Run(); - if(PromptYesNo("Use the text?")) { - text <<= AsQTF(dlg.editor.Get(), - CHARSET_UTF8, QTF_BODY|QTF_NOSTYLES|QTF_NOCHARSET|QTF_NOLANG); - Text(); - } - StoreToGlobal(dlg, "QTF-designer-editor"); -} - -QtfDlg::QtfDlg() -{ - CtrlLayout(*this, "QTF designer"); - text <<= THISBACK(Text); - qtf.SetFrame(ViewFrame()); - qtf.Background(SColorPaper); - Sizeable().Zoomable(); - Rect r = GetWorkArea(); - SetRect(0, 0, r.GetWidth() - 100, r.GetHeight() - 200); - - String path = AppendFileName(AppendFileName(PackageDirectory("RichText"), "srcdoc.tpp"), "QTF$en-us.tpp"); - if(FileExists(path)) - help.SetQTF(ReadTopic(LoadFile(path)).text); - else - help <<= "[= &&&QTF documentation not found"; - - clear <<= THISBACK(Clear); - copy <<= THISBACK(Copy); - editor <<= THISBACK(Editor); -} - -void QtfDlg::Serialize(Stream& s) -{ - int version = 0; - s / version; - s % text; - SerializePlacement(s); - Text(); -} - -void Ide::Qtf() -{ - QtfDlg dlg; - LoadFromGlobal(dlg, "QTF-designer"); - dlg.Run(); - StoreToGlobal(dlg, "QTF-designer"); -} +#include "ide.h" + +INITBLOCK { + RegisterGlobalConfig("QTF-designer"); + RegisterGlobalConfig("QTF-designer-editor"); +} + +class QtfDlg : public WithQtfLayout { + typedef QtfDlg CLASSNAME; + + void Text(); + void Clear(); + void Copy(); + void Editor(); + +public: + void Serialize(Stream& s); + + QtfDlg(); +}; + +void QtfDlg::Text() +{ + qtf <<= ~text; +} + +void QtfDlg::Clear() +{ + text.Clear(); + Text(); +} + +void QtfDlg::Copy() +{ + WriteClipboardText(~text); + Break(); +} + +struct QtfDlgEditor : TopWindow { + RichEditWithToolBar editor; + + void Serialize(Stream& s); + + QtfDlgEditor(); +}; + +void QtfDlgEditor::Serialize(Stream& s) +{ + SerializePlacement(s); +} + +QtfDlgEditor::QtfDlgEditor() +{ + Add(editor.SizePos()); + Rect r = GetWorkArea(); + SetRect(0, 0, r.GetWidth() - 100, r.GetHeight() - 100); +} + +void QtfDlg::Editor() +{ + QtfDlgEditor dlg; + LoadFromGlobal(dlg, "QTF-designer-editor"); + dlg.editor.SetQTF((String)~text); + dlg.Run(); + if(PromptYesNo("Use the text?")) { + text <<= AsQTF(dlg.editor.Get(), + CHARSET_UTF8, QTF_BODY|QTF_NOSTYLES|QTF_NOCHARSET|QTF_NOLANG); + Text(); + } + StoreToGlobal(dlg, "QTF-designer-editor"); +} + +QtfDlg::QtfDlg() +{ + CtrlLayout(*this, "QTF designer"); + text <<= THISBACK(Text); + qtf.SetFrame(ViewFrame()); + qtf.Background(SColorPaper); + Sizeable().Zoomable(); + Rect r = GetWorkArea(); + SetRect(0, 0, r.GetWidth() - 100, r.GetHeight() - 200); + + String path = AppendFileName(AppendFileName(PackageDirectory("RichText"), "srcdoc.tpp"), "QTF$en-us.tpp"); + if(FileExists(path)) + help.SetQTF(ReadTopic(LoadFile(path)).text); + else + help <<= "[= &&&QTF documentation not found"; + + clear <<= THISBACK(Clear); + copy <<= THISBACK(Copy); + editor <<= THISBACK(Editor); +} + +void QtfDlg::Serialize(Stream& s) +{ + int version = 0; + s / version; + s % text; + SerializePlacement(s); + Text(); +} + +void Ide::Qtf() +{ + QtfDlg dlg; + LoadFromGlobal(dlg, "QTF-designer"); + int l,h; + bool sel=editor.GetSelection(l,h); + if(qtfsel && sel){ + dlg.text<<=(~editor).ToString().Mid(l,h-l); + dlg.copy.SetLabel("Apply and close"); + dlg.Run(); + editor.Remove(l,h-l); + editor.Insert(l,(~dlg.text).ToString()); + } + else{ + dlg.copy.SetLabel("Copy and close"); + dlg.Run(); + } + StoreToGlobal(dlg, "QTF-designer"); +} diff --git a/uppsrc/ide/Setup.cpp b/uppsrc/ide/Setup.cpp index d6e953eb8..81ff2ffee 100644 --- a/uppsrc/ide/Setup.cpp +++ b/uppsrc/ide/Setup.cpp @@ -347,6 +347,7 @@ void Ide::SetupFormat() { (edt.no_parenthesis_indent, no_parenthesis_indent) (edt.showtabs, show_tabs) (edt.barline, barline) + (edt.qtfsel, qtfsel) (ide.tabs_icons, tabs_icons) (ide.tabs_crosses, tabs_crosses) (ide.tabs_grouping, tabs_grouping) diff --git a/uppsrc/ide/ide.h b/uppsrc/ide/ide.h index d746f9b44..d1af544f7 100644 --- a/uppsrc/ide/ide.h +++ b/uppsrc/ide/ide.h @@ -683,6 +683,7 @@ public: int hilite_bracket; int hilite_ifdef; bool barline; + bool qtfsel; enum { STYLE_NO_REPLACE, STYLE_CONFIRM_REPLACE, STYLE_AUTO_REPLACE }; diff --git a/uppsrc/ide/ide.lay b/uppsrc/ide/ide.lay index 0a3296c41..e46e50129 100644 --- a/uppsrc/ide/ide.lay +++ b/uppsrc/ide/ide.lay @@ -427,14 +427,15 @@ LAYOUT(SetupEditorLayout, 488, 280) ITEM(Option, no_parenthesis_indent, SetLabel(t_("No indent after parenthesis")).LeftPosZ(12, 176).TopPosZ(116, 16)) ITEM(Option, numbers, SetLabel(t_("Show line numbers")).LeftPosZ(12, 112).TopPosZ(136, 16)) ITEM(Option, bookmark_pos, SetLabel(t_("Bookmarks restore position")).LeftPosZ(12, 152).TopPosZ(156, 16)) - ITEM(Switch, insert_include, SetLabel(t_("No #include in new sources\n#include first\n#include previous")).LeftPosZ(284, 156).TopPosZ(24, 56)) + ITEM(Switch, insert_include, SetLabel(t_("No #include in new sources\n#include first\n#include previous")).LeftPosZ(284, 156).TopPosZ(24, 48)) ITEM(Option, forcecrlf, SetLabel(t_("Force CRLF line endings")).LeftPosZ(12, 160).TopPosZ(216, 16)) ITEM(Option, findpicksel, SetLabel(t_("Find picks selection")).LeftPosZ(12, 160).TopPosZ(236, 16)) ITEM(Option, findpicktext, SetLabel(t_("Find picks selection or text")).LeftPosZ(12, 160).TopPosZ(256, 16)) ITEM(Option, header_guards, SetLabel(t_("Insert guards to new headers")).LeftPosZ(284, 164).TopPosZ(4, 15)) ITEM(Option, auto_enclose, SetLabel(t_("[ { ( \" / * enclose selection")).LeftPosZ(12, 168).TopPosZ(176, 16)) ITEM(Option, mark_lines, SetLabel(t_("Mark lines with errors, warning and changes")).LeftPosZ(12, 256).TopPosZ(196, 16)) - ITEM(Option, barline, SetLabel(t_("Highlight line in the left bar")).LeftPosZ(284, 180).TopPosZ(88, 16)) + ITEM(Option, barline, SetLabel(t_("Highlight line in the left bar")).LeftPosZ(284, 180).TopPosZ(76, 16)) + ITEM(Option, qtfsel, SetLabel(t_("QTF designer edits selection")).LeftPosZ(284, 180).TopPosZ(96, 16)) END_LAYOUT LAYOUT(SetupIdeLayout, 520, 264) @@ -612,11 +613,11 @@ LAYOUT(ImportLayout, 400, 92) END_LAYOUT LAYOUT(QtfLayout, 964, 584) - ITEM(DocEdit, text, HSizePosZ(4, 612).TopPosZ(28, 204)) - ITEM(RichTextCtrl, qtf, HSizePosZ(4, 612).VSizePosZ(236, 8)) - ITEM(RichTextView, help, RightPosZ(4, 604).VSizePosZ(4, 8)) - ITEM(Button, editor, SetLabel(t_("Editor")).RightPosZ(612, 56).TopPosZ(4, 20)) - ITEM(Button, clear, SetLabel(t_("Clear")).RightPosZ(676, 56).TopPosZ(4, 20)) - ITEM(Button, copy, SetLabel(t_("Copy and close")).RightPosZ(736, 100).TopPosZ(4, 20)) + ITEM(DocEdit, text, LeftPosZ(4, 348).TopPosZ(28, 204)) + ITEM(RichTextCtrl, qtf, LeftPosZ(4, 348).VSizePosZ(236, 8)) + ITEM(RichTextView, help, HSizePosZ(356, 4).VSizePosZ(4, 8)) + ITEM(Button, editor, SetLabel(t_("Editor")).LeftPosZ(296, 56).TopPosZ(4, 20)) + ITEM(Button, clear, SetLabel(t_("Clear")).LeftPosZ(232, 56).TopPosZ(4, 20)) + ITEM(Button, copy, SetLabel(t_("Copy and close")).LeftPosZ(128, 100).TopPosZ(4, 20)) END_LAYOUT diff --git a/uppsrc/ide/idewin.cpp b/uppsrc/ide/idewin.cpp index ed63496c4..9ded90abd 100644 --- a/uppsrc/ide/idewin.cpp +++ b/uppsrc/ide/idewin.cpp @@ -80,7 +80,7 @@ void Ide::ConsolePaste() } void Ide::Serialize(Stream& s) { - int version = 16; + int version = 17; s.Magic(0x1234); s / version; s % main; @@ -119,6 +119,8 @@ void Ide::Serialize(Stream& s) { s % hilite_ifdef; if(version >= 16) s % barline; + if(version >= 17) + s % qtfsel; s % wrap_console_text; s % mute_sounds; s % line_numbers; @@ -580,6 +582,7 @@ Ide::Ide() hilite_bracket = 1; hilite_ifdef = 1; barline = true; + qtfsel = true; hilite_if_endif = false; wrap_console_text = true; mute_sounds = false;