Class: Glimmer::Gladiator

Inherits:
Object
  • Object
show all
Includes:
UI::CustomShell
Defined in:
lib/views/glimmer/gladiator.rb,
lib/models/glimmer/gladiator/dir.rb,
lib/models/glimmer/gladiator/file.rb,
lib/models/glimmer/gladiator/command.rb,
lib/views/glimmer/gladiator/text_editor.rb,
lib/views/glimmer/gladiator/file_edit_menu.rb,
lib/views/glimmer/gladiator/progress_shell.rb,
lib/views/glimmer/gladiator/file_lookup_list.rb,
lib/views/glimmer/gladiator/file_explorer_tree.rb,
lib/views/glimmer/gladiator/gladiator_menu_bar.rb

Overview

Gladiator (Glimmer Editor)

Defined Under Namespace

Classes: Command, Dir, File, FileEditMenu, FileExplorerTree, FileLookupList, GladiatorMenuBar, ProgressShell, TextEditor

Constant Summary collapse

APP_ROOT =
::File.expand_path('../../../..', __FILE__)
COMMAND_KEY =

TODO make sure COMMAND_KEY doesn’t clash on Linux/Windows for CMD+CTRL shortcuts

OS.mac? ? :command : :ctrl
CONTROL_KEY =
OS.mac? ? :ctrl : :alt
VERSION =
::File.read(::File.join(APP_ROOT, 'VERSION')).to_s.strip
LICENSE =
::File.read(::File.join(APP_ROOT, 'LICENSE.txt')).to_s.strip
ICON =
::File.expand_path(::File.join(APP_ROOT, 'images', 'glimmer-cs-gladiator-logo.png'))

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.dragObject

Returns the value of attribute drag.



54
55
56
# File 'lib/views/glimmer/gladiator.rb', line 54

def drag
  @drag
end

.drag_and_dropObject

Returns the value of attribute drag_and_drop.



53
54
55
# File 'lib/views/glimmer/gladiator.rb', line 53

def drag_and_drop
  @drag_and_drop
end

.startupObject

Returns the value of attribute startup.



55
56
57
# File 'lib/views/glimmer/gladiator.rb', line 55

def startup
  @startup
end

Instance Attribute Details

#current_tab_folderObject

Returns the value of attribute current_tab_folder.



66
67
68
# File 'lib/views/glimmer/gladiator.rb', line 66

def current_tab_folder
  @current_tab_folder
end

#current_tab_itemObject

Returns the value of attribute current_tab_item.



66
67
68
# File 'lib/views/glimmer/gladiator.rb', line 66

def current_tab_item
  @current_tab_item
end

#current_text_editorObject

Returns the value of attribute current_text_editor.



66
67
68
# File 'lib/views/glimmer/gladiator.rb', line 66

def current_text_editor
  @current_text_editor
end

#file_area_and_editor_area_sash_formObject (readonly)

Returns the value of attribute file_area_and_editor_area_sash_form.



65
66
67
# File 'lib/views/glimmer/gladiator.rb', line 65

def file_area_and_editor_area_sash_form
  @file_area_and_editor_area_sash_form
end

#file_explorer_expand_itemObject (readonly)

Returns the value of attribute file_explorer_expand_item.



65
66
67
# File 'lib/views/glimmer/gladiator.rb', line 65

def file_explorer_expand_item
  @file_explorer_expand_item
end

#file_explorer_expand_item_heightObject (readonly)

Returns the value of attribute file_explorer_expand_item_height.



65
66
67
# File 'lib/views/glimmer/gladiator.rb', line 65

def file_explorer_expand_item_height
  @file_explorer_expand_item_height
end

#file_lookup_expand_itemObject (readonly)

Returns the value of attribute file_lookup_expand_item.



65
66
67
# File 'lib/views/glimmer/gladiator.rb', line 65

def file_lookup_expand_item
  @file_lookup_expand_item
end

#file_lookup_expand_item_heightObject (readonly)

Returns the value of attribute file_lookup_expand_item_height.



65
66
67
# File 'lib/views/glimmer/gladiator.rb', line 65

def file_lookup_expand_item_height
  @file_lookup_expand_item_height
end

#filter_textObject (readonly)

Returns the value of attribute filter_text.



65
66
67
# File 'lib/views/glimmer/gladiator.rb', line 65

def filter_text
  @filter_text
end

#find_textObject (readonly)

Returns the value of attribute find_text.



