VMListViewController.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // Copyright © 2019 Halts. All rights reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #import "VMListViewController.h"
  17. #import "VMListViewCell.h"
  18. #import "UTMConfigurationDelegate.h"
  19. #import "UTMConfiguration.h"
  20. @interface VMListViewController ()
  21. @end
  22. @implementation VMListViewController
  23. static NSString * const reuseIdentifier = @"vmListCell";
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. // Uncomment the following line to preserve selection between presentations
  27. // self.clearsSelectionOnViewWillAppear = NO;
  28. // Do any additional setup after loading the view.
  29. [[self vmCollection] setDragInteractionEnabled:YES];
  30. }
  31. #pragma mark - Navigation
  32. // In a storyboard-based application, you will often want to do a little preparation before navigation
  33. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  34. if([segue.identifier isEqualToString:@"editVMConfig"]){
  35. UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
  36. id<UTMConfigurationDelegate> controller = (id<UTMConfigurationDelegate>)navController.topViewController;
  37. controller.configuration = [[UTMConfiguration alloc] initWithDefaults];
  38. }
  39. }
  40. #pragma mark <UICollectionViewDataSource>
  41. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  42. #warning Incomplete implementation, return the number of sections
  43. return 1;
  44. }
  45. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  46. #warning Incomplete implementation, return the number of items
  47. return 5;
  48. }
  49. VMListViewCell *test_cell;
  50. VMState test_state;
  51. - (VMListViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  52. VMListViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
  53. // Configure the cell
  54. [cell setName:@"Test VM"];
  55. [cell changeState:kStopped];
  56. test_state = kStopped;
  57. test_cell = cell;
  58. return cell;
  59. }
  60. #pragma mark <UICollectionViewDelegate>
  61. /*
  62. // Uncomment this method to specify if the specified item should be highlighted during tracking
  63. - (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
  64. return YES;
  65. }
  66. */
  67. /*
  68. // Uncomment this method to specify if the specified item should be selected
  69. - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  70. return YES;
  71. }
  72. */
  73. /*
  74. // Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
  75. - (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
  76. return NO;
  77. }
  78. - (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
  79. return NO;
  80. }
  81. - (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
  82. }
  83. */
  84. - (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
  85. return YES;
  86. }
  87. #pragma mark <UICollectionViewDragDelegate>
  88. - (nonnull NSArray<UIDragItem *> *)collectionView:(nonnull UICollectionView *)collectionView itemsForBeginningDragSession:(nonnull id<UIDragSession>)session atIndexPath:(nonnull NSIndexPath *)indexPath {
  89. NSItemProvider *provider = [[NSItemProvider alloc] init];
  90. UIDragItem *drag = [[UIDragItem alloc] initWithItemProvider:provider];
  91. return @[drag];
  92. }
  93. #pragma mark <UICollectionViewDropDelegate>
  94. - (void)collectionView:(nonnull UICollectionView *)collectionView performDropWithCoordinator:(nonnull id<UICollectionViewDropCoordinator>)coordinator {
  95. }
  96. @end