Class: TopinambourApplication

Inherits:
Gtk::Application
  • Object
show all
Defined in:
lib/application.rb

Overview

Gtk::Application class for topinambour

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTopinambourApplication

Returns a new instance of TopinambourApplication.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/application.rb', line 24

def initialize
  @options = {}
  @exit_status = 0
  @app_id = 'com.github.cedlemo.topinambour'
  @app_path = '/com/github/cedlemo/topinambour'

  super(@app_id, %i[non_unique handles_command_line])

  signal_connect 'startup' do |application|
    GLib.set_application_name('topinambout')
    GLib.set_prgname('topinambour')
    parent_schema = Gio::SettingsSchemaSource.default
    schema_source =
      Gio::SettingsSchemaSource.new(DATA_PATH, parent_schema, true)
    schema = schema_source.lookup(@app_id, true)
    @settings = Gio::Settings.new(schema: schema,
                                  path: @app_path + '/preferences/')

    TopinambourActions.add_actions_to(application)
    initialize_css_provider
    create_xdg_dirs
    load_css_config
    load_menu_ui(application)
  end

  signal_connect 'activate' do |application|
    window = TopinambourWindow.new(application)

    if @options[:execute]
      window.add_terminal(@options[:execute])
    else
      window.add_terminal
    end
    window.show_all
    window.present
  end

  signal_connect 'command-line' do |_application, command_line|
    begin
      parse_command_line(command_line.arguments)
    rescue SystemExit => error
      error.status
    rescue OptionParser::InvalidOption => error
      STDERR.puts error.message
      1
    rescue => error
      STDERR.puts "#{error.class}: #{error.message}"
      STDERR.puts error.backtrace
      1
    else
      activate
      @exit_status
    end
  end
end

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



23
24
25
# File 'lib/application.rb', line 23

def settings
  @settings
end

Instance Method Details

#check_css_file_pathObject



111
112
113
114
115
116
117
118
# File 'lib/application.rb', line 111

def check_css_file_path
  css_file = if File.exist?(@settings['css-file'])
               @settings['css-file']
             else
               "#{CONFIG_DIR}/#{@settings['css-file']}"
             end
  File.exist?(css_file) ? css_file : nil
end

#reload_css_configObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/application.rb', line 80

def reload_css_config
  bad_css = nil
  css_file = check_css_file_path
  return unless css_file

  @provider.signal_connect 'parsing-error' do |_css_prov, section, _error|
    buf = Gtk::TextBuffer.new
    buf.text = @css_content
    start_i = buf.get_iter_at(line: section.start_line,
                              index: section.start_position)
    end_i = buf.get_iter_at(line: section.start_line + 10,
                            index: section.end_position)
    bad_css = ''
    buf.get_text(start_i, end_i, true).lines.each_with_index do |line, i|
      bad_css += "#{section.start_line + 1 + i}  #{line}"
    end
  end

  begin
    load_custom_css(css_file)
  rescue => e
    windows.first.exit_overlay_mode
    # TODO : deal with the preferences window which is a transient one
    # that keeps the focus even when the popup shows up.
    error_popup = TopinambourCssErrorPopup.new(windows.first)
    error_popup.transient_for = windows.first
    error_popup.message = e.message + "\n\n" + bad_css
    error_popup.show_all
  end
end