65
66
67
# File 'lib/views/glimmer/gladiator.rb', line 65

def find_text
  @find_text
end

#line_number_textObject (readonly)

Returns the value of attribute line_number_text.



65
66
67
# File 'lib/views/glimmer/gladiator.rb', line 65

def line_number_text
  @line_number_text
end

#maximized_editorObject Also known as: maximized_editor?

Returns the value of attribute maximized_editor.



66
67
68
# File 'lib/views/glimmer/gladiator.rb', line 66

def maximized_editor
  @maximized_editor
end

#maximized_paneObject Also known as: maximized_pane?

Returns the value of attribute maximized_pane.



66
67
68
# File 'lib/views/glimmer/gladiator.rb', line 66

def maximized_pane
  @maximized_pane
end

Returns the value of attribute side_bar_sash_form.



65
66
67
# File 'lib/views/glimmer/gladiator.rb', line 65

def side_bar_sash_form
  @side_bar_sash_form
end

#split_orientationObject

Returns the value of attribute split_orientation.



65
66
67
# File 'lib/views/glimmer/gladiator.rb', line 65

def split_orientation
  @split_orientation
end

#tab_folder1Object

Returns the value of attribute tab_folder1.



66
67
68
# File 'lib/views/glimmer/gladiator.rb', line 66

def tab_folder1
  @tab_folder1
end

#tab_folder2Object

Returns the value of attribute tab_folder2.



66
67
68
# File 'lib/views/glimmer/gladiator.rb', line 66

def tab_folder2
  @tab_folder2
end

#tab_folder_sash_formObject (readonly)

Returns the value of attribute tab_folder_sash_form.



65
66
67
# File 'lib/views/glimmer/gladiator.rb', line 65

def tab_folder_sash_form
  @tab_folder_sash_form
end

Instance Method Details

#app_mode?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/views/glimmer/gladiator.rb', line 92

def app_mode?
  project_dir_path == '.' && ENV['APP_MODE'].to_s == 'true' || !::Dir.glob(::File.join(project_dir_path, 'glimmer-cs-gladiator.jar')).empty?
end

#close_all_tabs(closing_tab_folder = nil) ⇒ Object



844
845
846
847
848
849
850
851
852
853
854
855
# File 'lib/views/glimmer/gladiator.rb', line 844

def close_all_tabs(closing_tab_folder = nil)
  closing_tab_folder ||= current_tab_folder
  closing_tab_folder.swt_widget.getItems.each do |tab_item|
    project_dir.selected_child_path_history.delete(tab_item.getData('file_path'))
    tab_item.getData('proxy')&.dispose
  end
  close_tab_folder(closing_tab_folder)
  if self.current_tab_item.nil?
    filter_text.swt_widget.selectAll
    filter_text.swt_widget.setFocus
  end
end

#close_tab_folder(closing_tab_folder = nil, single_tab: false) ⇒ Object



857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
# File 'lib/views/glimmer/gladiator.rb', line 857

def close_tab_folder(closing_tab_folder = nil, single_tab: false)
  closing_tab_folder ||= current_tab_folder
  if @tab_folder2 && !selected_tab_item
    if closing_tab_folder == @tab_folder2
      @tab_folder2.swt_widget.dispose
      self.current_tab_folder = @tab_folder1
    else
      @tab_folder1.swt_widget.dispose
      self.current_tab_folder = self.tab_folder1 = @tab_folder2
    end
    self.tab_folder2 = nil
    body_root.pack_same_size

    @current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
    @current_text_editor = @current_tab_item.swt_tab_item.getData('text_editor')
    project_dir.selected_child = @current_tab_item.swt_tab_item.getData('file')
    @current_text_editor&.text_widget&.setFocus
    async_exec { @current_text_editor&.text_widget&.setFocus }
  elsif !single_tab
    self.current_tab_item = self.current_text_editor = project_dir.selected_child = nil
  end
end

#collapse_navigation_expand_bar_heightObject



892
893
894
895
896
897
# File 'lib/views/glimmer/gladiator.rb', line 892

def collapse_navigation_expand_bar_height
  @navigation_expand_item_height = @navigation_expand_item.swt_expand_item.height if @navigation_expand_item.swt_expand_item.height > 0
  @navigation_expand_item.swt_expand_item.height = 0
  body_root.pack_same_size
  async_exec { body_root.pack_same_size }
end

#display_about_dialogObject



938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
# File 'lib/views/glimmer/gladiator.rb', line 938

