⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formmain.h

📁 一个可视化的编译器
💻 H
📖 第 1 页 / 共 5 页
字号:
			file->Close();	
			//ui update
			this->tabControlCode->TabPages[0]->Text = currentFileName;

		}
	}

private: 
	System::Void saveAsToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
		this->saveFileDlg->Title = "Save To...";
		this->saveFileDlg->Filter = "*.lls(leastL Source)|*.lls|*.*(All Files)|*.*";
		this->saveFileDlg->ShowDialog();
	}

private: 
	System::Void FormMain_Load(System::Object^  sender, System::EventArgs^  e) {
		this->isChanged = false;
		this->isSavedToDisk = false;
		currentFilePath = gcnew String("NONE");
		currentFileName = gcnew String("Untitled");

		//Init UI
		//Tree View:
		array <String ^> ^logicDrives =System::IO::Directory::GetLogicalDrives();
		TreeNode ^root = gcnew TreeNode();
		ImageList ^imgList =gcnew ImageList();
		for (int i = 0;i< logicDrives->Length ;i++)
		{
			if (logicDrives[i]!="A:\\" && logicDrives[i]!="B:\\" ) {
				TreeNode ^drivesNode= gcnew TreeNode(logicDrives[i]);
				drivesNode->ImageIndex = 0;
				drivesNode->SelectedImageIndex = 0;
				treeViewFile->Nodes->Add(drivesNode);
				SetSubFolderNode(drivesNode);
			}
		}
		//Load Options
		options = gcnew IDEOptions();
		interpreter = gcnew Interpreter();
		options->Load();
		this->Tag = options;
		Drawing::Font ^nFont = gcnew Drawing::Font(options->GetEditorFontName(), options->GetEditorFontSize() );
		codeTextBox->SelectAll();
		codeTextBox->SelectionFont = nFont;
	}

private: 
	System::Void saveFileDlg_FileOk(System::Object^  sender, System::ComponentModel::CancelEventArgs^  e) {
		//write to file 
		if ( File::Exists(saveFileDlg->FileName) )
		{
			File::Delete(saveFileDlg->FileName);
		}
		FileStream ^ file = File::Create(saveFileDlg->FileName);
		array<Byte>^info = (gcnew UTF8Encoding( true ))->GetBytes(codeTextBox->Text);
		file->Write( info, 0, info->Length );
		file->Close();
		
		isChanged = false;
		isSavedToDisk = true;
		//ui update
		currentFilePath = saveFileDlg->FileName;
		array <String^> ^aPathList = saveFileDlg->FileName->Split('\\');
		currentFileName = aPathList[aPathList->Length - 1];
		this->tabControlCode->TabPages[0]->Text = currentFileName;
	}

private: 
	System::Void codeTextBox_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		RichTextBox ^ RTB =  (RichTextBox^)sender;
		if (!isChanged) {
			((TabPage^)(RTB->Parent))->Text = currentFileName + "*";
			isChanged = true;
		}

	}

private: 
	System::Void newToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
		this->codeTextBox->Text = "";
		this->saveFileDlg->Title = "New File Save To...";
		this->saveFileDlg->Filter = "*.lls(leastL Source)|*.lls|*.*(All Files)|*.*";
		this->saveFileDlg->ShowDialog();
	}
private:
	System::Void exitToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
		this->Close();
	}

private: 
	System::Void undoToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
		this->codeTextBox->Undo();
	}
private: 
	System::Void redoToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
		this->codeTextBox->Redo();
	}
private: 
	System::Void cutToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
		this->codeTextBox->Cut();	
	}
private: 
	System::Void copyToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
		this->codeTextBox->Copy();	
	}
private: 
	System::Void pasteToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
		this->codeTextBox->Paste();
	}

private: 
	System::Void deleteToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
		this->codeTextBox->SelectedText="";	
	}
	
private:
	System::Void tabControlBtm_MouseClick(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
		static bool status = false;
		static int lastSelectedIndex = tabControlBtm->SelectedIndex; 
		if (lastSelectedIndex == tabControlBtm->SelectedIndex) //click same tab
		{
			if (status) //fold
			{
				while (splitContainerH->SplitterDistance 
					< splitContainerH->Height 
						- tabControlBtm->ItemSize.Height
						- splitContainerH->SplitterWidth * 3)
				{
					splitContainerH->SplitterDistance += 15;
					this->Update();
				} 
				
			} 
			else //expand
			{
				while (splitContainerH->Height - splitContainerH->SplitterDistance <=  100){
					splitContainerH->SplitterDistance -= 15;
				} 
			}
		}
		else //click different tab, expand
		{
			while (splitContainerH->Height - splitContainerH->SplitterDistance <=  100){
				splitContainerH->SplitterDistance -= 15;
			} 
		}
		status = !status;
		lastSelectedIndex = tabControlBtm->SelectedIndex; 
	}


private: 
	System::Void aboutMeToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
		FormAbout ^formAbout = gcnew FormAbout();
		formAbout->ShowDialog();
	}


private: 
	System::Void treeViewFile_AfterExpand(System::Object^  sender, System::Windows::Forms::TreeViewEventArgs^  e) {
		for (int i = 0; i < e->Node->Nodes->Count; ++i) {
			SetSubFolderNode(e->Node->Nodes[i]);
		}
	}


