diff --git a/uppsrc/ide/GoToLine.cpp b/uppsrc/ide/GoToLine.cpp new file mode 100644 index 000000000..81ef24b7f --- /dev/null +++ b/uppsrc/ide/GoToLine.cpp @@ -0,0 +1,50 @@ +#include "ide.h" + +static const int MIN_LINE_NUMBER = 1; + +class GoToLineDialog : public WithGoToLineLayout { +public: + GoToLineDialog(int currentLine, int maxLine) + { + CtrlLayoutOKCancel(*this, String(t_("Go to line")) << ".."); + + lineInformation.SetText(GenerateLineInfo(maxLine)); + lineEdit.Min(MIN_LINE_NUMBER).Max(maxLine); + lineEdit.SetFocus(); + lineEdit.SetData(currentLine); + lineEdit.SelectAll(); + } + + int GetLine() const + { + return static_cast(lineEdit.GetData()); + } + +private: + String GenerateLineInfo(int maxLine) + { + StringStream ss; + + ss << t_("Go to line") << " (" << MIN_LINE_NUMBER << ", " << maxLine << "):"; + + return ss.GetResult(); + } +}; + +void Ide::GoToLine() +{ + const int currentLine = editor.GetCurrentLine() + 1; + + GoToLineDialog dlg(currentLine, editor.GetLineCount()); + if(dlg.Execute() != IDOK) + return; + + const int newLine = dlg.GetLine(); + if (currentLine == newLine) + return; + + AddHistory(); + editor.SetCursor(editor.GetPos(newLine - 1)); + editor.SetFocus(); + AddHistory(); +} diff --git a/uppsrc/ide/ide.h b/uppsrc/ide/ide.h index b83be48aa..ac2934c4d 100644 --- a/uppsrc/ide/ide.h +++ b/uppsrc/ide/ide.h @@ -777,12 +777,12 @@ public: void Print(); void Diff(); void GotoDiffLeft(int line, DiffDlg *df); - void GotoDiffRight(int line, FileDiff *df); + void GotoDiffRight(int line, FileDiff *df); void Patch(); void SvnHistory(); void Edit(Bar& menu); - bool IsDesignerFile(const String& path); + bool IsDesignerFile(const String& path); void DoEditAsText(const String& path); void EditAsText(); void EditAsHex(); @@ -927,6 +927,7 @@ public: void FindId(const String& id); void ContextGoto0(int pos); void ContextGoto(); + void GoToLine(); void CtrlClick(int pos); void Qtf(); void Xml(); diff --git a/uppsrc/ide/ide.key b/uppsrc/ide/ide.key index 66164c128..05ca48362 100644 --- a/uppsrc/ide/ide.key +++ b/uppsrc/ide/ide.key @@ -93,6 +93,7 @@ KEY(XML, "XML view", K_ALT_X) KEY(JSON, "JSON view", K_ALT_N) KEY(ASSIST, "Assist", ' '|K_CTRL) KEY(ABBR, "Complete abbreviation", K_CTRL_PERIOD) +KEY(GO_TO_LINE, "Go to line..", K_CTRL|K_SHIFT_G) KEY(DCOPY, "Copy as definition/declaration", K_ALT_C) KEY(VIRTUALS, "Virtual methods..", K_ALT_V) KEY(THISBACKS, "THISBACKs..", K_ALT_T) diff --git a/uppsrc/ide/ide.lay b/uppsrc/ide/ide.lay index 76aa0392e..79d4ae935 100644 --- a/uppsrc/ide/ide.lay +++ b/uppsrc/ide/ide.lay @@ -805,10 +805,17 @@ LAYOUT(RenamePackage2Layout, 228, 100) END_LAYOUT LAYOUT(NewPackageFileLayout, 260, 88) - ITEM(EditString, name, HSizePosZ(44, 8).TopPosZ(28, 19)) - ITEM(Label, dv___1, SetLabel(t_("Name ")).LeftPosZ(4, 64).TopPosZ(28, 19)) + ITEM(EditString, name, HSizePosZ(48, 8).TopPosZ(28, 19)) + ITEM(Label, dv___1, SetLabel(t_("Name ")).LeftPosZ(4, 40).TopPosZ(28, 19)) ITEM(DropList, type, HSizePosZ(4, 8).TopPosZ(4, 19)) ITEM(Button, ok, SetLabel(t_("OK")).RightPosZ(76, 64).BottomPosZ(8, 24)) ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 64).BottomPosZ(8, 24)) END_LAYOUT +LAYOUT(GoToLineLayout, 260, 88) + ITEM(StaticText, lineInformation, HSizePosZ(8, 8).TopPosZ(8, 19)) + ITEM(EditInt, lineEdit, NotNull(true).HSizePosZ(8, 8).TopPosZ(28, 19)) + ITEM(Button, ok, SetLabel(t_("OK")).RightPosZ(76, 64).BottomPosZ(8, 24)) + ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 64).BottomPosZ(8, 24)) +END_LAYOUT + diff --git a/uppsrc/ide/ide.upp b/uppsrc/ide/ide.upp index 1c8f3cfd5..fdaddd4d9 100644 --- a/uppsrc/ide/ide.upp +++ b/uppsrc/ide/ide.upp @@ -51,6 +51,7 @@ file Assist.cpp, DCopy.cpp, ContextGoto.cpp, + GoToLine.cpp, Swaps.cpp, ParamInfo.cpp, Navigator.cpp, diff --git a/uppsrc/ide/idebar.cpp b/uppsrc/ide/idebar.cpp index b02e78827..05dd7a7f0 100644 --- a/uppsrc/ide/idebar.cpp +++ b/uppsrc/ide/idebar.cpp @@ -610,6 +610,7 @@ void Ide::BrowseMenu(Bar& menu) 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, AK_GO_TO_LINE, THISBACK(GoToLine)); menu.Add(!designer, "Insert", THISBACK(InsertMenu)); menu.MenuSeparator(); } @@ -630,6 +631,11 @@ void Ide::BrowseMenu(Bar& menu) menu.MenuSeparator(); } } + else { + menu.Add(!designer, AK_GO_TO_LINE, THISBACK(GoToLine)); + menu.MenuSeparator(); + } + if(menu.IsMenuBar()) { menu.AddMenu(AK_CALC, IdeImg::calc(), THISBACK1(ToggleBottom, BCALC)) .Check(IsBottomShown() && btabs.GetCursor() == BCALC); diff --git a/uppsrc/ide/idetool.cpp b/uppsrc/ide/idetool.cpp index 46e1a3d34..f4d80f900 100644 --- a/uppsrc/ide/idetool.cpp +++ b/uppsrc/ide/idetool.cpp @@ -46,7 +46,7 @@ void Ide::GotoPos(String path, int line) if(path.GetCount()) { AddHistory(); if(IsDesignerFile(path)) - DoEditAsText(path); + DoEditAsText(path); EditFile(path); } editor.SetCursor(editor.GetPos(line - 1));