Browse Source

Projucer: Removed an unused lambda capture and some code cleanup in SourceCodeEditor

tags/2021-05-28
ed 7 years ago
parent
commit
590e49216e
2 changed files with 29 additions and 32 deletions
  1. +28
    -31
      extras/Projucer/Source/CodeEditor/jucer_SourceCodeEditor.cpp
  2. +1
    -1
      extras/Projucer/Source/CodeEditor/jucer_SourceCodeEditor.h

+ 28
- 31
extras/Projucer/Source/CodeEditor/jucer_SourceCodeEditor.cpp View File

@@ -119,7 +119,7 @@ SourceCodeEditor::SourceCodeEditor (OpenDocumentManager::Document* doc, CodeDocu
: DocumentEditorComponent (doc)
{
GenericCodeEditorComponent* ed = nullptr;
const File file (document->getFile());
auto file = document->getFile();
if (fileNeedsCppSyntaxHighlighting (file))
{
@@ -160,7 +160,7 @@ SourceCodeEditor::~SourceCodeEditor()
getAppSettings().appearance.settings.removeListener (this);
if (SourceCodeDocument* doc = dynamic_cast<SourceCodeDocument*> (getDocument()))
if (auto* doc = dynamic_cast<SourceCodeDocument*> (getDocument()))
doc->updateLastState (*editor);
}
@@ -183,11 +183,11 @@ void SourceCodeEditor::setEditor (GenericCodeEditorComponent* newEditor)
void SourceCodeEditor::scrollToKeepRangeOnScreen (Range<int> range)
{
const int space = jmin (10, editor->getNumLinesOnScreen() / 3);
auto space = jmin (10, editor->getNumLinesOnScreen() / 3);
const CodeDocument::Position start (editor->getDocument(), range.getStart());
const CodeDocument::Position end (editor->getDocument(), range.getEnd());
editor->scrollToKeepLinesOnScreen (Range<int> (start.getLineNumber() - space, end.getLineNumber() + space));
editor->scrollToKeepLinesOnScreen ({ start.getLineNumber() - space, end.getLineNumber() + space });
}
void SourceCodeEditor::highlight (Range<int> range, bool cursorAtStart)
@@ -287,7 +287,7 @@ void GenericCodeEditorComponent::getAllCommands (Array <CommandID>& commands)
void GenericCodeEditorComponent::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
{
const bool anythingSelected = isHighlightActive();
auto anythingSelected = isHighlightActive();
switch (commandID)
{
@@ -348,14 +348,10 @@ class GenericCodeEditorComponent::FindPanel : public Component
{
public:
FindPanel()
: caseButton ("Case-sensitive"),
findPrev ("<"),
findNext (">")
{
editor.setColour (CaretComponent::caretColourId, Colours::black);
addAndMakeVisible (editor);
label.setText ("Find:", dontSendNotification);
label.setColour (Label::textColourId, Colours::white);
label.attachToComponent (&editor, false);
@@ -376,10 +372,10 @@ public:
editor.setText (getSearchString());
editor.onTextChange = [this] { changeSearchString(); };
editor.onReturnKey = [this] { ProjucerApplication::getCommandManager().invokeDirectly (CommandIDs::findNext, true); };
editor.onReturnKey = [] { ProjucerApplication::getCommandManager().invokeDirectly (CommandIDs::findNext, true); };
editor.onEscapeKey = [this]
{
if (GenericCodeEditorComponent* ed = getOwner())
if (auto* ed = getOwner())
ed->hideFindPanel();
};
}
@@ -415,7 +411,7 @@ public:
{
setSearchString (editor.getText());
if (GenericCodeEditorComponent* ed = getOwner())
if (auto* ed = getOwner())
ed->findNext (true, false);
}
@@ -425,9 +421,10 @@ public:
}
TextEditor editor;
Label label;
ToggleButton caseButton;
TextButton findPrev, findNext;
Label label { {}, "Find:" };
ToggleButton caseButton { "Case-sensitive" };
TextButton findPrev { "<" },
findNext { ">" };
};
void GenericCodeEditorComponent::resized()
@@ -465,7 +462,7 @@ void GenericCodeEditorComponent::hideFindPanel()
void GenericCodeEditorComponent::findSelection()
{
const String selected (getTextInRange (getHighlightedRegion()));
auto selected = getTextInRange (getHighlightedRegion());
if (selected.isNotEmpty())
{
@@ -476,19 +473,19 @@ void GenericCodeEditorComponent::findSelection()
void GenericCodeEditorComponent::findNext (bool forwards, bool skipCurrentSelection)
{
const Range<int> highlight (getHighlightedRegion());
auto highlight = getHighlightedRegion();
const CodeDocument::Position startPos (getDocument(), skipCurrentSelection ? highlight.getEnd()
: highlight.getStart());
int lineNum = startPos.getLineNumber();
int linePos = startPos.getIndexInLine();
auto lineNum = startPos.getLineNumber();
auto linePos = startPos.getIndexInLine();
const int totalLines = getDocument().getNumLines();
const String searchText (getSearchString());
const bool caseSensitive = isCaseSensitiveSearch();
auto totalLines = getDocument().getNumLines();
auto searchText = getSearchString();
auto caseSensitive = isCaseSensitiveSearch();
for (int linesToSearch = totalLines; --linesToSearch >= 0;)
for (auto linesToSearch = totalLines; --linesToSearch >= 0;)
{
String line (getDocument().getLine (lineNum));
auto line = getDocument().getLine (lineNum);
int index;
if (forwards)
@@ -553,13 +550,13 @@ void CppCodeEditorComponent::handleReturnKey()
{
GenericCodeEditorComponent::handleReturnKey();
CodeDocument::Position pos (getCaretPos());
auto pos = getCaretPos();
String blockIndent, lastLineIndent;
CodeHelpers::getIndentForCurrentBlock (pos, getTabString (getTabSize()), blockIndent, lastLineIndent);
const String remainderOfBrokenLine (pos.getLineText());
const int numLeadingWSChars = CodeHelpers::getLeadingWhitespace (remainderOfBrokenLine).length();
auto remainderOfBrokenLine = pos.getLineText();
auto numLeadingWSChars = CodeHelpers::getLeadingWhitespace (remainderOfBrokenLine).length();
if (numLeadingWSChars > 0)
getDocument().deleteSection (pos, pos.movedBy (numLeadingWSChars));
@@ -569,8 +566,8 @@ void CppCodeEditorComponent::handleReturnKey()
else
insertTextAtCaret (lastLineIndent);
const String previousLine (pos.movedByLines (-1).getLineText());
const String trimmedPreviousLine (previousLine.trim());
auto previousLine = pos.movedByLines (-1).getLineText();
auto trimmedPreviousLine = previousLine.trim();
if ((trimmedPreviousLine.startsWith ("if ")
|| trimmedPreviousLine.startsWith ("if(")
@@ -588,7 +585,7 @@ void CppCodeEditorComponent::insertTextAtCaret (const String& newText)
{
if (getHighlightedRegion().isEmpty())
{
const CodeDocument::Position pos (getCaretPos());
auto pos = getCaretPos();
if ((newText == "{" || newText == "}")
&& pos.getLineNumber() > 0
@@ -640,7 +637,7 @@ void CppCodeEditorComponent::insertComponentClass()
while (aw.runModalLoop() != 0)
{
const String className (aw.getTextEditorContents (classNameField).trim());
auto className = aw.getTextEditorContents (classNameField).trim();
if (className == CodeHelpers::makeValidIdentifier (className, false, true, false))
{


+ 1
- 1
extras/Projucer/Source/CodeEditor/jucer_SourceCodeEditor.h View File

@@ -71,7 +71,7 @@ public:
{
while (*extensions != nullptr)
{
const File f (file.withFileExtension (*extensions++));
auto f = file.withFileExtension (*extensions++);
if (f.existsAsFile())
return f;


Loading…
Cancel
Save