Class: Watobo::Gui::NewProjectWizzard

Inherits:
FXDialogBox
  • Object
show all
Defined in:
lib/watobo/gui/project_wizzard.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, workspace_path = nil) ⇒ NewProjectWizzard

Returns a new instance of NewProjectWizzard.


216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/watobo/gui/project_wizzard.rb', line 216

def initialize(parent, workspace_path=nil)
  # Invoke base class initialize function first
  #  super(parent, "New Project", DECOR_TITLE|DECOR_BORDER)
  super(parent, "New Project", DECOR_ALL)
  
  @selected_project_path = ''
  @new_project_name = FXDataTarget.new('')
  @new_session_name = FXDataTarget.new('')
  @workspace_dt = FXDataTarget.new('')
  @target_url = FXDataTarget.new('')
  @proxy = FXDataTarget.new('')
  
  @project_name = ''
  @session_name = ''
  
  @session_name = ''
  
  if workspace_path then
    if File.exists?(workspace_path) then
      @workspace_dt.value = workspace_path 
      
    else
      #  FXMessageBox.information(FXApp.instance, MBOX_OK, "No Workspace Selected!", "You need to select a workspace directory before you can start")
    end
  end
  
  base_frame = FXVerticalFrame.new(self, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y)
  @switcher = FXSwitcher.new(base_frame,LAYOUT_FILL_X|LAYOUT_FILL_Y)   
  first_frame = FXVerticalFrame.new(@switcher, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y)
  
  workspace_path_form = FXHorizontalFrame.new(first_frame,
                                              :opts => LAYOUT_FILL_X|LAYOUT_SIDE_TOP)
  FXLabel.new(workspace_path_form, "Workspace Directory:" )
  @workspace_text = FXTextField.new(workspace_path_form, 25,
                                    :target => @workspace_dt, :selector => FXDataTarget::ID_VALUE,
                                    :opts => TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN)
  @workspace_text.handle(self, FXSEL(SEL_UPDATE, 0), nil)
  browse_button=FXButton.new(workspace_path_form, "Change")
  browse_button.connect(SEL_COMMAND, method(:open_select_workspace_dt_dialog) )
  
  
  #
  # PROJECT SELECTION
  #
  #projectSelectionFrame = FXHorizontalFrame.new(first_frame, :opts => LAYOUT_FILL_X|LAYOUT_SIDE_TOP)
  
  projectSelectionFrame = FXGroupBox.new(first_frame, "Select Project", LAYOUT_SIDE_TOP|FRAME_GROOVE|LAYOUT_FILL_X, 0, 0, 0, 0)
  
  projectSubSelection = FXVerticalFrame.new(projectSelectionFrame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_GROOVE)
  newProjectFrame = FXHorizontalFrame.new(projectSubSelection, :opts => LAYOUT_FILL_X|LAYOUT_SIDE_TOP)
  FXLabel.new(newProjectFrame, "Project Name:" )
  @projectTextField = FXTextField.new(newProjectFrame, 25,
                                      :target => @new_project_name, :selector => FXDataTarget::ID_VALUE,
                                      :opts => TEXTFIELD_NORMAL|LAYOUT_SIDE_LEFT)
  @newProjectButton = FXButton.new(newProjectFrame, "New" ,  nil, nil, :opts => BUTTON_NORMAL|LAYOUT_RIGHT)  
  
  @newProjectButton.disable if @workspace_dt.value == ''
  
  @new_project_name.connect(SEL_COMMAND, method(:createProject))
  @newProjectButton.connect(SEL_COMMAND, method(:createProject))
  
  projectListOuterFrame = FXVerticalFrame.new(projectSubSelection, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_GROOVE, :padding => 0)
  @projectList = FXList.new(projectListOuterFrame, :opts => LIST_EXTENDEDSELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y)
  @projectList.numVisible = 14
  
  @projectList.connect(SEL_COMMAND, method(:onProjectSelect))
  @projectList.connect(SEL_DOUBLECLICKED, method(:openProject))
  
  
  #
  # SECOND WIZZARD FRAME
  #
  step_two_frame = FXVerticalFrame.new(@switcher, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y)
  @projectCaption = FXLabel.new(step_two_frame, "Project: - unknown -", :opts => LAYOUT_FILL_X|JUSTIFY_LEFT)
  @projectCaption.setFont(FXFont.new(getApp(), "helvetica", 14, FONTWEIGHT_BOLD, FONTSLANT_ITALIC, FONTENCODING_DEFAULT))
  
  # SESSION SELECTION
  sessionSelectionFrame = FXGroupBox.new(step_two_frame, "Select Session", LAYOUT_SIDE_TOP|FRAME_GROOVE|LAYOUT_FILL_X, 0, 0, 0, 0)
  
  sessionSubSelection = FXVerticalFrame.new(sessionSelectionFrame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_GROOVE)
  newSessionFrame = FXHorizontalFrame.new(sessionSubSelection, :opts => LAYOUT_FILL_X|LAYOUT_SIDE_TOP)
  FXLabel.new(newSessionFrame, "Session Name:" )
  @sessionTextField = FXTextField.new(newSessionFrame, 25,
                                      :target => @new_session_name, :selector => FXDataTarget::ID_VALUE,
                                      :opts => TEXTFIELD_NORMAL|LAYOUT_SIDE_LEFT)
  @newSessionButton = FXButton.new(newSessionFrame, "New" ,  nil, nil, :opts => BUTTON_NORMAL|LAYOUT_RIGHT)
  
  
  @new_session_name.connect(SEL_COMMAND, method(:createSession))
  
  @newSessionButton.connect(SEL_COMMAND, method(:createSession))
  
  sessionListOuterFrame = FXVerticalFrame.new(sessionSubSelection, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_GROOVE, :padding => 0)
  @sessionList = FXList.new(sessionListOuterFrame, :opts => LIST_EXTENDEDSELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y)
  @sessionList.numVisible = 14
  
  @sessionList.connect(SEL_COMMAND, method(:onSessionSelect))
  
  @sessionList.connect(SEL_DOUBLECLICKED, method(:openSession))
  
  
  #updateSessionList(@project_dir)
  
  #
  # BUTTONS FRAME
  #
  buttons_frame = FXHorizontalFrame.new(base_frame,
                                        :opts => LAYOUT_FILL_X|LAYOUT_SIDE_TOP)
  
  @finishButton = FXButton.new(buttons_frame, "Finish" ,  nil, nil, :opts => BUTTON_NORMAL|LAYOUT_RIGHT)  
  @finishButton.disable
  @finishButton.connect(SEL_COMMAND) do |sender, sel, item|
    #self.handle(self, FXSEL(SEL_COMMAND, ID_CANCEL), nil)
    self.handle(self, FXSEL(SEL_COMMAND, ID_ACCEPT), nil)
  end 
  
  @nextButton = FXButton.new(buttons_frame, "Next" ,  nil, nil, :opts => BUTTON_NORMAL|LAYOUT_RIGHT)  
  @nextButton.disable
  @nextButton.connect(SEL_COMMAND) do |sender, sel, item|
    if @switcher.current < @switcher.numChildren-1
      @switcher.current = @switcher.current+1
      @backButton.enable
      @nextButton.disable if @switcher.current == @switcher.numChildren-1 
    end
    setButtons(@switcher.current)
  end 
  
  @backButton = FXButton.new(buttons_frame, "Back" ,  nil, nil, :opts => BUTTON_NORMAL|LAYOUT_RIGHT)  
  @backButton.disable
  @backButton.connect(SEL_COMMAND) do |sender, sel, item|
    if @switcher.current > 0
      @switcher.current = @switcher.current-1
      @backButton.disable if @switcher.current == 0
    end
    setButtons(@switcher.current)
  end 
  
  @cancelButton = FXButton.new(buttons_frame, "Cancel" ,
  :target => self, :selector => FXDialogBox::ID_CANCEL,
  :opts => BUTTON_NORMAL|LAYOUT_RIGHT)  
  
  
  updateProjectList(@workspace_dt.value)
  
  
  
  # apply setting