def display_about_dialog
  dialog {
    grid_layout(2, false) {
      margin_width 15
      margin_height 15
    }
    
    background :white
    image ICON
    text 'About'
    
    label {
      layout_data :center, :center, false, false
      background :white
      image ICON, height: 260
    }
    label {
      layout_data :fill, :fill, true, true
      background :white
      text "Gladiator v#{VERSION} (Beta)\n\n#{LICENSE}\n\nGladiator icon made by Freepik from www.flaticon.com"
    }
  }.open
end

#expand_navigation_expand_bar_heightObject



899
900
901
902
903
# File 'lib/views/glimmer/gladiator.rb', line 899

def expand_navigation_expand_bar_height
  @navigation_expand_item.swt_expand_item.height = @navigation_expand_item_height || 140
  body_root.pack_same_size
  async_exec { body_root.pack_same_size }
end

#extract_char(event) ⇒ Object



905
906
907
908
909
# File 'lib/views/glimmer/gladiator.rb', line 905

def extract_char(event)
  event.keyCode.chr
rescue => e
  nil
end

#find_tab_item(file_path) ⇒ Object



880
881
882
# File 'lib/views/glimmer/gladiator.rb', line 880

def find_tab_item(file_path)
  @current_tab_folder.swt_widget.getItems.detect { |ti| ti.getData('file_path') == file_path }
end

#handle_display_shortcut(key_event) ⇒ Object



962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
# File 'lib/views/glimmer/gladiator.rb', line 962

def handle_display_shortcut(key_event)
  if key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'f'
    if !@navigation_expand_item.swt_expand_item.get_expanded
      expand_navigation_expand_bar_height
      @navigation_expand_item.swt_expand_item.set_expanded true
    end
    if current_text_editor&.text_widget&.getSelectionText && current_text_editor&.text_widget&.getSelectionText&.size.to_i > 0
      find_text.swt_widget.setText current_text_editor.text_widget.getSelectionText
    end
    find_text.swt_widget.selectAll
    find_text.swt_widget.setFocus
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'c'
    Clipboard.copy(project_dir.selected_child.path)
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'g'
    project_dir.selected_child.find_previous
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'o'
    self.maximized_pane = false
    old_split_orientation = self.split_orientation
    self.split_orientation = split_pane? && split_orientation == swt(:horizontal) ? swt(:vertical) : swt(:horizontal)
    @tab_folder_sash_form.weights = [1, 1] if old_split_orientation.nil?
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'w'
    close_all_tabs
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :alt) && extract_char(key_event) == 'w'
    other_tab_items.each do |tab_item|
      project_dir.selected_child_path_history.delete(tab_item.getData('file_path'))
      tab_item.getData('proxy')&.dispose
    end
  elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'w'
    if selected_tab_item
      project_dir.selected_child_path_history.delete(project_dir.selected_child.path)
      selected_tab_item.getData('proxy')&.dispose
      close_tab_folder(single_tab: true)
#           if self.current_tab_item.nil?
#             filter_text.swt_widget.selectAll
#             filter_text.swt_widget.setFocus
#           else
#             current_text_editor&.text_widget&.setFocus
#           end
      if selected_tab_item.nil?
        self.current_tab_item = self.current_text_editor = project_dir.selected_child = nil
        filter_text.swt_widget.selectAll
        filter_text.swt_widget.setFocus
      else
        current_text_editor&.text_widget&.setFocus
