<commit_before>/*
 * TNSampleTabModule.j
 *
 * Copyright (C) 2010 <NAME> <<EMAIL>>
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

@import <Foundation/Foundation.j>

@import <AppKit/CPButton.j>
@import <AppKit/CPButtonBar.j>
@import <AppKit/CPSearchField.j>
@import <AppKit/CPTextField.j>
@import <AppKit/CPTextField.j>
@import <AppKit/CPWindow.j>

@import <LPKit/LPMultiLineTextField.j>
@import <TNKit/TNAlert.j>
@import <TNKit/TNUIKitScrollView.j>

@import "TNSnapshot.j";
@import "TNSnapshotsDatasource.j";


var TNArchipelSnapshotsOpenedSnapshots          = @"TNArchipelSnapshotsOpenedSnapshots_",
    TNArchipelPushNotificationSnapshoting       = @"archipel:push:snapshoting",
    TNArchipelTypeHypervisorSnapshot            = @"archipel:virtualmachine:snapshoting",
    TNArchipelTypeHypervisorSnapshotTake        = @"take",
    TNArchipelTypeHypervisorSnapshotGet         = @"get",
    TNArchipelTypeHypervisorSnapshotCurrent     = @"current",
    TNArchipelTypeHypervisorSnapshotDelete      = @"delete",
    TNArchipelTypeHypervisorSnapshotRevert      = @"revert";


/*! @defgroup  virtualmachinesnapshoting Module VirtualMachine Snapshots
    @desc Module to handle Virtual Machine snapshoting
*/

/*! @ingroup virtualmachinedrives
    main class of the module
*/
@implementation TNVirtualMachineSnapshotsController : TNModule
{
    @outlet CPButton                    buttonSnapshotTake;
    @outlet CPButtonBar                 buttonBarControl;
    @outlet CPSearchField               fieldFilter;
    @outlet CPTextField                 fieldInfo;
    @outlet CPTextField                 fieldNewSnapshotName;
    @outlet CPPopover                   popoverNewSnapshot;
    @outlet CPView                      viewTableContainer;
    @outlet LPMultiLineTextField        fieldNewSnapshotDescription;
    @outlet TNUIKitScrollView           scrollViewSnapshots;

    CPButton                            _minusButton;
    CPButton                            _plusButton;
    CPButton                            _revertButton;
    CPOutlineView                       _outlineViewSnapshots;
    TNSnapshot                          _currentSnapshot;
    TNSnapshotsDatasource               _datasourceSnapshots;
}

#pragma mark -
#pragma mark  Initialization