end

Instance Attribute Details

#new_project_nameObject (readonly)

Returns the value of attribute new_project_name


32
33
34
# File 'lib/watobo/gui/project_wizzard.rb', line 32

def new_project_name
  @new_project_name
end

#new_session_nameObject (readonly)

Returns the value of attribute new_session_name


31
32
33
# File 'lib/watobo/gui/project_wizzard.rb', line 31

def new_session_name
  @new_session_name
end

#project_nameObject (readonly)

Returns the value of attribute project_name


33
34
35
# File 'lib/watobo/gui/project_wizzard.rb', line 33

def project_name
  @project_name
end

#selected_project_pathObject (readonly)

Returns the value of attribute selected_project_path


30
31
32
# File 'lib/watobo/gui/project_wizzard.rb', line 30

def selected_project_path
  @selected_project_path
end

#selected_session_pathObject (readonly)

Returns the value of attribute selected_session_path


29
30
31
# File 'lib/watobo/gui/project_wizzard.rb', line 29

def selected_session_path
  @selected_session_path
end

#session_nameObject (readonly)

Returns the value of attribute session_name


34
35
36
# File 'lib/watobo/gui/project_wizzard.rb', line 34

def session_name
  @session_name
end

Instance Method Details

#createProject(sender, sel, event) ⇒ Object


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/watobo/gui/project_wizzard.rb', line 160

