| 1 | package Wrangler::Wx::Dialog::Settings; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Wx qw(:listctrl wxDefaultPosition wxDefaultSize wxDEFAULT_DIALOG_STYLE wxRESIZE_BORDER wxCLOSE_BOX wxLB_LEFT wxCLIP_CHILDREN wxHORIZONTAL wxID_OK wxALL wxGROW wxALIGN_RIGHT); | ||
| 7 | use Wx::Event qw(EVT_BUTTON EVT_LIST_ITEM_ACTIVATED EVT_LIST_ITEM_SELECTED); | ||
| 8 | use base 'Wx::Dialog'; | ||
| 9 | |||
| 10 | sub new { | ||
| 11 | my $class = shift; | ||
| 12 | my $parent = shift; | ||
| 13 | my $preselect = shift; | ||
| 14 | my $preselect_sub = shift; | ||
| 15 | |||
| 16 | # Set up the dialog | ||
| 17 | my $self = $class->SUPER::new($parent, -1, "Settings", wxDefaultPosition, [600,550], wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); | ||
| 18 | |||
| 19 | my $sizer = Wx::FlexGridSizer->new(3, 1, 0, 0); # rows,cols,vgap,hgap | ||
| 20 | $sizer->AddGrowableCol(0); # zerobased | ||
| 21 | $sizer->AddGrowableRow(0); # zerobased | ||
| 22 | $self->SetSizer($sizer); | ||
| 23 | |||
| 24 | # do a listbook | ||
| 25 | my $nb = Wx::Listbook->new( $self, -1, wxDefaultPosition, wxDefaultSize, wxLB_LEFT | wxCLIP_CHILDREN ); | ||
| 26 | $nb->{wrangler} = $parent->{wrangler}; # hook-up access to $wrangler | ||
| 27 | my %page; | ||
| 28 | $page{0} = Wrangler::Wx::Dialog::Settings::Wrangler->new($nb); | ||
| 29 | $page{1} = Wrangler::Wx::Dialog::Settings::FileBrowser->new($nb); | ||
| 30 | $page{2} = Wrangler::Wx::Dialog::Settings::Previewer->new($nb); | ||
| 31 | $page{3} = Wrangler::Wx::Dialog::Settings::Plugins->new($nb); | ||
| 32 | $nb->AddPage( $page{0}, "General", 0); | ||
| 33 | $nb->AddPage( $page{1}, "FileBrowser", 0); | ||
| 34 | $nb->AddPage( $page{2}, "Previewer", 0); | ||
| 35 | $nb->AddPage( $page{3}, "Plugins", 0); | ||
| 36 | $sizer->Add($nb, 0, wxALL|wxGROW, 5); | ||
| 37 | |||
| 38 | ## allow caller to preselect a page/subpage | ||
| 39 | $nb->ChangeSelection($preselect) if defined($preselect); # zerobased | ||
| 40 | $page{$preselect}->ChangeSelection($preselect_sub) if defined($preselect) && defined($preselect_sub) && defined($page{$preselect_sub}); # zerobased | ||
| 41 | |||
| 42 | ## button | ||
| 43 | my $btn_sizer = new Wx::BoxSizer(wxHORIZONTAL); | ||
| 44 | $btn_sizer->Add(Wx::Button->new($self, wxID_OK, 'OK'), 0, wxALL, 2); | ||
| 45 | $sizer->Add($btn_sizer, 0, wxALL|wxALIGN_RIGHT, 5); | ||
| 46 | |||
| 47 | EVT_BUTTON($self, wxID_OK, sub { | ||
| 48 | # print "Settings: OK\n"; | ||
| 49 | $_[1]->Skip(1); | ||
| 50 | }); | ||
| 51 | |||
| 52 | $self->Centre(); | ||
| 53 | $self->Show(); | ||
| 54 | |||
| 55 | return $self; | ||
| 56 | } | ||
| 57 | |||
| 58 | |||
| 59 | package Wrangler::Wx::Dialog::Settings::Wrangler; | ||
| 60 | |||
| 61 | use strict; | ||
| 62 | use warnings; | ||
| 63 | |||
| 64 | use Wx qw(wxVERTICAL wxDefaultPosition wxDefaultSize wxEXPAND wxCB_DROPDOWN wxCB_READONLY wxBOTTOM wxALL wxLC_REPORT wxLIST_FORMAT_LEFT wxGROW wxLIST_STATE_SELECTED wxLIST_NEXT_ALL wxID_OK); | ||
| 65 | use Wx::Event qw(EVT_MENU EVT_CHECKBOX EVT_LIST_ITEM_RIGHT_CLICK); | ||
| 66 | use base 'Wx::Notebook'; | ||
| 67 | |||
| 68 | sub new { | ||
| 69 | my $class = shift; | ||
| 70 | my $parent = shift; | ||
| 71 | |||
| 72 | my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxEXPAND); | ||
| 73 | |||
| 74 | # hook-up access to $wrangler | ||
| 75 | $self->{wrangler} = $parent->{wrangler}; | ||
| 76 | my $config = $self->{wrangler}->config(); | ||
| 77 | |||
| 78 | |||
| 79 | ## Panel 1 | ||
| 80 | my $panel_1 = Wx::Panel->new($self); | ||
| 81 | $self->AddPage( $panel_1, "Appearance", 0); | ||
| 82 | |||
| 83 | # language | ||
| 84 | my $combo_language = Wx::ComboBox->new($panel_1, -1, 'English (default)', wxDefaultPosition, wxDefaultSize, | ||
| 85 | [ | ||
| 86 | 'English (default)', | ||
| 87 | 'Deutsch', | ||
| 88 | ], wxCB_DROPDOWN|wxCB_READONLY | ||
| 89 | ); | ||
| 90 | my @LangSel = ('en','de'); | ||
| 91 | my %LangSel = ( en => 0, de => 1 ); | ||
| 92 | $combo_language->SetClientData(0, $LangSel[0]); | ||
| 93 | $combo_language->SetClientData(1, $LangSel[1]); | ||
| 94 | # $combo_language->SetSelection($LangSel{ $Wrangler::U{Language} }); | ||
| 95 | |||
| 96 | my $language_sizer = Wx::FlexGridSizer->new(1,1); # rows,cols,vgap,hgap | ||
| 97 | $language_sizer->Add($combo_language, 1, wxALL, 5); | ||
| 98 | my $language_boxsizer = Wx::StaticBoxSizer->new( Wx::StaticBox->new($panel_1, -1, "Language"), wxVERTICAL); | ||
| 99 | $language_boxsizer->Add($language_sizer, 1, wxALL, 10); | ||
| 100 | |||
| 101 | # widgets | ||
| 102 | my $check_show_menubar = Wx::CheckBox->new($panel_1, -1, 'Show MenuBar on top'); | ||
| 103 | $check_show_menubar->SetToolTip("Show a traditional 'File', 'Help' etc. menu below the window's title-bar"); | ||
| 104 | $check_show_menubar->SetValue( $config->{'ui.layout.menubar'} || 0); | ||
| 105 | my $check_show_navbar = Wx::CheckBox->new($panel_1, -1, 'Show Navbar'); | ||
| 106 | $check_show_navbar->SetToolTip("Show a widget that displays current folder/path"); | ||
| 107 | $check_show_navbar->SetValue( $config->{'ui.layout.navbar'} || 0); | ||
| 108 | my $check_show_sidebar = Wx::CheckBox->new($panel_1, -1, 'Show Sidebar'); | ||
| 109 | $check_show_sidebar->SetToolTip("Show a Sidebar with quick-links to Devices, Bookmarks"); | ||
| 110 | $check_show_sidebar->SetValue( $config->{'ui.layout.sidebar'} || 0); | ||
| 111 | my $check_show_statusbar = Wx::CheckBox->new($panel_1, -1, 'Show Statusbar on bottom'); | ||
| 112 | $check_show_statusbar->SetToolTip("Show a StatusBar on the bottom of the window"); | ||
| 113 | $check_show_statusbar->SetValue( $config->{'ui.layout.statusbar'} || 0); | ||
| 114 | |||
| 115 | my $widgets_sizer = Wx::FlexGridSizer->new(4,1); # rows,cols,vgap,hgap | ||
| 116 | $widgets_sizer->Add($check_show_menubar, 1, wxALL, 5); | ||
| 117 | $widgets_sizer->Add($check_show_navbar, 1, wxALL, 5); | ||
| 118 | $widgets_sizer->Add($check_show_sidebar, 1, wxALL, 5); | ||
| 119 | $widgets_sizer->Add($check_show_statusbar, 1, wxALL, 5); | ||
| 120 | |||
| 121 | my $widgets_boxsizer = Wx::StaticBoxSizer->new( Wx::StaticBox->new($panel_1, -1, "Widgets"), wxVERTICAL); | ||
| 122 | $widgets_boxsizer->Add($widgets_sizer, 1, wxALL, 10); | ||
| 123 | |||
| 124 | |||
| 125 | # panel 1 sizer | ||
| 126 | my $panel_1_sizer = Wx::FlexGridSizer->new(2,1,10); # rows,cols,vgap,hgap | ||
| 127 | $panel_1_sizer->AddGrowableCol(0); # zerobased | ||
| 128 | $panel_1_sizer->Add($language_boxsizer, 1, wxGROW); | ||
| 129 | $panel_1_sizer->Add($widgets_boxsizer, 1, wxGROW); | ||
| 130 | |||
| 131 | $panel_1->SetSizer($panel_1_sizer); | ||
| 132 | |||
| 133 | # panel 1 events | ||
| 134 | EVT_CHECKBOX($self, $check_show_menubar, sub { | ||
| 135 | $self->{wrangler}->config()->{'ui.layout.menubar'} = $_[1]->IsChecked() || 0; | ||
| 136 | Wrangler::PubSub::publish('main.menubar.toggle', $_[1]->IsChecked() || 0 ); | ||
| 137 | }); | ||
| 138 | EVT_CHECKBOX($self, $check_show_navbar, sub { | ||
| 139 | $self->{wrangler}->config()->{'ui.layout.navbar'} = $_[1]->IsChecked() || 0; | ||
| 140 | Wrangler::PubSub::publish('main.navbar.toggle'); | ||
| 141 | }); | ||
| 142 | EVT_CHECKBOX($self, $check_show_sidebar, sub { | ||
| 143 | $self->{wrangler}->config()->{'ui.layout.sidebar'} = $_[1]->IsChecked() || 0; | ||
| 144 | Wrangler::PubSub::publish('main.sidebar.toggle'); | ||
| 145 | }); | ||
| 146 | EVT_CHECKBOX($self, $check_show_statusbar, sub { | ||
| 147 | $self->{wrangler}->config()->{'ui.layout.statusbar'} = $_[1]->IsChecked() || 0; | ||
| 148 | Wrangler::PubSub::publish('main.statusbar.toggle', $_[1]->IsChecked() || 0 ); | ||
| 149 | }); | ||
| 150 | |||
| 151 | |||
| 152 | ## Panel 2: General(Wrangler): ValueShortcuts | ||
| 153 | my $panel_2 = Wx::Panel->new($self); | ||
| 154 | $self->AddPage( $panel_2, "Value Shortcuts", 0); | ||
| 155 | |||
| 156 | |||
| 157 | # columns | ||
| 158 | $self->{listctrl} = Wx::ListCtrl->new($panel_2, -1, wxDefaultPosition, wxDefaultSize, wxLC_REPORT); | ||
| 159 | $self->{listctrl}->InsertColumn( 1, 'Keyboard Shortcut', wxLIST_FORMAT_LEFT, 100 ); | ||
| 160 | $self->{listctrl}->InsertColumn( 2, 'Insert into... (key)', wxLIST_FORMAT_LEFT, 250 ); | ||
| 161 | $self->{listctrl}->InsertColumn( 3, 'Data value', wxLIST_FORMAT_LEFT, 100 ); | ||
| 162 | |||
| 163 | my $sizer = Wx::FlexGridSizer->new(2, 1, 20, 0); # rows,cols,vgap,hgap | ||
| 164 | $sizer->AddGrowableCol(0); # zerobased | ||
| 165 | $sizer->AddGrowableRow(1); # zerobased | ||
| 166 | $sizer->Add( Wx::StaticText->new($panel_2, -1, 'Wrangler offers a facility where users can define their own "Value Shortcuts". These are keyboard-shortcuts that trigger pre-defined user strings to be entered into data fields.'."\n\n".'Associating a metadata-key with a shortcut will insert the pre-defined string into this field without having to jump into the respective form-field; leaving the metadata-key blank means the data-string will be pasted at cursor position.', wxDefaultPosition, wxDefaultSize), 0, wxEXPAND|wxALL, 10 ); | ||
| 167 | $sizer->Add($self->{listctrl}, 0, wxALL|wxGROW, 5); | ||
| 168 | |||
| 169 | $panel_2->SetSizer($sizer); | ||
| 170 | |||
| 171 | ## Panel 2 events | ||
| 172 | EVT_LIST_ITEM_RIGHT_CLICK($self, $self->{listctrl}, sub { OnRightClick(@_); }); | ||
| 173 | |||
| 174 | $self->Populate(); | ||
| 175 | |||
| 176 | return $self; | ||
| 177 | } | ||
| 178 | |||
| 179 | sub GetSelections { | ||
| 180 | return () unless $_[0]->{listctrl}->GetSelectedItemCount(); # untested optimisation | ||
| 181 | |||
| 182 | my @selections; | ||
| 183 | my $currId = -1; | ||
| 184 | for(;;){ | ||
| 185 | $currId = $_[0]->{listctrl}->GetNextItem($currId, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); | ||
| 186 | if($currId == -1){ | ||
| 187 | last; | ||
| 188 | }else{ | ||
| 189 | push(@selections, $currId); | ||
| 190 | } | ||
| 191 | } | ||
| 192 | |||
| 193 | return wantarray ? @selections : \@selections; | ||
| 194 | } | ||
| 195 | |||
| 196 | sub Populate { | ||
| 197 | my $settings = shift; | ||
| 198 | my $shortcuts = $settings->{wrangler}->config()->{'valueshortcuts'} || {}; | ||
| 199 | |||
| 200 | $settings->{listctrl}->DeleteAllItems(); | ||
| 201 | |||
| 202 | my $prop_ref = $settings->{wrangler}->{fs}->available_properties($settings->{wrangler}->{current_dir}); | ||
| 203 | |||
| 204 | my $rowCnt = 0; | ||
| 205 | for(keys %$shortcuts){ | ||
| 206 | $settings->{lookup}->[$rowCnt] = $_; | ||
| 207 | |||
| 208 | # InsertItem returns a numeric $itemId | ||
| 209 | my $itemId = $settings->{listctrl}->InsertStringItem( $rowCnt, $shortcuts->{$_}->{name}); | ||
| 210 | $settings->{listctrl}->SetItem( $itemId, 1, $shortcuts->{$_}->{key} ); | ||
| 211 | $settings->{listctrl}->SetItem( $itemId, 2, $shortcuts->{$_}->{value} ); | ||
| 212 | $rowCnt++; | ||
| 213 | } | ||
| 214 | } | ||
| 215 | |||
| 216 | sub Add { | ||
| 217 | my $settings = shift; | ||
| 218 | |||
| 219 | require Wrangler::Wx::Dialog::ShortcutCollector; | ||
| 220 | my $dialog = Wrangler::Wx::Dialog::ShortcutCollector->new($settings); | ||
| 221 | |||
| 222 | return unless $dialog->ShowModal() == wxID_OK; | ||
| 223 | |||
| 224 | my $shortcuts = $settings->{wrangler}->config()->{'valueshortcuts'}; | ||
| 225 | $shortcuts->{ $dialog->{result_keycodes} } = { | ||
| 226 | name => $dialog->{result_human}, | ||
| 227 | key => '', | ||
| 228 | value => '', | ||
| 229 | }; | ||
| 230 | |||
| 231 | $settings->Populate(); | ||
| 232 | } | ||
| 233 | |||
| 234 | sub ChangeShortcut { | ||
| 235 | my $settings = shift; | ||
| 236 | |||
| 237 | require Wrangler::Wx::Dialog::ShortcutCollector; | ||
| 238 | my $dialog = Wrangler::Wx::Dialog::ShortcutCollector->new($settings); | ||
| 239 | |||
| 240 | return unless $dialog->ShowModal() == wxID_OK; | ||
| 241 | |||
| 242 | my @selections = $settings->GetSelections(); | ||
| 243 | my $id = $settings->{listctrl}->GetItem($selections[0]); | ||
| 244 | my $pos = $id->GetId; | ||
| 245 | |||
| 246 | my $shortcuts = $settings->{wrangler}->config()->{'valueshortcuts'}; | ||
| 247 | my $shortcut = $shortcuts->{ $settings->{lookup}->[$pos] }; | ||
| 248 | |||
| 249 | $shortcuts->{ $dialog->{result_keycodes} } = { | ||
| 250 | name => $dialog->{result_human}, | ||
| 251 | key => $shortcut->{key}, | ||
| 252 | value => $shortcut->{value}, | ||
| 253 | }; | ||
| 254 | delete($shortcuts->{ $settings->{lookup}->[$pos] }); | ||
| 255 | |||
| 256 | $settings->Populate(); | ||
| 257 | } | ||
| 258 | |||
| 259 | sub ChangeValue { | ||
| 260 | my $settings = shift; | ||
| 261 | |||
| 262 | my @selections = $settings->GetSelections(); | ||
| 263 | my $id = $settings->{listctrl}->GetItem($selections[0]); | ||
| 264 | my $pos = $id->GetId; | ||
| 265 | |||
| 266 | my $shortcuts = $settings->{wrangler}->config()->{'valueshortcuts'}; | ||
| 267 | my $shortcut = $shortcuts->{ $settings->{lookup}->[$pos] }; | ||
| 268 | |||
| 269 | my $dialog = Wx::TextEntryDialog->new($settings, "Change data value", "Change data value", $shortcut->{value} ); | ||
| 270 | |||
| 271 | return unless $dialog->ShowModal() == wxID_OK; | ||
| 272 | |||
| 273 | $shortcut->{value} = $dialog->GetValue(); | ||
| 274 | |||
| 275 | $dialog->Destroy(); | ||
| 276 | |||
| 277 | $settings->Populate(); | ||
| 278 | } | ||
| 279 | |||
| 280 | sub ChangeField { | ||
| 281 | my $settings = shift; | ||
| 282 | my $field_name = shift; | ||
| 283 | |||
| 284 | my @selections = $settings->GetSelections(); | ||
| 285 | my $id = $settings->{listctrl}->GetItem($selections[0]); | ||
| 286 | my $pos = $id->GetId; | ||
| 287 | |||
| 288 | my $shortcuts = $settings->{wrangler}->config()->{'valueshortcuts'}; | ||
| 289 | my $shortcut = $shortcuts->{ $settings->{lookup}->[$pos] }; | ||
| 290 | |||
| 291 | if($field_name eq '[none]'){ | ||
| 292 | $shortcut->{key} = undef; | ||
| 293 | }elsif($field_name){ | ||
| 294 | $shortcut->{key} = $field_name; | ||
| 295 | }else{ | ||
| 296 | my $dialog = Wx::TextEntryDialog->new($settings, "Change associated field", "Change associated field", $shortcut->{key}); | ||
| 297 | |||
| 298 | return unless $dialog->ShowModal() == wxID_OK; | ||
| 299 | |||
| 300 | $field_name = $dialog->GetValue(); | ||
| 301 | $shortcut->{key} = $field_name; | ||
| 302 | |||
| 303 | $dialog->Destroy(); | ||
| 304 | } | ||
| 305 | |||
| 306 | $settings->Populate(); | ||
| 307 | } | ||
| 308 | |||
| 309 | sub Remove { | ||
| 310 | my $settings = shift; | ||
| 311 | |||
| 312 | my @selections = $settings->GetSelections(); | ||
| 313 | |||
| 314 | my $id = $settings->{listctrl}->GetItem($selections[0]); | ||
| 315 | my $pos = $id->GetId; | ||
| 316 | |||
| 317 | my $shortcuts = $settings->{wrangler}->config()->{'valueshortcuts'}; | ||
| 318 | |||
| 319 | delete($shortcuts->{ $settings->{lookup}->[$pos] }); | ||
| 320 | |||
| 321 | $settings->Populate(); | ||
| 322 | } | ||
| 323 | |||
| 324 | sub OnRightClick { | ||
| 325 | my $settings = shift; | ||
| 326 | my $event = shift; | ||
| 327 | |||
| 328 | my $menu = Wx::Menu->new(); | ||
| 329 | |||
| 330 | my @selections = $settings->GetSelections(); | ||
| 331 | |||
| 332 | EVT_MENU( $settings, $menu->Append(-1, "Add a new Shortcut", 'Add a new Value Shortcut' ), sub { $settings->Add(); } ); | ||
| 333 | if( defined($selections[0]) ){ | ||
| 334 | $menu->AppendSeparator(); | ||
| 335 | EVT_MENU( $settings, $menu->Append(-1, "Change Shortcut", 'Change selected Value Shortcut' ), sub { $settings->ChangeShortcut(); } ); | ||
| 336 | my $submenu = Wx::Menu->new(); | ||
| 337 | for( @{ $settings->{wrangler}->{fs}->available_properties($settings->{wrangler}->{current_dir}) } ){ | ||
| 338 | my $item = $submenu->Append(-1, $_); | ||
| 339 | $submenu->Enable($item->GetId(),0) unless $settings->{wrangler}->{fs}->can_mod($_); | ||
| 340 | EVT_MENU( $settings, $item, sub { $settings->ChangeField($item->GetText()); } ); # deprecated: use GetItemLabel text soon | ||
| 341 | } | ||
| 342 | $submenu->AppendSeparator(); | ||
| 343 | my $itemOther = $submenu->Append(-1, 'Other...'); | ||
| 344 | EVT_MENU( $settings, $itemOther, sub { $settings->ChangeField(); } ); | ||
| 345 | $submenu->AppendSeparator(); | ||
| 346 | my $itemNone = $submenu->Append(-1, '[none]'); | ||
| 347 | EVT_MENU( $settings, $itemNone, sub { $settings->ChangeField('[none]'); } ); | ||
| 348 | $menu->Append(-1, "Associate field...", $submenu, 'Associate this shortcut with a metadata-key/field' ); | ||
| 349 | EVT_MENU( $settings, $menu->Append(-1, "Change value", 'Change data value' ), sub { $settings->ChangeValue(); } ); | ||
| 350 | $menu->AppendSeparator(); | ||
| 351 | EVT_MENU( $settings, $menu->Append(-1, "Delete selected Shortcut", 'Delete this Value Shortcut' ), sub { $settings->Remove(); } ); | ||
| 352 | } | ||
| 353 | |||
| 354 | $settings->PopupMenu( $menu, wxDefaultPosition ); | ||
| 355 | } | ||
| 356 | |||
| 357 | |||
| 358 | package Wrangler::Wx::Dialog::Settings::FileBrowser; | ||
| 359 | |||
| 360 | use strict; | ||
| 361 | use warnings; | ||
| 362 | |||
| 363 | use Wx qw(:listctrl wxDefaultPosition wxDefaultSize wxDEFAULT_DIALOG_STYLE wxEXPAND wxVERTICAL wxLEFT wxTOP wxBOTTOM wxRIGHT wxRESIZE_BORDER wxHORIZONTAL wxID_CANCEL wxID_OK wxALL wxGROW wxALIGN_RIGHT); | ||
| 364 | use Wx::Event qw(EVT_CHECKBOX EVT_TEXT EVT_COLOURPICKER_CHANGED EVT_LIST_ITEM_ACTIVATED EVT_LIST_ITEM_SELECTED EVT_LIST_ITEM_RIGHT_CLICK EVT_MENU EVT_LIST_BEGIN_DRAG); | ||
| 365 | use base 'Wx::Notebook'; | ||
| 366 | |||
| 367 | sub new { | ||
| 368 | my $class = shift; | ||
| 369 | my $parent = shift; | ||
| 370 | |||
| 371 | my $self = $class->SUPER::new($parent, -1); | ||
| 372 | |||
| 373 | # hook-up access to $wrangler | ||
| 374 | $self->{wrangler} = $parent->{wrangler}; | ||
| 375 | my $config = $self->{wrangler}->config(); | ||
| 376 | |||
| 377 | |||
| 378 | ## Panel 1 | ||
| 379 | my $panel_1 = Wx::Panel->new($self); | ||
| 380 | $self->AddPage( $panel_1, "Appearance", 0); | ||
| 381 | |||
| 382 | # listing | ||
| 383 | my $check_include_hidden = Wx::CheckBox->new($panel_1, -1, 'Show hidden files (dotfiles)'); | ||
| 384 | $check_include_hidden->SetToolTip("Check to enable this"); | ||
| 385 | $check_include_hidden->SetValue( $config->{'ui.filebrowser.include_hidden'} || 0); | ||
| 386 | my $check_include_updir = Wx::CheckBox->new($panel_1, -1, 'Include up-dir (..)'); | ||
| 387 | $check_include_updir->SetToolTip('If you use the Navbar, you may want to omit the "go up" entry in file-listings'); | ||
| 388 | $check_include_updir->SetValue( $config->{'ui.filebrowser.include_updir'} || 0); | ||
| 389 | my $check_zebra_striping = Wx::CheckBox->new($panel_1, -1, 'Use "Zebra-Striping"'); | ||
| 390 | $check_zebra_striping->SetToolTip("Check to enable this"); | ||
| 391 | $check_zebra_striping->SetValue( $config->{'ui.filebrowser.zebra_striping'} || 0); | ||
| 392 | |||
| 393 | my $listing_sizer = Wx::FlexGridSizer->new(4,1); # rows,cols,vgap,hgap | ||
| 394 | $listing_sizer->Add($check_include_hidden, 1, wxALL, 5); | ||
| 395 | $listing_sizer->Add($check_include_updir, 1, wxALL, 5); | ||
| 396 | $listing_sizer->Add($check_zebra_striping, 1, wxALL, 5); | ||
| 397 | my $listing_boxsizer = Wx::StaticBoxSizer->new( Wx::StaticBox->new($panel_1, -1, "Listing"), wxVERTICAL); | ||
| 398 | $listing_boxsizer->Add($listing_sizer, 1, wxALL, 10); | ||
| 399 | |||
| 400 | # highlighting | ||
| 401 | my $check_highlight_media = Wx::CheckBox->new($panel_1, -1, 'Highlight media files'); | ||
| 402 | $check_highlight_media->SetToolTip("Check to enable this"); | ||
| 403 | $check_highlight_media->SetValue( $config->{'ui.filebrowser.highlight_media'} || 0); | ||
| 404 | |||
| 405 | my $highlight_audio_label = Wx::StaticText->new($panel_1, -1, "Audio files"); | ||
| 406 | my $highlight_audio = Wx::ColourPickerCtrl->new($panel_1, -1, Wx::Colour->new(@{$config->{'ui.filebrowser.highlight_colour.audio'}}) ); | ||
| 407 | my $highlight_image_label = Wx::StaticText->new($panel_1, -1, "Image files"); | ||
| 408 | my $highlight_image = Wx::ColourPickerCtrl->new($panel_1, -1, Wx::Colour->new(@{$config->{'ui.filebrowser.highlight_colour.image'}}) ); | ||
| 409 | my $highlight_video_label = Wx::StaticText->new($panel_1, -1, "Video files"); | ||
| 410 | my $highlight_video = Wx::ColourPickerCtrl->new($panel_1, -1, Wx::Colour->new(@{$config->{'ui.filebrowser.highlight_colour.video'}}) ); | ||
| 411 | |||
| 412 | my $highlighting_sizer = Wx::FlexGridSizer->new(3,2); # rows,cols,vgap,hgap | ||
| 413 | $highlighting_sizer->Add($highlight_audio_label, 1, wxTOP, 5); | ||
| 414 | $highlighting_sizer->Add($highlight_audio, 1); | ||
| 415 | $highlighting_sizer->Add($highlight_image_label, 1, wxTOP, 5); | ||
| 416 | $highlighting_sizer->Add($highlight_image, 1); | ||
| 417 | $highlighting_sizer->Add($highlight_video_label, 1, wxTOP, 5); | ||
| 418 | $highlighting_sizer->Add($highlight_video, 1); | ||
| 419 | |||
| 420 | my $highlighting_subsizer = Wx::FlexGridSizer->new(2, 1, 10); # rows,cols,vgap,hgap | ||
| 421 | $highlighting_subsizer->AddGrowableRow(1); # zerobased | ||
| 422 | $highlighting_subsizer->Add($check_highlight_media); | ||
| 423 | $highlighting_subsizer->Add($highlighting_sizer); | ||
| 424 | |||
| 425 | my $highlighting_boxsizer = Wx::StaticBoxSizer->new( Wx::StaticBox->new($panel_1, -1, "File Highlighting"), wxVERTICAL); | ||
| 426 | $highlighting_boxsizer->Add($highlighting_subsizer, 1, wxALL, 10); | ||
| 427 | |||
| 428 | # panel 1 sizer | ||
| 429 | my $panel_1_sizer = Wx::FlexGridSizer->new(3,1,10); # rows,cols,vgap,hgap | ||
| 430 | $panel_1_sizer->AddGrowableCol(0); # zerobased | ||
| 431 | $panel_1_sizer->Add($listing_boxsizer, 1, wxGROW); | ||
| 432 | $panel_1_sizer->Add($highlighting_boxsizer, 1, wxGROW); | ||
| 433 | |||
| 434 | $panel_1->SetSizer($panel_1_sizer); | ||
| 435 | |||
| 436 | # panel 1 events | ||
| 437 | EVT_CHECKBOX($self, $check_include_hidden, sub { | ||
| 438 | # print "check_include_hidden: ".$_[1]->IsChecked()."->".$self->{wrangler}->config('ui.filebrowser.include_hidden')."\n"; | ||
| 439 | $self->{wrangler}->config()->{'ui.filebrowser.include_hidden'} = $_[1]->IsChecked() || 0; | ||
| 440 | Wrangler::PubSub::publish('filebrowser.refresh'); | ||
| 441 | }); | ||
| 442 | EVT_CHECKBOX($self, $check_include_updir, sub { | ||
| 443 | # print "check_include_updir: ".$_[1]->IsChecked()."->".$self->{wrangler}->config('ui.filebrowser.include_updir')."\n"; | ||
| 444 | $self->{wrangler}->config()->{'ui.filebrowser.include_updir'} = $_[1]->IsChecked() || 0; | ||
| 445 | Wrangler::PubSub::publish('filebrowser.refresh'); | ||
| 446 | }); | ||
| 447 | EVT_CHECKBOX($self, $check_zebra_striping, sub { | ||
| 448 | # print "check_zebra_striping: ".$_[1]->IsChecked()."->".$self->{wrangler}->config('ui.filebrowser.zebra_striping')."\n"; | ||
| 449 | $self->{wrangler}->config()->{'ui.filebrowser.zebra_striping'} = $_[1]->IsChecked() || 0; | ||
| 450 | Wrangler::PubSub::publish('filebrowser.refresh'); | ||
| 451 | }); | ||
| 452 | EVT_CHECKBOX($self, $check_highlight_media, sub { | ||
| 453 | # print "check_highlight_media: ".$_[1]->IsChecked()."->".$self->{wrangler}->config('ui.filebrowser.highlight_media')."\n"; | ||
| 454 | $self->{wrangler}->config()->{'ui.filebrowser.highlight_media'} = $_[1]->IsChecked() || 0; | ||
| 455 | Wrangler::PubSub::publish('filebrowser.refresh.all'); # refresh.all, as we need to update $wishlist registration | ||
| 456 | }); | ||
| 457 | EVT_COLOURPICKER_CHANGED($self, $highlight_audio, sub { | ||
| 458 | $self->{wrangler}->config()->{'ui.filebrowser.highlight_colour.audio'} = [ $_[1]->GetColour()->Red(), $_[1]->GetColour()->Green(), $_[1]->GetColour()->Blue() ]; | ||
| 459 | Wrangler::PubSub::publish('filebrowser.refresh'); | ||
| 460 | }); | ||
| 461 | EVT_COLOURPICKER_CHANGED($self, $highlight_image, sub { | ||
| 462 | $self->{wrangler}->config()->{'ui.filebrowser.highlight_colour.image'} = [ $_[1]->GetColour()->Red(), $_[1]->GetColour()->Green(), $_[1]->GetColour()->Blue() ]; | ||
| 463 | Wrangler::PubSub::publish('filebrowser.refresh'); | ||
| 464 | }); | ||
| 465 | EVT_COLOURPICKER_CHANGED($self, $highlight_video, sub { | ||
| 466 | $self->{wrangler}->config()->{'ui.filebrowser.highlight_colour.video'} = [ $_[1]->GetColour()->Red(), $_[1]->GetColour()->Green(), $_[1]->GetColour()->Blue() ]; | ||
| 467 | Wrangler::PubSub::publish('filebrowser.refresh'); | ||
| 468 | }); | ||
| 469 | |||
| 470 | |||
| 471 | ## Panel 2 | ||
| 472 | my $panel_2 = Wx::Panel->new($self); | ||
| 473 | $self->AddPage( $panel_2, "Behaviour", 0); | ||
| 474 | |||
| 475 | # Behaviour: Operations | ||
| 476 | my $check_offer_delete = Wx::CheckBox->new($panel_2, -1, "Offer a 'delete' in addition to trash"); | ||
| 477 | $check_offer_delete->SetToolTip("Check to enable this"); | ||
| 478 | $check_offer_delete->SetValue( $config->{'ui.filebrowser.offer.delete'} || 0); | ||
| 479 | my $check_confirm_delete = Wx::CheckBox->new($panel_2, -1, "Ask user to confirm real 'delete's"); | ||
| 480 | $check_confirm_delete->SetToolTip("Check to enable this"); | ||
| 481 | $check_confirm_delete->SetValue( $config->{'ui.filebrowser.confirm.delete'} || 0); | ||
| 482 | my $check_copy_preserves = Wx::CheckBox->new($panel_2, -1, "'copy' preserves xattribs"); | ||
| 483 | $check_copy_preserves->SetToolTip("Normally extended attributes are not copied. This here enables preservation of xattr on copy."); | ||
| 484 | $check_copy_preserves->SetValue( $config->{'ui.filebrowser.copy.preserve_xattribs'} || 0); | ||
| 485 | |||
| 486 | my $behaviour_sizer = Wx::FlexGridSizer->new(2,1); # rows,cols,vgap,hgap | ||
| 487 | $behaviour_sizer->Add($check_offer_delete, 1, wxALL, 5); | ||
| 488 | $behaviour_sizer->Add($check_confirm_delete, 1, wxALL, 5); | ||
| 489 | $behaviour_sizer->Add($check_copy_preserves, 1, wxALL, 5); | ||
| 490 | my $behaviour_boxsizer = Wx::StaticBoxSizer->new( Wx::StaticBox->new($panel_2, -1, "Operations"), wxVERTICAL); | ||
| 491 | $behaviour_boxsizer->Add($behaviour_sizer, 1, wxALL, 10); | ||
| 492 | |||
| 493 | # Behaviour: Sorting | ||
| 494 | my $check_per_directory_sorting = Wx::CheckBox->new($panel_2, -1, "Remember sorting 'per directory'"); | ||
| 495 | $check_per_directory_sorting->SetToolTip("Check to enable this"); | ||
| 496 | $check_per_directory_sorting->SetValue( $config->{'ui.filebrowser.sorting.per_directory'} || 0); | ||
| 497 | |||
| 498 | my $sorting_flexsizer = Wx::FlexGridSizer->new(2,1); # rows,cols,vgap,hgap | ||
| 499 | $sorting_flexsizer->Add( Wx::StaticText->new($panel_2, -1, "By default, FileBrowser will remember sorting globally. Checking\nthis here will tell Wrangler to remember sorting per directory.", wxDefaultPosition, wxDefaultSize), 1, wxALL, 5); | ||
| 500 | $sorting_flexsizer->Add($check_per_directory_sorting, 1, wxALL, 5); | ||
| 501 | |||
| 502 | my $sorting_boxsizer = Wx::StaticBoxSizer->new( Wx::StaticBox->new($panel_2, -1, "Sorting"), wxVERTICAL); | ||
| 503 | $sorting_boxsizer->Add( $sorting_flexsizer, 0, wxALL, 10 ); | ||
| 504 | |||
| 505 | # Behaviour: Change Monitoring | ||
| 506 | my $monitoring_pull_timeout = Wx::TextCtrl->new($panel_2, -1, $self->{wrangler}->config()->{'ui.filebrowser.pull_monitor_timeout'} ? ($self->{wrangler}->config()->{'ui.filebrowser.pull_monitor_timeout'} / 1000) : 7); | ||
| 507 | |||
| 508 | my $input_sizer = Wx::BoxSizer->new(wxHORIZONTAL); | ||
| 509 | $input_sizer->Add( $monitoring_pull_timeout, 0, wxRIGHT, 5 ); | ||
| 510 | $input_sizer->Add( Wx::StaticText->new($panel_2, -1, 'seconds', wxDefaultPosition, wxDefaultSize), 1, wxTOP, 7); | ||
| 511 | |||
| 512 | my $monitoring_sizer = Wx::FlexGridSizer->new(2,1); # rows,cols,vgap,hgap | ||
| 513 | $monitoring_sizer->Add( Wx::StaticText->new($panel_2, -1, "FileBrowser is currently only able to track directory changes\nin simple 'pull'-mode. This here sets the poll intervall\nbetween mtime checks.", wxDefaultPosition, wxDefaultSize), 1, wxALL, 5); | ||
| 514 | $monitoring_sizer->Add($input_sizer, 1, wxALL, 5); | ||
| 515 | |||
| 516 | my $monitoring_boxsizer = Wx::StaticBoxSizer->new( Wx::StaticBox->new($panel_2, -1, "Change monitoring"), wxVERTICAL); | ||
| 517 | $monitoring_boxsizer->Add( $monitoring_sizer, 0, wxALL, 10 ); | ||
| 518 | |||
| 519 | # panel 2 sizer | ||
| 520 | my $panel_2_sizer = Wx::FlexGridSizer->new(3,1,10); # rows,cols,vgap,hgap | ||
| 521 | $panel_2_sizer->AddGrowableCol(0); # zerobased | ||
| 522 | $panel_2_sizer->Add($behaviour_boxsizer, 1, wxGROW); | ||
| 523 | $panel_2_sizer->Add($sorting_boxsizer, 1, wxGROW); | ||
| 524 | $panel_2_sizer->Add($monitoring_boxsizer, 1, wxGROW); | ||
| 525 | |||
| 526 | $panel_2->SetSizer($panel_2_sizer); | ||
| 527 | |||
| 528 | # panel 2 events | ||
| 529 | EVT_CHECKBOX($self, $check_offer_delete, sub { | ||
| 530 | $self->{wrangler}->config()->{'ui.filebrowser.offer.delete'} = $_[1]->IsChecked() || 0; | ||
| 531 | }); | ||
| 532 | EVT_CHECKBOX($self, $check_confirm_delete, sub { | ||
| 533 | $self->{wrangler}->config()->{'ui.filebrowser.confirm.delete'} = $_[1]->IsChecked() || 0; | ||
| 534 | }); | ||
| 535 | EVT_CHECKBOX($self, $check_copy_preserves, sub { | ||
| 536 | $self->{wrangler}->config()->{'ui.filebrowser.copy.preserve_xattribs'} = $_[1]->IsChecked() || 0; | ||
| 537 | }); | ||
| 538 | EVT_CHECKBOX($self, $check_per_directory_sorting, sub { | ||
| 539 | $self->{wrangler}->config()->{'ui.filebrowser.sorting.per_directory'} = $_[1]->IsChecked() || 0; | ||
| 540 | $self->{wrangler}->config()->{'ui.filebrowser.sort'} = {} if ref($self->{wrangler}->config()->{'ui.filebrowser.sort'}) eq 'ARRAY'; | ||
| 541 | }); | ||
| 542 | EVT_TEXT($self, $monitoring_pull_timeout, sub { | ||
| 543 | my $value = int($monitoring_pull_timeout->GetValue()); | ||
| 544 | if($value && $value != 7){ | ||
| 545 | Wrangler::debug("Settings::FileBrowser: pull_monitor_timeout $value"); | ||
| 546 | $_[0]->{wrangler}->config()->{'ui.filebrowser.pull_monitor_timeout'} = ($value * 1000); | ||
| 547 | }else{ | ||
| 548 | Wrangler::debug("Settings::FileBrowser: remove custom pull_monitor_timeout"); | ||
| 549 | my $config = $_[0]->{wrangler}->config(); | ||
| 550 | delete($config->{'ui.filebrowser.pull_monitor_timeout'}); | ||
| 551 | } | ||
| 552 | }); | ||
| 553 | |||
| 554 | ## Panel 3 | ||
| 555 | my $panel_3 = Wx::Panel->new($self); | ||
| 556 | $self->AddPage( $panel_3, "Columns", 0); | ||
| 557 | |||
| 558 | # columns | ||
| 559 | $self->{listctrl} = Wx::ListCtrl->new($panel_3, -1, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_EDIT_LABELS); | ||
| 560 | $self->{listctrl}->InsertColumn( 1, 'Column label', wxLIST_FORMAT_LEFT, 120 ); | ||
| 561 | $self->{listctrl}->InsertColumn( 2, 'Source metadata', wxLIST_FORMAT_LEFT, 170 ); | ||
| 562 | $self->{listctrl}->InsertColumn( 3, 'Width', wxLIST_FORMAT_LEFT, 80 ); | ||
| 563 | $self->{listctrl}->InsertColumn( 3, 'Align', wxLIST_FORMAT_LEFT, 80 ); | ||
| 564 | |||
| 565 | my $sizer = Wx::FlexGridSizer->new(3, 1, 0, 0); # rows,cols,vgap,hgap | ||
| 566 | $sizer->AddGrowableCol(0); # zerobased | ||
| 567 | $sizer->AddGrowableRow(0); # zerobased | ||
| 568 | $sizer->Add($self->{listctrl}, 0, wxALL|wxGROW, 5); | ||
| 569 | |||
| 570 | $panel_3->SetSizer($sizer); | ||
| 571 | |||
| 572 | EVT_LIST_ITEM_ACTIVATED($self, $self->{listctrl}, sub { | ||
| 573 | Wrangler::debug("Settings::FileBrowser: columns row activated:"); | ||
| 574 | |||
| 575 | $self->Rename(); | ||
| 576 | }); | ||
| 577 | EVT_LIST_ITEM_SELECTED($self, $self->{listctrl}, sub { | ||
| 578 | print "Row selected:\n"; | ||
| 579 | $_[1]->Skip(1); | ||
| 580 | }); | ||
| 581 | EVT_LIST_ITEM_RIGHT_CLICK($self, $self->{listctrl}, sub { print "OnRightClick: @_\n"; OnRightClick(@_); }); | ||
| 582 | EVT_LIST_BEGIN_DRAG($self, $self->{listctrl}, sub { | ||
| 583 | print "OnBeginDrag: @_\n"; | ||
| 584 | }); | ||
| 585 | |||
| 586 | $self->Populate(); | ||
| 587 | |||
| 588 | |||
| 589 | ## Panel 4 default viewers/applications/commands | ||
| 590 | $self->AddPage( Wrangler::Wx::Dialog::Settings::FileBrowser::Viewers->new($self), "View/open with", 0); | ||
| 591 | |||
| 592 | return $self; | ||
| 593 | } | ||
| 594 | |||
| 595 | sub Populate { | ||
| 596 | my $settings = shift; | ||
| 597 | my $columns = $settings->{wrangler}->config()->{'ui.filebrowser.columns'} || []; | ||
| 598 | |||
| 599 | $settings->{listctrl}->DeleteAllItems(); | ||
| 600 | |||
| 601 | my $prop_ref = $settings->{wrangler}->{fs}->available_properties($settings->{wrangler}->{current_dir}); | ||
| 602 | |||
| 603 | my %used; | ||
| 604 | my $rowCnt = 0; | ||
| 605 | for(@$columns){ | ||
| 606 | $used{ $_->{value_from} } = $_; | ||
| 607 | |||
| 608 | # InsertItem returns a numeric $itemId | ||
| 609 | my $itemId = $settings->{listctrl}->InsertStringItem( $rowCnt, $_->{label}); | ||
| 610 | $settings->{listctrl}->SetItem( $itemId, 1, $_->{value_from} ); | ||
| 611 | $settings->{listctrl}->SetItem( $itemId, 2, $_->{width} ); | ||
| 612 | $settings->{listctrl}->SetItem( $itemId, 3, $_->{text_align} ); | ||
| 613 | $rowCnt++; | ||
| 614 | } | ||
| 615 | |||
| 616 | my $i=0; | ||
| 617 | for(@$prop_ref){ | ||
| 618 | unless($used{ $_ }){ | ||
| 619 | my $itemId = $settings->{listctrl}->InsertStringItem( $rowCnt, '' ); | ||
| 620 | $settings->{listctrl}->SetItem( $itemId, 1, $_ ); | ||
| 621 | $settings->{listctrl}->SetItemTextColour($itemId, Wx::Colour->new(128,128,128)); | ||
| 622 | $settings->{listctrl}->SetItemData($itemId, $i); | ||
| 623 | } | ||
| 624 | $rowCnt++; | ||
| 625 | $i++; | ||
| 626 | } | ||
| 627 | } | ||
| 628 | |||
| 629 | sub GetSelections { | ||
| 630 | return () unless $_[0]->{listctrl}->GetSelectedItemCount(); # untested optimisation | ||
| 631 | |||
| 632 | my @selections; | ||
| 633 | my $currId = -1; | ||
| 634 | for(;;){ | ||
| 635 | $currId = $_[0]->{listctrl}->GetNextItem($currId, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); | ||
| 636 | if($currId == -1){ | ||
| 637 | last; | ||
| 638 | }else{ | ||
| 639 | push(@selections, $currId); | ||
| 640 | } | ||
| 641 | } | ||
| 642 | |||
| 643 | return wantarray ? @selections : \@selections; | ||
| 644 | } | ||
| 645 | |||
| 646 | # compare AddField() in Wrangler::Wx::FormEditor | ||
| 647 | sub Add { | ||
| 648 | my $settings = shift; | ||
| 649 | my $field_name = shift; | ||
| 650 | |||
| 651 | unless($field_name){ | ||
| 652 | my $dialog = Wx::TextEntryDialog->new($settings, "Add this field to columns", "Add this field to columns", ""); | ||
| 653 | return if $dialog->ShowModal == wxID_CANCEL; | ||
| 654 | |||
| 655 | $field_name = $dialog->GetValue() ; | ||
| 656 | |||
| 657 | $dialog->Destroy(); | ||
| 658 | } | ||
| 659 | |||
| 660 | return if $field_name eq ''; | ||
| 661 | |||
| 662 | my $columns = $settings->{wrangler}->config()->{'ui.filebrowser.columns'}; | ||
| 663 | |||
| 664 | push(@$columns, { | ||
| 665 | label => $field_name, | ||
| 666 | value_from => $field_name, | ||
| 667 | text_align => 'left', | ||
| 668 | width => 50 | ||
| 669 | }); | ||
| 670 | |||
| 671 | $settings->Populate(); | ||
| 672 | Wrangler::PubSub::publish('filebrowser.refresh.all'); | ||
| 673 | } | ||
| 674 | |||
| 675 | sub AddFromList { | ||
| 676 | my $settings = shift; | ||
| 677 | |||
| 678 | my @selections = $settings->GetSelections(); | ||
| 679 | my $pos = $settings->{listctrl}->GetItemData($selections[0]); | ||
| 680 | |||
| 681 | my $columns = $settings->{wrangler}->config()->{'ui.filebrowser.columns'}; | ||
| 682 | my $prop_ref = $settings->{wrangler}->{fs}->available_properties($settings->{wrangler}->{current_dir}); | ||
| 683 | my $metakey = $prop_ref->[$pos]; | ||
| 684 | my $label = $metakey; | ||
| 685 | |||
| 686 | push(@$columns, { | ||
| 687 | label => $metakey, | ||
| 688 | value_from => $metakey, | ||
| 689 | text_align => 'left', | ||
| 690 | width => 50 | ||
| 691 | }); | ||
| 692 | |||
| 693 | $settings->Populate(); | ||
| 694 | Wrangler::PubSub::publish('filebrowser.refresh.all'); | ||
| 695 | } | ||
| 696 | |||
| 697 | sub Move { | ||
| 698 | my $settings = shift; | ||
| 699 | my $direction = shift; | ||
| 700 | |||
| 701 | my @selections = $settings->GetSelections(); | ||
| 702 | |||
| 703 | my $id = $settings->{listctrl}->GetItem($selections[0]); | ||
| 704 | my $pos = $id->GetId; | ||
| 705 | my $new_pos = $direction eq 'up' | ||
| 706 | ? $pos == 0 ? $pos : ($pos -1) | ||
| 707 | : $settings->{listctrl}->GetItemCount == $pos + 1 ? $pos : ($pos + 1); | ||
| 708 | |||
| 709 | my $columns = $settings->{wrangler}->config()->{'ui.filebrowser.columns'}; | ||
| 710 | |||
| 711 | # print "MOVE: '$direction': $id, $pos -> $new_pos\n"; | ||
| 712 | my $ref = ${ $columns }[$pos]; | ||
| 713 | splice(@$columns,$pos,1); # remove pos from array | ||
| 714 | splice(@$columns,$new_pos, 0, $ref); # ...and insert at new_pos | ||
| 715 | |||
| 716 | $settings->Populate(); | ||
| 717 | Wrangler::PubSub::publish('filebrowser.refresh.all'); | ||
| 718 | } | ||
| 719 | |||
| 720 | sub Rename { | ||
| 721 | my $settings = shift; | ||
| 722 | |||
| 723 | my @selections = $settings->GetSelections(); | ||
| 724 | my $id = $settings->{listctrl}->GetItem($selections[0]); | ||
| 725 | my $pos = $id->GetId; | ||
| 726 | |||
| 727 | my $columns = $settings->{wrangler}->config()->{'ui.filebrowser.columns'}; | ||
| 728 | |||
| 729 | my $dialog = Wx::TextEntryDialog->new( $settings, "Rename column", "Rename column", $columns->[$pos]->{label} ); | ||
| 730 | |||
| 731 | unless( $dialog->ShowModal == wxID_CANCEL ){ | ||
| 732 | my $newlabel = $dialog->GetValue(); | ||
| 733 | |||
| 734 | $columns->[$pos]->{label} = $newlabel; | ||
| 735 | |||
| 736 | $settings->Populate(); | ||
| 737 | Wrangler::PubSub::publish('filebrowser.refresh.all'); | ||
| 738 | } | ||
| 739 | |||
| 740 | $dialog->Destroy(); | ||
| 741 | } | ||
| 742 | |||
| 743 | sub ResetWidth { | ||
| 744 | my $settings = shift; | ||
| 745 | |||
| 746 | my @selections = $settings->GetSelections(); | ||
| 747 | my $id = $settings->{listctrl}->GetItem($selections[0]); | ||
| 748 | my $pos = $id->GetId; | ||
| 749 | |||
| 750 | my $columns = $settings->{wrangler}->config()->{'ui.filebrowser.columns'}; | ||
| 751 | |||
| 752 | $columns->[$pos]->{width} = undef; | ||
| 753 | |||
| 754 | $settings->Populate(); | ||
| 755 | Wrangler::PubSub::publish('filebrowser.refresh.all'); | ||
| 756 | } | ||
| 757 | |||
| 758 | sub ToggleAlign { | ||
| 759 | my $settings = shift; | ||
| 760 | |||
| 761 | my @selections = $settings->GetSelections(); | ||
| 762 | my $id = $settings->{listctrl}->GetItem($selections[0]); | ||
| 763 | my $pos = $id->GetId; | ||
| 764 | |||
| 765 | my $columns = $settings->{wrangler}->config()->{'ui.filebrowser.columns'}; | ||
| 766 | |||
| 767 | $columns->[$pos]->{text_align} = $columns->[$pos]->{text_align} && $columns->[$pos]->{text_align} eq 'right' ? 'left' : 'right'; | ||
| 768 | |||
| 769 | $settings->Populate(); | ||
| 770 | Wrangler::PubSub::publish('filebrowser.refresh.all'); | ||
| 771 | } | ||
| 772 | |||
| 773 | sub Remove { | ||
| 774 | my $settings = shift; | ||
| 775 | |||
| 776 | my @selections = $settings->GetSelections(); | ||
| 777 | |||
| 778 | my $id = $settings->{listctrl}->GetItem($selections[0]); | ||
| 779 | my $pos = $id->GetId; | ||
| 780 | |||
| 781 | my $columns = $settings->{wrangler}->config()->{'ui.filebrowser.columns'}; | ||
| 782 | |||
| 783 | my $ref = ${ $columns }[$pos]; | ||
| 784 | splice(@$columns,$pos,1); # remove pos from array | ||
| 785 | |||
| 786 | $settings->Populate(); | ||
| 787 | Wrangler::PubSub::publish('filebrowser.refresh.all'); | ||
| 788 | } | ||
| 789 | |||
| 790 | sub OnRightClick { | ||
| 791 | my $settings = shift; | ||
| 792 | my $event = shift; | ||
| 793 | |||
| 794 | my $menu = Wx::Menu->new(); | ||
| 795 | |||
| 796 | my @selections = $settings->GetSelections(); | ||
| 797 | |||
| 798 | if( defined($selections[0]) && $settings->{listctrl}->GetItemData( $selections[0] ) ){ | ||
| 799 | EVT_MENU( $settings, $menu->Append(-1, "Show this column", 'Show this column' ), sub { $settings->AddFromList(); } ); | ||
| 800 | }else{ | ||
| 801 | EVT_MENU( $settings, $menu->Append(-1, "Move up", 'Move column up' ), sub { $settings->Move('up'); } ); | ||
| 802 | EVT_MENU( $settings, $menu->Append(-1, "Move down", 'Move column down' ), sub { $settings->Move('down'); } ); | ||
| 803 | $menu->AppendSeparator(); | ||
| 804 | EVT_MENU( $settings, $menu->Append(-1, "Change label", 'Rename this column' ), sub { $settings->Rename(); } ); | ||
| 805 | # EVT_MENU( $settings, $menu->Append(-1, "Reset width", 'Reset width of this column' ), sub { $settings->ResetWidth(); } ); | ||
| 806 | EVT_MENU( $settings, $menu->Append(-1, "Toggle align", 'Change between text align left and right' ), sub { $settings->ToggleAlign(); } ); | ||
| 807 | $menu->AppendSeparator(); | ||
| 808 | EVT_MENU( $settings, $menu->Append(-1, "Hide this column", 'Remove this column' ), sub { $settings->Remove(); } ); | ||
| 809 | } | ||
| 810 | $menu->AppendSeparator(); | ||
| 811 | EVT_MENU( $settings, $menu->Append(-1, "Add column not on list...", 'Add a metadata key which is not on the list' ), sub { $settings->Add(); } ); | ||
| 812 | |||
| 813 | $settings->PopupMenu( $menu, wxDefaultPosition ); # alt: $event->GetPosition | ||
| 814 | } | ||
| 815 | |||
| 816 | |||
| 817 | package Wrangler::Wx::Dialog::Settings::FileBrowser::Viewers; | ||
| 818 | |||
| 819 | use strict; | ||
| 820 | use warnings; | ||
| 821 | |||
| 822 | use Wx qw(wxDefaultPosition wxDefaultSize wxLIST_FORMAT_LEFT wxALL wxGROW wxLC_EDIT_LABELS wxLC_REPORT wxLIST_NEXT_ALL wxLIST_STATE_SELECTED wxID_OK); | ||
| 823 | use Wx::Event qw(EVT_LIST_ITEM_ACTIVATED EVT_LIST_ITEM_RIGHT_CLICK EVT_MENU); | ||
| 824 | use base 'Wx::Panel'; | ||
| 825 | |||
| 826 | sub new { | ||
| 827 | my $class = shift; | ||
| 828 | my $parent = shift; | ||
| 829 | |||
| 830 | my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize); | ||
| 831 | |||
| 832 | # hook up $wrangler for config | ||
| 833 | $self->{wrangler} = $parent->{wrangler}; | ||
| 834 | |||
| 835 | # columns | ||
| 836 | $self->{listctrl} = Wx::ListCtrl->new($self, -1, wxDefaultPosition, wxDefaultSize, wxLC_REPORT); | ||
| 837 | $self->{listctrl}->InsertColumn( 1, 'MIME-Type', wxLIST_FORMAT_LEFT, 250 ); | ||
| 838 | $self->{listctrl}->InsertColumn( 2, 'Command', wxLIST_FORMAT_LEFT, 250 ); | ||
| 839 | |||
| 840 | my $sizer = Wx::FlexGridSizer->new(3, 1, 0, 0); # rows,cols,vgap,hgap | ||
| 841 | $sizer->AddGrowableCol(0); # zerobased | ||
| 842 | $sizer->AddGrowableRow(0); # zerobased | ||
| 843 | $sizer->Add($self->{listctrl}, 0, wxALL|wxGROW, 5); | ||
| 844 | |||
| 845 | $self->SetSizer($sizer); | ||
| 846 | |||
| 847 | EVT_LIST_ITEM_ACTIVATED($self, $self->{listctrl}, sub { | ||
| 848 | Wrangler::debug("Settings::FileBrowser: columns row activated:"); | ||
| 849 | |||
| 850 | $self->Edit(); | ||
| 851 | }); | ||
| 852 | EVT_LIST_ITEM_RIGHT_CLICK($self, $self->{listctrl}, sub { print "OnRightClick: @_\n"; OnRightClick(@_); }); | ||
| 853 | |||
| 854 | $self->Populate(); | ||
| 855 | |||
| 856 | return $self; | ||
| 857 | } | ||
| 858 | |||
| 859 | sub Populate { | ||
| 860 | my $settings = shift; | ||
| 861 | my $viewers = $settings->{wrangler}->config()->{'openwith'} || []; | ||
| 862 | |||
| 863 | $settings->{listctrl}->DeleteAllItems(); | ||
| 864 | |||
| 865 | my %used; | ||
| 866 | my $rowCnt = 0; | ||
| 867 | for(keys %$viewers){ | ||
| 868 | my $itemId = $settings->{listctrl}->InsertStringItem( $rowCnt, $_); | ||
| 869 | $settings->{listctrl}->SetItem( $itemId, 1, $viewers->{$_} ); | ||
| 870 | $rowCnt++; | ||
| 871 | } | ||
| 872 | } | ||
| 873 | |||
| 874 | sub GetSelections { | ||
| 875 | return () unless $_[0]->{listctrl}->GetSelectedItemCount(); # untested optimisation | ||
| 876 | |||
| 877 | my @selections; | ||
| 878 | my $currId = -1; | ||
| 879 | for(;;){ | ||
| 880 | $currId = $_[0]->{listctrl}->GetNextItem($currId, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); | ||
| 881 | if($currId == -1){ | ||
| 882 | last; | ||
| 883 | }else{ | ||
| 884 | push(@selections, $currId); | ||
| 885 | } | ||
| 886 | } | ||
| 887 | |||
| 888 | return wantarray ? @selections : \@selections; | ||
| 889 | } | ||
| 890 | |||
| 891 | sub Edit { | ||
| 892 | my $settings = shift; | ||
| 893 | |||
| 894 | # Edit() works as Add() when nothing is selected | ||
| 895 | my $mime; | ||
| 896 | my @selections = $settings->GetSelections(); | ||
| 897 | if(@selections){ | ||
| 898 | my $id = $settings->{listctrl}->GetItem($selections[0]); | ||
| 899 | $mime = $id->GetText; | ||
| 900 | } | ||
| 901 | |||
| 902 | my $viewers = $settings->{wrangler}->config()->{'openwith'}; | ||
| 903 | |||
| 904 | my $dialog = Wx::TextEntryDialog->new($settings, "Enter a MIME-Type for this viewer", "Enter MIME-Type to associate", $mime ); | ||
| 905 | return unless $dialog->ShowModal() == wxID_OK; | ||
| 906 | my $newmime = $dialog->GetValue(); | ||
| 907 | $dialog->Destroy(); | ||
| 908 | |||
| 909 | # it's a change of MIME-Type | ||
| 910 | if($mime && $mime ne $newmime){ | ||
| 911 | $viewers->{$newmime} = $viewers->{$mime}; | ||
| 912 | delete($viewers->{$mime}); | ||
| 913 | } | ||
| 914 | $mime = $newmime; | ||
| 915 | |||
| 916 | $dialog = Wx::TextEntryDialog->new($settings, "Path to a binary/command to execute", "Enter application to launch for $mime", $viewers->{$mime} ); | ||
| 917 | return unless $dialog->ShowModal() == wxID_OK; | ||
| 918 | $viewers->{$mime} = $dialog->GetValue(); | ||
| 919 | $dialog->Destroy(); | ||
| 920 | |||
| 921 | $settings->Populate(); | ||
| 922 | } | ||
| 923 | |||
| 924 | sub Delete { | ||
| 925 | my $settings = shift; | ||
| 926 | |||
| 927 | my @selections = $settings->GetSelections(); | ||
| 928 | |||
| 929 | my $id = $settings->{listctrl}->GetItem($selections[0]); | ||
| 930 | my $mime = $id->GetText; | ||
| 931 | |||
| 932 | my $viewers = $settings->{wrangler}->config()->{'openwith'}; | ||
| 933 | delete($viewers->{$mime}); | ||
| 934 | |||
| 935 | $settings->Populate(); | ||
| 936 | } | ||
| 937 | |||
| 938 | sub OnRightClick { | ||
| 939 | my $settings = shift; | ||
| 940 | my $event = shift; | ||
| 941 | |||
| 942 | my $menu = Wx::Menu->new(); | ||
| 943 | |||
| 944 | my @selections = $settings->GetSelections(); | ||
| 945 | |||
| 946 | my $itemAdd = Wx::MenuItem->new($menu, -1, "Add MIME/viewer command", 'Add MIME/viewer command'); | ||
| 947 | my $itemEdit = Wx::MenuItem->new($menu, -1, "Edit this entry", 'Edit this entry'); | ||
| 948 | my $itemDelete = Wx::MenuItem->new($menu, -1, "Delete this entry", 'Delete this entry'); | ||
| 949 | $menu->Append($itemAdd); | ||
| 950 | $menu->AppendSeparator(); | ||
| 951 | $menu->Append($itemEdit); | ||
| 952 | $menu->AppendSeparator(); | ||
| 953 | $menu->Append($itemDelete); | ||
| 954 | |||
| 955 | if( defined($selections[0]) ){ | ||
| 956 | $menu->Enable($itemAdd->GetId(),0); | ||
| 957 | EVT_MENU( $settings, $itemEdit, sub { $settings->Edit(); } ); | ||
| 958 | EVT_MENU( $settings, $itemDelete, sub { $settings->Delete(); } ); | ||
| 959 | }else{ | ||
| 960 | EVT_MENU( $settings, $itemAdd, sub { $settings->Edit(); } ); | ||
| 961 | $menu->Enable($itemEdit->GetId(),0); | ||
| 962 | $menu->Enable($itemDelete->GetId(),0); | ||
| 963 | } | ||
| 964 | |||
| 965 | $settings->PopupMenu( $menu, wxDefaultPosition ); # alt: $event->GetPosition | ||
| 966 | } | ||
| 967 | |||
| 968 | |||
| 969 | package Wrangler::Wx::Dialog::Settings::Previewer; | ||
| 970 | |||
| 971 | use strict; | ||
| 972 | use warnings; | ||
| 973 | |||
| 974 | use Wx qw(wxVERTICAL wxHORIZONTAL wxDefaultPosition wxDefaultSize wxEXPAND wxBOTTOM wxALL wxRIGHT wxTOP); | ||
| 975 | use Wx::Event qw(EVT_TEXT); | ||
| 976 | use base 'Wx::Notebook'; | ||
| 977 | |||
| 978 | sub new { | ||
| 979 | my $class = shift; | ||
| 980 | my $parent = shift; | ||
| 981 | |||
| 982 | my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxEXPAND); | ||
| 983 | |||
| 984 | # hook up $wrangler for config | ||
| 985 | $self->{wrangler} = $parent->{wrangler}; | ||
| 986 | |||
| 987 | ## Panel 1 | ||
| 988 | my $panel_1 = Wx::Panel->new($self); | ||
| 989 | $self->AddPage( $panel_1, "Previewer", 0); | ||
| 990 | |||
| 991 | # preview settings | ||
| 992 | my $use_original_image_as_preview = Wx::TextCtrl->new($panel_1, -1, $self->{wrangler}->config()->{'ui.previewer.image.original_as_preview_max_size'} || 300); | ||
| 993 | |||
| 994 | my $input_sizer = Wx::BoxSizer->new(wxHORIZONTAL); | ||
| 995 | $input_sizer->Add( $use_original_image_as_preview, 0, wxRIGHT, 5 ); | ||
| 996 | $input_sizer->Add( Wx::StaticText->new($panel_1, -1, 'KB', wxDefaultPosition, wxDefaultSize), 1, wxTOP, 7); | ||
| 997 | |||
| 998 | my $load_original_timeout = Wx::TextCtrl->new($panel_1, -1, $self->{wrangler}->config()->{'ui.previewer.image.load_original_timeout'} || 800); | ||
| 999 | |||
| 1000 | my $input2_sizer = Wx::BoxSizer->new(wxHORIZONTAL); | ||
| 1001 | $input2_sizer->Add( $load_original_timeout, 0, wxRIGHT, 5 ); | ||
| 1002 | $input2_sizer->Add( Wx::StaticText->new($panel_1, -1, 'ms', wxDefaultPosition, wxDefaultSize), 1, wxTOP, 7); | ||
| 1003 | |||
| 1004 | my $preview_sizer = Wx::FlexGridSizer->new(2,1); # rows,cols,vgap,hgap | ||
| 1005 | $preview_sizer->Add( Wx::StaticText->new($panel_1, -1, "First, Previewer tries to extract embedded preview thumbnails\nfrom images. If that fails, Previewer falls back to using the actual\nfile as preview, which might slow down with large images. This\nvalue here caps this behaviour, by providing a size value for when\nPreviewer will not use the image on the first preview pass.", wxDefaultPosition, wxDefaultSize), 1, wxALL, 5); | ||
| 1006 | $preview_sizer->Add($input_sizer, 1, wxALL, 5); | ||
| 1007 | $preview_sizer->Add( Wx::StaticText->new($panel_1, -1, "Previewer will load the original/actual file after this amount\nof milliseconds, unless the user moves selection away.", wxDefaultPosition, wxDefaultSize), 1, wxALL, 5); | ||
| 1008 | $preview_sizer->Add($input2_sizer, 1, wxALL, 5); | ||
| 1009 | |||
| 1010 | my $image_boxsizer = Wx::StaticBoxSizer->new( Wx::StaticBox->new($panel_1, -1, "Image previewing"), wxVERTICAL); | ||
| 1011 | $image_boxsizer->Add( $preview_sizer, 0, wxALL, 10 ); | ||
| 1012 | |||
| 1013 | my $video_thumbpos = Wx::TextCtrl->new($panel_1, -1, $self->{wrangler}->config()->{'ui.previewer.video.default_thumbnail_position'} || 2); | ||
| 1014 | |||
| 1015 | my $input3_sizer = Wx::BoxSizer->new(wxHORIZONTAL); | ||
| 1016 | $input3_sizer->Add( $video_thumbpos, 0, wxRIGHT, 5 ); | ||
| 1017 | $input3_sizer->Add( Wx::StaticText->new($panel_1, -1, 'seconds', wxDefaultPosition, wxDefaultSize), 1, wxTOP, 7); | ||
| 1018 | |||
| 1019 | my $preview2_sizer = Wx::FlexGridSizer->new(2,1); # rows,cols,vgap,hgap | ||
| 1020 | $preview2_sizer->Add( Wx::StaticText->new($panel_1, -1, "By default, Previewer extracts a frame from videos at 2 seconds\ninto the video. This may be inappropriate for very short or\nlong videos, so you can provide a different value here.", wxDefaultPosition, wxDefaultSize), 1, wxALL, 5); | ||
| 1021 | $preview2_sizer->Add($input3_sizer, 1, wxALL, 5); | ||
| 1022 | |||
| 1023 | my $preview_boxsizer = Wx::StaticBoxSizer->new( Wx::StaticBox->new($panel_1, -1, "Video previewing"), wxVERTICAL); | ||
| 1024 | $preview_boxsizer->Add( $preview2_sizer, 0, wxALL, 10 ); | ||
| 1025 | |||
| 1026 | # panel 1 sizer | ||
| 1027 | my $panel_1_sizer = Wx::FlexGridSizer->new(1,1,10); # rows,cols,vgap,hgap | ||
| 1028 | $panel_1_sizer->AddGrowableCol(0); # zerobased | ||
| 1029 | $panel_1_sizer->Add($image_boxsizer, 1); | ||
| 1030 | $panel_1_sizer->Add($preview_boxsizer, 1); | ||
| 1031 | |||
| 1032 | $panel_1->SetSizer($panel_1_sizer); | ||
| 1033 | |||
| 1034 | EVT_TEXT($self, $use_original_image_as_preview, sub { | ||
| 1035 | my $value = int($use_original_image_as_preview->GetValue()); | ||
| 1036 | if($value && $value != 300){ | ||
| 1037 | Wrangler::debug("Settings::Previewer: original_as_preview cap $value"); | ||
| 1038 | $_[0]->{wrangler}->config()->{'ui.previewer.image.original_as_preview_max_size'} = $value; | ||
| 1039 | }else{ | ||
| 1040 | Wrangler::debug("Settings::Previewer: remove custom original_as_preview cap"); | ||
| 1041 | my $config = $_[0]->{wrangler}->config(); | ||
| 1042 | delete($config->{'ui.previewer.image.original_as_preview_max_size'}); | ||
| 1043 | } | ||
| 1044 | }); | ||
| 1045 | EVT_TEXT($self, $load_original_timeout, sub { | ||
| 1046 | my $value = int($load_original_timeout->GetValue()); | ||
| 1047 | if($value && $value != 800){ | ||
| 1048 | Wrangler::debug("Settings::Previewer: load_original_timeout $value"); | ||
| 1049 | $_[0]->{wrangler}->config()->{'ui.previewer.image.load_original_timeout'} = $value; | ||
| 1050 | }else{ | ||
| 1051 | Wrangler::debug("Settings::Previewer: remove custom load_original_timeout"); | ||
| 1052 | my $config = $_[0]->{wrangler}->config(); | ||
| 1053 | delete($config->{'ui.previewer.image.load_original_timeout'}); | ||
| 1054 | } | ||
| 1055 | }); | ||
| 1056 | EVT_TEXT($self, $video_thumbpos, sub { | ||
| 1057 | my $value = int($video_thumbpos->GetValue()); | ||
| 1058 | if($value && $value != 2){ | ||
| 1059 | Wrangler::debug("Settings::Previewer: thumbpos at $value"); | ||
| 1060 | $_[0]->{wrangler}->config()->{'ui.previewer.video.default_thumbnail_position'} = $value; | ||
| 1061 | }else{ | ||
| 1062 | Wrangler::debug("Settings::Previewer: remove custom thumbpos"); | ||
| 1063 | my $config = $_[0]->{wrangler}->config(); | ||
| 1064 | delete($config->{'ui.previewer.video.default_thumbnail_position'}); | ||
| 1065 | } | ||
| 1066 | }); | ||
| 1067 | |||
| 1068 | return $self; | ||
| 1069 | } | ||
| 1070 | |||
| 1071 | |||
| 1072 | package Wrangler::Wx::Dialog::Settings::Plugins; | ||
| 1073 | |||
| 1074 | use strict; | ||
| 1075 | use warnings; | ||
| 1076 | |||
| 1077 | use Wx qw(wxVERTICAL wxID_OK wxCLOSE_BOX wxDEFAULT_DIALOG_STYLE wxRESIZE_BORDER wxDefaultPosition wxDefaultSize wxEXPAND wxBOTTOM wxALL wxLIST_FORMAT_LEFT wxLC_REPORT wxGROW wxLIST_NEXT_ALL wxLIST_STATE_SELECTED); | ||
| 1078 | use Wx::Event qw(EVT_BUTTON EVT_MENU EVT_LIST_ITEM_ACTIVATED EVT_LIST_ITEM_SELECTED EVT_LIST_ITEM_RIGHT_CLICK); | ||
| 1079 | use base 'Wx::Notebook'; | ||
| 1080 | |||
| 1081 | sub new { | ||
| 1082 | my $class = shift; | ||
| 1083 | my $parent = shift; | ||
| 1084 | |||
| 1085 | my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxEXPAND); | ||
| 1086 | |||
| 1087 | # hook up $wrangler for config | ||
| 1088 | $self->{wrangler} = $parent->{wrangler}; | ||
| 1089 | |||
| 1090 | ## Panel 1 | ||
| 1091 | my $panel_1 = Wx::Panel->new($self); | ||
| 1092 | $self->AddPage( $panel_1, "Plugins", 0); | ||
| 1093 | |||
| 1094 | # columns | ||
| 1095 | $self->{listctrl} = Wx::ListCtrl->new($panel_1, -1, wxDefaultPosition, wxDefaultSize, wxLC_REPORT); | ||
| 1096 | $self->{listctrl}->InsertColumn( 1, 'Plugin name', wxLIST_FORMAT_LEFT, 200 ); | ||
| 1097 | $self->{listctrl}->InsertColumn( 2, 'Scope', wxLIST_FORMAT_LEFT, 200 ); | ||
| 1098 | |||
| 1099 | my $sizer = Wx::FlexGridSizer->new(2, 1, 20, 0); # rows,cols,vgap,hgap | ||
| 1100 | $sizer->AddGrowableCol(0); # zerobased | ||
| 1101 | $sizer->AddGrowableRow(0); # zerobased | ||
| 1102 | $sizer->Add($self->{listctrl}, 0, wxALL|wxGROW, 5); | ||
| 1103 | |||
| 1104 | $panel_1->SetSizer($sizer); | ||
| 1105 | |||
| 1106 | ## Panel 2 events | ||
| 1107 | EVT_LIST_ITEM_ACTIVATED($self, $self->{listctrl}, sub { $self->ShowPluginSettings(@_); }); | ||
| 1108 | EVT_LIST_ITEM_RIGHT_CLICK($self, $self->{listctrl}, sub { OnRightClick(@_); }); | ||
| 1109 | |||
| 1110 | $self->Populate(); | ||
| 1111 | |||
| 1112 | return $self; | ||
| 1113 | } | ||
| 1114 | |||
| 1115 | sub GetSelections { | ||
| 1116 | return () unless $_[0]->{listctrl}->GetSelectedItemCount(); # untested optimisation | ||
| 1117 | |||
| 1118 | my @selections; | ||
| 1119 | my $currId = -1; | ||
| 1120 | for(;;){ | ||
| 1121 | $currId = $_[0]->{listctrl}->GetNextItem($currId, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); | ||
| 1122 | if($currId == -1){ | ||
| 1123 | last; | ||
| 1124 | }else{ | ||
| 1125 | push(@selections, $currId); | ||
| 1126 | } | ||
| 1127 | } | ||
| 1128 | |||
| 1129 | return wantarray ? @selections : \@selections; | ||
| 1130 | } | ||
| 1131 | |||
| 1132 | sub Populate { | ||
| 1133 | my $settings = shift; | ||
| 1134 | my $plugins = Wrangler::PluginManager::plugins(); | ||
| 1135 | |||
| 1136 | $settings->{listctrl}->DeleteAllItems(); | ||
| 1137 | |||
| 1138 | my $rowCnt = 0; | ||
| 1139 | for(@$plugins){ | ||
| 1140 | my $itemId = $settings->{listctrl}->InsertStringItem( $rowCnt, $_->plugin_name() ); | ||
| 1141 | $settings->{listctrl}->SetItem( $itemId, 1, join(', ', keys %{ $_->plugin_phases() }) ); | ||
| 1142 | $settings->{listctrl}->SetItemTextColour($itemId, Wx::Colour->new(128,128,128)) unless Wrangler::PluginManager::is_enabled($_->plugin_name()); | ||
| 1143 | $rowCnt++; | ||
| 1144 | } | ||
| 1145 | } | ||
| 1146 | |||
| 1147 | sub ShowInfo { | ||
| 1148 | my $settings = shift; | ||
| 1149 | |||
| 1150 | my @selections = $settings->GetSelections(); | ||
| 1151 | my $id = $settings->{listctrl}->GetItem($selections[0]); | ||
| 1152 | my $pos = $id->GetId; | ||
| 1153 | |||
| 1154 | my $plugins = Wrangler::PluginManager::plugins(); | ||
| 1155 | my $plugin = $plugins->[$pos]; | ||
| 1156 | |||
| 1157 | my $dialog = Wx::Dialog->new($settings, -1, $plugin->plugin_name()." Plugin Info", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxCLOSE_BOX ); | ||
| 1158 | my $sizer = Wx::FlexGridSizer->new(3, 1, 0, 0); # rows,cols,vgap,hgap | ||
| 1159 | $sizer->AddGrowableCol(0); # zerobased | ||
| 1160 | $sizer->AddGrowableRow(0); # zerobased | ||
| 1161 | $sizer->Add( Wx::StaticText->new($dialog, -1, $plugin->plugin_info(), wxDefaultPosition, wxDefaultSize), 0, wxEXPAND|wxALL, 10 ); | ||
| 1162 | $sizer->Add(Wx::Button->new($dialog, wxID_OK, 'OK'), 0, wxALL, 2); | ||
| 1163 | $dialog->SetSizer($sizer); | ||
| 1164 | |||
| 1165 | return unless $dialog->ShowModal() == wxID_OK; | ||
| 1166 | } | ||
| 1167 | |||
| 1168 | sub ShowPluginSettings { | ||
| 1169 | my $settings = shift; | ||
| 1170 | |||
| 1171 | my @selections = $settings->GetSelections(); | ||
| 1172 | my $id = $settings->{listctrl}->GetItem($selections[0]); | ||
| 1173 | my $pos = $id->GetId; | ||
| 1174 | |||
| 1175 | my $plugins = Wrangler::PluginManager::plugins(); | ||
| 1176 | my $plugin = $plugins->[$pos]; | ||
| 1177 | |||
| 1178 | my $dialog = Wx::Dialog->new($settings, -1, $plugin->plugin_name()." Plugin Settings", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCLOSE_BOX | wxRESIZE_BORDER ); | ||
| 1179 | |||
| 1180 | # plugins must return a $sizer via plugin_settings() | ||
| 1181 | $dialog->SetSizer( $plugin->plugin_settings($dialog) ); | ||
| 1182 | |||
| 1183 | return unless $dialog->ShowModal() == wxID_OK; | ||
| 1184 | } | ||
| 1185 | |||
| 1186 | sub Enable { | ||
| 1187 | my $settings = shift; | ||
| 1188 | |||
| 1189 | my @selections = $settings->GetSelections(); | ||
| 1190 | my $id = $settings->{listctrl}->GetItem($selections[0]); | ||
| 1191 | # my $pos = $id->GetId; | ||
| 1192 | my $plugin_name = $id->GetText; | ||
| 1193 | |||
| 1194 | Wrangler::PluginManager::enable_plugin($plugin_name); | ||
| 1195 | |||
| 1196 | $settings->Populate(); | ||
| 1197 | } | ||
| 1198 | |||
| 1199 | sub Disable { | ||
| 1200 | my $settings = shift; | ||
| 1201 | |||
| 1202 | my @selections = $settings->GetSelections(); | ||
| 1203 | my $id = $settings->{listctrl}->GetItem($selections[0]); | ||
| 1204 | # my $pos = $id->GetId; | ||
| 1205 | my $plugin_name = $id->GetText; | ||
| 1206 | |||
| 1207 | Wrangler::PluginManager::disable_plugin($plugin_name); | ||
| 1208 | |||
| 1209 | $settings->Populate(); | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | sub OnRightClick { | ||
| 1213 | my $settings = shift; | ||
| 1214 | my $event = shift; | ||
| 1215 | |||
| 1216 | my $menu = Wx::Menu->new(); | ||
| 1217 | |||
| 1218 | my @selections = $settings->GetSelections(); | ||
| 1219 | |||
| 1220 | my $itemInfo = Wx::MenuItem->new($menu, -1, "Show info"); | ||
| 1221 | my $itemPluginSettings = Wx::MenuItem->new($menu, -1, "Show settings"); | ||
| 1222 | my $itemEnable = Wx::MenuItem->new($menu, -1, "Enable this Plugin"); | ||
| 1223 | my $itemDisable = Wx::MenuItem->new($menu, -1, "Disable this Plugin"); | ||
| 1224 | $menu->Append($itemInfo); | ||
| 1225 | $menu->Append($itemPluginSettings); | ||
| 1226 | $menu->AppendSeparator(); | ||
| 1227 | $menu->Append($itemEnable); | ||
| 1228 | $menu->Append($itemDisable); | ||
| 1229 | |||
| 1230 | if( defined($selections[0]) ){ | ||
| 1231 | my $id = $settings->{listctrl}->GetItem($selections[0]); | ||
| 1232 | my $plugin_name = $id->GetText; | ||
| 1233 | |||
| 1234 | # my $plugins = Wrangler::PluginManager::plugins(); | ||
| 1235 | # my $plugin = $plugins->[$pos]; | ||
| 1236 | |||
| 1237 | $menu->Enable($itemInfo->GetId(),1); | ||
| 1238 | EVT_MENU( $settings, $itemInfo, sub { $settings->ShowInfo(); } ); | ||
| 1239 | EVT_MENU( $settings, $itemPluginSettings, sub { $settings->ShowPluginSettings(); } ); | ||
| 1240 | # unless( Wrangler::PluginManager::is_enabled($pos) ){ | ||
| 1241 | unless( Wrangler::PluginManager::is_enabled($plugin_name) ){ | ||
| 1242 | $menu->Enable($itemEnable->GetId(),1); | ||
| 1243 | $menu->Enable($itemDisable->GetId(),0); | ||
| 1244 | EVT_MENU( $settings, $itemEnable, sub { $settings->Enable(); } ); | ||
| 1245 | }else{ | ||
| 1246 | $menu->Enable($itemEnable->GetId(),0); | ||
| 1247 | $menu->Enable($itemDisable->GetId(),1); | ||
| 1248 | EVT_MENU( $settings, $itemDisable, sub { $settings->Disable(); } ); | ||
| 1249 | } | ||
| 1250 | }else{ | ||
| 1251 | $menu->Enable($itemInfo->GetId(),0); | ||
| 1252 | $menu->Enable($itemEnable->GetId(),0); | ||
| 1253 | $menu->Enable($itemDisable->GetId(),0); | ||
| 1254 | } | ||
| 1255 | |||
| 1256 | $settings->PopupMenu( $menu, wxDefaultPosition ); # alt: $event->GetPosition | ||
| 1257 | } | ||
| 1258 | |||
| 1259 | 1; |