mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-09-09 11:34:54 -06:00
theide - Complete abbreviation
git-svn-id: svn://ultimatepp.org/upp/trunk@694 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
9616903c73
commit
aa4926084c
11 changed files with 200 additions and 5 deletions
|
|
@ -989,7 +989,7 @@ void CodeEditor::PutI(WithDropChoice<EditString>& edit)
|
|||
}
|
||||
|
||||
CodeEditor::CodeEditor() {
|
||||
bracket_flash = true;
|
||||
bracket_flash = false;
|
||||
highlight_bracket_pos0 = 0;
|
||||
bracket_start = 0;
|
||||
stat_edit_time = 0;
|
||||
|
|
@ -1016,7 +1016,7 @@ CodeEditor::CodeEditor() {
|
|||
bar.WhenAnnotationRightClick = Proxy(WhenAnnotationRightClick);
|
||||
highlight = HIGHLIGHT_NONE;
|
||||
hilite_scope = 0;
|
||||
hilite_bracket = 2;
|
||||
hilite_bracket = 1;
|
||||
hilite_ifdef = 1;
|
||||
indent_spaces = false;
|
||||
indent_amount = GetTabSize();
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ void LineEdit::Paint0(Draw& w) {
|
|||
int l = ngp - gp;
|
||||
LLOG("Highlight -> tab[" << q << "] paper = " << h.paper);
|
||||
w.DrawRect(gp * fsz.cx - scx, y, fsz.cx * l, fsz.cy, h.paper);
|
||||
if(showtabs && h.paper != SColorHighlight) {
|
||||
if(showtabs && h.paper != SColorHighlight && q < tx.GetLength()) {
|
||||
Color c = Blend(SColorLight, SColorHighlight);
|
||||
w.DrawRect(gp * fsz.cx - scx + 2, y + fsz.cy / 2,
|
||||
l * fsz.cx - 4, 1, c);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include "CtrlCore/init"
|
||||
#include "RichText/init"
|
||||
#include "PdfDraw/init"
|
||||
#define BLITZ_INDEX__ F2AFAB801F99B3E8069C425DA8E8DCF65
|
||||
#define BLITZ_INDEX__ F9E4BBC13A1F4208D11AB0446CDBF7C80
|
||||
#include "CtrlLib.icpp"
|
||||
#undef BLITZ_INDEX__
|
||||
#endif
|
||||
|
|
|
|||
131
uppsrc/ide/Abbr.cpp
Normal file
131
uppsrc/ide/Abbr.cpp
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
#include "ide.h"
|
||||
|
||||
class AbbreviationsDlg : public WithAbbreviationsLayout<TopWindow> {
|
||||
typedef AbbreviationsDlg CLASSNAME;
|
||||
EditString keyword;
|
||||
|
||||
void Add();
|
||||
void Remove();
|
||||
void Edit();
|
||||
void Sync();
|
||||
void Menu(Bar& bar);
|
||||
void Finish(const String& s);
|
||||
|
||||
public:
|
||||
AbbreviationsDlg();
|
||||
};
|
||||
|
||||
void AbbreviationsDlg::Sync()
|
||||
{
|
||||
edit.Enable(abbr.IsCursor());
|
||||
remove.Enable(abbr.IsCursor());
|
||||
}
|
||||
|
||||
void AbbreviationsDlg::Menu(Bar& bar)
|
||||
{
|
||||
bar.Add("New..", THISBACK(Add));
|
||||
bar.Add(abbr.IsCursor(), "Edit..", THISBACK(Edit));
|
||||
bar.Add(abbr.IsCursor(), "Delete", THISBACK(Remove));
|
||||
}
|
||||
|
||||
void AbbreviationsDlg::Finish(const String& s)
|
||||
{
|
||||
abbr.Sort();
|
||||
Sync();
|
||||
abbr.FindSetCursor(s);
|
||||
}
|
||||
|
||||
void AbbreviationsDlg::Add()
|
||||
{
|
||||
String s;
|
||||
EditText(s, "New abbreviation", "Keyword", CharFilterAlpha);
|
||||
abbr.Add(s, Null);
|
||||
Finish(s);
|
||||
}
|
||||
|
||||
void AbbreviationsDlg::Remove()
|
||||
{
|
||||
if(abbr.IsCursor() && PromptYesNo("Remove abbreviation?"))
|
||||
abbr.Remove(abbr.GetCursor());
|
||||
Sync();
|
||||
}
|
||||
|
||||
void AbbreviationsDlg::Edit()
|
||||
{
|
||||
if(!abbr.IsCursor())
|
||||
return;
|
||||
String s = abbr.GetKey();
|
||||
EditText(s, "Edit keyword", "Keyword", CharFilterAlpha);
|
||||
abbr.Set(0, s);
|
||||
Finish(s);
|
||||
}
|
||||
|
||||
AbbreviationsDlg::AbbreviationsDlg()
|
||||
{
|
||||
CtrlLayoutOKCancel(*this, "Abbreviations");
|
||||
abbr.AddColumn("Keyword").Edit(keyword);
|
||||
abbr.AddCtrl(code);
|
||||
abbr.WhenBar = THISBACK(Menu);
|
||||
add <<= THISBACK(Add);
|
||||
remove <<= THISBACK(Remove);
|
||||
edit <<= THISBACK(Edit);
|
||||
code.Highlight(CodeEditor::HIGHLIGHT_CPP);
|
||||
code.ShowTabs();
|
||||
Sync();
|
||||
}
|
||||
|
||||
void Ide::Abbreviations()
|
||||
{
|
||||
AbbreviationsDlg dlg;
|
||||
for(int i = 0; i < abbr.GetCount(); i++)
|
||||
dlg.abbr.Add(abbr.GetKey(i), abbr[i]);
|
||||
if(dlg.Execute() != IDOK)
|
||||
return;
|
||||
abbr.Clear();
|
||||
for(int i = 0; i < dlg.abbr.GetCount(); i++)
|
||||
abbr.Add(dlg.abbr.Get(i, 0), dlg.abbr.Get(i, 1));
|
||||
SaveAbbr();
|
||||
}
|
||||
|
||||
void Ide::LoadAbbr()
|
||||
{
|
||||
abbr.Clear();
|
||||
String s = LoadFile(ConfigFile("ide.abbrs"));
|
||||
try {
|
||||
CParser p(s);
|
||||
while(!p.IsEof()) {
|
||||
String a = p.ReadString();
|
||||
p.Char('=');
|
||||
String b = p.ReadString();
|
||||
p.Char(';');
|
||||
abbr.Add(a, b);
|
||||
}
|
||||
}
|
||||
catch(CParser::Error) {}
|
||||
if(abbr.GetCount() == 0) {
|
||||
abbr.Add("c", "case @:\r\n\tbreak;");
|
||||
abbr.Add("d", "do\r\n\t@;\r\nwhile();");
|
||||
abbr.Add("db", "do {\r\n\t@;\r\n}\r\nwhile();");
|
||||
abbr.Add("e", "else\r\n\t;");
|
||||
abbr.Add("eb", "else {\r\n\t;\r\n}");
|
||||
abbr.Add("ei", "else\r\nif(@)\r\n\t;");
|
||||
abbr.Add("eib", "else\r\nif(@) {\r\n\t;\r\n}");
|
||||
abbr.Add("f", "for(@;;)\r\n\t;");
|
||||
abbr.Add("fb", "for(@;;) {\r\n\t\r\n}");
|
||||
abbr.Add("i", "if(@)\r\n\t;");
|
||||
abbr.Add("ib", "if(@) {\r\n\t\r\n}");
|
||||
abbr.Add("ie", "if(@)\r\n\t;\r\nelse\r\n\t;");
|
||||
abbr.Add("ieb", "if(@) {\r\n\t\r\n}\r\nelse {\r\n\t\r\n}");
|
||||
abbr.Add("sw", "switch(@) {\r\ncase :\r\n\tbreak;\r\ndefault:\r\n\tbreak;\r\n}");
|
||||
abbr.Add("w", "while(@)\r\n\t;");
|
||||
abbr.Add("wb", "while(@) {\r\n\t\r\n}");
|
||||
}
|
||||
}
|
||||
|
||||
void Ide::SaveAbbr()
|
||||
{
|
||||
String r;
|
||||
for(int i = 0; i < abbr.GetCount(); i++)
|
||||
r << AsCString(abbr.GetKey(i)) << '=' << AsCString(abbr[i]) << ";\r\n";
|
||||
UPP::SaveFile(ConfigFile("ide.abbrs"), r);
|
||||
}
|
||||
|
|
@ -457,6 +457,47 @@ void AssistEditor::Complete()
|
|||
PopUpAssist(true);
|
||||
}
|
||||
|
||||
void AssistEditor::Abbr()
|
||||
{
|
||||
CloseAssist();
|
||||
int c = GetCursor();
|
||||
int ch;
|
||||
String s;
|
||||
while(IsAlpha(ch = Ch(c - 1))) {
|
||||
s.Insert(0, ch);
|
||||
--c;
|
||||
}
|
||||
int len = s.GetCount();
|
||||
s = theide->abbr.Get(s, String());
|
||||
if(IsNull(s))
|
||||
return;
|
||||
NextUndo();
|
||||
SetCursor(c);
|
||||
Remove(c, len);
|
||||
int linepos = c;
|
||||
int line = GetLinePos(linepos);
|
||||
WString h = GetWLine(line).Mid(0, linepos);
|
||||
DDUMP(h);
|
||||
for(int i = 0; i < s.GetCount(); i++) {
|
||||
ch = s[i];
|
||||
switch(ch) {
|
||||
case '@':
|
||||
c = GetCursor();
|
||||
break;
|
||||
case '\n':
|
||||
InsertChar('\n');
|
||||
for(int j = 0; j < h.GetCount(); j++)
|
||||
InsertChar(h[j]);
|
||||
break;
|
||||
default:
|
||||
if((byte)s[i] >= ' ' || s[i] == '\t')
|
||||
InsertChar(s[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
SetCursor(c);
|
||||
}
|
||||
|
||||
void AssistEditor::AssistInsert()
|
||||
{
|
||||
if(assist.IsCursor()) {
|
||||
|
|
|
|||
|
|
@ -433,6 +433,7 @@ struct AssistEditor : CodeEditor {
|
|||
void StartParamInfo(const CppItem& m);
|
||||
|
||||
void Complete();
|
||||
void Abbr();
|
||||
|
||||
void Context(Parser& parser, int pos);
|
||||
void ExpressionType(const String& type, const Vector<String>& xp, int ii,
|
||||
|
|
@ -783,6 +784,7 @@ public:
|
|||
int state_icon;
|
||||
|
||||
String export_dir;
|
||||
VectorMap<String, String> abbr;
|
||||
|
||||
// ------------------------------------
|
||||
|
||||
|
|
@ -848,6 +850,9 @@ public:
|
|||
|
||||
void GotoPos(String path, int line);
|
||||
void GotoCpp(const CppItem& pos);
|
||||
|
||||
void LoadAbbr();
|
||||
void SaveAbbr();
|
||||
|
||||
Vector<String> SvnDirs();
|
||||
|
||||
|
|
@ -980,6 +985,7 @@ public:
|
|||
void SetupFormat();
|
||||
void ToggleVerboseBuild();
|
||||
void AutoSetup();
|
||||
void Abbreviations();
|
||||
|
||||
void BrowseMenu(Bar& menu);
|
||||
void RescanCode();
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ KEY(SEARCHTOPICS, "Search word in Help & Topics", K_CTRL_F1)
|
|||
KEY(BROWSETOPICS, "Help & Topics", K_F1)
|
||||
KEY(CALC, "Calculator", K_CTRL_E)
|
||||
KEY(ASSIST, "Assist", ' '|K_CTRL)
|
||||
KEY(COMPLETE, "Complete identifier", K_CTRL_COMMA)
|
||||
KEY(ABBR, "Complete abbreviation", K_CTRL_PERIOD)
|
||||
KEY(DCOPY, "Copy as definition/declaration", K_ALT_C)
|
||||
KEY(VIRTUALS, "Virtual methods..", K_ALT_V)
|
||||
KEY(THISBACKS, "THISBACKs..", K_ALT_T)
|
||||
|
|
@ -90,6 +90,7 @@ KEY(CLEARMARKERSALL, "Remove all change markers", K_SHIFT|K_ALT_R)
|
|||
KEY(TOGGLEINDEX, "File index", K_CTRL_F12)
|
||||
KEY(SEARCHINDEX, "File index search", K_F12)
|
||||
KEY(SEARCHCODE, "Search code", K_CTRL_Q)
|
||||
KEY(COMPLETE, "Complete identifier", K_CTRL_COMMA)
|
||||
|
||||
KEY(TOUPPER, "To uppercase", 0)
|
||||
KEY(TOLOWER, "To lowercase", 0)
|
||||
|
|
|
|||
|
|
@ -566,3 +566,14 @@ LAYOUT(InsertColorLayout, 432, 520)
|
|||
ITEM(Button, cancel, SetLabel(t_("Cancel")).LeftPosZ(284, 144).TopPosZ(492, 24))
|
||||
END_LAYOUT
|
||||
|
||||
LAYOUT(AbbreviationsLayout, 424, 476)
|
||||
ITEM(ArrayCtrl, abbr, LeftPosZ(4, 108).TopPosZ(4, 432))
|
||||
ITEM(CodeEditor, code, LeftPosZ(116, 304).TopPosZ(4, 408))
|
||||
ITEM(Button, add, SetLabel(t_("Add")).LeftPosZ(4, 64).TopPosZ(444, 24))
|
||||
ITEM(Button, edit, SetLabel(t_("Edit")).LeftPosZ(72, 64).TopPosZ(444, 24))
|
||||
ITEM(Button, remove, SetLabel(t_("Remove")).LeftPosZ(140, 64).TopPosZ(444, 24))
|
||||
ITEM(Button, ok, SetLabel(t_("OK")).LeftPosZ(288, 64).TopPosZ(444, 24))
|
||||
ITEM(Button, cancel, SetLabel(t_("Cancel")).LeftPosZ(356, 64).TopPosZ(444, 24))
|
||||
ITEM(Label, dv___7, SetLabel(t_("Use '@' character to place the caret.")).LeftPosZ(116, 304).TopPosZ(416, 19))
|
||||
END_LAYOUT
|
||||
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ file
|
|||
Macro.cpp,
|
||||
Calc.cpp,
|
||||
FormatCode.cpp,
|
||||
Abbr.cpp,
|
||||
Compile readonly separator,
|
||||
Methods.cpp,
|
||||
AutoSetup.cpp,
|
||||
|
|
|
|||
|
|
@ -276,6 +276,8 @@ void Ide::Setup(Bar& menu) {
|
|||
.Help("Log detailed description of build and debug");
|
||||
menu.Add("Environment..", THISBACK(SetupFormat))
|
||||
.Help("Fonts, tabs, indentation, status bar");
|
||||
menu.Add("Abbreviations..", THISBACK(Abbreviations))
|
||||
.Help("Edit abbreviation keywords and code");
|
||||
menu.Add("Keyboard shortcuts..", callback(EditKeys))
|
||||
.Help("Edit key bindings");
|
||||
menu.Add("Build methods..", THISBACK(SetupBuildMethods))
|
||||
|
|
@ -474,6 +476,7 @@ void Ide::BrowseMenu(Bar& menu) {
|
|||
menu.Add(!designer, AK_VIRTUALS, callback(&editor, &AssistEditor::Virtuals));
|
||||
menu.Add(!designer, AK_THISBACKS, callback(&editor, &AssistEditor::Thisbacks));
|
||||
menu.Add(!designer, AK_COMPLETE, callback(&editor, &AssistEditor::Complete));
|
||||
menu.Add(!designer, AK_ABBR, callback(&editor, &AssistEditor::Abbr));
|
||||
menu.Add(!designer, "Insert", THISBACK(InsertMenu));
|
||||
menu.Separator();
|
||||
menu.Add("Rescan code", THISBACK(RescanCode));
|
||||
|
|
|
|||
|
|
@ -933,6 +933,7 @@ void AppMain___()
|
|||
}
|
||||
|
||||
LoadFromFile(ide);
|
||||
ide.LoadAbbr();
|
||||
|
||||
ide.SyncCh();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue