def integration_action(task): edit_item = config.get(ck.KEY_EDIT_ITEM) _id = helpers.extract_todo_id(edit_item) todo = itemlist.get_todo(_id)['title'] if task.startswith("eggtimer:"): alarm_time = task.replace("eggtimer:", "") alarm_command = "alarm " + alarm_time + " " + todo config.put(ck.KEY_EDIT_ACTION, 'integration') config.put(ck.KEY_INTEGRATION_COMMAND, alarm_command)
def perform_action(_id): content = itemlist.get_todo(_id)['title'] (action, content) = analyse_content(content) smartcontent_actions = { 'copy_to_clipboard': lambda _id, content: itemlist.copy_todo_to_clipboard(_id), 'open_url': lambda _id, content: open_url(content), 'open_file': lambda _id, content: open_url(content), 'open_dir': lambda _id, content: open_url(content) } smartcontent_actions[action](_id, content)
def update_todo(_id, query): info = parser.parse(query) todo = itemlist.get_todo(_id) done = itemlist.feature(todo, 'done') edit_tag = info['tag'] edit_text = info['task'] edit_due = info['due'] edit_clear_due = info['clear_due'] todo_tag = todo['group'] todo_text = todo['title'] todo_due = itemlist.feature(todo, 'due') tag_changed = edit_tag and edit_tag != todo_tag task_changed = len(edit_text) > 0 and edit_text != todo_text due_changed = edit_due and edit_due != todo_due title = todo['title'] tag = todo['group'] update_info = {} if (task_changed): update_info['title'] = edit_text title = edit_text if (tag_changed): update_info['group'] = edit_tag tag = edit_tag if (due_changed): update_info['due'] = edit_due if edit_clear_due: update_info['due'] = None itemlist.update_todo(_id, update_info) config.put(ck.KEY_EDIT_ACTION, 'edit_done' if done else 'edit_todo') if tag != 'default': print ("Updated '" + title + "' tagged #" + tag).encode('utf-8') else: print ("Updated '" + title + "'").encode('utf-8')
def generate_view_itemedit(_id, query): todo = itemlist.get_todo(_id) if not todo: generate_select_item() return todo_tag = todo['group'] todo_text = todo['title'] todo_due = itemlist.feature(todo, 'due') info = parser.parse(query) edit_tag = info['tag'] edit_text = info['task'] edit_due = info['due'] edit_clear_due = info['clear_due'] # TODO: Change this later so that parse will handle this clear_due = False if edit_clear_due and todo_due is not None: clear_due = True edit_text = edit_text.replace('@!', '').strip() feedback_items = [] tag_changed = edit_tag and edit_tag != todo_tag task_changed = len(edit_text) > 0 and edit_text != todo_text due_changed = edit_due and edit_due != todo_due nothing_to_update = not task_changed and not tag_changed and not due_changed and not clear_due changed_items = [] if (task_changed): changed_items.append('text') if (tag_changed): changed_items.append('tag') if (due_changed or clear_due): changed_items.append('due') pinned = itemlist.feature(todo, 'pinned') done = itemlist.feature(todo, 'done') # integration items integration.apply_integration(feedback_items, todo, query) # action item feedback_items.append(alfred.Item( attributes={ 'uid': uuid4(), 'arg': query + " ", 'valid': 'no' if nothing_to_update else 'yes' }, title="No change" if nothing_to_update else "Change " + ", ".join(changed_items), subtitle="", icon="todo_edit.png" )) # info item - task title # if a edit tag is specified, append that and add todo text text_autocomplete = "".join([ "" if not edit_tag else "#"+edit_tag+' ', todo_text ]).strip() if len(text_autocomplete) == 2: text_autocomplete = text_autocomplete + " " feedback_items.append(alfred.Item( attributes={ 'uid': uuid4(), 'arg': '', 'valid': 'no', 'autocomplete': text_autocomplete }, title=todo_text, subtitle=u"Change to: {0}".format(edit_text) if task_changed else "No change", icon="todo_done.png" if done else ("todo_pin.png" if pinned else "icon.png") )) # info item - tag name formatted_query = query if edit_tag: formatted_query = formatted_query.replace("#"+edit_tag, "") tag_autocomplete = "".join([ "#" + todo_tag + " ", formatted_query.strip() ]).strip() if len(tag_autocomplete) == 2: tag_autocomplete = tag_autocomplete + " " feedback_items.append(alfred.Item( attributes={ 'uid': uuid4(), 'arg': '', 'valid': 'no', 'autocomplete': tag_autocomplete }, title="#" + todo_tag, subtitle=u"Change to: #{0}".format(edit_tag) if tag_changed else "No change", icon="todo_tag.png" )) # due item subtitle = "No change" if todo_due is not None: subtitle = subtitle + " (@! will clear)" if due_changed: subtitle = u"Change to: {0}".format(helpers.due_date_text(edit_due)) if clear_due: subtitle = "Clear due" feedback_items.append(alfred.Item( attributes={ 'uid': uuid4(), 'arg': '', 'valid': 'no' }, title=helpers.due_date_text(todo_due) if todo_due else "No due date", subtitle=subtitle, icon="todo_due.png" )) # in which list is this item feedback_items.append(alfred.Item( attributes={ 'uid': uuid4(), 'arg': '', 'valid': 'no' }, title='List: ' + listmanager.friendly_file(listmanager.active_list()), subtitle="", icon="icon.png" )) alfred.write(alfred.xml(feedback_items))