0 Star 2 Fork 1

Cadaqs/XStudio

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
TextDetail.xcsm 10.55 KB
一键复制 编辑 原始数据 按行查看 历史
Cadaqs 提交于 2021-04-10 02:39 . 1.0.18.10130
//xlang Source, Name:TextDetail.xcsm
//Date: Sun Sep 01:45:35 2018
class TextDetail : QDialog {
String title = "详细信息";
String text;
QScintilla _sci;
static QRect rect = nilptr;
public interface closeListener{
void onCreate();
void onClose(String text, bool updated);
};
closeListener cl_lis ;
public TextDetail(closeListener l){
cl_lis = l;
}
public TextDetail(){
}
public void syntaxForOutput(){
if (Setting.isDarkStyle()){
syntaxForOutputDark();
return ;
}
_sci.sendEditor(QScintilla.SCI_SETCODEPAGE, QScintilla.SC_CP_UTF8);
_sci.setWrap(true);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_DEFAULT, 0xffffffff);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_DEFAULT, 0xff222827);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, 75, 0xff222827);
_sci.sendEditor(QScintilla.SCI_STYLECLEARALL, 0, 0);
//_sci.sendEditor(QScintilla.STYLE_LINENUMBER, 1, 0);
_sci.sendEditor(QScintilla.SCI_STYLESETFONT, QScintilla.STYLE_DEFAULT,Setting.getEditorFont());
_sci.sendEditor(QScintilla.SCI_STYLESETSIZEFRACTIONAL, QScintilla.STYLE_DEFAULT,Setting.getEditorFontSize());
_sci.sendEditor(QScintilla.SCI_STYLECLEARALL, 0, 0);
_sci.sendEditor(QScintilla.SCI_SETEOLMODE, 1, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, 0, QScintilla.SC_MARGIN_NUMBER);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 0, 40);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 1, 10);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 2, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 3, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 4, 0);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_LINENUMBER, 0xffefefef);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_LINENUMBER, 0xffaf912b);
_sci.sendEditor(QScintilla.SCI_SETMARGINLEFT, 0, 0);
_sci.sendEditor(QScintilla.SCI_SETCARETFORE,0xff000000,0);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEVISIBLE, 1);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEBACK, 0xffefefef);
_sci.sendEditor(QScintilla.SCI_SETTABWIDTH, 4);
}
public void syntaxForOutputDark(){
_sci.sendEditor(QScintilla.SCI_SETCODEPAGE, QScintilla.SC_CP_UTF8);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_DEFAULT, 0xff262525);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_DEFAULT, 0xffefefef);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, 75, 0xffefefef);
_sci.sendEditor(QScintilla.SCI_STYLECLEARALL, 0, 0);
//_sci.sendEditor(QScintilla.STYLE_LINENUMBER, 1, 0);
_sci.sendEditor(QScintilla.SCI_STYLESETFONT, QScintilla.STYLE_DEFAULT,Setting.getEditorFont());
_sci.sendEditor(QScintilla.SCI_STYLESETSIZEFRACTIONAL, QScintilla.STYLE_DEFAULT,Setting.getEditorFontSize());
_sci.sendEditor(QScintilla.SCI_STYLECLEARALL, 0, 0);
//_sci.sendEditor(QScintilla.SCI_SETREADONLY, 1);
//C++语法解析
//_sci.sendEditor(QScintilla.SCI_SETLEXER, QScintilla.SCLEX_CPP, 0);
//_sci.sendEditor(QScintilla.SCI_SETKEYWORDS, 0, szKeywords1);//设置关键字
//_sci.sendEditor(QScintilla.SCI_SETKEYWORDS, 1, szKeywords2);//设置关键字
// 下面设置各种语法元素风格
_sci.sendEditor(QScintilla.SCI_SETEOLMODE, 1, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, 0, QScintilla.SC_MARGIN_NUMBER);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 0, 40);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 1, 10);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 2, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 3, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 4, 0);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_LINENUMBER, 0xff262525);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_LINENUMBER, 0xff666666);
_sci.sendEditor(QScintilla.SCI_SETMARGINLEFT, 0, 0);
_sci.sendEditor(QScintilla.SCI_SETCARETFORE,0xffffffff,0);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEVISIBLE, 1);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEBACK, 0xff202020);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENT, 0xff666666);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTLINE, 0xff666666);
}
public bool onClose(){
rect = new QRect(x(), y(), width(), height());
if (cl_lis != nilptr){
String update_txt = _sci.getText();
cl_lis.onClose(update_txt, text.equals(update_txt) == false);
}
return true;
}
public bool create(String caption,@NotNilptr String str, QWidget parent, bool modal){
title = caption;
text = str;
if (parent == nilptr){
parent = XWorkspace.workspace;
}
if (super.create(XWorkspace.workspace)){
_sci = new QScintilla();
if (_sci.create(this)){
syntaxForOutput();
_sci.sendEditor(QScintilla.SCI_SETEOLMODE, QScintilla.SC_EOL_LF, 0);
setOnLayoutEventListener(new onLayoutEventListener(){
void onResize(QObject obj, int w, int h, int oldw, int oldh)override {
if (_sci != nilptr){
_sci.resize(w, h );
}
}
});
//setWindowFlags(CustomizeWindowHint | WindowMinMaxButtonsHint | WindowCloseButtonHint);
setWindowFlags(Constant.CustomizeWindowHint | Constant.WindowCloseButtonHint | Constant.Dialog | Constant.WindowTitleHint);
setWindowTitle(title);
_sci.setText(str);
if (modal){
setModal(true);
}
resize(400, 300);
if (cl_lis == nilptr){
_sci.setReadOnly(true);
}else{
cl_lis.onCreate();
}
if (rect != nilptr){
move(rect.left,rect.top);
resize(rect.right,rect.bottom);
}
createContextMenu();
_contextMenu.enableAll(true);
show();
setOnActivateListener(new onActivateListener(){
void onWindowActivate(@NotNilptr QObject obj){
((QWidget)obj).setOpacity(1.0);
}
void onWindowDeactivate(QObject obj){
((QWidget)obj).setOpacity(0.6);
}
});
return true;
}
}
return false;
}
ContextMenu _contextMenu = new ContextMenu();
public void createContextMenu(){
static String _default_folder = "", _default_openpath = "", _default_savepath = "";
onEventListener menuListener = new onEventListener(){
String toRelativePath(String ref, String path, bool cov){
bool breslash = false;
if ((_system_.getPlatformId() == _system_.PLATFORM_WINDOWS) && Setting.isUnixPath()){
breslash = true;
}
path = String.formatPath(path, breslash);
if (cov == false || ref == nilptr){
return path;
}
return path.toRelativePath(ref,false,true);
}
void onTrigger(QObject obj) override{
if (obj == _contextMenu.actions[0]){
String path = QFileDialog.getFolderPath("浏览文件夹","",_default_folder, TextDetail.this);
if (path != nilptr && path.length() > 0){
bool breal = false;
String pjdir = XWorkspace.workspace.currentProjectDir();
if (pjdir != nilptr && QMessageBox.Question("提示","是否转换为当前项目的相对路径?",QMessageBox.Yes | QMessageBox.No,QMessageBox.Yes) == QMessageBox.Yes){
breal = true;
}
_default_folder = path;
_sci.insertText(_sci.currentPosition(),toRelativePath(pjdir, path, breal));
}
}else
if (obj == _contextMenu.actions[2]){
String [] path = QFileDialog.getOpenFileNames("浏览文件", _default_openpath, "*",TextDetail.this);
if (path != nilptr){
bool breal = false;
String pjdir = XWorkspace.workspace.currentProjectDir();
if (pjdir != nilptr && QMessageBox.Question("提示","是否转换为当前项目的相对路径?",QMessageBox.Yes | QMessageBox.No,QMessageBox.Yes) == QMessageBox.Yes){
breal = true;
}
for (int i =0; i < path.length; i++){
if (i == 0){
_default_openpath = path[i].findVolumePath();
}
_sci.insertText(_sci.currentPosition(),toRelativePath(pjdir, path[i], breal) + "\n");
}
}
}else
if (obj == _contextMenu.actions[3]){
String path = QFileDialog.getSaveFileName("选择保存位置",_default_savepath,"*",TextDetail.this);
if (path != nilptr && path.length() > 0){
bool breal = false;
String pjdir = XWorkspace.workspace.currentProjectDir();
if (pjdir != nilptr && QMessageBox.Question("提示","是否转换为当前项目的相对路径?",QMessageBox.Yes | QMessageBox.No,QMessageBox.Yes) == QMessageBox.Yes){
breal = true;
}
_default_savepath = path;
_sci.insertText(_sci.currentPosition(),toRelativePath(pjdir, path, breal));
}
}else
if (obj == _contextMenu.actions[5]){
_sci.Copy();
}else
if (obj == _contextMenu.actions[6]){
_sci.Paste();
}else
if (obj == _contextMenu.actions[8]){
TextDetail.this.close();
}
}
};
String []acts = {"浏览文件夹", "-", "浏览文件", "选择保存位置", "-", "复制", "粘贴", "-", "关闭"};
_contextMenu.create(_sci, acts, menuListener, nilptr);
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/ixlang/XStudio.git
git@gitee.com:ixlang/XStudio.git
ixlang
XStudio
XStudio
master

搜索帮助