private: 
	System::Void treeViewFile_AfterSelect(System::Object^  sender, System::Windows::Forms::TreeViewEventArgs^  e) {
		if (!treeViewFile->SelectedNode)
			return;
		DirectoryInfo ^curDir = gcnew DirectoryInfo(treeViewFile->SelectedNode->FullPath);
		array <IO::FileInfo ^> ^subFiles;
		listViewFile->Items->Clear();
		try {
			subFiles = curDir->GetFiles();
			for (int i = 0; i < subFiles->Length; ++i) {
				if ("*.*" == textBoxFileFilter->Text->Trim()->ToLower()
					|| subFiles[i]->Extension->ToLower() == textBoxFileFilter->Text->Substring(1)->Trim()->ToLower())
				{
					ListViewItem ^ fileItem = gcnew ListViewItem();
					fileItem->Text = subFiles[i]->ToString();
					fileItem->ImageIndex = 3;
					fileItem->StateImageIndex = 3;
					listViewFile->Items->Add(fileItem);
				}
			}
		}catch(...){}
	}

private: 
	System::Void listViewFile_DoubleClick(System::Object^  sender, System::EventArgs^  e) {
		String ^selectFilePath = treeViewFile->SelectedNode->FullPath 
			+ "\\"
			+ listViewFile->SelectedItems[0]->SubItems[0]->Text;
		
		codeTextBox->Text = "";
		FileStream ^ file = File::OpenRead(selectFilePath);
		array<Byte> ^ codeData = gcnew array<Byte>(1024);
		UTF8Encoding ^ temp = gcnew UTF8Encoding( true );
		while ( file->Read( codeData, 0, codeData->Length ) > 0 )
		{
			this->codeTextBox->Text += temp->GetString(codeData);
		}
		file->Close();

		currentFilePath = selectFilePath;
		array <String^> ^aPathList = selectFilePath->Split('\\');
		currentFileName = aPathList[aPathList->Length - 1];
		this->tabControlCode->TabPages[0]->Text = currentFileName;

		isChanged = false;
		isSavedToDisk = true;
	}

private: 
	System::Void runToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
		saveToolStripMenuItem_Click(sender, e);

		RunInterpreter(currentFilePath, 0);
		textBoxOutput->Clear();
		String ^buf = gcnew String("");
		buf = interpreter->Read();
		textBoxOutput->AppendText(buf + Environment::NewLine);
		if (-1 == textBoxOutput->Text->IndexOf(" 0个错误")) {
			ParseErrors(textBoxOutput->Text);
			return;
		}
		RunInterpreter(currentFilePath, 1);	
	}

private: 
	System::Void findAndReplaceToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
		FormFindNReplace ^formFNR = gcnew FormFindNReplace();
		formFNR->Show(this);
		formFNR->Focus();
	}

private: 
	System::Void toolStripComboBoxFind_KeyPress(System::Object^  sender, System::Windows::Forms::KeyPressEventArgs^  e) {
		if (e->KeyChar == '\n' && !String::IsNullOrEmpty(this->toolStripComboBoxFind->Text))
		{
			this->QuickFind(this->toolStripComboBoxFind->Text);
		}	
	}

private: 
	System::Void toolStripButtonFind_Cick(System::Object^  sender, System::EventArgs^  e) {
		if (!String::IsNullOrEmpty(this->toolStripComboBoxFind->Text))
		{
			this->QuickFind(this->toolStripComboBoxFind->Text);
		}	
	}
private: 
	System::Void setIDEToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
		FormOptions ^formOptions = gcnew FormOptions();
		formOptions->ShowDialog(this);
		options->Load();
	}

private:
	System::Void listBoxErrors_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
		RegularExpressions::Regex ^r = gcnew Regex(".*\\..*\\((\\d*)\\)");//匹配行号
		Match ^ret = r->Match(listBoxErrors->Text);
		if (ret->Success) {
			int lineNum = int::Parse(ret->Groups[1]->Value);
			codeTextBox->SelectionStart = 0;
			codeTextBox->Focus();
			for (int i = 0; i < lineNum - 1; ++i)
				Windows::Forms::SendKeys::Send("{DOWN}");
		}
	}
private: 
	System::Void textBoxOutput_KeyUp(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) {
		if (interpreter->IsRunning()) {

			interpreter->Write(e->KeyValue);
			if (e->KeyValue == 13) 
				interpreter->Write(10);

			System::Threading::Thread::Sleep(1500);
			if (-1 != interpreter->Peek()) {
				String ^buf = gcnew String("");
				buf = interpreter->Read();
				textBoxOutput->AppendText(buf);
			}
		}

	}

private: 
	System::Void compileToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
		saveToolStripMenuItem_Click(sender, e);
		RunInterpreter(currentFilePath, 0);	
		textBoxOutput->Clear();
		String ^buf = gcnew String("");
		buf = interpreter->Read();
		textBoxOutput->AppendText(buf + Environment::NewLine);
		if (-1 == textBoxOutput->Text->IndexOf(" 0个错误")) {
			ParseErrors(textBoxOutput->Text);
		}
	}
};
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -