-
-
Save mengu/721ffc0b7463781da78a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Runs when a mouse click event occurs on the file browser tree. | |
* | |
* @param GdkEventButton* event button | |
* @param Widget gtk widget. | |
* | |
*/ | |
bool showButtonPress(GdkEventButton* button, Widget widget) | |
{ | |
// implement double click. | |
if (button.type == EventType.DOUBLE_BUTTON_PRESS) | |
{ | |
TreeIter selectedIter = this.getSelectedIter(); | |
string filePath = selectedIter.getValueString(1); | |
if (isdir(filePath)) | |
{ | |
if (!this.rowExpanded(selectedIter.getTreePath)) | |
{ | |
this.expandRow(selectedIter.getTreePath, 0); | |
} | |
else | |
{ | |
this.collapseRow(selectedIter.getTreePath); | |
} | |
return false; | |
} | |
string[] splittedFileName = selectedIter.getValueString(0).split("."); | |
string language; | |
if (splittedFileName.length > 1) | |
{ | |
foreach (langKey; sourceFiles.keys) | |
{ | |
if (splittedFileName[1] == langKey) | |
{ | |
language = sourceFiles[langKey]; | |
} | |
} | |
} | |
ScrolledWindow sc = new ScrolledWindow(); | |
SourceView newSourceView = new SourceView(); | |
newSourceView.setTabWidth(4); | |
newSourceView.setInsertSpacesInsteadOfTabs(true); | |
newSourceView.modifyFont("Monaco", 10); | |
SourceBuffer sourceBuffer = newSourceView.getBuffer(); | |
SourceLanguageManager slm = new SourceLanguageManager(); | |
SourceLanguage dLang = slm.getLanguage(language); | |
SourceStyleSchemeManager sssm = new SourceStyleSchemeManager(); | |
string[] styleSearchPaths = ["/home/mengu/projects/pearl-studio/styles"]; | |
sssm.setSearchPath(styleSearchPaths); | |
SourceStyleScheme sCheme = sssm.getScheme("railscasts"); | |
sourceBuffer.setStyleScheme(sCheme); | |
if ( dLang !is null ) | |
{ | |
sourceBuffer.setLanguage(dLang); | |
sourceBuffer.setHighlightSyntax(true); | |
} | |
newSourceView.setShowLineNumbers(true); | |
File newFile = File(filePath, "rb"); | |
string fileContent; | |
while (!newFile.eof()) | |
{ | |
fileContent ~= newFile.readln(); | |
} | |
sourceBuffer.setText(fileContent); | |
newSourceView.setBuffer(sourceBuffer); | |
sc.add(newSourceView); | |
// create tab label. | |
HBox hBox = new HBox(0, 0); | |
Label label = new Label(selectedIter.getValueString(0)); | |
Button closeButton = new Button(); | |
closeButton.addOnClicked(delegate void(Button btn) { | |
int pageNum = this.filesTab.pageNum(cast(Widget)btn.getData("tabIndex")); | |
this.filesTab.removePage(pageNum); | |
}); | |
Image closeIcon = new Image(); | |
closeIcon.setFromStock(StockDesc[7], GtkIconSize.MENU); | |
closeButton.setImage(closeIcon); | |
closeButton.setRelief(GtkReliefStyle.NONE); | |
// close icon and label. | |
hBox.packStart(closeButton, true, true, 0); | |
hBox.packEnd(label, false, false, 0); | |
hBox.showAll(); | |
// end tab label. | |
int newTabIndex = this.filesTab.appendPage(sc, hBox); | |
closeButton.setData("tabIndex", cast(void*)sc); | |
this.filesTab.showAll(); | |
this.filesTab.setCurrentPage(newTabIndex); | |
} | |
// implement right click event. | |
if (button.button == 3) | |
{ | |
Menu rcMenu = new Menu(); | |
MenuItem rcMenuItem1 = new MenuItem("New Folder"); | |
rcMenuItem1.addOnActivate(delegate void(MenuItem menuItem) | |
{ | |
}); | |
MenuItem rcMenuItem2 = new MenuItem("New File"); | |
rcMenuItem2.addOnActivate(delegate void(MenuItem menuItem) | |
{ | |
TreeIter selectedFileBrowserIter = this.getSelectedIter(); | |
if (selectedFileBrowserIter !is null) | |
{ | |
string filePath = this.getTreeIterFilePath(selectedFileBrowserIter); | |
if (filePath !is null) | |
{ | |
if (isdir(filePath)) | |
{ | |
TreeIter newTreeIter = this.fileTreeStore.createIter(selectedFileBrowserIter); | |
this.fileTreeStore.set(newTreeIter, [0], ["untitled"]); | |
} | |
} | |
writeln(filePath); | |
} | |
}); | |
rcMenu.add(rcMenuItem1); | |
rcMenu.add(rcMenuItem2); | |
rcMenu.showAll(); | |
rcMenu.popup(button.type, button.time); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment