internal static IDelegateCommand CopyASCIIToCBoardCommand(IHexDataContext hexDataContext) { var copyASCIIToCBoardCommand = CommandFactory.CreateDelegateCommand( () => { if (hexDataContext.SelectionStart == -1 || hexDataContext.SelectionLength == -1) //若需剪切数据大于4GB { return; } if (hexDataContext.SelectionLength > MaxCopyToClipBoardSize) { MsgBoxService.Current?.Show(LanguageService.Current?.FindResourceString(Constants.MsgText_TooLargeCopySize)); } try { var buffer = hexDataContext.GetSelectionData(); ClipBoardService.SetDataObject(Encoding.ASCII.GetString(buffer, 0, buffer.Length)); } catch (Exception ex) { LoggerService.WriteCallerLine(ex.Message); MsgBoxService.Current?.Show($"{ex.Message}"); } }); return(copyASCIIToCBoardCommand); }
private static ICommandItem GetCopyAsProCommandItem(IHexDataContext hexDataContext, IBufferToCodeFormatter formatter) { var comm = CommandFactory.CreateDelegateCommand(() => { if (hexDataContext.SelectionStart == -1 || hexDataContext.SelectionLength == -1) { return; } if (hexDataContext.SelectionLength - hexDataContext.SelectionStart > MaxCopyToClipBoardSize) { MsgBoxService.Current?.Show(LanguageService.Current?.FindResourceString(Constants.MsgText_TooLargeCopySize)); return; } try { var buffer = GetSelectionData(hexDataContext); ClipBoardService.SetText(formatter.FormatAsCode(buffer)); } catch (Exception ex) { LoggerService.WriteCallerLine(ex.Message); } }); var cmi = CommandItemFactory.CreateNew(comm); cmi.Name = LanguageService.FindResourceString(formatter.CodeLanguageName); return(cmi); }
public void CreateCopyASCIIToCBoardCommandItemTest() { var rightString = "U?"; ExecuteCopy(510, 2, HexDataContextCommandFactory.CreateCopyASCIIToCBoardCommandItem); Assert.AreEqual(ClipBoardService.GetText(), rightString); }
private void _ProjectPanel_ProjectLoaded(Project project) { _project = project; _projectService = new ProjectService(new ErrorService(), project); _graphicsService = new GraphicsService(_errorService, project); _levelService = new LevelService(_errorService, project); _palettesService = new PalettesService(_errorService, project); _worldService = new WorldService(_errorService, project); _tileService = new TileService(_errorService, project); _textService = new TextService(_errorService, project); _clipBoardService = new ClipBoardService(); _romService = new RomService(_errorService, _graphicsService, _palettesService, _tileService, _levelService, _worldService, _textService); _gameObjectService = new GameObjectService(_errorService, project); _levelService.LevelUpdated += _levelService_LevelUpdated; _worldService.WorldUpdated += _worldService_WorldUpdated; List <WorldInfo> worldInfos = new List <WorldInfo>(); worldInfos.AddRange(project.WorldInfo); worldInfos.Add(project.EmptyWorld); FilePanel.Initialize(_levelService, _worldService); SplashText.Visibility = Visibility.Collapsed; _config.LastProjectPath = _project.DirectoryPath + "\\" + _project.Name + ".json"; }
public ImageController(TagRespository tagRespository, ClipBoardService clipBoardService, CaseRespository caseRespository) { _tagRespository = tagRespository; _clipBoardService = clipBoardService; _caseRespository = caseRespository; Application.Current.Dispatcher.Invoke(() => { _clipBoardService.Register(Application.Current.MainWindow); }); }
internal static IDelegateCommand CreateCopyToClipBoardCommand(IHexDataContext hexDataContext) { var copyToClipBoardCommand = CommandFactory.CreateDelegateCommand( () => { if (hexDataContext.SelectionStart == -1 || hexDataContext.SelectionLength == -1) { return; } //若需剪切数据大于4GB,提示警告; if (hexDataContext.SelectionLength - hexDataContext.SelectionStart > MaxCopyToClipBoardSize) { MsgBoxService.Current?.Show(LanguageService.Current?.FindResourceString(Constants.MsgText_TooLargeCopySize)); return; } hexDataContext.Stream.Position = hexDataContext.SelectionStart; InterceptStream sourceStream = null; StreamReader sr = null; try { sourceStream = InterceptStream.CreateFromStream( hexDataContext.Stream, hexDataContext.SelectionStart, hexDataContext.SelectionLength); sr = new StreamReader(sourceStream); ClipBoardService.SetDataObject(sr.ReadToEnd()); } catch (Exception ex) { LoggerService.WriteCallerLine(ex.Message); MsgBoxService.Current?.Show($"{ex.Message}"); } finally { sourceStream?.Dispose(); sr?.Dispose(); } }); return(copyToClipBoardCommand); }
public void CreateCopyToCopyHexToCBoardCommandItemTest() { ExecuteCopy(510, 2, HexDataContextCommandFactory.CreateCopyToCopyHexToCBoardCommandItem); Assert.AreEqual(ClipBoardService.GetText(), "55AA"); }