#             async_exec { current_text_editor&.text_widget&.setFocus }
      end
    end
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == ']' || Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :ctrl) && key_event.keyCode == swt(:page_down)
    current_tab_folder.swt_widget.setSelection((current_tab_folder.swt_widget.getSelectionIndex() + 1) % current_tab_folder.swt_widget.getItemCount) if current_tab_folder.swt_widget.getItemCount > 0
    current_text_editor&.text_widget&.setFocus
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == '[' || Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :ctrl) && key_event.keyCode == swt(:page_up)
    current_tab_folder.swt_widget.setSelection((current_tab_folder.swt_widget.getSelectionIndex() - 1) % current_tab_folder.swt_widget.getItemCount) if current_tab_folder.swt_widget.getItemCount > 0
    current_text_editor&.text_widget&.setFocus
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, CONTROL_KEY) && extract_char(key_event) == ']'
    navigate_to_next_tab_folder
    key_event.doit = false
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, CONTROL_KEY) && extract_char(key_event) == '['
    navigate_to_previous_tab_folder
    key_event.doit = false
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '1'
    current_tab_folder.swt_widget.setSelection(0) if current_tab_folder.swt_widget.getItemCount >= 1
    current_text_editor&.text_widget&.setFocus
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '2'
    current_tab_folder.swt_widget.setSelection(1) if current_tab_folder.swt_widget.getItemCount >= 2
    current_text_editor&.text_widget&.setFocus
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '3'
    current_tab_folder.swt_widget.setSelection(2) if current_tab_folder.swt_widget.getItemCount >= 3
    current_text_editor&.text_widget&.setFocus
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '4'
    current_tab_folder.swt_widget.setSelection(3) if current_tab_folder.swt_widget.getItemCount >= 4
    current_text_editor&.text_widget&.setFocus
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '5'
    current_tab_folder.swt_widget.setSelection(4) if current_tab_folder.swt_widget.getItemCount >= 5
    current_text_editor&.text_widget&.setFocus
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '6'
    current_tab_folder.swt_widget.setSelection(5) if current_tab_folder.swt_widget.getItemCount >= 6
    current_text_editor&.text_widget&.setFocus
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '7'
    current_tab_folder.swt_widget.setSelection(6) if current_tab_folder.swt_widget.getItemCount >= 7
    current_text_editor&.text_widget&.setFocus
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '8'
    current_tab_folder.swt_widget.setSelection(7) if current_tab_folder.swt_widget.getItemCount >= 8
    current_text_editor&.text_widget&.setFocus
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '9'
    current_tab_folder.swt_widget.setSelection(current_tab_folder.swt_widget.getItemCount - 1) if current_tab_folder.swt_widget.getItemCount > 0
    current_text_editor&.text_widget&.setFocus
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == 'g'
    project_dir.selected_child.find_next
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == 'l'
    unless @navigation_expand_item.swt_expand_item.get_expanded
      @navigation_expand_item.swt_expand_item.set_expanded true
      @navigation_expand_item.swt_expand_item.height = @navigation_expand_item_height if @navigation_expand_item_height
      async_exec {
        body_root.pack_same_size
      }
      async_exec {
        line_number_text.swt_widget.selectAll
        line_number_text.swt_widget.setFocus
      }
    else
      line_number_text.swt_widget.selectAll
      line_number_text.swt_widget.setFocus
    end
  elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'r'
    self.maximized_editor = false
    unless @file_lookup_expand_item.swt_expand_item.get_expanded
      @file_lookup_expand_item.swt_expand_item.set_expanded true
      @file_lookup_expand_item.swt_expand_item.height = @file_lookup_expand_item_height if @file_lookup_expand_item_height
      @side_bar_sash_form.weights = [@file_lookup_expand_bar_height, @file_explorer_expand_bar_height]
    end
    filter_text.swt_widget.selectAll
    filter_text.swt_widget.setFocus
  elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 't'
    self.maximized_editor = false
    unless @file_explorer_expand_item.swt_expand_item.get_expanded
      @file_explorer_expand_item.swt_expand_item.set_expanded true
      @file_explorer_expand_item.swt_expand_item.height = @file_explorer_expand_item_height if @file_explorer_expand_item_height
      @side_bar_sash_form.weights = [@file_lookup_expand_bar_height, @file_explorer_expand_bar_height]
    end
    @file_explorer_tree.select_tree_item
    @file_explorer_tree.swt_widget.setFocus
  elsif key_event.keyCode == swt(:esc)
    if current_text_editor
      project_dir.selected_child_path = current_text_editor.file.path
      current_text_editor&.text_widget&.setFocus
    end
  end
end

#load_configObject



713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
# File 'lib/views/glimmer/gladiator.rb', line 713

