logic: Codeview Snippet order
Sorting the Snippets in. the Codeview. Active Token first then declaration, filename and extension
This commit is contained in:
@@ -1,12 +1,56 @@
|
||||
#include "component/view/CodeView.h"
|
||||
|
||||
#include "component/controller/CodeController.h"
|
||||
#include "utility/FileSystem.h"
|
||||
|
||||
CodeView::CodeSnippetParams::CodeSnippetParams()
|
||||
: locationFile("")
|
||||
: startLineNumber(0)
|
||||
, endLineNumber(0)
|
||||
, lineCount(0)
|
||||
, locationFile("")
|
||||
, isActive(false)
|
||||
, isDeclaration(false)
|
||||
{
|
||||
}
|
||||
|
||||
bool CodeView::CodeSnippetParams::sort( CodeSnippetParams a, CodeSnippetParams b )
|
||||
{
|
||||
// sort active snippet first
|
||||
if(a.isActive)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(b.isActive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// sort declarations
|
||||
if(a.isDeclaration && !b.isDeclaration)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (!a.isDeclaration && b.isDeclaration)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// first header
|
||||
if( FileSystem::filePathWithoutExtension(a.locationFile.getFilePath())
|
||||
== FileSystem::filePathWithoutExtension(b.locationFile.getFilePath()) )
|
||||
{
|
||||
return FileSystem::extension(a.locationFile.getFilePath())
|
||||
> FileSystem::extension(b.locationFile.getFilePath());
|
||||
}
|
||||
// alphabetical filepath without extension
|
||||
else
|
||||
{
|
||||
return FileSystem::filePathWithoutExtension(a.locationFile.getFilePath())
|
||||
< FileSystem::filePathWithoutExtension(b.locationFile.getFilePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CodeView::CodeView(ViewLayout* viewLayout)
|
||||
: View(viewLayout, Vec2i(100, 100))
|
||||
{
|
||||
|
||||
@@ -19,8 +19,14 @@ public:
|
||||
uint lineCount;
|
||||
|
||||
std::string code;
|
||||
TokenLocationFile locationFile;
|
||||
std::vector<Id> activeTokenIds;
|
||||
|
||||
TokenLocationFile locationFile;
|
||||
|
||||
bool isActive;
|
||||
bool isDeclaration;
|
||||
|
||||
//comparefunctions for snippetsorting
|
||||
static bool sort(CodeSnippetParams a, CodeSnippetParams b);
|
||||
};
|
||||
|
||||
CodeView(ViewLayout* viewLayout);
|
||||
@@ -31,6 +37,7 @@ public:
|
||||
virtual void showCodeFile(const CodeSnippetParams& params) = 0;
|
||||
virtual void addCodeSnippet(const CodeSnippetParams& params) = 0;
|
||||
virtual void clearCodeSnippets() = 0;
|
||||
virtual void setActiveTokenIds(std::vector<Id> ids) = 0;
|
||||
|
||||
private:
|
||||
CodeController* getController();
|
||||
|
||||
Reference in New Issue
Block a user