/*! called at cib awaking
*/
- (void)awakeFromCib
{
    [viewTableContainer setBorderedWithHexColor:@"#C0C7D2"];

    // this really sucks, but something have change in capp that made the textfield not take care of the Atlas defined values;
    [fieldNewSnapshotDescription setFrameSize:CPSizeMake(366, 120)];

    // VM table view
    _datasourceSnapshots    = [[TNSnapshotsDatasource alloc] init];
    _outlineViewSnapshots   = [[CPOutlineView alloc] initWithFrame:[scrollViewSnapshots bounds]];

    [scrollViewSnapshots setAutoresizingMask: CPViewWidthSizable | CPViewHeightSizable];
    [scrollViewSnapshots setAutohidesScrollers:YES];
    [scrollViewSnapshots setDocumentView:_outlineViewSnapshots];

    [_outlineViewSnapshots setUsesAlternatingRowBackgroundColors:YES];
    [_outlineViewSnapshots setAutoresizingMask: CPViewWidthSizable | CPViewHeightSizable];
    [_outlineViewSnapshots setAllowsColumnResizing:YES];
    [_outlineViewSnapshots setAllowsEmptySelection:YES];
    [_outlineViewSnapshots setAllowsMultipleSelection:NO];
    [_outlineViewSnapshots setColumnAutoresizingStyle:CPTableViewLastColumnOnlyAutoresizingStyle];
    // [_outlineViewSnapshots setRowHeight:50.0];

    var outlineColumn = [[CPTableColumn alloc] initWithIdentifier:@"outline"],
        columnName = [[CPTableColumn alloc] initWithIdentifier:@"name"],
        columnDescription = [[CPTableColumn alloc] initWithIdentifier:@"description"],
        columnCreationTime = [[CPTableColumn alloc] initWithIdentifier:@"creationTime"],
        columnState     = [[CPTableColumn alloc] initWithIdentifier:@"isCurrent"],
        imgView         = [[CPImageView alloc] initWithFrame:CGRectMake(0,0,16,16)];

    [outlineColumn setWidth:16];

    [[columnName headerView] setStringValue:CPBundleLocalizedString(@"UUID", @"UUID")];
    [columnName setWidth:100];
    [columnName setSortDescriptorPrototype:[CPSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]];

    [[columnDescription headerView] setStringValue:CPBundleLocalizedString(@"Description", @"Description")];
    [columnDescription setWidth:400];
    [columnDescription setSortDescriptorPrototype:[CPSortDescriptor sortDescriptorWithKey:@"description" ascending:YES]];

    [[columnCreationTime headerView] setStringValue:CPBundleLocalizedString(@"Creation date", @"Creation date")];
    [columnCreationTime setWidth:130];
    [columnCreationTime setSortDescriptorPrototype:[CPSortDescriptor sortDescriptorWithKey:@"creationTime" ascending:YES]];

    [imgView setImageScaling:CPScaleNone];
    [columnState setDataView:imgView];
    [columnState setResizingMask:CPTableColumnAutoresizingMask ];
    [columnState setWidth:16];
    [[columnState headerView] setStringValue:@""];

    // [_outlineViewSnapshots addTableColumn:outlineColumn];
    [_outlineViewSnapshots addTableColumn:columnState];
    [_outlineViewSnapshots addTableColumn:columnDescription];
    [_outlineViewSnapshots addTableColumn:columnCreationTime];
    [_outlineViewSnapshots addTableColumn:columnName];
    [_outlineViewSnapshots setOutlineTableColumn:columnDescription];
    [_outlineViewSnapshots setDelegate:self];

    [_datasourceSnapshots setParentKeyPath:@"parent"];
    [_datasourceSnapshots setChildCompKeyPath:@"name"];
    [_datasourceSnapshots setSearchableKeyPaths:[@"name", @"description", @"creationTime"]];

    [fieldFilter setTarget:_datasourceSnapshots];
    [fieldFilter setAction:@selector(filterObjects:)];

    [_outlineViewSnapshots setDataSource:_datasourceSnapshots];

    _plusButton = [CPButtonBar plusButton];
    [_plusButton setTarget:self];
    [_plusButton setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"IconsButtons/photo-add.png"] size:CPSizeMake(14, 14)]];
    [_plusButton setAction:@selector(openWindowNewSnapshot:)];
    [_plusButton setToolTip:CPBundleLocalizedString(@"Take a new snapshot", @"Take a new snapshot")];

    _minusButton = [CPButtonBar minusButton];
    [_minusButton setTarget:self];
    [_minusButton setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"IconsButtons/photo-remove.png"] size:CPSizeMake(14, 14)]];
    [_minusButton setAction:@selector(deleteSnapshot:)];
    [_minusButton setToolTip:CPBundleLocalizedString(@"Delete selected snapshot", @"Delete selected snapshot")];<commit_msg>deactivate the search field in snapshot. datasource is broken for the moment<commit_after>/*
 * TNSampleTabModule.j
 *
 * Copyright (C) 2010 <NAME> <<EMAIL>>
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

@import <Foundation/Foundation.j>

@import <AppKit/CPButton.j>
@import <AppKit/CPButtonBar.j>
@import <AppKit/CPSearchField.j>
@import <AppKit/CPTextField.j>
@import <AppKit/CPTextField.j>
@import <AppKit/CPWindow.j>

@import <LPKit/LPMultiLineTextField.j>
@import <TNKit/TNAlert.j>
@import <TNKit/TNUIKitScrollView.j>

@import "TNSnapshot.j";
@import "TNSnapshotsDatasource.j";


var TNArchipelSnapshotsOpenedSnapshots          = @"TNArchipelSnapshotsOpenedSnapshots_",
    TNArchipelPushNotificationSnapshoting       = @"archipel:push:snapshoting",
    TNArchipelTypeHypervisorSnapshot            = @"archipel:virtualmachine:snapshoting",
    TNArchipelTypeHypervisorSnapshotTake        = @"take",
    TNArchipelTypeHypervisorSnapshotGet         = @"get",
    TNArchipelTypeHypervisorSnapshotCurrent     = @"current",
    TNArchipelTypeHypervisorSnapshotDelete      = @"delete",
    TNArchipelTypeHypervisorSnapshotRevert      = @"revert";


/*! @defgroup  virtualmachinesnapshoting Module VirtualMachine Snapshots
    @desc Module to handle Virtual Machine snapshoting
*/

/*! @ingroup virtualmachinedrives
    main class of the module
*/
@implementation TNVirtualMachineSnapshotsController : TNModule
{
    @outlet CPButton                    buttonSnapshotTake;
    @outlet CPButtonBar                 buttonBarControl;
    @outlet CPSearchField               fieldFilter;
    @outlet CPTextField                 fieldInfo;
    @outlet CPTextField                 fieldNewSnapshotName;
    @outlet CPPopover                   popoverNewSnapshot;
    @outlet CPView                      viewTableContainer;
    @outlet LPMultiLineTextField        fieldNewSnapshotDescription;
    @outlet TNUIKitScrollView           scrollViewSnapshots;

    CPButton                            _minusButton;
    CPButton                            _plusButton;
    CPButton                            _revertButton;
    CPOutlineView                       _outlineViewSnapshots;
    TNSnapshot                          _currentSnapshot;
    TNSnapshotsDatasource               _datasourceSnapshots;
}

#pragma mark -
#pragma mark  Initialization