def load_config
  if ::File.exists?(@config_file_path)
    config_yaml = ::File.read(@config_file_path)
    return if config_yaml.to_s.strip.empty?
    @config = YAML.load(config_yaml)
    project_dir.ignore_paths = @config[:ignore_paths] if @config[:ignore_paths]
    project_dir.ignore_paths ||= ['packages', 'tmp']
    open_file_paths1 = @config[:open_file_paths1] || @config[:open_file_paths]
    open_file_paths2 = @config[:open_file_paths2]
    self.split_orientation = (swt(@config[:split_orientation]) rescue swt(:horizontal)) if @config[:split_orientation]
    if @progress_shell.nil?
      @progress_shell = progress_shell(gladiator: self, progress_text: 'Opening Last Open Files')
      async_exec {
        @progress_shell.open
      }
    end
    open_file_paths1.to_a.each do |file_path|
      async_exec {
        Gladiator.drag = false
        Gladiator.startup = file_path != open_file_paths1.to_a[-1]
        project_dir.selected_child_path = file_path
      }
    end
    # TODO replace the next line with one that selects the visible tab
    async_exec {
      # TODO check why this is not working
      if open_file_paths1.to_a.include?(@config[:selected_child_path])
        Gladiator.drag = false
        Gladiator.startup = false
        project_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path]
        project_dir.selected_child&.caret_position  = project_dir.selected_child&.caret_position_for_caret_position_start_of_line(@config[:caret_position].to_i) if @config[:caret_position]
        project_dir.selected_child&.top_pixel = @config[:top_pixel].to_i if @config[:top_pixel]
      end
    }
    async_exec {
      open_file_paths2.to_a.each do |file_path|
        async_exec {
          Gladiator.drag = true
          Gladiator.startup = file_path != open_file_paths2.to_a[-1]
          project_dir.selected_child_path = file_path
        }
      end
      # TODO replace the next line with one that selects the visible tab
      async_exec {
        # TODO check why this is not working
        if open_file_paths2.to_a.include?(@config[:selected_child_path])
          Gladiator.drag = true
          Gladiator.startup = false
          project_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path]
          project_dir.selected_child&.caret_position  = project_dir.selected_child&.caret_position_for_caret_position_start_of_line(@config[:caret_position].to_i) if @config[:caret_position]
          project_dir.selected_child&.top_pixel = @config[:top_pixel].to_i if @config[:top_pixel]
        end
      }
      async_exec do
        Gladiator.drag = false
        @progress_shell&.close
        @progress_shell = nil
        @loaded_config = true
      end
    }
    async_exec do
      Thread.new {
        all_files = open_file_paths1.to_a + open_file_paths2.to_a
        all_files.each do |file|
          project_dir.find_child_file(file)&.dirty_content
        end
      }
    end
  else
    @loaded_config = true
  end
end

#load_config_ignore_pathsObject



702
703
704
705
706
707
708
709
710
711
# File 'lib/views/glimmer/gladiator.rb', line 702

def load_config_ignore_paths
  # TODO eliminate duplication with load_config
  if ::File.exists?(@config_file_path)
    config_yaml = ::File.read(@config_file_path)
    return if config_yaml.to_s.strip.empty?
    @config = YAML.load(config_yaml)
    project_dir.ignore_paths = @config[:ignore_paths] if @config[:ignore_paths]
    project_dir.ignore_paths ||= ['packages', 'tmp']
  end
end


814
815
816
817
818
819
820
821
822
823
824
825
826
827
# File 'lib/views/glimmer/gladiator.rb', line 814

def navigate_to_next_tab_folder
  if tab_folder2
    self.maximized_pane = false
    if current_tab_folder == tab_folder1
      self.current_tab_folder = tab_folder2
    else
      self.current_tab_folder = tab_folder1
    end
    self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
    self.project_dir.selected_child = current_tab_item&.swt_tab_item&.getData('file')
    self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
    current_tab_item&.swt_tab_item&.getData('text_editor')&.text_widget&.setFocus
  end
end


829
830
831
832
833
834
835
836
837
838
839
840
841
842
# File 'lib/views/glimmer/gladiator.rb', line 829

def navigate_to_previous_tab_folder
 if tab_folder2
    self.maximized_pane = false
    if current_tab_folder == tab_folder2
      self.current_tab_folder = tab_folder1
    else
      self.current_tab_folder = tab_folder2
    end
    self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
    self.project_dir.selected_child = current_tab_item&.swt_tab_item&.getData('file')
    self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
    current_tab_item&.swt_tab_item&.getData('text_editor')&.text_widget&.setFocus
  end
end

#open_projectObject



911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
# File 'lib/views/glimmer/gladiator.rb', line 911

def open_project
  selected_directory = directory_dialog.open
  return if selected_directory.nil?
  @progress_shell = progress_shell(gladiator: self, progress_text: "Opening Project: #{::File.basename(selected_directory)}")
  async_exec {
    @progress_shell.open
  }
  async_exec do
    gladiator(project_dir_path: selected_directory) {
      on_swt_show {
        @@app_mode_shell.hide if app_mode?
        @progress_shell.close
        @progress_shell = nil
      }
    }.open if selected_directory
  end