def createProject(sender, sel, event)
  begin
    if @new_project_name.value != '' then
      @project_name = @new_project_name.value
      if File.exists?(@workspace_dt.value) then
        new_folder = File.join(@workspace_dt.value, @new_project_name.value)
        if File.exists?(new_folder) then
          puts "! folder already exists"
        else
          Dir.mkdir(new_folder)
          @projectCaption.text = "Project: #{@new_project_name.value}"
          
          @selected_project_path = new_folder
          updateProjectList(@workspace_dt.value)
          new_project_index = @projectList.findItem(@new_project_name.value)
          new_project_item = @projectList.selectItem(new_project_index, true)
          @projectList.makeItemVisible(new_project_index)
          
          updateSessionList(@selected_project_path)
          @new_project_name.value = ''
          @nextButton.enable
          @nextButton.setFocus()
          @nextButton.setDefault()
          @finishButton.disable
        end
      else
        FXMessageBox.information(FXApp.instance, MBOX_OK, "No Workspace Selected!", "You need to select a workspace directory before you can start")
      end
    end
  rescue => bang
    puts "!!!ERROR: could not create project"
    puts bang
  end
end

#createSession(sender, sel, event) ⇒ Object


128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/watobo/gui/project_wizzard.rb', line 128

def createSession(sender, sel, event)
  begin
    if @new_session_name.value != '' then
      @session_name = @new_session_name.value 
      if File.exists?(@selected_project_path) then
        new_folder = File.join(@selected_project_path, @new_session_name.value)
        if File.exists?(new_folder) then
          puts "! folder already exists"
        else
          Dir.mkdir(new_folder)
          updateSessionList(@selected_project_path)
          new_session_index = @sessionList.findItem(@new_session_name.value)
          @session_name = @new_session_name.value
          
          new_session_item = @sessionList.selectItem(new_session_index)
          @sessionList.makeItemVisible(new_session_index)
          @selected_session_path = File.join(@selected_project_path, @session_name)
          
          # @new_session_name.value = ''
          @finishButton.enable
          @finishButton.setFocus()
          @finishButton.setDefault()
        end
      end
    end
  rescue => bang
    puts "!!!ERROR: could not create session"
    puts bang
    @finishButton.disable
  end
end

#onProjectSelect(sender, sel, index) ⇒ Object


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

def onProjectSelect(sender, sel, index)
  @selected_project_path = File.join(@workspace_dt.value, @projectList.getItemText(index))
  @new_project_name.value = @projectList.getItemText(index)
  @project_name = @projectList.getItemText(index)
  @projectCaption.text = "Project: #{@new_project_name.value}"
#  puts @selected_project_path
  updateSessionList(@selected_project_path)
  @projectTextField.handle(self, FXSEL(SEL_UPDATE, 0), nil)
  @nextButton.enable
  @finishButton.disable
 
end

#onSessionSelect(sender, sel, index) ⇒ Object


110
111
112
113
114
115
116
117
118
# File 'lib/watobo/gui/project_wizzard.rb', line 110

