示例#1
0
long ShortcutList::onApplyChanges(FXObject*o,FXSelector sel,void*p)
{
    FXHotKey hk=sce->getChord();
    FXIconItem*item=acclist->getItem(acclist->getCurrentItem());
    MenuSpec*spec=(MenuSpec*)item->getData();
    if (hk) {
        if (Verify(hk,spec) && ConfirmOverwrite(hk,spec)) {
            ApplyShortcut(hk,spec);
        }
    } else {
        if (DeleteShortcut(spec)) {
            apply_btn->disable();
        }
    }
    return 1;
}
示例#2
0
void GridWindow::on_action_file_export()
{
	Gtk::FileChooserDialog dialog("Export empty grid...", Gtk::FILE_CHOOSER_ACTION_SAVE);
	dialog.set_transient_for(*this);

	//Add response buttons the the dialog:
	dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
	dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);

	//Add filters, so that only certain file types can be selected:
	Gtk::FileFilter filter_png;
	filter_png.set_name("PNG files");
	filter_png.add_mime_type("image/png");
	dialog.add_filter(filter_png);

	Gtk::FileFilter filter_jpeg;
	filter_jpeg.set_name("JPEG files");
	filter_jpeg.add_mime_type("image/jpeg");
	dialog.add_filter(filter_jpeg);
	
	Gtk::FileFilter filter_bmp;
	filter_bmp.set_name("BMP files");
	filter_bmp.add_mime_type("image/bmp");
	dialog.add_filter(filter_bmp);
	
	Gtk::FileFilter filter_html;
	filter_html.set_name("HTML files");
	filter_html.add_mime_type("text/html");
	dialog.add_filter(filter_html);

  	bool error = true;
  	while (error)
  	{
  		error = false;
		//Show the dialog and wait for a user response:
		int result = dialog.run();
	
		//Handle the response:
		switch(result)
		{
			case Gtk::RESPONSE_OK:
			{
				Glib::ustring filename = dialog.get_filename();
				if (ConfirmOverwrite(filename.c_str()))
				{
					const Gtk::FileFilter *filter = dialog.get_filter();
					bool success = true;
					FileType t = GetTypeFromFilename(filename.c_str());
					switch (t)
					{
						case PNG:
							success = mGridView.SavePNG(filename.c_str()); break;
						case JPEG:
							success = mGridView.SaveJPEG(filename.c_str()); break;
						case BMP:
							success = mGridView.SaveBMP(filename.c_str()); break;
						case HTML:
							success = mGridView.SaveHTML(filename.c_str()); break;
						default:
							if (filter == &filter_png)
								success = mGridView.SavePNG(filename.c_str());
							else if (filter == &filter_jpeg)
								success = mGridView.SaveJPEG(filename.c_str());
							else if (filter == &filter_bmp)
								success = mGridView.SaveBMP(filename.c_str());
							else if (filter == &filter_html)
								success = mGridView.SaveHTML(filename.c_str());
							break;
					}
					if (!success)
					{
						Gtk::MessageDialog dialog(*this, "Error saving the file!", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK);
						dialog.run();
						error = true;
					}
				}
				break;
			}
			case Gtk::RESPONSE_CANCEL:
			default:
				break;
		}
  	}
}
示例#3
0
文件: tarcmd.cpp 项目: dzzie/libs
bool extract_file(CTar32CmdInfo &cmdinfo, CTar32 *pTarfile, const char *fname,std::vector<char> &buffer)
{
	CTar32FileStatus &stat = pTarfile->m_currentfile_status;
	std::string fname2 = fname;

	EXTRACTINGINFOEX extractinfo;
	EXTRACTINGINFOEX64 exinfo64;
	MakeExtractingInfo(pTarfile,fname2.c_str(),extractinfo,exinfo64);
	{
		int ret = SendArcMessage(cmdinfo, ARCEXTRACT_BEGIN, &extractinfo,&exinfo64);
		if(ret){throw CTar32Exception("Cancel button was pushed.",ERROR_USER_CANCEL);}
		fname2 = extractinfo.exinfo.szDestFileName;
	}

	//上書き確認
	if(cmdinfo.b_confirm_overwrite){
		switch(ConfirmOverwrite(cmdinfo, exinfo64)){
		case -1://cancel(abort)
			throw CTar32Exception("Cancel button was pushed.",ERROR_USER_CANCEL);
			break;
		case 1:	//yes to all
			cmdinfo.b_confirm_overwrite=false;
			break;
		}
	}

	size64 filesize = pTarfile->m_currentfile_status.original_size;

	CTar32InternalFile file; file.open(pTarfile);


	//std::ofstream fs_w;
	fast_fstream fs_w;
	if(!cmdinfo.b_print){
		mkdir_recursive(get_dirname(fname2.c_str()).c_str());
		fs_w.open(fname2.c_str(), std::ios::out|std::ios::binary);
		if(fs_w.fail()){return false;}
	}

	size64 readsize = 0;
	//static std::vector<char> buf;
	//const int bufsize=512*1024;
	//buf.resize(bufsize);
	const size_t bufsize=buffer.size();
	while(filesize ==-1 || readsize<filesize){
		size64 nextreadsize;
		if(filesize == -1){ // case ".gz",".Z",".bz2"
			//nextreadsize = sizeof(buf);
			nextreadsize=bufsize;
		}else{
			size64 nextreadsize64 = filesize-readsize;
			if(nextreadsize64 > bufsize){nextreadsize64 = bufsize;}
			nextreadsize = nextreadsize64;
			if(nextreadsize==0){
				Sleep(0);
			}
			// nextreadsize = (int)min(filesize-readsize, sizeof(buf));
		}
		if(nextreadsize==0){
			Sleep(0);
		}
		size64 n = file.read(&buffer[0],nextreadsize);
		readsize += n;
		if(cmdinfo.b_print){
			cmdinfo.output.write(&buffer[0],(size_t)n);	//TODO:size lost
		}else{
			fs_w.write(&buffer[0],n);
			if(fs_w.fail()){return false;}
		}
		if(n != nextreadsize){
			if(filesize == -1){ // case .gz/.Z/.bz2"
				break;
			}else{
				return false;
			}
		}
//		if(cmdinfo.hTar32StatusDialog){
			extractinfo.exinfo.dwWriteSize = (DWORD)readsize;
			exinfo64.exinfo.dwWriteSize = (DWORD)readsize;
			exinfo64.llWriteSize = readsize;
			int ret = SendArcMessage(cmdinfo, ARCEXTRACT_INPROCESS, &extractinfo,&exinfo64);
			if(ret){throw CTar32Exception("Cancel button was pushed.",ERROR_USER_CANCEL);}
//		}
	}
	if(!cmdinfo.b_print){
		fs_w.close();
		struct _utimbuf ut;
		ut.actime = (stat.atime ? stat.atime : time(NULL));
		ut.modtime = (stat.mtime ? stat.mtime : time(NULL));
		int ret;
		ret = _utime(fname2.c_str(), &ut);
		ret = _chmod(fname2.c_str(), stat.mode);
	}
//	if(cmdinfo.hTar32StatusDialog){
		extractinfo.exinfo.dwWriteSize = (DWORD)readsize;
		exinfo64.exinfo.dwWriteSize = (DWORD)readsize;
		exinfo64.llWriteSize = readsize;
		int ret = SendArcMessage(cmdinfo, 6, &extractinfo,&exinfo64);
		if(ret){throw CTar32Exception("Cancel button was pushed.",ERROR_USER_CANCEL);}
//	}
	return true;
}
示例#4
0
void GridWindow::on_action_file_saveas()
{
	Gtk::FileChooserDialog dialog("Save As", Gtk::FILE_CHOOSER_ACTION_SAVE);
	dialog.set_transient_for(*this);

	//Add response buttons the the dialog:
	dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
	dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);

	//Add filters, so that only certain file types can be selected:
	Gtk::FileFilter filter_any;
	filter_any.set_name("Any files");
	filter_any.add_pattern("*");
	dialog.add_filter(filter_any);

	Gtk::FileFilter filter_xml;
	filter_xml.set_name("XML files");
	filter_xml.add_mime_type("text/xml");
	dialog.add_filter(filter_xml);

	Gtk::FileFilter filter_puz;
	filter_puz.set_name(".PUZ files");
	dialog.add_filter(filter_puz);
  
  	bool error = true;
  	while (error)
  	{
  		error = false;
		//Show the dialog and wait for a user response:
		int result = dialog.run();
	
		//Handle the response:
		switch(result)
		{
			case Gtk::RESPONSE_OK:
			{
				mFilename = dialog.get_filename();
				if (ConfirmOverwrite(mFilename.c_str()))
				{
					const Gtk::FileFilter *filter = dialog.get_filter();
					bool success = true;
					FileType t = GetTypeFromFilename(mFilename.c_str());
					GetTitleFromFilename();
					switch (t)
					{
						case NONE:
							success = mGrid.Save(mFilename.c_str()); break;
						case PUZ:
							success = mGrid.SavePUZ(mFilename.c_str()); break;
						case XML:
							success = mGrid.SaveXML(mFilename.c_str()); break;
						default:
							if (filter == &filter_puz)
								success = mGrid.SavePUZ(mFilename.c_str());
							else if (filter == &filter_xml)
								success = mGrid.SaveXML(mFilename.c_str());
							else
								success = mGrid.Save(mFilename.c_str());
							break;
					}				
					if (!success)
					{
						Gtk::MessageDialog dialog(*this, "Error saving the file!", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK);
						dialog.run();
						error = true;
					}
				}
				break;
			}
			case Gtk::RESPONSE_CANCEL:
			default:
				break;
		}
  	}
}