end

#other_tab_itemsObject



888
889
890
# File 'lib/views/glimmer/gladiator.rb', line 888

def other_tab_items
  @current_tab_folder.swt_widget.getItems.reject { |ti| ti.getData('file_path') == project_dir.selected_child&.path }
end

#project_dirObject



70
71
72
# File 'lib/views/glimmer/gladiator.rb', line 70

def project_dir
  @project_dir ||= Dir.new(project_dir_path)
end

#project_dir_pathObject

Add options like the following to configure CustomShell by outside consumers

options :title, :background_color option :width, 320 option :height, 240



63
# File 'lib/views/glimmer/gladiator.rb', line 63

option :project_dir_path

#quitObject



929
930
931
932
933
934
935
936
# File 'lib/views/glimmer/gladiator.rb', line 929

def quit
  @@quitting = true
  display.shells.each { |shell|
    gladiator = shell.get_data('custom_shell')
    gladiator.project_dir.selected_child&.write_dirty_content unless app_mode?
    shell.get_data('proxy').close
  }
end

#save_configObject



786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
# File 'lib/views/glimmer/gladiator.rb', line 786

def save_config
  return if !@loaded_config || body_root&.disposed? || @paused_save_config
  child = project_dir.selected_child
  return if child.nil?
  tab_folder1 = @tab_folder1 || @current_tab_folder
  tab_folder2 = @tab_folder2
  open_file_paths1 = tab_folder1&.swt_widget&.items.to_a.map {|i| i.get_data('file_path')}.reject {|path| path.to_s.strip.empty?}
  open_file_paths2 = tab_folder2&.swt_widget&.items.to_a.map {|i| i.get_data('file_path')}.reject {|path| path.to_s.strip.empty?}
  split_orientation_value = split_orientation == swt(:horizontal) ? 'horizontal' : (split_orientation == swt(:vertical) ? 'vertical' : nil)
  @config = {
    selected_child_path: child.nil? ? open_file_paths1&.first&.path : child.path,
    split_orientation: split_orientation_value,
    caret_position: child.caret_position,
    top_pixel: child.top_pixel,
    shell_width: swt_widget&.getBounds&.width,
    shell_height: swt_widget&.getBounds&.height,
    shell_x: swt_widget&.getBounds&.x,
    shell_y: swt_widget&.getBounds&.y,
    open_file_paths1: open_file_paths1,
    open_file_paths2: open_file_paths2,
    ignore_paths: project_dir.ignore_paths
  }
  config_yaml = YAML.dump(@config)
  ::File.write(@config_file_path, config_yaml) unless config_yaml.to_s.empty?
rescue => e
  Glimmer::Config.logger.error {e.full_message}
end

#selected_tab_itemObject



884
885
886
# File 'lib/views/glimmer/gladiator.rb', line 884

def selected_tab_item
  find_tab_item(project_dir.selected_child&.path)
end

#split_pane?Boolean

Returns:

  • (Boolean)


87
88
89
90
# File 'lib/views/glimmer/gladiator.rb', line 87

def split_pane?
  pane_count = @tab_folder_sash_form&.children&.size
  pane_count && pane_count > 1
end

#text_editor_group_tab_folderObject



672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
# File 'lib/views/glimmer/gladiator.rb', line 672

def text_editor_group_tab_folder
  tab_folder { |tab_folder_proxy|
    on_widget_selected {
      self.current_tab_folder = tab_folder_proxy
      selected_file = @current_tab_item&.swt_tab_item&.getData('file')
      if selected_file
        project_dir.selected_child = selected_file
        @current_tab_item = @current_tab_folder.swt_widget.getSelection.first.getData('proxy')
        @current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item) #TODO see if we can get rid of this as it seems redundant
        @current_text_editor = @current_tab_item.swt_tab_item.getData('text_editor')
        @current_text_editor&.load_content
        @current_text_editor&.text_widget&.setFocus
      end
    }
    drag_source(DND::DROP_COPY) {
      transfer [TextTransfer.getInstance].to_java(Transfer)
      event_data = nil
      on_drag_start {|event|
        Gladiator.drag = true
        tab_folder = event.widget.getControl
        tab_item = tab_folder.getItem(Point.new(event.x, event.y))
        event_data = tab_item&.getData('file_path')
      }
      on_drag_set_data { |event|
        event.data = event_data
      }
    }
  }
end