Top Level Namespace

Defined Under Namespace

Modules: SVN_Info Classes: AppError, Clip, ClipArray, Gui, Jota, JotaCli, Preferences, Version

Instance Method Summary collapse

Instance Method Details

#array_to_color(arr) ⇒ Object



49
50
51
52
# File 'lib/helper.rb', line 49

def array_to_color(arr)
#{{{1

  return Gdk::Color.new(arr[0],arr[1],arr[2])
end

#color_to_array(gdk_color) ⇒ Object

}}}1



54
55
56
57
# File 'lib/helper.rb', line 54

def color_to_array(gdk_color)
#{{{1

        return [gdk_color.red, gdk_color.green, gdk_color.blue]
end

#escape_from(str) ⇒ Object

}}}1



59
60
61
62
63
# File 'lib/helper.rb', line 59

def escape_from(str)
#{{{1

  str.gsub!(/\n(>*)From /,"\n\\1>From ")
  return str
end

#expand_filename(str, dirname, filename) ⇒ Object

expand strftime() time in str and expand %s to ‘filename’



72
73
74
75
76
77
78
79
# File 'lib/helper.rb', line 72

def expand_filename(str, dirname, filename)
#{{{1

  result = Time.now.strftime(str)
  result = result.gsub(/\$f/,filename)
  result = result.gsub(/\$d/,dirname)
  result = result.gsub(/\$\$/,"$")
  return result
end

#get_filename(filename, mode) ⇒ Object

if you use vim and don’t like folds type zR



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/helper.rb', line 6

def get_filename(filename, mode)
#{{{1

  if filename.class == Symbol and filename == :ask then
    case mode
    when :save
      action = Gtk::FileChooser::ACTION_SAVE
      ok_button = Gtk::Stock::SAVE
    when :open
      action = Gtk::FileChooser::ACTION_OPEN
      ok_button = Gtk::Stock::OPEN
    else
      raise "Wrong mode #{mode} in helper:get_filenamen"
    end

    title = "Select Filename"

    dialog = Gtk::FileChooserDialog.new(
      title,
      nil,
      action,
      nil,
      [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
      [ok_button, Gtk::Dialog::RESPONSE_ACCEPT])

    case dialog.run
    when Gtk::Dialog::RESPONSE_ACCEPT
      filename = dialog.filename
    else
      filename = nil
    end
    dialog.destroy
  end

  if filename.nil? then
    return
  end

  filename = Time.now.strftime(filename)

  return filename
end

#obtain_exclusive_lock(file) ⇒ Object

}}}1



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/helper.rb', line 97

def obtain_exclusive_lock(file)
#{{{1

  release_lock(file) # necessary for win32


  # an exclusive, non-blocking lock

  print_debug "obtaining EXCLUSIVE LOCK on '#{file.path}'"
  if not file.flock(File::LOCK_EX|File::LOCK_NB) then
    print_debug "  cannot lock"
    #file.flock(File::LOCK_EX)    TODO

  end
end

#obtain_shared_lock(file) ⇒ Object

Locking



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/helper.rb', line 85

def obtain_shared_lock(file)
#{{{1

  release_lock(file) # necessary for win32


  # a shared, non-blocking lock

  print_debug "obtaining SHARED LOCK on '#{file.path}'"
  if not file.flock(File::LOCK_SH|File::LOCK_NB) then
    print_debug "  cannot lock"
    #file.flock(File::LOCK_SH)    TODO

  end
end

}}}1



122
123
124
125
126
127
# File 'lib/helper.rb', line 122

def print_debug(msg)
#{{{1

  if $DEBUG then
    puts "#{Process.pid}- #{msg}"
  end  
end

}}}1



115
116
117
118
119
120
# File 'lib/helper.rb', line 115

def print_verbose(msg)
#{{{1

  if $VERBOSE then
    puts "#{Process.pid}# #{msg}"
  end  
end

#release_lock(file) ⇒ Object

}}}1



109
110
111
112
113
# File 'lib/helper.rb', line 109

def release_lock(file)
#{{{1

  print_debug "releasing LOCK from '#{file.path}'"
  file.flock(File::LOCK_UN)
end

#unescape_from(str) ⇒ Object

}}}1



65
66
67
68
69
# File 'lib/helper.rb', line 65

def unescape_from(str)
#{{{1

  str.gsub!(/\n(>*)>From /,"\n\\1From ")
  return str
end