def onSessionSelect(sender, sel, index)
  @selected_session_path = File.join(@selected_project_path, @sessionList.getItemText(index))
  @new_session_name.value = @sessionList.getItemText(index)
  @session_name = @new_session_name.value 
  #  @session_name = @sessionList.getItemText(index)
  @sessionTextField.handle(self, FXSEL(SEL_UPDATE, 0), nil)
 # puts @selected_session_path
  @finishButton.enable
end

#open_select_workspace_dt_dialog(sender, sel, ptr) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/watobo/gui/project_wizzard.rb', line 42

def open_select_workspace_dt_dialog(sender, sel, ptr)
  workspace_dt = FXFileDialog.getOpenDirectory(self, "Select Workspace Directory", @workspace_dt.value)
  if workspace_dt != "" then
    if File.exists?(workspace_dt) then
      @workspace_dt.value = workspace_dt
      @workspace_text.handle(self, FXSEL(SEL_UPDATE, 0), nil)
      updateProjectList(@workspace_dt.value)
      @newProjectButton.enable
    end
    
  end
end

#openProject(sender, sel, index) ⇒ Object


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/watobo/gui/project_wizzard.rb', line 81

def openProject(sender, sel, index)
  @selected_project_path = File.join(@workspace_dt.value, @projectList.getItemText(index))
  @new_project_name.value = @projectList.getItemText(index)
  @project_name = @projectList.getItemText(index)
  @projectCaption.text = "Project: #{@new_project_name.value}"
#  puts @selected_project_path
  updateSessionList(@selected_project_path)
  @projectTextField.handle(self, FXSEL(SEL_UPDATE, 0), nil)
  @nextButton.enable
  @finishButton.disable
   @switcher.current = @switcher.current+1
  @backButton.enable
  @nextButton.disable if @switcher.current == @switcher.numChildren-1 
  setButtons(@switcher.current)
end

#openSession(sender, sel, index) ⇒ Object


120
121
122
123
124
125
126
# File 'lib/watobo/gui/project_wizzard.rb', line 120

def openSession(sender, sel, index)
  @selected_session_path = File.join(@selected_project_path, @sessionList.getItemText(index))
  @new_session_name.value = @sessionList.getItemText(index)
  @session_name = @new_session_name.value 
 # puts @selected_session_path
  self.handle(self, FXSEL(SEL_COMMAND, ID_ACCEPT), nil)
end

#setButtons(index) ⇒ Object


196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/watobo/gui/project_wizzard.rb', line 196

def setButtons(index)
  case index
    when 0 
    # select project screen
    if @projectList.currentItem >= 0 and @projectList.itemSelected?(@projectList.currentItem)  then
      @nextButton.enable
    end        
    when 1
    # select session screen
    @sessionTextField.setFocus()
    @sessionTextField.setDefault()
    if @sessionList.currentItem >= 0 and @sessionList.itemSelected?(@sessionList.currentItem)  then
    #  puts "session selected"
    #  puts @sessionList.currentItem
      @finishButton.enable 
    end
  end
end

#updateProjectList(workspace_dt) ⇒ Object


55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/watobo/gui/project_wizzard.rb', line 55

def updateProjectList(workspace_dt)
  @projectList.clearItems
  
  if File.exists?(workspace_dt) then
    Dir.foreach(workspace_dt) do |file|
      #puts file
      if not file =~ /^\.{1,2}/ and File.ftype(File.join(workspace_dt,file)) == 'directory' then
        @projectList.appendItem(file)
      end
    end
  end
  
#  puts "found #{@projectList.numItems} projects"
end

#updateSessionList(project_dir) ⇒ Object


70
71
72
73
74
75
76
77
78
# File 'lib/watobo/gui/project_wizzard.rb', line 70

def updateSessionList(project_dir)
  @sessionList.clearItems
  Dir.foreach(project_dir) do |file|
    if not file =~ /^\.{1,2}/ and File.ftype(File.join(project_dir,file)) == 'directory' then
      @sessionList.appendItem(file)
    end
  end
     #   puts "found #{@sessionList.numItems} sessions"
end

#workspace_dirObject


38
39
40
# File 'lib/watobo/gui/project_wizzard.rb', line 38

def workspace_dir
  return @workspace_dt.value  
end