/*! called at cib awaking
*/
- (void)awakeFromCib
{
    [viewTableContainer setBorderedWithHexColor:@"#C0C7D2"];

    // this really sucks, but something have change in capp that made the textfield not take care of the Atlas defined values;
    [fieldNewSnapshotDescription setFrameSize:CPSizeMake(366, 120)];

    // VM table view
    _datasourceSnapshots    = [[TNSnapshotsDatasource alloc] init];
    _outlineViewSnapshots   = [[CPOutlineView alloc] initWithFrame:[scrollViewSnapshots bounds]];

    [scrollViewSnapshots setAutoresizingMask: CPViewWidthSizable | CPViewHeightSizable];
    [scrollViewSnapshots setAutohidesScrollers:YES];
    [scrollViewSnapshots setDocumentView:_outlineViewSnapshots];

    [_outlineViewSnapshots setUsesAlternatingRowBackgroundColors:YES];
    [_outlineViewSnapshots setAutoresizingMask: CPViewWidthSizable | CPViewHeightSizable];
    [_outlineViewSnapshots setAllowsColumnResizing:YES];
    [_outlineViewSnapshots setAllowsEmptySelection:YES];
    [_outlineViewSnapshots setAllowsMultipleSelection:NO];
    [_outlineViewSnapshots setColumnAutoresizingStyle:CPTableViewLastColumnOnlyAutoresizingStyle];
    // [_outlineViewSnapshots setRowHeight:50.0];

    var outlineColumn = [[CPTableColumn alloc] initWithIdentifier:@"outline"],
        columnName = [[CPTableColumn alloc] initWithIdentifier:@"name"],
        columnDescription = [[CPTableColumn alloc] initWithIdentifier:@"description"],
        columnCreationTime = [[CPTableColumn alloc] initWithIdentifier:@"creationTime"],
        columnState     = [[CPTableColumn alloc] initWithIdentifier:@"isCurrent"],
        imgView         = [[CPImageView alloc] initWithFrame:CGRectMake(0,0,16,16)];

    [outlineColumn setWidth:16];

    [[columnName headerView] setStringValue:CPBundleLocalizedString(@"UUID", @"UUID")];
    [columnName setWidth:100];
    [columnName setSortDescriptorPrototype:[CPSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]];

    [[columnDescription headerView] setStringValue:CPBundleLocalizedString(@"Description", @"Description")];
    [columnDescription setWidth:400];
    [columnDescription setSortDescriptorPrototype:[CPSortDescriptor sortDescriptorWithKey:@"description" ascending:YES]];

    [[columnCreationTime headerView] setStringValue:CPBundleLocalizedString(@"Creation date", @"Creation date")];
    [columnCreationTime setWidth:130];
    [columnCreationTime setSortDescriptorPrototype:[CPSortDescriptor sortDescriptorWithKey:@"creationTime" ascending:YES]];

    [imgView setImageScaling:CPScaleNone];
    [columnState setDataView:imgView];
    [columnState setResizingMask:CPTableColumnAutoresizingMask ];
    [columnState setWidth:16];
    [[columnState headerView] setStringValue:@""];

    // [_outlineViewSnapshots addTableColumn:outlineColumn];
    [_outlineViewSnapshots addTableColumn:columnState];
    [_outlineViewSnapshots addTableColumn:columnDescription];
    [_outlineViewSnapshots addTableColumn:columnCreationTime];
    [_outlineViewSnapshots addTableColumn:columnName];
    [_outlineViewSnapshots setOutlineTableColumn:columnDescription];
    [_outlineViewSnapshots setDelegate:self];

    [_datasourceSnapshots setParentKeyPath:@"parent"];
    [_datasourceSnapshots setChildCompKeyPath:@"name"];
    [_datasourceSnapshots setSearchableKeyPaths:[@"name", @"description", @"creationTime"]];

    // @TODO: this doesn't work because the datasourve sucks.
    // while waiting for me to fix it, let's just deactivate this
    //[fieldFilter setTarget:_datasourceSnapshots];
    //[fieldFilter setAction:@selector(filterObjects:)];

    [_outlineViewSnapshots setDataSource:_datasourceSnapshots];

    _plusButton = [CPButtonBar plusButton];
    [_plusButton setTarget:self];
    [_plusButton setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"IconsButtons/photo-add.png"] size:CPSizeMake(14, 14)]];
    [_plusButton setAction:@selector(openWindowNewSnapshot:)];
    [_plusButton setToolTip:CPBundleLocalizedString(@"Take a new snapshot", @"Take a new snapshot")];

    _minusButton = [CPButtonBar minusButton];
    [_minusButton setTarget:self];
    [_minusButton setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"IconsButtons/photo-remove.png"] size:CPSizeMake(14, 14)]];
    [_minusButton setAction:@selector(deleteSnapshot:)];
    [_minusButton setToolTip:CPBundleLocalizedString(@"Delete selected snapshot", @"Delete selected snapshot")];
{'fraction_non_alphanumeric': 0.09036431733060947, 'fraction_numerical': 0.00599250936329588, 'mean_word_length': 4.56498673740053, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '264014', 'n_tokens_mistral': 4360, 'n_tokens_neox': 4029, 'n_words': 883}